From 30456b8faaaeec8351a01b7e82cc36d8f83624ea Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Tue, 4 Apr 2023 09:50:44 +0200 Subject: [PATCH 01/17] first commit --- inc/VAnaSumRunParameterLinkDef.h | 6 + inc/VBaseRawDataReader.h | 10 +- inc/VCalibrationData.h | 3 +- inc/VCalibrator.h | 21 +- inc/VCamera.h | 2 +- inc/VDST.h | 8 +- inc/VDSTReader.h | 6 +- inc/VDSTTree.h | 2 +- inc/VDataMCComparision.h | 8 +- inc/VDeadPixelOrganizer.h | 4 +- inc/VDisplay.h | 6 +- inc/VEnergyThreshold.h | 64 +- inc/VEventLoop.h | 25 +- inc/VEvndispData.h | 46 +- inc/VEvndispRunParameter.h | 3 +- inc/VFitTraceHandler.h | 4 +- inc/VGammaHadronCuts.h | 9 +- inc/VGlobalRunParameter.h | 7 +- inc/VGrIsuReader.h | 6 +- inc/VIPRCalculator.h | 62 + inc/VImageAnalyzer.h | 6 +- inc/VImageAnalyzerData.h | 6 +- inc/VImageBaseAnalyzer.h | 2 +- inc/VImageCleaning.h | 6 +- inc/VImageParameterCalculation.h | 8 +- inc/VInstrumentResponseFunctionRunParameter.h | 7 +- inc/VNoiseFileReader.h | 2 +- inc/VPedestalCalculator.h | 18 +- inc/VPlotAnasumHistograms.h | 5 +- inc/VPlotCompareDataWithMC.h | 6 +- inc/VPlotTMVAParameters.h | 47 + inc/VPlotTMVAParametersLinkDef.h | 3 + inc/VRawDataReader.h | 4 +- inc/VReadRunParameter.h | 8 +- inc/VSensitivityCalculator.h | 6 +- inc/VSimulationDataReader.h | 2 +- inc/VStereoAnalysis.h | 2 +- inc/VTMVAEvaluator.h | 77 +- inc/VTMVARunData.h | 18 +- inc/VVirtualDataReader.h | 2 +- src/.VCalibrator.cpp.swp | Bin 0 -> 16384 bytes src/.VIPRCalculator.cpp.swo | Bin 0 -> 49152 bytes src/.VIPRCalculator.cpp.swp | Bin 0 -> 20480 bytes src/.VPedestalCalculator.cpp.swo | Bin 0 -> 32768 bytes src/.VPedestalCalculator.cpp.swp | Bin 0 -> 20480 bytes src/._VIPRCalculator.cpp | Bin 0 -> 4096 bytes src/VAnaSum.cpp | 9 +- src/VAnaSumRunParameter.cpp | 185 ++- src/VCalibrationData.cpp | 20 +- src/VCalibrator.cpp | 1082 +------------- src/VDataMCComparision.cpp | 39 +- src/VEffectiveAreaCalculator.cpp | 134 +- src/VEnergyThreshold.cpp | 251 ++-- src/VEventLoop.cpp | 49 +- src/VEvndispRunParameter.cpp | 9 - src/VGammaHadronCuts.cpp | 138 +- src/VGlobalRunParameter.cpp | 20 - src/VIPRCalculator.cpp | 748 ++++++++++ src/VImageBaseAnalyzer.cpp | 11 + src/VImageCleaning.cpp | 46 + ...InstrumentResponseFunctionRunParameter.cpp | 8 +- src/VMonteCarloRateCalculator.cpp | 6 +- src/VPedestalCalculator.cpp | 33 +- src/VPlotAnasumHistograms.cpp | 41 +- src/VPlotCompareDataWithMC.cpp | 94 +- src/VPlotInstrumentResponseFunction.cpp | 10 +- src/VPlotTMVAParameters.cpp | 179 +++ src/VReadRunParameter.cpp | 5 +- src/VSensitivityCalculator.cpp | 62 +- src/VStereoAnalysis.cpp | 73 +- src/VStereoHistograms.cpp | 5 +- src/VTMVAEvaluator.cpp | 1329 +++++++++++------ src/VTMVARunData.cpp | 241 +-- src/VTMVARunDataEnergyCut.cpp | 3 + src/VTS.calculateCrabRateFromMC.cpp | 173 +++ src/VTS.getRunListFromDB.cpp | 6 +- src/VTableLookupDataHandler.cpp | 4 +- src/calculateCrabRateFromMC.cpp | 570 ------- src/combineEffectiveAreas.cpp | 6 +- src/compareDatawithMC.cpp | 24 +- src/makeEffectiveArea.cpp | 6 +- src/makeRadialAcceptance.cpp | 47 +- src/printRunParameter.cpp | 23 +- src/trainTMVAforAngularReconstruction.cpp | 4 +- src/trainTMVAforGammaHadronSeparation.cpp | 555 +++---- ...AforGammaHadronSeparation_TrainingFile.cpp | 178 +++ src/writeParticleRateFilesForTMVA.cpp | 177 ++- ...iteParticleRateFilesFromEffectiveAreas.cpp | 251 ++++ 88 files changed, 3960 insertions(+), 3431 deletions(-) create mode 100644 inc/VIPRCalculator.h create mode 100644 inc/VPlotTMVAParameters.h create mode 100644 inc/VPlotTMVAParametersLinkDef.h create mode 100644 src/.VCalibrator.cpp.swp create mode 100644 src/.VIPRCalculator.cpp.swo create mode 100644 src/.VIPRCalculator.cpp.swp create mode 100644 src/.VPedestalCalculator.cpp.swo create mode 100644 src/.VPedestalCalculator.cpp.swp create mode 100644 src/._VIPRCalculator.cpp create mode 100644 src/VIPRCalculator.cpp create mode 100644 src/VPlotTMVAParameters.cpp create mode 100644 src/VTS.calculateCrabRateFromMC.cpp delete mode 100644 src/calculateCrabRateFromMC.cpp create mode 100644 src/trainTMVAforGammaHadronSeparation_TrainingFile.cpp create mode 100644 src/writeParticleRateFilesFromEffectiveAreas.cpp diff --git a/inc/VAnaSumRunParameterLinkDef.h b/inc/VAnaSumRunParameterLinkDef.h index b680e2cae..e21bcbaec 100644 --- a/inc/VAnaSumRunParameterLinkDef.h +++ b/inc/VAnaSumRunParameterLinkDef.h @@ -3,8 +3,14 @@ #pragma link off all classes; #pragma link off all functions; +//#pragma link C++ nestedclasses ; + #pragma link C++ class vector+; #pragma link C++ class VAnaSumRunParameterDataClass+; #pragma link C++ class VAnaSumRunParameterListOfExclusionRegions+; #pragma link C++ class VAnaSumRunParameter+; +//#pragma link C++ class std::vector+; + +//#pragma read sourceClass="VAnaSumRunParameter" source="std::vector fRunList" \ +// targetClass="VAnaSumRunParameter" target="std::vector fRunList" attributes="Owner" ; #endif diff --git a/inc/VBaseRawDataReader.h b/inc/VBaseRawDataReader.h index bfe440b53..3764d3ff9 100644 --- a/inc/VBaseRawDataReader.h +++ b/inc/VBaseRawDataReader.h @@ -3,13 +3,13 @@ #ifndef VBASEDATAREADER_H #define VBASEDATAREADER_H -#include "VDetectorGeometry.h" -#include "VMonteCarloRunHeader.h" -#include "VNoiseFileReader.h" +#include +#include +#include #include #include -#include "VVirtualDataReader.h" -#include "VSimulationDataReader.h" +#include +#include #include "TRandom3.h" diff --git a/inc/VCalibrationData.h b/inc/VCalibrationData.h index e7917d3a2..b00490225 100644 --- a/inc/VCalibrationData.h +++ b/inc/VCalibrationData.h @@ -143,7 +143,7 @@ class VCalibrationData // IPR graphs map< unsigned int, TGraphErrors* > fGraphIPRGraph; // one IPR graph per summation window - + map< unsigned int, TGraphErrors* > fGraphTSIPRGraph; // one IPR graph per time slice VCalibrationData( unsigned int iTel, string iDir, string iPedfile, string iGainfile, string iTofffile, string iPedLowGainfile, string iGainLowGainFile = "", string iToffLowGainFile = "", string iLowGainMultFile = "", @@ -237,6 +237,7 @@ class VCalibrationData } } TGraphErrors* getIPRGraph( unsigned int iSumWindow, bool iMakeNewGraph = false ); + TGraphErrors* getIPRGraphTimeSlice( bool iMakeNewGraph = false, unsigned int TimeSlice = 0 ); TH1F* getLowGainMultiplierDistribution() { return getHistoDist( C_LOWGAIN, true ); diff --git a/inc/VCalibrator.h b/inc/VCalibrator.h index e57ac9f7b..b2e743519 100644 --- a/inc/VCalibrator.h +++ b/inc/VCalibrator.h @@ -3,9 +3,10 @@ #ifndef VCALIBRATOR_H #define VCALIBRATOR_H -#include "VImageBaseAnalyzer.h" -#include "VPedestalCalculator.h" -#include "VDB_CalibrationInfo.h" +#include +#include +#include +#include #include #include "TClonesArray.h" @@ -99,16 +100,10 @@ class VCalibrator : public VImageBaseAnalyzer int readLowGainCalibrationValues_fromCalibFile( string iVariable = "LOWGAINPED", unsigned int iTel = 9999, int iSumWindow = 9999 ); string getCalibrationFileName( int iTel, int irun, string iSuffix, string name = "" ); void readCalibrationData(); - bool readCalibrationDatafromDSTFiles( string iSourceFile ); void readfromVOFFLINE_DBText( int gain_or_toff, vector< unsigned int >& VchannelList, vector< double >& Vmean, vector< double >& Vrms ); void readfromVOFFLINE_DB( int gain_or_toff, string& iFile, vector< unsigned int >& VchannelList, vector< double >& Vmean, vector< double >& Vrms ); void readGains( bool iLowGain = false ); bool readIPRGraph_from_DSTFile( string iDSTFile, unsigned int iSummationWindow, ULong64_t iTelType ); - bool calculateIPRGraphs(); - bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); - bool copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); - TH1F* initializeIPRAveraged( unsigned int iSummationWindow, unsigned int iTelType ); - TH1F* calculateIPRGraphAveraged( unsigned int iSummationWindow ); bool readLowGainMultiplier( ); bool readPeds( string iFile, bool, unsigned int ); bool readPeds_from_grisufile( bool, unsigned int ); @@ -121,10 +116,9 @@ class VCalibrator : public VImageBaseAnalyzer void setCalibrationFileNames(); void writeGains( bool iLowGain = false ); - void writePeds( bool iLowGain, VPedestalCalculator* iP = 0, bool iWriteAsciiFile = true ); + void writePeds( bool iLowGain, VPedestalCalculator* iP = 0, bool iWriteAsciiFile = true, VIPRCalculator *fIPRCalculator = 0 ); void writeTOffsets( bool iLowGain = false ); void writeAverageTZeros( bool iLowGain = false ); - bool writeIPRgraphs( string iFile = "" ); public: @@ -135,7 +129,8 @@ class VCalibrator : public VImageBaseAnalyzer void calculatePedestals( bool iLowGain = false ); void calculateGainsAndTOffsets( bool iLowGain = false ); unsigned int getNumberOfEventsUsedInCalibration( int iTelID, int iType ); - void initialize(); - void terminate( VPedestalCalculator* ); + //void calculateIPRGraphs(VIPRCalculator *fIPRCalculator = 0, VPedestalCalculator *iP = 0); + void initialize( VIPRCalculator *fIPRCalculator ); + void terminate( VPedestalCalculator* iP, VIPRCalculator *fIPRCalculator ); }; #endif diff --git a/inc/VCamera.h b/inc/VCamera.h index 44a54b51d..f846c49e4 100644 --- a/inc/VCamera.h +++ b/inc/VCamera.h @@ -15,7 +15,7 @@ #include #include -#include "VEvndispData.h" +#include #ifndef NOVBF #include #endif diff --git a/inc/VDST.h b/inc/VDST.h index 780f54044..74bc91670 100644 --- a/inc/VDST.h +++ b/inc/VDST.h @@ -8,10 +8,10 @@ #include #include -#include "VGlobalRunParameter.h" -#include "VImageBaseAnalyzer.h" -#include "VImageCleaning.h" -#include "VDSTTree.h" +#include +#include +#include +#include /////////////////////////////////////////////////////////////////////////////////// // MAXIMUM NUMBER OF TELESCOPES AND CHANNELS IS DEFINED IN EVNDISP_definition.h diff --git a/inc/VDSTReader.h b/inc/VDSTReader.h index 9aabbe44f..de64f15d9 100644 --- a/inc/VDSTReader.h +++ b/inc/VDSTReader.h @@ -3,9 +3,9 @@ #ifndef VDSTREADER_H #define VDSTREADER_H -#include "VGlobalRunParameter.h" -#include "VDSTTree.h" -#include "VVirtualDataReader.h" +#include +#include +#include #include "TFile.h" #include "TTree.h" diff --git a/inc/VDSTTree.h b/inc/VDSTTree.h index e4d26ddad..6813346a9 100644 --- a/inc/VDSTTree.h +++ b/inc/VDSTTree.h @@ -16,7 +16,7 @@ #include #include -#include "VGlobalRunParameter.h" +#include //////////////////////////////////////////////////////////////////////////////////////// // MAXIMUM NUMBERS OF TELESCOPES AND CHANNELS ARE DEFINED IN inc/VGlobalRunParameter.h diff --git a/inc/VDataMCComparision.h b/inc/VDataMCComparision.h index 2c0ecfd28..844749fac 100644 --- a/inc/VDataMCComparision.h +++ b/inc/VDataMCComparision.h @@ -87,7 +87,6 @@ class VDataMCComparision // cuts VGammaHadronCuts* fCuts; bool fCalculateMVAValues; - string fEpochATM; // lists with all histograms TList* hisList; @@ -119,7 +118,7 @@ class VDataMCComparision public: - VDataMCComparision( string, int ); + VDataMCComparision( string, int, bool ); ~VDataMCComparision() {} void defineHistograms(); bool fillHistograms( string ifile, int iSingleTelescopeCuts ); @@ -131,11 +130,6 @@ class VDataMCComparision hAzWeight = hAz; } void setAzRange( double iAzMin, double iAzMax ); - void setTMVABDTComparision( string iEpochATM ) - { - fCalculateMVAValues = true; - fEpochATM = iEpochATM; - } void setZeRange( double iZeMin, double iZeMax ); bool setOnOffHistograms( VDataMCComparision*, VDataMCComparision*, double norm ); void setShowerMaximZe_deg( double iZe = 20. ) diff --git a/inc/VDeadPixelOrganizer.h b/inc/VDeadPixelOrganizer.h index 3553658b7..96a2c1707 100644 --- a/inc/VDeadPixelOrganizer.h +++ b/inc/VDeadPixelOrganizer.h @@ -18,8 +18,8 @@ #include -#include "VDetectorGeometry.h" -#include "VEvndispRunParameter.h" +#include +#include using namespace std ; diff --git a/inc/VDisplay.h b/inc/VDisplay.h index 73ff5e89c..552b7a43d 100644 --- a/inc/VDisplay.h +++ b/inc/VDisplay.h @@ -43,9 +43,9 @@ #include #include -#include "VCamera.h" -#include "VDisplayBirdsEye.h" -#include "VEventLoop.h" +#include +#include +#include #include #include diff --git a/inc/VEnergyThreshold.h b/inc/VEnergyThreshold.h index a7c765b5f..eae7d1f48 100644 --- a/inc/VEnergyThreshold.h +++ b/inc/VEnergyThreshold.h @@ -4,17 +4,14 @@ #define VEnergyThreshold_H #include "TCanvas.h" -#include "TChain.h" #include "TF1.h" #include "TFile.h" -#include "TGraph.h" #include "TGraphErrors.h" #include "TH1D.h" -#include "TH2F.h" #include "TList.h" #include "TMath.h" #include "TObject.h" -#include "TROOT.h" +#include "TProfile.h" #include "TStyle.h" #include "TText.h" #include "TTree.h" @@ -26,6 +23,7 @@ #include #include "VRunList.h" +#include "CEffArea.h" using namespace std; @@ -36,7 +34,7 @@ class VEnergyThreshold : public TObject bool fDebug; TFile* fEffAreaFile; - TChain* fEffArea; + CEffArea* fEffArea; TFile* fEnergyThresholdFile; @@ -46,32 +44,30 @@ class VEnergyThreshold : public TObject TFile* fOutFile; TTree* fTreeEth; - float fze; - UShort_t fAzBin; - float fAzMin; - float fAzMax; - float fWoff; - UShort_t fTNoise; - float fTPedvar; - float feth; - float fesys_10p; - float fesys_15p; - float fesys_20p; - float feffFract_05p; - float feffFract_10p; - float feffFract_20p; - float feffFract_50p; - float feffFract_90p; - float feff_300GeV; - float feff_500GeV; - float feff_1TeV; - - UShort_t nbins; - float e0[1000]; - float eff[1000]; - UShort_t nbins_esys; - float e0_esys[1000]; - float esys_rel[1000]; + double fze; + int fAzBin; + double fAzMin; + double fAzMax; + double fXoff; + double fYoff; + double fWoff; + int fTNoise; + double fTNoisePE; + double fTPedvar; + double fSpectralIndex; + double feth; + double fesys_10p; + double fesys_15p; + double fesys_20p; + double feffFract_05p; + double feffFract_10p; + double feffFract_20p; + double feffFract_50p; + double feffFract_90p; + // effective areas + double feff_300GeV; + double feff_500GeV; + double feff_1TeV; int fPlottingMarkerStyle; int fPlottingMarkerColor; @@ -83,6 +79,7 @@ class VEnergyThreshold : public TObject double getEnergyThreshold( TH1D* h = 0, bool bLogEnergyAxis = true, bool bFit = true ); bool openEnergyThresholdFile(); bool setUpThresholdTree(); + void copyEntry(); double interpolateEnergyThreshold( VRunList* ); @@ -95,14 +92,13 @@ class VEnergyThreshold : public TObject bool closeOutputFile(); bool openEffectiveAreaFile( string ifile ); bool calculateEnergyThreshold( bool bFit = true, int nentries = -1 ); - double getEnergy_maxSystematic( vector< double > x, vector< double > y, double iSys = 0.1 ); - double getEnergy_maxSystematic( TGraphErrors* g, double iSys = 0.1 ); + double getEnergy_maxSystematic( TObject* h = 0, double iSys = 0.1 ); double getEnergy_MaxEffectiveAreaFraction( TObject* h = 0, double iFrac = 0.1 ); double getEnergy_fixedValue() { return fEnergyThresholdFixedValue; } - void plot_energyThresholds( string var = "E_diffmax", double ze = 20., double woff = 0.5, int noise = 150, int az = 16, bool bPlot = true, string plot_option = "p" ); + void plot_energyThresholds( string var = "E_diffmax", double ze = 20., double woff = 0.5, int noise = 150, double index = 2.4, int az = 16, bool bPlot = true, string plot_option = "p" ); void setPlottingStyle( int iC = 1, int iS = 21, float iW = 2., float iL = 2. ) { fPlottingMarkerStyle = iS; diff --git a/inc/VEventLoop.h b/inc/VEventLoop.h index e8562e014..740f4f98d 100644 --- a/inc/VEventLoop.h +++ b/inc/VEventLoop.h @@ -9,21 +9,22 @@ #include #include -#include "VImageAnalyzer.h" -#include "VArrayAnalyzer.h" -#include "VCalibrator.h" -#include "VEvndispData.h" -#include "VDeadTime.h" -#include "VDST.h" +#include +#include +#include +#include +#include +#include +#include #ifndef NOVBF #include -#include "VRawDataReader.h" -#include "VBFDataReader.h" +#include +#include #endif -#include "VPedestalCalculator.h" -#include "VEvndispRunParameter.h" +#include +#include -#include "VDeadPixelOrganizer.h" +#include #include #include @@ -40,6 +41,7 @@ class VEventLoop : public VEvndispData enum E_runmode {R_ANA, R_PED, R_GTO, R_BCK, R_DST, R_GTOLOW, R_PEDLOW, R_TZERO, R_TZEROLOW }; VCalibrator* fCalibrator; //!< default calibration class + VIPRCalculator* fIPRCalculator; VPedestalCalculator* fPedestalCalculator; //!< default pedestal calculator VImageAnalyzer* fAnalyzer; //!< default analyzer class VArrayAnalyzer* fArrayAnalyzer; //!< default array analyzer @@ -55,6 +57,7 @@ class VEventLoop : public VEvndispData bool fAnalyzeMode; //!< used for gotoEvent (go through file without analyse events) bool bMCSetAtmosphericID; vector< bool > fBoolPrintSample; + bool fIPRTimeSlices; bool fCutTelescope; //!< cuts apply only to one telescope int fNCutNArrayTrigger; //!< show only events with more than fNCutNArrayTrigger triggered telescopes diff --git a/inc/VEvndispData.h b/inc/VEvndispData.h index be1574d03..4fb75ff23 100644 --- a/inc/VEvndispData.h +++ b/inc/VEvndispData.h @@ -3,27 +3,27 @@ #ifndef VDATA_H #define VDATA_H -#include "VImageAnalyzerData.h" -#include "VEvndispReconstructionParameter.h" -#include "VCalibrationData.h" -#include "VDeadChannelFinder.h" -#include "VDetectorGeometry.h" -#include "VDetectorTree.h" -#include "VDSTReader.h" -#include "VGrIsuReader.h" -#include "VMCParameters.h" -#include "VMultipleGrIsuReader.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifndef NOVBF -#include "VBaseRawDataReader.h" +#include #endif -#include "VDB_PixelDataReader.h" -#include "VEvndispRunParameter.h" -#include "VFitTraceHandler.h" -#include "VStarCatalogue.h" -#include "VShowerParameters.h" -#include "VPointing.h" -#include "VArrayPointing.h" -#include "VTraceHandler.h" +#include +#include +#include +#include +#include +#include +#include +#include #include "TDirectory.h" #include "TFile.h" @@ -523,6 +523,14 @@ class VEvndispData { return fCalData[fTelID]->getIPRGraph( iSumWindow, iMakeNewGraph ); } + TGraphErrors* getIPRGraphTimeSlice( unsigned int TimeSlice = 0 ) + { + return fCalData[fTelID]->getIPRGraphTimeSlice( false, TimeSlice ); + } + TGraphErrors* getIPRGraphTimeSlice( bool iMakeNewGraph = false, unsigned int TimeSlice = 0 ) + { + return fCalData[fTelID]->getIPRGraphTimeSlice( iMakeNewGraph, TimeSlice ); + } float getL1Rate( unsigned int iChannel ) { if( fDB_PixelDataReader ) diff --git a/inc/VEvndispRunParameter.h b/inc/VEvndispRunParameter.h index 0bd48a1dd..7beb44a94 100644 --- a/inc/VEvndispRunParameter.h +++ b/inc/VEvndispRunParameter.h @@ -312,7 +312,6 @@ class VEvndispRunParameter : public TNamed, public VGlobalRunParameter { return fDBTextDirectory; } - string getInstrumentATMString(); string getInstrumentEpoch( bool iMajor = false, bool iUpdateInstrumentEpoch = false ); bool isMC() @@ -333,6 +332,6 @@ class VEvndispRunParameter : public TNamed, public VGlobalRunParameter return ( fDBTextDirectory.size() > 0 ); } - ClassDef( VEvndispRunParameter, 2006 ); //(increase this number) + ClassDef( VEvndispRunParameter, 2005 ); //(increase this number) }; #endif diff --git a/inc/VFitTraceHandler.h b/inc/VFitTraceHandler.h index 67a8c679c..c5dc79055 100644 --- a/inc/VFitTraceHandler.h +++ b/inc/VFitTraceHandler.h @@ -17,8 +17,8 @@ #include "TMath.h" #include "TMinuit.h" -#include "VTraceHandler.h" -#include "VVirtualDataReader.h" +#include +#include using namespace std; diff --git a/inc/VGammaHadronCuts.h b/inc/VGammaHadronCuts.h index 08a6c0711..4880aa5e2 100644 --- a/inc/VGammaHadronCuts.h +++ b/inc/VGammaHadronCuts.h @@ -129,6 +129,7 @@ class VGammaHadronCuts : public VAnalysisUtilities unsigned int fTMVAWeightFileIndex_Emax; unsigned int fTMVAWeightFileIndex_Zmin; unsigned int fTMVAWeightFileIndex_Zmax; + double fTMVAEnergyStepSize; map< unsigned int, double > fTMVASignalEfficiency; map< unsigned int, double > fTMVA_MVACut; double fTMVAProbabilityThreshold; @@ -176,7 +177,7 @@ class VGammaHadronCuts : public VAnalysisUtilities bool initPhaseCuts( string iDir ); bool initProbabilityCuts( int irun ); bool initProbabilityCuts( string iDir ); - bool initTMVAEvaluator( string iTMVAFile, unsigned int iTMVAWeightFileIndex_Emin, unsigned int iTMVAWeightFileIndex_Emax, unsigned int iTMVAWeightFileIndex_Zmin, unsigned int iTMVAWeightFileIndex_Zmax ); + bool initTMVAEvaluator( string iTMVAFile, unsigned int iTMVAWeightFileIndex_Emin, unsigned int iTMVAWeightFileIndex_Emax, unsigned int iTMVAWeightFileIndex_Zmin, unsigned int iTMVAWeightFileIndex_Zmax, double iTMVAEnergy_StepSize ); string getTelToAnalyzeString(); @@ -348,6 +349,10 @@ class VGammaHadronCuts : public VAnalysisUtilities return fCut_Theta2_max; } double getTheta2Cut_max( double e ); // get theta2 max cut (might be energy dependent) [TeV] energy (linear) + TGraph* getTheta2Cut_TMVA_max() + { + return getEnergyDependentCut( "TMVABoxCut_Theta2_max" ); + } TGraph* getTheta2Cut_IRF_Max() { return getEnergyDependentCut( "IRFAngRes" ); @@ -431,6 +436,6 @@ class VGammaHadronCuts : public VAnalysisUtilities return fUseOrbitalPhaseCuts; } - ClassDef( VGammaHadronCuts, 59 ); + ClassDef( VGammaHadronCuts, 58 ); }; #endif diff --git a/inc/VGlobalRunParameter.h b/inc/VGlobalRunParameter.h index 0cbcdde4d..14a4cb997 100644 --- a/inc/VGlobalRunParameter.h +++ b/inc/VGlobalRunParameter.h @@ -57,7 +57,6 @@ class VGlobalRunParameter // DIRECTORIES static string fEVNDISPAnaDataDirectory; // directory where all data (detectorgeometry, ...) is expected and written to (output file) - static string fEVNDISPAnaDataDirectory_tmp; // tmp directories for aux data (rarely used) static string fVBFRawDataDirectory; // directory with VERITAS vbf data (vbf files) static string fEVNDISPCalibrationDataDirectory; // directory where calibration data is expected and written to static string fEVNDISPOutputDirectory; // output- and result files are written into this directory @@ -77,10 +76,6 @@ class VGlobalRunParameter { return fEVNDISPAnaDataDirectory; } - static string getDirectory_EVNDISPAnaDataTMP() - { - return fEVNDISPAnaDataDirectory_tmp; - } string getDirectory_EVNDISPCalibrationData() { return fEVNDISPAnaDataDirectory + "/Calibration/"; @@ -153,7 +148,7 @@ class VGlobalRunParameter bool setDirectory_EVNDISPCalibrationData( string iDir ); bool update( TChain* ic ); - ClassDef( VGlobalRunParameter, 11 ); + ClassDef( VGlobalRunParameter, 10 ); }; #endif diff --git a/inc/VGrIsuReader.h b/inc/VGrIsuReader.h index e45589c78..3f6d68591 100644 --- a/inc/VGrIsuReader.h +++ b/inc/VGrIsuReader.h @@ -17,10 +17,10 @@ #include "TSystem.h" #include "TTree.h" -#include "VDetectorGeometry.h" +#include #include "VMonteCarloRunHeader.h" -#include "VSkyCoordinatesUtilities.h" -#include "VVirtualDataReader.h" +#include +#include using namespace std; diff --git a/inc/VIPRCalculator.h b/inc/VIPRCalculator.h new file mode 100644 index 000000000..c5268fe31 --- /dev/null +++ b/inc/VIPRCalculator.h @@ -0,0 +1,62 @@ +#ifndef VIPRCALCULATOR_H +#define VIPRCALCULATOR_H + +#include +#include +#include + +#include "TClonesArray.h" +#include "TFile.h" +#include "TH1F.h" +#include "TLeaf.h" +#include "TMath.h" +#include "TProfile.h" +#include "TSystem.h" +#include "TTree.h" + +#include +#include +#include +#include +#include + +using namespace std; + +class VIPRCalculator : public VImageBaseAnalyzer +{ + + private: + VEvndispData* fData; + vector< string > fPedFile; + bool fIPRTimeSlices; + bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs + bool fIPRInTimeSlices; + int fPedPerTelescopeTypeMinCnt; + TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + TGraphErrors* updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow); + float convertRate(unsigned int i_tel); + float getTsearch(); + void definePedestalFile( std::vector fPedFileNameC ); + TFile* initializePedestalFile( int i_tel ); + TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + bool calculateIPRGraphsTimeSlices( const int TimeSlice, int iSummationWindow, const int itel); + bool calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); + bool copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ); + TH1F* calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); + public: + + vector>>> fpedcal_histo_storage; + TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); + vector>>> getStorageHist(); + void fillIPRPedestalHisto(); + void fillIPRPedestalHisto(const int telID, const vector>>& fpedcal_histo ); + bool calculateIPRGraphs( std::vector fPedFileNameC); + bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); + void checkHistEmpty(const int telID, const int ts, const int pixel, const int sw); + + VIPRCalculator(); + ~VIPRCalculator() {} + + void initialize(); +}; +#endif diff --git a/inc/VImageAnalyzer.h b/inc/VImageAnalyzer.h index b4e80d390..b00fb6cb7 100644 --- a/inc/VImageAnalyzer.h +++ b/inc/VImageAnalyzer.h @@ -8,9 +8,9 @@ #include "TTree.h" #include "TROOT.h" -#include "VImageBaseAnalyzer.h" -#include "VImageParameterCalculation.h" -#include "VImageCleaning.h" +#include +#include +#include #include #include diff --git a/inc/VImageAnalyzerData.h b/inc/VImageAnalyzerData.h index 1306d11cd..13695dab3 100644 --- a/inc/VImageAnalyzerData.h +++ b/inc/VImageAnalyzerData.h @@ -8,9 +8,9 @@ #include "TProfile2D.h" #include "TRandom3.h" -#include "VImageAnalyzerHistograms.h" -#include "VSpecialChannel.h" -#include "VImageParameter.h" +#include +#include +#include #include #include diff --git a/inc/VImageBaseAnalyzer.h b/inc/VImageBaseAnalyzer.h index 59c357600..5d68d3b7d 100644 --- a/inc/VImageBaseAnalyzer.h +++ b/inc/VImageBaseAnalyzer.h @@ -3,7 +3,7 @@ #ifndef VIMAGEBASEANALYZER_H #define VIMAGEBASEANALYZER_H -#include "VEvndispData.h" +#include #include "TTree.h" diff --git a/inc/VImageCleaning.h b/inc/VImageCleaning.h index 97acdcb4c..d55fc4d1e 100644 --- a/inc/VImageCleaning.h +++ b/inc/VImageCleaning.h @@ -3,7 +3,7 @@ #ifndef VIMAGECLEANING_H #define VIMAGECLEANING_H -#include "VEvndispData.h" +#include #include #include "VImageCleaningRunParameter.h" @@ -42,6 +42,9 @@ class VImageCleaning TObjArray* fProb2nnCurves; TObjArray* fProbBoundCurves; TObjArray* fIPRgraphs; + //vector< vector< TObjArray* > > fIPRTSgraphs; + vector< TObjArray* > fIPRTSgraphs; + //TObjArray*** fIPRTSgraphs; vector< vector< bool > > fifActiveNN; // [nteltypes][nngroups] bool ifActiveNN[VDST_MAXNNGROUPTYPES][VDST_MAXTELTYPES]; // if NN groups is searched in NN-image cleaning procedure int VALIDITY[VDST_MAXCHANNELS]; // Flags for pixels, accepted by nn-image cleaning. VALIDITY[i]=2-6 : core pixels, VALIDITY[i]>6 :boundary pixels @@ -73,6 +76,7 @@ class VImageCleaning int ImageCleaningCharge( unsigned int TrigSimTelType ); bool InitNNImageCleaning(); bool InitNNImgClnPerTelType( unsigned int TrigSimTelType ); + bool InitNNImgClnPerTelTypeTimeSlice( unsigned int teltype, unsigned int ts ); void DiscardTimeOutlayers( unsigned int TrigSimTelType ); void DiscardLocalTimeOutlayers( float NNthresh[6] ); // use this function void DiscardIsolatedPixels(); diff --git a/inc/VImageParameterCalculation.h b/inc/VImageParameterCalculation.h index 496eded3d..c3f9d0f7f 100644 --- a/inc/VImageParameterCalculation.h +++ b/inc/VImageParameterCalculation.h @@ -8,10 +8,10 @@ #include #include -#include "VDetectorGeometry.h" -#include "VEvndispData.h" -#include "VHoughTransform.h" -#include "VImageParameter.h" +#include +#include +#include +#include #include "TError.h" #include "TMath.h" diff --git a/inc/VInstrumentResponseFunctionRunParameter.h b/inc/VInstrumentResponseFunctionRunParameter.h index bb1fac76f..e3588ccfd 100644 --- a/inc/VInstrumentResponseFunctionRunParameter.h +++ b/inc/VInstrumentResponseFunctionRunParameter.h @@ -36,7 +36,6 @@ class VInstrumentResponseFunctionRunParameter : public TNamed string fCutFileName; string fInstrumentEpoch; - string fInstrumentEpochATM; vector< unsigned int > fTelToAnalyse; // telescopes used in analysis (optional, not always filled) int fGammaHadronCutSelector; int fDirectionCutSelector; @@ -101,16 +100,12 @@ class VInstrumentResponseFunctionRunParameter : public TNamed ~VInstrumentResponseFunctionRunParameter() {} string getInstrumentEpoch( bool iMajor = false ); - string getInstrumentATMString() - { - return fInstrumentEpochATM; - } void print(); VMonteCarloRunHeader* readMCRunHeader(); bool readRunParameterFromTextFile( string iFile ); bool testRunparameters(); - ClassDef( VInstrumentResponseFunctionRunParameter, 17 ); + ClassDef( VInstrumentResponseFunctionRunParameter, 16 ); }; #endif diff --git a/inc/VNoiseFileReader.h b/inc/VNoiseFileReader.h index 2e7d351c8..95005d68a 100644 --- a/inc/VNoiseFileReader.h +++ b/inc/VNoiseFileReader.h @@ -3,7 +3,7 @@ #ifndef VNoiseFileReader_H #define VNoiseFileReader_H -#include "VGrIsuReader.h" +#include #include #include diff --git a/inc/VPedestalCalculator.h b/inc/VPedestalCalculator.h index 5bf71b24b..fa2876e72 100644 --- a/inc/VPedestalCalculator.h +++ b/inc/VPedestalCalculator.h @@ -3,9 +3,10 @@ #ifndef VPEDESTALCALCULATOR_H #define VPEDESTALCALCULATOR_H -#include "VImageBaseAnalyzer.h" -#include "VGlobalRunParameter.h" -#include "VSkyCoordinatesUtilities.h" +#include +#include +#include +#include #include "TDirectory.h" #include "TFile.h" @@ -47,7 +48,8 @@ class VPedestalCalculator : public VImageBaseAnalyzer vector< vector< vector< float > > > fpedcal_mean; vector< vector< vector< float > > > fpedcal_mean2; vector< vector< vector< TH1F* > > > fpedcal_histo; - + std::vector > copy_fpedcal_histo; + vector< vector< float > > v_temp_pedEntries; vector< vector< float > > v_temp_ped; vector< vector< float > > v_temp_pedvar; @@ -62,7 +64,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer void reset(); public: - + vector< int > NTimeSlices; vector< vector< int > > v_MJD; //! [telid][time slice] vector< vector< double > > v_time; //! [telid][time slice] //! [telid][time slice][npixel][summation window] @@ -73,11 +75,13 @@ class VPedestalCalculator : public VImageBaseAnalyzer vector< vector< vector< vector< float > > > > v_pedvar; vector< vector< vector< vector< float > > > > v_ped_median; vector< vector< vector< vector< float > > > > v_pedvar68; - + + vector< vector< vector< TH1F* > > > fpedcal_histo_sw; + VPedestalCalculator(); ~VPedestalCalculator() {} - void doAnalysis( bool iLowGain = false ); + void doAnalysis( bool iLowGain = false , VIPRCalculator *fIPRCalculator = 0 ); vector< TTree* > getPedestalTree() { return fTree; diff --git a/inc/VPlotAnasumHistograms.h b/inc/VPlotAnasumHistograms.h index a324d430f..3ed72ac27 100644 --- a/inc/VPlotAnasumHistograms.h +++ b/inc/VPlotAnasumHistograms.h @@ -100,8 +100,7 @@ class VPlotAnasumHistograms : public VAnalysisUtilities, public VPlotUtilities, void plot_deadTimes(); void plot_mscPlots( int irebin = 2, double xmin = -2., double xmax = 4., string mscwfile = "" ); void plot_qualityHistograms( double iSourceStrength = 1., bool bUpper = true, int iMethod = 0 ); - TCanvas* plot_theta2( double t2min = 0., double t2max = 0.3, int irbin = 5, - double setYMax = -9999., double setYMin = -9999. ); + TCanvas* plot_theta2( double t2min = 0., double t2max = 0.3, int irbin = 5 ); void plot_theta2Correction(); void plot_UncorrelatedSkyPlots(); void plot_CorrelatedSkyPlots(); @@ -144,7 +143,7 @@ class VPlotAnasumHistograms : public VAnalysisUtilities, public VPlotUtilities, } bool setRunNumber( int iRun ); // select run for plotting - ClassDef( VPlotAnasumHistograms, 16 ); + ClassDef( VPlotAnasumHistograms, 15 ); }; #endif diff --git a/inc/VPlotCompareDataWithMC.h b/inc/VPlotCompareDataWithMC.h index f9ee22e0f..4dd409b3a 100644 --- a/inc/VPlotCompareDataWithMC.h +++ b/inc/VPlotCompareDataWithMC.h @@ -38,7 +38,6 @@ class VPlotCompareDataWithMC : public VHistogramUtilities double fRelatePlotRange_min; double fRelatePlotRange_max; - int fScalingMethod; void drawMatchingTests( TH1D* h1, TH1D* h2, double xmin = -9999., double xmax = 9999. ); TF1* do_theta2Fit( TH1D* h, int icolor = 1, int istyle = 1 ); @@ -63,7 +62,7 @@ class VPlotCompareDataWithMC : public VHistogramUtilities void help(); void centroids(); - TCanvas* core_plots( int iRebin = 1 ); + TCanvas* core_plots( int iRebin = 1, int iScaling = 1 ); TCanvas* distance_plots(); TCanvas* emission_height( double iEmissionHeightMax = 20. ); void erecRatio_vs_energy_plots( int iTelescope = 1, int iRebin = 1, double xmin = 0., double xmax = 2. ); @@ -89,7 +88,7 @@ class VPlotCompareDataWithMC : public VHistogramUtilities double iSystematicCutCheck = -99., string iXVariable = "Erec", double y_min = -99., bool iPlotLogY = false ); TCanvas* single_telescope( int telid = -1 ); - TCanvas* single_telescope( int telid, string iPlot, bool iOneCanvas = true, int i_rebin = 1 ); + TCanvas* single_telescope( int telid, string iPlot, bool iOneCanvas = true, int iScalingMethod = 1, int i_rebin = 1 ); TCanvas* stereo_parameter(); void mva_parameter(); @@ -114,7 +113,6 @@ class VPlotCompareDataWithMC : public VHistogramUtilities fRelatePlotRange_min = iMin; fRelatePlotRange_max = iMax; } - void setScalingMethod( int iScalingMethod = 1 ); }; #endif diff --git a/inc/VPlotTMVAParameters.h b/inc/VPlotTMVAParameters.h new file mode 100644 index 000000000..61d5b97f6 --- /dev/null +++ b/inc/VPlotTMVAParameters.h @@ -0,0 +1,47 @@ +//! VPlotTMVAParameters plot results from TMVA optimization + +#ifndef VPlotTMVAParameters_H +#define VPlotTMVAParameters_H + +#include +#include +#include +#include +#include + +#include "TCanvas.h" +#include "TH1D.h" + +#include "VTMVAEvaluator.h" + +using namespace std; + +class VPlotTMVAParameters +{ + private: + + vector< string > fSubArrays; + string fDataDirectory; + + vector< TH1D* > hSignalEfficiency; + vector< TH1D* > hBackgroundEfficiency; + vector< TH1D* > hMVA; + + bool initializeHistograms( unsigned int iEnergyWeightFileIndex_min, unsigned int iEnergyWeightFileIndex_max, unsigned int iZenithWeightFileIndex_min, unsigned int iZenithWeightFileIndex_max ); + + public: + VPlotTMVAParameters(); + ~VPlotTMVAParameters() {} + + void initializeWeightFiles( string iDirectory, string iTMVADirectory, unsigned int iEnergyWeightFileIndex_min, unsigned int iEnergyWeightFileIndex_max, unsigned int iZenithWeightFileIndex_min, unsigned int iZenithWeightFileIndex_max, double iParticleNumberFile_Conversion_Rate_to_seconds = 60. ); + void plot( bool iPrint = false ); + void setDirectories( string iDataDirectory ) + { + fDataDirectory = iDataDirectory; + } + bool setSubArrays( string iSubarrayFile ); +}; + + + +#endif diff --git a/inc/VPlotTMVAParametersLinkDef.h b/inc/VPlotTMVAParametersLinkDef.h new file mode 100644 index 000000000..cbce04275 --- /dev/null +++ b/inc/VPlotTMVAParametersLinkDef.h @@ -0,0 +1,3 @@ +#ifdef __CINT__ +#pragma link C++ class VPlotTMVAParameters++; +#endif diff --git a/inc/VRawDataReader.h b/inc/VRawDataReader.h index 6f2b016e2..1f3b29c19 100644 --- a/inc/VRawDataReader.h +++ b/inc/VRawDataReader.h @@ -7,8 +7,8 @@ #include #include #include -#include "VVirtualDataReader.h" -#include "VSimulationDataReader.h" +#include +#include #include #include diff --git a/inc/VReadRunParameter.h b/inc/VReadRunParameter.h index 97bcd9d55..d448f10f9 100644 --- a/inc/VReadRunParameter.h +++ b/inc/VReadRunParameter.h @@ -15,10 +15,10 @@ #include "TSystem.h" #include "TTree.h" -#include "VGlobalRunParameter.h" -#include "VDBRunInfo.h" -#include "VEvndispRunParameter.h" -#include "VUtilities.h" +#include +#include +#include +#include class VReadRunParameter { diff --git a/inc/VSensitivityCalculator.h b/inc/VSensitivityCalculator.h index aef602abb..e134ba029 100644 --- a/inc/VSensitivityCalculator.h +++ b/inc/VSensitivityCalculator.h @@ -227,7 +227,6 @@ class VSensitivityCalculator : public TObject, public VPlotUtilities, public VHi TGraphAsymmErrors* getSensitivityGraphFromWPPhysFile( string bUnit, double iEnergyMin_TeV_lin, double iEnergyMax_TeV_lin, double dE_Log10 ); - void list_sensitivity_table( unsigned int iD ); void plot_guidingLines( double x, TGraph* g, bool iHours ); void plotEffectiveArea(); void plotDebugPlotsBackgroundParticleNumbers( vector< VDifferentialFlux > iDifferentialFlux, @@ -262,8 +261,7 @@ class VSensitivityCalculator : public TObject, public VPlotUtilities, public VHi TGraph* getObservationTimevsFluxGraph( unsigned int ID = 0 ); unsigned int listDataSets(); void listUnits(); - void list_sensitivity( unsigned int iD = 0, bool latex_table_line = false, string iTitle = "" ); - void list_sensitivity_latex_table( unsigned int iD, string iTitle, double iSignalE = -1., double iBackgroundE = -1. ); + void list_sensitivity( unsigned int iD = 0 ); TCanvas* plotCanvas_SensitivityvsEnergy( string bUnit, bool bIntegralSensitivity, bool bNewCanvas = false ); TCanvas* plotObservationTimevsFlux( unsigned int iD = 0, TCanvas* c = 0, int iLineColor = 1, double iLineWidth = 4., bool bGuidingLines = true ); void plotObservationTimevsFluxFromTextFile( TCanvas* c, string iTextFile, int iLineColor = 4, double iLineWidth = 1., int iLineStyle = 2 ); @@ -360,6 +358,6 @@ class VSensitivityCalculator : public TObject, public VPlotUtilities, public VHi fDebugParticleNumberFile = iFile; } - ClassDef( VSensitivityCalculator, 26 ); + ClassDef( VSensitivityCalculator, 25 ); }; #endif diff --git a/inc/VSimulationDataReader.h b/inc/VSimulationDataReader.h index 0c85f44ff..b58c7fd08 100644 --- a/inc/VSimulationDataReader.h +++ b/inc/VSimulationDataReader.h @@ -12,7 +12,7 @@ #include #include -#include "VMonteCarloRunHeader.h" +#include #include #include #include diff --git a/inc/VStereoAnalysis.h b/inc/VStereoAnalysis.h index fa979a103..e0c4eb3cd 100644 --- a/inc/VStereoAnalysis.h +++ b/inc/VStereoAnalysis.h @@ -220,7 +220,7 @@ class VStereoAnalysis CData* fDataRun; TTree* fDataRunTree; TFile* fDataFile; - string fInstrumentEpochMinor; + string fInstrumentEpoch; vector< unsigned int > fTelToAnalyze; vector< VSkyCoordinates* > fAstro; //!< Astronomical source parameters for this analysis diff --git a/inc/VTMVAEvaluator.h b/inc/VTMVAEvaluator.h index 5fb0c29eb..216e9cea5 100644 --- a/inc/VTMVAEvaluator.h +++ b/inc/VTMVAEvaluator.h @@ -41,17 +41,15 @@ class VTMVAEvaluatorData : public TNamed { public: - string fTMVAName; + unsigned int fCounter; // needed??? string fTMVAFileName; string fTMVAFileNameXML; string fTMVAMethodTag; string fTMVAMethodTag_2; - unsigned int fEnergyBin; double fEnergyCut_Log10TeV_min; double fEnergyCut_Log10TeV_max; double fSpectralWeightedMeanEnergy_Log10TeV; - unsigned int fZenithBin; double fZenithCut_min; double fZenithCut_max; @@ -60,6 +58,8 @@ class VTMVAEvaluatorData : public TNamed double fTMVACutValue; bool fTMVAOptimumCutValueFound; double fSourceStrengthAtOptimum_CU; + double fAngularContainmentRadius; + double fAngularContainmentFraction; TMVA::Reader* fTMVAReader; //! @@ -67,7 +67,7 @@ class VTMVAEvaluatorData : public TNamed ~VTMVAEvaluatorData() {} void print(); - ClassDef( VTMVAEvaluatorData, 3 ); + ClassDef( VTMVAEvaluatorData, 1 ); }; /////////////////////////////////////////////////////////////////////////////// @@ -114,11 +114,17 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities double fOptimizationMinBackGroundEvents; double fOptimizationBackgroundAlpha; double fOptimizationObservingTime_h; + double fTMVAAngularContainmentThetaFixedMinRadius; + bool fTMVAIgnoreTheta2Cut; // ignore theta2 cut in TMVA + bool fTMVAThetaCutVariableSet; // check if TMVA provides a theta2 cut variable double fTMVA_EvaluationResult; // result from TVMA evaluator + bool fTMVA_OptimizeAngularContainment; // optimize angular containment (using angular resolution vs containment histograms + bool fSmoothAndInterpolateMVAValues; string fTMVAMethodName; + double fTMVAngularContainmentRadiusMax; // maximum angular containment radius (optimization scales relative to this value) double fTMVAErrorFraction_min; // remove bins from background efficiency curves with large errors double fSpectralIndexForEnergyWeighting; // used to calculate the spectral weighted mean of an energy bin @@ -131,25 +137,24 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities float fMLR; float fEmissionHeight; float fEmissionHeightChi2_log10; + unsigned int fEnergyReconstructionMethod; float fEChi2S; float fEChi2S_log10; float fdES; float fSizeSecondMax_log10; + float fTheta2; float fCoreDist; float fImages_Ttype[VDST_MAXTELESCOPES]; float fDispDiff; - float fDispDiff_log10; float fDummy; bool bPlotEfficiencyPlotsPerBin; - bool fPrintPlotting; TH1F* getEfficiencyHistogram( string iName, TFile* iF, string iMethodTag_2 ); + double getMeanEnergyAfterCut( TFile* f, double iCut, unsigned int iDataBin ); bool optimizeSensitivity( unsigned int iDataBin ); TGraph* fillfromGraph2D( TObject* i_G, double i_ze_min, double i_ze_max ); void fillTMVAEvaluatorResults(); - string getBDTFileName( string iWeightFileName, - unsigned int i_E_index, unsigned int i_Z_index, string iSuffix = "" ); unsigned int getDataBin(); unsigned int getDataBin( double iErec_log10TeV, double iZe ); double getSignalEfficiency( unsigned int iEbin, double iE_min, double iE_max, unsigned int iZbin, double iZ_min, double iZ_max ); @@ -158,24 +163,26 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities double getValueFromMap( map< unsigned int, double > iDataMap, double iDefaultData, unsigned int iEnergyBin, double iE_min_log10, double iE_max_log10, unsigned int iZenithBin, double iZ_min, double iZ_max, string iVariable ); vector< string > getTrainingVariables( string iFile, vector< bool >& iSpectator ); + void getOptimalAngularContainmentRadius( double effS, double effB, double Ndif, double Nof, + TH2D* iHAngContainment, double iEnergy_log10_TeV, + double& i_Signal_to_sqrtNoise, double& i_AngularContainmentRadius, + double& i_AngularContainmentFraction ); void plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSignal_to_sqrtNoise, TGraph* iGSignal_to_sqrtNoise_Smooth, TH1F* hEffS, TH1F* hEffB, - TGraph* iGSignalEvents, TGraph* iGBackgroundEvents ); + TGraph* iGSignalEvents, TGraph* iGBackgroundEvents, + TGraph* iGOpt_AngularContainmentRadius, TGraph* iGOpt_AngularContainmentFraction ); TGraph* readNonNoffGraphsFromFile( TFile* iF, double i_ze_min, double i_ze_max, bool bIsOn = true ); void reset(); - void smoothAndInterPolateMVAValue( TH1F*, TH1F*, - unsigned int iE_min, unsigned int iE_max, unsigned int iZ_min, unsigned int iZ_max ); - void smoothAndInterPolateMVAValue_EnergyOnly( TH1F*, TH1F* ); - void smoothAndInterPolateMVAValue_Energy_and_Zenith( TH1F*, TH1F*, - unsigned int iE_min, unsigned int iE_max, unsigned int iZ_min, unsigned int iZ_max ); - + void smoothAndInterPolateMVAValue( TH1F*, TH1F*, unsigned int iE_min, unsigned int iE_max, unsigned int iZ_min, unsigned int iZ_max ); + public: VTMVAEvaluator(); ~VTMVAEvaluator() {}; bool evaluate(); + TGraph* getOptimalTheta2Cut_Graph(); vector< double > getBackgroundEfficiency(); vector< bool > getOptimumCutValueFound(); vector< double > getSignalEfficiency(); @@ -185,28 +192,36 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities { return fTMVAEvaluatorResults; } + bool getTMVAThetaCutVariable() + { + return fTMVAThetaCutVariableSet; + } double getTMVA_EvaluationResult() { return fTMVA_EvaluationResult; } bool initializeWeightFiles( string iWeightFileName, unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, - unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ); + unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax, double iEnergyStepSize = 0.2, string iInstrumentEpoch = "noepoch" ); bool initializeDataStrutures( CData* iC ); bool IsZombie() { return fIsZombie; } TGraphAsymmErrors* plotSignalAndBackgroundEfficiencies( bool iLogY = true, double iYmin = 1.e-4, double iMVA_min = -1., double iMVA_max = 1. ); - void printOptimizedMVACutValues( string iEpoch = "V6" ); + void printAngularContainmentRadius(); void printSensitivityOptimizationParameters(); void printSignalEfficiency(); + void printSourceStrength_CU(); void setDebug( bool iB = false ) { fDebug = iB; } - void setSensitivityOptimizationParameters( - double iSignificance = 5., double iMinEvents = 10., double iObservationTime_h = 50., - double iMinBackgroundRateRatio = 1. / 5, double iMinBackgroundEvents = 0. ) + void setIgnoreTheta2Cut( bool iB = false ) + { + fTMVAIgnoreTheta2Cut = iB; + } + void setSensitivityOptimizationParameters( double iSignificance = 5., double iMinEvents = 10., double iObservationTime_h = 50., + double iMinBackgroundRateRatio = 1. / 5, double iMinBackgroundEvents = 0. ) { fOptimizationSourceSignificance = iSignificance; fOptimizationMinSignalEvents = iMinEvents; @@ -217,6 +232,10 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities void setSensitivityOptimizationFixedSignalEfficiency( double iOptimizationFixedSignalEfficiency = 1. ); void setSensitivityOptimizationMinSourceStrength( double iOptimizationMinSourceStrength = 0.001 ); + void setOptimizeAngularContainment( bool iO = true ) + { + fTMVA_OptimizeAngularContainment = iO; + } void setParticleNumberFile( string iParticleNumberFile = "", double iConversionFactor_to_seconds = 60. ) { fParticleNumberFileName = iParticleNumberFile; @@ -226,10 +245,6 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities { bPlotEfficiencyPlotsPerBin = iB; } - void setPrintPlotting( bool iPrintPlotting = false ) - { - fPrintPlotting = iPrintPlotting; - } void setSignalEfficiency( double iSignalEfficiency = -99. ); void setSignalEfficiency( map< unsigned int, double > iMSignalEfficiency ); void setSmoothAndInterPolateMVAValues( bool iS = true ) @@ -240,15 +255,27 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities { fSpectralIndexForEnergyWeighting = iS; } + void setTMVAAngularContainmentThetaFixedMinRadius( double iR = 0. ) + { + fTMVAAngularContainmentThetaFixedMinRadius = iR; + } + void setTMVAAngularContainmentRadiusMax( double iC = 0.68 ) + { + fTMVAngularContainmentRadiusMax = iC; + } void setTMVACutValue( double iE = -99. ); void setTMVACutValue( map< unsigned int, double > iMVA ); void setTMVAErrorFraction( double iTMVAErrorFraction_min = 0.2 ) { fTMVAErrorFraction_min = iTMVAErrorFraction_min; } + void setTMVAThetaCutVariable( bool iB = false ) + { + fTMVAThetaCutVariableSet = iB; + } void setTMVAMethod( string iMethodName = "BDT" ); - ClassDef( VTMVAEvaluator, 33 ); + ClassDef( VTMVAEvaluator, 31 ); }; #endif diff --git a/inc/VTMVARunData.h b/inc/VTMVARunData.h index a5796b001..2c454ab7b 100644 --- a/inc/VTMVARunData.h +++ b/inc/VTMVARunData.h @@ -15,12 +15,10 @@ #include #include #include -#include #include #include #include -#include "VTableLookupRunParameter.h" #include "VTMVARunDataEnergyCut.h" #include "VTMVARunDataZenithCut.h" #include "VUtilities.h" @@ -36,14 +34,9 @@ class VTMVARunData : public TNamed bool fDebug; - bool fillEnergyCutData( - vector< double > iEnergyCut_Log10TeV_min, vector< double > iEnergyCut_Log10TeV_max ); - unsigned int getTrainOptionValue( string iVarName, unsigned int i_default ); - public: string fName; - string fRunOption; // run type bool fTrainGammaHadronSeparation; @@ -53,7 +46,9 @@ class VTMVARunData : public TNamed string fOutputFileName; string fOutputDirectoryName; vector< vector< TFile* > > fOutputFile; - string fSelectedEventFileName; + + // training options + bool fCheckValidityOfInputVariables; // training data double fSignalWeight; @@ -62,8 +57,6 @@ class VTMVARunData : public TNamed double fBackgroundWeight; vector< string > fBackgroundFileName; vector< TChain* > fBackgroundTree; - unsigned int fnTrain_Signal; - unsigned int fnTrain_Background; // list of training variables vector< string > fTrainingVariable; @@ -100,7 +93,6 @@ class VTMVARunData : public TNamed VTMVARunData(); ~VTMVARunData() {} void print(); - VTableLookupRunParameter* getTLRunParameter(); bool readConfigurationFile( char* ); bool openDataFiles(); void setDebug( bool iB = true ) @@ -111,10 +103,8 @@ class VTMVARunData : public TNamed { fName = iN; } - void shuffleFileVectors(); - void updateTrainingEvents( string iVarName, unsigned int iNEvents ); - ClassDef( VTMVARunData, 11 ); + ClassDef( VTMVARunData, 9 ); }; #endif diff --git a/inc/VVirtualDataReader.h b/inc/VVirtualDataReader.h index 2541c03d1..382ef01e9 100644 --- a/inc/VVirtualDataReader.h +++ b/inc/VVirtualDataReader.h @@ -8,7 +8,7 @@ #include #include #else -#include "VDummyArrayTrigger.h" +#include #endif #include diff --git a/src/.VCalibrator.cpp.swp b/src/.VCalibrator.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..1112f139c1d651bbac35169ab8174a4e5ad112e9 GIT binary patch literal 16384 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 Xrsdz%%w6p=x3kMt$u!&(vSR)Rl2fFX literal 0 HcmV?d00001 diff --git a/src/.VIPRCalculator.cpp.swo b/src/.VIPRCalculator.cpp.swo new file mode 100644 index 0000000000000000000000000000000000000000..9214cc0a3b12c31c7eaa83ad781873427a6cdb83 GIT binary patch literal 49152 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 literal 0 HcmV?d00001 diff --git a/src/.VIPRCalculator.cpp.swp b/src/.VIPRCalculator.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..d154624e860afdc925111dae08f1ecdfec9e9dc2 GIT binary patch literal 20480 zcmeI3Ym6k+U#Ox@Tv*cl`jtSZryRp3*YPzeZ z%Uj*mR8{ZpWP`{Dk`Do6M-d`HhzJB9g2;y`1|$?IQ5*pYA;O9v;6x!70!s))f&@YG zBmB;-y7lPCOs^fm2Y1VV_w;?7d+)jDoO{l>cXy6Iy!N2_nd-e3pYOM0#cf&%>_LY0LBPWdRsqNT} z%g_sh#=W(N*VZ?dY_HL$iyu@Qz21n)OpB%*cs+5TAGMC%|EBZz+Ec>pR!|IMh z=U-18n67oofhh;39GG%o%7G~drW}}ZV9J5lJqM!Rt=2EYh3`o?v6+0|H1Pes$!`-e zTpXx>P<-n8!Qw~fyFy+9M1FuUC*iFm&1!CpDlmr0x|0e!_ z;VqW+XW&o4$H5t*l~cn-~*ru-Uj~pR?B)C{2?F>Vzt1}fu9A3z*pX2S$_?l0H?um@E^BW z)_cKGa69-GiILBOYv2~}aS{<{!4dGU@KpG^1KtV#4nF@H_|+sgF(`0q!Vixq-0rSC zrLa57-Cpn79jB}crQbD5^}5?t?tA4<+ zylAmK^MZv(FKS^y9aohD2dUMR-RpUKDsber%oRuN+H7CL4+5tluV+-`E4LdtyMZ0C z%tqS|cAan%y5*K1KuAwkca-TWyK8%Up&Ql>DP;$aYPp^Vb=yNgn|lg|>IJE=zY_&^ zgOMj%O4DiCeJ`q~1VT+cqoR19lV5j&Eyr`hhTn6x z_Il3tj8wUl$uHe3DcbCJI{K;91-IMuujZ>xTBTBHK+p8Niq_*s^lUuaRPs4;M7e5S zgnt=vVD+K%YGm2NPPdNh&wvCFQzR627Dz6Zsn3Gso8)eJvJE zSA=1wuOHSGB`Q;t0eMNsxpA3k$hjd>o2>a98X>=(Zqv)gGp%M+EATsNW<-tH6;40} z|5ckc_}H^fsKi8tM*7v&So~u>8BmH5G*j(Tkto!#de!q&K}KA+fobQ=i+Eq7d>*W?YX?y5UzU#c%X%FV_Mm^(Y{of%%k4Oup4)IjFp*O#ck~Ujt-z6^3u>ks_5ZRIhh?ewbTET%4{$tHgq8ec?woSFZsgh?206cZ<>L5iPPqg6GbiSJXil_~ zxyi8>4|gL{BIcx7uV2xYeqR3_^JcL)o4EmVJ~XrQ5BS~PpXOa~dO8kvkx5prTUNH` zRw{T|nUQ(tn#%#ca&c{Id-c@X1LrqZMxEP6k7lGfwy9dJY79hd31f$0?2Gbe(h8x-V<6HXht{K)(9Y=ZTb zD+f-!we0NlcbREvB6_p4If~btb6srT1 zI<|)g+{b+m^id)e-qz-5=0;X zo8Sca8u9%XPzyTXz3A_W$gC7Au1a1c3gvVb4&w(!j;rZvm^fTqa zlmk-^yfzMSm?fTm6!bZ5N*r#npM7j`nbbjq|13eODO>XVFfM9qpWxWy1^z8oTmr3< z{b)D5B*U(rT3!kz z5=n-B&BF?HL;PH*Cm5P#Y2vww$OMQ<3kzSsPY$oL7p2lBi3!_Vxu)}C1WCI4P?B(q zteLZxlmBrLi9#vqMwV`+>vM#S7J9P%2%QktCuztevS+Y3q!{Un>%p zg|lim9u>bp7fTubOmf?b#cBaiMVMi0}f|i9;YXn zm&Zv4wR=u;8&`iwwvyx!t>RpaBx5|^?>x2|2|{Yj43j0%I|E5`yV$^w&^$S^MkvQTsop-mD{mR?PMlrc&|H(ANH zN7${iV4|CevpLDQ6Om1~B$-{u?#-(-$eL3-zVDHJGt*_o>=|}LX+uK@8mP!*F4fwy z*d=2hP6u|k(I!xqsD$KDoUxplQ%AI^m>a05ts(d34AH`@#pSS7eyEh-H~^fJ5na85F2 zlCLspPPC&(_EeHNBqDP(F)w1~(s2vPGHpnbD#I5JWjV;@%jA&Y%=z`@Q(G%BMT91t2+y`0Pw=a9GXDkHr6Xb2t5a@_?TB-@NbtV`BRcf&0Mi;8Vo$yWl?XEV24W z!NcI~;8%#%H$WM@0sI@W`g7oKz-Pf{fW+~i0#ASs01vpJ1%4150?!i5{{{F6_%QIm zDR3wF7BTxX;1l3Ja2I$pc!~J@W8gQz6W|)S0{S2VzX(o)cL2Hb|6y7~;9>9s;01X8Ctw{s&wGGxjCm9A+F}BFC#DwH&B&6zlDueNb8(c9EpFnjxREvq zX^U+fi{r&+n6tPUZg-X%%oB|X{of3C!=p^zVe*#Q;)nP(Igx`~9^B%)x`E>);o#jT zZR&RVow7P1B4U|&58K3yaa#P=eePvBk>vWo$Y{nFr? zxe@J8%ax(a%1aoM{B9ajnf{m(?FO44=6j#HB$qIm+m?6N2Ch~0v_?!b&P@zR zG;%fZq;)ueaOJO{lC(h12AI_l{*2l_%ha21NuS6A9(gbmvJ|<}8pTBDl?hdS{8EqC zNAhqc)DN{X^J7TTwB-h&L^a4t6XNoWOuvK6l-x8Pr*iUeD04`%Ej%dag6T&OR z#FJiGk?7M7>uK(8xs2tCn?z$p9n()BW`|5VRlLl}KkJ&y5g>UAjhI4CxXic*eP=>= zP)k#<1LOQ`G)?)d zV+ba2^aNflbBasUD?B6SX~IXoH@+I#)=Vt(Ql+<-7m%zmn}V!sf;~T&o7(otV@FB3 WpU^4yg=8Y(^SlD{QZJ*Rs72OWH@Q6=F1VCEe_3 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 literal 0 HcmV?d00001 diff --git a/src/VAnaSum.cpp b/src/VAnaSum.cpp index 0ed7dfbe5..61b9e5723 100644 --- a/src/VAnaSum.cpp +++ b/src/VAnaSum.cpp @@ -32,14 +32,7 @@ VAnaSum::VAnaSum( string i_datadir, unsigned int iAnalysisType ) check run mode */ -void VAnaSum::initialize( - string i_LongListFilename, - string i_ShortListFilename, - int i_singletel, - unsigned int iRunType, - string i_outfile, - int iRandomSeed, - string iRunParameterfile ) +void VAnaSum::initialize( string i_LongListFilename, string i_ShortListFilename, int i_singletel, unsigned int iRunType, string i_outfile, int iRandomSeed, string iRunParameterfile ) { char i_temp[2000]; char i_title[200]; diff --git a/src/VAnaSumRunParameter.cpp b/src/VAnaSumRunParameter.cpp index 48cd4988e..dec67cefd 100644 --- a/src/VAnaSumRunParameter.cpp +++ b/src/VAnaSumRunParameter.cpp @@ -730,7 +730,7 @@ int VAnaSumRunParameter::loadShortFileList( string i_listfilename, string iDataD { cout << " VAnaSumRunParameter::loadShortFileList error: file with list of runs not found : " << i_listfilename << endl; cout << "exiting..." << endl; - exit( EXIT_FAILURE ); + exit( -1 ); } string is_line; string temp; @@ -745,87 +745,84 @@ int VAnaSumRunParameter::loadShortFileList( string i_listfilename, string iDataD { istringstream is_stream( is_line ); is_stream >> temp; + cout << "RUN NUMBER " << temp << endl; i_sT.fRunOn = atoi( temp.c_str() ); i_sT.fRunOff = atoi( temp.c_str() ); - if( !bTotalAnalysisOnly ) + // open mscw file and read out telescope participating in analysis + temp = iDataDir + "/" + temp + ".mscw.root"; + TFile iF( temp.c_str(), "READ" ); + if( iF.IsZombie() ) { - // open mscw file and read out telescope participating in analysis - temp = iDataDir + "/" + temp + ".mscw.root"; - TFile iF( temp.c_str(), "READ" ); - if( iF.IsZombie() ) - { - cout << "VAnaSumRunParameter::loadShortFileList: error, data file not found: "; - cout << temp << endl; - exit( EXIT_FAILURE ); - } - VEvndispRunParameter* iPar = ( VEvndispRunParameter* )iF.Get( "runparameterV2" ); - if( !iPar ) - { - cout << "VAnaSumRunParameter::loadShortFileList: error, no run parameters found in: "; - cout << temp << endl; - exit( EXIT_FAILURE ); - } - char hTelToAna[200]; - for( unsigned int i = 0; i < iPar->fTelToAnalyze.size(); i++ ) - { - if( i == 0 ) - { - sprintf( hTelToAna, "%d", iPar->fTelToAnalyze[i] + 1 ); - } - else - { - string tmp_str = hTelToAna; - sprintf( hTelToAna, "%s%d", tmp_str.c_str(), iPar->fTelToAnalyze[i] + 1 ); - } - } - iF.Close(); - i_sT.fTelToAna = hTelToAna; - i_sT.fCutFile = fTMPL_CutFile; - i_sT.fSourceRadius = fTMPL_SourceRadius; - i_sT.fBackgroundModel = fTMPL_fBackgroundModel; - i_sT.fmaxradius = fTMPL_maxradius; - i_sT.fEffectiveAreaFile = fTMPL_EffectiveAreaFile; - if( i_sT.fTelToAna == "1234" ) - { - i_sT.fEffectiveAreaFile += ".root"; - } - else - { - i_sT.fEffectiveAreaFile += "_T" + i_sT.fTelToAna + ".root"; - } - i_sT.fAcceptanceFile = fTMPL_AcceptanceFile; - if( i_sT.fTelToAna == "1234" ) - { - i_sT.fAcceptanceFile += ".root"; - } - else - { - i_sT.fAcceptanceFile += "_T" + i_sT.fTelToAna + ".root"; - } - if( i_sT.fBackgroundModel == eRINGMODEL ) - { - i_sT.fRM_RingRadius = fTMPL_RM_RingRadius; - i_sT.fRM_RingWidth = fTMPL_RM_RingWidth; - } - else if( i_sT.fBackgroundModel == eREFLECTEDREGION ) + cout << "VAnaSumRunParameter::loadShortFileList: error, data file not found: "; + cout << temp << endl; + exit( -1 ); + } + VEvndispRunParameter* iPar = ( VEvndispRunParameter* )iF.Get( "runparameterV2" ); + if( !iPar ) + { + cout << "VAnaSumRunParameter::loadShortFileList: error, no run parameters found in: "; + cout << temp << endl; + exit( -1 ); + } + char hTelToAna[200]; + for( unsigned int i = 0; i < iPar->fTelToAnalyze.size(); i++ ) + { + if( i == 0 ) { - i_sT.fRE_distanceSourceOff = fTMPL_RE_distanceSourceOff; - i_sT.fRE_nMinoffsource = fTMPL_RE_nMinoffsource; - i_sT.fRE_nMaxoffsource = fTMPL_RE_nMaxoffsource; + sprintf( hTelToAna, "%d", iPar->fTelToAnalyze[i] + 1 ); } else { - cout << "VAnaSumRunParameter error: "; - cout << " unknown background model " << i_sT.fBackgroundModel << endl; - cout << "\t or" << endl; - cout << "VAnaSumRunParameter warning: "; - cout << " short runlist not implemented yet for this background model " << i_sT.fBackgroundModel << endl; + string tmp_str = hTelToAna; + sprintf( hTelToAna, "%s%d", tmp_str.c_str(), iPar->fTelToAnalyze[i] + 1 ); } - - i_sT.f2DAcceptanceMode = f2DAcceptanceMode ; // USE2DACCEPTANCE + } + iF.Close(); + i_sT.fTelToAna = hTelToAna; + i_sT.fCutFile = fTMPL_CutFile; + i_sT.fSourceRadius = fTMPL_SourceRadius; + i_sT.fBackgroundModel = fTMPL_fBackgroundModel; + i_sT.fmaxradius = fTMPL_maxradius; + i_sT.fEffectiveAreaFile = fTMPL_EffectiveAreaFile; + if( i_sT.fTelToAna == "1234" ) + { + i_sT.fEffectiveAreaFile += ".root"; + } + else + { + i_sT.fEffectiveAreaFile += "_T" + i_sT.fTelToAna + ".root"; + } + i_sT.fAcceptanceFile = fTMPL_AcceptanceFile; + if( i_sT.fTelToAna == "1234" ) + { + i_sT.fAcceptanceFile += ".root"; + } + else + { + i_sT.fAcceptanceFile += "_T" + i_sT.fTelToAna + ".root"; + } + if( i_sT.fBackgroundModel == eRINGMODEL ) + { + i_sT.fRM_RingRadius = fTMPL_RM_RingRadius; + i_sT.fRM_RingWidth = fTMPL_RM_RingWidth; + } + else if( i_sT.fBackgroundModel == eREFLECTEDREGION ) + { + i_sT.fRE_distanceSourceOff = fTMPL_RE_distanceSourceOff; + i_sT.fRE_nMinoffsource = fTMPL_RE_nMinoffsource; + i_sT.fRE_nMaxoffsource = fTMPL_RE_nMaxoffsource; + } + else + { + cout << "VAnaSumRunParameter error: "; + cout << " unknown background model " << i_sT.fBackgroundModel << endl; + cout << "\t or" << endl; + cout << "VAnaSumRunParameter warning: "; + cout << " short runlist not implemented yet for this background model " << i_sT.fBackgroundModel << endl; } // fill the runlist vector + i_sT.f2DAcceptanceMode = f2DAcceptanceMode ; // USE2DACCEPTANCE fRunList.push_back( i_sT ); // fill the runlist map fMapRunList[i_sT.fRunOn] = fRunList.back(); @@ -1018,7 +1015,7 @@ int VAnaSumRunParameter::loadLongFileList( string i_listfilename, bool bShortLis cout << "VAnaSumRunParameter::loadLongFileList: error in run list: " << endl; cout << is_line << endl; cout << "invalid maximum distance " << i_sT.fmaxradius << endl; - exit( EXIT_FAILURE ); + exit( -1 ); } } // file for effective areas @@ -1027,35 +1024,27 @@ int VAnaSumRunParameter::loadLongFileList( string i_listfilename, bool bShortLis // cuts are in the effective area files if( fVersion >= 7 ) { - if( i_sT.fEffectiveAreaFile.find( "IGNOREEFFECTIVEAREA" ) != string::npos ) + // check if IRF runparameters are consistent with ANASUM.runparameter file + checkAnasumParameter( i_sT.fEffectiveAreaFile ); + + i_sT.fCutFile = temp; + // source radius (actually (source radius)^2 ) + // (read theta2 cut from cut file) + if( !bTotalAnalysisOnly ) { - cout << "VAnaSumRunParameter::loadLongFileList warning: "; - cout << "ignore effective areas - cannot read cuts from effective area files" << endl; + readCutParameter( i_sT.fCutFile, i_sT.fSourceRadius, i_sT.fmaxradius ); } else { - // check if IRF runparameters are consistent with ANASUM.runparameter file - checkAnasumParameter( i_sT.fEffectiveAreaFile ); - - i_sT.fCutFile = temp; - // source radius (actually (source radius)^2 ) - // (read theta2 cut from cut file) - if( !bTotalAnalysisOnly ) - { - readCutParameter( i_sT.fCutFile, i_sT.fSourceRadius, i_sT.fmaxradius ); - } - else - { - i_sT.fSourceRadius = 0.1; - i_sT.fmaxradius = 2.0; - } - if( i_sT.fSourceRadius <= 0. ) - { - cout << "VAnaSumRunParameter::loadLongFileList: error in run list: " << endl; - cout << is_line << endl; - cout << "invalid source radius " << i_sT.fSourceRadius << endl; - exit( EXIT_FAILURE ); - } + i_sT.fSourceRadius = 0.1; + i_sT.fmaxradius = 2.0; + } + if( i_sT.fSourceRadius <= 0. ) + { + cout << "VAnaSumRunParameter::loadLongFileList: error in run list: " << endl; + cout << is_line << endl; + cout << "invalid source radius " << i_sT.fSourceRadius << endl; + exit( -1 ); } } // background model dependend parameters @@ -1099,7 +1088,7 @@ int VAnaSumRunParameter::loadLongFileList( string i_listfilename, bool bShortLis is_stream >> temp; i_sT.fTE_mscl_max = atof( temp.c_str() ); cout << "DO NOT USE " << endl; - exit( EXIT_SUCCESS ); + exit( 0 ); } else if( i_sT.fBackgroundModel == eONOFF ) { diff --git a/src/VCalibrationData.cpp b/src/VCalibrationData.cpp index 5f7d7ee5c..e10762d31 100644 --- a/src/VCalibrationData.cpp +++ b/src/VCalibrationData.cpp @@ -802,7 +802,7 @@ valarray& VCalibrationData::getPedvars( bool iLowGain, unsigned int iSW, cout << getPedvarsVTS_vector( iLowGain )[0].size(); } cout << endl; - exit( EXIT_FAILURE ); + exit( 0 ); } } ////////////////////////////////////////////////////////// @@ -1043,6 +1043,24 @@ TGraphErrors* VCalibrationData::getIPRGraph( unsigned int iSumWindow, bool iMake return 0; } +TGraphErrors* VCalibrationData::getIPRGraphTimeSlice( bool iMakeNewGraph, unsigned int TimeSlice ){ + + if( fGraphTSIPRGraph.find( TimeSlice) != fGraphTSIPRGraph.end() && fGraphTSIPRGraph[TimeSlice] ) + { + return fGraphTSIPRGraph[TimeSlice]; + } + else if( iMakeNewGraph ) + { + fGraphTSIPRGraph[TimeSlice] = new TGraphErrors( 1 ); + fGraphTSIPRGraph[TimeSlice]->SetTitle( "" ); + char hname[200]; + sprintf( hname, "IRPFGraph_TelID%d_TimeSlice%d", fTelID, TimeSlice ); + fGraphTSIPRGraph[TimeSlice]->SetName( hname ); + return fGraphTSIPRGraph[TimeSlice]; + } + return 0; +} + void VCalibrationData::setIPRGraph( unsigned int iSumWindow, TGraphErrors* g ) { fGraphIPRGraph[iSumWindow] = g; diff --git a/src/VCalibrator.cpp b/src/VCalibrator.cpp index 66bd82ad8..b4ba1f216 100644 --- a/src/VCalibrator.cpp +++ b/src/VCalibrator.cpp @@ -17,7 +17,6 @@ VCalibrator::VCalibrator() fPedSingleOutFile = 0; fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements - fIPRAverageTel = false; } /* @@ -359,7 +358,7 @@ void VCalibrator::calculatePedestals( bool iLowGain ) this might be an ascii file and/or a root file */ -void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile ) +void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile, VIPRCalculator *fIPRCalculator ) { if( getDebugFlag() ) { @@ -507,6 +506,18 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul } } } + for (unsigned int ts = 0; ts < (fIPRCalculator->getStorageHist())[tel].size(); ts++){ + for (unsigned int p = 0; p < getNChannels(); p++){ + for(unsigned int sw = 0; sw < (fIPRCalculator->getStorageHist())[tel][ts][p].size(); sw++) + { + if (fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw) ){ + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetName(Form( "hped_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw ) ); + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetTitle( Form("hped_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw ) ); + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->Write(); + } + } + } + } } iFileWritten[telType] = true; } @@ -546,6 +557,8 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul /////////////////////////////////////////////////////////////////// // calculate IPR graphs already at this point and write them to // the dst calibration file + // MK: adapt later + /* if( getRunParameter()->fCombineChannelsForPedestalCalculation && getRunParameter()->fPedestalSingleRootFile ) { @@ -578,14 +591,14 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul { // summation window int i_sw = j + 1; - + cout << "I am actually calculating this IPR" << endl; calculateIPRGraphs( fPedSingleOutFile->GetName(), i_sw, iTelType, i ); iTelDone[getTelType( i )] = true; } } } writeIPRgraphs( fPedSingleOutFile->GetName() ); - } + }*/ } @@ -1589,11 +1602,12 @@ void VCalibrator::writeTOffsets( bool iLowGain ) } -void VCalibrator::terminate( VPedestalCalculator* iP ) +void VCalibrator::terminate( VPedestalCalculator* iP, VIPRCalculator *fIPRCalculator ) { + if( fRunPar->frunmode == 1 || fRunPar->frunmode == 6 ) { - writePeds( fRunPar->frunmode == 6, iP, !fRunPar->fPedestalSingleRootFile ); + writePeds( fRunPar->frunmode == 6, iP, !fRunPar->fPedestalSingleRootFile, fIPRCalculator ); } else if( fRunPar->frunmode == 2 || fRunPar->frunmode == 5 ) { @@ -1604,6 +1618,7 @@ void VCalibrator::terminate( VPedestalCalculator* iP ) { writeAverageTZeros( fRunPar->frunmode == 8 ); } + } @@ -1639,6 +1654,9 @@ void VCalibrator::readCalibrationData() getGains( true ) = getGains( false ); } } + else{ + + } // read average tzeros if( getRunParameter()->frunmode != 2 && getRunParameter()->frunmode != 5 @@ -3091,7 +3109,7 @@ void VCalibrator::readTOffsets( bool iLowGain ) } -void VCalibrator::initialize() +void VCalibrator::initialize(VIPRCalculator *fIPRCalculator ) { if( fDebug ) { @@ -3201,6 +3219,8 @@ void VCalibrator::initialize() { readCalibrationData(); } + else{ + } } // PE mode: set gains to 1 else @@ -3213,15 +3233,16 @@ void VCalibrator::initialize() readGains( true ); } // read peds from DST file (for DST MC source file) - if( fRunPar->frunmode != 1 && ( fRunPar->fsourcetype == 7 || fRunPar->fsourcetype == 4 ) ) + // MK take a look later + /*if( fRunPar->frunmode != 1 && ( fRunPar->fsourcetype == 7 || fRunPar->fsourcetype == 4 ) ) { - readCalibrationDatafromDSTFiles( fRunPar->fsourcefile ); - } + readCalibrationDatafromDSTFiles( fRunPar->fsourcefile, fIPRCalculator ); + }*/ } // if needed: write IPR graphs to disk if( getRunParameter()->ifCreateIPRdatabase == true && getRunParameter()->ifReadIPRfromDatabase == false ) { - writeIPRgraphs(); + fIPRCalculator->writeIPRgraphs( hped_vec, ""); } // initialize dead channel finder @@ -3237,11 +3258,20 @@ void VCalibrator::initialize() && fRunPar->frunmode != 1 && fRunPar->frunmode != 6 ) { - calculateIPRGraphs(); + cout << "MK calculating IPR graphs"<< endl; + fIPRCalculator->calculateIPRGraphs(fPedFileNameC); } } } + +//void VCalibrator::calculateIPRGraphs(VIPRCalculator *fIPRCalculator, VPedestalCalculator *iP ) +//{ +// cout << "MK calculating IPR" << endl; +// fIPRCalculator->calculateIPRGraphs(fPedFileNameC, iP->getPedestalIPRHist()); +//} + + void VCalibrator::setCalibrationFileNames() { if( fDebug ) @@ -3979,559 +4009,49 @@ bool VCalibrator::readLowGainMultiplier( ) return true; } - -/* - - read calibration data from DST file - -*/ -bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) -{ - if( iDSTfile.size() == 0 ) - { - cout << "VCalibrator::readCalibrationDatafromDSTFiles: no DST file given" << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } - - TFile iF( iDSTfile.c_str() ); - if( iF.IsZombie() ) - { - cout << "VCalibrator::readCalibrationDatafromDSTFiles error while opening DST tree in " << iDSTfile << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } - TTree* t = ( TTree* )iF.Get( "calibration" ); - if( !t ) - { - cout << "VCalibrator::readCalibrationDatafromDSTFiles warning: failed reading calibration tree from file " << iDSTfile << endl; - return false; - } - cout << "reading calibration data from dst file" << endl; - - int fTelID = 0; - unsigned int nPixel = 0; - unsigned int fnum_sumwindow = 1; - unsigned int fsumwindow[VDST_MAXSUMWINDOW]; - float fPed_high[VDST_MAXCHANNELS]; - float* fPedvar_high = new float[VDST_MAXCHANNELS * VDST_MAXSUMWINDOW]; - float fPed_low[VDST_MAXCHANNELS]; - float* fPedvar_low = new float[VDST_MAXCHANNELS * VDST_MAXSUMWINDOW]; - float fConv_high[VDST_MAXCHANNELS]; - float fConv_low[VDST_MAXCHANNELS]; - float ftzero[VDST_MAXCHANNELS]; - - for( unsigned int i = 0; i < VDST_MAXCHANNELS; i++ ) - { - ftzero[i] = -99.; - } - - t->SetBranchAddress( "TelID", &fTelID ); - t->SetBranchAddress( "NPixel", &nPixel ); - t->SetBranchAddress( "num_sumwindow", &fnum_sumwindow ); - t->SetBranchAddress( "sumwindow", fsumwindow ); - t->SetBranchAddress( "ped_high", fPed_high ); - // check if this is a old or new style pedvar tree - bool iPedVarTreeTypeNew = true; - if( t->GetLeaf( "pedvar_high" ) ) - { - string i_temp = ( string )t->GetLeaf( "pedvar_high" )->GetTitle(); - if( i_temp.find_first_of( "[" ) == i_temp.find_last_of( "[" ) ) - { - iPedVarTreeTypeNew = true; - } - else - { - iPedVarTreeTypeNew = false; - } - } - if( !iPedVarTreeTypeNew ) - { - cout << "VCalibrator::readCalibrationDatafromDSTFiles: old style DST file: warning: pedvars will not be set correctly" << endl; - cout << " (you might be able to proceed if you don't do FADC trace analysis and use the pedvars for the image cleaning" << endl; - } - t->SetBranchAddress( "pedvar_high", fPedvar_high ); - t->SetBranchAddress( "ped_low", fPed_low ); - t->SetBranchAddress( "pedvar_low", fPedvar_low ); - t->SetBranchAddress( "conv_high", fConv_high ); - t->SetBranchAddress( "conv_low", fConv_low ); - if( t->GetBranch( "tzero" ) ) - { - t->SetBranchAddress( "tzero", ftzero ); - } - - // reset histograms with pedestal distributions - if( getPedvarsDist() ) - { - getPedvarsDist()->Reset(); - } - if( getPedDist() ) - { - getPedDist()->Reset(); - } - if( getPedvarsLowGainDist() ) - { - getPedvarsLowGainDist()->Reset(); - } - if( getPedLowGainDist() ) - { - getPedLowGainDist()->Reset(); - } - - // histogram for average tzero calculation (per telescope type) - vector iTelType = getDetectorGeometry()->getTelType_list(); - vector< TH1D* > iH_averageTZero; - char hname[200]; - for( unsigned int i = 0; i < iTelType.size(); i++ ) - { - sprintf( hname, "iH_averageTZero_%d", i ); - iH_averageTZero.push_back( new TH1D( hname, "", 3 * ( int )getNSamples(), 0., ( float )getNSamples() ) ); - } - - if( getNTel() != ( unsigned int )t->GetEntries() ) - { - cout << "VCalibrator::readCalibrationDatafromDSTFiles error: mismatch in number of telescopes: " << endl; - cout << "\t expected: " << getNTel() << endl; - cout << "\t found: " << t->GetEntries() << endl; - exit( EXIT_FAILURE ); - } - // loop over all telescopes - for( int i = 0; i < t->GetEntries(); i++ ) - { - t->GetEntry( i ); - - setTelID( i ); - - // no calibration data available for this telescope - if( nPixel == 0 ) - { - continue; - } - - // pedestals - if( nPixel == getPeds( false ).size() ) - { - for( unsigned int p = 0; p < nPixel; p++ ) - { - getPeds( false )[p] = fPed_high[p]; - if( getPedDist() ) - { - getPedDist()->Fill( fPed_high[p] ); - } - } - } - else - { - cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile )"; - cout << " error: index out of range (peds, high gain): "; - cout << nPixel << "\t" << getPeds( false ).size(); - cout << " (telescope " << getTelID() + 1 << ")" << endl; - } - if( nPixel == getPeds( true ).size() ) - { - for( unsigned int p = 0; p < nPixel; p++ ) - { - getPeds( true )[p] = fPed_low[p]; - if( getPedLowGainDist() ) - { - getPedLowGainDist()->Fill( fPed_low[p] ); - } - } - } - else - { - cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile )"; - cout << "error: index out of range (peds, low gain): "; - cout << nPixel << "\t" << getPeds( true ).size(); - cout << " (telescope " << getTelID() + 1 << ")" << endl; - } - // pedvars - if( nPixel == getPedvars( false ).size() ) - { - for( unsigned int p = 0; p < nPixel; p++ ) - { - if( p < getPedvars( false ).size() ) - { - for( unsigned int s = 0; s < fnum_sumwindow; s++ ) - { - if( iPedVarTreeTypeNew ) - { - getPedvars( false, fsumwindow[s] )[p] = fPedvar_high[p * VDST_MAXSUMWINDOW + s]; - if( fsumwindow[s] == 1 ) - { - getPedrms( false ) = fPedvar_high[p * VDST_MAXSUMWINDOW + s]; - } - } - if( fsumwindow[s] == getSumWindow() && getPedvarsDist() ) - { - if( iPedVarTreeTypeNew ) - { - getPedvarsDist()->Fill( fPedvar_high[p * VDST_MAXSUMWINDOW + s] ); - } - } - } - } - } - } - else - { - cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; - cout << "index out of range (pedvars, high gain): "; - cout << nPixel << "\t" << getPedvars( false ).size(); - cout << " (telescope " << getTelID() + 1 << ")" << endl; - } - if( nPixel == getPedvars( true ).size() ) - { - for( unsigned int p = 0; p < nPixel; p++ ) - { - if( p < getPedvars( true ).size() ) - { - for( unsigned int s = 0; s < fnum_sumwindow; s++ ) - { - if( iPedVarTreeTypeNew ) - { - getPedvars( true, fsumwindow[s] )[p] = fPedvar_low[p * VDST_MAXSUMWINDOW + s]; - if( fsumwindow[s] == 1 ) - { - getPedrms( true ) = fPedvar_low[p * VDST_MAXSUMWINDOW + s]; - } - } - if( fsumwindow[s] == getSumWindow() && getPedvarsDist( true ) ) - { - if( iPedVarTreeTypeNew ) - { - getPedvarsDist( true )->Fill( fPedvar_low[p * VDST_MAXSUMWINDOW + s] ); - } - } - } - } - } - } - else - { - cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; - cout << "index out of range (pedvars, low gain): "; - cout << nPixel << "\t" << getPedvars( true ).size(); - cout << " (telescope " << getTelID() + 1 << ")" << endl; - } - //////////////// - // relative gains - if( nPixel == getGains( false ).size() ) - { - // mean conversion factor - float i_z = 0; - float i_meanC = 0; - for( unsigned int p = 0; p < nPixel; p++ ) - { - if( fConv_high[p] > 0. ) - { - i_z++; - i_meanC += fConv_high[p]; - } - } - if( i_z > 0. && i_meanC > 0. ) - { - i_meanC /= i_z; - } - else - { - i_meanC = 1.; - } - // calculate relative gain - for( unsigned int p = 0; p < nPixel; p++ ) - { - if( fConv_high[p] > 0. && !getRunParameter()->fIgnoreDSTGains ) - { - getGains( false )[p] = 1. / fConv_high[p]; - if( getGainDist( false ) ) - { - getGainDist( false )->Fill( i_meanC / fConv_high[p] ); - } - } - else - { - getGains( false )[p] = 1.; - } - } - } - else - { - cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; - cout << "index out of range (gains, high gain): "; - cout << nPixel << "\t" << getGains( false ).size(); - cout << " (telescope " << getTelID() + 1 << ")" << endl; - } - if( nPixel == getGains( true ).size() ) - { - // use high-gain conversion and understand differences between low and high gain as multiplication factor - for( unsigned int p = 0; p < nPixel; p++ ) - { - if( getGains( false )[p] > 0. && !getRunParameter()->fIgnoreDSTGains ) - { - getGains( true )[p] = getGains( false )[p]; - if( getGainDist( true ) ) - { - getGainDist( true )->Fill( getGains( true )[p] ); - } - setLowGainMultiplier_Trace( fConv_low[p] / fConv_high[p] ); //assumes fConv_low / fConv_high is the same for all pixels. Ok as long as we don't have low gain in cta. - } - else - { - getGains( true )[p] = 1.; - } - } - } - else - { - cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; - cout << "index out of range (gains, low gain): "; - cout << nPixel << "\t" << getGains( true ).size(); - cout << " (telescope " << getTelID() + 1 << ")" << endl; - } - //////////////// - // tzeros - if( nPixel == getAverageTZeros( false ).size() ) - { - double i_mean = 0.; - double i_nn = 0.; - // get teltype counter - unsigned int iTelTypeC = 0; - for( unsigned int t = 0; t < iTelType.size(); t++ ) - { - if( iTelType[t] == getDetectorGeometry()->getTelType()[i] ) - { - iTelTypeC = t; - break; - } - } - for( unsigned int p = 0; p < nPixel; p++ ) - { - getAverageTZeros( false )[p] = ftzero[p]; - // check if this pixel is inside the averateTZeroFiducialRadius - if( getRunParameter()->faverageTZeroFiducialRadius < 1. ) - { - double d = getDetectorGeometry()->getOuterEdgeDistance( p ); - if( d > 0.5 * getDetectorGeometry()->getFieldofView()[i] * getRunParameter()->faverageTZeroFiducialRadius ) - { - continue; - } - } - if( getAverageTZeros( false )[p] > -98. ) - { - i_mean += ftzero[p]; - i_nn++; - setAverageTZero( p, ftzero[p], false ); - if( iTelTypeC < iH_averageTZero.size() && iH_averageTZero[iTelTypeC] ) - { - iH_averageTZero[iTelTypeC]->Fill( ftzero[p] ); - } - } - } - } - else - { - cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; - cout << " index out of range (tzero, high gain): "; - cout << nPixel << "\t" << getAverageTZeros( false ).size(); - cout << " (telescope " << getTelID() + 1 << ")" << endl; - } - } - - //////////////////////////////////////////////////////////////////////////// - // get average tzero per telescope type - // use median, as outliers are expected - cout << "\t calculate average tzeros" << endl; - for( int i = 0; i < t->GetEntries(); i++ ) - { - t->GetEntry( i ); - - setTelID( i ); - - // no calibration data available for this telescope - if( nPixel == 0 ) - { - continue; - } - // get teltype counter - unsigned int iTelTypeC = 0; - for( unsigned int t = 0; t < iTelType.size(); t++ ) - { - if( iTelType[t] == getDetectorGeometry()->getTelType()[i] ) - { - iTelTypeC = t; - break; - } - } - if( iTelTypeC < iH_averageTZero.size() && iH_averageTZero[iTelTypeC] ) - { - if( iH_averageTZero[iTelTypeC]->GetEntries() > 0. ) - { - double i_a[] = { 0.5 }; - double i_b[] = { 0.0 }; - iH_averageTZero[iTelTypeC]->GetQuantiles( 1, i_b, i_a ); - setMeanAverageTZero( i_b[0], false ); - } - } - } - - //////////////////////////////////////////////////////////////////////////// - // read IPR graph from dst root file (for direct usage or creation of database ) - if( getRunParameter()->ifReadIPRfromDSTFile == true ) - { - cout << "\t reading IPR graphs for NN image cleaning from DST file" << endl; - for( int i = 0; i < t->GetEntries(); i++ ) - { - setTelID( i ); - readIPRGraph_from_DSTFile( iDSTfile, getSumWindow(), getTelType( i ) ); - } - } - else if( getRunParameter()->ifReadIPRfromDatabase == true || getRunParameter()->ifCreateIPRdatabase == true ) - { - cout << "\t reading IPR graphs for NN image cleaning" << endl; - for( int i = 0; i < t->GetEntries(); i++ ) - { - setTelID( i ); - calculateIPRGraphs( iDSTfile, getSumWindow(), getTelType( i ), i ); - } - } - else if( getRunParameter()->fIPRdatabase.Length() > 0 ) - { - cout << "\t IPR graphs for NN cleaning will be read from external database: "; - cout << getRunParameter()->fIPRdatabase << endl; - } - - iF.Close(); - return true; -} - -/* - * - * write IPR graphs to disk (one per telescope type) - * - */ -bool VCalibrator::writeIPRgraphs( string iFile ) -{ - TFile* fgraphs = 0; - if( iFile.size() == 0 ) - { - fgraphs = new TFile( getRunParameter()->fIPRdatabaseFile, "RECREATE" ); - } - else - { - fgraphs = new TFile( iFile.c_str(), "UPDATE" ); - } - if( fgraphs->IsZombie() ) - { - cout << "VCalibrator::writeIPRgraphs error opening IPR output file: " << endl; - cout << "\t" << fgraphs->GetName() << endl; - return false; - } - - // tree with conditions for these IRPs - TTree* header = new TTree( "IPRheader", "IPR parameters" ); - unsigned int sumwin = 0; // [FADC slices] - unsigned int Nsamples = 0; // [FADC slices] - float ROwin = 0.; // [ns] - float FADCslice = 0.; // [ns] - unsigned int SignalExtractor = 0; // [ Selected Extractor ] - header->Branch( "SignalExtractor", &SignalExtractor, "SignalExtractor/i" ); - header->Branch( "SummationWindow", &sumwin, "SummationWindow/i" ); - header->Branch( "Nsamples", &Nsamples, "Nsamples/i" ); - header->Branch( "FADCtimeSlice", &FADCslice, "FADCtimeSlice/F" ); - header->Branch( "ReadoutWindow", &ROwin, "ReadoutWindow/F" ); - - // one graph per telescope ID - map< ULong64_t, bool > iTelDone; - for( unsigned int i = 0; i < getDetectorGeometry()->getTelType_list().size(); i++ ) - { - iTelDone[getDetectorGeometry()->getTelType_list()[i]] = false; - } - - for( unsigned int i = 0; i < getNTel(); i++ ) - { - setTelID( i ); - if( iTelDone[getTelType( i )] ) - { - continue; - } - - if( hped_vec.find( getTelType( i ) ) == hped_vec.end() ) - { - continue; - } - - // loop over all summation windows - for( unsigned int j = 0; j < hped_vec[getTelType( i )].size(); j++ ) - { - // summation window - int i_sw = j + 1; - - TGraphErrors* g = getIPRGraph( i_sw, false ); - if( !g ) - { - continue; - } - SignalExtractor = getRunParameter()->fTraceIntegrationMethod.at( getTelID() ); - sumwin = i_sw; - Nsamples = getNSamples(); - FADCslice = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); //[ns] - ROwin = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * ( float )getNSamples(); // [ns] - - header->Fill(); - g->Write(); - } - - iTelDone[getTelType( i )] = true; - } - header->Write(); - fgraphs->Close(); - fgraphs->Delete(); - - return true; -} - unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( int iTelID, int iType ) { - if( iType == 1 || iType == 6 ) - { - return getNumberOfEventsUsedInCalibration( fNumberPedestalEvents, iTelID ); - } - else if( iType == 2 || iType == 5 ) - { - return getNumberOfEventsUsedInCalibration( fNumberGainEvents, iTelID ); - } - else if( iType == 7 || iType == 8 ) - { - return getNumberOfEventsUsedInCalibration( fNumberTZeroEvents, iTelID ); - } - return 0; + if( iType == 1 || iType == 6 ) + { + return getNumberOfEventsUsedInCalibration( fNumberPedestalEvents, iTelID ); + } + else if( iType == 2 || iType == 5 ) + { + return getNumberOfEventsUsedInCalibration( fNumberGainEvents, iTelID ); + } + else if( iType == 7 || iType == 8 ) + { + return getNumberOfEventsUsedInCalibration( fNumberTZeroEvents, iTelID ); + } + return 0; } + unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( vector< int > iE, int iTelID ) -{ - if( iTelID > 0 && iTelID < ( int )iE.size() ) - { - return iE[iTelID]; - } - else - { - int iTot = 0; - int iN = 0; - for( unsigned int tel = 0; tel < getTeltoAna().size(); tel++ ) - { - if( tel < iE.size() ) - { - iTot += iE[tel]; - iN++; - } - } - if( iN > 0 ) - { - return iTot / iN; - } - } - - return 0; +{ + if( iTelID > 0 && iTelID < ( int )iE.size() ) + { + return iE[iTelID]; + } + else + { + int iTot = 0; + int iN = 0; + for( unsigned int tel = 0; tel < getTeltoAna().size(); tel++ ) + { + if( tel < iE.size() ) + { + iTot += iE[tel]; + iN++; + } + } + if( iN > 0 ) + { + return iTot / iN; + } + } + + return 0; } unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( map< ULong64_t, int > iE, int iTelID ) @@ -4569,451 +4089,11 @@ unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( map< ULong64_t, in return 0; } -/* - * calculate IPR graphs and write them to disk - * - * (loop over all telescopes) - * -*/ -bool VCalibrator::calculateIPRGraphs() -{ - for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) - { - setTelID( getTeltoAna()[i] ); - - // first find dead channels - // (ignore low gains here) - findDeadChans( false ); - // calculate IPR graphs - if( fIPRAverageTel == false ) - { - calculateIPRGraphs( fPedFileNameC[getTeltoAna()[i]], getSumWindow(), getTelType( getTeltoAna()[i] ), i ); - } - else - { - copyIPRTelAveraged( getSumWindow(), getTeltoAna()[i], i ); - } - } - return true; -} /* - * calculate IPR graphs and write them to disk - * - * (this is done per telescope type) - * + * Unecessary for veritas? Probably remove! */ -bool VCalibrator::copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) -{ - - TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); - - setTelID( getTeltoAna()[0] ); - TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); - - setTelID( getTeltoAna()[i_tel] ); - - if( !i_IPRGraph ) - { - cout << "VCalibrator::copyIPRTelAveraged: no IPR graph found for telescope type " << iTelType << endl; - return false; - } - if( !i_IPRGraph_Tel0 ) - { - cout << "VCalibrator::copyIPRTelAveraged: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; - return false; - } - - for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) - { - i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); - } - - i_IPRGraph->SetMinimum( 1 ); - i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); - i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); - i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); - i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); - - return true; - -} - -bool VCalibrator::calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) -{ - TH1F* hIPR = ( TH1F* )initializeIPRAveraged( iSummationWindow, getTeltoAna()[i_tel] ); - TDirectory* iG_CurrentDirectory = gDirectory; - - // get an IPR graph - TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); - if( !i_IPRGraph ) - { - cout << "VCalibrator::calculateIPRGraphs info: no IPR graph found for telescope type " << iTelType << endl; - return false; - } - // check suffix of ped file - if( iPedFileName.find( ".root" ) == string::npos ) - { - iPedFileName += ".root"; - } - // open pedestal files - TFile iPedFile( iPedFileName.c_str() ); - if( iPedFile.IsZombie() ) - { - cout << "VCalibrator::calculateIPRGraphs error reading IPR graphs from "; - cout << iPedFileName << endl; - return false; - } - // histograms with IPR distributions are either - // i) in a directory called distributions_TelType - // ii) in the current directory - cout << "Telescope type " << iTelType << ": "; - cout << "reading IPR histograms for summation window " << iSummationWindow; - cout << " from "; - cout << iPedFileName << endl; - - stringstream i_Directory( stringstream::in | stringstream::out ); - i_Directory << "distributions_" << iTelType; - if( iPedFile.Get( i_Directory.str().c_str() ) ) - { - iPedFile.cd( i_Directory.str().c_str() ); - } - - hIPR->Reset(); - - ////////////////////////////////////////////////// - // average over all channels in one telescope - float i_gainCorrect = 1.; - for( unsigned int i = 0; i < getNChannels(); i++ ) - { - if( getDetectorGeometry()->getAnaPixel()[i] > 0 - && i < getDead().size() && !getDead()[i] ) - { - stringstream i_Hname( stringstream::in | stringstream::out ); - i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; - TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); - - if( h ) - { - float ped = 0; - // default: pedestals are subtracted here - // (for combined channel analysis: charges are filled already pedestal subtracted) - // apply relative gain correction to integrated charges - if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) - { - ped = getPeds()[i]; - } - // special treatment for ASTRI telescopes - else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) - { - stringstream i_Pname( stringstream::in | stringstream::out ); - i_Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; - TH1F* hP = ( TH1F* )gDirectory->Get( i_Pname.str().c_str() ); - if( hP ) - { - ped = hP->GetMean(); - } - } - for( int j = 1; j <= h->GetNbinsX(); j++ ) - { - if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) - { - i_gainCorrect = getGains()[i]; - if( getHIGHQE_gainfactor( i ) > 0. ) - { - i_gainCorrect *= getHIGHQE_gainfactor( i ); - } - if( i_gainCorrect > 0. ) - { - hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); - } - } - } - } - } - } - - int z = 0; - float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); - if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts - { - fIPRAverageTel = true; - cout << "Telescope " << iTelType << ": "; - cout << "VCalibrator::calculateIPRGraphs WARNING: too few statistics to measure IPR curves "; - cout << "(total counts available: " << norm << ", "; - cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; - cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; - cout << "VCalibrator::calculateIPRGraphs(): fIPRAverageTel = " << fIPRAverageTel << endl; - hIPR = calculateIPRGraphAveraged( iSummationWindow ); - cout << "VCalibrator::calculateIPRGraphs norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; - } - if( norm == 0 ) - { - cout << "VCalibrator::calculateIPRGraphs ERROR: no counts in IPR histogram !" << endl; - return false; - } - // convert to Rate - float nsToSec = 1E-9; - float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); - if( getSearchWindowLast() < getNSamples() ) - { - Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] - } - else - { - Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] - } - float convToHz = 1.; - if( nsToSec > 0. && Tsearch > 0. ) - { - convToHz /= ( nsToSec * Tsearch ); - } - else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice - && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 - && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) - { - // simple peak sensing: sim_telarray uses the maximum bin only - // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file - // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as - // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns - // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. - convToHz /= ( nsToSec - * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice - * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); - } - - for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) - { - if( hIPR->GetBinContent( i ) > 5 ) - { - double val = convToHz * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; - double valerr = convToHz * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; - double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); - double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); - - i_IPRGraph->SetPoint( z, charge_pe, val ); - i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); - z++; - } - } - - i_IPRGraph->SetMinimum( 1 ); - i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", Tsearch, - getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); - if( getRunParameter()->fIgnoreDSTGains ) - { - i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); - } - else - { - i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); - } - i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); - i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); - hIPR->Delete(); - - iPedFile.Close(); - - iG_CurrentDirectory->cd(); - - return true; -} - -TH1F* VCalibrator::initializeIPRAveraged( unsigned int iSummationWindow, unsigned int iTelType ) -{ - //get reference hpedPerTelescopeType for channel 1 - cout << "VCalibrator::initializeIPRAveraged initializing IPR graph for calculation of average of telescopes." << endl; - TH1F* hIPR = 0; - - - int TelType = getTelType( iTelType ); - string PedFile_name = fPedFileNameC[iTelType]; - - // check suffix of ped file - if( PedFile_name.find( ".root" ) == string::npos ) - { - PedFile_name += ".root"; - } - // open pedestal files - TFile PedFile( PedFile_name.c_str() ); - - if( PedFile.IsZombie() ) - { - cout << "VCalibrator::calculateIPRGraphsStatistics: error reading IPR graphs from "; - cout << PedFile_name << endl; - return hIPR; - } - - // histograms with IPR distributions are either - // i) in a directory called distributions_TelType - // ii) in the current directory - cout << "Telescope type " << TelType << ": "; - cout << "reading IPR histograms for summation window " << iSummationWindow; - cout << " from "; - cout << PedFile_name << endl; - - stringstream Directory( stringstream::in | stringstream::out ); - Directory << "distributions_" << TelType; - if( !PedFile.Get( Directory.str().c_str() ) ) - { - return hIPR; - } - - // get charge distribution for first channel as reference histogram - stringstream hIPRname( stringstream::in | stringstream::out ); - hIPRname << "distributions_" << TelType << "/hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << 1; - - //? - TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); - PedFile.Close(); - - if( !href ) - { - cout << " Error: cannot find IPR histogram " << hIPRname.str().c_str(); - cout << " in file:" << PedFile_name << " ... exiting " << endl; - return hIPR; - } - - - //summary histogram - if( getRunParameter()->fIgnoreDSTGains ) - { - // work in dc - hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); - cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; - return hIPR; - } - else - { - // work in pe - hIPR = new TH1F( "", "", 1000, 0., 100. ); - return hIPR; - } -} - -TH1F* VCalibrator::calculateIPRGraphAveraged( unsigned int iSummationWindow ) -{ - - TH1F* hIPR = ( TH1F* )initializeIPRAveraged( iSummationWindow, getTeltoAna()[0] ); - - for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) - { - setTelID( getTeltoAna()[teltype] ); - - // first find dead channels - // (ignore low gains here) - findDeadChans( false ); - // calculate IPR graphs - string PedFile_name = fPedFileNameC[getTeltoAna()[teltype]]; - int TelType = getTelType( getTeltoAna()[teltype] ); - - if( PedFile_name.find( ".root" ) == string::npos ) - { - PedFile_name += ".root"; - } - // open pedestal files - TFile PedFile( PedFile_name.c_str() ); - if( PedFile.IsZombie() ) - { - cout << "VCalibrator::calculateIPRGraphAveraged error reading IPR graphs from "; - cout << PedFile_name << endl; - TH1F* hNull = 0; - return hNull; - } - // histograms with IPR distributions are either - // i) in a directory called distributions_TelType - // ii) in the current directory - cout << "VCalibrator::calculateIPRGraphAveraged Telescope type " << TelType << ": "; - cout << "reading IPR histograms for summation window " << iSummationWindow; - cout << " from "; - cout << PedFile_name << endl; - stringstream Directory( stringstream::in | stringstream::out ); - Directory.str( std::string() ); - Directory << "distributions_" << TelType; - cout << Directory.str().c_str() << endl; - if( PedFile.Get( Directory.str().c_str() ) ) - { - PedFile.cd( Directory.str().c_str() ); - } - else - { - cout << "VCalibrator::calculateIPRGraphAveraged no directory: " << Directory.str().c_str() << endl; - } - - /////////////////////////// - // average over all channels in one telescope - float i_gainCorrect = 1.; - for( unsigned int i = 0; i < getNChannels(); i++ ) - { - if( getDetectorGeometry()->getAnaPixel()[i] > 0 - && i < getDead().size() && !getDead()[i] ) - { - stringstream HistName( stringstream::in | stringstream::out ); - HistName << "hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << i; - TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); - - - if( h ) - { - float ped = 0; - // default: pedestals are subtracted here - // (for combined channel analysis: charges are filled already pedestal subtracted) - // apply relative gain correction to integrated charges - if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) - { - ped = getPeds()[i]; - } - // special treatment for ASTRI telescopes - else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) - { - stringstream Pname( stringstream::in | stringstream::out ); - Pname << "hped_" << TelType << "_" << iSummationWindow << "_" << i; - TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); - if( hP ) - { - ped = hP->GetMean(); - } - } - for( int j = 1; j <= h->GetNbinsX(); j++ ) - { - if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) - { - i_gainCorrect = getGains()[i]; - if( getHIGHQE_gainfactor( i ) > 0. ) - { - i_gainCorrect *= getHIGHQE_gainfactor( i ); - } - if( i_gainCorrect > 0. ) - { - hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); - } - } - } - } - } - } - PedFile.Close(); - - } - hIPR->Scale( 1. / getTeltoAna().size() ); - float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); - cout << "VCalibrator::calculateIPRGraphAveraged normalization of average IPR histogram " << norm; - cout << ". Returning IPR histogram." << endl; - if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts - { - cout << "VCalibrator::calculateIPRGraphAveraged WARNING: there is NOT enough statistics "; - cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; - return hIPR; - } - else - { - cout << "VCalibrator::calculateIPRGraphsStatistics: there is enough statistics to average over telescopes. " << endl; - return hIPR; - } -} - - bool VCalibrator::readIPRGraph_from_DSTFile( string iDSTFile, unsigned int iSummationWindow, ULong64_t iTelType ) { TDirectory* iG_CurrentDirectory = gDirectory; diff --git a/src/VDataMCComparision.cpp b/src/VDataMCComparision.cpp index 8876f84d9..33a6996ad 100644 --- a/src/VDataMCComparision.cpp +++ b/src/VDataMCComparision.cpp @@ -9,8 +9,7 @@ #include "VDataMCComparision.h" -VDataMCComparisionHistogramData::VDataMCComparisionHistogramData( - string iName, string iHistogramType, unsigned int iTelescopeID ) +VDataMCComparisionHistogramData::VDataMCComparisionHistogramData( string iName, string iHistogramType, unsigned int iTelescopeID ) { fVarName = iName; fHistogramType = iHistogramType; @@ -92,9 +91,7 @@ bool VDataMCComparisionHistogramData::initHistogram( string iXTitle, int iNbins, * fill comparison histograms as function of energy, ntubes, size, sizeHG, sizeLG * */ -void VDataMCComparisionHistogramData::fill( - double iV, double iWeight, double iLogEnergy_TeV, - int i_ntubes, double i_size, double i_fracLow ) +void VDataMCComparisionHistogramData::fill( double iV, double iWeight, double iLogEnergy_TeV, int i_ntubes, double i_size, double i_fracLow ) { if( fHis1D ) { @@ -124,7 +121,7 @@ void VDataMCComparisionHistogramData::fill( //////////////////////////////////////////////////////////////////////////////////////// -VDataMCComparision::VDataMCComparision( string iname, int intel ) +VDataMCComparision::VDataMCComparision( string iname, int intel, bool iMVAValues ) { fNTel = intel; fName = iname; @@ -138,8 +135,7 @@ VDataMCComparision::VDataMCComparision( string iname, int intel ) fData = 0; fCuts = 0; - fCalculateMVAValues = false; - fEpochATM = ""; + fCalculateMVAValues = iMVAValues; // spectral weighting (will be set later correctly, as it is run from MC run header) fSpectralWeight = new VSpectralWeight(); @@ -181,14 +177,10 @@ VDataMCComparision::VDataMCComparision( string iname, int intel ) */ void VDataMCComparision::initialGammaHadronCuts() { - VGlobalRunParameter( true ); fCuts = new VGammaHadronCuts(); fCuts->initialize(); fCuts->resetCutValues(); - fCuts->setNTel( 4 ); - fCuts->setInstrumentEpoch( fEpochATM ); // HARDWIRED CUT FILE - // used for BDT comparision if( !fCuts->readCuts( "$VERITAS_EVNDISP_AUX_DIR/GammaHadronCutFiles/ANASUM.GammaHadron-Cut-NTel2-PointSource-Moderate-TMVA-BDT.dat" ) ) { cout << "exiting..." << endl; @@ -455,6 +447,7 @@ bool VDataMCComparision::setOnOffHistograms( VDataMCComparision* on, VDataMCComp hTel2D[j]->Add( on->hTel2D[j], off->hTel2D[j], 1., norm ); } + return true; } @@ -500,7 +493,7 @@ void VDataMCComparision::setEntries( TH2D* iH ) bool VDataMCComparision::fillHistograms( string ifile, int iSingleTelescopeCuts ) { // quality cuts - double fCoreMax_QC = 350; // cut on core distance + double fCoreMax_QC = 350; //350.; // cut on core distance int fNImages_min = 2; // minimum number of images per event // stereo cuts double theta2_cut = 0.035; // 0.35; @@ -519,6 +512,13 @@ bool VDataMCComparision::fillHistograms( string ifile, int iSingleTelescopeCuts double msl_max = 0.5; double msl_min = -1.2; + /* + double msw_max = 1.15; + double msw_min = 0.05; + double msl_max = 0.40; + double msl_min = 0.05; + */ + double size_min = 200.; double size2ndmax_min = 0.; @@ -786,6 +786,7 @@ bool VDataMCComparision::fillHistograms( string ifile, int iSingleTelescopeCuts } } + ///////////////////////////////////////////////////////// // --- apply theta2 cuts --- ///////////////////////////////////////////////////////// @@ -956,16 +957,10 @@ bool VDataMCComparision::fillHistograms( string ifile, int iSingleTelescopeCuts if( fCuts ) { fCuts->newEvent(); - // apply stereo quality cuts to ensure good response of TMV - if( fCuts->applyInsideFiducialAreaCut( true ) - && fCuts->applyStereoQualityCuts( 1, true, i, true ) ) + fCuts->applyTMVACut( i ); + if( fCuts->getTMVA_EvaluationResult() > -90. && fHistoArray[EMVA] ) { - fCuts->applyTMVACut( i ); - if( fCuts->getTMVA_EvaluationResult() > -90. && fHistoArray[EMVA] ) - { - fHistoArray[EMVA]->fill( - fCuts->getTMVA_EvaluationResult(), weight, log10( fData->ErecS ) ); - } + fHistoArray[EMVA]->fill( fCuts->getTMVA_EvaluationResult(), weight, log10( fData->ErecS ) ); } } } diff --git a/src/VEffectiveAreaCalculator.cpp b/src/VEffectiveAreaCalculator.cpp index bd983816a..f9d8fd20a 100644 --- a/src/VEffectiveAreaCalculator.cpp +++ b/src/VEffectiveAreaCalculator.cpp @@ -19,7 +19,7 @@ VEffectiveAreaCalculator::VEffectiveAreaCalculator( VInstrumentResponseFunctionR { cout << "VEffectiveAreaCalculator: no run parameters given" << endl; cout << "...exiting..." << endl; - exit( EXIT_FAILURE ); + exit( -1 ); } reset(); @@ -951,61 +951,50 @@ VEffectiveAreaCalculator::VEffectiveAreaCalculator( string iInputFile, double az fGDirectory = gDirectory; // test if input file with effective areas exists - if( iInputFile.find( "IGNOREEFFECTIVEAREA" ) == string::npos ) + iInputFile = VUtilities::testFileLocation( iInputFile, "EffectiveAreas", true ); + if( iInputFile.size() == 0 ) { - iInputFile = VUtilities::testFileLocation( iInputFile, "EffectiveAreas", true ); - if( iInputFile.size() == 0 ) - { - exit( EXIT_FAILURE ); - } + exit( 0 ); + } + + TFile fIn( iInputFile.c_str() ); + if( fIn.IsZombie() ) + { + cout << "Error opening file with effective areas: " << iInputFile << endl; + exit( -1 ); + } + cout << "\t reading effective areas from " << fIn.GetName() << endl; + + // test which kind of file is available + // i) effective areas values for each energy bin (bEffectiveAreasareHistograms = true) + // ii) fit functions to effective area histograms (bEffectiveAreasareFunctions = true) + // (favorable, to avoid binning effects) + // + // prefer fit function over histograms + // + bEffectiveAreasareFunctions = false; + bEffectiveAreasareHistograms = false; + if( getEffectiveAreasFromFitFunction( ( TTree* )gDirectory->Get( "EffFit" ), azmin, azmax, iSpectralIndex ) ) + { + bEffectiveAreasareFunctions = true; + } + else if( initializeEffectiveAreasFromHistograms( ( TTree* )gDirectory->Get( "fEffArea" ), + ( TH1D* )gDirectory->Get( "hEmc" ), + azmin, azmax, iSpectralIndex, ipedvar, + ( TTree* )gDirectory->Get( "fEffAreaH2F" ) ) ) + { + bEffectiveAreasareHistograms = true; } - if( iInputFile.find( "IGNOREEFFECTIVEAREA" ) != string::npos ) + if( !bEffectiveAreasareHistograms && !bEffectiveAreasareFunctions ) { - cout << "ignoring effective areas: "; + cout << "VEffectiveAreaCalculator ERROR: no effective areas found" << endl; cout << "all energy spectra will be invalid" << endl; bNOFILE = true; } - else + fIn.Close(); + if( fGDirectory ) { - TFile fIn( iInputFile.c_str() ); - if( fIn.IsZombie() ) - { - cout << "Error opening file with effective areas: " << iInputFile << endl; - exit( -1 ); - } - cout << "\t reading effective areas from " << fIn.GetName() << endl; - - // test which kind of file is available - // i) effective areas values for each energy bin (bEffectiveAreasareHistograms = true) - // ii) fit functions to effective area histograms (bEffectiveAreasareFunctions = true) - // (favorable, to avoid binning effects) - // - // prefer fit function over histograms - // - bEffectiveAreasareFunctions = false; - bEffectiveAreasareHistograms = false; - if( getEffectiveAreasFromFitFunction( ( TTree* )gDirectory->Get( "EffFit" ), azmin, azmax, iSpectralIndex ) ) - { - bEffectiveAreasareFunctions = true; - } - else if( initializeEffectiveAreasFromHistograms( ( TTree* )gDirectory->Get( "fEffArea" ), - ( TH1D* )gDirectory->Get( "hEmc" ), - azmin, azmax, iSpectralIndex, ipedvar, - ( TTree* )gDirectory->Get( "fEffAreaH2F" ) ) ) - { - bEffectiveAreasareHistograms = true; - } - if( !bEffectiveAreasareHistograms && !bEffectiveAreasareFunctions ) - { - cout << "VEffectiveAreaCalculator ERROR: no effective areas found" << endl; - cout << "all energy spectra will be invalid" << endl; - bNOFILE = true; - } - fIn.Close(); - if( fGDirectory ) - { - fGDirectory->cd(); - } + fGDirectory->cd(); } } @@ -2078,7 +2067,7 @@ bool VEffectiveAreaCalculator::fill( TH1D* hE0mc, CData* d, } // reset unique event counter fUniqueEventCounter.clear(); - Long64_t iSuccessfullEventStatistics = 0; + int iSuccessfullEventStatistics = 0; ////////////////////////////////////////////////////////////////// // print some run information @@ -2361,10 +2350,34 @@ bool VEffectiveAreaCalculator::fill( TH1D* hE0mc, CData* d, hEcutSub[6]->Fill( eMC, 1. ); } + // unique event counter - if( !bDirectionCut ) + // (make sure that map doesn't get too big) + if( !bDirectionCut && iSuccessfullEventStatistics >= 0 ) { iSuccessfullEventStatistics++; + /* This was removed in v502, is it necessary? + if( fUniqueEventCounter.size() < 100000 ) + { + unsigned int iUIEnergy = ( unsigned int )( d->MCe0 * 1.e5 ); + if( fUniqueEventCounter.find( iUIEnergy ) != fUniqueEventCounter.end() ) + { + fUniqueEventCounter[iUIEnergy]++; + } + else + { + fUniqueEventCounter[iUIEnergy] = 1; + } + } + else + { + iSuccessfullEventStatistics *= -1; + } + */ + } + else + { + iSuccessfullEventStatistics--; } // loop over all az bins @@ -2791,6 +2804,25 @@ bool VEffectiveAreaCalculator::fill( TH1D* hE0mc, CData* d, } fCuts->printCutStatistics(); + + // print out uniqueness of events + /* cout << "event statistics: " << endl; + if( iSuccessfullEventStatistics > 0 ) + { + map< unsigned int, unsigned short int>::iterator it; + for( it = fUniqueEventCounter.begin(); it != fUniqueEventCounter.end(); it++ ) + { + if( (*it).second > 1 ) + { + cout << "\t multiple event after cuts at " << (double)((*it).first)/1.e5 << " TeV, used " << (*it).second << " times" << endl; + } + } + } + else iSuccessfullEventStatistics *= -1; */ + if( iSuccessfullEventStatistics < 0 ) + { + iSuccessfullEventStatistics *= -1; + } cout << "\t total number of events after cuts: " << iSuccessfullEventStatistics << endl; return true; diff --git a/src/VEnergyThreshold.cpp b/src/VEnergyThreshold.cpp index 820d3ad31..5e3451815 100644 --- a/src/VEnergyThreshold.cpp +++ b/src/VEnergyThreshold.cpp @@ -37,7 +37,7 @@ iii) plot energy thresholds // create a new instance, open the data file VEnergyThreshold a( 0.0, "myOutputFile.root" ); -// plot everything (for ze=20, wobble offset=0.5 deg, noise = 150, az bin = 16) +// plot everything (for ze=20, wobble offset=0.5 deg, noise = 150, index = 2.4, az bin = 16) a.plot_energyThresholds( "E_diffmax", 20., 0.5, 150, 2.4, 16 ); Energy thresholds are defined (currently) in 3 ways: @@ -141,32 +141,17 @@ bool VEnergyThreshold::openEffectiveAreaFile( string iname ) cout << "VEnergyThreshold::openEffectiveAreaFile " << iname << endl; } - fEffArea = new TChain( "fEffAreaH2F" ); - fEffArea->Add( iname.c_str() ); - if( fEffArea->GetListOfFiles()->GetEntries() == 0 ) + TChain* f = new TChain( "fEffArea" ); + f->Add( iname.c_str() ); + if( f->GetListOfFiles()->GetEntries() == 0 ) { - cout << "error opening " << iname << "(" << fEffArea->GetListOfFiles()->GetEntries() << ")" << endl; + cout << "error opening " << iname << "(" << f->GetListOfFiles()->GetEntries() << ")" << endl; return false; } + fEffArea = new CEffArea( f ); cout << "reading effective areas from " << iname << endl; - cout << "total number of effective areas: " << fEffArea->GetEntries() << endl; - - fEffArea->SetBranchAddress( "ze", &fze ); - fEffArea->SetBranchAddress( "az", &fAzBin ); - fEffArea->SetBranchAddress( "azMin", &fAzMin ); - fEffArea->SetBranchAddress( "azMax", &fAzMax ); - fEffArea->SetBranchAddress( "Woff", &fWoff ); - fEffArea->SetBranchAddress( "noise", &fTNoise ); - fEffArea->SetBranchAddress( "pedvar", &fTPedvar ); - nbins = 0; - fEffArea->SetBranchAddress( "nbins", &nbins ); - fEffArea->SetBranchAddress( "e0", e0 ); - fEffArea->SetBranchAddress( "eff", eff ); - nbins_esys = 0; - fEffArea->SetBranchAddress( "nbins_esys", &nbins_esys ); - fEffArea->SetBranchAddress( "e0_esys", e0_esys ); - fEffArea->SetBranchAddress( "esys_rel", esys_rel ); + cout << "total number of effective areas: " << f->GetEntries() << endl; return true; } @@ -211,9 +196,13 @@ bool VEnergyThreshold::calculateEnergyThreshold( bool bFit, int nentries ) } } - if( nentries < 0 || nentries > fEffArea->GetEntries() ) + if( nentries < 0 ) { - nentries = fEffArea->GetEntries(); + nentries = fEffArea->fChain->GetEntries(); + } + if( nentries > fEffArea->fChain->GetEntries() ) + { + nentries = fEffArea->fChain->GetEntries(); } for( int i = 0; i < nentries; i++ ) { @@ -239,56 +228,63 @@ bool VEnergyThreshold::calculateEnergyThreshold( bool bFit, int nentries ) feff_500GeV = 0.; feff_1TeV = 0.; - if( nbins > 1 ) + copyEntry(); + + TH1D* hLin = fEffArea->hEcut500; + if( hLin ) { - double idE = e0[1] - e0[0]; - TH1D hLin( "hLin", "", nbins, - e0[0] - idE, - e0[nbins - 1] + idE ); - for( int b = 0; b < nbins; b++ ) + feth = getEnergyThreshold( hLin, true, bFit ); + } + else + { + if( fEffArea->nbins > 1 ) { - hLin.SetBinContent( b + 1, e0[b], - eff[b] * - TMath::Power( TMath::Power( 10., e0[b] ), - -1.*2.4 ) ); + double idE = fEffArea->e0[1] - fEffArea->e0[0]; + TH1D hLin( "hLin", "", fEffArea->nbins, + fEffArea->e0[0] - idE, + fEffArea->e0[fEffArea->nbins - 1] + idE ); + for( int b = 0; b < fEffArea->nbins; b++ ) + { + hLin.SetBinContent( b + 1, fEffArea->e0[b], + fEffArea->eff[b] * + TMath::Power( TMath::Power( 10., fEffArea->e0[b] ), + -1.*fEffArea->index ) ); + } + feth = getEnergyThreshold( &hLin, true, bFit ); } - feth = getEnergyThreshold( &hLin, true, bFit ); } - if( nbins_esys > 1 ) + TProfile* hSys = fEffArea->hEsysMCRelative; + if( hSys ) + { + fesys_10p = getEnergy_maxSystematic( hSys, 0.10 ); + fesys_15p = getEnergy_maxSystematic( hSys, 0.15 ); + fesys_20p = getEnergy_maxSystematic( hSys, 0.20 ); + } + TGraph* hG = fEffArea->gEffAreaRec; + if( !hG ) { - vector< double > x; - vector< double > y; - for( int b = 0; b < nbins_esys; b++ ) + hG = new TGraph( 1 ); + for( int b = 0; b < fEffArea->nbins; b++ ) { - if( TMath::Abs( esys_rel[b] ) > 1.e-3 ) - { - x.push_back( e0_esys[b] ); - y.push_back( esys_rel[b] ); - } + hG->SetPoint( b, fEffArea->e0[b], fEffArea->eff[b] ); } - fesys_10p = getEnergy_maxSystematic( x, y, 0.10 ); - fesys_15p = getEnergy_maxSystematic( x, y, 0.15 ); - fesys_20p = getEnergy_maxSystematic( x, y, 0.20 ); + feff_300GeV = hG->Eval( log10( 0.3 ) ); + feff_500GeV = hG->Eval( log10( 0.5 ) ); + feff_1TeV = hG->Eval( log10( 1. ) ); } - TGraph* gEffAreaRec = new TGraph( 1 ); - for( int b = 0; b < nbins; b++ ) + if( hG ) { - gEffAreaRec->SetPoint( b, e0[b], eff[b] ); + feffFract_05p = getEnergy_MaxEffectiveAreaFraction( hG, 0.05 ); + feffFract_10p = getEnergy_MaxEffectiveAreaFraction( hG, 0.10 ); + feffFract_20p = getEnergy_MaxEffectiveAreaFraction( hG, 0.20 ); + feffFract_50p = getEnergy_MaxEffectiveAreaFraction( hG, 0.50 ); + feffFract_90p = getEnergy_MaxEffectiveAreaFraction( hG, 0.90 ); + delete hG; } - feff_300GeV = gEffAreaRec->Eval( log10( 0.3 ) ); - feff_500GeV = gEffAreaRec->Eval( log10( 0.5 ) ); - feff_1TeV = gEffAreaRec->Eval( log10( 1. ) ); - feffFract_05p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.05 ); - feffFract_10p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.10 ); - feffFract_20p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.20 ); - feffFract_50p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.50 ); - feffFract_90p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.90 ); - delete gEffAreaRec; - - if( TMath::Abs( fAzMax - 1000. ) < 1.e-3 ) + if( TMath::Abs( fEffArea->index - 2.4 ) < 1.e-3 && TMath::Abs( fEffArea->azMax - 1000. ) < 1.e-3 ) { - cout << "Threshold : "; + cout << "Threshold for index " << fEffArea->index << ": "; cout << feth << " TeV, 10\% sys: " << fesys_10p << endl; } fTreeEth->Fill(); @@ -296,34 +292,45 @@ bool VEnergyThreshold::calculateEnergyThreshold( bool bFit, int nentries ) return true; } -double VEnergyThreshold::getEnergy_maxSystematic( TGraphErrors* g, double iSys ) + +/*! + calculate lower energy threshold from systematics: + (interpolate between two closest values) +*/ +double VEnergyThreshold::getEnergy_maxSystematic( TObject* h, double iSys ) { - if( !g ) + if( !h ) { return 0.; } vector< double > x; vector< double > y; - double e = 0.; - double s = 0.; - for( int b = 0; b < g->GetN(); b++ ) + + if( strcmp( "TProfile", h->ClassName() ) == 0 ) { - g->GetPoint( b, e, s ); - if( TMath::Abs( s ) > 1.e-3 ) + TProfile* p = ( TProfile* )h; + for( int i = 1; i < p->GetNbinsX(); i++ ) { - x.push_back( e ); - y.push_back( s ); + if( p->GetBinError( i ) < 0.001 ) + { + continue; + } + x.push_back( p->GetBinCenter( i ) ); + y.push_back( p->GetBinContent( i ) ); } } - return getEnergy_maxSystematic( x, y, iSys ); -} - -/*! - calculate lower energy threshold from systematics: - (interpolate between two closest values) -*/ -double VEnergyThreshold::getEnergy_maxSystematic( vector< double > x, vector< double > y, double iSys ) -{ + else if( strcmp( "TGraphErrors", h->ClassName() ) == 0 ) + { + double a, b; + TGraphErrors* g = ( TGraphErrors* )h; + for( int i = 0; i < g->GetN(); i++ ) + { + g->GetPoint( i, a, b ); + x.push_back( a ); + y.push_back( b ); + } + } + double x1, x2, y1, y2, a, b; for( unsigned int i = 0; i < x.size(); i++ ) @@ -418,6 +425,22 @@ double VEnergyThreshold::getEnergyThreshold( TH1D* h, bool bLogEnergyAxis, bool } +void VEnergyThreshold::copyEntry() +{ + fze = fEffArea->ze; + fAzBin = fEffArea->az; + fAzMin = fEffArea->azMin; + fAzMax = fEffArea->azMax; + fXoff = fEffArea->Xoff; + fYoff = fEffArea->Yoff; + fWoff = fEffArea->Woff; + fTNoise = fEffArea->noise; + fTNoisePE = fEffArea->noisePE; + fTPedvar = fEffArea->pedvar; + fSpectralIndex = fEffArea->index; +} + + bool VEnergyThreshold::setUpThresholdTree() { if( fDebug ) @@ -443,25 +466,29 @@ bool VEnergyThreshold::setUpThresholdTree() fOutFile->cd(); fTreeEth = new TTree( "fTreeEth", "thresholds in energy reconstruction" ); - fTreeEth->Branch( "ze", &fze, "ze/F" ); - fTreeEth->Branch( "az", &fAzBin, "az/s" ); - fTreeEth->Branch( "azMin", &fAzMin, "azMin/F" ); - fTreeEth->Branch( "azMax", &fAzMax, "azMax/F" ); - fTreeEth->Branch( "Woff", &fWoff, "Woff/F" ); - fTreeEth->Branch( "noise", &fTNoise, "noise/s" ); - fTreeEth->Branch( "pedvar", &fTPedvar, "pedvar/F" ); - fTreeEth->Branch( "E_diffmax", &feth, "E_diffmax/F" ); - fTreeEth->Branch( "E_sys10p", &fesys_10p, "E_sys10p/F" ); - fTreeEth->Branch( "E_sys15p", &fesys_15p, "E_sys15p/F" ); - fTreeEth->Branch( "E_sys20p", &fesys_20p, "E_sys20p/F" ); - fTreeEth->Branch( "E_effFract_05p", &feffFract_05p, "E_effFract_05p/F" ); - fTreeEth->Branch( "E_effFract_10p", &feffFract_10p, "E_effFract_10p/F" ); - fTreeEth->Branch( "E_effFract_20p", &feffFract_20p, "E_effFract_20p/F" ); - fTreeEth->Branch( "E_effFract_50p", &feffFract_50p, "E_effFract_50p/F" ); - fTreeEth->Branch( "E_effFract_90p", &feffFract_90p, "E_effFract_90p/F" ); - fTreeEth->Branch( "EffArea_300GeV", &feff_300GeV, "EffArea_300GeV/F" ); - fTreeEth->Branch( "EffArea_500GeV", &feff_500GeV, "EffArea_500GeV/F" ); - fTreeEth->Branch( "EffArea_1TeV", &feff_1TeV, "EffArea_1TeV/F" ); + fTreeEth->Branch( "ze", &fze, "ze/D" ); + fTreeEth->Branch( "az", &fAzBin, "az/I" ); + fTreeEth->Branch( "azMin", &fAzMin, "azMin/D" ); + fTreeEth->Branch( "azMax", &fAzMax, "azMax/D" ); + fTreeEth->Branch( "Xoff", &fXoff, "Xoff/D" ); + fTreeEth->Branch( "Yoff", &fYoff, "Yoff/D" ); + fTreeEth->Branch( "Woff", &fWoff, "Woff/D" ); + fTreeEth->Branch( "noise", &fTNoise, "noise/I" ); + fTreeEth->Branch( "noisePE", &fTNoisePE, "noisePE/D" ); + fTreeEth->Branch( "pedvar", &fTPedvar, "pedvar/D" ); + fTreeEth->Branch( "index", &fSpectralIndex, "index/D" ); + fTreeEth->Branch( "E_diffmax", &feth, "E_diffmax/D" ); + fTreeEth->Branch( "E_sys10p", &fesys_10p, "E_sys10p/D" ); + fTreeEth->Branch( "E_sys15p", &fesys_15p, "E_sys15p/D" ); + fTreeEth->Branch( "E_sys20p", &fesys_20p, "E_sys20p/D" ); + fTreeEth->Branch( "E_effFract_05p", &feffFract_05p, "E_effFract_05p/D" ); + fTreeEth->Branch( "E_effFract_10p", &feffFract_10p, "E_effFract_10p/D" ); + fTreeEth->Branch( "E_effFract_20p", &feffFract_20p, "E_effFract_20p/D" ); + fTreeEth->Branch( "E_effFract_50p", &feffFract_50p, "E_effFract_50p/D" ); + fTreeEth->Branch( "E_effFract_90p", &feffFract_90p, "E_effFract_90p/D" ); + fTreeEth->Branch( "EffArea_300GeV", &feff_300GeV, "EffArea_300GeV/D" ); + fTreeEth->Branch( "EffArea_500GeV", &feff_500GeV, "EffArea_500GeV/D" ); + fTreeEth->Branch( "EffArea_1TeV", &feff_1TeV, "EffArea_1TeV/D" ); return true; } @@ -562,7 +589,7 @@ double VEnergyThreshold::interpolateEnergyThreshold( VRunList* iRunData ) } -void VEnergyThreshold::plot_energyThresholds( string var, double ze, double woff, int noise, int az, bool bPlot, string plot_option ) +void VEnergyThreshold::plot_energyThresholds( string var, double ze, double woff, int noise, double index, int az, bool bPlot, string plot_option ) { if( !fTreeEth ) { @@ -585,36 +612,44 @@ void VEnergyThreshold::plot_energyThresholds( string var, double ze, double woff vector< string > iName; vector< string > iTitle; + // energy threshold vs spectral index + iName.push_back( "spectral index" ); + iDraw.push_back( var + "*1.e3:index" ); + sprintf( hname, "az == %d && noise == %d && TMath::Abs( ze - %f ) < 0.1 && TMath::Abs( Woff - %f ) < 0.05", az, noise, ze, woff ); + iCut.push_back( hname ); + sprintf( hname, "ze=%d deg, woff = %.2f deg, noise level = %d", ( int )ze, woff, noise ); + iTitle.push_back( hname ); + // energy threshold vs zenith angle iName.push_back( "zenith angle [deg]" ); iDraw.push_back( var + "*1.e3:ze" ); - sprintf( hname, "az == %d && noise == %d && TMath::Abs( Woff - %f ) < 0.05", az, noise, woff ); + sprintf( hname, "az == %d && noise == %d && TMath::Abs( index - %f ) < 0.1 && TMath::Abs( Woff - %f ) < 0.05", az, noise, index, woff ); iCut.push_back( hname ); - sprintf( hname, "woff = %.2f deg, noise level = %d", woff, noise ); + sprintf( hname, "woff = %.2f deg, noise level = %d, spectral index = %.1f", woff, noise, index ); iTitle.push_back( hname ); // energy threshold vs wobble offsets iName.push_back( "wobble offset [deg]" ); iDraw.push_back( var + "*1.e3:Woff" ); - sprintf( hname, "az == %d && noise == %d && TMath::Abs( ze - %f ) < 0.05", az, noise, ze ); + sprintf( hname, "az == %d && noise == %d && TMath::Abs( index - %f ) < 0.1 && TMath::Abs( ze - %f ) < 0.05", az, noise, index, ze ); iCut.push_back( hname ); - sprintf( hname, "ze=%d deg, noise level = %d", ( int )ze, noise ); + sprintf( hname, "ze=%d deg, noise level = %d, spectral index = %.1f", ( int )ze, noise, index ); iTitle.push_back( hname ); // energy threshold vs pedestal variations iName.push_back( "pedestal variation" ); iDraw.push_back( var + "*1.e3:pedvar" ); - sprintf( hname, "az == %d && TMath::Abs( Woff - %f ) < 0.05 && TMath::Abs( ze - %f ) < 0.05", az, woff, ze ); + sprintf( hname, "az == %d && TMath::Abs( Woff - %f ) < 0.05 && TMath::Abs( index - %f ) < 0.1 && TMath::Abs( ze - %f ) < 0.05", az, woff, index, ze ); iCut.push_back( hname ); - sprintf( hname, "ze=%d deg, woff = %.2f deg", ( int )ze, woff ); + sprintf( hname, "ze=%d deg, woff = %.2f deg, spectral index = %.1f", ( int )ze, woff, index ); iTitle.push_back( hname ); // energy threshold vs azimuth angle iName.push_back( "azimuth angle [deg]" ); iDraw.push_back( var + "*1.e3:azMin+30." ); - sprintf( hname, "az != 16 && noise == %d && TMath::Abs( Woff - %f ) < 0.05 && TMath::Abs( ze - %f ) < 0.05", noise, woff, ze ); + sprintf( hname, "az != 16 && noise == %d && TMath::Abs( Woff - %f ) < 0.05 && TMath::Abs( index - %f ) < 0.1 && TMath::Abs( ze - %f ) < 0.05", noise, woff, index, ze ); iCut.push_back( hname ); - sprintf( hname, "ze=%d deg, woff = %.2f deg, noise level = %d", ( int )ze, woff, noise ); + sprintf( hname, "ze=%d deg, woff = %.2f deg, noise level = %d, spectral index = %.1f", ( int )ze, woff, noise, index ); iTitle.push_back( hname ); TCanvas* c = 0; diff --git a/src/VEventLoop.cpp b/src/VEventLoop.cpp index 0931cb181..4c2b4133c 100644 --- a/src/VEventLoop.cpp +++ b/src/VEventLoop.cpp @@ -101,6 +101,7 @@ VEventLoop::VEventLoop( VEvndispRunParameter* irunparameter ) fCalibrated.push_back( false ); } fCalibrator = new VCalibrator(); + fIPRCalculator = new VIPRCalculator(); // create data summarizer fDST = new VDST( ( fRunMode == R_DST ), ( fRunPar->fsourcetype == 1 || fRunPar->fsourcetype == 2 || fRunPar->fsourcetype == 6 ) ); @@ -134,6 +135,9 @@ VEventLoop::VEventLoop( VEvndispRunParameter* irunparameter ) // reset cut strings and variables resetRunOptions(); + + //add if statement: if ipr should be in time slices + fIPRTimeSlices = true; } @@ -274,16 +278,12 @@ bool VEventLoop::initEventLoop( string iFileName ) unsigned int i_counter = 0; for( ;; ) { - if( !i_tempReader.getNextEvent() ) - { - break; - } + i_tempReader.getNextEvent(); for( unsigned int i = 0; i < fRunPar->fTelToAnalyze.size(); i++ ) { i_tempReader.setTelescopeID( fRunPar->fTelToAnalyze[i] ); // set number of samples - // (require at least 10 samples for any reasonable analysis) - if( i_tempReader.getNumSamples() > 9 ) + if( i_tempReader.getNumSamples() > 4 ) { setNSamples( fRunPar->fTelToAnalyze[i], i_tempReader.getNumSamples() ); i_nSampleSet[i] = true; @@ -322,18 +322,22 @@ bool VEventLoop::initEventLoop( string iFileName ) } } i_counter++; - if( i_counter == 10000 ) + if( i_counter == 1000 ) { - cout << "VEventLoop warning: could not find number of samples in the first 10000 events"; + cout << "VEventLoop warning: could not find number of samples in the first 1000 events"; cout << " (this is normal for runs with event losses at the beginning)" << endl; } + if( i_counter > 999999 ) + { + cout << "VEventLoop warning: could not find number of samples in the first 999999 events" << endl; + break; + } } - // if( getNSamples() == 0 || i_counter > 9999998 ) - if( getNSamples() == 0 ) + if( getNSamples() == 0 || i_counter > 99999 ) { cout << "VEventLoop::initEventLoop error: could not find any telescope events to determine sample length" << endl; cout << "exiting..." << endl; - exit( EXIT_FAILURE ); + exit( -1 ); } cout << "Found consistent number of samples in vbf file after " << i_counter + 1 << " event(s): "; for( unsigned int i = 0; i < fRunPar->fTelToAnalyze.size(); i++ ) @@ -475,13 +479,17 @@ bool VEventLoop::initEventLoop( string iFileName ) // initialize analyzers (output files are created as well here) initializeAnalyzers(); - + + if( fIPRCalculator ){ + cout << "initializing IPR calculator" << endl; + fIPRCalculator->initialize(); + } + // create calibrators, analyzers, etc. at first event if( fCalibrator ) { - fCalibrator->initialize(); + fCalibrator->initialize(fIPRCalculator); } - // initialize pedestal calculator if( fPedestalCalculator && fRunPar->fPedestalsInTimeSlices ) { @@ -821,7 +829,7 @@ void VEventLoop::shutdown() } if( fCalibrator ) { - fCalibrator->terminate( iP ); + fCalibrator->terminate( iP , fIPRCalculator); } } // write data summary @@ -1014,6 +1022,14 @@ bool VEventLoop::nextEvent() else { cout << "!!! void VEventLoop::nextEvent(): no next event (end of file)" << endl; + for (int tel =0; tel < fIPRCalculator->getStorageHist().size(); tel++){ + for (int ts =0; ts < fIPRCalculator->getStorageHist()[tel].size(); ts++){ + for (int p =0; p < fIPRCalculator->getStorageHist()[tel][ts].size(); p++){ + for (int sw =0; sw < fIPRCalculator->getStorageHist()[tel][ts][p].size(); sw++){ + fIPRCalculator->checkHistEmpty(tel, ts, p, sw); + }}}} + + // if the display is run in the loop mode, goto event 0 and start again if( fRunPar->floopmode ) { @@ -1122,6 +1138,7 @@ int VEventLoop::analyzeEvent() cout << "\t now at event " << getEventNumber() << endl; cout << "----------------------------------------" << endl; } + // analysis is running fAnalyzeMode = true; int i_cut = 0; @@ -1452,7 +1469,7 @@ int VEventLoop::analyzeEvent() setTelID( fRunPar->fTelToAnalyze[i] ); if( fRunPar->fPedestalsInTimeSlices && !fReader->wasLossyCompressed() ) { - fPedestalCalculator->doAnalysis( fRunMode == R_PEDLOW ); + fPedestalCalculator->doAnalysis( fRunMode == R_PEDLOW, fIPRCalculator ); } } } diff --git a/src/VEvndispRunParameter.cpp b/src/VEvndispRunParameter.cpp index cf75609c5..680e4edfe 100644 --- a/src/VEvndispRunParameter.cpp +++ b/src/VEvndispRunParameter.cpp @@ -1048,12 +1048,3 @@ unsigned int VEvndispRunParameter::getAtmosphereID( bool iUpdateInstrumentEpoch return fAtmosphereID; } - -string VEvndispRunParameter::getInstrumentATMString() -{ - ostringstream i_temp; - i_temp << getInstrumentEpoch( false ); - i_temp << "_ATM" << getAtmosphereID(); - - return i_temp.str(); -} diff --git a/src/VGammaHadronCuts.cpp b/src/VGammaHadronCuts.cpp index 2abee2b7b..5cd3c4b9f 100644 --- a/src/VGammaHadronCuts.cpp +++ b/src/VGammaHadronCuts.cpp @@ -92,6 +92,7 @@ VGammaHadronCuts::VGammaHadronCuts() fTMVAWeightFileIndex_Emax = 0; fTMVAWeightFileIndex_Zmin = 0; fTMVAWeightFileIndex_Zmax = 0; + fTMVAEnergyStepSize = 0.2; fTMVAWeightFile = ""; fTMVASignalEfficiency.clear(); fTMVA_MVACut.clear(); @@ -385,7 +386,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) if( fNTel == 0 || fNTel > 10 ) { cout << "VGammaHadronCuts::readCuts warning: cut identifier " << temp << " ignored for "; - cout << "current telescope configuration ( " << fNTel << " telescopes)" << endl; + cout << "current telescope configuration ( " << fNTel << "telescopes)" << endl; continue; } // calculate how many possible telescope combinations exist (16 for 4 telescopes) @@ -414,7 +415,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) if( !( is_stream >> std::ws ).eof() ) { is_stream >> temp; - if( fInstrumentEpoch.size() > 1 && temp != fInstrumentEpoch.substr( 0, 2 ) ) + if( temp != fInstrumentEpoch ) { i_useTheseCuts = false; } @@ -562,7 +563,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) if( !( is_stream >> std::ws ).eof() ) { is_stream >> temp; - if( fInstrumentEpoch.size() > 1 && temp == fInstrumentEpoch.substr( 0, 2 ) ) + if( temp == fInstrumentEpoch ) { fCut_SizeSecondMax_min = isize_min; fCut_SizeSecondMax_max = isize_max; @@ -594,7 +595,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) if( !( is_stream >> std::ws ).eof() ) { is_stream >> temp; - if( fInstrumentEpoch.size() > 0 && temp == fInstrumentEpoch.substr( 0, 2 ) ) + if( temp == fInstrumentEpoch ) { while( !( is_stream >> std::ws ).eof() ) { @@ -619,16 +620,18 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) { is_stream >> fTMVAWeightFileIndex_Zmax; } - string iWeightFileDirectory; if( !( is_stream >> std::ws ).eof() ) { - is_stream >> iWeightFileDirectory; + if( !( is_stream >> fTMVAEnergyStepSize ) ) + { + cout << "VGammaHadronCuts::readCuts: missing TMVAPARAMETER energy step size " << endl; + break; + } } - if( fInstrumentEpoch.size() > 1 ) + string iWeightFileDirectory; + if( !( is_stream >> std::ws ).eof() ) { - iWeightFileDirectory.replace( - iWeightFileDirectory.find( fInstrumentEpoch.substr( 0, 1 ) ), - 2, fInstrumentEpoch ); + is_stream >> iWeightFileDirectory; } string iWeightFileName; if( !( is_stream >> std::ws ).eof() ) @@ -639,7 +642,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) // check of path name is complete if( gSystem->AccessPathName( fTMVAWeightFile.c_str() ) ) { - fTMVAWeightFile = VGlobalRunParameter::getDirectory_EVNDISPAnaDataTMP() + fTMVAWeightFile; + fTMVAWeightFile = VGlobalRunParameter::getDirectory_EVNDISPAnaData() + fTMVAWeightFile; if( gSystem->AccessPathName( fTMVAWeightFile.c_str() ) ) { cout << "VGammaHadronCuts::readCuts error,"; @@ -653,6 +656,11 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) break; } } + else if( iPrint != 0 ) + { + cout << "VGammaHadronCuts::readCuts: skipping TMVAPARAMETER due to epoch mismatch:"; + cout << " required: " << fInstrumentEpoch << ", is: " << temp << endl; + } } } else if( iCutVariable == "TMVACUTS" ) @@ -744,6 +752,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) } } } + //////////////////////////////////////////////////////////////////////////////////////////////////// } //////////////////////////////////////////////////////////////////////////////////////////////////// // direction cut values @@ -888,6 +897,26 @@ void VGammaHadronCuts::printDirectionCuts() cout << "VGammaHadronCuts::printDirectionCuts WARNING: no function found" << endl; } } + // theta cut using TMVA + else if( fDirectionCutSelector == 4 ) + { + cout << "Direction cut from TMVA angular containment optimizer" << endl; + } + else if( fDirectionCutSelector == 3 || fDirectionCutSelector == 5 ) + { + cout << "Direction cut from TMVA " << endl; + if( fDirectionCutSelector == 3 ) + { + cout << "using TMVA evaluator (part of gamma/hadron cuts)" << endl; + } + if( fDirectionCutSelector == 5 ) + { + if( fDirectionCutSelector == 5 && getTheta2Cut_TMVA_max() ) + { + getTheta2Cut_TMVA_max()->Print(); + } + } + } cout << "Direction cut scale factor " << fAngRes_ScalingFactor; cout << ", minimum : " << fAngRes_AbsoluteMinimum << " [deg] "; cout << ", maximum : " << fAngRes_AbsoluteMaximum << " [deg]" << endl; @@ -931,23 +960,23 @@ void VGammaHadronCuts::printCutSummary() { cout << "Shape cuts: "; cout << fCut_MSCW_min << " < MSCW < " << fCut_MSCW_max; - cout << ", " << fCut_MSCL_min << " < MSCL < " << fCut_MSCL_max << endl; + cout << ", " << fCut_MSCL_min << " < MSCL < " << fCut_MSCL_max << ", "; } // mean cuts else if( fGammaHadronCutSelector % 10 == 1 ) { cout << "Shape cuts: "; cout << fCut_MeanImageWidth_min << " < mean width < " << fCut_MeanImageWidth_max; - cout << ", " << fCut_MeanImageLength_min << " < mean length < " << fCut_MeanImageLength_max << endl; + cout << ", " << fCut_MeanImageLength_min << " < mean length < " << fCut_MeanImageLength_max << ", "; } // mean scaled cuts else if( fGammaHadronCutSelector % 10 == 3 ) { cout << "Shape cuts: "; cout << fCut_MSW_min << " < MWR < " << fCut_MSW_max; - cout << ", " << fCut_MSL_min << " < MLR < " << fCut_MSL_max << endl; + cout << ", " << fCut_MSL_min << " < MLR < " << fCut_MSL_max << ", "; } - cout << "Average core distance < " << fCut_AverageCoreDistanceToTelescopes_max << " m"; + cout << "average core distance < " << fCut_AverageCoreDistanceToTelescopes_max << " m"; cout << " (max distance to telescopes (mintel) " << fCut_MinimumCoreDistanceToTelescopes_max << " m)"; // probability cuts if( fGammaHadronCutSelector / 10 >= 1 && fGammaHadronCutSelector / 10 <= 3 ) @@ -1658,9 +1687,7 @@ void VGammaHadronCuts::initializeCuts( int irun, string iFile ) // TMVA cuts else if( useTMVACuts() ) { - if( !initTMVAEvaluator( fTMVAWeightFile, - fTMVAWeightFileIndex_Emin, fTMVAWeightFileIndex_Emax, - fTMVAWeightFileIndex_Zmin, fTMVAWeightFileIndex_Zmax ) ) + if( !initTMVAEvaluator( fTMVAWeightFile, fTMVAWeightFileIndex_Emin, fTMVAWeightFileIndex_Emax, fTMVAWeightFileIndex_Zmin, fTMVAWeightFileIndex_Zmax, fTMVAEnergyStepSize ) ) { cout << "VGammaHadronCuts::initializeCuts: failed setting TMVA reader for " << fTMVAWeightFile; cout << "(" << fTMVAWeightFileIndex_Emin << "," << fTMVAWeightFileIndex_Emax << ")" << endl; @@ -1689,18 +1716,23 @@ void VGammaHadronCuts::initializeCuts( int irun, string iFile ) } } -/* - * initialize TMVA evaluator - * - */ -bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, - unsigned int iTMVAWeightFileIndex_Emin, unsigned int iTMVAWeightFileIndex_Emax, - unsigned int iTMVAWeightFileIndex_Zmin, unsigned int iTMVAWeightFileIndex_Zmax ) +bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, unsigned int iTMVAWeightFileIndex_Emin, unsigned int iTMVAWeightFileIndex_Emax, + unsigned int iTMVAWeightFileIndex_Zmin, unsigned int iTMVAWeightFileIndex_Zmax, double iTMVAEnergy_StepSize ) { TDirectory* cDir = gDirectory; fTMVAEvaluator = new VTMVAEvaluator(); + //EP turn off theta2 optimization except for TMVA direction cut selector flags + if( fDirectionCutSelector == 3 || fDirectionCutSelector == 4 || fDirectionCutSelector == 5 ) + { + fTMVAEvaluator->setOptimizeAngularContainment( true ); + } + else + { + fTMVAEvaluator->setOptimizeAngularContainment( false ); + } + fTMVAEvaluator->setDebug( fDebug ); // smoothing of MVA values fTMVAEvaluator->setSmoothAndInterPolateMVAValues( true ); @@ -1713,8 +1745,7 @@ bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, fTMVAOptimizeSignalEfficiencyObservationTime_h, 1. / 5. ); fTMVAEvaluator->setSensitivityOptimizationFixedSignalEfficiency( fTMVAFixedSignalEfficiencyMax ); - fTMVAEvaluator->setParticleNumberFile( - fTMVAOptimizeSignalEfficiencyParticleNumberFile, fTMVAParticleNumberFile_Conversion_Rate_to_seconds ); + fTMVAEvaluator->setParticleNumberFile( fTMVAOptimizeSignalEfficiencyParticleNumberFile, fTMVAParticleNumberFile_Conversion_Rate_to_seconds ); fTMVAEvaluator->setSensitivityOptimizationMinSourceStrength( fTMVAMinSourceStrength ); } // set a constant signal efficiency @@ -1736,9 +1767,10 @@ bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, exit( EXIT_FAILURE ); } fTMVAEvaluator->setTMVAMethod( fTMVA_MVAMethod ); + fTMVAEvaluator->setTMVAAngularContainmentThetaFixedMinRadius( fTMVAFixedThetaCutMin ); // read MVA weight files; set MVA cut values (e.g. find optimal values) if( !fTMVAEvaluator->initializeWeightFiles( iTMVAFile, iTMVAWeightFileIndex_Emin, iTMVAWeightFileIndex_Emax, - iTMVAWeightFileIndex_Zmin, iTMVAWeightFileIndex_Zmax ) ) + iTMVAWeightFileIndex_Zmin, iTMVAWeightFileIndex_Zmax, iTMVAEnergy_StepSize, fInstrumentEpoch ) ) { cout << "VGammaHadronCuts::initTMVAEvaluator: error while initializing TMVA weight files" << endl; cout << "exiting... " << endl; @@ -1747,6 +1779,22 @@ bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, fTMVAEvaluatorResults = fTMVAEvaluator->getTMVAEvaluatorResults(); fTMVAEvaluator->printSignalEfficiency(); + fTMVAEvaluator->printAngularContainmentRadius(); + + if( fDirectionCutSelector == 3 ) + { + fTMVAEvaluator->setIgnoreTheta2Cut( false ); + } + else + { + fTMVAEvaluator->setIgnoreTheta2Cut( true ); + } + fEnergyDependentCut[ "TMVABoxCut_Theta2_max" ] = fTMVAEvaluator->getOptimalTheta2Cut_Graph(); + if( getTheta2Cut_TMVA_max() ) + { + cout << "VGammaHadronCuts::initTMVAEvaluator: found theta2_max graph from TMVA" << endl; + getTheta2Cut_TMVA_max()->SetName( "TMVAtheta2" ); + } if( cDir ) { @@ -2191,6 +2239,40 @@ double VGammaHadronCuts::getTheta2Cut_max( double e ) theta_cut_max = getEnergyDependentCut( e, getTheta2Cut_IRF_Max(), true ); } + ///////////////////////////////////////////// + // use TMVA determined cut + else if( fDirectionCutSelector == 3 ) + { + theta_cut_max = -1.; + } + // optimal theta2 cut + else if( fDirectionCutSelector == 4 && fTMVAEvaluator ) + { + theta_cut_max = fTMVAEvaluator->getOptimalTheta2Cut( e ); + if( theta_cut_max > 0. ) + { + theta_cut_max = TMath::Sqrt( theta_cut_max ); + } + else + { + theta_cut_max = 0.; + } + } + ///////////////////////////////////////////// + // use a graph with theta2 cuts + else if( fDirectionCutSelector == 5 && getTheta2Cut_TMVA_max() ) + { + theta_cut_max = getEnergyDependentCut( e, getTheta2Cut_TMVA_max(), true, true ); + if( theta_cut_max < 0. ) + { + theta_cut_max = 0.; + } + // set minimum theta2 cut + if( theta_cut_max < fTMVAFixedThetaCutMin ) + { + theta_cut_max = fTMVAFixedThetaCutMin; + } + } } // apply scale factors diff --git a/src/VGlobalRunParameter.cpp b/src/VGlobalRunParameter.cpp index 2b54dc725..cab9ceff3 100644 --- a/src/VGlobalRunParameter.cpp +++ b/src/VGlobalRunParameter.cpp @@ -223,21 +223,6 @@ bool VGlobalRunParameter::setDirectories() exit( EXIT_FAILURE ); } - ////////////////////////////////////////////////////////////////////// - // some scripts require a temporary directory for auxiliary files - // if note set: use fEVNDISPAnaDataDirectory - // important: no access control here - const char* vtmp_aux = gSystem->Getenv( "VERITAS_EVNDISP_TMP_AUX_DIR" ); - if( vtmp_aux ) - { - fEVNDISPAnaDataDirectory_tmp = vtmp_aux; - fEVNDISPAnaDataDirectory_tmp += "/"; - } - else - { - fEVNDISPAnaDataDirectory_tmp = fEVNDISPAnaDataDirectory; - } - return true; } @@ -329,10 +314,6 @@ void VGlobalRunParameter::printGlobalRunParameter() if( fEVNDISPAnaDataDirectory.size() > 0 ) { cout << " for EVNDISP aux data: \t\t" << fEVNDISPAnaDataDirectory << endl; - if( fEVNDISPAnaDataDirectory_tmp != fEVNDISPAnaDataDirectory ) - { - cout << " for temporary EVNDISP aux data: \t\t" << fEVNDISPAnaDataDirectory_tmp << endl; - } } if( fVBFRawDataDirectory.size() > 0 ) { @@ -365,7 +346,6 @@ string VGlobalRunParameter::fEVNDISP_VERSION = "v.4.90"; string VGlobalRunParameter::fDBServer = ""; string VGlobalRunParameter::fRawDataServer = ""; string VGlobalRunParameter::fEVNDISPAnaDataDirectory = ""; -string VGlobalRunParameter::fEVNDISPAnaDataDirectory_tmp = ""; string VGlobalRunParameter::fEVNDISPCalibrationDataDirectory = ""; string VGlobalRunParameter::fVBFRawDataDirectory = ""; string VGlobalRunParameter::fEVNDISPOutputDirectory = ""; diff --git a/src/VIPRCalculator.cpp b/src/VIPRCalculator.cpp new file mode 100644 index 000000000..deb774d78 --- /dev/null +++ b/src/VIPRCalculator.cpp @@ -0,0 +1,748 @@ +/*! \class IPRCalculator + * \brief calculation and save IPR GRAPH + * + * */ + +#include "VIPRCalculator.h" + +VIPRCalculator::VIPRCalculator() +{ + fIPRTimeSlices = true; + fIPRAverageTel = false; + fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements +} + +void VIPRCalculator::initialize() +{ + if( fDebug ) + { + cout << "VIPRCalculator::initialize()" << endl; + } + + // set the data readers + initializeDataReader(); + if( !initializeDataReader() ) + { + cout << "VIPRCalculator::initialize, error: cannot initialize data readers" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + + +} + +void VIPRCalculator::definePedestalFile( std::vector fPedFileNameC ) +{ + fPedFile = fPedFileNameC; +} + + +TFile* VIPRCalculator::initializePedestalFile( int i_tel ) +{ + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return nullptr; + } + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << getTelType( getTeltoAna()[i_tel] ) << ": "; + cout << "reading IPR histograms for summation window " << getSumWindow(); + cout << " from "; + cout << iPedFileName << endl; + return iPedFile; + +} + +float VIPRCalculator::getTsearch() +{ + float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); + if( getSearchWindowLast() < getNSamples() ) + { + Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] + } + else + { + Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] + } + return Tsearch; +} + +float VIPRCalculator::convertRate( unsigned int i_tel) +{ + // convert to Rate + float nsToSec = 1E-9; + float convToHz = 1.; + if( nsToSec > 0. && getTsearch() > 0. ) + { + convToHz /= ( nsToSec * getTsearch() ); + } + else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) + { + // simple peak sensing: sim_telarray uses the maximum bin only + // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file + // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as + // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns + // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. + convToHz /= ( nsToSec + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); + } + return convToHz; + +} + + +/* + HANDLING OF IPR FOR NO TIME SLICE CASE + +*/ + +TH1F* VIPRCalculator::initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + //get reference hpedPerTelescopeType for channel 1 + cout << "VIPRCalculator::initializeIPRHistogram initializing IPR graph for calculation of average of telescopes." << endl; + TH1F* hIPR = 0; + + TFile* iPedFile = (TFile*)initializePedestalFile( i_tel ); + if( iPedFile == nullptr ) + { + return hIPR; + } + + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + //cout << "VIPRCalculator::initializeIPRHistogram Telescope type:" << iTelType << endl; + //cout << "reading IPR histograms for summation window " << iSummationWindow; + + stringstream Directory( stringstream::in | stringstream::out ); + Directory << "distributions_" << iTelType; + if( !iPedFile->Get( Directory.str().c_str() ) ) + { + return hIPR; + } + + // get charge distribution for first channel as reference fpedcal_histo_storagegram + stringstream hIPRname( stringstream::in | stringstream::out ); + hIPRname << "distributions_" << iTelType << "/hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << 1; + + //? + TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); + iPedFile->Close(); + + if( !href ) + { + cout << " Error: cannot find IPR histogram" << hIPRname.str().c_str(); + return hIPR; + } + //summary fpedcal_histo_storagegram + if( getRunParameter()->fIgnoreDSTGains ) + { + // work in dc + hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); + cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; + return hIPR; + } + else + { + // work in pe + hIPR = new TH1F( "", "", 1000, 0., 100. ); + return hIPR; + } +} + +TH1F* VIPRCalculator::FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, i_tel ); + // check suffix of ped file + TFile* iPedFile = (TFile*)initializePedestalFile( i_tel ); + + stringstream i_Directory( stringstream::in | stringstream::out ); + i_Directory << "distributions_" << iTelType; + if( iPedFile->Get( i_Directory.str().c_str() ) ) + { + iPedFile->cd( i_Directory.str().c_str() ); + } + + float i_gainCorrect = 1.; + //hIPR->Reset(); + // //float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + iPedFile->Close(); + return hIPR; +} + +/* +IN CASE IPR IS GIVEN AS AVERAGE OF TELESCOPES, FOR TEL > 0 COPY IPR CALCULATED FOR TEL = 0. +*/ + +bool VIPRCalculator::copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[0] ); + TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[i_tel] ); + + if( !i_IPRGraph ) + { + cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << iTelType << endl; + return false; + } + if( !i_IPRGraph_Tel0 ) + { + cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; + return false; + } + + for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) + { + i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); + } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); + i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); + i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", iTelType, iSummationWindow ) ); + + return true; + +} + +TH1F* VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ) +{ + + TH1F* hIPR = ( TH1F* )initializeIPRHistogram(iSummationWindow , 0); + int iTelType = getTelType( getTeltoAna()[i_tel] ); + + for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) + { + setTelID( getTeltoAna()[teltype] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + TFile* iPedFile = (TFile*)initializePedestalFile( teltype ); + if( iPedFile == nullptr ) + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices error reading IPR graphs from pedestal file "; + TH1F* hNull = 0; + return hNull; + } + + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices Telescope type " << iTelType << ": "; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << iTelType; + if( iPedFile->Get( Directory.str().c_str() ) ) + { + iPedFile->cd( Directory.str().c_str() ); + } + else + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices no directory: " << Directory.str().c_str() << endl; + } + + /////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream HistName( stringstream::in | stringstream::out ); + HistName << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); + + + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream Pname( stringstream::in | stringstream::out ); + Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + if( i == 0){cout << "gain : " << getGains()[i] << endl;} + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + iPedFile->Close(); + + } + hIPR->Scale( 1. / getTeltoAna().size() ); + float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices normalization of average IPR fpedcal_histo_storagegram " << norm; + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices WARNING: there is NOT enough statistics "; + cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; + return hIPR; + } + else + { + cout << "VIPRCalculator::calculateIPRGraphsAveragedNoTimeSlices: there is enough statistics to average over telescopes. " << endl; + return hIPR; + } +} + +TGraphErrors* VIPRCalculator::updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow) +{ + + TGraphErrors* i_IPRGraph = new TGraphErrors( 1 ); + i_IPRGraph->SetTitle( "" ); + + int z = 0; + float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )getTelType( getTeltoAna()[i_tel] ), iSummationWindow ) ); + return i_IPRGraph; +} + +bool VIPRCalculator::calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ) +{ + TDirectory* iG_CurrentDirectory = gDirectory; + + // get an IPR graph + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + if( !i_IPRGraph ) + { + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices info: no IPR graph found for telescope type " << getTelType( getTeltoAna()[i_tel] ) << endl; + return false; + } + + ////////////////////////////////////////////////// + // average over all channels in one telescope + + TH1F *hIPR = (TH1F*)FillIPRHistogram( iSummationWindow, i_tel); + float norm = 0; + if (hIPR) + { + norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "norm: " << norm << endl; + } + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; + hIPR = calculateIPRGraphAveragedNoTimeSlices( iSummationWindow, i_tel ); + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; + return false; + } + i_IPRGraph = (TGraphErrors*)updateIPRGraph(hIPR, i_tel, iSummationWindow); + hIPR->Delete(); + iG_CurrentDirectory->cd(); + return true; +} + + +/* + + HANDLE IPR CALCULATION IF ASKED FOR IN TIME SLICES + +*/ + +void VIPRCalculator::checkHistEmpty(const int telID, const int ts, const int pixel, const int sw) +{ + if (fpedcal_histo_storage[telID][ts][pixel][sw]->GetEntries() != 0) + { + cout << "MK " << telID << " " << ts << " " << pixel << " " << sw << " " << fpedcal_histo_storage[telID][ts][pixel][sw]->GetEntries() << endl; + } +} + +vector>>> VIPRCalculator::getStorageHist() +{ + return fpedcal_histo_storage; +} + +void VIPRCalculator::fillIPRPedestalHisto(){ + fpedcal_histo_storage.resize(getTeltoAna().size()); +} + +void VIPRCalculator::fillIPRPedestalHisto(const int telID, const vector>>& fpedcal_histo ) +{ + fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); +} + + +TH1F* VIPRCalculator::getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw){ + + if (fpedcal_histo_storage.empty()){cout << "empty" << endl;} + if(fpedcal_histo_storage[telID][ts][pixel][sw]) + { + return fpedcal_histo_storage[telID][ts][pixel][sw]; + } + else + { + return nullptr; + } +} + +//needs sliding window fpedcal_histo_storagegram!! +bool VIPRCalculator::calculateIPRGraphsTimeSlices(const int TimeSlice, const int iSummationWindow, const int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TDirectory* iG_CurrentDirectory = gDirectory; + TGraphErrors* i_IPRGraph = getIPRGraphTimeSlice( true, TimeSlice ); + + TFile* iPedFile = (TFile*)initializePedestalFile( i_tel ); + if(iPedFile == nullptr) + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices could not open pedestal file for telescope: " << iTelType; + return false; + } + + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices for Telescope type " << iTelType << ": "; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << iTelType; + if( iPedFile->Get( Directory.str().c_str() ) ) + { + iPedFile->cd( Directory.str().c_str() ); + } + else + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices no directory: " << Directory.str().c_str() << endl; + } + + //Simplify: always do this in digital counts. No need to check for initialization. + TH1F *hIPR = new TH1F( "", "", 1000, 0., 100. ); + float i_gainCorrect = 1.; + + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 && i < getDead().size() && !getDead()[i] ) + { + + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hped_Tel" << iTelType << "_TS" << TimeSlice << "_Pix" << i << "_SW" << iSummationWindow; + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + + if(h) + { + float ped = 0; + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getCalData()->getPedsTS_vector( false )[TimeSlice][i]; + } + for( unsigned int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + //hIPR->Fill( ( h[i_tel][TimeSlice][i][iSummationWindow]->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h[i_tel][TimeSlice][i][iSummationWindow]->GetBinContent( j ) ); + hIPR->Fill( ( h->GetBinCenter( 0 ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( 0 ) ); + } + } + } + } + } + } + int z = 0; + float norm = 0; + if (hIPR) + { + norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "norm: " << norm << endl; + } + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "VIPRCalculator::calculateIPRGraphTimeSlices WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; + //hIPR = calculateIPRGraphAveragedNoTimeSlices( fPedFileNameC , iSummationWindow, i_tel ); + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; + return false; + } + + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d_TS%d", iTelType, iSummationWindow, TimeSlice ) ); + hIPR->Delete(); + iPedFile->Close(); + iG_CurrentDirectory->cd(); + + return true; + +} + +/* + * calculate IPR graphs and write them to disk + * + * (loop over all telescopes) + * +*/ + +bool VIPRCalculator::calculateIPRGraphs(std::vector fPedFileNameC) +{ + + definePedestalFile(fPedFileNameC); + for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) + { + setTelID( getTeltoAna()[i] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + if( fIPRAverageTel == false ) + { + calculateIPRGraphsNoTimeSlices( getSumWindow(), i ); + } + else + { + copyIPRInitialized( getSumWindow(), i ); + } + + if(fIPRTimeSlices){ + for (unsigned int ts = 0 ; ts < getCalData()->getPedsTS_vector( false ).size() ; ts++ ) + { + cout << "MK ts: " << getCalData()->getPedsTS_vector( false ).size() << endl; + calculateIPRGraphsTimeSlices( ts, getSumWindow(), i); + } + } + } + return true; +} + + +/* + * + * write IPR graphs to disk (one per telescope type) + * + */ +bool VIPRCalculator::writeIPRgraphs( map>> &hped_vec, string iFile ) +{ + TFile* fgraphs = 0; + if( iFile.size() == 0 ) + { + fgraphs = new TFile( getRunParameter()->fIPRdatabaseFile, "RECREATE" ); + } + else + { + fgraphs = new TFile( iFile.c_str(), "UPDATE" ); + } + if( fgraphs->IsZombie() ) + { + cout << "VIPRCalculator::writeIPRgraphs error opening IPR output file: " << endl; + cout << "\t" << fgraphs->GetName() << endl; + return false; + } + + // tree with conditions for these IRPs + TTree* header = new TTree( "IPRheader", "IPR parameters" ); + unsigned int sumwin = 0; // [FADC slices] + unsigned int Nsamples = 0; // [FADC slices] + float ROwin = 0.; // [ns] + float FADCslice = 0.; // [ns] + unsigned int SignalExtractor = 0; // [ Selected Extractor ] + header->Branch( "SignalExtractor", &SignalExtractor, "SignalExtractor/i" ); + header->Branch( "SummationWindow", &sumwin, "SummationWindow/i" ); + header->Branch( "Nsamples", &Nsamples, "Nsamples/i" ); + header->Branch( "FADCtimeSlice", &FADCslice, "FADCtimeSlice/F" ); + header->Branch( "ReadoutWindow", &ROwin, "ReadoutWindow/F" ); + + // one graph per telescope ID + map< ULong64_t, bool > iTelDone; + for( unsigned int i = 0; i < getDetectorGeometry()->getTelType_list().size(); i++ ) + { + iTelDone[getDetectorGeometry()->getTelType_list()[i]] = false; + } + + for( unsigned int i = 0; i < getNTel(); i++ ) + { + setTelID( i ); + if( iTelDone[getTelType( i )] ) + { + continue; + } + + if( hped_vec.find( getTelType( i ) ) == hped_vec.end() ) + { + continue; + } + + // loop over all summation windows + for( unsigned int j = 0; j < hped_vec[getTelType( i )].size(); j++ ) + { + // summation window + int i_sw = j + 1; + + TGraphErrors* g = getIPRGraph( i_sw, false ); + if( !g ) + { + continue; + } + SignalExtractor = getRunParameter()->fTraceIntegrationMethod.at( getTelID() ); + sumwin = i_sw; + Nsamples = getNSamples(); + FADCslice = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); //[ns] + ROwin = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * ( float )getNSamples(); // [ns] + + header->Fill(); + g->Write(); + } + + iTelDone[getTelType( i )] = true; + } + header->Write(); + fgraphs->Close(); + fgraphs->Delete(); + + return true; +} diff --git a/src/VImageBaseAnalyzer.cpp b/src/VImageBaseAnalyzer.cpp index 8e61f0053..6546918e8 100644 --- a/src/VImageBaseAnalyzer.cpp +++ b/src/VImageBaseAnalyzer.cpp @@ -863,6 +863,17 @@ void VImageBaseAnalyzer::findDeadChans( bool iLowGain, bool iFirst ) } // reset dead channel vector + /* + // this is duplicated code, simplify + if( fRunPar->fMCNdead && iFirst ) + { + setDead( false, iLowGain ); + } + else + { + setDead( false, iLowGain ); + } + */ setDead( false, iLowGain ); // get mean and rms of pedvar diff --git a/src/VImageCleaning.cpp b/src/VImageCleaning.cpp index eab1846ca..b483140c6 100644 --- a/src/VImageCleaning.cpp +++ b/src/VImageCleaning.cpp @@ -22,7 +22,21 @@ VImageCleaning::VImageCleaning( VEvndispData* iData ) if( fData && fData->getImageCleaningParameter()->getImageCleaningMethod() == "TIMENEXTNEIGHBOUR" ) { kInitNNImageCleaning = InitNNImageCleaning(); + cout << "1" << endl; + //if ( fIPRTimeSlices ) + if ( true ) + { + fIPRTSgraphs.resize(VDST_PEDTIMESLICES); + for (unsigned int i = 0; i < fIPRTSgraphs.size(); ++i) { + //fIPRTSgraphs[i].push_back(new TObjArray( VDST_MAXTELTYPES )); + fIPRTSgraphs[i] = new TObjArray( VDST_MAXTELTYPES ); + } + cout << typeid(fIPRTSgraphs[0]).name() << endl; + cout << "finished resizing" << endl; + } + fIPRgraphs = new TObjArray( VDST_MAXTELTYPES ); + } fWriteGraphToFileRecreate = true; @@ -426,6 +440,36 @@ bool VImageCleaning::InitNNImageCleaning() } +/* + * Initialize IPR graph per telescope and time slice + */ + +bool VImageCleaning::InitNNImgClnPerTelTypeTimeSlice( unsigned int teltype, unsigned int ts ) +{ + + TGraphErrors* IPRgraph = NULL; + IPRgraph = fData->getIPRGraphTimeSlice( false, ts ); + if( IPRgraph ) + { + cout << "\t found graph: " << IPRgraph->GetName() << endl; + IPRgraph->SetName( Form( "IPRchargeTelType%dTS%d", teltype, ts ) ); + } + else + { + cout << "VImageCleaning::InitNNImgClnPerTelTypeTimeSlice( int type ) ERROR: IPR graph is NULL for teltype " << teltype << " and time slice " << ts << " !!!" << endl; + ////printDataError( "" ); + } + //*** + if(fIPRTSgraphs[ts]){ + fIPRTSgraphs[ts]->AddAt(IPRgraph, teltype); + } + //cout << "IPR for TelType (TrigSim, TIMENEXTNEIGHBOUR): " << teltype << " read: " << IPRgraph->GetName(); + cout << endl; + return true; + +} + + /* get IPR graphs from different sources (files), calculate probability contours @@ -546,6 +590,7 @@ bool VImageCleaning::InitNNImgClnPerTelType( unsigned int teltype ) iFileN = "RECREATE"; } ostringstream i_NNGraphFileName; + cout << "MK name " << gSystem->DirName( fData->getRunParameter()->foutputfileName.c_str() ) << endl; i_NNGraphFileName << gSystem->DirName( fData->getRunParameter()->foutputfileName.c_str() ); i_NNGraphFileName << "/" << fData->getRunParameter()->frunnumber << ".IPR.root"; TFile* fgraphs = new TFile( i_NNGraphFileName.str().c_str(), iFileN.c_str() ); @@ -2000,6 +2045,7 @@ void VImageCleaning::cleanNNImageFixed( VImageCleaningRunParameter* iImageCleani fifActiveNN[teltype] = iImageCleaningParameters->fNNOpt_ActiveNN; } // initiate probability contours + InitNNImgClnPerTelTypeTimeSlice( 0, 0 ); kInitNNImgClnPerTelType[teltype] = InitNNImgClnPerTelType( teltype ); } diff --git a/src/VInstrumentResponseFunctionRunParameter.cpp b/src/VInstrumentResponseFunctionRunParameter.cpp index 5b0b2093a..9694a9295 100644 --- a/src/VInstrumentResponseFunctionRunParameter.cpp +++ b/src/VInstrumentResponseFunctionRunParameter.cpp @@ -16,7 +16,7 @@ VInstrumentResponseFunctionRunParameter::VInstrumentResponseFunctionRunParameter fSpectralIndexMin = 2.0; fSpectralIndexStep = 0.1; - fEnergyReconstructionMethod = 1; + fEnergyReconstructionMethod = 0; fEnergyAxisBins_log10 = 60; fIgnoreEnergyReconstructionQuality = false; @@ -471,7 +471,6 @@ bool VInstrumentResponseFunctionRunParameter::readRunParameters( string ifilenam { fObservatory = i_runPara->getObservatory(); fInstrumentEpoch = i_runPara->fInstrumentEpoch; - fInstrumentEpochATM = i_runPara->getInstrumentATMString(); fTelToAnalyse = i_runPara->fTelToAnalyze; } else @@ -479,7 +478,6 @@ bool VInstrumentResponseFunctionRunParameter::readRunParameters( string ifilenam cout << "VInstrumentResponseFunctionRunParameter::readRunParameters() warning: cannot read instrument epoch and active telecopes from MC event file" << endl; cout << "this might lead to a wrong choice in the gamma/hadron cuts - please check" << endl; fInstrumentEpoch = "NOT_FOUND"; - fInstrumentEpochATM = "NOT_FOUND"; } // get NSB (pedvar) level VTableLookupRunParameter* fR = ( VTableLookupRunParameter* )iFile->Get( "TLRunParameter" ); @@ -608,9 +606,7 @@ void VInstrumentResponseFunctionRunParameter::print() } if( fInstrumentEpoch != "NOT_SET" ) { - cout << "Instrument epoch: " << fInstrumentEpoch; - cout << " (" << fInstrumentEpochATM << ")"; - cout << endl; + cout << "Instrument epoch: " << fInstrumentEpoch << endl; } else { diff --git a/src/VMonteCarloRateCalculator.cpp b/src/VMonteCarloRateCalculator.cpp index d9e349731..4868d99f0 100644 --- a/src/VMonteCarloRateCalculator.cpp +++ b/src/VMonteCarloRateCalculator.cpp @@ -38,6 +38,7 @@ VMonteCarloRateCalculator::VMonteCarloRateCalculator( string ifile ) fMCTree->SetBranchAddress( "noise", &fnoise ); fMCTree->SetBranchAddress( "nrates", &fnrates ); fMCTree->SetBranchAddress( "MCrate", fMCrate ); + } @@ -128,10 +129,9 @@ double VMonteCarloRateCalculator::getMonteCarloRate( vector< double >& e, vector if( bDebug ) { cout << "VMonteCarloRateCalculator::getMonteCarloRate " << e.size() << "\t" << eff.size() << endl; - cout << "\t Gamma " << i_gamma; - cout << scientific << " phi: " << i_phi << fixed << " E0: " << iE0; + cout << "\t Gamma " << i_gamma << " phi: " << i_phi << " E0: " << iE0; cout << " EMin: " << iEMin << " EMax: " << iEMax; - cout << " Rate [1/s]: " << iTot << " Rate [1/min]: " << iTot * 60. << endl; + cout << "Rate [1/s]: " << iTot << " Rate [1/min]: " << iTot * 60. << endl; } if( e.size() != eff.size() || e.size() <= 2 ) { diff --git a/src/VPedestalCalculator.cpp b/src/VPedestalCalculator.cpp index 1bafb52a2..1ba7fb709 100644 --- a/src/VPedestalCalculator.cpp +++ b/src/VPedestalCalculator.cpp @@ -16,7 +16,6 @@ VPedestalCalculator::VPedestalCalculator() fSumWindow = 24; fNPixel = 500; fSumFirst = 0; - bCalibrationRun = false; } @@ -76,9 +75,9 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe reset(); // pedestal histogram binning - int i_hist_nbin = 2000.; + int i_hist_nbin = 1500.; float i_hist_xmin = 0.; - float i_hist_xmax = 2000.; + float i_hist_xmax = 750.; // set up the trees TDirectory* iDir = gDirectory; @@ -164,7 +163,7 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe // initialise the pedvars variables iped_cal2.clear(); - iped_histo2.clear(); + iped_histo.clear(); for( unsigned int p = 0; p < fNPixel; p++ ) { iped_cal.clear(); @@ -172,7 +171,7 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe for( int w = 0; w < fSumWindow; w++ ) { iped_cal.push_back( 0. ); - sprintf( hname, "hped_cal_%d_%d_%d", t + 1, p, w ); + sprintf( hname, "hped_cal_%d_%d_%d", i, p, w ); iped_histo.push_back( new TH1F( hname, "", i_hist_nbin, i_hist_xmin, i_hist_xmax ) ); @@ -184,9 +183,11 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe fpedcal_mean.push_back( iped_cal2 ); fpedcal_mean2.push_back( iped_cal2 ); fpedcal_histo.push_back( iped_histo2 ); - + fpedcal_histo_sw.push_back( iped_histo2 ); + // define the time vector fTimeVec.push_back( 0 ); + NTimeSlices.push_back( 0 ); } iDir->cd(); @@ -194,7 +195,6 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe { cout << "END: VPedestalCalculator::initialize " << endl; } - return true; } @@ -251,6 +251,7 @@ void VPedestalCalculator::fillTimeSlice( unsigned int telID ) fpedcal_n[telID][p][w] = 0.; fpedcal_mean[telID][p][w] = 0.; fpedcal_mean2[telID][p][w] = 0.; + fpedcal_histo_sw[telID][p][w]->Reset(); fpedcal_histo[telID][p][w]->Reset(); } // deroate the pixel coordinates @@ -277,7 +278,7 @@ void VPedestalCalculator::fillTimeSlice( unsigned int telID ) } -void VPedestalCalculator::doAnalysis( bool iLowGain ) +void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalculator ) { double t = getEventTime(); // get right index for tel id @@ -290,7 +291,6 @@ void VPedestalCalculator::doAnalysis( bool iLowGain ) break; } } - // temporary vectors if( telID < fTimeVec.size() ) { @@ -304,12 +304,21 @@ void VPedestalCalculator::doAnalysis( bool iLowGain ) else if( t - fTimeVec[telID] > fLengthofTimeSlice ) { time = t; + if (NTimeSlices[telID] == 0 and telID == 0){ + fIPRCalculator->fillIPRPedestalHisto(); + } + + NTimeSlices[telID]+=1; + + fIPRCalculator->fillIPRPedestalHisto(telID, fpedcal_histo); fillTimeSlice( telID ); + fTimeVec[telID] = t; } // if( t - fTimeVec[telID] > fLengthofTimeSlice ) /////////////////////////////////////////////////////// double i_tr_sum = 0.; + double i_tr_sum_sw = 0.; // calculate the sums (don't use calcsums because it overwrites getSums() ) // and fill the histograms for( unsigned int i = 0; i < getNChannels(); i++ ) @@ -345,10 +354,15 @@ void VPedestalCalculator::doAnalysis( bool iLowGain ) { // calculate trace sum i_tr_sum = fTraceHandler->getTraceSum( fSumFirst, fSumFirst + ( w + 1 ), true, 1 ); + i_tr_sum_sw = fTraceHandler->getTraceSum( fSumFirst, fSumFirst + ( w + 1 ), false, 1 ); if( i_tr_sum > 0. && i_tr_sum < 50.*( w + 1 ) ) { if( chanID < fpedcal_n[telID].size() && w < fpedcal_n[telID][chanID].size() ) { + if( i_tr_sum_sw > 0. && i_tr_sum_sw < 50.*( w + 1 ) ) + { + fpedcal_histo_sw[telID][chanID][w]->Fill( i_tr_sum_sw ); + } fpedcal_n[telID][chanID][w]++; fpedcal_mean[telID][chanID][w] += i_tr_sum; fpedcal_mean2[telID][chanID][w] += i_tr_sum * i_tr_sum; @@ -380,7 +394,6 @@ void VPedestalCalculator::doAnalysis( bool iLowGain ) } // if( telID < fTree.size() && fTree[telID] && telID < fTimeVec.size() ) } - void VPedestalCalculator::terminate( bool iWrite, bool iDebug_IO ) { if( iWrite ) diff --git a/src/VPlotAnasumHistograms.cpp b/src/VPlotAnasumHistograms.cpp index 5eb06115b..1668784bd 100644 --- a/src/VPlotAnasumHistograms.cpp +++ b/src/VPlotAnasumHistograms.cpp @@ -645,9 +645,10 @@ void VPlotAnasumHistograms::plot_CorrelatedSkyPlots() * * */ -TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irbin, double setYMax, double setYMin ) +TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irbin ) { // int iPlotPSF = 0; + double setYMax = -1.; char hname[200]; char htitle[200]; @@ -663,23 +664,28 @@ TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irb // canvas that will contain the theta2 and the theta2_diff plots TCanvas* c_t2 = 0; - TCanvas* c_t2_diff = 0; if( htheta2_diff && htheta2_on && htheta2_off ) { sprintf( hname, "c_t2_%d", fRunNumber ); sprintf( htitle, "theta2 (run %d)", fRunNumber ); - c_t2 = new TCanvas( hname, htitle, 10, 10, 400, 400 ); - sprintf( hname, "c_t2_diff_%d", fRunNumber ); - c_t2_diff = new TCanvas( hname, htitle, 410, 10, 400, 400 ); - c_t2_diff->SetLeftMargin( 0.12 ); + c_t2 = new TCanvas( hname, htitle, 10, 10, 900, 400 ); + c_t2->Divide( 2, 1 ); + //c_t2->SetLeftMargin( 0.12 ); - c_t2->cd(); + c_t2->cd( 1 ); htheta2_on->SetXTitle( "#Theta^{2} [deg^{2}]" ); htheta2_on->SetTitle( "" ); htheta2_off->SetTitle( "#Theta^{2} Histogram" ); htheta2_off->SetTitle( "" ); - htheta2_off->SetMaximum( htheta2_on->GetMaximum() * 1.1 ); + if( setYMax < 0. ) + { + htheta2_off->SetMaximum( htheta2_on->GetMaximum() * 1.1 ); + } + else + { + htheta2_off->SetMaximum( setYMax ); + } sprintf( hname, "Number of events / %.3f deg^{2}", htheta2_off->GetXaxis()->GetBinWidth( 2 ) ); htheta2_on->SetYTitle( hname ); htheta2_off->SetYTitle( hname ); @@ -710,24 +716,15 @@ TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irb } } - c_t2_diff->cd(); - htheta2_diff->SetFillColor( 418 ); + c_t2->cd( 2 ); + htheta2_diff->SetFillColor( 8 ); htheta2_diff->SetXTitle( "#Theta^{2} [deg^{2}]" ); htheta2_diff->SetTitle( "" ); sprintf( hname, "Number of events / %.3f deg^{2}", htheta2_diff->GetXaxis()->GetBinWidth( 2 ) ); htheta2_diff->SetYTitle( hname ); - htheta2_diff->GetYaxis()->SetTitleOffset( 1.6 ); - setHistogramPlottingStyle( htheta2_diff, 418, 2, 1, 1, irbin, 1001 ); + htheta2_diff->GetYaxis()->SetTitleOffset( 1.4 ); + setHistogramPlottingStyle( htheta2_diff, 1, 2, 1, 1, irbin, 1001 ); htheta2_diff->SetAxisRange( t2min, t2max ); - if( setYMax > -999. ) - { - htheta2_diff->SetMaximum( setYMax ); - } - if( setYMin > -999. ) - { - htheta2_diff->SetMinimum( setYMin ); - } - htheta2_diff->Draw( "hist e" ); @@ -760,7 +757,7 @@ TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irb cout << "histograms not found" << endl; } - return c_t2_diff; + return c_t2; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/VPlotCompareDataWithMC.cpp b/src/VPlotCompareDataWithMC.cpp index 7b3ce5f8b..fedea67ed 100644 --- a/src/VPlotCompareDataWithMC.cpp +++ b/src/VPlotCompareDataWithMC.cpp @@ -13,7 +13,6 @@ VPlotCompareDataWithMC::VPlotCompareDataWithMC( string iFile ) setNTel(); setPrintName(); setRelativePlotRange(); - setScalingMethod(); fDataFileName = iFile; fDataFile = 0; @@ -128,28 +127,15 @@ void VPlotCompareDataWithMC::plotLegend( TH1D* hsims, TH1D* hdiff, double x0 ) iLegend->Draw(); } -void VPlotCompareDataWithMC::setScalingMethod( int iScalingMethod ) -{ - if( iScalingMethod > 0 && iScalingMethod < 4 ) - { - fScalingMethod = iScalingMethod; - return; - } - cout << "Error setting scaling method; should be in [1,3]" << endl; - cout << "Exiting..." << endl; - exit( EXIT_FAILURE ); -} - - /*! get scale factor between simulations and data - iScalingMethod = 1: scale to same contents - iScalingMethod = 2: scale to same maximum value - iScalingMethod = 3: scale to same maximum value (three bins around maximum) + bContents = 1: scale to same contents + bContents = 2: scale to same maximum value + bContents = 3: scale to same maximum value (three bins around maximum) */ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_sims, double& s_diff, - int iScalingMethod, double xmin, double xmax ) + int bContents, double xmin, double xmax ) { if( !h_sims || !h_diff ) { @@ -158,7 +144,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s double z = 0.; //////////////////////////////////// // scale to same contents (integral) - if( iScalingMethod == 1 ) + if( bContents == 1 ) { int i_min = 1; int i_max = h_sims->GetNbinsX(); @@ -188,7 +174,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s } for( int i = i_min; i <= i_max; i++ ) { - // if( h_diff->GetBinContent( i ) > 0 ) + if( h_diff->GetBinContent( i ) > 0 ) { z += h_diff->GetBinContent( i ); } @@ -203,7 +189,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s } ////////////////////////////////// // scale to same maximum - else if( iScalingMethod == 2 ) + else if( bContents == 2 ) { s_sims = h_sims->GetMaximum(); z = h_diff->GetMaximum(); @@ -216,7 +202,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s } ////////////////////////////////// // scale to peak (three bins around maximum) - else if( iScalingMethod == 3 ) + else if( bContents == 3 ) { int imaxbin = h_sims->GetMaximumBin(); s_sims = h_sims->GetBinContent( imaxbin ); @@ -257,7 +243,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s } void VPlotCompareDataWithMC::getScaling( double& s_sims, double& s_diff, string his, - int iScalingMethod, double xmin, double xmax ) + int bContents, double xmin, double xmax ) { if( fDataFile == 0 ) { @@ -267,15 +253,15 @@ void VPlotCompareDataWithMC::getScaling( double& s_sims, double& s_diff, string return; } cout << "scale on histograms " << his << ", scale to"; - if( iScalingMethod == 1 ) + if( bContents == 1 ) { cout << " histogram contents" << endl; } - else if( iScalingMethod == 2 ) + else if( bContents == 2 ) { cout << " histogram maximum" << endl; } - else if( iScalingMethod == 3 ) + else if( bContents == 3 ) { cout << " histogram maximum (peak)" << endl; } @@ -293,7 +279,7 @@ void VPlotCompareDataWithMC::getScaling( double& s_sims, double& s_diff, string return; } - getScaling( h_sims, h_diff, s_sims, s_diff, fScalingMethod, xmin, xmax ); + getScaling( h_sims, h_diff, s_sims, s_diff, bContents, xmin, xmax ); } @@ -508,7 +494,7 @@ void VPlotCompareDataWithMC::multiplicity_plots() // get the scaling between simulations and data double s_sims = 1.; double s_diff = 1.; - getScaling( s_sims, s_diff, "NImages", fScalingMethod ); + getScaling( s_sims, s_diff, "NImages", 1 ); char hname[600]; char htitle[600]; @@ -624,7 +610,7 @@ TCanvas* VPlotCompareDataWithMC::plot_singleCanvas( string iHistoName, string iC // get the scaling between simulations and data double s_sims = 1.; double s_diff = 1.; - getScaling( s_sims, s_diff, iScalingVariable, fScalingMethod, -9999., iHistoXAxisMax ); + getScaling( s_sims, s_diff, iScalingVariable, 1, -9999., iHistoXAxisMax ); sprintf( hname, "c%s_%s", iHistoName.c_str(), fDataFileName.c_str() ); sprintf( htitle, "%s (%s)", iCanvasTitle.c_str(), fDataFileName.c_str() ); @@ -838,8 +824,7 @@ TCanvas* VPlotCompareDataWithMC::plot_energyDependentDistributions( string iVari TH1D* hDiff = h_diff->ProjectionY( hname, i, i ); setHistogramAtt( hDiff, 1, 1, 1, 21, iRebin ); - // getScaling( hSims, hDiff, s_sims, s_diff, 3 ); - getScaling( hSims, hDiff, s_sims, s_diff, fScalingMethod ); + getScaling( hSims, hDiff, s_sims, s_diff, 3 ); if( hSims->GetEntries() > 0 ) { hSims->Scale( s_sims ); @@ -1028,7 +1013,7 @@ TCanvas* VPlotCompareDataWithMC::stereo_parameter() // get the scaling between simulations and data double s_sims = 1.; double s_diff = 1.; - getScaling( s_sims, s_diff, "theta2", fScalingMethod ); + getScaling( s_sims, s_diff, "theta2", 1 ); ht2_sims->Scale( s_sims ); ht2_diff->Scale( s_diff ); @@ -1060,7 +1045,7 @@ TCanvas* VPlotCompareDataWithMC::stereo_parameter() TH1D* hlt2_diff = ( TH1D* )fDataFile->Get( "hltheta2_DIFF" ); setHistogramAtt( hlt2_diff, 1, 3, 1, 25, 1 ); - getScaling( s_sims, s_diff, "ltheta2", fScalingMethod ); + getScaling( s_sims, s_diff, "ltheta2", 2 ); hlt2_sims->Scale( s_sims ); hlt2_diff->Scale( s_diff ); @@ -1092,7 +1077,7 @@ TCanvas* VPlotCompareDataWithMC::stereo_parameter() setHistogramAtt( hmscw_diff, 1, 1, 1, 25, 2 ); hmscw_sims->SetAxisRange( -1., 1. ); - getScaling( s_sims, s_diff, "MSCW", fScalingMethod, -0.5, 0.5 ); + getScaling( s_sims, s_diff, "MSCW", 2, -0.5, 0.5 ); if( hmscw_sims->GetEntries() > 0 ) { hmscw_sims->Scale( s_sims ); @@ -1133,7 +1118,7 @@ TCanvas* VPlotCompareDataWithMC::stereo_parameter() hmscl_diff->SetStats( 0 ); hmscl_sims->SetAxisRange( -1., 1. ); - getScaling( s_sims, s_diff, "MSCL", fScalingMethod, -0.75, 0.75 ); + getScaling( s_sims, s_diff, "MSCL", 1, -0.75, 0.75 ); if( hmscl_sims->GetEntries() > 0 ) { hmscl_sims->Scale( s_sims ); @@ -1214,7 +1199,7 @@ void VPlotCompareDataWithMC::mva_parameter() double error_diff = 0.; hmva_sims->SetAxisRange( -1., 1. ); - getScaling( s_sims, s_diff, "MVA", fScalingMethod, -0.75, 0.75 ); + getScaling( s_sims, s_diff, "MVA", 1, -0.75, 0.75 ); if( hmva_sims->GetEntries() > 0 ) { hmva_sims->Scale( s_sims ); @@ -1266,7 +1251,7 @@ void VPlotCompareDataWithMC::mva_parameter() * horrible code...programmer doesn't know what a loop is */ -TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin ) +TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin, int iScaling ) { if( !fDataFile ) { @@ -1308,7 +1293,7 @@ TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin ) double nSims = 0.; double nDiff = 0.; - getScaling( nSims, nDiff, "Xcore", fScalingMethod ); + getScaling( nSims, nDiff, "Xcore", iScaling ); hXcore_diff->Scale( nDiff ); hXcore_sims->Scale( nSims ); @@ -1347,7 +1332,7 @@ TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin ) hYcore_sims->SetAxisRange( -250., 250. ); hYcore_on->SetAxisRange( -250., 250. ); - getScaling( nSims, nDiff, "Ycore", fScalingMethod ); + getScaling( nSims, nDiff, "Ycore", iScaling ); hYcore_diff->Scale( nDiff ); hYcore_sims->Scale( nSims ); @@ -1378,7 +1363,7 @@ TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin ) setHistogramAtt( hArrayEl_diff, 1, 1, 1, 21, iRebin ); hArrayEl_sims->SetAxisRange( 40., 90. ); hArrayEl_on->SetAxisRange( 40., 90. ); - getScaling( nSims, nDiff, "ArrayEl", fScalingMethod ); + getScaling( nSims, nDiff, "ArrayEl", iScaling ); hArrayEl_diff->Scale( nDiff ); hArrayEl_sims->Scale( nSims ); @@ -1405,7 +1390,7 @@ TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin ) setHistogramAtt( hArrayAz_on, 3, 1, 1, 20, 1 ); setHistogramAtt( hArrayAz_off, 4, 1, 1, 20, 1 ); setHistogramAtt( hArrayAz_diff, 1, 1, 1, 21, 1 ); - getScaling( nSims, nDiff, "ArrayAz", fScalingMethod ); + getScaling( nSims, nDiff, "ArrayAz", iScaling ); hArrayAz_diff->Scale( nDiff ); hArrayAz_sims->Scale( nSims ); @@ -1627,7 +1612,7 @@ TCanvas* VPlotCompareDataWithMC::distance_plots() sprintf( hname, "r_%u", i + 1 ); - getScaling( s_sims, s_diff, hname, fScalingMethod ); + getScaling( s_sims, s_diff, hname, 1 ); if( hR_sims[i]->GetEntries() > 0 ) { hR_sims[i]->Scale( s_sims ); @@ -1754,7 +1739,8 @@ TCanvas* VPlotCompareDataWithMC::single_telescope( int telid ) return c; } -TCanvas* VPlotCompareDataWithMC::single_telescope( int telid, string iPlot, bool iOneCanvas, int i_rebin ) +TCanvas* VPlotCompareDataWithMC::single_telescope( int telid, string iPlot, bool iOneCanvas, + int iScalingMethod, int i_rebin ) { if( iPlot != "SIMSDIFF" && iPlot != "ONOFF" && iPlot != "REL" ) @@ -1775,7 +1761,7 @@ TCanvas* VPlotCompareDataWithMC::single_telescope( int telid, string iPlot, bool double s_diff = 1.; char htitle[600]; sprintf( htitle, "width_%d", telid ); - getScaling( s_sims, s_diff, htitle, fScalingMethod ); + getScaling( s_sims, s_diff, htitle, iScalingMethod ); ////////////////////////////////////// // histogram names to be plotted @@ -1937,7 +1923,7 @@ TCanvas* VPlotCompareDataWithMC::single_telescope( int telid, string iPlot, bool hon->Rebin( f_rebin[j] ); hoff->Rebin( f_rebin[j] ); sprintf( htitle, "%s_%d", hname[j].c_str(), telid ); - getScaling( s_sims, s_diff, htitle, fScalingMethod ); + getScaling( s_sims, s_diff, htitle, iScalingMethod ); // normalize sims histograms to data histograms hsims->Scale( s_sims ); if( TMath::Abs( s_diff - 1. ) > 1.e-2 ) @@ -2170,7 +2156,7 @@ void VPlotCompareDataWithMC::msc_plots( char* offFile, char* helium, char* proto // get the scaling between simulations and data double s_sims = 1.; double s_diff = 1.; - getScaling( s_sims, s_diff, ivar.c_str(), fScalingMethod ); + getScaling( s_sims, s_diff, ivar.c_str(), true ); hMSC_sims->SetAxisRange( xmin, xmax ); if( hMSC_sims->GetEntries() > 0 ) { @@ -2366,16 +2352,6 @@ void VPlotCompareDataWithMC::plot( string iPrintName ) { cP->Print( hname ); } - cP = plot_energyDependentDistributions( "MVA", 1, -0.75, 0.75, "SIMSDIFF" ); - if( cP ) - { - cP->Print( hname ); - } - cP = plot_energyDependentDistributions( "MVA", 1, -0.75, 0.75, "CUMU" ); - if( cP ) - { - cP->Print( hname ); - } // telescope dependent plots for( unsigned int i = 1; i <= 4; i++ ) { @@ -2563,7 +2539,7 @@ void VPlotCompareDataWithMC::plot( string iPrintName ) } for( unsigned int i = 1; i <= 4; i++ ) { - cP = plot_energyDependentDistributions( "disp", 2, -2., 2., "SIMSDIFF", i, -99., "Erec" ); + cP = plot_energyDependentDistributions( "disp", 2, -2.5, 2.5, "SIMSDIFF", i, -99., "Erec" ); if( cP ) { cP->Print( hname ); @@ -2571,7 +2547,7 @@ void VPlotCompareDataWithMC::plot( string iPrintName ) } for( unsigned int i = 1; i <= 4; i++ ) { - cP = plot_energyDependentDistributions( "disp", 2, -2., 2., "SIMSDIFF", i, -99., "size" ); + cP = plot_energyDependentDistributions( "disp", 2, -2.5, 2.5, "SIMSDIFF", i, -99., "size" ); if( cP ) { cP->Print( hname ); @@ -2579,7 +2555,7 @@ void VPlotCompareDataWithMC::plot( string iPrintName ) } for( unsigned int i = 1; i <= 4; i++ ) { - cP = plot_energyDependentDistributions( "disp", 2, -2., 2., "SIMSDIFF", i, -99., "ntubes" ); + cP = plot_energyDependentDistributions( "disp", 2, -2.5, 2.5, "SIMSDIFF", i, -99., "ntubes" ); if( cP ) { cP->Print( hname ); diff --git a/src/VPlotInstrumentResponseFunction.cpp b/src/VPlotInstrumentResponseFunction.cpp index 9acd19f50..2320dbb36 100644 --- a/src/VPlotInstrumentResponseFunction.cpp +++ b/src/VPlotInstrumentResponseFunction.cpp @@ -439,19 +439,19 @@ void VPlotInstrumentResponseFunction::plotEnergyReconstructionMatrix( unsigned i } char hname[200]; + char htitle[200]; sprintf( hname, "cEA_Ematrix_%d_%d_%d_%d", iDataSetID, bFineBinning, bQualityCuts, bInterPol ); - ostringstream htitle; - htitle << "energy reconstruction matrix (" << iDataSetID << "," << bInterPol << ")"; + sprintf( htitle, "energy reconstruction matrix (%d,%d)", iDataSetID, bInterPol ); if( bFineBinning ) { - htitle << " (fine binning)"; + sprintf( htitle, "%s (fine binning)", htitle ); } if( bQualityCuts ) { - htitle << " , QC"; + sprintf( htitle, "%s, QC", htitle ); } - TCanvas* iEnergyReconstructionMatrixCanvas = new TCanvas( hname, htitle.str().c_str(), 610, 10, fCanvasSize_X, fCanvasSize_Y ); + TCanvas* iEnergyReconstructionMatrixCanvas = new TCanvas( hname, htitle, 610, 10, fCanvasSize_X, fCanvasSize_Y ); iEnergyReconstructionMatrixCanvas->SetGridx( 0 ); iEnergyReconstructionMatrixCanvas->SetGridy( 0 ); iEnergyReconstructionMatrixCanvas->SetLeftMargin( 0.11 ); diff --git a/src/VPlotTMVAParameters.cpp b/src/VPlotTMVAParameters.cpp new file mode 100644 index 000000000..c7c11ce57 --- /dev/null +++ b/src/VPlotTMVAParameters.cpp @@ -0,0 +1,179 @@ +/* \class VPlotTMVAParameters + + plot signal and background efficiency, and MVA cut variable for different + subarrays from TMVA output files + + Example: + + .L lib/libVAnaSum.so + VPlotTMVAParameters a; + a.setSubArrays( "scripts/CTA/subArray.prod1-red.list"); + a.setDirectories( "$CTA_USER_DATA_DIR/analysis/AnalysisData/cta-ultra3/EffectiveArea-ID2-d20130415/QualityCuts001CU/" ); + a.initializeWeightFiles( "$CTA_USER_DATA_DIR/analysis/AnalysisData/cta-ultra3/", "TMVA/BDT-ID2-d20130415-0.0/BDT_", 0, 8 ); + +*/ + +#include "VPlotTMVAParameters.h" + +VPlotTMVAParameters::VPlotTMVAParameters() +{ + fDataDirectory = ""; +} + +void VPlotTMVAParameters::plot( bool iPrint ) +{ + char hname[2000]; + char htitle[2000]; + + for( unsigned int i = 0; i < hSignalEfficiency.size(); i++ ) + { + + // signal and background efficiency + sprintf( hname, "cTMVA_S_BC_%d", i ); + sprintf( htitle, "signal/background efficiency distribution (energy/zenith bin %d)", i ); + TCanvas* c = new TCanvas( hname, htitle, 100 + i * 20, 100 + i * 20, 400, 400 ); + c->SetGridx( 0 ); + c->SetGridy( 0 ); + + if( hSignalEfficiency[i] ) + { + hSignalEfficiency[i]->Draw(); + cout << "Signal efficiency in energy/zenith bin " << i << ": "; + cout << hSignalEfficiency[i]->GetMean() << " +- " << hSignalEfficiency[i]->GetRMS() << endl; + } + if( i < hBackgroundEfficiency.size() && hBackgroundEfficiency[i] && hBackgroundEfficiency[i]->GetEntries() > 0 ) + { + hBackgroundEfficiency[i]->Draw( "same" ); + cout << "\t Background efficiency in energy/zenith bin " << i << ": "; + cout << hBackgroundEfficiency[i]->GetMean() << " +- " << hBackgroundEfficiency[i]->GetRMS() << endl; + } + if( iPrint ) + { + sprintf( hname, "efficiency-%d.eps", i ); + c->Print( hname ); + } + + + // MVA cut variable + sprintf( hname, "cTMVA_MVA_%d", i ); + sprintf( htitle, "MVA cut variable(energy/zenith bin %d)", i ); + TCanvas* d = new TCanvas( hname, htitle, 600 + i * 20, 100 + i * 20, 400, 400 ); + d->SetGridx( 0 ); + d->SetGridy( 0 ); + + if( i < hMVA.size() ) + { + hMVA[i]->Draw(); + cout << "\t MVA cut in energy/zenith bin " << i << ": "; + cout << hMVA[i]->GetMean() << " +- " << hMVA[i]->GetRMS() << endl; + } + if( iPrint ) + { + sprintf( hname, "mva-%d.eps", i ); + d->Print( hname ); + } + } +} + +bool VPlotTMVAParameters::initializeHistograms( unsigned int iEnergyWeightFileIndex_min, unsigned int iEnergyWeightFileIndex_max, unsigned int iZenithWeightFileIndex_min, unsigned int iZenithWeightFileIndex_max ) +{ + char hname[2000]; + + hSignalEfficiency.clear(); + hBackgroundEfficiency.clear(); + hMVA.clear(); + + for( unsigned int i = iEnergyWeightFileIndex_min; i <= iEnergyWeightFileIndex_max; i++ ) + { + for( unsigned int j = iZenithWeightFileIndex_min; j <= iEnergyWeightFileIndex_max; j++ ) + { + sprintf( hname, "hSignalEfficiency_%d_%d", i, j ); + hSignalEfficiency.push_back( new TH1D( hname, "", 100, 0., 1. ) ); + hSignalEfficiency.back()->SetXTitle( "efficiency" ); + hSignalEfficiency.back()->SetLineWidth( 2 ); + + sprintf( hname, "hBackgroundEfficiency_%d_%d", i, j ); + hBackgroundEfficiency.push_back( new TH1D( hname, "", 100, 0., 1. ) ); + hBackgroundEfficiency.back()->SetXTitle( "efficiency" ); + hBackgroundEfficiency.back()->SetLineWidth( 2 ); + hBackgroundEfficiency.back()->SetLineColor( 2 ); + + sprintf( hname, "hMVA_%d_%d", i, j ); + hMVA.push_back( new TH1D( hname, "", 100, -1., 1. ) ); + hMVA.back()->SetXTitle( "MVA variable" ); + hMVA.back()->SetLineWidth( 2 ); + hMVA.back()->SetLineColor( 4 ); + } + } + + return true; +} + +void VPlotTMVAParameters::initializeWeightFiles( string iDirectory, string iTMVADirectory, unsigned int iEnergyWeightFileIndex_min, unsigned int iEnergyWeightFileIndex_max, unsigned int iZenithWeightFileIndex_min, unsigned int iZenithWeightFileIndex_max, double iParticleNumberFile_Conversion_Rate_to_seconds ) +{ + if( !initializeHistograms( iEnergyWeightFileIndex_min, iEnergyWeightFileIndex_max, iZenithWeightFileIndex_min, iZenithWeightFileIndex_max ) ) + { + cout << "VPlotTMVAParameters::initializeWeightFiles error initializing histograms" << endl; + return; + } + + // loop over all sub arrays, get efficiency from optimization and fill them into histograms + char hname[2000]; + for( unsigned int i = 0; i < fSubArrays.size(); i++ ) + { + VTMVAEvaluator a; + sprintf( hname, "%s/ParticleNumbers.%s.00.root", fDataDirectory.c_str(), fSubArrays[i].c_str() ); + a.setParticleNumberFile( hname, iParticleNumberFile_Conversion_Rate_to_seconds ); + sprintf( hname, "%s/%s/%s", iDirectory.c_str(), fSubArrays[i].c_str(), iTMVADirectory.c_str() ); + a.initializeWeightFiles( hname, iEnergyWeightFileIndex_min, iEnergyWeightFileIndex_max, iZenithWeightFileIndex_min, iZenithWeightFileIndex_max ); + + for( unsigned int j = 0; j < a.getOptimumCutValueFound().size(); j++ ) + { + if( a.getOptimumCutValueFound()[j] ) + { + if( j < a.getSignalEfficiency().size() && j < hSignalEfficiency.size() && hSignalEfficiency[j] ) + { + hSignalEfficiency[j]->Fill( a.getSignalEfficiency()[j] ); + } + if( j < a.getBackgroundEfficiency().size() && j < hBackgroundEfficiency.size() && hBackgroundEfficiency[j] ) + { + hBackgroundEfficiency[j]->Fill( a.getBackgroundEfficiency()[j] ); + } + if( j < a.getTMVACutValue().size() && j < hMVA.size() && hMVA[j] ) + { + hMVA[j]->Fill( a.getTMVACutValue()[j] ); + } + } + } + } +} + +bool VPlotTMVAParameters::setSubArrays( string iFileTxt ) +{ + fSubArrays.clear(); + + ifstream is; + is.open( iFileTxt.c_str(), ifstream::in ); + if( !is ) + { + return false; + } + + string is_line; + while( getline( is, is_line ) ) + { + fSubArrays.push_back( is_line ); + } + + if( fSubArrays.size() == 0 ) + { + cout << "VPlotTMVAParameters::setSubArrays: no arrays found" << endl; + cout << "\t " << iFileTxt << endl; + return false; + } + + cout << "found " << fSubArrays.size() << " sub arrays" << endl; + + return true; +} + diff --git a/src/VReadRunParameter.cpp b/src/VReadRunParameter.cpp index 26ebcd052..161dc729d 100644 --- a/src/VReadRunParameter.cpp +++ b/src/VReadRunParameter.cpp @@ -779,6 +779,7 @@ bool VReadRunParameter::readCommandline( int argc, char* argv[] ) { fRunPara->foutputfileName = ""; } + cout << fRunPara->foutputfileName.c_str() << endl; } else if( iTemp.find( "highres" ) < iTemp.size() ) { @@ -1554,7 +1555,9 @@ void VReadRunParameter::setDirectories() // outputfilename //suppress output file for peds gain/toffset low gain/toffset lpeds DSTs - if( fRunPara->frunmode == 1 || fRunPara->frunmode == 2 || fRunPara->frunmode == 5 || fRunPara->frunmode == 6 || fRunPara->frunmode == 4 ) + cout << fRunPara->foutputfileName << endl; + //if( fRunPara->frunmode == 1 || fRunPara->frunmode == 2 || fRunPara->frunmode == 5 || fRunPara->frunmode == 6 || fRunPara->frunmode == 4 ) + if( fRunPara->frunmode == 2 || fRunPara->frunmode == 5 || fRunPara->frunmode == 6 || fRunPara->frunmode == 4 ) { fRunPara->foutputfileName = "-1"; } diff --git a/src/VSensitivityCalculator.cpp b/src/VSensitivityCalculator.cpp index 605406fa8..2daac0541 100644 --- a/src/VSensitivityCalculator.cpp +++ b/src/VSensitivityCalculator.cpp @@ -495,7 +495,7 @@ vector< TGraph* > VSensitivityCalculator::getCrabSpectrum( vector< double > i_fC if( fEnergySpectrumfromLiterature == 0 ) { char hname[800]; - ostringstream hname2; + char hname2[800]; unsigned int i_CrabSpectrum_ID = 1; // NOTE: hardwired to 1! // Whipple Crab spectrum (1989) @@ -519,19 +519,17 @@ vector< TGraph* > VSensitivityCalculator::getCrabSpectrum( vector< double > i_fC } if( bUnit == "PFLUX" ) { - hname2 << hname; + sprintf( hname2, "%s", hname ); } else if( bUnit == "ENERGY" ) { - hname2 << hname << " * 1.e12 * x * x * " << scientific << fConstant_Flux_To_Ergs; + sprintf( hname2, "%s * 1.e12 * x * x * %e", hname, fConstant_Flux_To_Ergs ); } else { - hname2.clear(); - hname2.str( std::string() ); - hname2 << "1."; + sprintf( hname2, "%f", 1. ); } - i_fFunCrabFlux = new TF1( "i_fFunCrabFlux", hname2.str().c_str(), TMath::Power( 10., fEnergy_min_Log ), 10000. ); + i_fFunCrabFlux = new TF1( "i_fFunCrabFlux", hname2, TMath::Power( 10., fEnergy_min_Log ), 10000. ); } // use spectrum from text file else @@ -1357,7 +1355,7 @@ TCanvas* VSensitivityCalculator::plotObservationTimevsFlux( unsigned int iD, TCa } -void VSensitivityCalculator::list_sensitivity( unsigned int iD, bool print_latex_table_line, string iTitle ) +void VSensitivityCalculator::list_sensitivity( unsigned int iD ) { if( !checkDataSet( iD, "plotObservationTimevsFlux" ) ) { @@ -1366,18 +1364,6 @@ void VSensitivityCalculator::list_sensitivity( unsigned int iD, bool print_latex calculateObservationTimevsFlux( iD ); - if( print_latex_table_line ) - { - list_sensitivity_latex_table( iD, iTitle ); - } - else - { - list_sensitivity_table( iD ); - } -} - -void VSensitivityCalculator::list_sensitivity_table( unsigned int iD ) -{ cout << " Flux time time" << endl; cout << " [Crab Units] [min] [h]" << endl; cout << " ========================================" << endl; @@ -1394,42 +1380,6 @@ void VSensitivityCalculator::list_sensitivity_table( unsigned int iD ) cout << " events, and using Li & Ma formula " << fLiAndMaEqu << ")" << endl; } -void VSensitivityCalculator::list_sensitivity_latex_table( - unsigned int iD, string iTitle, - double iSignalE, double iBackgroundE ) -{ - cout << "LATEXLINE "; - cout << iTitle << " & "; - if( iSignalE > 0. ) - { - cout << fData[iD].fSignal << " \\pm " << iSignalE << " & "; - } - else - { - cout << fData[iD].fSignal << " & "; - } - if( iBackgroundE > 0. ) - { - cout << fData[iD].fBackground << " \\pm " << iBackgroundE << " & "; - } - else - { - cout << fData[iD].fBackground << " & "; - } - // assume that 10 and 1% values are in source strength vectors - for( unsigned int i = 0; i < fSourceStrength.size(); i++ ) - { - if( TMath::Abs( fSourceStrength[i] - 0.1 ) < 1.e-7 ) - { - cout << setprecision( 3 ) << fGraphObsvsTime[iD]->Eval( fSourceStrength[i] ) * 60. << " & "; - } - if( TMath::Abs( fSourceStrength[i] - 0.01 ) < 1.e-7 ) - { - cout << setprecision( 3 ) << fGraphObsvsTime[iD]->Eval( fSourceStrength[i] ) << " "; - } - } - cout << "\\\\" << endl; -} double VSensitivityCalculator::calculateObservationTimevsFlux( unsigned int iD ) { diff --git a/src/VStereoAnalysis.cpp b/src/VStereoAnalysis.cpp index 67e977e13..574cca6b1 100644 --- a/src/VStereoAnalysis.cpp +++ b/src/VStereoAnalysis.cpp @@ -11,7 +11,7 @@ VStereoAnalysis::VStereoAnalysis( bool ion, string i_hsuffix, VAnaSumRunParamete fDebug = false; fDataFile = 0; - fInstrumentEpochMinor = "NOT_SET"; + fInstrumentEpoch = "NOT_SET"; fDirTot = iDirTot; fDirTotRun = iDirRun; bTotalAnalysisOnly = iTotalAnalysisOnly; @@ -848,38 +848,34 @@ void VStereoAnalysis::writeHistograms( bool bOn ) // copy effective areas and radial acceptance to anasum output file if( bOn ) { - if( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile != "IGNOREEFFECTIVEAREA" - && fRunPara->fRunList[fHisCounter].fEffectiveAreaFile != "IGNOREIRF" ) + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveArea ); + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gTimeBinnedMeanEffectiveArea ); + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEsys_MC ); + + // Both MC and REC effective areas are required for Binned Likelihood analysis + if( fRunPara->fLikelihoodAnalysis ) { - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveArea ); - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gTimeBinnedMeanEffectiveArea ); - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEsys_MC ); - - // Both MC and REC effective areas are required for Binned Likelihood analysis - if( fRunPara->fLikelihoodAnalysis ) + if( gMeanEffectiveAreaMC ) { - if( gMeanEffectiveAreaMC ) - { - // When nOn = 0 gMeanEffectiveAreaMC_on(E) = 0 - // VLikelihoodFitter will check gMeanEffectiveAreaMC_on::integral > 1 - gMeanEffectiveAreaMC->SetTitle( "gMeanEffectiveAreaMC_on" ); - gMeanEffectiveAreaMC->SetName( "gMeanEffectiveAreaMC_on" ); - - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveAreaMC ); - } - if( hResponseMatrix ) - { - hResponseMatrix->SetTitle( "hResponseMatrix_on" ); - hResponseMatrix->SetName( "hResponseMatrix_on" ); - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", hResponseMatrix ); - } + // (SOB) When nOn = 0 gMeanEffectiveAreaMC_on(E) = 0 + // VLikelihoodFitter will check gMeanEffectiveAreaMC_on::integral > 1 + gMeanEffectiveAreaMC->SetTitle( "gMeanEffectiveAreaMC_on" ); + gMeanEffectiveAreaMC->SetName( "gMeanEffectiveAreaMC_on" ); + + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveAreaMC ); } - if( fRunPara->fRunList[fHisCounter].fAcceptanceFile.size() > 0 - && fRunPara->fRunList[fHisCounter].fAcceptanceFile != "IGNOREACCEPTANCE" ) + if( hResponseMatrix ) { - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fAcceptanceFile, "RadialAcceptances", 0 ); + hResponseMatrix->SetTitle( "hResponseMatrix_on" ); + hResponseMatrix->SetName( "hResponseMatrix_on" ); + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", hResponseMatrix ); } } + if( fRunPara->fRunList[fHisCounter].fAcceptanceFile.size() > 0 + && fRunPara->fRunList[fHisCounter].fAcceptanceFile != "IGNOREACCEPTANCE" ) + { + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fAcceptanceFile, "RadialAcceptances", 0 ); + } } else { @@ -894,15 +890,11 @@ void VStereoAnalysis::writeHistograms( bool bOn ) sprintf( hname, "%s_off", gTimeBinnedMeanEffectiveArea->GetName() ); gTimeBinnedMeanEffectiveArea->SetName( hname ); } - if( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile != "IGNOREEFFECTIVEAREA" - && fRunPara->fRunList[fHisCounter].fEffectiveAreaFile != "IGNOREIRF" ) - { - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveArea ); - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gTimeBinnedMeanEffectiveArea ); - } + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveArea ); + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gTimeBinnedMeanEffectiveArea ); // Both MC and REC effective areas are required for Binned Likelihood analysis - // A set of Off MC effective areas and response matrix are used as a back up + // (SOB) A set of Off MC effective areas and response matrix are used as a back up // If zero On counts the Off set will be used if( fRunPara->fLikelihoodAnalysis ) { @@ -1797,10 +1789,8 @@ void VStereoAnalysis::setCuts( VAnaSumRunParameterDataClass iL, int irun ) { if( iL.fCutFile != "" ) { - // read cuts from effective area root file - if( iL.fCutFile.find( ".root" ) != string::npos - && iL.fCutFile.find( "IGNOREEFFECTIVEAREA" ) == string::npos - && iL.fCutFile.find( "IGNOREIRF" ) == string::npos ) + // read cuts from root file + if( iL.fCutFile.find( ".root" ) != string::npos ) { string iEffFile = VUtilities::testFileLocation( iL.fCutFile, "EffectiveAreas", true ); @@ -1821,14 +1811,13 @@ void VStereoAnalysis::setCuts( VAnaSumRunParameterDataClass iL, int irun ) exit( EXIT_FAILURE ); } fCuts = iC; - cout << "Reading gamma/hadron cuts from effective area file " << iEffFile << endl; iF->Close(); } // read cuts from text file else { fCuts->setNTel( iL.fMaxTelID ); - fCuts->setInstrumentEpoch( fInstrumentEpochMinor ); + fCuts->setInstrumentEpoch( fInstrumentEpoch ); fCuts->setTelToAnalyze( fTelToAnalyze ); fCuts->readCuts( iL.fCutFile ); fCuts->setTheta2Cut( iL.fSourceRadius ); @@ -1975,7 +1964,7 @@ CData* VStereoAnalysis::getDataFromFile( int i_runNumber ) VEvndispRunParameter* i_runPara = ( VEvndispRunParameter* )fDataFile->Get( "runparameterV2" ); if( i_runPara ) { - fInstrumentEpochMinor = i_runPara->getInstrumentATMString(); + fInstrumentEpoch = i_runPara->getInstrumentEpoch( true ); fTelToAnalyze = i_runPara->fTelToAnalyze; } else @@ -1983,7 +1972,7 @@ CData* VStereoAnalysis::getDataFromFile( int i_runNumber ) cout << "VStereoAnalysis::getDataFromFile() warning: epoch of current file " << endl; cout << "and active telescope combination cannot be determined; " << endl; cout << "this might lead to a wrong choice in the gamma/hadron cuts - please check" << endl; - fInstrumentEpochMinor = "NOT_FOUND"; + fInstrumentEpoch = "NOT_FOUND"; } } return c; diff --git a/src/VStereoHistograms.cpp b/src/VStereoHistograms.cpp index f59eb06e8..845d61298 100644 --- a/src/VStereoHistograms.cpp +++ b/src/VStereoHistograms.cpp @@ -897,10 +897,7 @@ void VStereoHistograms::writeObjects( string iFile, string iDirectory, TObject* } wDir = gDirectory; - if( iFile.find( "IGNOREEFFECTIVEAREA" ) == string::npos ) - { - iFile = VUtilities::testFileLocation( iFile, iDirectory, true ); - } + iFile = VUtilities::testFileLocation( iFile, iDirectory, true ); if( iFile.size() == 0 ) { iDir->cd(); diff --git a/src/VTMVAEvaluator.cpp b/src/VTMVAEvaluator.cpp index 1b67aa745..80a046b24 100644 --- a/src/VTMVAEvaluator.cpp +++ b/src/VTMVAEvaluator.cpp @@ -1,6 +1,10 @@ /*! \class VTMVAEvaluator \brief use a TMVA weight file for energy dependent gamma/hadron separation + TODO list + + - test theta2(E) optimization + */ #include "VTMVAEvaluator.h" @@ -27,13 +31,14 @@ void VTMVAEvaluator::reset() fMLR = 0.; fEmissionHeight = 0.; fEmissionHeightChi2_log10 = 0.; + fEnergyReconstructionMethod = 1; fEChi2S = 0.; fEChi2S_log10 = 0.; fdES = 0.; fSizeSecondMax_log10 = 0; + fTheta2 = 0.; fCoreDist = 0.; fDispDiff = 0.; - fDispDiff_log10 = 0.; fDummy = 0.; for( int i = 0; i < VDST_MAXTELESCOPES; i++ ) { @@ -42,15 +47,19 @@ void VTMVAEvaluator::reset() setTMVACutValue(); setSignalEfficiency(); + setIgnoreTheta2Cut(); setSpectralIndexForEnergyWeighting(); setParticleNumberFile(); setPlotEfficiencyPlotsPerBin(); - setPrintPlotting(); setSensitivityOptimizationParameters(); setSensitivityOptimizationFixedSignalEfficiency(); setSensitivityOptimizationMinSourceStrength(); + setTMVAAngularContainmentThetaFixedMinRadius(); setTMVAMethod(); + // default: don't expect that the theta2 cut is performed here + setTMVAThetaCutVariable( false ); setTMVAErrorFraction(); + setTMVAAngularContainmentRadiusMax(); fTMVA_EvaluationResult = -99.; fTMVACutValueNoVec = -99.; @@ -120,39 +129,14 @@ vector< string > VTMVAEvaluator::getTrainingVariables( string iXMLFile, vector< return iVar; } -/* - * return BDT file name - * -*/ -string VTMVAEvaluator::getBDTFileName( string iWeightFileName, unsigned int i_E_index, unsigned int i_Z_index, string iSuffix ) -{ - ostringstream iFullFileName; - if( iWeightFileName.size() > 0 ) - { - iFullFileName << iWeightFileName; - } - else - { - iFullFileName << fTMVAMethodName; - } - iFullFileName << "_" << i_E_index; - iFullFileName << "_" << i_Z_index; - if( iSuffix.find( "xml" ) != string::npos ) - { - iFullFileName << "_" << fTMVAMethodName; - } - iFullFileName << iSuffix; - return iFullFileName.str(); -} - /* initialize TMVA readers */ -bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, - unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, - unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ) +bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, + unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax, + double iEnergyStepSize, string iInstrumentEpoch ) { ////////////////////////////// // sanity checks @@ -198,110 +182,137 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int jMinMissingBin = 0; for( unsigned int j = 0; j < iNbinZ; j++ ) { - string iTMVAName = getBDTFileName( "", - iWeightFileIndex_Emin + i, iWeightFileIndex_Zmin + j ); - string iFullFileName = getBDTFileName( iWeightFileName, - iWeightFileIndex_Emin + i, iWeightFileIndex_Zmin + j, ".root" ); - string iFullFileNameXML = getBDTFileName( iWeightFileName, - iWeightFileIndex_Emin + i, iWeightFileIndex_Zmin + j, "_0.weights.xml" ); - + ostringstream iFullFileName; + ostringstream iFullFileNameXML; + iFullFileName << iWeightFileName << "_" << iWeightFileIndex_Emin + i; + // backwards compatibility with CTA + if( iInstrumentEpoch != "noepoch" && iInstrumentEpoch != "CTA" ) + { + iFullFileName << "_" << iWeightFileIndex_Zmin + j; + } + iFullFileName << ".root"; + iFullFileNameXML << iWeightFileName << "_" << iWeightFileIndex_Emin + i; + if( iInstrumentEpoch != "noepoch" && iInstrumentEpoch != "CTA" ) + { + iFullFileNameXML << "_" << iWeightFileIndex_Zmin + j; + } + iFullFileNameXML << "_" << fTMVAMethodName << "_0.weights.xml"; + TFile iF( iFullFileName.str().c_str() ); bool bGoodRun = true; VTMVARunDataEnergyCut* iEnergyData = 0; VTMVARunDataZenithCut* iZenithData = 0; - if( gSystem->AccessPathName( iFullFileName.c_str() ) ) + if( iF.IsZombie() ) { bGoodRun = false; } else { - TFile iF( iFullFileName.c_str() ); - if( iF.IsZombie() ) + iEnergyData = ( VTMVARunDataEnergyCut* )iF.Get( "fDataEnergyCut" ); + iZenithData = ( VTMVARunDataZenithCut* )iF.Get( "fDataZenithCut" ); + if( !iEnergyData ) { + cout << "No energy cut data: setting goodrun to false" << endl; bGoodRun = false; } - else + // backwards compatibility + if( !iZenithData && iInstrumentEpoch != "noepoch" && iInstrumentEpoch != "CTA" ) + { + cout << "No zenith cut data: "; + cout << " setting goodrun to false" << endl; + bGoodRun = false; + } + // signal efficiency + sprintf( hname, "Method_%s/%s_0/MVA_%s_0_effS", fTMVAMethodName.c_str(), fTMVAMethodName.c_str(), fTMVAMethodName.c_str() ); + + if( !iF.Get( hname ) ) + { + cout << "No signal efficiency histogram found (" << hname << ")" << endl; + bGoodRun = false; + } + } + // allow that first files are missing (this happens when there are no training events in the first energy bins) + if( !bGoodRun ) + { + if( i == iMinMissingBin || j == jMinMissingBin ) { - iEnergyData = ( VTMVARunDataEnergyCut* )iF.Get( "fDataEnergyCut" ); - iZenithData = ( VTMVARunDataZenithCut* )iF.Get( "fDataZenithCut" ); - if( !iEnergyData || !iZenithData ) + cout << "VTMVAEvaluator::initializeWeightFiles() warning: TMVA root file not found or incomplete file (" << i << ") " << endl; + cout << iFullFileName.str() << endl; + if( i == iMinMissingBin ) { - cout << " No energy or zenith cut data" << endl; - bGoodRun = false; + cout << " assume this is a low-energy empty bin (bin number " << i << ";"; + cout << " number of missing bins: " << iMinMissingBin + 1 << ")" << endl; + iMinMissingBin++; } - // signal efficiency - sprintf( hname, "Method_%s/%s_0/MVA_%s_0_effS", - fTMVAMethodName.c_str(), fTMVAMethodName.c_str(), fTMVAMethodName.c_str() ); - - if( !iF.Get( hname ) ) + if( j == jMinMissingBin ) { - cout << " No signal efficiency histogram found (" << hname << ")" << endl; - bGoodRun = false; + cout << " assume this is a zenith empty bin (bin number " << j << ";"; + cout << " number of missing bins: " << jMinMissingBin + 1 << ")" << endl; } + continue; } - // allow that first files are missing - // (this happens when there are no training events in the first energy or zenith bins) - if( !bGoodRun ) + else if( i == ( iWeightFileIndex_Emax ) || j == ( iWeightFileIndex_Zmax ) ) { - if( i == iMinMissingBin || j == jMinMissingBin ) + cout << "VTMVAEvaluator::initializeWeightFiles() warning: TMVA root file not found " << iFullFileName.str() << endl; + if( i == ( iWeightFileIndex_Emax ) ) { - cout << "VTMVAEvaluator::initializeWeightFiles() warning: "; - cout << "TMVA root file not found or incomplete file (" << i << ") " << endl; - cout << iFullFileName << endl; - if( i == iMinMissingBin ) - { - cout << " assume this is a low-energy empty bin (bin number " << i << ";"; - cout << " number of missing energy bins: " << iMinMissingBin + 1 << ")" << endl; - iMinMissingBin++; - } - if( j == jMinMissingBin ) - { - cout << " assume this is a zenith empty bin (bin number " << j << ";"; - cout << " number of missing zenith bins: " << jMinMissingBin + 1 << ")" << endl; - jMinMissingBin++; - } - continue; + cout << " assume this is a high-energy empty bin (bin number " << i << ")" << endl; + iNbinE--; + iWeightFileIndex_Emax--; } - else if( i == ( iWeightFileIndex_Emax ) || j == ( iWeightFileIndex_Zmax ) ) + if( j == ( iWeightFileIndex_Zmax ) ) { - cout << "VTMVAEvaluator::initializeWeightFiles(): TMVA root file not found " << iFullFileName << endl; - if( i == ( iWeightFileIndex_Emax ) ) - { - cout << " assume this is a high-energy empty bin (bin number " << i << ")" << endl; - } - if( j == ( iWeightFileIndex_Zmax ) ) - { - cout << " assume this is a high-zenith empty bin (bin number " << j << ")" << endl; - } - continue; - } - else - { - cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while initializing energies from TMVA root file "; - cout << iFullFileName << endl; - cout << "(this might be not a problem if the sensitive energy range of the given array is relatively small)" << endl; - continue; + cout << " assume this is a high-zenith empty bin (bin number " << j << ")" << endl; + iNbinZ--; + iWeightFileIndex_Zmax--; } + continue; } - if( !iEnergyData ) + else { - cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while reading energies from TMVA root file "; - cout << iFullFileName << endl; - fIsZombie = true; - return false; + cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while initializing energies from TMVA root file "; + cout << iFullFileName.str() << endl; + cout << "(this might be not a problem if the sensitive energy range of the given array is relatively small)" << endl; + continue; } - // form here on: expect a good TMVA file - // initialize one value per energy/zenith bin - - // set energy binning: - // - one VTMVAEvaluatorData per energy bin - // - bins are set for the energy interval read from the root file: - // [iEnergyData->fEnergyCut_Log10TeV_min, iEnergyData->fEnergyCut_Log10TeV_max] + } + if( !iEnergyData ) + { + cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while reading energies from TMVA root file "; + cout << iFullFileName.str() << endl; + fIsZombie = true; + return false; + } + /* if( !iZenithData ) + { + cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while reading zeniths from TMVA root file "; + cout << iFullFileName.str() << endl; + fIsZombie = true; + return false; + } */ + // form here on: expect a good TMVA file + // initialize one value per energy/zenith bin + + // set energy binning: + // - one VTMVAEvaluatorData per energy bin + // - bins are set for the energy interval read from the root file: + // [iEnergyData->fEnergyCut_Log10TeV_min, iEnergyData->fEnergyCut_Log10TeV_max] + // - sub-bins given by iEnergyStepSize; + double e = iEnergyData->fEnergyCut_Log10TeV_min; + do + { // central data element for this energy bin fTMVAData.push_back( new VTMVAEvaluatorData() ); - fTMVAData.back()->fEnergyBin = i; - fTMVAData.back()->fZenithBin = j; - fTMVAData.back()->fEnergyCut_Log10TeV_min = iEnergyData->fEnergyCut_Log10TeV_min; - fTMVAData.back()->fEnergyCut_Log10TeV_max = iEnergyData->fEnergyCut_Log10TeV_max; + // find e_min and e_max + fTMVAData.back()->fEnergyCut_Log10TeV_min = e; + if( iEnergyStepSize > 0. ) + { + fTMVAData.back()->fEnergyCut_Log10TeV_max = e + iEnergyStepSize; + } + else + { + fTMVAData.back()->fEnergyCut_Log10TeV_max = iEnergyData->fEnergyCut_Log10TeV_max; + } + e = fTMVAData.back()->fEnergyCut_Log10TeV_max; // calculate spectral weighted mean energy fTMVAData.back()->fSpectralWeightedMeanEnergy_Log10TeV = @@ -336,22 +347,37 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, fTMVAData.back()->fBackgroundEfficiency = -99.; fTMVAData.back()->fTMVAOptimumCutValueFound = false; fTMVAData.back()->fSourceStrengthAtOptimum_CU = 0.; + fTMVAData.back()->fAngularContainmentRadius = -99.; + fTMVAData.back()->fAngularContainmentFraction = -99.; sprintf( hname, "bin %d, %.2f < log10(E) < %.2f, %.2f < Ze < %.2f)", ( int )( fTMVAData.size() - 1 ), fTMVAData.back()->fEnergyCut_Log10TeV_min, fTMVAData.back()->fEnergyCut_Log10TeV_max, fTMVAData.back()->fZenithCut_min, fTMVAData.back()->fZenithCut_max ); fTMVAData.back()->SetTitle( hname ); - sprintf( hname, "%d%d", i, j ); + sprintf( hname, "MVA%d%d", i, j ); fTMVAData.back()->fTMVAMethodTag = hname; - sprintf( hname, "%d_%d", i, j ); + if( iNbinZ > 1 ) + { + sprintf( hname, "%d_%d", i, j ); + } + else + { + sprintf( hname, "%d", i ); + } + fTMVAData.back()->fTMVAMethodTag_2 = hname; - fTMVAData.back()->fTMVAName = iTMVAName; - fTMVAData.back()->fTMVAFileName = iFullFileName; - fTMVAData.back()->fTMVAFileNameXML = iFullFileNameXML; + fTMVAData.back()->fTMVAFileName = iFullFileName.str(); + fTMVAData.back()->fTMVAFileNameXML = iFullFileNameXML.str(); - iF.Close(); + if( iEnergyStepSize < 0. ) + { + break; + } } + while( e < ( iEnergyData->fEnergyCut_Log10TeV_max - 0.0001 ) ); + + iF.Close(); }//end loop on zenith bins }//end loop on energy bins @@ -434,6 +460,15 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, { fTMVAData[b]->fTMVAReader->AddVariable( "dE", &fdES ); } + else if( iTrainingVariables[t] == "EChi2" && !iVariableIsASpectator[t] ) + { + fTMVAData[b]->fTMVAReader->AddVariable( "EChi2", &fEChi2S ); + fEnergyReconstructionMethod = 0; + } + else if( iTrainingVariables[t] == "log10(EChi2)" && !iVariableIsASpectator[t] ) + { + fTMVAData[b]->fTMVAReader->AddVariable( "log10(EChi2)", &fEChi2S_log10 ); + } else if( iTrainingVariables[t] == "dES" && !iVariableIsASpectator[t] ) { fTMVAData[b]->fTMVAReader->AddVariable( "dES", &fdES ); @@ -445,11 +480,17 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, else if( iTrainingVariables[t] == "EChi2S" && !iVariableIsASpectator[t] ) { fTMVAData[b]->fTMVAReader->AddVariable( "EChi2S", &fEChi2S ); + fEnergyReconstructionMethod = 1; } else if( iTrainingVariables[t] == "log10(EChi2S)" && !iVariableIsASpectator[t] ) { fTMVAData[b]->fTMVAReader->AddVariable( "log10(EChi2S)", &fEChi2S_log10 ); } + else if( iTrainingVariables[t] == "(Xoff*Xoff+Yoff*Yoff)" && !iVariableIsASpectator[t] ) + { + fTMVAData[b]->fTMVAReader->AddVariable( "(Xoff*Xoff+Yoff*Yoff)", &fTheta2 ); + setTMVAThetaCutVariable( true ); + } else if( iTrainingVariables[t] == "sqrt(Xcore*Xcore+Ycore*Ycore)" && !iVariableIsASpectator[t] ) { fTMVAData[b]->fTMVAReader->AddVariable( "sqrt(Xcore*Xcore+Ycore*Ycore)", &fCoreDist ); @@ -458,10 +499,6 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, { fTMVAData[b]->fTMVAReader->AddVariable( "DispDiff", &fDispDiff ); } - else if( iTrainingVariables[t] == "log10(DispDiff)" && !iVariableIsASpectator[t] ) - { - fTMVAData[b]->fTMVAReader->AddVariable( "log10(DispDiff)", &fDispDiff_log10 ); - } // Note: assume not more then 3 different telescope types else if( iTrainingVariables[t] == "NImages_Ttype[0]" && !iVariableIsASpectator[t] ) { @@ -493,9 +530,7 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, cout << endl; } } - if( !fTMVAData[b]->fTMVAReader->BookMVA( - fTMVAData[b]->fTMVAMethodTag_2.c_str(), - fTMVAData[b]->fTMVAFileNameXML.c_str() ) ) + if( !fTMVAData[b]->fTMVAReader->BookMVA( fTMVAData[b]->fTMVAMethodTag_2.c_str(), fTMVAData[b]->fTMVAFileNameXML.c_str() ) ) { cout << "VTMVAEvaluator::initializeWeightFiles: error while initializing TMVA reader from weight file "; cout << fTMVAData[b]->fTMVAFileNameXML << endl; @@ -523,9 +558,7 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, // smooth and interpolate if( fParticleNumberFileName.size() > 0 && fSmoothAndInterpolateMVAValues ) { - smoothAndInterPolateMVAValue( 0, 0, - iWeightFileIndex_Emin, iWeightFileIndex_Emax, - iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); + smoothAndInterPolateMVAValue( 0, 0, iWeightFileIndex_Emin, iWeightFileIndex_Emax, iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); } // print some info to screen @@ -700,16 +733,33 @@ bool VTMVAEvaluator::evaluate() { fEmissionHeightChi2_log10 = -10.; // !!! not clear what the best value is } - fEChi2S = fData->EChi2S; - if( fEChi2S > 0. ) + // fill according of energy reconstruction method + if( fEnergyReconstructionMethod == 0 ) { - fEChi2S_log10 = TMath::Log10( fEChi2S ); + fEChi2S = fData->EChi2; + if( fEChi2S > 0. ) + { + fEChi2S_log10 = TMath::Log10( fEChi2S ); + } + else + { + fEChi2S_log10 = 0.; // !!! not clear what the best value is + } + fdES = fData->dE; } else { - fEChi2S_log10 = 0.; // !!! not clear what the best value is + fEChi2S = fData->EChi2S; + if( fEChi2S > 0. ) + { + fEChi2S_log10 = TMath::Log10( fEChi2S ); + } + else + { + fEChi2S_log10 = 0.; // !!! not clear what the best value is + } + fdES = fData->dES; } - fdES = fData->dES; fSizeSecondMax_log10 = fData->SizeSecondMax; if( fSizeSecondMax_log10 > 0. ) { @@ -719,16 +769,17 @@ bool VTMVAEvaluator::evaluate() { fSizeSecondMax_log10 = 0.; // !!! not clear what the best value is } - fCoreDist = sqrt( fData->Xcore * fData->Xcore + fData->Ycore * fData->Ycore ); - fDispDiff = fData->DispDiff; - if( fDispDiff > 0. ) + // for no theta2: set this value extremely small + if( fTMVAIgnoreTheta2Cut ) { - fDispDiff_log10 = log10( fDispDiff ); + fTheta2 = 1.e-30; } else { - fDispDiff_log10 = 0.; // !!! not clear what the best value is + fTheta2 = fData->Xoff * fData->Xoff + fData->Yoff * fData->Yoff; } + fCoreDist = sqrt( fData->Xcore * fData->Xcore + fData->Ycore * fData->Ycore ); + fDispDiff = fData->DispDiff; if( fData->NTtype < VDST_MAXTELESCOPES ) { for( int i = 0; i < fData->NTtype; i++ ) @@ -759,26 +810,14 @@ bool VTMVAEvaluator::evaluate() // evaluate MVA for this event fTMVA_EvaluationResult = fTMVAData[iDataBin]->fTMVAReader->EvaluateMVA( fTMVAData[iDataBin]->fTMVAMethodTag_2 ); - // apply MVA cut - bool i_useTMVAGraph = false; - // interpolate cuts - if( i_useTMVAGraph ) + if( fTMVA_EvaluationResult < fTMVAData[iDataBin]->fTMVACutValue ) { - // TMPTMPTMP to be implemented - cout << "NOT IMPLEMENTED" << endl; + return false; } - // no interpolation applied else { - if( fTMVA_EvaluationResult < fTMVAData[iDataBin]->fTMVACutValue ) - { - return false; - } - else - { - return true; - } + return true; } } return false; @@ -791,11 +830,27 @@ bool VTMVAEvaluator::evaluate() */ unsigned int VTMVAEvaluator::getDataBin() { - if( !fData || fData->ErecS <= 0 ) + if( !fData ) + { + return 9999; + } + + double ze = fData->Ze; + double iErec = 0; + if( fEnergyReconstructionMethod == 0 && fData->Erec > 0 ) + { + iErec = log10( fData->Erec ); + } + else if( fEnergyReconstructionMethod == 1 && fData->ErecS > 0 ) + { + iErec = log10( fData->ErecS ); + } + else { return 9999; } - return getDataBin( log10( fData->ErecS ), fData->Ze ); + + return getDataBin( iErec, ze ); } @@ -812,11 +867,9 @@ unsigned int VTMVAEvaluator::getDataBin( double iErec, double iZe ) if( ( iZe > fTMVAData[i]->fZenithCut_min && iZe <= fTMVAData[i]->fZenithCut_max ) || iZe < -998. ) { // mean energy of this energy bin (possibly spectral weighted) - iMeanEnergy = VMathsandFunctions::getMeanEnergyInBin( - 2, - fTMVAData[i]->fEnergyCut_Log10TeV_min, - fTMVAData[i]->fEnergyCut_Log10TeV_max, - fSpectralIndexForEnergyWeighting ); + iMeanEnergy = VMathsandFunctions::getMeanEnergyInBin( 2, fTMVAData[i]->fEnergyCut_Log10TeV_min, + fTMVAData[i]->fEnergyCut_Log10TeV_max, + fSpectralIndexForEnergyWeighting ); // check which energy bin is closest if( TMath::Abs( iMeanEnergy - iErec ) < i_Diff_Energy ) { @@ -830,8 +883,8 @@ unsigned int VTMVAEvaluator::getDataBin( double iErec, double iZe ) { cout << "VTMVAEvaluator::getDataBin: " << iBin << endl; fTMVAData[iBin]->print(); - cout << "\t closest mean energy " << iMeanEnergy_min; - cout << ", log10 energy_tested " << iErec << ", distance: " << i_Diff_Energy ; + cout << "\t mean energy " << iMeanEnergy_min; + cout << ", log10 energy " << iErec << "\t" << i_Diff_Energy ; cout << "\t" << fSpectralIndexForEnergyWeighting << endl; } @@ -851,12 +904,70 @@ bool VTMVAEvaluator::initializeDataStrutures( CData* iC ) return true; } +/* + + get energy dependent theta2 cut + +*/ +double VTMVAEvaluator::getOptimalTheta2Cut( double iEnergy_log10TeV, double iZe ) +{ + if( fTMVAData.size() == 0 ) + { + cout << "VTMVAEvaluator::getOptimalTheta2Cut error: empty data vector" << endl; + return -99.; + } + + unsigned int iDataBin = getDataBin( iEnergy_log10TeV, iZe ); + + if( iDataBin < fTMVAData.size() ) + { + return ( fTMVAData[iDataBin]->fAngularContainmentRadius * fTMVAData[iDataBin]->fAngularContainmentRadius ); + } + + return 0.; +} + +/* + return a graph with all the theta2 cuts + + (is a memory leak...) + +*/ +TGraph* VTMVAEvaluator::getOptimalTheta2Cut_Graph() +{ + if( fTMVAData.size() == 0 ) + { + cout << "VTMVAEvaluator::getOptimalTheta2Cut_Graph error: empty data vector" << endl; + return 0; + } + + // sort + map< double, double > i_AngContaint; + for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + { + if( fTMVAData[i] && fTMVAData[i]->fAngularContainmentRadius > 1.e-10 ) + { + i_AngContaint[0.5 * ( fTMVAData[i]->fEnergyCut_Log10TeV_min + fTMVAData[i]->fEnergyCut_Log10TeV_max )] = fTMVAData[i]->fAngularContainmentRadius; + } + } + + // fill the graph - energy is at the spectral weighted energy + TGraph* g = new TGraph( 1 ); + unsigned int z = 0; + for( map::iterator it = i_AngContaint.begin(); it != i_AngContaint.end(); ++it ) + { + g->SetPoint( z, it->first, it->second ); + z++; + } + + return g; +} + /* * plot signal and background efficiencies * */ -TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( - bool iLogY, double iYmin, double iMVA_min, double iMVA_max ) +TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( bool iLogY, double iYmin, double iMVA_min, double iMVA_max ) { if( fTMVAData.size() == 0 ) { @@ -884,44 +995,45 @@ TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( continue; } - if( fTMVAData[i]->fSignalEfficiency < 0. || fTMVAData[i]->fBackgroundEfficiency < 0. ) + if( fTMVAData[i]->fSignalEfficiency > 0. && fTMVAData[i]->fBackgroundEfficiency > 0. ) { - cout << "VTMVAEvaluator::plotSignalAndBackgroundEfficiencies: "; - cout << "signal / background efficiency histograms not found " << endl; - cout << fTMVAData[i]->fSignalEfficiency << "\t" << fTMVAData[i]->fBackgroundEfficiency << endl; - continue; - } - if( fTMVAData[i]->fTMVAOptimumCutValueFound ) - { - igSignal->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fSignalEfficiency ); - igSignal->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igSignal->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - igBck->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fBackgroundEfficiency ); - igBck->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igBck->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - igCVa->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); - igCVa->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igCVa->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - z_opt++; + if( fTMVAData[i]->fTMVAOptimumCutValueFound ) + { + igSignal->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fSignalEfficiency ); + igSignal->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igSignal->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + igBck->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fBackgroundEfficiency ); + igBck->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igBck->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + igCVa->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); + igCVa->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igCVa->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + z_opt++; + } + else if( fTMVAData[i]->fTMVACutValue > -90. ) + { + igSignalOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fSignalEfficiency ); + igSignalOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igSignalOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + igBckOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fBackgroundEfficiency ); + igBckOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igBckOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + igCVaOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); + igCVaOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igCVaOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + z_noOpt++; + } } - else if( fTMVAData[i]->fTMVACutValue > -90. ) + else { - igSignalOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fSignalEfficiency ); - igSignalOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igSignalOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - igBckOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fBackgroundEfficiency ); - igBckOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igBckOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - igCVaOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); - igCVaOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igCVaOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - z_noOpt++; + cout << "VTMVAEvaluator::plotSignalAndBackgroundEfficiencies: signal / background efficiency histograms not found " << endl; + cout << fTMVAData[i]->fSignalEfficiency << "\t" << fTMVAData[i]->fBackgroundEfficiency << endl; } if( fTMVAData[i]->fBackgroundEfficiency < iMinBck ) { @@ -930,8 +1042,7 @@ TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( } // plot everything - TCanvas* iCanvas = new TCanvas( "cSignalAndBackgroundEfficiencies", "signal and background efficiencies", - 10, 10, 400, 400 ); + TCanvas* iCanvas = new TCanvas( "cSignalAndBackgroundEfficiencies", "signal and background efficiencies", 10, 10, 400, 400 ); iCanvas->SetGridx( 0 ); iCanvas->SetGridy( 0 ); iCanvas->SetLeftMargin( 0.13 ); @@ -991,10 +1102,6 @@ TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( { igBckOpt->Draw( "pl" ); } - if( fPrintPlotting ) - { - iCanvas->Print( "MVA-SignalBackgroundEfficiency.pdf" ); - } // plot MVA cut value if( igCVa ) @@ -1017,10 +1124,6 @@ TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( setGraphPlottingStyle( igCVaOpt, 1, 1., 24 ); igCVaOpt->Draw( "p" ); } - if( fPrintPlotting ) - { - iCVACanvas->Print( "MVA-MVACut.pdf" ); - } } return igCVa; @@ -1053,6 +1156,44 @@ void VTMVAEvaluator::setTMVACutValue( double iE ) fTMVACutValueNoVec = iE; } +void VTMVAEvaluator::printSourceStrength_CU() +{ + for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + { + if( fTMVAData[i] ) + { + cout << "E [" << showpoint << setprecision( 3 ) << fTMVAData[i]->fEnergyCut_Log10TeV_min << "," << fTMVAData[i]->fEnergyCut_Log10TeV_max << "] TeV"; + cout << " (bin " << i << "):\t "; + cout << fTMVAData[i]->fSourceStrengthAtOptimum_CU << " CU " << endl; + } + } +} + +void VTMVAEvaluator::printAngularContainmentRadius() +{ + if( fTMVAData.size() == 0 ) + { + return; + } + + cout << endl; + cout << "======================= VTMVAEvaluator: energy dependent optimal containment radius cut =======================" << endl; + for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + { + if( fTMVAData[i] ) + { + cout << "E [" << showpoint << setprecision( 3 ) << fTMVAData[i]->fEnergyCut_Log10TeV_min << "," << fTMVAData[i]->fEnergyCut_Log10TeV_max << "] TeV"; + cout << ", Ze [" << fTMVAData[i]->fZenithCut_min << "," << fTMVAData[i]->fZenithCut_max << "] deg"; + cout << " (bin " << i << "):\t "; + cout << fTMVAData[i]->fAngularContainmentRadius << " [deg], "; + cout << "T^2: " << fTMVAData[i]->fAngularContainmentRadius* fTMVAData[i]->fAngularContainmentRadius << " [deg^2], "; + cout << fTMVAData[i]->fAngularContainmentFraction << "%"; + cout << endl; + } + } + cout << noshowpoint << endl; +} + void VTMVAEvaluator::printSignalEfficiency() { if( fTMVAData.size() == 0 ) @@ -1066,8 +1207,7 @@ void VTMVAEvaluator::printSignalEfficiency() { if( fTMVAData[i] ) { - cout << "E [" << showpoint << setprecision( 3 ); - cout << fTMVAData[i]->fEnergyCut_Log10TeV_min << "," << fTMVAData[i]->fEnergyCut_Log10TeV_max << "] TeV"; + cout << "E [" << showpoint << setprecision( 3 ) << fTMVAData[i]->fEnergyCut_Log10TeV_min << "," << fTMVAData[i]->fEnergyCut_Log10TeV_max << "] TeV"; cout << ", Ze [" << fTMVAData[i]->fZenithCut_min << "," << fTMVAData[i]->fZenithCut_max << "] deg"; cout << " (bin " << i << "):\t "; cout << fTMVAData[i]->fSignalEfficiency; @@ -1093,30 +1233,11 @@ void VTMVAEvaluator::printSignalEfficiency() cout << noshowpoint << endl; } -/* - * print MVA cut values after optimization to be used - * in gamma/hadron cuts files - */ -void VTMVAEvaluator::printOptimizedMVACutValues( string iEpoch ) -{ - cout << "Printing Optimised cuts for gamma/hadron cut values" << endl; - cout << "\t this is only correct for an energyStepSize of -1" << endl; - cout << "* TMVA_MVACut " << iEpoch; - for( unsigned int i = 0; i < fTMVAData.size(); i++ ) - { - cout << " " << fTMVAData[i]->fTMVAMethodTag; - cout << " " << fTMVAData[i]->fTMVACutValue; - } - cout << endl; - cout << "(first digit: energy bin, second digit: zenith bin)" << endl; -} - /* calculate the optimal signal to noise ratio for a given particle number spectrum - this routine is possibly too complicated - + this routine is possible too complicated - main problem is how to deal with low statistics bins */ @@ -1149,14 +1270,8 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) } cout << "TVMAEvaluator::optimizeSensitivity reading: " << fParticleNumberFileName << endl; // get the NOn (signal + background) and NOff (background) graphs - TGraph* i_on = readNonNoffGraphsFromFile( - &iPN, - fTMVAData[iDataBin]->fZenithCut_min, fTMVAData[iDataBin]->fZenithCut_max, - true ); - TGraph* i_of = readNonNoffGraphsFromFile( - &iPN, - fTMVAData[iDataBin]->fZenithCut_min, fTMVAData[iDataBin]->fZenithCut_max, - false ); + TGraph* i_on = readNonNoffGraphsFromFile( &iPN, fTMVAData[iDataBin]->fZenithCut_min, fTMVAData[iDataBin]->fZenithCut_max, true ); + TGraph* i_of = readNonNoffGraphsFromFile( &iPN, fTMVAData[iDataBin]->fZenithCut_min, fTMVAData[iDataBin]->fZenithCut_max, false ); if( !i_on || !i_of ) { cout << "VTVMAEvaluator::optimizeSensitivity error:" << endl; @@ -1164,6 +1279,19 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) cout << i_on << "\t" << i_of << endl; return false; } + // angular containment histogram + // (optional, only needed when containment radius is also optimized) + TH2D* iHAngContainment = ( TH2D* )iPN.Get( "AngResCumulative" ); + if( iHAngContainment ) + { + cout << "TVMAEvaluator::optimizeSensitivity: found angular containment histogram ("; + cout << fTMVAngularContainmentRadiusMax << "%)"; + cout << endl; + } + else + { + cout << "TVMAEvaluator::optimizeSensitivity no angular containment histogram found" << endl; + } ////////////////////////////////////////////////////// // get mean energy of the considered bins @@ -1216,11 +1344,10 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) // // Convert the observing time in seconds as the particle rate is given in 1/seconds // Get the value of the middle of the energy and zenith angle bin - Non = i_on->Eval( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) - * fOptimizationObservingTime_h * fParticleNumberFile_Conversion_Rate_to_seconds; - Nof = i_of->Eval( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) - * fOptimizationObservingTime_h * fParticleNumberFile_Conversion_Rate_to_seconds; - + // TODODODODO minutes or seconds? + Non = i_on->Eval( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) * fOptimizationObservingTime_h * fParticleNumberFile_Conversion_Rate_to_seconds; + Nof = i_of->Eval( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) * fOptimizationObservingTime_h * fParticleNumberFile_Conversion_Rate_to_seconds; + if( Nof < 0. ) { Nof = 0.; @@ -1230,14 +1357,11 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) cout << "VTVMAEvaluator::optimizeSensitivity event numbers: "; cout << " non = " << Non; cout << " noff = " << Nof; - cout << " ndiff = " << Ndif << " (1 CU)" << endl; + cout << " ndif = " << Ndif << " (1 CU)" << endl; cout << "VTVMAEvaluator::optimizeSensitivity event numbers: "; cout << " (data bin " << iDataBin; - cout << ", weighted mean energy "; - cout << TMath::Power( 10., fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) << " [TeV], "; - cout << fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV << "), "; - cout << " Ebin [" << fTMVAData[iDataBin]->fEnergyCut_Log10TeV_min; - cout << ", " << fTMVAData[iDataBin]->fEnergyCut_Log10TeV_max << "]"; + cout << ", weighted mean energy " << TMath::Power( 10., fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) << " [TeV], "; + cout << fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV << ")"; cout << endl; /////////////////////////////////////////////////////////////////// @@ -1261,35 +1385,84 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) cout << effS << "\t" << effB << endl; return false; } + // evaluate errors on determination of background cut efficiency and remove bins with large errors + char hname[800]; + sprintf( hname, "Method_%s/%s_0/MVA_%s_0_B", fTMVAMethodName.c_str(), + fTMVAMethodName.c_str(), fTMVAMethodName.c_str() ); + TH1F* effB_counts = ( TH1F* )iTMVAFile.Get( hname ); + if( effB_counts ) + { + double iMaxMVACutValue = -1.; + for( int i = effB_counts->GetNbinsX() - 1; i > 0; i-- ) + { + if( effB_counts->GetBinContent( i ) > 0. ) + { + if( effB_counts->GetBinError( i ) / effB_counts->GetBinContent( i ) > fTMVAErrorFraction_min ) + { + iMaxMVACutValue = effB_counts->GetBinCenter( i ); + } + else + { + break; + } + } + } + if( iMaxMVACutValue > 0. ) + { + cout << "VTVMAEvaluator::optimizeSensitivity() removing low significance bins from background efficiency curve ("; + cout << fTMVAErrorFraction_min << ", " << iMaxMVACutValue << ")" << endl; + for( int i = 1; i <= effB->GetNbinsX(); i++ ) + { + if( effB->GetBinCenter( i ) > iMaxMVACutValue ) + { + effB->SetBinContent( i, 0. ); + } + } + } + } + else + { + cout << "VTVMAEvaluator::optimizeSensitivity() no background efficiency histogram found" << endl; + } + + cout << "VTVMAEvaluator::optimizeSensitivity() optimization parameters: "; + cout << "maximum signal efficiency is " << fOptimizationFixedSignalEfficiency << " minimum source strength is " << fOptimizationMinSourceStrength << endl; + cout << " (alpha: " << fOptimizationBackgroundAlpha << ")" << endl; + ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // optimization starts here ////////////////////////////////////////////////////////////////////////// double i_Signal_to_sqrtNoise = 0.; + double i_AngularContainmentRadius = 0.; + double i_AngularContainmentFraction = 0.; double i_TMVACutValue_AtMaximum = -99.; double i_SourceStrength_atMaximum = 0.; double i_SignalEfficiency_AtMaximum = -99.; double i_BackgroundEfficiency_AtMaximum = -99.; double i_Signal_to_sqrtNoise_atMaximum = 0.; + double i_AngularContainmentRadiusAtMaximum = 0.; + double i_AngularContainmentFractionAtMaximum = 0.; TGraph* iGSignal_to_sqrtNoise = 0; TGraph* iGSignalEvents = 0; TGraph* iGBackgroundEvents = 0; TGraph* iGSignal_to_sqrtNoise_Smooth = 0; + TGraph* iGOpt_AngularContainmentRadius = 0; + TGraph* iGOpt_AngularContainmentFraction = 0; ////////////////////////////////////////////////////// // loop over different source strengths (in Crab Units) // (hardwired: start at 0.001 CU to 30 CU) - unsigned int iSourceStrengthStepSizeN = - ( unsigned int )( ( log10( 30. ) - log10( fOptimizationMinSourceStrength ) ) / 0.005 ); + unsigned int iSourceStrengthStepSizeN = ( unsigned int )( ( log10( 30. ) - log10( fOptimizationMinSourceStrength ) ) / 0.005 ); cout << "VTVMAEvaluator::optimizeSensitivity(), source strength steps: " << iSourceStrengthStepSizeN << endl; for( unsigned int s = 0; s < iSourceStrengthStepSizeN; s++ ) { double iSourceStrength = log10( fOptimizationMinSourceStrength ) + s * 0.005; iSourceStrength = TMath::Power( 10., iSourceStrength ); - // source (excess) events + // source events Ndif = ( Non - Nof ) * iSourceStrength; // first quick pass to see if there is a change of reaching the required fOptimizationSourceSignificance @@ -1302,10 +1475,9 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) { if( fOptimizationBackgroundAlpha > 0. ) { - i_Signal_to_sqrtNoise = VStatistics::calcSignificance( - effS->GetBinContent( i ) * Ndif + effB->GetBinContent( i ) * Nof, - effB->GetBinContent( i ) * Nof / fOptimizationBackgroundAlpha, - fOptimizationBackgroundAlpha ); + i_Signal_to_sqrtNoise = VStatistics::calcSignificance( effS->GetBinContent( i ) * Ndif + effB->GetBinContent( i ) * Nof, + effB->GetBinContent( i ) * Nof / fOptimizationBackgroundAlpha, + fOptimizationBackgroundAlpha ); // check significance criteria if( i_Signal_to_sqrtNoise > fOptimizationSourceSignificance ) { @@ -1328,15 +1500,22 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) ////////////////////////////////////////////////////// // now loop over signal and background efficiency levels i_Signal_to_sqrtNoise = 0.; + i_AngularContainmentRadius = 0.; + i_AngularContainmentFraction = 0.; + i_TMVACutValue_AtMaximum = -99.; i_SourceStrength_atMaximum = 0.; i_SignalEfficiency_AtMaximum = -99.; i_BackgroundEfficiency_AtMaximum = -99.; i_Signal_to_sqrtNoise_atMaximum = 0.; + i_AngularContainmentRadiusAtMaximum = 0.; + i_AngularContainmentFractionAtMaximum = 0.; iGSignal_to_sqrtNoise = new TGraph( 1 ); iGSignalEvents = new TGraph( 1 ); iGBackgroundEvents = new TGraph( 1 ); + iGOpt_AngularContainmentRadius = new TGraph( 1 ); + iGOpt_AngularContainmentFraction = new TGraph( 1 ); int z = 0; int z_SB = 0; @@ -1347,15 +1526,28 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) { if( fOptimizationBackgroundAlpha > 0. ) { - // optimize signal/sqrt(noise) - i_Signal_to_sqrtNoise = VStatistics::calcSignificance( - effS->GetBinContent( i ) * Ndif + effB->GetBinContent( i ) * Nof, + if( iHAngContainment && fTMVA_OptimizeAngularContainment ) + { + getOptimalAngularContainmentRadius( effS->GetBinContent( i ), effB->GetBinContent( i ), Ndif, Nof, + iHAngContainment, fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV, + i_Signal_to_sqrtNoise, i_AngularContainmentRadius, i_AngularContainmentFraction ); + } + else + { + i_Signal_to_sqrtNoise = VStatistics::calcSignificance( effS->GetBinContent( i ) * Ndif + effB->GetBinContent( i ) * Nof, effB->GetBinContent( i ) * Nof / fOptimizationBackgroundAlpha, fOptimizationBackgroundAlpha ); + i_AngularContainmentRadius = VHistogramUtilities::interpolateTH2D( iHAngContainment, + fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV, + fTMVAngularContainmentRadiusMax ); + i_AngularContainmentFraction = fTMVAngularContainmentRadiusMax; + } } else { i_Signal_to_sqrtNoise = 0.; + i_AngularContainmentRadius = 0.; + i_AngularContainmentFraction = fTMVAngularContainmentRadiusMax; } if( fDebug ) { @@ -1388,9 +1580,12 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) if( iGSignal_to_sqrtNoise && i_Signal_to_sqrtNoise > 1.e-2 ) { iGSignal_to_sqrtNoise->SetPoint( z, effS->GetBinCenter( i ), i_Signal_to_sqrtNoise ); + iGOpt_AngularContainmentRadius->SetPoint( z, effS->GetBinCenter( i ), i_AngularContainmentRadius ); + iGOpt_AngularContainmentFraction->SetPoint( z, effS->GetBinCenter( i ), i_AngularContainmentFraction ); if( fDebug ) { - cout << "\t SET " << z << "\t" << effS->GetBinCenter( i ) << "\t" << i_Signal_to_sqrtNoise << endl; + cout << "\t SET " << z << "\t" << effS->GetBinCenter( i ) << "\t" << i_Signal_to_sqrtNoise << "\t"; + cout << i_AngularContainmentRadius << "\t" << i_AngularContainmentFraction << endl; } z++; } @@ -1401,8 +1596,6 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) } } } // END loop over all signal efficiency bins - ///////////////////////// - // determine position of maximum significance // fill a histogram from these values, smooth it, and determine position of maximum significance double i_xmax = -99.; if( iGSignal_to_sqrtNoise ) @@ -1421,8 +1614,8 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) i_ymax = y; i_xmax = x; } - // stop after first maximum (makes maximum research more robust to fluctuations of the - // background efficiency) + // stop after first maximim (makes maximum research more robust to fluctuations of the + // background efficiency else if( y < i_ymax ) { break; @@ -1433,6 +1626,8 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) i_TMVACutValue_AtMaximum = i_xmax; i_Signal_to_sqrtNoise_atMaximum = i_ymax; i_SourceStrength_atMaximum = iSourceStrength; + i_AngularContainmentRadiusAtMaximum = iGOpt_AngularContainmentRadius->Eval( i_xmax ); + i_AngularContainmentFractionAtMaximum = iGOpt_AngularContainmentFraction->Eval( i_xmax ); } /////////////////////////////////////////////////////// // check if value if really at the optimum or if information is missing from background efficiency curve @@ -1503,6 +1698,14 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) { delete iGSignal_to_sqrtNoise_Smooth; } + if( iGOpt_AngularContainmentRadius ) + { + delete iGOpt_AngularContainmentRadius; + } + if( iGOpt_AngularContainmentFraction ) + { + delete iGOpt_AngularContainmentFraction; + } } } // end of loop over source strength /////////////////////////////////////////////////////////////////////// @@ -1525,14 +1728,15 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) { i_TMVACutValue_AtMaximum = effS->GetBinCenter( i ); i_BackgroundEfficiency_AtMaximum = effB->GetBinContent( i ); + i_AngularContainmentRadiusAtMaximum = iGOpt_AngularContainmentRadius->Eval( i_TMVACutValue_AtMaximum ); + i_AngularContainmentFractionAtMaximum = iGOpt_AngularContainmentFraction->Eval( i_TMVACutValue_AtMaximum ); break; } } } - cout << "VTMVAEvaluator::optimizeSensitivity: setting signal efficiency to "; - cout << fOptimizationFixedSignalEfficiency; - cout << " (from " << i_SignalEfficiency_AtMaximum << ")" << endl; i_SignalEfficiency_AtMaximum = fOptimizationFixedSignalEfficiency; + cout << "VTMVAEvaluator::optimizeSensitivity: setting signal efficiency to "; + cout << fOptimizationFixedSignalEfficiency << endl; } else { @@ -1543,249 +1747,292 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) } cout << "\t MVA parameter: " << i_TMVACutValue_AtMaximum; cout << ", background efficiency: " << i_BackgroundEfficiency_AtMaximum << endl; + cout << "\t angular containment is " << i_AngularContainmentFractionAtMaximum * 100. << "%, radius "; + cout << i_AngularContainmentRadiusAtMaximum << " [deg]"; + if( iHAngContainment ) + { + cout << " (scaled from " << iHAngContainment->GetBinContent( iHAngContainment->GetXaxis()->FindBin( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ), + iHAngContainment->GetYaxis()->FindBin( fTMVAngularContainmentRadiusMax ) ); + cout << " [deg], " << fTMVAngularContainmentRadiusMax * 100. << "%)"; + } + cout << endl; //////////////////////////////////////////////////////////////// + // get mean energy for this bin + double iMeanEnergyAfterCuts = getMeanEnergyAfterCut( &iTMVAFile, i_TMVACutValue_AtMaximum, iDataBin ); + cout << "Mean energy after cuts [TeV]: " << iMeanEnergyAfterCuts << endl; + // fill results into data vectors fTMVAData[iDataBin]->fSignalEfficiency = i_SignalEfficiency_AtMaximum; fTMVAData[iDataBin]->fBackgroundEfficiency = i_BackgroundEfficiency_AtMaximum; fTMVAData[iDataBin]->fTMVACutValue = i_TMVACutValue_AtMaximum; fTMVAData[iDataBin]->fSourceStrengthAtOptimum_CU = i_SourceStrength_atMaximum; + if( iMeanEnergyAfterCuts > 0. ) + { + fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV = log10( iMeanEnergyAfterCuts ); + } + fTMVAData[iDataBin]->fAngularContainmentRadius = i_AngularContainmentRadiusAtMaximum; + fTMVAData[iDataBin]->fAngularContainmentFraction = i_AngularContainmentFractionAtMaximum; // plot optimziation procedure and event numbers if( bPlotEfficiencyPlotsPerBin ) { plotEfficiencyPlotsPerBin( iDataBin, iGSignal_to_sqrtNoise, iGSignal_to_sqrtNoise_Smooth, - effS, effB, iGSignalEvents, iGBackgroundEvents ); + effS, effB, iGSignalEvents, iGBackgroundEvents, + iGOpt_AngularContainmentRadius, iGOpt_AngularContainmentFraction ); } return true; } - /* + smoothing of optimal cut value vs energy curves - (energy axis only) + missing (non-optimized) are interpolated + + note: signal and background efficiencies are not updated */ -void VTMVAEvaluator::smoothAndInterPolateMVAValue_EnergyOnly( - TH1F* effS, TH1F* effB ) +void VTMVAEvaluator::smoothAndInterPolateMVAValue( TH1F* effS, TH1F* effB, unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ) { - int z = 0; - // fill graph to be smoothed - TGraph* iG = new TGraph( 1 ); - for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + if( fTMVAData.size() == 0 ) { - if( fTMVAData[i] ) - { - if( fTMVAData[i]->fTMVAOptimumCutValueFound ) - { - iG->SetPoint( z, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); - z++; - } - } + return; } - // smooth graph - TGraph* iGout = new TGraph( 1 ); - TGraphSmooth* iGSmooth = new TGraphSmooth( "t" ); - iGout = ( TGraph* )iGSmooth->SmoothKern( iG, "normal", 0.5, 100 ); - // fill smoothed and interpolated values into MVA vector - // set all points to 'optimized' - for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + cout << "Smooth and interpolate MVA cut values" << endl; + + int z = 0; + + // take zenith angle dependence into account + unsigned int Ebins = iWeightFileIndex_Emax - iWeightFileIndex_Emin + 1; + unsigned int ZEbins = iWeightFileIndex_Zmax - iWeightFileIndex_Zmin + 1; + + // only energy dependent + if( ZEbins == 1 ) { - if( fTMVAData[i] ) + // fill graph to be smoothed + TGraph* iG = new TGraph( 1 ); + for( unsigned int i = 0; i < fTMVAData.size(); i++ ) { - cout << "\t TMVA values: unsmoothed at "; - cout << TMath::Power( 10., fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - cout << " TeV, \t" << fTMVAData[i]->fTMVACutValue; - fTMVAData[i]->fTMVACutValue = iGout->Eval( fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - cout << ", smoothed " << fTMVAData[i]->fTMVACutValue; - if( !fTMVAData[i]->fTMVAOptimumCutValueFound ) - { - cout << " (interpolated non-optimal value)"; - } - cout << " (" << i << ")" << endl; - fTMVAData[i]->fTMVAOptimumCutValueFound = true; - - // get efficiency histograms - TFile iTMVAFile( fTMVAData[i]->fTMVAFileName.c_str() ); - TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[i]->fTMVAMethodTag_2 ); - TH1F* effB = getEfficiencyHistogram( "effB", &iTMVAFile, fTMVAData[i]->fTMVAMethodTag_2 ); - - if( effS ) + if( fTMVAData[i] ) { - fTMVAData[i]->fSignalEfficiency = effS->GetBinContent( effS->FindBin( fTMVAData[i]->fTMVACutValue ) ); + if( fTMVAData[i]->fTMVAOptimumCutValueFound ) + { + iG->SetPoint( z, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); + z++; + } } - if( effB ) + } + // smooth graph + TGraph* iGout = new TGraph( 1 ); + TGraphSmooth* iGSmooth = new TGraphSmooth( "t" ); + iGout = ( TGraph* )iGSmooth->SmoothKern( iG, "normal", 0.5, 100 ); + //iGout = ( TGraph* )iGSmooth->SmoothLowess( iG, " ", 0.90 ); + + // fill smoothed and interpolated values into MVA vector + // set all points to 'optimized' + for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + { + if( fTMVAData[i] ) { - fTMVAData[i]->fBackgroundEfficiency = effB->GetBinContent( effB->FindBin( fTMVAData[i]->fTMVACutValue ) ); - // background efficiency might be zero -> fill it with first non-zero value - if( fTMVAData[i]->fBackgroundEfficiency < 1.e-8 ) + cout << "\t TMVA values: unsmoothed at " << TMath::Power( 10., fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + cout << " TeV, \t" << fTMVAData[i]->fTMVACutValue; + fTMVAData[i]->fTMVACutValue = iGout->Eval( fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + cout << ", smoothed " << fTMVAData[i]->fTMVACutValue; + if( !fTMVAData[i]->fTMVAOptimumCutValueFound ) + { + cout << " (interpolated non-optimal value)"; + } + cout << " (" << i << ")" << endl; + fTMVAData[i]->fTMVAOptimumCutValueFound = true; + + // get efficiency histograms + TFile iTMVAFile( fTMVAData[i]->fTMVAFileName.c_str() ); + TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[i]->fTMVAMethodTag_2 ); + TH1F* effB = getEfficiencyHistogram( "effB", &iTMVAFile, fTMVAData[i]->fTMVAMethodTag_2 ); + + if( effS ) + { + fTMVAData[i]->fSignalEfficiency = effS->GetBinContent( effS->FindBin( fTMVAData[i]->fTMVACutValue ) ); + cout << "eff S " << fTMVAData[i]->fSignalEfficiency << endl; + } + if( effB ) { - int iS = effB->FindBin( fTMVAData[i]->fTMVACutValue ); - for( int j = iS; j > 0; j-- ) + fTMVAData[i]->fBackgroundEfficiency = effB->GetBinContent( effB->FindBin( fTMVAData[i]->fTMVACutValue ) ); + // background efficiency might be zero -> fill it with first non-zero value + if( fTMVAData[i]->fBackgroundEfficiency < 1.e-8 ) { - if( effB->GetBinContent( j ) > 0. ) + int iS = effB->FindBin( fTMVAData[i]->fTMVACutValue ); + for( int j = iS; j > 0; j-- ) { - fTMVAData[i]->fBackgroundEfficiency = effB->GetBinContent( j ); - break; + if( effB->GetBinContent( j ) > 0. ) + { + fTMVAData[i]->fBackgroundEfficiency = effB->GetBinContent( j ); + break; + } } } } } } } -} - -/* - - smoothing of optimal cut value vs energy curves - - (energy and zenith angle dependent) - -*/ -void VTMVAEvaluator::smoothAndInterPolateMVAValue_Energy_and_Zenith( - TH1F* effS, TH1F* effB, - unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, - unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ) -{ - - unsigned int Ebins = iWeightFileIndex_Emax - iWeightFileIndex_Emin + 1; - unsigned int ZEbins = iWeightFileIndex_Zmax - iWeightFileIndex_Zmin + 1; - - // 2D histogram to be smoothed (energy and zenith angle dependence) - TH2D* iH2 = new TH2D( "h1", "Smooth cut values", - Ebins, iWeightFileIndex_Emin, iWeightFileIndex_Emax, - ZEbins, iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); - Double_t effS_value[Ebins * ZEbins]; - for( unsigned int l = 0; l < fTMVAData.size(); l++ ) - { - if( fTMVAData[l] ) - { - TFile iTMVAFile( fTMVAData[l]->fTMVAFileName.c_str() ); - if( iTMVAFile.IsZombie() ) - { - cout << "VTMVAEvaluator: error reading file with cut efficiencies: "; - cout << fTMVAData[l]->fTMVAFileName << endl; - cout << "Exiting..." << endl; - exit( EXIT_FAILURE ); - } - TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[l]->fTMVAMethodTag_2 ); - effS_value[l] = effS->GetBinContent( effS->FindBin( fTMVAData[l]->fTMVACutValue ) ); - } - } - for( unsigned int z = 0; z < fTMVAData.size(); z++ ) + // energy and zenith angle dependent + else { - if( !fTMVAData[z] ) - { - continue; - cout << "VTMVAEvaluator: error reading file with cut efficiencies for bins: "; - cout << ", entry " << z << endl; - cout << "Exiting..." << endl; - exit( EXIT_FAILURE ); - } - // get signal efficiency histograms and cut values - TFile iTMVAFile( fTMVAData[z]->fTMVAFileName.c_str() ); - TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[z]->fTMVAMethodTag_2 ); - if( fTMVAData[z]->fTMVAOptimumCutValueFound ) + TH2D* iH2 = new TH2D( "h1", "Smooth cut values", Ebins, iWeightFileIndex_Emin, iWeightFileIndex_Emax, ZEbins, iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); + // fill 2D histogram to be smoothed (energy and zenith angle dependence) + Double_t effS_value[Ebins * ZEbins]; + for( unsigned int l = 0; l < fTMVAData.size(); l++ ) { - iH2->SetBinContent( fTMVAData[z]->fEnergyBin, fTMVAData[z]->fZenithBin, fTMVAData[z]->fTMVACutValue ); - } - // bins without optimal cut value and not in highest energy bin - else if( !fTMVAData[z]->fTMVAOptimumCutValueFound - && ( fTMVAData[z]->fZenithBin < ZEbins ) - && ( fTMVAData[z]->fEnergyBin != Ebins - 1 ) ) - { - for( int k = 0; k < effS->GetNbinsX(); k++ ) + if( fTMVAData[l] ) { - // search for similar cut efficiency in neighbouring bin - unsigned int i_alt_index = z + 1; - if( z > 0 ) - { - i_alt_index = z - 1; - } - if( i_alt_index < fTMVAData.size() - && TMath::Abs( effS->GetBinContent( k ) - effS_value[i_alt_index] ) < 0.001 ) - { - fTMVAData[z]->fTMVACutValue = effS->GetBinCenter( k ); - effS_value[z] = effS->GetBinContent( k ); - } + TFile iTMVAFile( fTMVAData[l]->fTMVAFileName.c_str() ); + TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[l]->fTMVAMethodTag_2 ); + effS_value[l] = effS->GetBinContent( effS->FindBin( fTMVAData[l]->fTMVACutValue ) ); } } - // bins without optimal cut value and in highest energy bin - else if( !fTMVAData[z]->fTMVAOptimumCutValueFound - && ( fTMVAData[z]->fZenithBin < ZEbins ) && ( fTMVAData[z]->fEnergyBin == Ebins - 1 ) ) + for( unsigned int i = 0; i < Ebins; i++ ) { - for( unsigned int l = 0; l < ZEbins; l++ ) + for( unsigned int j = 0; j < ZEbins; j++ ) { - if( effS_value[fTMVAData.size() - l] > 1.e-10 ) + if( fTMVAData[z] ) { - for( int k = 0; k < effS->GetNbinsX(); k++ ) + // get signal efficiency histograms and cut values + TFile iTMVAFile( fTMVAData[z]->fTMVAFileName.c_str() ); + TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[z]->fTMVAMethodTag_2 ); + if( fTMVAData[z]->fTMVAOptimumCutValueFound ) + { + iH2->SetBinContent( i, j, fTMVAData[z]->fTMVACutValue ); + } + // bins without optimal cut value and not in highest energy bin + else if( !fTMVAData[z]->fTMVAOptimumCutValueFound && ( j < ZEbins ) && ( i != Ebins - 1 ) ) { - if( TMath::Abs( effS->GetBinContent( k ) - effS_value[fTMVAData.size() - l] ) < 0.0001 ) + for( int k = 0; k < effS->GetNbinsX(); k++ ) { - fTMVAData[z]->fTMVACutValue = effS->GetBinCenter( k ); - effS_value[z] = effS->GetBinContent( k ); + if( TMath::Abs( effS->GetBinContent( k ) - effS_value[z - 1] ) < 0.001 ) + { + fTMVAData[z]->fTMVACutValue = effS->GetBinCenter( k ); + effS_value[z] = effS->GetBinContent( k ); + } } } + // bins without optimal cut value and in highest energy bin + else if( !fTMVAData[z]->fTMVAOptimumCutValueFound && ( j < ZEbins ) && ( i == Ebins - 1 ) ) + { + for( unsigned int l = 0; l < ZEbins; l++ ) + { + if( effS_value[fTMVAData.size() - l] > 1.e-10 ) + { + for( int k = 0; k < effS->GetNbinsX(); k++ ) + { + if( TMath::Abs( effS->GetBinContent( k ) - effS_value[fTMVAData.size() - l] ) < 0.0001 ) + { + fTMVAData[z]->fTMVACutValue = effS->GetBinCenter( k ); + effS_value[z] = effS->GetBinContent( k ); + } + } + } + } + } + if( fTMVAData[z]->fTMVACutValue == -99 ) + { + cout << "Error: no optimal cut value found for this bin" << endl; + } + cout << "\t TMVA values: at " << TMath::Power( 10., fTMVAData[z]->fSpectralWeightedMeanEnergy_Log10TeV ); + cout << " TeV, \t" << fTMVAData[z]->fTMVACutValue; + if( !fTMVAData[z]->fTMVAOptimumCutValueFound ) + { + cout << " (interpolated non-optimal value)"; + } + cout << ", signal efficiency: " << effS_value[z]; + cout << " (" << z << ")" << endl; } + z++; } - if( fTMVAData[z]->fTMVACutValue == -99 ) - { - cout << "Error: no optimal cut value found for this bin" << endl; - } - cout << "\t TMVA values: at " << TMath::Power( 10., fTMVAData[z]->fSpectralWeightedMeanEnergy_Log10TeV ); - cout << " TeV, \t" << fTMVAData[z]->fTMVACutValue; - if( !fTMVAData[z]->fTMVAOptimumCutValueFound ) - { - cout << " (interpolated non-optimal value)"; - } - cout << ", signal efficiency: " << effS_value[z]; - cout << " (" << z << ")" << endl; } + + // smooth the histogram and draw it + /* + iH2->Smooth(); + iH2->Draw("colz"); + int t = 0; + for( unsigned int i = 0; i < Ebins; i++ ) + { + for( unsigned int j = 0; j < ZEbins; j++ ) + { + + cout << "\t TMVA values: unsmoothed at " << TMath::Power( 10., fTMVAData[t]->fSpectralWeightedMeanEnergy_Log10TeV ); + cout << " TeV, \t" << fTMVAData[t]->fTMVACutValue; + cout << ", smoothed " << iH2->GetBinContent( i, j, fTMVAData[t]->fTMVACutValue); + if( !fTMVAData[t]->fTMVAOptimumCutValueFound ) + { + cout << " (interpolated non-optimal value)"; + } + cout << " (" << t << ")" << endl; + t++; + } + }*/ } } -/* - - smoothing of optimal cut value vs energy curves - - missing (non-optimized) are interpolated - - note: signal and background efficiencies are not updated - -*/ -void VTMVAEvaluator::smoothAndInterPolateMVAValue( - TH1F* effS, TH1F* effB, - unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, - unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ) +void VTMVAEvaluator::getOptimalAngularContainmentRadius( double effS, double effB, double Ndif, double Nof, + TH2D* iHAngContainment, double iEnergy_log10_TeV, + double& i_Signal_to_sqrtNoise, double& i_AngularContainmentRadius, + double& i_AngularContainmentFraction ) { - if( fTMVAData.size() == 0 ) + i_AngularContainmentFraction = 0.; + i_Signal_to_sqrtNoise = -99.; + i_AngularContainmentRadius = -99.; + if( !iHAngContainment || fOptimizationBackgroundAlpha <= 0 ) { return; } + double iR_Max = VHistogramUtilities::interpolateTH2D( iHAngContainment, iEnergy_log10_TeV, fTMVAngularContainmentRadiusMax ); - cout << "Smooth and interpolate MVA cut values" << endl; - - ////////////////////////////////////////////// - // energy dependent TMVA cut optimization only - if( iWeightFileIndex_Zmax == iWeightFileIndex_Zmin ) - { - smoothAndInterPolateMVAValue_EnergyOnly( effS, effB ); - } - // energy and zenith angle dependent - else + // find containment radius giving maximum significance + double iC = 0.; + double iR = 0.; + double iOn = 0.; + double iOff = 0.; + double iSigma = 0.; + for( int i = 1; i < iHAngContainment->GetNbinsY(); i++ ) { - smoothAndInterPolateMVAValue_Energy_and_Zenith( - effS, effB, - iWeightFileIndex_Emin, iWeightFileIndex_Emax, - iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); + iC = iHAngContainment->GetYaxis()->GetBinLowEdge( i ); + iR = VHistogramUtilities::interpolateTH2D( iHAngContainment, iEnergy_log10_TeV, iHAngContainment->GetYaxis()->GetBinLowEdge( i ) ); + + if( iC > fTMVAngularContainmentRadiusMax ) + { + iR = iR_Max; + iC = fTMVAngularContainmentRadiusMax; + } + // make sure that containment cut is not getting too small + if( iR < fTMVAAngularContainmentThetaFixedMinRadius ) + { + continue; + } + + // gamma point source + iOn = effS * Ndif * iC / fTMVAngularContainmentRadiusMax; + iOn += effB * Nof * iR * iR / iR_Max / iR_Max; + iOff = effB * Nof / fOptimizationBackgroundAlpha * iR * iR / iR_Max / iR_Max; + + iSigma = VStatistics::calcSignificance( iOn, iOff, fOptimizationBackgroundAlpha ); + + if( iSigma >= i_Signal_to_sqrtNoise ) + { + i_Signal_to_sqrtNoise = iSigma; + i_AngularContainmentRadius = iR; + i_AngularContainmentFraction = iC; + } } } + void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSignal_to_sqrtNoise, TGraph* iGSignal_to_sqrtNoise_Smooth, TH1F* hEffS, TH1F* hEffB, - TGraph* iGSignalEvents, TGraph* iGBackgroundEvents ) + TGraph* iGSignalEvents, TGraph* iGBackgroundEvents, + TGraph* iGOpt_AngularContainmentRadius, TGraph* iGOpt_AngularContainmentFraction ) { char hname[800]; char htitle[800]; @@ -1820,7 +2067,6 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig hEffB->SetTitle( "" ); hEffB->SetLineColor( 2 ); hEffB->SetLineWidth( 3 ); - hEffB->SetLineStyle( 9 ); hEffB->DrawCopy( "same" ); } @@ -1831,12 +2077,6 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig iL->SetLineWidth( 3 ); iL->Draw(); } - - if( fPrintPlotting ) - { - sprintf( hname, "MVAOpt-SignalBackgroundEfficiency-%s.pdf", fTMVAData[iBin]->fTMVAName.c_str() ); - iCanvas->Print( hname ); - } } // signal to noise @@ -1845,28 +2085,21 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig sprintf( hname, "cSignalToSqrtNoise_%d", iBin ); sprintf( htitle, "signal / sqrt( noise ) (%s)", fTMVAData[iBin]->GetTitle() ); TCanvas* iCanvas = new TCanvas( hname, htitle, 425, 10 + iBin * 30, 400, 400 ); - iCanvas->SetLeftMargin( 0.12 ); + iCanvas->SetLeftMargin( 0.13 ); iCanvas->SetGridx( 0 ); iCanvas->SetGridy( 0 ); - sprintf( hname, "hSignalToSqrtNoise_%d", iBin ); - TH1F* iSignal_to_sqrtNoise = new TH1F( hname, "", 100, -1., 1. ); - iSignal_to_sqrtNoise->SetMinimum( 0. ); - iSignal_to_sqrtNoise->SetMaximum( 6. ); - iSignal_to_sqrtNoise->SetXTitle( "MVA value #Tau" ); - iSignal_to_sqrtNoise->SetYTitle( "significance" ); - iSignal_to_sqrtNoise->GetYaxis()->SetTitleOffset( 1.3 ); - iSignal_to_sqrtNoise->SetStats( 0 ); - iSignal_to_sqrtNoise->Draw(); - iGSignal_to_sqrtNoise->SetTitle( "" ); - setGraphPlottingStyle( iGSignal_to_sqrtNoise, 4, 1., 20, 0.5, 0, 1 ); + setGraphPlottingStyle( iGSignal_to_sqrtNoise, 1, 1., 20 ); - iGSignal_to_sqrtNoise->Draw( "pl" ); + iGSignal_to_sqrtNoise->Draw( "apl" ); + iGSignal_to_sqrtNoise->GetHistogram()->GetYaxis()->SetTitleOffset( 1.5 ); + iGSignal_to_sqrtNoise->GetHistogram()->SetXTitle( "MVA value #Tau" ); + iGSignal_to_sqrtNoise->GetHistogram()->SetYTitle( "significance" ); if( iGSignal_to_sqrtNoise_Smooth ) { - setGraphPlottingStyle( iGSignal_to_sqrtNoise_Smooth, 2, 1., 20, 0.5 ); + setGraphPlottingStyle( iGSignal_to_sqrtNoise_Smooth, 2, 2. ); iGSignal_to_sqrtNoise_Smooth->Draw( "pl" ); } @@ -1877,11 +2110,6 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig iL->SetLineStyle( 2 ); iL->Draw(); } - if( fPrintPlotting ) - { - sprintf( hname, "MVAOpt-SignalToSqrtNoise-%s.pdf", fTMVAData[iBin]->fTMVAName.c_str() ); - iCanvas->Print( hname ); - } } // signal and background events numbers @@ -1945,6 +2173,93 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig } } + // angular containment radius + if( iGOpt_AngularContainmentRadius ) + { + sprintf( hname, "cCR_%d", iBin ); + sprintf( htitle, "containment radius (%s)", fTMVAData[iBin]->GetTitle() ); + TCanvas* iCanvas = new TCanvas( hname, htitle, 750, 10 + iBin * 30, 400, 400 ); + iCanvas->SetLeftMargin( 0.13 ); + iCanvas->SetGridx( 0 ); + iCanvas->SetGridy( 0 ); + + sprintf( hname, "hBC_%d", iBin ); + TH1D* hnull = new TH1D( hname, "", 100, -1., 1. ); + hnull->SetXTitle( "cut value" ); + hnull->SetYTitle( "containment radius [deg]" ); + hnull->SetMinimum( 1.e-3 ); + double x = 0.; + double y = 0.; + double y_max = 0.; + for( int i = 0; i < iGOpt_AngularContainmentRadius->GetN(); i++ ) + { + iGOpt_AngularContainmentRadius->GetPoint( i, x, y ); + if( y > y_max ) + { + y_max = y; + } + } + if( y_max < 1.e-3 ) + { + y_max = 1.; + } + hnull->SetMaximum( y_max * 1.5 ); + hnull->SetStats( 0 ); + hnull->GetYaxis()->SetTitleOffset( 1.5 ); + hnull->DrawCopy(); + + setGraphPlottingStyle( iGOpt_AngularContainmentRadius, 1, 1., 20 ); + iGOpt_AngularContainmentRadius->Draw( "pl" ); + if( iBin < fTMVAData.size() && fTMVAData[iBin] ) + { + TLine* iL = new TLine( fTMVAData[iBin]->fTMVACutValue, hnull->GetMinimum(), fTMVAData[iBin]->fTMVACutValue, y_max * 1.5 ); + iL->SetLineStyle( 2 ); + iL->SetLineWidth( 3 ); + iL->Draw(); + } + } + // angular containment fraction + if( iGOpt_AngularContainmentFraction ) + { + sprintf( hname, "cCF_%d", iBin ); + sprintf( htitle, "containment fraction (%s)", fTMVAData[iBin]->GetTitle() ); + TCanvas* iCanvas = new TCanvas( hname, htitle, 750, 10 + iBin * 30, 400, 400 ); + iCanvas->SetLeftMargin( 0.13 ); + iCanvas->SetGridx( 0 ); + iCanvas->SetGridy( 0 ); + + sprintf( hname, "hBF_%d", iBin ); + TH1D* hnull = new TH1D( hname, "", 100, -1., 1. ); + hnull->SetXTitle( "cut value" ); + hnull->SetYTitle( "containment fraction" ); + hnull->SetMinimum( 1.e-3 ); + double x = 0.; + double y = 0.; + double y_max = 0.; + for( int i = 0; i < iGOpt_AngularContainmentFraction->GetN(); i++ ) + { + iGOpt_AngularContainmentFraction->GetPoint( i, x, y ); + if( y > y_max ) + { + y_max = y; + } + } + hnull->SetMaximum( y_max * 1.5 ); + hnull->SetStats( 0 ); + hnull->GetYaxis()->SetTitleOffset( 1.5 ); + hnull->DrawCopy(); + + setGraphPlottingStyle( iGOpt_AngularContainmentFraction, 1, 1., 20 ); + iGOpt_AngularContainmentFraction->Draw( "pl" ); + if( iBin < fTMVAData.size() && fTMVAData[iBin] ) + { + TLine* iL = new TLine( fTMVAData[iBin]->fTMVACutValue, hnull->GetMinimum(), fTMVAData[iBin]->fTMVACutValue, y_max * 1.5 ); + iL->SetLineStyle( 2 ); + iL->SetLineWidth( 3 ); + iL->Draw(); + } + } + } void VTMVAEvaluator::setTMVAMethod( string iMethodName ) @@ -2001,10 +2316,6 @@ double VTMVAEvaluator::getValueFromMap( map< unsigned int, double > iDataMap, do return -1.; } -/* - * return signal efficiency at a given energy - * - */ double VTMVAEvaluator::getSignalEfficiency( unsigned int iEnergyBin, double iE_min_log10, double iE_max_log10, unsigned int iZenithBin, double iZ_min, double iZ_max ) { return getValueFromMap( fSignalEfficiencyMap, fSignalEfficiencyNoVec, iEnergyBin, iE_min_log10, iE_max_log10, iZenithBin, iZ_min, iZ_max, "SignalEfficiency" ); @@ -2024,8 +2335,68 @@ void VTMVAEvaluator::printSensitivityOptimizationParameters() cout << "\t" << fOptimizationSourceSignificance << " minimum significance" << endl; cout << "\t" << fOptimizationMinSignalEvents << " minimum number of on events" << endl; cout << "\t" << fOptimizationBackgroundAlpha << " signal to background area ratio" << endl; - cout << "\t" << fOptimizationFixedSignalEfficiency << " maximum signal efficiency" << endl; - cout << "\t" << fOptimizationMinSourceStrength << " minimum source strength" << endl; +} + +/* + * calculate mean energy in an energy bin after applying MVA cuts + * (use training tree TrainTree out of e.g. BDT file for this) + */ +double VTMVAEvaluator::getMeanEnergyAfterCut( TFile* f, double iCut, unsigned int iDataBin ) +{ + if( !f ) + { + return -99.; + } + if( iDataBin >= fTMVAData.size() || !fTMVAData[iDataBin] ) + { + return -99.; + } + double iEmin = TMath::Power( 10., fTMVAData[iDataBin]->fEnergyCut_Log10TeV_min ); + double iEmax = TMath::Power( 10., fTMVAData[iDataBin]->fEnergyCut_Log10TeV_max ); + TTree* t = ( TTree* )f->Get( "TrainTree" ); + if( !t ) + { + cout << "VTMVAEvaluator::getMeanEnergyAfterCut(): test tree not found in " << f->GetName() << endl; + return -99.; + } + float iErec = 0.; + float iMVA = 0.; + int classID = 0;; + t->SetBranchAddress( "ErecS", &iErec ); + ostringstream iCutName; + // variable names changed with time - keep backwards compatibility + iCutName << fTMVAMethodName << "_" << fTMVAData[iDataBin]->fTMVAMethodTag_2; + if( t->GetBranchStatus( iCutName.str().c_str() ) ) + { + t->SetBranchAddress( iCutName.str().c_str(), &iMVA ); + } + else + { + iCutName.clear(); + iCutName.str( std::string() ); + iCutName << fTMVAMethodName << "_0"; + t->SetBranchAddress( iCutName.str().c_str(), &iMVA ); + } + t->SetBranchAddress( "classID", &classID ); + + float n = 0.; + float m = 0.; + for( int i = 0; i < t->GetEntries(); i++ ) + { + t->GetEntry( i ); + + if( classID == 0 && iErec > 0. && iErec > iEmin && iErec < iEmax && iMVA > iCut ) + { + m += iErec; + n++; + } + } + if( n > 0. ) + { + return m / n; + } + + return -99.; } vector< double > VTMVAEvaluator::getBackgroundEfficiency() @@ -2085,8 +2456,7 @@ vector< bool > VTMVAEvaluator::getOptimumCutValueFound() * interpolates between zenith range and return a TGraph * */ -TGraph* VTMVAEvaluator::readNonNoffGraphsFromFile( - TFile* iF, double i_ze_min, double i_ze_max, bool bIsOn ) +TGraph* VTMVAEvaluator::readNonNoffGraphsFromFile( TFile* iF, double i_ze_min, double i_ze_max, bool bIsOn ) { if( !iF && iF->IsZombie() ) { @@ -2096,6 +2466,10 @@ TGraph* VTMVAEvaluator::readNonNoffGraphsFromFile( if( bIsOn ) { i_N = iF->Get( "gONRate" ); + if( !i_N ) + { + i_N = iF->Get( "gSignalRate" ); + } } else { @@ -2142,16 +2516,13 @@ TGraph* VTMVAEvaluator::fillfromGraph2D( TObject* i_G, double i_ze_min, double i VTMVAEvaluatorData::VTMVAEvaluatorData() { - fTMVAName = ""; + fCounter = 0; fTMVAFileName = ""; fTMVAFileNameXML = ""; fTMVAMethodTag = ""; - fTMVAMethodTag_2 = ""; - fEnergyBin = 0; fEnergyCut_Log10TeV_min = -99.; fEnergyCut_Log10TeV_max = -99.; fSpectralWeightedMeanEnergy_Log10TeV = -99.; - fZenithBin = 0; fZenithCut_min = -99.; fZenithCut_max = -99.; @@ -2160,6 +2531,8 @@ VTMVAEvaluatorData::VTMVAEvaluatorData() fTMVACutValue = -99.; fTMVAOptimumCutValueFound = false; fSourceStrengthAtOptimum_CU = -99.; + fAngularContainmentRadius = -99.; + fAngularContainmentFraction = -99.; // transients fTMVAReader = 0; @@ -2168,8 +2541,8 @@ VTMVAEvaluatorData::VTMVAEvaluatorData() void VTMVAEvaluatorData::print() { cout << "\t file " << fTMVAFileName << endl; - cout << "\t energy bin [" << fEnergyCut_Log10TeV_min << "," << fEnergyCut_Log10TeV_max << "] "; - cout << "(mean energy " << fSpectralWeightedMeanEnergy_Log10TeV << ")"; + cout << "\t energy bin [" << fEnergyCut_Log10TeV_min << "," << fEnergyCut_Log10TeV_max << "] (mean energy " << fSpectralWeightedMeanEnergy_Log10TeV << ")"; cout << ", zenith bin [" << fZenithCut_min << "," << fZenithCut_max << "]"; cout << endl; } + diff --git a/src/VTMVARunData.cpp b/src/VTMVARunData.cpp index 6f167dd33..ffac166c2 100644 --- a/src/VTMVARunData.cpp +++ b/src/VTMVARunData.cpp @@ -7,20 +7,18 @@ VTMVARunData::VTMVARunData() { - setDebug( false ); + setDebug(); fName = "noname"; - fRunOption = "TRAIN"; fTrainGammaHadronSeparation = true; fTrainReconstructionQuality = false; // in development: please ignore + fCheckValidityOfInputVariables = true; + fOutputDirectoryName = ""; fOutputFileName = ""; - fnTrain_Signal = 0; - fnTrain_Background = 0; - fQualityCuts = "1"; fQualityCutsBkg = "1"; fMCxyoffCut = "1"; @@ -31,7 +29,6 @@ VTMVARunData::VTMVARunData() fBackgroundWeight = 1.; fMinSignalEvents = 50; fMinBackgroundEvents = 0; - fSelectedEventFileName = ""; fNTtype = -1; @@ -115,12 +112,12 @@ bool VTMVARunData::openDataFiles() { if( fSignalTree[k] ) { - fSignalTree[k]->Draw( ">>+signalList", - fQualityCuts - && fMCxyoffCut && - fEnergyCutData[i]->fEnergyCut && - fZenithCutData[j]->fZenithCut, - "entrylist" ); + fSignalTree[k]->Draw( ">>+signalList", + fQualityCuts + && fMCxyoffCut && + fEnergyCutData[i]->fEnergyCut && + fZenithCutData[j]->fZenithCut, + "entrylist" ); i_j_SignalList = ( TEntryList* )gDirectory->Get( "signalList" ); } } @@ -131,7 +128,7 @@ bool VTMVARunData::openDataFiles() cout << i_j_SignalList->GetN() << "\t required > " << fMinSignalEvents << endl; cout << " (cuts are " << fQualityCuts << "&&" << fMCxyoffCut; cout << "&&" << fEnergyCutData[i]->fEnergyCut << "&&" << fZenithCutData[j]->fZenithCut; - cout << ")" << endl; + cout << ")" << endl; if( i_j_SignalList->GetN() < fMinSignalEvents ) { iEnoughEvents = false; @@ -147,15 +144,15 @@ bool VTMVARunData::openDataFiles() if( fMCxyoffCutSignalOnly ) // Do we need this? { fBackgroundTree[k]->Draw( ">>+BackgroundList", fQualityCuts && fQualityCutsBkg - && fMCxyoffCut && fEnergyCutData[i]->fEnergyCut - && fZenithCutData[j]->fZenithCut, "entrylist" ); + && fMCxyoffCut && fEnergyCutData[i]->fEnergyCut + && fZenithCutData[j]->fZenithCut, "entrylist" ); i_j_BackgroundList = ( TEntryList* )gDirectory->Get( "BackgroundList" ); } else if( fBackgroundTree[k] ) { fBackgroundTree[k]->Draw( ">>+BackgroundList", fQualityCuts && fQualityCutsBkg - && fMCxyoffCut && fEnergyCutData[i]->fEnergyCut - && fZenithCutData[j]->fZenithCut, "entrylist" ); + && fMCxyoffCut && fEnergyCutData[i]->fEnergyCut + && fZenithCutData[j]->fZenithCut, "entrylist" ); i_j_BackgroundList = ( TEntryList* )gDirectory->Get( "BackgroundList" ); } } @@ -166,7 +163,7 @@ bool VTMVARunData::openDataFiles() cout << "\t required > " << fMinBackgroundEvents << endl; cout << " (cuts are " << fQualityCuts << "&&" << fQualityCutsBkg << "&&" << fMCxyoffCut; cout << "&&" << fEnergyCutData[i]->fEnergyCut << "&&" << fZenithCutData[j]->fZenithCut; - cout << ")" << endl; + cout << ")" << endl; if( i_j_BackgroundList->GetN() < fMinBackgroundEvents ) { iEnoughEvents = false; @@ -201,42 +198,36 @@ bool VTMVARunData::openDataFiles() if( fEnergyCutData.size() > 1 && fZenithCutData.size() > 1 ) { iTempS << fOutputDirectoryName << "/" << fOutputFileName; - iTempS << "_" << i << "_" << j << ".root"; // append a _# at the file name + iTempS << "_" << i << "_" << j << ".root"; // append a _# at the file name iTempS2 << fOutputFileName << "_" << i << "_" << j; } else if( fEnergyCutData.size() > 1 && fZenithCutData.size() <= 1 ) { iTempS << fOutputDirectoryName << "/" << fOutputFileName; - iTempS << "_" << i << ".root"; // append a _# at the file name + iTempS << "_" << i << ".root"; // append a _# at the file name iTempS2 << fOutputFileName << "_" << i; } else if( fZenithCutData.size() > 1 && fEnergyCutData.size() <= 1 ) { iTempS << fOutputDirectoryName << "/" << fOutputFileName; - iTempS << "_0_" << j << ".root"; // append a _# at the file name + iTempS << "_0_" << j << ".root"; // append a _# at the file name iTempS2 << fOutputFileName << "_0_" << i; } else { - iTempS << fOutputDirectoryName << "/" << fOutputFileName; - fSelectedEventFileName = iTempS.str() + "_preselect.root"; - if( fRunOption == "WRITETRAININGEVENTS" ) - { - iTempS << "_preselect"; - } - iTempS << ".root"; + iTempS << fOutputDirectoryName << "/" << fOutputFileName << ".root"; iTempS2 << fOutputFileName; } output_zenith.push_back( new TFile( iTempS.str().c_str(), "RECREATE" ) ); if( output_zenith.back()->IsZombie() ) { cout << "VTMVARunData::openDataFiles() error creating output file "; - cout << output_zenith.back()->GetName() << endl; + cout << output_zenith.back()->GetName() << endl; cout << "aborting..." << endl; return false; } output_zenith.back()->SetTitle( iTempS2.str().c_str() ); - if( i < fEnergyCutData.size() && fEnergyCutData[i] ) + if( i < fEnergyCutData.size() && fEnergyCutData[i] ) { fEnergyCutData[i]->Write(); } @@ -244,7 +235,7 @@ bool VTMVARunData::openDataFiles() { fZenithCutData[j]->Write(); } - output_zenith.back()->Write(); + output_zenith.back()->Write(); } fOutputFile.push_back( output_zenith ); } @@ -258,42 +249,6 @@ bool VTMVARunData::openDataFiles() return true; } -/* - * read a unsigned int from the TMVA option string - * - */ -unsigned int VTMVARunData::getTrainOptionValue( string iVarName, unsigned int i_default ) -{ - if( fPrepareTrainingOptions.find( iVarName ) == string::npos ) - { - return i_default; - } - size_t s_0 = fPrepareTrainingOptions.find( iVarName ) + iVarName.size() + 1; - size_t s_1 = fPrepareTrainingOptions.find( ":", s_0 ); - - return ( unsigned int )atoi( fPrepareTrainingOptions.substr( s_0, s_1 - s_0 ).c_str() ); -} - - -/* - * update number of training events, if lower than requested - * - */ -void VTMVARunData::updateTrainingEvents( string iVarName, unsigned int iNEvents ) -{ - unsigned int i_requested_nevents = getTrainOptionValue( iVarName, 0 ); - - size_t s_0 = fPrepareTrainingOptions.find( iVarName ) + iVarName.size() + 1; - size_t s_1 = fPrepareTrainingOptions.find( ":", s_0 ); - - if( iNEvents < i_requested_nevents ) - { - cout << "WARNING: changing " << iVarName << " from "; - cout << i_requested_nevents << " to " << iNEvents << endl; - fPrepareTrainingOptions.replace( s_0, s_1 - s_0, std::to_string( iNEvents ) ); - } -} - /*! print run information to screen */ @@ -377,20 +332,17 @@ void VTMVARunData::print() { cout << "energy reconstruction method " << fEnergyCutData[0]->fEnergyReconstructionMethod << endl; } - if( fRunOption == "WRITETRAININGEVENTS" ) + cout << "signal data file(s): " << endl; + for( unsigned int i = 0; i < fSignalFileName.size(); i++ ) { - cout << "signal data file(s): " << endl; - for( unsigned int i = 0; i < fSignalFileName.size(); i++ ) - { - cout << "\t" << fSignalFileName[i] << endl; - } - if( !fTrainReconstructionQuality ) + cout << "\t" << fSignalFileName[i] << endl; + } + if( !fTrainReconstructionQuality ) + { + cout << "background data file(s): " << endl; + for( unsigned int i = 0; i < fBackgroundFileName.size(); i++ ) { - cout << "background data file(s): " << endl; - for( unsigned int i = 0; i < fBackgroundFileName.size(); i++ ) - { - cout << "\t" << fBackgroundFileName[i] << endl; - } + cout << "\t" << fBackgroundFileName[i] << endl; } } cout << "output file: " << fOutputFileName << " (" << fOutputDirectoryName << ")" << endl; @@ -575,8 +527,7 @@ bool VTMVARunData::readConfigurationFile( char* iC ) { fPrepareTrainingOptions = is_stream.str().substr( is_stream.tellg(), is_stream.str().size() ).c_str(); fPrepareTrainingOptions = VUtilities::removeSpaces( fPrepareTrainingOptions ); - fnTrain_Signal = getTrainOptionValue( "nTrain_Signal", 0 ); - fnTrain_Background = getTrainOptionValue( "nTrain_Background", 0 ); + // remove all spaces } else { @@ -584,6 +535,16 @@ bool VTMVARunData::readConfigurationFile( char* iC ) return false; } } + // check event validity + if( temp == "CHECKEVENTVALIDITY" ) + { + if( !( is_stream >> std::ws ).eof() ) + { + int iT = 0; + is_stream >> iT; + fCheckValidityOfInputVariables = ( bool )iT; + } + } // signal weight if( temp == "SIGNALWEIGHT" ) { @@ -656,29 +617,18 @@ bool VTMVARunData::readConfigurationFile( char* iC ) } } // energy bins - if( temp == "ENERGYBINEDGES" ) + if( temp == "ENERGYBINS" ) { vector< double > iEnergyCut_Log10TeV_min; vector< double > iEnergyCut_Log10TeV_max; + vector< TCut > iEnergyCut; - // read in energy bin - while( !( is_stream >> std::ws ).eof() ) - { - double iT = 0.; - is_stream >> iT; - iEnergyCut_Log10TeV_min.push_back( iT ); - is_stream >> iT; - iEnergyCut_Log10TeV_max.push_back( iT ); - } - if( !fillEnergyCutData( iEnergyCut_Log10TeV_min, iEnergyCut_Log10TeV_max ) ) + // energy reconstruction method (should be 1, unless you know it better) + unsigned int iEMethod; + if( !( is_stream >> std::ws ).eof() ) { - return false; + is_stream >> iEMethod; } - } - if( temp == "ENERGYBINS" ) - { - vector< double > iEnergyCut_Log10TeV_min; - vector< double > iEnergyCut_Log10TeV_max; // read in energy bin while( !( is_stream >> std::ws ).eof() ) @@ -689,6 +639,12 @@ bool VTMVARunData::readConfigurationFile( char* iC ) } // sort sort( iEnergyCut_Log10TeV_min.begin(), iEnergyCut_Log10TeV_min.end() ); + // check sanity + if( iEnergyCut_Log10TeV_min.size() < 2 ) + { + cout << "VTMVARunData::readConfigurationFile error: need at least two energy bins " << iEnergyCut_Log10TeV_min.size() << endl; + return false; + } // fill maximum bins for( unsigned int i = 1; i < iEnergyCut_Log10TeV_min.size(); i++ ) { @@ -696,9 +652,31 @@ bool VTMVARunData::readConfigurationFile( char* iC ) } // remove last minimum iEnergyCut_Log10TeV_min.pop_back(); - if( !fillEnergyCutData( iEnergyCut_Log10TeV_min, iEnergyCut_Log10TeV_max ) ) + // fill cuts + for( unsigned int i = 0; i < iEnergyCut_Log10TeV_min.size(); i++ ) { - return false; + ostringstream iCut; + if( iEMethod == 0 ) + { + iCut << "Erec>0.&&" << iEnergyCut_Log10TeV_min[i] << "0.&&" << iEnergyCut_Log10TeV_min[i] << "SetName( "fDataEnergyCut" ); + fEnergyCutData.back()->fEnergyCutBin = 0; + fEnergyCutData.back()->fEnergyCut_Log10TeV_min = iEnergyCut_Log10TeV_min[i]; + fEnergyCutData.back()->fEnergyCut_Log10TeV_max = iEnergyCut_Log10TeV_max[i]; + fEnergyCutData.back()->fEnergyCut = iEnergyCut[i]; + fEnergyCutData.back()->fEnergyReconstructionMethod = iEMethod; } } // zenith angle bins (in [deg]) @@ -720,8 +698,7 @@ bool VTMVARunData::readConfigurationFile( char* iC ) // check sanity if( iZenithCut_min.size() < 2 ) { - cout << "VTMVARunData::readConfigurationFile error: need at least one zenith bin "; - cout << iZenithCut_min.size() << endl; + cout << "VTMVARunData::readConfigurationFile error: need at least one zenith bin " << iZenithCut_min.size() << endl; return false; } // fill maximum bins @@ -769,63 +746,3 @@ bool VTMVARunData::readConfigurationFile( char* iC ) return true; } -void VTMVARunData::shuffleFileVectors() -{ - std::random_device rd; - std::mt19937 g( rd() ); - std::shuffle( fSignalFileName.begin(), fSignalFileName.end(), g ); - std::shuffle( fBackgroundFileName.begin(), fBackgroundFileName.end(), g ); -} - -VTableLookupRunParameter* VTMVARunData::getTLRunParameter() -{ - TDirectory* iG_CurrentDirectory = gDirectory; - if( fSignalFileName.size() > 0 ) - { - TFile* iF = new TFile( fSignalFileName[0].c_str() ); - if( iF->IsZombie() ) - { - cout << "Error reading run parameters from "; - cout << fSignalFileName[0] << endl; - return 0; - } - VTableLookupRunParameter* iP = ( VTableLookupRunParameter* )iF->Get( "TLRunParameter" ); - iG_CurrentDirectory->cd(); - return iP; - } - return 0; -} - -bool VTMVARunData::fillEnergyCutData( - vector< double > iEnergyCut_Log10TeV_min, - vector< double > iEnergyCut_Log10TeV_max ) -{ - // check sanity - if( iEnergyCut_Log10TeV_min.size() < 1 ) - { - cout << "VTMVARunData::readConfigurationFile error: need at least two energy bins "; - cout << iEnergyCut_Log10TeV_min.size() << endl; - return false; - } - vector< TCut > iEnergyCut; - // fill cuts - for( unsigned int i = 0; i < iEnergyCut_Log10TeV_min.size(); i++ ) - { - ostringstream iCut; - iCut << "ErecS>0.&&" << iEnergyCut_Log10TeV_min[i]; - iCut << "SetName( "fDataEnergyCut" ); - fEnergyCutData.back()->fEnergyCutBin = 0; - fEnergyCutData.back()->fEnergyCut_Log10TeV_min = iEnergyCut_Log10TeV_min[i]; - fEnergyCutData.back()->fEnergyCut_Log10TeV_max = iEnergyCut_Log10TeV_max[i]; - fEnergyCutData.back()->fEnergyCut = iEnergyCut[i]; - } - return true; -} diff --git a/src/VTMVARunDataEnergyCut.cpp b/src/VTMVARunDataEnergyCut.cpp index b458ca474..e86d97acb 100644 --- a/src/VTMVARunDataEnergyCut.cpp +++ b/src/VTMVARunDataEnergyCut.cpp @@ -1,6 +1,7 @@ /*! \class VTMVARunDataEnergyCut \brief VTMVARunDataEnergyCut data class for TMVA energy cuts + */ #include "VTMVARunDataEnergyCut.h" @@ -22,3 +23,5 @@ void VTMVARunDataEnergyCut::print() cout << " method " << fEnergyReconstructionMethod << endl; cout << "\t cuts: " << fEnergyCut.GetTitle() << endl; } + + diff --git a/src/VTS.calculateCrabRateFromMC.cpp b/src/VTS.calculateCrabRateFromMC.cpp new file mode 100644 index 000000000..a366146f5 --- /dev/null +++ b/src/VTS.calculateCrabRateFromMC.cpp @@ -0,0 +1,173 @@ +/*! \file VTS.calculateCrabRateFromMC.cpp + \brief calculate gamma ray rate from Crab Nebula with effective areas from MC + + + +*/ + +#include "TF1.h" +#include "TFile.h" +#include "TTree.h" + +#include "CEffArea.h" +#include "VGlobalRunParameter.h" +#include "VMonteCarloRateCalculator.h" +#include "VEnergySpectrumfromLiterature.h" + +#include +#include + + +using namespace std; + +int main( int argc, char* argv[] ) +{ + const double index = 2.4; + bool bDebug = false; + + cout << endl; + cout << "VTS.calculateCrabRateFromMC (" << VGlobalRunParameter::getEVNDISP_VERSION() << ")" << endl; + cout << "--------------------------------" << endl; + if( argc != 4 ) + { + cout << "VTS.calculateCrabRateFromMC " << endl; + cout << endl; + exit( 0 ); + } + cout << endl; + cout << "selecting effective areas with spectral index " << index << endl; + + string ieff = argv[1]; + string ioffile = argv[2]; + // energy threshold + double fEnergyThreshold = atof( argv[3] ); + cout << "energy threshold: " << fEnergyThreshold << " TeV" << endl; + if( fEnergyThreshold < 1.e-2 ) + { + fEnergyThreshold = 1.e-2; // take care of log(fEnergyThreshold) + } + + double ze = 0.; + int az = 0; + double Woff = 0.; + int noise = 0; + double pedvar = 0.; + unsigned int nrates = 0; + double MCrate[1000]; + + TFile* f1 = new TFile( ioffile.c_str(), "RECREATE" ); + if( f1->IsZombie() ) + { + cout << "error opening output file: " << ioffile << endl; + exit( 0 ); + } + TTree* fMC = new TTree( "fMCRate", "MC rate predictions" ); + fMC->Branch( "ze", &ze, "ze/D" ); + fMC->Branch( "az", &az, "az/I" ); + fMC->Branch( "Woff", &Woff, "Woff/D" ); + fMC->Branch( "noise", &noise, "noise/I" ); + fMC->Branch( "pedvar", &pedvar, "pedvar/D" ); + fMC->Branch( "nrates", &nrates, "nrates/i" ); + fMC->Branch( "MCrate", MCrate, "MCrate[nrates]/D" ); + + TFile* f = new TFile( ieff.c_str() ); + if( f->IsZombie() ) + { + cout << "error opening file with effective areas: " << ieff << endl; + exit( 0 ); + } + TTree* t = ( TTree* )gDirectory->Get( "fEffArea" ); + if( !t ) + { + exit( 0 ); + } + CEffArea* c = new CEffArea( t ); + + // Crab Nebula Spectra + vector< unsigned int > fID; + fID.push_back( 1 ); // Whipple + fID.push_back( 5 ); // HEGRA + /* fID.push_back( 2 ); // H.E.S.S. + fID.push_back( 5 ); // HEGRA + fID.push_back( 6 ); // MAGIC */ + vector< VEnergySpectrumfromLiterature* > fESpecFun; + char hname[2000]; + VGlobalRunParameter* fRunParameter = new VGlobalRunParameter(); + sprintf( hname, "%s/AstroData/TeV_data/EnergySpectrum_literatureValues_CrabNebula.dat", fRunParameter->getDirectory_EVNDISPAnaData().c_str() ); + VEnergySpectrumfromLiterature* fESpec = new VEnergySpectrumfromLiterature( hname ); + if( fESpec->isZombie() ) + { + exit( -1 ); + } + for( unsigned int i = 0; i < fID.size(); i++ ) + { + fESpecFun.push_back( fESpec ); + } + + // error checks + if( fESpecFun.size() != fID.size() ) + { + cout << "Error: vector mismatch - check code" << endl; + exit( -1 ); + } + + // print everything + for( unsigned int i = 0; i < fESpecFun.size(); i++ ) + { + if( fESpecFun[i] ) + { + fESpecFun[i]->listValues( fID[i] ); + } + } + + // rate calculator + VMonteCarloRateCalculator* fMCR = new VMonteCarloRateCalculator(); + + cout << endl; + cout << "reading " << c->fChain->GetEntries() << " effective areas " << endl; + + // loop over all effective areas and calculate expected rates + unsigned int iN = c->fChain->GetEntries(); + for( unsigned int i = 0; i < iN; i++ ) + { + c->GetEntry( i ); + + if( TMath::Abs( c->index - index ) > 1.e-2 ) + { + continue; + } + if( i % 5000 == 0 ) + { + cout << "now at entry " << i << endl; + } + + ze = c->ze; + az = c->az; + Woff = c->Woff; + noise = c->noise; + pedvar = c->pedvar; + + vector< double > fenergy; + vector< double > feffectivearea; + for( int e = 0; e < c->nbins; e++ ) + { + fenergy.push_back( c->e0[e] ); + feffectivearea.push_back( c->eff[e] ); + } + + // hardwire Whipple spectrum (much faster than outer functino call) + nrates = 1; + MCrate[0] = fMCR->getMonteCarloRate( fenergy, feffectivearea, -2.440, 3.250e-11, 1., fEnergyThreshold, 1.e7, bDebug ); + /* for( unsigned int t = 0; t < fESpecFun.size(); t++ ) + { + MCrate[t] = fMCR->getMonteCarloRate( fenergy, feffectivearea, fESpecFun[t], fID[t], fEnergyThreshold, 1.e7, bDebug ); + if( bDebug ) cout << "MC Rate " << ze << "\t" << MCrate[t] << endl; + } */ + fMC->Fill(); + } + cout << endl; + cout << "writing results to " << f1->GetName() << endl; + f1->cd(); + fMC->Write(); + f1->Close(); +} diff --git a/src/VTS.getRunListFromDB.cpp b/src/VTS.getRunListFromDB.cpp index 8ae3a8c5d..328a8dff1 100644 --- a/src/VTS.getRunListFromDB.cpp +++ b/src/VTS.getRunListFromDB.cpp @@ -255,11 +255,7 @@ void parseOptions( int argc, char* argv[] ) { char readme[500]; sprintf( readme, "cat %s/README/README.GETRUNLIST", ENV ); - int sys_ret = system( readme ); - if( sys_ret == -1 ) - { - cout << "error reading " << readme << endl; - } + system( readme ); } else { diff --git a/src/VTableLookupDataHandler.cpp b/src/VTableLookupDataHandler.cpp index 61d0b2f9a..40f4fdbcd 100644 --- a/src/VTableLookupDataHandler.cpp +++ b/src/VTableLookupDataHandler.cpp @@ -291,7 +291,7 @@ bool VTableLookupDataHandler::getNextEvent( bool bShort ) int VTableLookupDataHandler::fillNextEvent( bool bShort ) { /////////////////////////////////////////////////////////////////////////////// - // read partial event for quick reconstruction quality assessment + // read partical event for quick reconstruction quality assessment if( !fshowerpars->GetEntry( fEventCounter ) ) { return -1; @@ -1913,10 +1913,10 @@ void VTableLookupDataHandler::writeDeadTimeHistograms() TDirectoryFile* iDeadtimeDirectory = ( TDirectoryFile* )f->Get( "deadTimeHistograms" ); if( iDeadtimeDirectory ) { - fDeadTime->readHistograms( iDeadtimeDirectory ); fDeadTime->calculateDeadTime(); fDeadTime->printDeadTime(); fDeadTime->writeHistograms(); + fDeadTime->readHistograms( iDeadtimeDirectory ); } } } diff --git a/src/calculateCrabRateFromMC.cpp b/src/calculateCrabRateFromMC.cpp deleted file mode 100644 index c2ebe7c40..000000000 --- a/src/calculateCrabRateFromMC.cpp +++ /dev/null @@ -1,570 +0,0 @@ -/*! \file VTS.calculateCrabRateFromMC.cpp - \brief calculate gamma ray rate from Crab Nebula with effective areas from MC - - - -*/ - -#include "TF1.h" -#include "TFile.h" -#include "TGraph2DErrors.h" -#include "TProfile2D.h" -#include "TTree.h" - -#include "CEffArea.h" -#include "VGlobalRunParameter.h" -#include "VMonteCarloRateCalculator.h" - -#include -#include -#include - - -using namespace std; - -/* - * fill profile histogram with a new rate entry - * - */ -void fill_profilehistogram_for_TMVA( - TProfile2D* fMCRates_TMVA, - double i_E, double i_Ze, double iRate ) -{ - if( fMCRates_TMVA && iRate > 0. ) - { - fMCRates_TMVA->Fill( i_E, i_Ze, iRate ); - } -} - -/* - * read zenith bin vector from MC tree - * - */ -vector< double > read_zenith_bins( string fEffAreaFile ) -{ - TFile* f = new TFile( fEffAreaFile.c_str() ); - if( f->IsZombie() ) - { - cout << "error opening file with effective areas " << fEffAreaFile << endl; - exit( EXIT_FAILURE ); - } - TTree* t = ( TTree* )gDirectory->Get( "fEffAreaH2F" ); - if( !t ) - { - cout << "error reading effective area tree from " << fEffAreaFile << endl; - exit( EXIT_FAILURE ); - } - float ze = 0.; - t->SetBranchAddress( "ze", &ze ); - // - read unique vector of zenith angles - vector< double > tmp_zebins; - for( unsigned int i = 0; i < t->GetEntries(); i++ ) - { - t->GetEntry( i ); - bool bFound = false; - for( unsigned int z = 0; z < tmp_zebins.size(); z++ ) - { - if( TMath::Abs( ze - tmp_zebins[z] ) < 1.e-1 ) - { - bFound = true; - break; - } - } - if( !bFound ) - { - tmp_zebins.push_back( ze ); - } - } - tmp_zebins.push_back( tmp_zebins.back() + 10. ); - vector< double > tmp_zebin_edges; - tmp_zebin_edges.push_back( 0. ); - for( unsigned int z = 1; z < tmp_zebins.size(); z++ ) - { - tmp_zebin_edges.push_back( 0.5 * ( tmp_zebins[z] + tmp_zebins[z - 1] ) ); - } - cout << "Zenith bins: "; - for( unsigned int z = 0; z < tmp_zebin_edges.size(); z++ ) - { - cout << tmp_zebin_edges[z] << ", "; - } - cout << endl; - - f->Close(); - - return tmp_zebin_edges; -} - -vector< pair< double, double > > read_energy_minmax_pairs( - vector< double > tmp_ebins_histo, string iEnergyKeyWord ) -{ - vector< pair< double, double > > e; - if( tmp_ebins_histo.size() > 1 ) - { - if( iEnergyKeyWord == "ENERGYBINS" ) - { - for( unsigned int i = 0; i < tmp_ebins_histo.size() - 1; i++ ) - { - e.push_back( make_pair( tmp_ebins_histo[i], tmp_ebins_histo[i + 1] ) ); - } - } - else - { - for( unsigned int i = 0; i < tmp_ebins_histo.size(); i += 2 ) - { - e.push_back( make_pair( tmp_ebins_histo[i], tmp_ebins_histo[i + 1] ) ); - } - } - } - return e; -} - - -/* - * read energy bin vector from TMVA run parameter file - * - * ENERGYBINEDGES -1.5 -0.5 -1. 0. -0.5 0.5 0.0 1. 0.5 2.0 - * ENERGYBINS -1.50 -0.75 -0.25 0.5 2.0 - */ -vector< double > read_energy_bins( - string iTMVAParameterFile, - string iEnergyKeyWord ) -{ - vector< double > tmp_e; - ifstream is( iTMVAParameterFile.c_str(), ifstream::in ); - if( !is ) - { - cout << "Error reading energy bins from TMVA run parameter file" << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } - string is_line; - string temp; - while( getline( is, is_line ) ) - { - if( is_line.size() == 0 ) - { - continue; - } - istringstream is_stream( is_line ); - if( ( is_stream >> std::ws ).eof() ) - { - continue; - } - is_stream >> temp; - if( temp != "*" ) - { - continue; - } - is_stream >> temp; - if( temp == iEnergyKeyWord ) - { - while( !( is_stream >> std::ws ).eof() ) - { - double iT = 0.; - is_stream >> iT; - tmp_e.push_back( iT ); - } - } - } - is.close(); - - return tmp_e; -} - -/* - * convert overlapping pairs of energy bin definitions to non-overlapping - * for histogram definition - * Energy bins (rate calculation): [-1.5, -0.5], [-1, 0], [-0.5, 0.5], [0, 1], [0.5, 2], -*/ -vector< double > read_energy_histo( vector< pair< double, double >> ebins ) -{ - vector< double > e; - if( ebins.size() == 0 ) - { - return e; - } - e.push_back( ebins[0].first ); - for( unsigned int i = 0; i < ebins.size() - 1; i++ ) - { - e.push_back( 0.5 * ( ebins[i].first + ebins[i + 1].second ) ); - } - e.push_back( ebins.back().second ); - - return e; -} - -/* - initialize profile histograms rates as function of energy and zenith angle - - entry 0: MC rates from the Crab nebula - -*/ -vector< TProfile2D* > initializeRateProfileHistos( - string fEffAreaFile, string fTMVAParameterFile, vector< double > tmp_ebins ) -{ - vector< TProfile2D* > h; - - vector< double > tmp_zebin_edges = read_zenith_bins( fEffAreaFile ); - - double* ie = &tmp_ebins[0]; - double* iz = &tmp_zebin_edges[0]; - h.push_back( new TProfile2D( - "MCRatesTMVA", "", - ( int )tmp_ebins.size() - 1, ie, - ( int )tmp_zebin_edges.size() - 1, iz ) ); - h.back()->SetXTitle( "log_{10} Energy/TeV" ); - h.back()->SetYTitle( "zenith angle (deg)" ); - h.back()->SetZTitle( "rate from Crab Nebula (1/min)" ); - - h.push_back( new TProfile2D( - "BackgroundRatesTMVA", "", - ( int )tmp_ebins.size() - 1, ie, - ( int )tmp_zebin_edges.size() - 1, iz ) ); - h.back()->SetXTitle( "log_{10} Energy/TeV" ); - h.back()->SetYTitle( "zenith angle (deg)" ); - h.back()->SetZTitle( "background rate (1/min)" ); - - return h; -} - -/* - * fill MC rates from effective area trees - * - */ -TTree* fillMCRates( - string fEffAreaFile, - TProfile2D* h, - double fEnergyThreshold, - double fDeadTime, - vector< pair< double, double > > ebins ) -{ - float ze = 0.; - int az = 0; - float Woff = 0.; - int noise = 0; - float pedvar = 0.; - float MCrate; - - TTree* fMC = new TTree( "fMCRate", "MC rate predictions" ); - fMC->Branch( "ze", &ze, "ze/F" ); - fMC->Branch( "az", &az, "az/I" ); - fMC->Branch( "Woff", &Woff, "Woff/F" ); - fMC->Branch( "noise", &noise, "noise/I" ); - fMC->Branch( "pedvar", &pedvar, "pedvar/F" ); - fMC->Branch( "MCrate", &MCrate, "MCrate/F" ); - - TFile* f = new TFile( fEffAreaFile.c_str() ); - if( f->IsZombie() ) - { - cout << "error opening file with effective areas " << fEffAreaFile << endl; - exit( EXIT_FAILURE ); - } - TTree* t = ( TTree* )gDirectory->Get( "fEffAreaH2F" ); - if( !t ) - { - cout << "error reading effective area tree from " << fEffAreaFile << endl; - exit( EXIT_FAILURE ); - } - UShort_t t_az = 0; - UShort_t t_noise = 0; - UShort_t t_nbins = 0; - float t_e0[1000]; - float t_eff[1000]; - t->SetBranchAddress( "ze", &ze ); - t->SetBranchAddress( "az", &t_az ); - t->SetBranchAddress( "Woff", &Woff ); - t->SetBranchAddress( "noise", &t_noise ); - t->SetBranchAddress( "pedvar", &pedvar ); - t->SetBranchAddress( "nbins", &t_nbins ); - t->SetBranchAddress( "e0", t_e0 ); - t->SetBranchAddress( "eff", t_eff ); - - // rate calculator - VMonteCarloRateCalculator* fMCR = new VMonteCarloRateCalculator(); - // hardwired Whipple spectrum - double fWhippleNorm = 3.250e-11; - double fWhippleIndex = -2.440; - - // loop over all effective areas and calculate expected rates - unsigned int iN = t->GetEntries(); - - cout << "reading " << iN << " effective areas from "; - cout << fEffAreaFile << endl; - cout << endl; - for( unsigned int i = 0; i < iN; i++ ) - { - t->GetEntry( i ); - - az = ( int )t_az; - noise = ( int )t_noise; - - vector< double > fenergy; - vector< double > feffectivearea; - for( int e = 0; e < t_nbins; e++ ) - { - fenergy.push_back( t_e0[e] ); - feffectivearea.push_back( t_eff[e] ); - } - - MCrate = fMCR->getMonteCarloRate( - fenergy, feffectivearea, - fWhippleIndex, fWhippleNorm, 1., fEnergyThreshold, 1.e7, false ); - MCrate *= ( 1. - fDeadTime / 100. ); - fMC->Fill(); - - for( unsigned int e = 0; e < ebins.size(); e++ ) - { - fill_profilehistogram_for_TMVA( - h, - 0.5 * ( ebins[e].first + ebins[e].second ), - ze, - fMCR->getMonteCarloRate( - fenergy, feffectivearea, - fWhippleIndex, fWhippleNorm, 1., - TMath::Power( 10., ebins[e].first ), - TMath::Power( 10., ebins[e].second ), - false ) * ( 1. - fDeadTime / 100. ) ); - } - } - f->Close(); - return fMC; -} - -/* - * read list of runs - * -*/ -vector< string > read_run_list( string iRunList ) -{ - vector< string > i_runs; - ifstream is( iRunList.c_str(), ifstream::in ); - if( !is ) - { - cout << "Error reading run list of background files" << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } - string is_line; - while( getline( is, is_line ) ) - { - i_runs.push_back( is_line ); - } - cout << "Found list with " << i_runs.size() << " background runs" << endl; - - return i_runs; -} - -/* - * fill background rates for a given run - * - * assume that anasum files contain a single run only (!!) - */ -void fillBackgroundRates_perRun( - string i_runFileName, - TProfile2D* h, - vector< pair< double, double > > ebins ) -{ - TFile* f = new TFile( i_runFileName.c_str() ); - if( f->IsZombie() ) - { - cout << "Background rate file not found: " << i_runFileName << endl; - return; - } - TTree* t = ( TTree* )f->Get( "total_1/stereo/tRunSummary" ); - if( !t ) - { - cout << "Background rate file incomplete (missing tRunSummary tree): " << i_runFileName << endl; - return; - } - int runOn = 0; - double elevationOff = 0.; - double OffNorm = 0.; - double NOff = 0.; - double tOff = 0.; - t->SetBranchAddress( "runOn", &runOn ); - t->SetBranchAddress( "elevationOff", &elevationOff ); - t->SetBranchAddress( "OffNorm", &OffNorm ); - t->SetBranchAddress( "tOff", &tOff ); - t->SetBranchAddress( "NOff", &NOff ); - t->GetEntry( 0 ); - // skip runs shorter than 10 min - if( tOff < 600. || NOff < 0.01 ) - { - cout << "\t skipping short run " << runOn << " (run length " << tOff << "s)" << endl; - f->Close(); - return; - } - cout << "RUN " << elevationOff << ", " << tOff << ", " << OffNorm; - cout << ", " << elevationOff << ", " << NOff << ", " << runOn << endl; - stringstream iTemp; - iTemp << "run_" << runOn << "/stereo/energyHistograms/herecCounts_off"; - TH1D* hOff = ( TH1D* )f->Get( iTemp.str().c_str() ); - if( !hOff ) - { - cout << "Background rate file incomplete (missing off histogram)" << i_runFileName << endl; - return; - } - for( unsigned int e = 0; e < ebins.size(); e++ ) - { - int i_binStart = hOff->GetXaxis()->FindBin( ebins[e].first ); - int i_binStop = hOff->GetXaxis()->FindBin( ebins[e].second ); - double iR = 0.; - for( int b = i_binStart; b <= i_binStop; b++ ) - { - iR += hOff->GetBinContent( b ); - } - if( tOff > 0. && iR > 0. ) - { - h->Fill( - 0.5 * ( ebins[e].first + ebins[e].second ), - 90. - elevationOff, - iR * OffNorm / tOff * 60. ); - } - } - - f->Close(); -} - - -/* - * fill background rates from anasum files - * - */ -void fillBackgroundRates( string iRunList, TProfile2D* h, vector< pair< double, double > > ebins ) -{ - vector< string > i_runs = read_run_list( iRunList ); - - for( unsigned int i = 0; i < i_runs.size(); i++ ) - { - fillBackgroundRates_perRun( i_runs[i], h, ebins ); - } -} - -/* - * convert 2D histograms to 2D graphs - * - */ -TGraph2DErrors* getTGraph2D( vector< TProfile2D* > h, string iGraphName ) -{ - TGraph2DErrors* i_g = new TGraph2DErrors( 1 ); - i_g->SetName( iGraphName.c_str() ); - if( iGraphName == "gONRate" ) - { - i_g->SetTitle( "signal + background rate (1/s)" ); - } - else - { - i_g->SetTitle( "background rate (1/s)" ); - } - unsigned int z = 0; - for( int b_x = 1; b_x <= h[1]->GetNbinsX(); b_x++ ) - { - for( int b_y = 1; b_y <= h[1]->GetNbinsY(); b_y++ ) - { - double i_z = h[1]->GetBinContent( b_x, b_y ); - if( iGraphName == "gONRate" ) - { - i_z += h[0]->GetBinContent( b_x, b_y ); - } - // expect rate graphs in 1./s - i_g->SetPoint( - z, - h[1]->GetXaxis()->GetBinCenter( b_x ), - h[1]->GetYaxis()->GetBinCenter( b_y ), - i_z / 60. ); - i_g->SetPointError( z, 0., 0., 0. ); - z++; - } - } - return i_g; -} - - -int main( int argc, char* argv[] ) -{ - cout << endl; - cout << "calculateCrabRateFromMC (" << VGlobalRunParameter::getEVNDISP_VERSION() << ")" << endl; - cout << "--------------------------------" << endl; - if( argc != 6 ) - { - cout << "VTS.calculateCrabRateFromMC "; - cout << " "; - cout << ""; - cout << endl << endl; - exit( EXIT_SUCCESS ); - } - cout << endl; - - string fEffAreaFile = argv[1]; - string ioffile = argv[2]; - double fDeadTime = atof( argv[3] ); - cout << "dead time (%): " << fDeadTime << endl; - double fEnergyThreshold = 0.01; - cout << "energy threshold (hardwired): " << fEnergyThreshold << " TeV" << endl; - if( fEnergyThreshold < 1.e-2 ) - { - fEnergyThreshold = 1.e-2; // take care of log(fEnergyThreshold) - } - string fTMVAParameterFile = argv[4]; - string fBackgroundRunList = argv[5]; - - cout << "Note! Hardwired Whipple spectrum (power law)" << endl; - - TFile* f1 = new TFile( ioffile.c_str(), "RECREATE" ); - if( f1->IsZombie() ) - { - cout << "error opening output file: " << ioffile << endl; - exit( EXIT_SUCCESS ); - } - // two types of energy binning - // - for rate integration (possibly overlapping bins used for TMVA - // training and evaluation) - // - for histogram definition (non-overlapping) - vector< double > tmp_ebins_histo = read_energy_bins( fTMVAParameterFile, "ENERGYBINS" ); - vector< pair< double, double > > tmp_ebins; - if( tmp_ebins_histo.size() > 0 ) - { - tmp_ebins = read_energy_minmax_pairs( tmp_ebins_histo, "ENERGYBINS" ); - } - else - { - tmp_ebins = read_energy_minmax_pairs( - read_energy_bins( fTMVAParameterFile, "ENERGYBINEDGES" ), "ENERGYBINEDGES" ); - tmp_ebins_histo = read_energy_histo( tmp_ebins ); - } - - cout << "Energy bins (rate calculation): "; - for( unsigned int i = 0; i < tmp_ebins.size(); i++ ) - { - cout << "[" << tmp_ebins[i].first << ", " << tmp_ebins[i].second << "], "; - } - cout << endl; - cout << "Energy bins (histogram): "; - for( unsigned int e = 0; e < tmp_ebins_histo.size(); e++ ) - { - cout << tmp_ebins_histo[e] << ", "; - } - cout << endl; - - vector< TProfile2D* > hRateProfileHisto = initializeRateProfileHistos( - fEffAreaFile, fTMVAParameterFile, tmp_ebins_histo ); - - TTree* fMC = fillMCRates( - fEffAreaFile, hRateProfileHisto[0], - fEnergyThreshold, fDeadTime, - tmp_ebins ); - - fillBackgroundRates( - fBackgroundRunList, hRateProfileHisto[1], tmp_ebins ); - - cout << "writing results to " << f1->GetName() << endl; - f1->cd(); - fMC->Write(); - for( unsigned int i = 0; i < hRateProfileHisto.size(); i++ ) - { - hRateProfileHisto[i]->Write(); - } - getTGraph2D( hRateProfileHisto, "gONRate" )->Write(); - getTGraph2D( hRateProfileHisto, "gBGRate" )->Write(); - f1->Close(); -} diff --git a/src/combineEffectiveAreas.cpp b/src/combineEffectiveAreas.cpp index d93ed4fd8..f6588b3a8 100644 --- a/src/combineEffectiveAreas.cpp +++ b/src/combineEffectiveAreas.cpp @@ -455,11 +455,7 @@ void write_log_files( vector< string > file_list, string outputfile ) i_sys << outputfile << ".combine.log"; cout << "merge log files into " << i_sys.str() << endl; - int sys_ret = system( i_sys.str().c_str() ); - if( sys_ret == -1 ) - { - cout << "Error executing system command " << i_sys.str() << endl; - } + system( i_sys.str().c_str() ); cout << "done.." << endl; } diff --git a/src/compareDatawithMC.cpp b/src/compareDatawithMC.cpp index c634f135f..8b7fb2161 100644 --- a/src/compareDatawithMC.cpp +++ b/src/compareDatawithMC.cpp @@ -208,8 +208,7 @@ int main( int argc, char* argv[] ) cout << "(e.g. from Crab Nebula or Mrk 421 observations)" << endl; cout << endl; cout << endl; - cout << "compareDatawithMC "; - cout << "[BDT gamma/hadron cuts] [epoch_ATM] [shower max zenith angle (default=20deg)]" << endl; + cout << "compareDatawithMC [BDT gamma/hadron cuts] [shower max zenith angle (default=20deg)]" << endl; cout << endl; cout << "\t input file list: see example file COMPAREMC.runparameter in the parameter files directory" << endl; cout << "\t cuts: " << endl; @@ -235,17 +234,19 @@ int main( int argc, char* argv[] ) readInputfile( fInputFile ); int fSingleTelescopeCuts = atoi( argv[2] ); + string fOutputfile = argv[3]; bool fCalculateMVACut = false; + if( argc > 4 && atoi( argv[4] ) == 1 ) { fCalculateMVACut = true; } - string fEpochATM = ""; + double fShowerMaxZe_deg = 20.; if( argc > 5 ) { - fEpochATM = argv[5]; + fShowerMaxZe_deg = atof( argv[5] ); } // test number of telescopes @@ -266,6 +267,7 @@ int main( int argc, char* argv[] ) } } } + // -------- end of reading input parameters TH1D* hAzOn = 0; @@ -278,9 +280,10 @@ int main( int argc, char* argv[] ) { if( fInputData[i].fType == "ON" ) { - VDataMCComparision iTemp( fInputData[i].fType, fInputData[i].fNTelescopes ); + VDataMCComparision iTemp( fInputData[i].fType, fInputData[i].fNTelescopes, fCalculateMVACut ); iTemp.setAzRange( fInputData[i].fAz_deg_min, fInputData[i].fAz_deg_max ); iTemp.setZeRange( fInputData[i].fZe_deg_min, fInputData[i].fZe_deg_max ); + iTemp.setShowerMaximZe_deg( fShowerMaxZe_deg ); hAzOn = iTemp.getAzimuthWeightingHistogram( fInputData[i].fFileName ); if( hAzOn ) { @@ -308,19 +311,14 @@ int main( int argc, char* argv[] ) { cout << fInputData[i].fType << endl; cout << "----" << endl; - fStereoCompare.push_back( new VDataMCComparision( fInputData[i].fType, fInputData[i].fNTelescopes ) ); - if( fCalculateMVACut ) - { - fStereoCompare.back()->setTMVABDTComparision( fEpochATM ); - } + fStereoCompare.push_back( new VDataMCComparision( fInputData[i].fType, fInputData[i].fNTelescopes, fCalculateMVACut ) ); fStereoCompare.back()->setAzRange( fInputData[i].fAz_deg_min, fInputData[i].fAz_deg_max ); fStereoCompare.back()->setZeRange( fInputData[i].fZe_deg_min, fInputData[i].fZe_deg_max ); // get telescope coordinates fStereoCompare.back()->resetTelescopeCoordinates(); for( int t = 0; t < fInputData[i].fNTelescopes; t++ ) { - if( !fStereoCompare.back()->setTelescopeCoordinates( - fInputData[i].fTelX[t], fInputData[i].fTelY[t], fInputData[i].fTelZ[t] ) ) + if( !fStereoCompare.back()->setTelescopeCoordinates( fInputData[i].fTelX[t], fInputData[i].fTelY[t], fInputData[i].fTelZ[t] ) ) { exit( EXIT_FAILURE ); } @@ -353,7 +351,7 @@ int main( int argc, char* argv[] ) // calculate difference histograms cout << "DIFF" << endl; cout << "----" << endl; - VDataMCComparision* fDiff = new VDataMCComparision( "DIFF", iNT ); + VDataMCComparision* fDiff = new VDataMCComparision( "DIFF", iNT, fCalculateMVACut ); // assume 5 background regions fDiff->setOnOffHistograms( fStereoCompareOn, fStereoCompareOff, 1. / 5. ); fDiff->writeHistograms( fOutputfile ); diff --git a/src/makeEffectiveArea.cpp b/src/makeEffectiveArea.cpp index d569826a4..cd36c1afc 100644 --- a/src/makeEffectiveArea.cpp +++ b/src/makeEffectiveArea.cpp @@ -94,7 +94,7 @@ int main( int argc, char* argv[] ) fRunPara->print(); ///////////////////////////////////////////////////////////////// - // open output file and write results to disk + // open output file and write results to dist TFile* fOutputfile = new TFile( fOutputfileName.c_str(), "RECREATE" ); if( fOutputfile->IsZombie() ) { @@ -108,7 +108,7 @@ int main( int argc, char* argv[] ) VGammaHadronCuts* fCuts = new VGammaHadronCuts(); fCuts->initialize(); fCuts->setNTel( fRunPara->telconfig_ntel, fRunPara->telconfig_arraycentre_X, fRunPara->telconfig_arraycentre_Y ); - fCuts->setInstrumentEpoch( fRunPara->getInstrumentATMString() ); + fCuts->setInstrumentEpoch( fRunPara->getInstrumentEpoch( true ) ); fCuts->setTelToAnalyze( fRunPara->fTelToAnalyse ); if( !fCuts->readCuts( fRunPara->fCutFileName, 2 ) ) { @@ -246,7 +246,7 @@ int main( int argc, char* argv[] ) if( fMC_histo ) { fMC_histo->matchDataVectors( fRunPara->fAzMin, fRunPara->fAzMax, fRunPara->fSpectralIndex ); - // fMC_histo->print(); + fMC_histo->print(); } else { diff --git a/src/makeRadialAcceptance.cpp b/src/makeRadialAcceptance.cpp index 6db1ce7f7..c5c70e890 100644 --- a/src/makeRadialAcceptance.cpp +++ b/src/makeRadialAcceptance.cpp @@ -92,7 +92,7 @@ int main( int argc, char* argv[] ) // read gamma/hadron cuts from cut file VGammaHadronCuts* fCuts = new VGammaHadronCuts(); - // fCuts->setInstrumentEpoch( fInstrumentEpoch ); + fCuts->setInstrumentEpoch( fInstrumentEpoch ); fCuts->setTelToAnalyze( teltoana ); fCuts->setNTel( ntel ); if( cutfilename.size() > 0 ) @@ -180,12 +180,10 @@ int main( int argc, char* argv[] ) } } - // loop over all files and fill acceptances for( unsigned int i = 0; i < fRunPara->fRunList.size(); i++ ) { sprintf( ifile, "%s/%d.mscw.root", datadir.c_str(), fRunPara->fRunList[i].fRunOff ); - cout << "now chaining " << ifile; - cout << " (wobble offset " << -1.*fRunPara->fRunList[i].fWobbleNorth << ", " << fRunPara->fRunList[i].fWobbleWest << ")" << endl; + cout << "now chaining " << ifile << " (wobble offset " << -1.*fRunPara->fRunList[i].fWobbleNorth << ", " << fRunPara->fRunList[i].fWobbleWest << ")" << endl; // test if file exists TFile fTest( ifile ); if( fTest.IsZombie() ) @@ -199,34 +197,31 @@ int main( int argc, char* argv[] ) // Check number of telescopes in run VEvndispRunParameter* iParV2 = ( VEvndispRunParameter* )fTest.Get( "runparameterV2" ); - if( !iParV2 ) + if( iParV2 ) { - cout << "Error reading run parameters " << endl; - continue; - } - cout << "Testing telescope multiplicity " << teltoanastring << endl; - if( teltoana.size() != iParV2->fTelToAnalyze.size() || !equal( teltoana.begin(), teltoana.end(), iParV2->fTelToAnalyze.begin() ) ) - { - cout << endl; - cout << "error: Requested telescopes " << teltoanastring << " do not equal telescopes in run " << ifile << endl; - cout << "PAR "; - for( unsigned int i = 0; i < iParV2->fTelToAnalyze.size(); i++ ) - { - cout << iParV2->fTelToAnalyze[i] << " "; - } - cout << endl; - cout << "USER "; - for( unsigned int i = 0; i < teltoana.size(); i++ ) + cout << "Testing telescope multiplicity " << teltoanastring << endl; + if( teltoana.size() != iParV2->fTelToAnalyze.size() || !equal( teltoana.begin(), teltoana.end(), iParV2->fTelToAnalyze.begin() ) ) { - cout << teltoana[i] << " "; + cout << endl; + cout << "error: Requested telescopes " << teltoanastring << " do not equal telescopes in run " << ifile << endl; + cout << "PAR "; + for( unsigned int i = 0; i < iParV2->fTelToAnalyze.size(); i++ ) + { + cout << iParV2->fTelToAnalyze[i] << " "; + } + cout << endl; + cout << "USER "; + for( unsigned int i = 0; i < teltoana.size(); i++ ) + { + cout << teltoana[i] << " "; + } + cout << endl; + cout << "\t" << teltoana.size() << "\t" << iParV2->fTelToAnalyze.size() << endl; + exit( EXIT_FAILURE ); } - cout << endl; - cout << "\t" << teltoana.size() << "\t" << iParV2->fTelToAnalyze.size() << endl; - exit( EXIT_FAILURE ); } // set gamma/hadron cuts - fCuts->setInstrumentEpoch( iParV2->getInstrumentATMString() ); fCuts->initializeCuts( fRunPara->fRunList[i].fRunOff, datadir ); // pointer to data tree fCuts->setDataTree( d ); diff --git a/src/printRunParameter.cpp b/src/printRunParameter.cpp index 5099e2f25..231258562 100644 --- a/src/printRunParameter.cpp +++ b/src/printRunParameter.cpp @@ -105,8 +105,6 @@ bool readRunParameter( TFile* fIn, string iPara ) { cout << fPar->fTelToAnalyze[i] + 1; } - cout << "\t" << fPar->fRunDuration; - cout << "\t" << fPar->fTargetName; cout << endl; } @@ -137,11 +135,8 @@ bool readWobbleOffset( TFile* fIn, bool printInteger ) return false; } -/* - * read mean elevation or zenith - * - */ -bool readMeanElevation( TFile* fIn, bool print_zenith = false ) + +bool readMeanElevation( TFile* fIn ) { if( !fIn ) { @@ -216,14 +211,7 @@ bool readMeanElevation( TFile* fIn, bool print_zenith = false ) if( iMeanN > 0. ) { iMean_f /= iMeanN; - if( print_zenith ) - { - cout << "Average zenith angle: " << 90. - iMean_f << endl; - } - else - { - cout << "Average elevation: " << iMean_f << endl; - } + cout << "Average elevation: " << iMean_f << endl; } } else @@ -306,7 +294,6 @@ int main( int argc, char* argv[] ) cout << " -runinfo print relevant run info in one line" << endl; cout << " -updated-runinfo print relevant run info in one line (update epoch from VERITAS.Epochs.runparameter)" << endl; cout << " -elevation print (rough) average elevation" << endl; - cout << " -zenith print (rough) average zenith angle" << endl; cout << " -wobble print wobble offset" << endl; cout << " -wobbleInt print wobble offset (as integer, x100)" << endl; cout << endl; @@ -341,10 +328,6 @@ int main( int argc, char* argv[] ) { readMeanElevation( fIn ); } - else if( fOption.find( "-zenith" ) != string::npos ) - { - readMeanElevation( fIn, true ); - } else if( fOption.find( "-wobble" ) != string::npos ) { readWobbleOffset( fIn, ( fOption.find( "-wobbleInt" ) != string::npos ) ); diff --git a/src/trainTMVAforAngularReconstruction.cpp b/src/trainTMVAforAngularReconstruction.cpp index 4185aa35b..c96c0896e 100644 --- a/src/trainTMVAforAngularReconstruction.cpp +++ b/src/trainTMVAforAngularReconstruction.cpp @@ -175,7 +175,7 @@ bool trainTMVA( string iOutputDir, float iTrainTest, dataloader->AddVariable( "asym", 'F' ); dataloader->AddVariable( "loss", 'F' ); dataloader->AddVariable( "dist", 'F' ); - dataloader->AddVariable( "fui", 'F' ); + dataloader->AddVariable( "fui" , 'F' ); if( iTargetML.find( "DispEnergy" ) != string::npos && !iSingleTelescopeAnalysis ) { dataloader->AddVariable( "EHeight", 'F' ); @@ -549,7 +549,7 @@ bool writeTrainingFile( const string iInputFile, ULong64_t iTelType, fMapOfTrainingTree[i_tel.TelType]->Branch( "length", &length, "length/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "wol", &wol, "wol/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "dist", &dist, "dist/F" ); - fMapOfTrainingTree[i_tel.TelType]->Branch( "fui", &fui, "fui/F" ); + fMapOfTrainingTree[i_tel.TelType]->Branch( "fui" , &fui , "fui/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "tgrad_x", &tgrad_x, "tgrad_x/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "meanPedvar_Image", &meanPedvar_Image, "meanPedvar_Image/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "Fitstat", &Fitstat, "Fitstat/I" ); diff --git a/src/trainTMVAforGammaHadronSeparation.cpp b/src/trainTMVAforGammaHadronSeparation.cpp index 67aedbbef..5da073dd8 100644 --- a/src/trainTMVAforGammaHadronSeparation.cpp +++ b/src/trainTMVAforGammaHadronSeparation.cpp @@ -29,200 +29,115 @@ using namespace std; bool train( VTMVARunData* iRun, unsigned int iEnergyBin, unsigned int iZenithBin, bool iGammaHadronSeparation ); bool trainGammaHadronSeparation( VTMVARunData* iRun, unsigned int iEnergyBin, unsigned int iZenithBin ); bool trainReconstructionQuality( VTMVARunData* iRun, unsigned int iEnergyBin, unsigned int iZenithBin ); -TTree* prepareSelectedEventsTree( VTMVARunData* iRun, TCut iCut, bool iSignal ); - /* - * prepare training / testing trees with reduced number of events - * - * - apply pre-cuts here - * - copy only variables which are needed for TMVA into new tree - * - delete full trees (IMPORTANT) - * - */ -TTree* prepareSelectedEventsTree( VTMVARunData* iRun, TCut iCut, - bool iSignal ) + check if a training variable is constant + + (constant variables are removed from set of training variables) + + return values: + + -1: value is variable + 0-N: value is constant (array identifier) + +*/ +double checkIfVariableIsConstant( VTMVARunData* iRun, TCut iCut, string iVariable, bool iSignal, bool iSplitBlock ) { - if( !iRun ) + char hname[2000]; + TH1D* h = 0; + cout << "initializing TMVA variables: checking"; + if( iSignal ) { - return 0; + cout << " signal"; } + else + { + cout << " background"; + } + cout << " variable " << iVariable << " for consistency " << endl; vector< TChain* > iTreeVector; - string iDataTree_reducedName; if( iSignal ) { - cout << "Preparing reduced signal trees" << endl; iTreeVector = iRun->fSignalTree; - iDataTree_reducedName = "data_signal"; } else { - cout << "Preparing reduced background trees" << endl; iTreeVector = iRun->fBackgroundTree; - iDataTree_reducedName = "data_background"; } - // reduced tree (and name) - TTree* iDataTree_reduced = 0; - // list of variables copied. - // must include at least the variables used for the training - Double_t Ze = 0.; - Double_t Az = 0.; - Double_t WobbleN = 0; - Double_t WobbleE = 0; - Double_t MSCW = 0.; - Double_t MSCL = 0.; - Double_t ErecS = 0.; - Double_t EChi2S = 0.; - Double_t Xcore = 0.; - Double_t Ycore = 0.; - Double_t Xoff_derot = 0.; - Double_t Yoff_derot = 0.; - Int_t NImages = 0; - Float_t EmissionHeight = 0.; - Float_t EmissionHeightChi2 = 0.; - Double_t SizeSecondMax = 0.; - Double_t DispDiff = 0.; - Double_t MCe0 = 0.; - iDataTree_reduced = new TTree( iDataTree_reducedName.c_str(), iDataTree_reducedName.c_str() ); - iDataTree_reduced->Branch( "Ze", &Ze, "Ze/D" ); - iDataTree_reduced->Branch( "Az", &Az, "Az/D" ); - iDataTree_reduced->Branch( "WobbleN", &WobbleN, "WobbleN/D" ); - iDataTree_reduced->Branch( "WobbleE", &WobbleE, "WobbleE/D" ); - iDataTree_reduced->Branch( "MSCW", &MSCW, "MSCW/D" ); - iDataTree_reduced->Branch( "MSCL", &MSCL, "MSCL/D" ); - iDataTree_reduced->Branch( "ErecS", &ErecS, "ErecS/D" ); - iDataTree_reduced->Branch( "EChi2S", &EChi2S, "EChi2S/D" ); - iDataTree_reduced->Branch( "Xcore", &Xcore, "Xcore/D" ); - iDataTree_reduced->Branch( "Ycore", &Ycore, "Ycore/D" ); - iDataTree_reduced->Branch( "Xoff_derot", &Xoff_derot, "Xoff_derot/D" ); - iDataTree_reduced->Branch( "Yoff_derot", &Yoff_derot, "Yoff_derot/D" ); - iDataTree_reduced->Branch( "NImages", &NImages, "NImages/I" ); - iDataTree_reduced->Branch( "EmissionHeight", &EmissionHeight, "EmissionHeight/F" ); - iDataTree_reduced->Branch( "EmissionHeightChi2", &EmissionHeightChi2, "EmissionHeightChi2/F" ); - iDataTree_reduced->Branch( "SizeSecondMax", &SizeSecondMax, "SizeSecondMax/D" ); - iDataTree_reduced->Branch( "DispDiff", &DispDiff, "DispDiff/D" ); - iDataTree_reduced->Branch( "MCe0", &MCe0, "MCe0/D" ); - Long64_t n = 0; + // add cut on number of telescope (per type) for + if( iVariable.find( "NImages_Ttype" ) != string::npos || iVariable.find( "EmissionHeightChi2" ) != string::npos ) + { + ostringstream iTemp; + if( iVariable.find( "NImages_Ttype" ) != string::npos ) + { + iTemp << "NTtype>0 && "; + } + iTemp << iVariable << " >=2"; + TCut ntCut( iTemp.str().c_str() ); + iCut = iCut && ntCut; + } for( unsigned int i = 0; i < iTreeVector.size(); i++ ) { + h = 0; if( iTreeVector[i] ) { - iTreeVector[i]->SetBranchAddress( "Ze", &Ze ); - iTreeVector[i]->SetBranchAddress( "Az", &Az ); - iTreeVector[i]->SetBranchAddress( "WobbleN", &WobbleN ); - iTreeVector[i]->SetBranchAddress( "WobbleE", &WobbleE ); - iTreeVector[i]->SetBranchAddress( "MSCW", &MSCW ); - iTreeVector[i]->SetBranchAddress( "MSCL", &MSCL ); - iTreeVector[i]->SetBranchAddress( "ErecS", &ErecS ); - iTreeVector[i]->SetBranchAddress( "EChi2S", &EChi2S ); - iTreeVector[i]->SetBranchAddress( "Xcore", &Xcore ); - iTreeVector[i]->SetBranchAddress( "Ycore", &Ycore ); - iTreeVector[i]->SetBranchAddress( "Xoff_derot", &Xoff_derot ); - iTreeVector[i]->SetBranchAddress( "Yoff_derot", &Yoff_derot ); - iTreeVector[i]->SetBranchAddress( "NImages", &NImages ); - iTreeVector[i]->SetBranchAddress( "EmissionHeight", &EmissionHeight ); - iTreeVector[i]->SetBranchAddress( "EmissionHeightChi2", &EmissionHeightChi2 ); - iTreeVector[i]->SetBranchAddress( "SizeSecondMax", &SizeSecondMax ); - iTreeVector[i]->SetBranchAddress( "DispDiff", &DispDiff ); - if( iTreeVector[i]->GetBranchStatus( "MCe0" ) ) + // fill a histogram with the variable to be checked + sprintf( hname, "hXX_%d", i ); + h = new TH1D( hname, "", 100, -1.e5, 1.e5 ); + Long64_t iNEntriesBlock = 0; + if( iSplitBlock ) { - iTreeVector[i]->SetBranchAddress( "MCe0", &MCe0 ); + iNEntriesBlock = iTreeVector[i]->GetEntries() / 2; } - if( !iDataTree_reduced ) + else { - cout << "Error preparing reduced tree" << endl; - return 0; + iNEntriesBlock = iTreeVector[i]->GetEntries(); } - iTreeVector[i]->Draw( ">>elist", iCut, "entrylist" ); - TEntryList* elist = ( TEntryList* )gDirectory->Get( "elist" ); - if( elist && elist->GetN() > 0 ) + iTreeVector[i]->Project( h->GetName(), iVariable.c_str(), iCut, "", iNEntriesBlock ); + if( h ) { - // select a random subsample - // require trainging and testing sample - // (add factor 10 to make sure that there are plenty - // of testing events) - double i_event_selected = ( double )iRun->fnTrain_Background; - if( iSignal ) - { - i_event_selected = ( double )iRun->fnTrain_Signal; - } - double i_fraction_of_events_to_keep = i_event_selected / ( double )elist->GetN(); - i_fraction_of_events_to_keep *= 10.; - if( iTreeVector.size() > 0. ) - { - i_fraction_of_events_to_keep /= ( double )iTreeVector.size(); - } - if( i_fraction_of_events_to_keep > 1. ) - { - i_fraction_of_events_to_keep = 1.; - } - cout << "\t keeping " << i_fraction_of_events_to_keep * 100. << "\% of events of "; - if( iSignal ) + if( h->GetRMS() > 1.e-5 ) { - cout << iRun->fSignalFileName[i]; + cout << "\t variable " << iVariable << " ok, RMS: " << h->GetRMS() << ", tree: " << i; + // (confusing) cout << ", nbins " << h->GetNbinsX() << ", xmin " << h->GetXaxis()->GetXmin() << ", xmax " << h->GetXaxis()->GetXmax(); + cout << ", entries " << h->GetEntries(); + cout << endl; + h->Delete(); + return -9999.; } - else - { - cout << iRun->fBackgroundFileName[i]; - } - cout << " (training events: " << i_event_selected; - cout << ", events after pre-cuts: " << elist->GetN() << " number of runs: " << iTreeVector.size() << ")"; - cout << endl; - for( Long64_t el = 0; el < elist->GetN(); el++ ) - { - if( gRandom->Uniform() > i_fraction_of_events_to_keep ) - { - continue; - } - Long64_t treeEntry = elist->GetEntry( el ); - iTreeVector[i]->GetEntry( treeEntry ); - iDataTree_reduced->Fill(); - n++; - } - } - // remove this tree - if( iSignal ) - { - iRun->fSignalTree[i]->Delete(); - iRun->fSignalTree[i] = 0; - } - else - { - iRun->fBackgroundTree[i]->Delete(); - iRun->fBackgroundTree[i] = 0; } } + if( i < iTreeVector.size() - 1 && h ) + { + h->Delete(); + } } - if( iSignal && iDataTree_reduced ) + // means: variable is in all trees constant + cout << "\t warning: constant variable " << iVariable << " in "; + if( iSignal ) { - cout << "\t Reduced signal tree entries: " << iDataTree_reduced->GetEntries() << endl; + cout << " signal tree"; } - else if( iDataTree_reduced ) + else { - cout << "\t Reduced background tree entries: " << iDataTree_reduced->GetEntries() << endl; + cout << " background tree"; } - else + if( h ) { - cout << "Error in reducing data trees (missing tree)" << endl; - return 0; + cout << " (mean " << h->GetMean() << ", RMS " << h->GetRMS() << ", entries " << h->GetEntries() << ")"; } - // cleanup all remaining trees - for( unsigned int i = 0; i < iTreeVector.size(); i++ ) + cout << ", checked " << iTreeVector.size() << " trees"; + cout << endl; + double i_mean = -9999.; + if( h ) { - if( iSignal && iRun->fSignalTree[i] ) - { - iRun->fSignalTree[i]->Delete(); - iRun->fSignalTree[i] = 0; - } - else if( !iSignal && iRun->fBackgroundTree[i] ) - { - iRun->fBackgroundTree[i]->Delete(); - iRun->fBackgroundTree[i] = 0; - } + i_mean = h->GetMean(); + h->Delete(); } - return iDataTree_reduced; + + return i_mean; } /*! @@ -232,21 +147,21 @@ TTree* prepareSelectedEventsTree( VTMVARunData* iRun, TCut iCut, */ bool trainGammaHadronSeparation( VTMVARunData* iRun, - unsigned int iEnergyBin, unsigned int iZenithBin ) + unsigned int iEnergyBin, unsigned int iZenithBin ) { return train( iRun, iEnergyBin, iZenithBin, true ); } bool trainReconstructionQuality( VTMVARunData* iRun, - unsigned int iEnergyBin, unsigned int iZenithBin ) + unsigned int iEnergyBin, unsigned int iZenithBin ) { return train( iRun, iEnergyBin, iZenithBin, false ); } bool train( VTMVARunData* iRun, - unsigned int iEnergyBin, unsigned int iZenithBin, - bool iTrainGammaHadronSeparation ) + unsigned int iEnergyBin, unsigned int iZenithBin, + bool iTrainGammaHadronSeparation ) { // sanity checks if( !iRun ) @@ -255,122 +170,142 @@ bool train( VTMVARunData* iRun, } if( iRun->fEnergyCutData.size() <= iEnergyBin || iRun->fOutputFile.size() <= iEnergyBin ) { - cout << "error during training: energy bin out of range " << iEnergyBin << endl; + cout << "error in train: energy bin out of range " << iEnergyBin; return false; } if( iRun->fZenithCutData.size() < iZenithBin || iRun->fOutputFile[0].size() < iZenithBin ) { - cout << "error during training: zenith bin out of range " << iZenithBin << endl; + cout << "error in train: zenith bin out of range " << iZenithBin; return false; } - // quality cuts before training - TCut iCutSignal = iRun->fQualityCuts - && iRun->fMCxyoffCut && - iRun->fEnergyCutData[iEnergyBin]->fEnergyCut - && iRun->fZenithCutData[iZenithBin]->fZenithCut; - - TCut iCutBck = iRun->fQualityCuts && iRun->fQualityCutsBkg - && iRun->fEnergyCutData[iEnergyBin]->fEnergyCut - && iRun->fZenithCutData[iZenithBin]->fZenithCut; - - if( !iRun->fMCxyoffCutSignalOnly ) - { - iCutBck = iCutBck && iRun->fMCxyoffCut; - } - // adding training variables - if( iRun->fTrainingVariable.size() != iRun->fTrainingVariableType.size() ) - { - cout << "train: error: training-variable vectors have different size" << endl; - return false; - } + TMVA::Tools::Instance(); - // prepare trees for training and testing with selected events only - // this step is necessary to minimise the memory impact for the BDT - // training - TTree* iSignalTree_reduced = 0; - TTree* iBackgroundTree_reduced = 0; - if( iRun->fRunOption == "WRITETRAININGEVENTS" ) + // set output directory + gSystem->mkdir( iRun->fOutputDirectoryName.c_str() ); + TString iOutputDirectory( iRun->fOutputDirectoryName.c_str() ); + gSystem->ExpandPathName( iOutputDirectory ); + ( TMVA::gConfig().GetIONames() ).fWeightFileDir = iOutputDirectory; + + ////////////////////////////////////////// + // defining training class + TMVA::Factory* factory = new TMVA::Factory( iRun->fOutputFile[iEnergyBin][iZenithBin]->GetTitle(), iRun->fOutputFile[iEnergyBin][iZenithBin], "V" ); + TMVA::DataLoader* dataloader = new TMVA::DataLoader( "dataset" ); + //////////////////////////// + // train gamma/hadron separation + if( iTrainGammaHadronSeparation ) { - iSignalTree_reduced = prepareSelectedEventsTree( iRun, - iCutSignal, true ); - iBackgroundTree_reduced = prepareSelectedEventsTree( iRun, - iCutBck, false ); - if( !iSignalTree_reduced || !iBackgroundTree_reduced ) + // adding signal and background trees + for( unsigned int i = 0; i < iRun->fSignalTree.size(); i++ ) { - cout << "Error: failed preparing traing / testing trees" << endl; - return false; + dataloader->AddSignalTree( iRun->fSignalTree[i], iRun->fSignalWeight ); } - iSignalTree_reduced->Write(); - iBackgroundTree_reduced->Write(); - if( iRun->getTLRunParameter() ) + for( unsigned int i = 0; i < iRun->fBackgroundTree.size(); i++ ) { - iRun->getTLRunParameter()->Write(); + dataloader->AddBackgroundTree( iRun->fBackgroundTree[i], iRun->fBackgroundWeight ); } - cout << "Writing reduced event lists for training: "; - cout << gDirectory->GetName() << endl; - return true; } + //////////////////////////// + // train reconstruction quality else { - cout << "Reading training / testing trees from "; - cout << iRun->fSelectedEventFileName << endl; - TFile* iF = new TFile( iRun->fSelectedEventFileName.c_str() ); - if( iF->IsZombie() ) + for( unsigned int i = 0; i < iRun->fSignalTree.size(); i++ ) { - cout << "Error open file with pre-selected events: "; - cout << iRun->fSelectedEventFileName << endl; - return false; + dataloader->AddRegressionTree( iRun->fSignalTree[i], iRun->fSignalWeight ); } - iSignalTree_reduced = ( TTree* )iF->Get( "data_signal" ); - iBackgroundTree_reduced = ( TTree* )iF->Get( "data_background" ); + dataloader->AddRegressionTarget( iRun->fReconstructionQualityTarget.c_str(), iRun->fReconstructionQualityTargetName.c_str() ); } - if( !iSignalTree_reduced || !iBackgroundTree_reduced ) + + // quality cuts before training + TCut iCutSignal = iRun->fQualityCuts + && iRun->fMCxyoffCut && + iRun->fEnergyCutData[iEnergyBin]->fEnergyCut + && iRun->fZenithCutData[iZenithBin]->fZenithCut; + + TCut iCutBck = iRun->fQualityCuts && iRun->fQualityCutsBkg + && iRun->fEnergyCutData[iEnergyBin]->fEnergyCut + && iRun->fZenithCutData[iZenithBin]->fZenithCut; + + if( !iRun->fMCxyoffCutSignalOnly ) { - cout << "Error: failed preparing traing / testing trees" << endl; - return false; + iCutBck = iCutBck && iRun->fMCxyoffCut; } - if( iSignalTree_reduced->GetEntries() < 1000 || iBackgroundTree_reduced->GetEntries() < 1000 ) + + // adding training variables + if( iRun->fTrainingVariable.size() != iRun->fTrainingVariableType.size() ) { - cout << "Error: less than 1000 events available for training: "; - cout << " signal (" << iSignalTree_reduced->GetEntries() << "), "; - cout << " background (" << iBackgroundTree_reduced->GetEntries() << ")" << endl; + cout << "train: error: training-variable vectors have different size" << endl; return false; } - iRun->updateTrainingEvents( "nTrain_Signal", ( unsigned int )iSignalTree_reduced->GetEntries() * 0.7 ); - iRun->updateTrainingEvents( "nTrain_Background", ( unsigned int )iBackgroundTree_reduced->GetEntries() * 0.7 ); - - TMVA::Tools::Instance(); - gSystem->mkdir( iRun->fOutputDirectoryName.c_str() ); - TString iOutputDirectory( iRun->fOutputDirectoryName.c_str() ); - gSystem->ExpandPathName( iOutputDirectory ); - ( TMVA::gConfig().GetIONames() ).fWeightFileDir = iOutputDirectory; - ////////////////////////////////////////// - // defining training class - TMVA::Factory* factory = new TMVA::Factory( iRun->fOutputFile[iEnergyBin][iZenithBin]->GetTitle(), - iRun->fOutputFile[iEnergyBin][iZenithBin], - "V:!DrawProgressBar" ); - TMVA::DataLoader* dataloader = new TMVA::DataLoader( "" ); - //////////////////////////// - // train gamma/hadron separation - if( iTrainGammaHadronSeparation ) + // check split mode + bool iSplitBlock = false; + if( iRun->fPrepareTrainingOptions.find( "SplitMode=Block" ) != string::npos ) { - dataloader->AddSignalTree( iSignalTree_reduced, iRun->fSignalWeight ); - dataloader->AddBackgroundTree( iBackgroundTree_reduced, iRun->fBackgroundWeight ); - } - //////////////////////////// - // train reconstruction quality - else - { - dataloader->AddSignalTree( iSignalTree_reduced, iRun->fSignalWeight ); - dataloader->AddRegressionTarget( iRun->fReconstructionQualityTarget.c_str(), iRun->fReconstructionQualityTargetName.c_str() ); + cout << "train: use option SplitMode=Block" << endl; + iSplitBlock = true; } // loop over all trainingvariables and add them to TMVA + // (test first if variable is constant, TMVA will stop when a variable + // is constant) for( unsigned int i = 0; i < iRun->fTrainingVariable.size(); i++ ) { - dataloader->AddVariable( iRun->fTrainingVariable[i].c_str(), iRun->fTrainingVariableType[i] ); + if( iRun->fTrainingVariable[i].find( "NImages_Ttype" ) != string::npos ) + { + for( int j = 0; j < iRun->fNTtype; j++ ) + { + ostringstream iTemp; + iTemp << iRun->fTrainingVariable[i] << "[" << j << "]"; + ostringstream iTempCut; + // require at least 2 image per telescope type + iTempCut << iTemp.str() << ">1"; + TCut iCutCC = iTempCut.str().c_str(); + + double iSignalMean = 1.; + double iBckMean = -1.; + if( iRun->fCheckValidityOfInputVariables ) + { + iSignalMean = checkIfVariableIsConstant( iRun, iCutSignal && iCutCC, iTemp.str(), true, iSplitBlock ); + iBckMean = checkIfVariableIsConstant( iRun, iCutBck && iCutCC, iTemp.str(), false, iSplitBlock ); + cout << "\t mean values " << iSignalMean << "\t" << iBckMean << endl; + } + if( ( TMath::Abs( iSignalMean - iBckMean ) > 1.e-6 + || TMath::Abs( iSignalMean + 9999. ) < 1.e-2 || TMath::Abs( iBckMean + 9999. ) < 1.e-2 ) + && iSignalMean != 0 && iBckMean != 0 ) + { + dataloader->AddVariable( iTemp.str().c_str(), iRun->fTrainingVariableType[i] ); + } + else + { + cout << "warning: removed constant variable " << iTemp.str() << " from training (added to spectators)" << endl; + dataloader->AddSpectator( iTemp.str().c_str() ); + } + } + } + else + { + // check if the training variable is constant + double iSignalMean = 1.; + double iBckMean = -1.; + if( iRun->fCheckValidityOfInputVariables ) + { + checkIfVariableIsConstant( iRun, iCutSignal, iRun->fTrainingVariable[i].c_str(), true, iSplitBlock ); + checkIfVariableIsConstant( iRun, iCutBck, iRun->fTrainingVariable[i].c_str(), false, iSplitBlock ); + cout << "\t mean values " << iSignalMean << "\t" << iBckMean << endl; + } + + if( TMath::Abs( iSignalMean - iBckMean ) > 1.e-6 + || TMath::Abs( iSignalMean + 9999. ) < 1.e-2 || TMath::Abs( iBckMean + 9999. ) < 1.e-2 ) + { + dataloader->AddVariable( iRun->fTrainingVariable[i].c_str(), iRun->fTrainingVariableType[i] ); + } + else + { + cout << "warning: removed constant variable " << iRun->fTrainingVariable[i] << " from training (added to spectators)" << endl; + dataloader->AddSpectator( iRun->fTrainingVariable[i].c_str() ); + } + } } // adding spectator variables for( unsigned int i = 0; i < iRun->fSpectatorVariable.size(); i++ ) @@ -383,52 +318,52 @@ bool train( VTMVARunData* iRun, // nTrain Signal=5000:nTrain Background=5000: nTest Signal=4000:nTest Background=5000 dataloader->PrepareTrainingAndTestTree( iCutSignal, - iCutBck, - iRun->fPrepareTrainingOptions ); - + iCutBck, + iRun->fPrepareTrainingOptions ); + ////////////////////////////////////////// // book all methods char htitle[6000]; for( unsigned int i = 0; i < iRun->fMVAMethod.size(); i++ ) { - TMVA::Types::EMVA i_tmva_type = TMVA::Types::kBDT; + TMVA::Types::EMVA i_tmva_type = TMVA::Types::kBDT; if( iRun->fMVAMethod[i] == "BDT" ) { if( iTrainGammaHadronSeparation ) { sprintf( htitle, "BDT_0" ); - i_tmva_type = TMVA::Types::kBDT; + i_tmva_type = TMVA::Types::kBDT; } else { sprintf( htitle, "BDT_RecQuality_0" ); } - } - else if( iRun->fMVAMethod[i] == "MLP" ) - { - i_tmva_type = TMVA::Types::kMLP; - } - + } + else if( iRun->fMVAMethod[i] == "MLP" ) + { + i_tmva_type = TMVA::Types::kMLP; + } + ////////////////////////// - if( iRun->fMVAMethod[i] != "BOXCUTS" ) + if( iRun->fMVAMethod[i] != "BOXCUTS" ) { if( iTrainGammaHadronSeparation ) { - sprintf( htitle, "%s_%u", iRun->fMVAMethod[i].c_str(), i ); + sprintf( htitle, "%s_%u", iRun->fMVAMethod[i].c_str(), i ); } else { - sprintf( htitle, "%s_RecQuality_%u", iRun->fMVAMethod[i].c_str(), i ); + sprintf( htitle, "%s_RecQuality_%u", iRun->fMVAMethod[i].c_str(), i ); } if( i < iRun->fMVAMethod_Options.size() ) { - cout << "Booking method " << htitle << endl; - factory->BookMethod( dataloader, i_tmva_type, htitle, iRun->fMVAMethod_Options[i].c_str() ); + cout << "Booking method " << htitle << endl; + factory->BookMethod( dataloader, i_tmva_type, htitle, iRun->fMVAMethod_Options[i].c_str() ); } else { - factory->BookMethod( dataloader, i_tmva_type, htitle ); + factory->BookMethod( dataloader, i_tmva_type, htitle ); } } ////////////////////////// @@ -437,7 +372,7 @@ bool train( VTMVARunData* iRun, else if( iRun->fMVAMethod[i] == "BOXCUTS" ) { stringstream i_opt; - i_opt << iRun->fMVAMethod_Options[i].c_str(); + i_opt << iRun->fMVAMethod_Options[i].c_str(); for( unsigned int i = 0; i < iRun->fTrainingVariable_CutRangeMin.size(); i++ ) { i_opt << ":CutRangeMin[" << i << "]=" << iRun->fTrainingVariable_CutRangeMin[i]; @@ -468,7 +403,6 @@ bool train( VTMVARunData* iRun, factory->EvaluateAllMethods(); - dataloader->Delete(); factory->Delete(); return true; @@ -493,13 +427,13 @@ int main( int argc, char* argv[] ) cout << endl; cout << "trainTMVAforGammaHadronSeparation " << VGlobalRunParameter::getEVNDISP_VERSION() << endl; cout << "----------------------------------------" << endl; - if( argc != 2 && argc != 3 ) + if( argc != 2 ) { cout << endl; - cout << "./trainTMVAforGammaHadronSeparation [WRITETRAININGEVENTS]" << endl; + cout << "./trainTMVAforGammaHadronSeparation " << endl; cout << endl; cout << " (an example for a configuration file can be found in " << endl; - cout << " $VERITAS_EVNDISP_AUX_DIR/ParameterFiles/TMVA.BDT.runparameter )" << endl; + cout << " $CTA_EVNDISP_AUX_DIR/ParameterFiles/TMVA.BDT.runparameter )" << endl; cout << endl; exit( EXIT_SUCCESS ); } @@ -519,12 +453,6 @@ int main( int argc, char* argv[] ) cout << ")" << endl; exit( EXIT_FAILURE ); } - if( argc == 3 ) - { - fData->fRunOption = "WRITETRAININGEVENTS"; - } - // randomize list of input files - cout << "randomizing input files" << endl; fData->print(); ////////////////////////////////////// @@ -537,10 +465,10 @@ int main( int argc, char* argv[] ) ////////////////////////////////////// // train MVA - // (one training per energy and zenith bin) - cout << "Number of energy bins: " << fData->fEnergyCutData.size(); - cout << ", number of zenith bins: " << fData->fZenithCutData.size(); - cout << endl; + // (one training per energy bin) + cout << "Number of energy bins: " << fData->fEnergyCutData.size(); + cout << ", number of zenith bins: " << fData->fZenithCutData.size(); + cout << endl; cout << "================================" << endl << endl; for( unsigned int i = 0; i < fData->fEnergyCutData.size(); i++ ) { @@ -549,20 +477,15 @@ int main( int argc, char* argv[] ) if( fData->fEnergyCutData[i]->fEnergyCut && fData->fZenithCutData[j]->fZenithCut ) { cout << "Training energy bin " << fData->fEnergyCutData[i]->fEnergyCut; - cout << " zenith bin " << fData->fZenithCutData[j]->fZenithCut << endl; + cout << " zenith bin " << fData->fZenithCutData[j]->fZenithCut << endl; cout << "===================================================================================" << endl; cout << endl; } - /////////////////////////////////////////////// - // training + // training if( fData->fTrainGammaHadronSeparation && !trainGammaHadronSeparation( fData, i, j ) ) { - cout << "Error during training...exiting" << endl; - exit( EXIT_FAILURE ); - } - if( fData->fRunOption == "WRITETRAININGEVENTS" ) - { - continue; + cout << "Error during training...exiting" << endl; + exit( EXIT_FAILURE ); } if( fData->fTrainReconstructionQuality ) { @@ -591,37 +514,37 @@ int main( int argc, char* argv[] ) iTempS2 << fData->fOutputFileName << ".root"; } - // prepare a short root file with the necessary values only - // write energy & zenith cuts, plus signal and background efficiencies + // prepare a short root file with the necessary values only + // write energy & zenith cuts, plus signal and background efficiencies TFile* root_file = fData->fOutputFile[i][j]; - if( !root_file ) - { - cout << "Error finding tvma root file " << endl; - continue; - } + if( !root_file ) + { + cout << "Error finding tvma root file " << endl; + continue; + } TFile* short_root_file = TFile::Open( iTempS.str().c_str(), "RECREATE" ); - if( !short_root_file->IsZombie() ) - { - VTMVARunDataEnergyCut* fDataEnergyCut = ( VTMVARunDataEnergyCut* )root_file->Get( "fDataEnergyCut" ); - VTMVARunDataZenithCut* fDataZenithCut = ( VTMVARunDataZenithCut* )root_file->Get( "fDataZenithCut" ); - TH1D* MVA_BDT_0_effS = ( TH1D* )root_file->Get( "Method_BDT/BDT_0/MVA_BDT_0_effS" ); - TH1D* MVA_BDT_0_effB = ( TH1D* )root_file->Get( "Method_BDT/BDT_0/MVA_BDT_0_effB" ); - fDataEnergyCut->Write(); - fDataZenithCut->Write(); - TDirectory* Method_BDT = short_root_file->mkdir( "Method_BDT" ); - Method_BDT->cd(); - TDirectory* BDT_0 = Method_BDT->mkdir( "BDT_0" ); - BDT_0->cd(); - MVA_BDT_0_effS->Write(); - MVA_BDT_0_effB->Write(); - short_root_file->GetList(); - short_root_file->Write(); - short_root_file->Close(); - } - else - { - cout << "Error: could not create file with energy cuts " << iTempS.str().c_str() << endl; - } + if( !short_root_file->IsZombie() ) + { + VTMVARunDataEnergyCut* fDataEnergyCut = ( VTMVARunDataEnergyCut* )root_file->Get( "fDataEnergyCut" ); + VTMVARunDataZenithCut* fDataZenithCut = ( VTMVARunDataZenithCut* )root_file->Get( "fDataZenithCut" ); + TH1D* MVA_BDT_0_effS = ( TH1D* )root_file->Get( "Method_BDT/BDT_0/MVA_BDT_0_effS" ); + TH1D* MVA_BDT_0_effB = ( TH1D* )root_file->Get( "Method_BDT/BDT_0/MVA_BDT_0_effB" ); + fDataEnergyCut->Write(); + fDataZenithCut->Write(); + TDirectory* Method_BDT = short_root_file->mkdir( "Method_BDT" ); + Method_BDT->cd(); + TDirectory* BDT_0 = Method_BDT->mkdir( "BDT_0" ); + BDT_0->cd(); + MVA_BDT_0_effS->Write(); + MVA_BDT_0_effB->Write(); + short_root_file->GetList(); + short_root_file->Write(); + short_root_file->Close(); + } + else + { + cout << "Error: could not create file with energy cuts " << iTempS.str().c_str() << endl; + } // copy complete TMVA output root-file to another directory string iOutputFileName( fData->fOutputDirectoryName + "/" + iTempS2.str() ); string iOutputFileNameCompleteSubDir( "complete_BDTroot" ); @@ -638,6 +561,6 @@ int main( int argc, char* argv[] ) rename( iTempS.str().c_str(), iFinalRootFileName.c_str() ); } } - fData->Delete(); return 0; } + diff --git a/src/trainTMVAforGammaHadronSeparation_TrainingFile.cpp b/src/trainTMVAforGammaHadronSeparation_TrainingFile.cpp new file mode 100644 index 000000000..f27baf420 --- /dev/null +++ b/src/trainTMVAforGammaHadronSeparation_TrainingFile.cpp @@ -0,0 +1,178 @@ +/* \file trainTMVAforGammaHadronSeparation_TrainingFile.cpp + \brief make background training files for TMVA using MC and randomize theta2 + + Note: no wobble offsets are implemented yet + +*/ + +#include +#include +#include +#include +#include + +#include "TFile.h" +#include "TMath.h" +#include "TRandom3.h" +#include "TSystem.h" +#include "TTree.h" + +using namespace std; + +/* + + get list of file names (full paths) from parameter file + +*/ +vector< string > getListofFiles( string iFileName ) +{ + ifstream is; + is.open( iFileName.c_str(), ifstream::in ); + if( !is ) + { + cout << "error, no input file list found: " << iFileName << endl; + exit( -1 ); + + } + cout << "list of files from " << iFileName << endl; + cout << endl; + string is_line; + string temp; + vector< string > iFileList; + + while( getline( is, is_line ) ) + { + stringstream is_stream( is_line ); + is_stream >> temp; + if( temp != "*" ) + { + continue; + } + is_stream >> temp; + if( temp != "BACKGROUNDFILE" ) + { + continue; + } + is_stream >> temp; + iFileList.push_back( temp ); + } + is.close(); + + return iFileList; +} + + +/* + + main... + +*/ +int main( int argc, char* argv[] ) +{ + if( argc != 5 ) + { + cout << endl; + cout << "trainTMVAforGammaHadronSeparation_TrainingFile " << endl; + cout << endl; + cout << ""; + cout << "parameter file with list of background mscw file (same format as in trainTMVAforGammaHadronSeparation)" << endl; + cout << " seed for random generator (default: 0)" << endl; + cout << endl; + cout << "Note: no wobble offsets are implemented yet" << endl; + cout << "Note: you might want to have some additional cuts (e.g. distance to the camera center) hardwired" << endl; + cout << endl; + exit( 0 ); + } + + cout << endl; + cout << "trainTMVAforGammaHadronSeparation_TrainingFile" << endl; + cout << "====================================" << endl; + cout << endl; + + double fMaxTheta = TMath::Sqrt( atof( argv[3] ) ); + UInt_t fRandomSeed = ( UInt_t )( atoi( argv[4] ) ); + + cout << "replacing Xoff/Yoff by random value inside a circle of radius " << fMaxTheta << " deg" << endl; + cout << "replace MCxoff/MCyoff by 0,0 " << endl; + + // random generator + TRandom3* fRandom = new TRandom3( fRandomSeed ); + + // get list of files to change + vector< string > iFileList = getListofFiles( argv[1] ); + string i_outputDir = argv[2]; + + // loop over all input files + for( unsigned int f = 0; f < iFileList.size(); f++ ) + { + + // input data file + string iIfile = iFileList[f]; + + TFile* fInput = new TFile( iIfile.c_str() ); + if( fInput->IsZombie() ) + { + cout << "error reading input file " << iIfile << endl; + cout << "exit..." << endl; + exit( -1 ); + } + // input data tree + TTree* fInputData = ( TTree* )fInput->Get( "data" ); + if( !fInputData ) + { + cout << "error reading input tree from " << iIfile << endl; + exit( -1 ); + } + double fXoff = 0.; + double fYoff = 0.; + double fMCXoff = 0.; + double fMCYoff = 0.; + fInputData->SetBranchAddress( "Xoff", &fXoff ); + fInputData->SetBranchAddress( "Yoff", &fYoff ); + fInputData->SetBranchAddress( "MCxoff", &fMCXoff ); + fInputData->SetBranchAddress( "MCyoff", &fMCYoff ); + Int_t nentries = ( Int_t )fInputData->GetEntries(); + + // output data file + string iOfile = i_outputDir + "/" + gSystem->BaseName( iFileList[f].c_str() ); + if( iIfile == iOfile ) + { + cout << "error: input and output file is identical" << endl; + exit( -1 ); + } + TFile* fOutput = new TFile( iOfile.c_str(), "RECREATE" ); + if( fOutput->IsZombie() ) + { + cout << "error opening output file " << iOfile << endl; + exit( -1 ); + } + + // output data tree + TTree* fOutputData = fInputData->CloneTree( 0 ); + + double i_theta = 0.; + double i_r = 0.; + + // loop over all entries + cout << "Looping over " << nentries << " events in " << fInput->GetName() << endl; + for( Int_t i = 0; i < nentries; i++ ) + { + fInputData->GetEntry( i ); + + i_r = TMath::Sqrt( fRandom->Uniform( 1. ) ); + i_theta = fRandom->Uniform( TMath::TwoPi() ); + fXoff = fMaxTheta * i_r * TMath::Cos( i_theta ); + fYoff = fMaxTheta * i_r * TMath::Sin( i_theta ); + + fMCXoff = 0.; + fMCYoff = 0.; + + fOutputData->Fill(); + } + cout << "writing new tree to " << fOutput->GetName() << endl; + fOutputData->AutoSave(); + + delete fInput; + delete fOutput; + } // end of loop over all files +} diff --git a/src/writeParticleRateFilesForTMVA.cpp b/src/writeParticleRateFilesForTMVA.cpp index cafec7f38..0ed2a20d2 100644 --- a/src/writeParticleRateFilesForTMVA.cpp +++ b/src/writeParticleRateFilesForTMVA.cpp @@ -1,7 +1,6 @@ /* writeParticleRateFilesForTMVA write files with particle number spectra for on (gamma) and off (protons+electrons) counts - (differential counting rates) files are needed e.g. for setting the optimal cut value for TMVA cuts @@ -13,16 +12,27 @@ */ +#include "VTMVARunData.h" +#include "VInstrumentResponseFunctionReader.h" +#include "VWPPhysSensitivityFile.h" #include #include #include +#include "TStyle.h" #include "TFile.h" #include "TTree.h" #include "TH1D.h" +#include "TCanvas.h" +#include "TGraph.h" +#include "TGraphErrors.h" #include "TH2D.h" +#include "TGraph2D.h" #include "TMath.h" +#include "TLegend.h" +#include "TMultiGraph.h" +#include "TGraph2D.h" #include "TGraph2DErrors.h" using namespace std; @@ -40,8 +50,10 @@ int main( int argc, char* argv[] ) { cout << endl; cout << "writeParticleRateFilesForTMVA "; + //cout << " [qsub options]" << endl; + //cout << argc << endl; cout << endl; - exit( EXIT_FAILURE ); + exit( 0 ); } cout << endl; @@ -52,51 +64,64 @@ int main( int argc, char* argv[] ) string iDataDir = argv[1]; string iOutFil = argv[2]; + Int_t runOn; + Double_t OffNorm, elevationOn, elevationOff, azimuthOn, azimuthOff; + Double_t tOn = 0.; + Double_t tObs, alphaNorm; + tObs = 0.; + alphaNorm = 0.; + /* Name and directory to the COMBINED anasum root file */ - TFile* f1 = new TFile( iDataDir.c_str() , "OPEN" ); - if( f1->IsZombie() ) - { - cout << "Error reading file " << iDataDir << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } + char iInputFile[800]; + sprintf( iInputFile, "%s", iDataDir.c_str() ); + TFile* f1 = new TFile( iInputFile, "OPEN" ); char reddataname[256], histnameOn[256], histnameOff[256]; TTree* RunSum = ( TTree* )f1->Get( "total_1/stereo/tRunSummary" ); - if( !RunSum ) - { - cout << "Error reading run summary tree" << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } - if( RunSum->GetEntries() == 0 ) - { - cout << "Error reading run summary tree - empty tree" << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } - Int_t runOn = 0; - Double_t OffNorm = 0.; - Double_t elevationOff = 0.; - Double_t alphaNorm = 0.; + RunSum->SetBranchAddress( "runOn", &runOn ); RunSum->SetBranchAddress( "runOn", &runOn ); RunSum->SetBranchAddress( "OffNorm", &OffNorm ); + RunSum->SetBranchAddress( "elevationOn", &elevationOn ); RunSum->SetBranchAddress( "elevationOff", &elevationOff ); + RunSum->SetBranchAddress( "azimuthOn", &azimuthOn ); + RunSum->SetBranchAddress( "azimuthOff", &azimuthOff ); + RunSum->SetBranchAddress( "tOn", &tOn ); + + double iZenithperrun; + + double new_on; + double new_off; + double new_on_error, new_off_error; + + unsigned int iBin = 0; + + for( unsigned int i = 0; i < ( RunSum->GetEntries() - 1 ); i++ ) + { + RunSum->GetEntry( i ); + + sprintf( histnameOn, "run_%d/stereo/energyHistograms/herecCounts_on", runOn ); + sprintf( histnameOff, "run_%d/stereo/energyHistograms/herecCounts_off", runOn ); + TH1D* t2 = ( TH1D* )f1->Get( histnameOff ); + + //unsigned int nbins_t1 = t1->GetNbinsX(); + unsigned int nbins_t2 = t2->GetNbinsX(); + iBin = nbins_t2; + } - // assume that all histograms for all runs have the same binning - RunSum->GetEntry( 0 ); - sprintf( histnameOn, "run_%d/stereo/energyHistograms/herecCounts_on", runOn ); - sprintf( histnameOff, "run_%d/stereo/energyHistograms/herecCounts_off", runOn ); - TH1D* t2 = ( TH1D* )f1->Get( histnameOff ); - unsigned int iBin = t2->GetNbinsX(); + // ----------------------------------------------------------------- + // + // loop over the number of runs in the combined anasum root file + // + // check if the zenith angle is within a range of 5 degrees (zenith angle intervals are used for an easier optimization) + // + // ----------------------------------------------------------------- TGraph2DErrors* tRatePerEnergyON = new TGraph2DErrors(); - tRatePerEnergyON->SetMarkerStyle( 20 ); TGraph2DErrors* tRatePerEnergyOFF = new TGraph2DErrors(); - tRatePerEnergyOFF->SetMarkerStyle( 20 ); TGraph2DErrors* tRatePerEnergySignal = new TGraph2DErrors(); - tRatePerEnergySignal->SetMarkerStyle( 20 ); + + int l = 0; int m = 0; for( unsigned int i = 0; i < ( RunSum->GetEntries() - 1 ); i++ ) @@ -104,7 +129,8 @@ int main( int argc, char* argv[] ) RunSum->GetEntry( i ); alphaNorm = OffNorm; - double iZenithperrun = 90.0 - elevationOff; + //iZenithperrun = 90.0 - elevationOn; + iZenithperrun = 90.0 - elevationOff; sprintf( histnameOn, "run_%d/stereo/energyHistograms/herecCounts_on", runOn ); sprintf( histnameOff, "run_%d/stereo/energyHistograms/herecCounts_off", runOn ); TH1D* t1 = ( TH1D* )f1->Get( histnameOn ); @@ -113,52 +139,93 @@ int main( int argc, char* argv[] ) // get the observation time of each run sprintf( reddataname, "run_%d/stereo/pointingDataReduced", runOn ); TTree* tReddata = ( TTree* )f1->Get( reddataname ); - if( !tReddata ) - { - cout << "Error reading pointingDataReduced tree for run " << runOn << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } - Double_t tObs = tReddata->GetEntries(); + + tObs = tReddata->GetEntries(); cout << "Run Number: " << runOn ; + cout << ", Elevation angle = " << 90 - iZenithperrun ; cout << ", Zenith angle = " << iZenithperrun ; cout << ", Time for Run = " << tObs << "s" << endl; // get the bin content of the ON and OFF events per second and scale the off-counts with the alpha factor for( unsigned int k = 0; k < iBin; k++ ) { - double n_on = ( t1->GetBinContent( k ) ) * 1.0 / tObs; - double n_on_error = ( t1->GetBinError( k ) ) * 1.0 / tObs; - double n_off = ( t2->GetBinContent( k ) ) * alphaNorm / tObs; - double n_off_error = ( t2->GetBinError( k ) ) * alphaNorm / tObs; + new_on = ( t1->GetBinContent( k ) ) * 1.0 / tObs; + new_on_error = ( t1->GetBinError( k ) ) * 1.0 / tObs; + new_off = ( t2->GetBinContent( k ) ) * alphaNorm / tObs; + new_off_error = ( t2->GetBinError( k ) ) * alphaNorm / tObs; /* ON rate (signal and background) */ - tRatePerEnergyON->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, n_on ); - tRatePerEnergyON->SetPointError( m, 0., 0., n_on_error ); + tRatePerEnergyON->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, new_on ); + tRatePerEnergyON->SetPointError( m, 0., 0., new_on_error ); + tRatePerEnergyON->SetMarkerStyle( 20 ); /* Signal rate (ON minus OFF) */ - tRatePerEnergySignal->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, TMath::Abs( n_on - n_off ) ); - tRatePerEnergySignal->SetPointError( m, 0., 0., ( TMath::Abs( n_on_error + n_off_error ) / 2.0 ) ); + tRatePerEnergySignal->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, TMath::Abs( new_on - new_off ) ); + tRatePerEnergySignal->SetPointError( m, 0., 0., ( TMath::Abs( new_on_error + new_off_error ) / 2.0 ) ); + tRatePerEnergySignal->SetMarkerStyle( 20 ); /* OFF rate */ - tRatePerEnergyOFF->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, n_off ); - tRatePerEnergyOFF->SetPointError( m, 0., 0., n_off_error ); + tRatePerEnergyOFF->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, new_off ); + tRatePerEnergyOFF->SetPointError( m, 0., 0., new_off_error ); + tRatePerEnergyOFF->SetMarkerStyle( 20 ); m++; } + l++; } - // write particle number file - TFile* SignalRateFile = new TFile( iOutFil.c_str() , "RECREATE" ); + // ----------------------------------------------------------------- + // + // Plot the ON, OFF and Signal rates (ON minus OFF) for the specific zenith angle intervals + // + // ----------------------------------------------------------------- + gStyle->SetPalette( 1 ); + + /* ON rate = Signal plus background */ + TCanvas* c1 = new TCanvas( "c1", "1D_On_Counts", 0, 0, 700, 500 ); + c1->cd(); + c1->SetRightMargin( 0.15 ); + + tRatePerEnergyON->SetTitle( "signal+background rate (1/sec); Log_{10}E [TeV]; Zenith angle [deg]" ); + tRatePerEnergyON->Draw( "P" ); + c1->Update(); + + // OFF rate = Background rate + TCanvas* c2 = new TCanvas( "c2", "1D_Off_Counts", 750, 0, 700, 500 ); + c2->cd(); + c2->SetRightMargin( 0.15 ); + + tRatePerEnergyOFF->SetTitle( "background rate (1/sec); Log_{10}E [TeV]; Zenith angle [deg]" ); + tRatePerEnergyOFF->Draw( "P" ); + c2->Update(); + + TCanvas* c3 = new TCanvas( "c3", "1D_Signal_Counts", 750, 750, 700, 500 ); + c3->cd(); + c3->SetRightMargin( 0.15 ); + tRatePerEnergySignal->SetTitle( "signal rate (1/sec); Log_{10}E [TeV]; Zenith angle [deg] " ); + tRatePerEnergySignal->Draw( "P" ); + c3->Update(); + + ////////////////////////////////////////////////////////////////////////////////////////// + + /* write particle number file */ + + char iOutputFile[800]; + sprintf( iOutputFile, "%s", iOutFil.c_str() ); + TFile* SignalRateFile = new TFile( iOutputFile, "RECREATE" ); + + SignalRateFile->cd(); + SignalRateFile->Write(); // write graphs of ON rate to file tRatePerEnergyON->Write( "gONRate" ); + // write graphs of OFF rate to file tRatePerEnergyOFF->Write( "gBGRate" ); + // write graphs of signal rate to file tRatePerEnergySignal->Write( "gSignalRate" ); - SignalRateFile->Close(); return 0; } diff --git a/src/writeParticleRateFilesFromEffectiveAreas.cpp b/src/writeParticleRateFilesFromEffectiveAreas.cpp new file mode 100644 index 000000000..8c4e07d2d --- /dev/null +++ b/src/writeParticleRateFilesFromEffectiveAreas.cpp @@ -0,0 +1,251 @@ +/* writeParticleRateFilesFromEffectiveAreas + + write files with particle number spectra for on (gamma) and off (protons+electrons) counts + + files are needed e.g. for setting the optimal cut value for TMVA cuts + + Input: + * effective areas (gammas/protons/electrons/ec) + * cosmic ray spectra (read from files) + + Output: + * root file with signal and background rates + * [optional] angular resolution histograms + +*/ + +#include "VHistogramUtilities.h" +#include "VInstrumentResponseFunctionReader.h" +#include "VWPPhysSensitivityFile.h" + +#include +#include +#include + +using namespace std; + +/* + + calculate angular angular resolution vs containment radius vs energy +*/ +void writeAngResHistogram( char* iMC_Gamma = 0, string iParticleNumberFile = "particleNumbers.tmp.root" ) +{ + if( !iMC_Gamma ) + { + return; + } + + VInstrumentResponseFunctionReader iR; + iR.fillData( iMC_Gamma ); + for( unsigned int i = 0; i < iR.fIRF_TreeNames.size(); i++ ) + { + if( iR.fIRF_TreeNames[i] == "t_angular_resolution_095p" ) + { + TH2D* h = 0; + if( i < iR.fIRF_Data.size() && iR.fIRF_Data[i] ) + { + h = iR.fIRF_Data[i]->f2DHisto[VInstrumentResponseFunctionData::E_DIFF]; + } + TH2D* hRes = VHistogramUtilities::calculateContainmentDistance( h, "AngResCumulative" ); + if( hRes ) + { + TFile hh( iParticleNumberFile.c_str(), "update" ); + cout << "writing angular resolution histogram to " << hh.GetName() << endl; + hRes->Write(); + hh.Close(); + } + break; + } + } +} + + + + +void writeParticleNumberFile( char* iMC_Gamma = 0, char* iMC_Proton = 0, char* iMC_Electron = 0, + unsigned int iCrabSpec_ID = 5, string iParticleNumberFile = "particleNumbers.tmp.root", + string iObservatory = "CTA" ) +{ + string iESpecDataFile_CrabNebula = "$" + iObservatory + "_EVNDISP_AUX_DIR/AstroData/TeV_data/EnergySpectrum_literatureValues_CrabNebula.dat"; + string iESpecDataFile_CosmicRays = "$" + iObservatory + "_EVNDISP_AUX_DIR/AstroData/TeV_data/EnergySpectrum_literatureValues_CR.dat"; + + if( iMC_Gamma && iMC_Proton ) + { + // use sensitivity calculator for differential flux calculation + VSensitivityCalculator b; + b.setDebug( false ); // creates lots of output (if set to true) + // set Crab Nebula spectrum + b.setEnergySpectrumfromLiterature( iESpecDataFile_CrabNebula, iCrabSpec_ID ); + // set output result file name + b.setWriteParticleNumberFile( iParticleNumberFile ); + // CTA + int i_Azbin_gamma = 0; + double i_index_gamma = 2.5; + int i_noise_gamma = 250; + double i_woff_gamma = 0.; + + int i_Azbin_proton = 0; + double i_index_proton = 2.5; + int i_noise_proton = 250; + double i_woff_proton = 0.; + cout << "SETTING EFFECTIVE AREA SEARCH VALUES TO " << iObservatory << endl; + ////////////////////////////////////////////////////////////////////////// + + // gammas + b.setMonteCarloParameters( 1, iESpecDataFile_CrabNebula, iCrabSpec_ID, iMC_Gamma, 20., + i_Azbin_gamma, i_woff_gamma, i_noise_gamma, i_index_gamma, + -1.9 ); + // protons + b.setMonteCarloParameters( 14, iESpecDataFile_CosmicRays, 0, iMC_Proton, 20., + i_Azbin_proton, i_woff_proton, i_noise_proton, i_index_proton, + -1.9 ); + // electrons (spectral index?) + if( iMC_Electron ) + { + b.setMonteCarloParameters( 2, iESpecDataFile_CosmicRays, 8, iMC_Electron, 20., 0, 0.0, 250, 3.0, -1.9 ); + } + // calculate differential fluxes for 5 bins per decade (0.2) + b.calculateParticleNumberGraphs_MC( 0.2 ); + } +} + +/* + + write files with particle number spectra for on (gamma) and off (protons+electrons) counts + + files are needed e.g. for setting the optimal cut value for TMVA cuts + + (for all sub arrays) + +*/ +int main( int argc, char* argv[] ) +{ + if( argc != 5 && argc != 6 ) + { + cout << endl; + cout << "writeParticleRateFilesFromEffectiveAreas "; + cout << " [directory with angular resolution files]" << endl; + cout << argc << endl; + cout << endl; + exit( 0 ); + } + + cout << endl; + cout << "writeParticleRateFilesFromEffectiveAreas" << endl; + cout << "========================================" << endl; + cout << endl; + + string SubArray = argv[1]; + string iOnSource = argv[2]; + int iRecID = atoi( argv[3] ); + string iDataDir = argv[4]; + string iAngResDir = ""; + if( argc == 6 ) + { + iAngResDir = argv[5]; + } + + // hardwired total number of off source bins + int iOffSetCounter = -1; + if( iOnSource == "onSource" ) + { + iOffSetCounter = 0; + } + else if( iOnSource == "cone" ) + { + iOffSetCounter = 8; + } + else if( iOnSource == "offset_7_bin_Norm_Pointing" ) + { + iOffSetCounter = 7; + } + else if( iOnSource == "offset_9_bin_WARSAW" ) + { + iOffSetCounter = 9; + } + else + { + cout << iOnSource << " invalid off source descriptor; should be: onSource or cone" << endl; + exit( -1 ); + } + + // effective area file names + string iMC_Gamma_onSource = "gamma_onSource"; + string iMC_Gamma_cone = "gamma_cone"; + string iMC_Proton = "proton"; + string iMC_Proton_onSource = "proton_onSource"; + string iMC_Electron = "electron"; + string iMC_Electron_onSource = "electron_onSource"; + + if( iOnSource == "offset_9_bin_WARSAW" ) + { + iMC_Gamma_cone = "gamma_0-20_WARSAW"; + iMC_Proton = "proton_0-20_rER_WARSAW"; + iMC_Electron = ""; + iMC_Gamma_onSource = ""; + } + if( iOnSource == "offset_7_bin_Norm_Pointing" ) + { + iMC_Gamma_cone = "gamma_0-20_Norm_Pointing"; + iMC_Proton = "proton_0-20_rER_Norm_Pointing"; + iMC_Electron = ""; + iMC_Gamma_onSource = ""; + } + + + char iGamma[800]; + char iProton[800]; + char iElectron[800]; + char iParticleNumberFile[800]; + + cout << "STARTING SUBARRAY " << SubArray << endl; + + // on-axis rates + if( iMC_Gamma_onSource.size() > 0 ) + { + sprintf( iParticleNumberFile, "%s/ParticleNumbers.%s.00.root", iDataDir.c_str(), SubArray.c_str() ); + sprintf( iGamma, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Gamma_onSource.c_str(), SubArray.c_str(), iRecID, 0 ); + sprintf( iProton, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Proton_onSource.c_str(), SubArray.c_str(), iRecID, 0 ); + if( iMC_Electron_onSource.size() > 0 ) + { + sprintf( iElectron, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Electron_onSource.c_str(), SubArray.c_str(), iRecID, 0 ); + writeParticleNumberFile( iGamma, iProton, iElectron, 5, iParticleNumberFile ); + } + else + { + writeParticleNumberFile( iGamma, iProton, 0, 5, iParticleNumberFile ); + } + // angular resolution histogram + if( iAngResDir.size() > 0 ) + { + sprintf( iGamma, "%s/%s.%s_ID%d.eff-%d.root", iAngResDir.c_str(), iMC_Gamma_onSource.c_str(), SubArray.c_str(), iRecID, 0 ); + writeAngResHistogram( iGamma, iParticleNumberFile ); + } + } + + // off-axis rates + for( int j = 0; j < iOffSetCounter; j++ ) // use first bin on source particle file + { + + sprintf( iParticleNumberFile, "%s/ParticleNumbers.%s.%d.root", iDataDir.c_str(), SubArray.c_str(), j ); + sprintf( iGamma, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Gamma_cone.c_str(), SubArray.c_str(), iRecID, j ); + sprintf( iProton, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Proton.c_str(), SubArray.c_str(), iRecID, j ); + + if( iMC_Electron.size() > 0 ) + { + sprintf( iElectron, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Electron.c_str(), SubArray.c_str(), iRecID, j ); + writeParticleNumberFile( iGamma, iProton, iElectron, 5, iParticleNumberFile ); + } + else + { + writeParticleNumberFile( iGamma, iProton, 0, 5, iParticleNumberFile ); + } + // angular resolution histogram + if( iAngResDir.size() > 0 ) + { + sprintf( iGamma, "%s/%s.%s_ID%d.eff-%d.root", iAngResDir.c_str(), iMC_Gamma_cone.c_str(), SubArray.c_str(), iRecID, j ); + writeAngResHistogram( iGamma, iParticleNumberFile ); + } + } +} + From 9f753e270a13de93d371409e3fe909e79b61ee37 Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Tue, 4 Apr 2023 09:56:30 +0200 Subject: [PATCH 02/17] remove old files --- src/.VCalibrator.cpp.swp | Bin 16384 -> 0 bytes src/.VIPRCalculator.cpp.swo | Bin 49152 -> 0 bytes src/.VIPRCalculator.cpp.swp | Bin 20480 -> 0 bytes src/.VPedestalCalculator.cpp.swo | Bin 32768 -> 0 bytes src/.VPedestalCalculator.cpp.swp | Bin 20480 -> 0 bytes src/._VIPRCalculator.cpp | Bin 4096 -> 0 bytes 6 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/.VCalibrator.cpp.swp delete mode 100644 src/.VIPRCalculator.cpp.swo delete mode 100644 src/.VIPRCalculator.cpp.swp delete mode 100644 src/.VPedestalCalculator.cpp.swo delete mode 100644 src/.VPedestalCalculator.cpp.swp delete mode 100644 src/._VIPRCalculator.cpp diff --git a/src/.VCalibrator.cpp.swp b/src/.VCalibrator.cpp.swp deleted file mode 100644 index 1112f139c1d651bbac35169ab8174a4e5ad112e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 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 Xrsdz%%w6p=x3kMt$u!&(vSR)Rl2fFX diff --git a/src/.VIPRCalculator.cpp.swo b/src/.VIPRCalculator.cpp.swo deleted file mode 100644 index 9214cc0a3b12c31c7eaa83ad781873427a6cdb83..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 49152 zcmeI53w&Hxedh-Vv?4(HK$j*^nrnr)BU_ea=ZRk%MV4(9M;4M|JF#8uSh|v~J(>}7 zN0uL(1Onkz9$5l}wAmB_%VXPgOW5+rejtR9Y_{DlP-uaYkbX8HX<$o9KXkV(dF=Op z9`}7UGm>c8W%TjS_s+fN`9J6U&-p*jxkvi;4PEYB+;c&JzZVw@pZe)!0Yvt0hIeE3z-{OqF@sgfX?m~Umt@KQ}{z?AJh|pVJ@ar|VciP`{e(y}Jx-j2+ z+^u=_lHa@FyEVVpWayPDy@SWyN_~gt&zDOlhbn%(R4$k5UbW)K-b@_7V508&_49lE z+GOv(p^?#nQh9QLpw(K>|hz(Rd`!zC{)oWE&fpH%QYo47eTqKDYtA8&p6UjDrinV=pQc zz6TxwUjknQzXv`9N?d&^yb?T&GUC60qu?y?G{XP4zJzhP^&nT)ynbl>h4opf)`f@cQ$DLb)7Tg)<+jABc)nt&aJz(V%LW4(?fHm8F!%U zmMUIlCV1r^^l;HAA11)?@ZS0QMCCHC;`i?uaJs_G^Ru#VR+Ob*nwu}X{ zf=$$3Ej66pZBEgt_~X?vcQO^Kx7V32O-)Yt3v&}ksDrc33F@-V*>s_Eo-@2Kcf_qZ z)oDj6SSLfrt3aRQrLymoChH5hv7B^BV9uR#7Up|$^O&1GMe-N+^^xf1ySd-C-AUAf z_nRndRuVg_HOD=nD&6f&^8?2mXL6xdb0_Ogv46hiY`nP3=^q;(9ddkcPW)wXt?72W zy5sqd?{cZg3u(AgtyVhelrr-fCt0et;QA_;WC2T+sgOdYnrl;5r7``)nYVq&nfA)* zrh(`bgw}KB-O@2qsQC1*&GFLVJ>;u8&XrD3ojHf*ajKQ_$$&VggF7erw|4ES^yckO zpVRfz$|XrzG7GYD%Raqqy10^Bc+-O?<{27ZeJp3Fq}fB}pmEeV9rxW*ZF08Q6&>SY z6G&mrAakfmkE5F)jHMoi#GEcyOZ9+d(eF3*gselqw8`;qaKo#^w{#yVr(3H#^{O*k zs=I~L1sx^sEw*{H2`6ES&H~+Rrotd)_&SP#bqO1_eaCQ7Q{phYFoX?hf;j7hv%ocn zHGzF-vq653EzIroYJOeO%AvRiEB@gipO9wK%E9Bt*^H?M*zZ-Qs*8I{D*2YOGyN$e znXQRhB%8@rc$J9N* z!N<^<_56BuhPlu1J@~oepw6NqxYH>)=*HDeP>jrVwnUxO)b%H;^R81r$$vHykH`6K ziBYfiS4zb$GmAQ1l62?hXc6f&p4TNTJ7Dv4+9^-CeYFP zD#*aFh1sxu$iJ#Ocf@n0zXn0ZCGB-VC|M@Bi;j94#+829!&;)w+9}E8?c^gRZr0n$GhrbTfHr?Ttk!Q+65|Eu1gWr2)8*wOnWP37}(N5;>WArl#@() z%B6O(<}OmXsm+^@t6{NK-Ro*?kEbblhI9^>&fzoL-`o>kz32=c7#g40**~=BiqXMn zQ`%6r4|hs%h}+ZCqsDri1*JkKD-`zOZryP=Gk7bNsw~!Q?{=n2^^)q)xKn3j67LIZ z!iYPFHwuT7rF^8>vjc>~l-??|Q%nc(cRjP6P<5T^ zCF^>*vp)_Usd?_S@Nwn$&N|+ab+=zS?kc9dYqWo4ccFLP8t2etx#auuFm#eHi2VO+ z$f0jXCKdVL+P9xVuD>7L3+@Joz*S%nbb~JN5VHIO;4i?}fyn!}f;WQKgKqFNa{Ld$ z55VK#Ztx~B49)^SK!*PUxE5>zKSXB#H1NR%U=w&Lcmlco7H~5-0ImRI;8kD^cro~4 zN1^b2@F4g$_zUnm;3n{P@MiEv@SEUQz)QiC$n=kahru1-qu@i}M({4M6|4bIA=it{ z-v!PCF9FX1&p@{)!MDJlgL}Xq0+IQD8@vMuZQlmke{Bl1DbS`sn*v!BK#nugfSxUp z>ZbK_e8ct~h)Rg%NKxUlfpXQ?k7m`vWyALU>?PArNUOtRPTo@NMMuXNT9Q(E@I<|ab`x1j zMNesl$9d}xv7n+oMZ&z?tl*bK>4DOr_mst$tjCF<5>PUQzewn#&U$B~dLawgg!E2W$q=<^ zLJf43n0;G_yw#aSJexp}NcF8A9~qM_;~ZVTUX_&$%GK(;Q)Qj#AZw?x^T~^Us@l<7 zOBtljHme>jtZ8}$ommTQK^Q~|wSHeZ$^4Na)MY`>$e~3X1`9-@AZc27nid|kkd8|P zskEmnT~M`&=8~faBAV1>qKx)IR2+w8Y}!S16ZtlkY|td8baSQotS%2lw5Yu8KVs*>!_+iW^=tw$!JSt(wD%Jx1-oIdfSdzEKSHn9Gyix*7$hMMPsD<1>u#xNS@KP zU~Bq0WR)MG!2|(c#wUefQ?-lk5j7kfWC~>f`=qVi2Oc;yIs%u`qtZ;Vc96knwSKho zP+bY#!IZm;VU30bb`oeyJHpU$;dJxnMVWdjofA?UcEU@7}m`-S+L< zowb(5cN-0zCIERmfi^(3fs*-6D`4?JC40;%3O9@Mu{vy5;wt&S2RZ#3Ao4#Vx%zts z`Tn!u)8HoXKJZ>J12%y^&&W@P3qArlCf16I*XKS3WM#wSz?cqn8W*bgFkE<57Tj>9X7i#Wc*=m(D;Ho~_< z9oMfH?ZRo~5cxCI3GXbOnxqPqqkvgC1Zmq8e+qf1TIhCNX?ayAvE)b>IaQm+`7Nuy z%ZfzzTy8uRO!*DCj7qyQR3d3gxqb>|YpLN?{-z+yDa|UBpCncx6_IvTGOLspN(GZ# zrdyF|%AWZJe|F+XY4TVx7R^q!x%%uDZ>=Jl5no&-V7k&#xuvV_l(oYOc}=X#K45gfZNYl4iQ7WR|n*w93TlX;3t$+^$r` zwHM2h#owNCilKC4+I35aQlvg&|34GkwAisl{WMzWDI}4tQ_Ucb|cw#zt)M(3t5b`JXaFB&OX}o3Mg}A|{c{Q4uob za3O$YgoS|e@M86|R5TlBgEH30PKJ)FW%;1~3v`icI4iG6tyjb*frq5N$5s>E&qnT- z%2h8b4)(EQ0Uaot6$Y?H;rCOVjj2MVeY|NW&YCPY2+}=*MwNJIOC3Rh^zTb4{pbC;a; z(d4W(Q5{GI6L=_Izz+G_|WBp&e)!zfx$7%2Qc)AqixLj!*&R7*TjJATavSY zjX(Q_?UNX}w_t^3jTdtb@g{hpd;nl##h8;o*TOu;9kEcU_eF`zeka-B#3f% zumy!~m9{FE`97h~U< zbJj$xXg2q_e{ZE)o3kb=8zNnw<(62bE=8Oa7kKu{7`vWsmLcu!Q7$?gyB+3GR2myQG`Ue!e;EsUwF)*k!&M~8=o zcWq`vSJjzjXGKT}+2dtAwbkIE(#P2un2~p?QMJ#RtzX7CVo8=yuP(9b2jzeun#{6J zt^`{`=?daK9-nZ8L}uVvYMD8pL;c=n22Z2$1V4-x+EE;i^`-WCFiByR?huo*v(5~% zqB1adVbT_XSqaL*TXKh0FscfcQg|QWX)Z4Cp^MYxEc+6$zzYu(({s>kBe8m0{99^E z!D?~j*s%91(^bWfgMo`j#R8u7(x^d=THd-9-}Dh}GThrD6If(Bk(#lrvs)yH^0lLM z>U~y|NuQ1~LfQ(}!uEjBNkGZ}w<3eCLv9uM-=2^6G%~;J0eBMJ2;Kw6Kqoi{JdWJ| zDEKSzAovq-Ke!Lv3*G}>30?snL;n9P@PX(AE&{IvF9#n(A8->8Ux4?3b>MMy1NVbl zKpA*oJJ( zpa8yrj^MN4^`Hta0G;56=n4J^{4O{Qc7d0JGr+~@1nxu+@DXq$cssZrya8MTj)5`I z5Bk6p(D^R#N8liMEfCtT1?Pfuz**qMpaWcszTgD75NrUl*Z;doodLzq`Ln~+URTEV zY%0m?a#BsEp?@zYrPblf+2vW{>Azf23$|2CEar0O6&u%HTbyNVwA1FMU>}IQBC|@! zxRO&(5RzqxoNgeqkqBP``H%PN#)i|sc@udcx1t}@krFR>qgR?TpA{W^X9E=u0t8#z z#951N*XUI7yiTqhdBq0ViJ6jUeAH11EL?*Gj1EYpAi_t76gT!KMvFxDX4CG$V4bf_ z9?6VDMUyGz(N;^@YCg6yl2I_FLs(lMYIj<-hkc-~JXH>GQ4;C>`>Zp7Q+?1%PN8SH z83P?1(w$YQ+14lfIL#(|R;&K_n0Tq9@yEeZyTix(qSVfo!Voa!7dfECy8*MP+gYuV zvNEiYU$E!UdP0(%9{0LbGR92?q(9pgF5@DEP`7F&it1C&NznIQGZC48m&;}WZ(?^v z_D!o@)7JSj+D(#)ng~jGQXZ7!Zdu7b;_WT2=jzSG_?UVa3{(Ad#5Yro#^{<4$ zsVb=V5%a%`U~V#%?Z&c~T0h;qnZ@wGO*|6cTgD$Gl8#^+AjhelQvfKC_}SAdRd3?d z40PSn>386MUhJ}ZS)Q*69!lVdnmN|X5>EWKg=3!lx-pYOgabG_5~76iSw^s(aQn}U)m~kFZLJ=OgFC5 zN;!FvrS3$N77in*E}a`gS}k~~dSL8$g^5@Wu3@9mXA zkAkc0sRLKodd49(`HIjrYm~uUR*|O91gD9_hpO#S%uLiFev(PHem>{~E$H-_;~D2U zcEKK3Y23TIP6wk%JyC;MsRlTzP0xPGZVpGMXV|G%scItBhIFA%gS2(Mq2?aT7TR~Q z|D%g9d_`nRM{bw>`f^6!+rYJ;1lEEMAie-k0ol9%At18-Q6OjYJ&8>JIq+Gq z04@bD0%w5#h75lf_&m4`+yFe#16~ClL1w=hyant8-$Z7=4jciy!P!7){Xd$Q;URd_ zf0jw-T~PsXFiL5mT;CiVF~iApayHw-5w(ev`IaMl!n3CGQcA4y@`8mLu4D+A3}+ed z$>;X>Kg)tJc_c`DTGb1`%w=En6>NfSlaa+<>q|geX?x8ln+?&z>d!{8*A^F=1sg9c zR9a$byq2WvnLoT7)waEiRi!KuwGch(vJq9;`IZPA6fLDBh^(_P7t$cXWSCgjG11v_ zoz7gLEfF=+dn2KmSga*FOHj7vS7WBoD_Dp)LA_}iy}tGrrl-9VVuupx4fixxFY?)% z$lMbZ&B9dIhv7q zY!rKi*o)QLF_CxXLoOQ*tp*4EEm^E!QK75_W<~4F*4*is4ncKLM;ifymj^gH6P1Sw zcz|P&kQ&5tw{)=52^}nM)v#5~r4l^>yKv8iXyJnVt%8HC`F*_ULiuLPoi1ALOI4uA zkhVpMP<<*q*)^oPVTmc_$IuM=QFq7KxYFcA#yjRd**RT1nZGbC*vwn(TtO>3rWwsK zUvdC|vfLmp>*EL2%p_D!Yem978?WRVp(^zV3TNe;4cmhQHEg-f3@j0r(#m8PK!&_c zsJHiDhZ)-7jo74m-#ZH@T8&AX;~s2jV$9c;rg_e5lc7toCWmvDY8XGG!nqPGr{z>n zc`K$+vG7Ai)>V~BcZnVol(ES!lW5zpEgR|(!~<`5Z^Q%78R#DyRPsM! zYT+$L{P&}`~=zk3Gi+374RCc0h|k74(xgSau)ylKtK3X zd;9T$%h$BA! z{{h?xM5ez0h@Jk0;J+i!%eMeO2R;l$#vcGrK+jKuPlDUQhrzqRJHT&&w*y6UE!sEZ z3mLVQB5-!tt{!?620Aw%ogoS!x-<)6eX>iD6_v-FEHPvLu65rm6bU`hgayf(83M*g zdPq*{#3ZK}>##V@YL9mDo|V$Hl0I7oeRGHst242-ht=ysd1aZ0y{4I+eZv{cCy723 z9FvMbm?BMdy<#JV)2n?FTbj<#BK#9;0#ol#nsLr}dAQft>K61OWN zKiz=g!BaF2+UY zWlmg?L*L>@f}y-MUY$@-1;}bIb*!sChuRbv_E6PwpoUSAn>EM z6MlvSAgkl3i*=A(V6)h;easvb3Z62CPlz4ij6;;W4+^frRK%H`Izf(HGF>B5^B91>>#qM)(_o>6`NFZD8^hix4 z9f+Edq$BCg_qaXr6vOTqV+||KNSzPGvIvLKy!=`gSuGJ-y)qheY|>4g9bpBnmc8^2$+l_-JR9K&ET0mQe$Lms<}81o!NP+b`u*zBx3j z5ZSUW;|nkSwq6~XRmX59^R>T|`ID<=H0k^Xj7t>GKr7GCP?x<0`ja5)Qy=={9whF+ zu7*}h7i1{dz2Ify<*fqF&XP8MkWhLUSc~e4x59)gJEy%7#u8pzLZnM2 zSCMA0CAPxEmM~7%^cwge*evWdR{&3C9bLbs)}Urz3B1FU5cZH(prkS-e0yt*rHZ;X z-yV^Xv#gCVV*lTX47v|_RP6uTv^-jP1G4`FxD;FnhX{770vnPEd0QX{)-M?qLPb9KazM8q&Bl;p!`!2nG2??xpH zr;bJ;?RzyZsYQBpQfkF3)~1woZN5CgRM*&(HY=m7XRVX3^%yo^F~2f3k0?rB&KDKM z5N=;Kdu^UtHbvEXBayX(ebMM@6uTo7I^TPDByFWyYNeZ(r%FayD?~@TOoxrU#PgoV zY(}aC&D%Tj(o8;YzP&`$%>CqF)Bf6=TDAC`LwKPA^CqZj`XtVC2yija> zQtv+z8wOe)R_yBFe0YKu8q=z~XqwS`QPsf;gDu)t`-U#5R6gl@sD4e7$_EUO5BV5e zsVwHWlYxU+#5XJyE27zC-IMhyd79bOoAfxd!5cTZVs{LJd`a1+W%%2Y>`kmTqCL#_ zFS4m6uQq1D)K@UWEa)zI{53ox6)V-KX;zZu8Pcmf*RpO%%2U_L^>nm^#%4 z%dbPI#1?nIz$>BgU`*#MT`EitozxQPWlW(#-fB2U{X+csVr5IgR?A+4s5yH$Y&d(3 z4d5X1@<;FrJ3^ogjO>cH+I~e0#FKQT83IlDQ`kyN_~m`ZG?GH5L%$q-;Op-wh)N>X zbkWb5hFc@k{n740m>uSmreS4+J%nZ^k+;ky5g!O!xX?D6bcRUjVlqb~`eP>is6UNz zjxgUeWeuga?kVR^X$_J8f1MfdCXs!S|F1Ce?>mj$|5arDKQJ=?2-oL=hmrNK2M56m zz-N&2uLo3+@uo=7>+>hSiK5#EM2?oIq@B})9$H1q6ocZ@=a1fji&II>D z*V};5_x(cS=Kg}-fMwm@NBL61ImZTReOnSMclj1XmLSGJ3%cC@i*{pEwWh7dmJ~89 z#al?xMY%1E2gc~Yl5E~92Zd#M0tHPbpZHL^{OIa3#~&!^^@f(WPb@uoZqh;f!Ozq& zAz3UV@tLb+9$CKAvS@B>b6$p#cuD(ke7Abk62>H*VH6HSh$*@+ZaXH5wjHb8k+wC$ zC@OSd{R-`pVTdr%AXwu>mrkfbiHIDxSr%-$(-ToxPGzE3)<@Pgm<57n2`ix99#D3@ zB?4Tj4Sx|;RJeFjt7gn*6WY4O2$H?YS$PfPGHz{5OO$`PwxyJ>&oU12v7RS=hh^Ck zcmE8lEc`ffWRId|WIdQ}l7E>hMOR==Rz-%l?ODDu^2+DnX4IXfjj|;v-WmkW+t;co zqmC%Be2AWu+Mt|%{OT19xCEnr@*uv1FhOoq$Y94k9hGC%K>zqGAzBZ){1`T-HmJ+iqRhi% zT0WK~(+(2ho;Ke`*O28j3TfY~rDE(@6Lly_^V&O`P~)bwA(Pj*DXY0tUXp3#{azkH z;0D>p%*cr0e2PL|c6ra^RaERIG`nqSI=SX+Bh9+9GiS1@(m4NBw5B!Rp_ZfWZ(J22 zAsr#L(Q8%J`$$ed6}3L;uC_W~fBmaBgDdhcojQlU>{ojDR zzYn|${1fuNe8=w#;P-*p{ND<$0egV#@fUmluY#9=4p=De+=Fa?H~1oWC-A^5I0ViEe~WzoJs^7pWS{@V;2vcAQSfKT@?Qh*08f&tC$1z@y0R4}crNOTjbH<|*(bcn`P%Tm^(?2SE0p9crx| z)RDKWNV)*UP7f|RiT$ljt})nAVAiDJLOtYL;j`wQe39Q++F=`%?^z>s$r(#|E622l zQmX=9+v}IFqSs{8?sV=(Roe|)z0!U;MwPbLZ`p-@MWE|EDW({1oY= zGjsLd~IKdFq~+ZFRX7VxpJxAyAMlaR4uGJG&hBxLa`+XZcT;SGMi4 zQ>TWf3I0T3sa0z6Lbp!GEHXNwZ>%Nf@ZRwZl423FIbwMcVL_dbyJQ`^S~&dOCfBJz zI)s$d3}Ou918cvHJ#3ZGi@`*~5lu+MmS79Egf7YkN%!2wZ<-I$ddTI+Sb0pF!q2J> p%a-qS!QQocT{WGS%{agN*bt4baRt!o>bPv)DKZ)u&^{{`S4L-GIs diff --git a/src/.VIPRCalculator.cpp.swp b/src/.VIPRCalculator.cpp.swp deleted file mode 100644 index d154624e860afdc925111dae08f1ecdfec9e9dc2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 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 WpU^4yg=8Y(^SlD{QZJ*Rs72OWH@Q6=F1VCEe_3 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 From e3fad036e262e2dce8b6e2d2db6c8f76b36b3c7a Mon Sep 17 00:00:00 2001 From: GernotMaier Date: Tue, 18 Apr 2023 09:52:45 +0200 Subject: [PATCH 03/17] resolve conflicts --- inc/VCalibrator.h | 3 +++ src/VEventLoop.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/inc/VCalibrator.h b/inc/VCalibrator.h index 69f742e50..9021befcc 100644 --- a/inc/VCalibrator.h +++ b/inc/VCalibrator.h @@ -100,10 +100,12 @@ class VCalibrator : public VImageBaseAnalyzer int readLowGainCalibrationValues_fromCalibFile( string iVariable = "LOWGAINPED", unsigned int iTel = 9999, int iSumWindow = 9999 ); string getCalibrationFileName( int iTel, int irun, string iSuffix, string name = "" ); void readCalibrationData(); + bool readCalibrationDatafromDSTFiles( string iSourceFile ); void readfromVOFFLINE_DBText( int gain_or_toff, vector< unsigned int >& VchannelList, vector< double >& Vmean, vector< double >& Vrms ); void readfromVOFFLINE_DB( int gain_or_toff, string& iFile, vector< unsigned int >& VchannelList, vector< double >& Vmean, vector< double >& Vrms ); void readGains( bool iLowGain = false ); bool readIPRGraph_from_DSTFile( string iDSTFile, unsigned int iSummationWindow, ULong64_t iTelType ); + bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool readLowGainMultiplier( ); bool readPeds( string iFile, bool, unsigned int ); bool readPeds_from_grisufile( bool, unsigned int ); @@ -119,6 +121,7 @@ class VCalibrator : public VImageBaseAnalyzer void writePeds( bool iLowGain, VPedestalCalculator* iP = 0, bool iWriteAsciiFile = true, VIPRCalculator* fIPRCalculator = 0 ); void writeTOffsets( bool iLowGain = false ); void writeAverageTZeros( bool iLowGain = false ); + bool writeIPRgraphs( string iFile = "" ); public: diff --git a/src/VEventLoop.cpp b/src/VEventLoop.cpp index 5f2df9b0b..553698719 100644 --- a/src/VEventLoop.cpp +++ b/src/VEventLoop.cpp @@ -1023,13 +1023,13 @@ bool VEventLoop::nextEvent() else { cout << "!!! void VEventLoop::nextEvent(): no next event (end of file)" << endl; - for( int tel = 0; tel < fIPRCalculator->getStorageHist().size(); tel++ ) + for( unsigned int tel = 0; tel < fIPRCalculator->getStorageHist().size(); tel++ ) { - for( int ts = 0; ts < fIPRCalculator->getStorageHist()[tel].size(); ts++ ) + for( unsigned int ts = 0; ts < fIPRCalculator->getStorageHist()[tel].size(); ts++ ) { - for( int p = 0; p < fIPRCalculator->getStorageHist()[tel][ts].size(); p++ ) + for( unsigned int p = 0; p < fIPRCalculator->getStorageHist()[tel][ts].size(); p++ ) { - for( int sw = 0; sw < fIPRCalculator->getStorageHist()[tel][ts][p].size(); sw++ ) + for( unsigned int sw = 0; sw < fIPRCalculator->getStorageHist()[tel][ts][p].size(); sw++ ) { fIPRCalculator->checkHistEmpty( tel, ts, p, sw ); } From d875f786fff9a004b915438d724c168de7974e22 Mon Sep 17 00:00:00 2001 From: GernotMaier Date: Tue, 18 Apr 2023 09:54:00 +0200 Subject: [PATCH 04/17] conflict fix --- inc/VEvndispRunParameter.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/inc/VEvndispRunParameter.h b/inc/VEvndispRunParameter.h index e9d0d90e0..3286a6bbb 100644 --- a/inc/VEvndispRunParameter.h +++ b/inc/VEvndispRunParameter.h @@ -331,10 +331,6 @@ class VEvndispRunParameter : public TNamed, public VGlobalRunParameter return ( fDBTextDirectory.size() > 0 ); } - <<< <<< < HEAD - ClassDef( VEvndispRunParameter, 2005 ); //(increase this number) - == == == = - ClassDef( VEvndispRunParameter, 2007 ); //(increase this number) - >>> >>> > main + ClassDef( VEvndispRunParameter, 2007 ); //(increase this number) }; #endif From 25645ef877978f5b3f5bbfbcbb70b2b5351fa318 Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Tue, 18 Apr 2023 10:10:25 +0200 Subject: [PATCH 05/17] Update recent changes by GM --- inc/VAnaSumRunParameterLinkDef.h | 6 - inc/VBaseRawDataReader.h | 10 +- inc/VCalibrator.h | 22 +- inc/VCamera.h | 2 +- inc/VDST.h | 8 +- inc/VDSTReader.h | 6 +- inc/VDSTTree.h | 2 +- inc/VDataMCComparision.h | 8 +- inc/VDeadPixelOrganizer.h | 4 +- inc/VDisplay.h | 6 +- inc/VEnergyThreshold.h | 64 +- inc/VEventLoop.h | 24 +- inc/VEvndispData.h | 38 +- inc/VEvndispRunParameter.h | 3 +- inc/VFitTraceHandler.h | 4 +- inc/VGammaHadronCuts.h | 9 +- inc/VGlobalRunParameter.h | 7 +- inc/VGrIsuReader.h | 6 +- inc/VIPRCalculator.h | 24 +- inc/VIPRCalculator.h.bsk | 62 + inc/VImageAnalyzer.h | 6 +- inc/VImageAnalyzerData.h | 6 +- inc/VImageBaseAnalyzer.h | 2 +- inc/VImageCleaning.h | 20 +- inc/VImageCleaningRunParameter.h | 1 - inc/VImageParameterCalculation.h | 8 +- inc/VInstrumentResponseFunctionRunParameter.h | 7 +- inc/VNoiseFileReader.h | 2 +- inc/VPedestalCalculator.h | 17 +- inc/VPlotAnasumHistograms.h | 5 +- inc/VPlotCompareDataWithMC.h | 6 +- inc/VPlotTMVAParameters.h | 47 - inc/VPlotTMVAParametersLinkDef.h | 3 - inc/VRawDataReader.h | 4 +- inc/VReadRunParameter.h | 8 +- inc/VSensitivityCalculator.h | 6 +- inc/VSimulationDataReader.h | 2 +- inc/VStereoAnalysis.h | 2 +- inc/VTMVAEvaluator.h | 77 +- inc/VTMVARunData.h | 18 +- inc/VVirtualDataReader.h | 2 +- src/VAnaSum.cpp | 9 +- src/VAnaSumRunParameter.cpp | 185 +-- src/VCalibrationData.cpp | 2 +- src/VCalibrator.cpp | 1089 +++++++++++++- src/VDataMCComparision.cpp | 39 +- src/VEffectiveAreaCalculator.cpp | 134 +- src/VEnergyThreshold.cpp | 251 ++-- src/VEventLoop.cpp | 46 +- src/VEvndispRunParameter.cpp | 11 +- src/VGammaHadronCuts.cpp | 138 +- src/VGlobalRunParameter.cpp | 24 +- src/VIPRCalculator.cpp | 1023 +++++-------- src/VIPRCalculator.cpp.bak | 830 ++++++++++ src/VImageBaseAnalyzer.cpp | 11 - src/VImageCleaning.cpp | 243 +-- src/VImageCleaningRunParameter.cpp | 10 +- ...InstrumentResponseFunctionRunParameter.cpp | 8 +- src/VMonteCarloRateCalculator.cpp | 6 +- src/VPedestalCalculator.cpp | 32 +- src/VPlotAnasumHistograms.cpp | 41 +- src/VPlotCompareDataWithMC.cpp | 94 +- src/VPlotInstrumentResponseFunction.cpp | 10 +- src/VPlotTMVAParameters.cpp | 179 --- src/VReadRunParameter.cpp | 11 +- src/VSensitivityCalculator.cpp | 62 +- src/VStereoAnalysis.cpp | 73 +- src/VStereoHistograms.cpp | 5 +- src/VTMVAEvaluator.cpp | 1329 ++++++----------- src/VTMVARunData.cpp | 241 ++- src/VTMVARunDataEnergyCut.cpp | 3 - src/VTS.calculateCrabRateFromMC.cpp | 173 --- src/VTS.getRunListFromDB.cpp | 8 +- src/VTableLookupDataHandler.cpp | 4 +- src/VTableLookupRunParameter.cpp | 4 +- src/anasum.cpp | 4 +- src/calculateCrabRateFromMC.cpp | 570 +++++++ src/combineEffectiveAreas.cpp | 6 +- src/compareDatawithMC.cpp | 24 +- src/makeEffectiveArea.cpp | 10 +- src/makeRadialAcceptance.cpp | 47 +- src/printRunParameter.cpp | 23 +- src/trainTMVAforAngularReconstruction.cpp | 4 +- src/trainTMVAforGammaHadronSeparation.cpp | 555 ++++--- ...AforGammaHadronSeparation_TrainingFile.cpp | 178 --- src/writeParticleRateFilesForTMVA.cpp | 177 +-- ...iteParticleRateFilesFromEffectiveAreas.cpp | 251 ---- 87 files changed, 4822 insertions(+), 3919 deletions(-) create mode 100644 inc/VIPRCalculator.h.bsk delete mode 100644 inc/VPlotTMVAParameters.h delete mode 100644 inc/VPlotTMVAParametersLinkDef.h create mode 100644 src/VIPRCalculator.cpp.bak delete mode 100644 src/VPlotTMVAParameters.cpp delete mode 100644 src/VTS.calculateCrabRateFromMC.cpp create mode 100644 src/calculateCrabRateFromMC.cpp delete mode 100644 src/trainTMVAforGammaHadronSeparation_TrainingFile.cpp delete mode 100644 src/writeParticleRateFilesFromEffectiveAreas.cpp diff --git a/inc/VAnaSumRunParameterLinkDef.h b/inc/VAnaSumRunParameterLinkDef.h index e21bcbaec..b680e2cae 100644 --- a/inc/VAnaSumRunParameterLinkDef.h +++ b/inc/VAnaSumRunParameterLinkDef.h @@ -3,14 +3,8 @@ #pragma link off all classes; #pragma link off all functions; -//#pragma link C++ nestedclasses ; - #pragma link C++ class vector+; #pragma link C++ class VAnaSumRunParameterDataClass+; #pragma link C++ class VAnaSumRunParameterListOfExclusionRegions+; #pragma link C++ class VAnaSumRunParameter+; -//#pragma link C++ class std::vector+; - -//#pragma read sourceClass="VAnaSumRunParameter" source="std::vector fRunList" \ -// targetClass="VAnaSumRunParameter" target="std::vector fRunList" attributes="Owner" ; #endif diff --git a/inc/VBaseRawDataReader.h b/inc/VBaseRawDataReader.h index 3764d3ff9..bfe440b53 100644 --- a/inc/VBaseRawDataReader.h +++ b/inc/VBaseRawDataReader.h @@ -3,13 +3,13 @@ #ifndef VBASEDATAREADER_H #define VBASEDATAREADER_H -#include -#include -#include +#include "VDetectorGeometry.h" +#include "VMonteCarloRunHeader.h" +#include "VNoiseFileReader.h" #include #include -#include -#include +#include "VVirtualDataReader.h" +#include "VSimulationDataReader.h" #include "TRandom3.h" diff --git a/inc/VCalibrator.h b/inc/VCalibrator.h index b2e743519..53ed877ae 100644 --- a/inc/VCalibrator.h +++ b/inc/VCalibrator.h @@ -3,10 +3,10 @@ #ifndef VCALIBRATOR_H #define VCALIBRATOR_H -#include -#include -#include -#include +#include "VImageBaseAnalyzer.h" +#include "VPedestalCalculator.h" +#include "VIPRCalculator.h" +#include "VDB_CalibrationInfo.h" #include #include "TClonesArray.h" @@ -100,10 +100,16 @@ class VCalibrator : public VImageBaseAnalyzer int readLowGainCalibrationValues_fromCalibFile( string iVariable = "LOWGAINPED", unsigned int iTel = 9999, int iSumWindow = 9999 ); string getCalibrationFileName( int iTel, int irun, string iSuffix, string name = "" ); void readCalibrationData(); + bool readCalibrationDatafromDSTFiles( string iSourceFile ); void readfromVOFFLINE_DBText( int gain_or_toff, vector< unsigned int >& VchannelList, vector< double >& Vmean, vector< double >& Vrms ); void readfromVOFFLINE_DB( int gain_or_toff, string& iFile, vector< unsigned int >& VchannelList, vector< double >& Vmean, vector< double >& Vrms ); void readGains( bool iLowGain = false ); bool readIPRGraph_from_DSTFile( string iDSTFile, unsigned int iSummationWindow, ULong64_t iTelType ); + bool calculateIPRGraphs(); + bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); + bool copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); + TH1F* initializeIPRAveraged( unsigned int iSummationWindow, unsigned int iTelType ); + TH1F* calculateIPRGraphAveraged( unsigned int iSummationWindow ); bool readLowGainMultiplier( ); bool readPeds( string iFile, bool, unsigned int ); bool readPeds_from_grisufile( bool, unsigned int ); @@ -116,9 +122,10 @@ class VCalibrator : public VImageBaseAnalyzer void setCalibrationFileNames(); void writeGains( bool iLowGain = false ); - void writePeds( bool iLowGain, VPedestalCalculator* iP = 0, bool iWriteAsciiFile = true, VIPRCalculator *fIPRCalculator = 0 ); + void writePeds( bool iLowGain, VPedestalCalculator* iP = 0, bool iWriteAsciiFile = true ); void writeTOffsets( bool iLowGain = false ); void writeAverageTZeros( bool iLowGain = false ); + bool writeIPRgraphs( string iFile = "" ); public: @@ -129,8 +136,7 @@ class VCalibrator : public VImageBaseAnalyzer void calculatePedestals( bool iLowGain = false ); void calculateGainsAndTOffsets( bool iLowGain = false ); unsigned int getNumberOfEventsUsedInCalibration( int iTelID, int iType ); - //void calculateIPRGraphs(VIPRCalculator *fIPRCalculator = 0, VPedestalCalculator *iP = 0); - void initialize( VIPRCalculator *fIPRCalculator ); - void terminate( VPedestalCalculator* iP, VIPRCalculator *fIPRCalculator ); + void initialize(VIPRCalculator *fIPRCalculator ); + void terminate( VPedestalCalculator* ); }; #endif diff --git a/inc/VCamera.h b/inc/VCamera.h index f846c49e4..44a54b51d 100644 --- a/inc/VCamera.h +++ b/inc/VCamera.h @@ -15,7 +15,7 @@ #include #include -#include +#include "VEvndispData.h" #ifndef NOVBF #include #endif diff --git a/inc/VDST.h b/inc/VDST.h index 74bc91670..780f54044 100644 --- a/inc/VDST.h +++ b/inc/VDST.h @@ -8,10 +8,10 @@ #include #include -#include -#include -#include -#include +#include "VGlobalRunParameter.h" +#include "VImageBaseAnalyzer.h" +#include "VImageCleaning.h" +#include "VDSTTree.h" /////////////////////////////////////////////////////////////////////////////////// // MAXIMUM NUMBER OF TELESCOPES AND CHANNELS IS DEFINED IN EVNDISP_definition.h diff --git a/inc/VDSTReader.h b/inc/VDSTReader.h index de64f15d9..9aabbe44f 100644 --- a/inc/VDSTReader.h +++ b/inc/VDSTReader.h @@ -3,9 +3,9 @@ #ifndef VDSTREADER_H #define VDSTREADER_H -#include -#include -#include +#include "VGlobalRunParameter.h" +#include "VDSTTree.h" +#include "VVirtualDataReader.h" #include "TFile.h" #include "TTree.h" diff --git a/inc/VDSTTree.h b/inc/VDSTTree.h index 6813346a9..e4d26ddad 100644 --- a/inc/VDSTTree.h +++ b/inc/VDSTTree.h @@ -16,7 +16,7 @@ #include #include -#include +#include "VGlobalRunParameter.h" //////////////////////////////////////////////////////////////////////////////////////// // MAXIMUM NUMBERS OF TELESCOPES AND CHANNELS ARE DEFINED IN inc/VGlobalRunParameter.h diff --git a/inc/VDataMCComparision.h b/inc/VDataMCComparision.h index 844749fac..2c0ecfd28 100644 --- a/inc/VDataMCComparision.h +++ b/inc/VDataMCComparision.h @@ -87,6 +87,7 @@ class VDataMCComparision // cuts VGammaHadronCuts* fCuts; bool fCalculateMVAValues; + string fEpochATM; // lists with all histograms TList* hisList; @@ -118,7 +119,7 @@ class VDataMCComparision public: - VDataMCComparision( string, int, bool ); + VDataMCComparision( string, int ); ~VDataMCComparision() {} void defineHistograms(); bool fillHistograms( string ifile, int iSingleTelescopeCuts ); @@ -130,6 +131,11 @@ class VDataMCComparision hAzWeight = hAz; } void setAzRange( double iAzMin, double iAzMax ); + void setTMVABDTComparision( string iEpochATM ) + { + fCalculateMVAValues = true; + fEpochATM = iEpochATM; + } void setZeRange( double iZeMin, double iZeMax ); bool setOnOffHistograms( VDataMCComparision*, VDataMCComparision*, double norm ); void setShowerMaximZe_deg( double iZe = 20. ) diff --git a/inc/VDeadPixelOrganizer.h b/inc/VDeadPixelOrganizer.h index 96a2c1707..3553658b7 100644 --- a/inc/VDeadPixelOrganizer.h +++ b/inc/VDeadPixelOrganizer.h @@ -18,8 +18,8 @@ #include -#include -#include +#include "VDetectorGeometry.h" +#include "VEvndispRunParameter.h" using namespace std ; diff --git a/inc/VDisplay.h b/inc/VDisplay.h index 552b7a43d..73ff5e89c 100644 --- a/inc/VDisplay.h +++ b/inc/VDisplay.h @@ -43,9 +43,9 @@ #include #include -#include -#include -#include +#include "VCamera.h" +#include "VDisplayBirdsEye.h" +#include "VEventLoop.h" #include #include diff --git a/inc/VEnergyThreshold.h b/inc/VEnergyThreshold.h index eae7d1f48..a7c765b5f 100644 --- a/inc/VEnergyThreshold.h +++ b/inc/VEnergyThreshold.h @@ -4,14 +4,17 @@ #define VEnergyThreshold_H #include "TCanvas.h" +#include "TChain.h" #include "TF1.h" #include "TFile.h" +#include "TGraph.h" #include "TGraphErrors.h" #include "TH1D.h" +#include "TH2F.h" #include "TList.h" #include "TMath.h" #include "TObject.h" -#include "TProfile.h" +#include "TROOT.h" #include "TStyle.h" #include "TText.h" #include "TTree.h" @@ -23,7 +26,6 @@ #include #include "VRunList.h" -#include "CEffArea.h" using namespace std; @@ -34,7 +36,7 @@ class VEnergyThreshold : public TObject bool fDebug; TFile* fEffAreaFile; - CEffArea* fEffArea; + TChain* fEffArea; TFile* fEnergyThresholdFile; @@ -44,30 +46,32 @@ class VEnergyThreshold : public TObject TFile* fOutFile; TTree* fTreeEth; - double fze; - int fAzBin; - double fAzMin; - double fAzMax; - double fXoff; - double fYoff; - double fWoff; - int fTNoise; - double fTNoisePE; - double fTPedvar; - double fSpectralIndex; - double feth; - double fesys_10p; - double fesys_15p; - double fesys_20p; - double feffFract_05p; - double feffFract_10p; - double feffFract_20p; - double feffFract_50p; - double feffFract_90p; - // effective areas - double feff_300GeV; - double feff_500GeV; - double feff_1TeV; + float fze; + UShort_t fAzBin; + float fAzMin; + float fAzMax; + float fWoff; + UShort_t fTNoise; + float fTPedvar; + float feth; + float fesys_10p; + float fesys_15p; + float fesys_20p; + float feffFract_05p; + float feffFract_10p; + float feffFract_20p; + float feffFract_50p; + float feffFract_90p; + float feff_300GeV; + float feff_500GeV; + float feff_1TeV; + + UShort_t nbins; + float e0[1000]; + float eff[1000]; + UShort_t nbins_esys; + float e0_esys[1000]; + float esys_rel[1000]; int fPlottingMarkerStyle; int fPlottingMarkerColor; @@ -79,7 +83,6 @@ class VEnergyThreshold : public TObject double getEnergyThreshold( TH1D* h = 0, bool bLogEnergyAxis = true, bool bFit = true ); bool openEnergyThresholdFile(); bool setUpThresholdTree(); - void copyEntry(); double interpolateEnergyThreshold( VRunList* ); @@ -92,13 +95,14 @@ class VEnergyThreshold : public TObject bool closeOutputFile(); bool openEffectiveAreaFile( string ifile ); bool calculateEnergyThreshold( bool bFit = true, int nentries = -1 ); - double getEnergy_maxSystematic( TObject* h = 0, double iSys = 0.1 ); + double getEnergy_maxSystematic( vector< double > x, vector< double > y, double iSys = 0.1 ); + double getEnergy_maxSystematic( TGraphErrors* g, double iSys = 0.1 ); double getEnergy_MaxEffectiveAreaFraction( TObject* h = 0, double iFrac = 0.1 ); double getEnergy_fixedValue() { return fEnergyThresholdFixedValue; } - void plot_energyThresholds( string var = "E_diffmax", double ze = 20., double woff = 0.5, int noise = 150, double index = 2.4, int az = 16, bool bPlot = true, string plot_option = "p" ); + void plot_energyThresholds( string var = "E_diffmax", double ze = 20., double woff = 0.5, int noise = 150, int az = 16, bool bPlot = true, string plot_option = "p" ); void setPlottingStyle( int iC = 1, int iS = 21, float iW = 2., float iL = 2. ) { fPlottingMarkerStyle = iS; diff --git a/inc/VEventLoop.h b/inc/VEventLoop.h index 740f4f98d..168cbdcdb 100644 --- a/inc/VEventLoop.h +++ b/inc/VEventLoop.h @@ -9,22 +9,22 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "VImageAnalyzer.h" +#include "VArrayAnalyzer.h" +#include "VCalibrator.h" +#include "VEvndispData.h" +#include "VDeadTime.h" +#include "VDST.h" #ifndef NOVBF #include -#include -#include +#include "VRawDataReader.h" +#include "VBFDataReader.h" #endif -#include -#include +#include "VPedestalCalculator.h" +#include "VIPRCalculator.h" +#include "VEvndispRunParameter.h" -#include +#include "VDeadPixelOrganizer.h" #include #include diff --git a/inc/VEvndispData.h b/inc/VEvndispData.h index 4fb75ff23..954e23942 100644 --- a/inc/VEvndispData.h +++ b/inc/VEvndispData.h @@ -3,27 +3,27 @@ #ifndef VDATA_H #define VDATA_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "VImageAnalyzerData.h" +#include "VEvndispReconstructionParameter.h" +#include "VCalibrationData.h" +#include "VDeadChannelFinder.h" +#include "VDetectorGeometry.h" +#include "VDetectorTree.h" +#include "VDSTReader.h" +#include "VGrIsuReader.h" +#include "VMCParameters.h" +#include "VMultipleGrIsuReader.h" #ifndef NOVBF -#include +#include "VBaseRawDataReader.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include +#include "VDB_PixelDataReader.h" +#include "VEvndispRunParameter.h" +#include "VFitTraceHandler.h" +#include "VStarCatalogue.h" +#include "VShowerParameters.h" +#include "VPointing.h" +#include "VArrayPointing.h" +#include "VTraceHandler.h" #include "TDirectory.h" #include "TFile.h" diff --git a/inc/VEvndispRunParameter.h b/inc/VEvndispRunParameter.h index 7beb44a94..0bd48a1dd 100644 --- a/inc/VEvndispRunParameter.h +++ b/inc/VEvndispRunParameter.h @@ -312,6 +312,7 @@ class VEvndispRunParameter : public TNamed, public VGlobalRunParameter { return fDBTextDirectory; } + string getInstrumentATMString(); string getInstrumentEpoch( bool iMajor = false, bool iUpdateInstrumentEpoch = false ); bool isMC() @@ -332,6 +333,6 @@ class VEvndispRunParameter : public TNamed, public VGlobalRunParameter return ( fDBTextDirectory.size() > 0 ); } - ClassDef( VEvndispRunParameter, 2005 ); //(increase this number) + ClassDef( VEvndispRunParameter, 2006 ); //(increase this number) }; #endif diff --git a/inc/VFitTraceHandler.h b/inc/VFitTraceHandler.h index c5dc79055..67a8c679c 100644 --- a/inc/VFitTraceHandler.h +++ b/inc/VFitTraceHandler.h @@ -17,8 +17,8 @@ #include "TMath.h" #include "TMinuit.h" -#include -#include +#include "VTraceHandler.h" +#include "VVirtualDataReader.h" using namespace std; diff --git a/inc/VGammaHadronCuts.h b/inc/VGammaHadronCuts.h index 4880aa5e2..08a6c0711 100644 --- a/inc/VGammaHadronCuts.h +++ b/inc/VGammaHadronCuts.h @@ -129,7 +129,6 @@ class VGammaHadronCuts : public VAnalysisUtilities unsigned int fTMVAWeightFileIndex_Emax; unsigned int fTMVAWeightFileIndex_Zmin; unsigned int fTMVAWeightFileIndex_Zmax; - double fTMVAEnergyStepSize; map< unsigned int, double > fTMVASignalEfficiency; map< unsigned int, double > fTMVA_MVACut; double fTMVAProbabilityThreshold; @@ -177,7 +176,7 @@ class VGammaHadronCuts : public VAnalysisUtilities bool initPhaseCuts( string iDir ); bool initProbabilityCuts( int irun ); bool initProbabilityCuts( string iDir ); - bool initTMVAEvaluator( string iTMVAFile, unsigned int iTMVAWeightFileIndex_Emin, unsigned int iTMVAWeightFileIndex_Emax, unsigned int iTMVAWeightFileIndex_Zmin, unsigned int iTMVAWeightFileIndex_Zmax, double iTMVAEnergy_StepSize ); + bool initTMVAEvaluator( string iTMVAFile, unsigned int iTMVAWeightFileIndex_Emin, unsigned int iTMVAWeightFileIndex_Emax, unsigned int iTMVAWeightFileIndex_Zmin, unsigned int iTMVAWeightFileIndex_Zmax ); string getTelToAnalyzeString(); @@ -349,10 +348,6 @@ class VGammaHadronCuts : public VAnalysisUtilities return fCut_Theta2_max; } double getTheta2Cut_max( double e ); // get theta2 max cut (might be energy dependent) [TeV] energy (linear) - TGraph* getTheta2Cut_TMVA_max() - { - return getEnergyDependentCut( "TMVABoxCut_Theta2_max" ); - } TGraph* getTheta2Cut_IRF_Max() { return getEnergyDependentCut( "IRFAngRes" ); @@ -436,6 +431,6 @@ class VGammaHadronCuts : public VAnalysisUtilities return fUseOrbitalPhaseCuts; } - ClassDef( VGammaHadronCuts, 58 ); + ClassDef( VGammaHadronCuts, 59 ); }; #endif diff --git a/inc/VGlobalRunParameter.h b/inc/VGlobalRunParameter.h index 14a4cb997..0cbcdde4d 100644 --- a/inc/VGlobalRunParameter.h +++ b/inc/VGlobalRunParameter.h @@ -57,6 +57,7 @@ class VGlobalRunParameter // DIRECTORIES static string fEVNDISPAnaDataDirectory; // directory where all data (detectorgeometry, ...) is expected and written to (output file) + static string fEVNDISPAnaDataDirectory_tmp; // tmp directories for aux data (rarely used) static string fVBFRawDataDirectory; // directory with VERITAS vbf data (vbf files) static string fEVNDISPCalibrationDataDirectory; // directory where calibration data is expected and written to static string fEVNDISPOutputDirectory; // output- and result files are written into this directory @@ -76,6 +77,10 @@ class VGlobalRunParameter { return fEVNDISPAnaDataDirectory; } + static string getDirectory_EVNDISPAnaDataTMP() + { + return fEVNDISPAnaDataDirectory_tmp; + } string getDirectory_EVNDISPCalibrationData() { return fEVNDISPAnaDataDirectory + "/Calibration/"; @@ -148,7 +153,7 @@ class VGlobalRunParameter bool setDirectory_EVNDISPCalibrationData( string iDir ); bool update( TChain* ic ); - ClassDef( VGlobalRunParameter, 10 ); + ClassDef( VGlobalRunParameter, 11 ); }; #endif diff --git a/inc/VGrIsuReader.h b/inc/VGrIsuReader.h index 3f6d68591..e45589c78 100644 --- a/inc/VGrIsuReader.h +++ b/inc/VGrIsuReader.h @@ -17,10 +17,10 @@ #include "TSystem.h" #include "TTree.h" -#include +#include "VDetectorGeometry.h" #include "VMonteCarloRunHeader.h" -#include -#include +#include "VSkyCoordinatesUtilities.h" +#include "VVirtualDataReader.h" using namespace std; diff --git a/inc/VIPRCalculator.h b/inc/VIPRCalculator.h index c5268fe31..ac7af3656 100644 --- a/inc/VIPRCalculator.h +++ b/inc/VIPRCalculator.h @@ -27,32 +27,20 @@ class VIPRCalculator : public VImageBaseAnalyzer private: VEvndispData* fData; - vector< string > fPedFile; + vector< string > fPedFileNameC; bool fIPRTimeSlices; bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs bool fIPRInTimeSlices; int fPedPerTelescopeTypeMinCnt; TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); - TGraphErrors* updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow); - float convertRate(unsigned int i_tel); - float getTsearch(); - void definePedestalFile( std::vector fPedFileNameC ); - TFile* initializePedestalFile( int i_tel ); + void definePedestalFile( std::vector fPedFileNameCalibrator ); TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); - bool calculateIPRGraphsTimeSlices( const int TimeSlice, int iSummationWindow, const int itel); - bool calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); - bool copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ); - TH1F* calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); + bool copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); + TH1F* calculateIPRGraphAveraged( unsigned int iSummationWindow ); public: - - vector>>> fpedcal_histo_storage; - TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); - vector>>> getStorageHist(); - void fillIPRPedestalHisto(); - void fillIPRPedestalHisto(const int telID, const vector>>& fpedcal_histo ); - bool calculateIPRGraphs( std::vector fPedFileNameC); + bool calculateIPRGraphs( std::vector fPedFileNameCalibrator ); + bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); - void checkHistEmpty(const int telID, const int ts, const int pixel, const int sw); VIPRCalculator(); ~VIPRCalculator() {} diff --git a/inc/VIPRCalculator.h.bsk b/inc/VIPRCalculator.h.bsk new file mode 100644 index 000000000..b2a59e4fc --- /dev/null +++ b/inc/VIPRCalculator.h.bsk @@ -0,0 +1,62 @@ +#ifndef VIPRCALCULATOR_H +#define VIPRCALCULATOR_H + +#include +#include +#include + +#include "TClonesArray.h" +#include "TFile.h" +#include "TH1F.h" +#include "TLeaf.h" +#include "TMath.h" +#include "TProfile.h" +#include "TSystem.h" +#include "TTree.h" + +#include +#include +#include +#include +#include + +using namespace std; + +class VIPRCalculator : public VImageBaseAnalyzer +{ + + private: + VEvndispData* fData; + vector< string > fPedFile; + bool fIPRTimeSlices; + bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs + bool fIPRInTimeSlices; + int fPedPerTelescopeTypeMinCnt; + TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + TGraphErrors* updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow); + float convertRate(unsigned int i_tel); + float getTsearch(); + void definePedestalFile( std::vector fPedFileNameC ); + TFile* initializePedestalFile( int i_tel ); + TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + bool calculateIPRGraphsTimeSlices( const int TimeSlice, int iSummationWindow, const int itel); + bool calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); + bool copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ); + TH1F* calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); + public: + void clearHistos(); + vector>>> fpedcal_histo_storage; + TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); + vector>>> getStorageHist(); + void fillIPRPedestalHisto(); + void fillIPRPedestalHisto(const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ); + bool calculateIPRGraphs( std::vector fPedFileNameC); + bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); + void checkHistEmpty(const int telID, const int ts, const int pixel, const int sw); + + VIPRCalculator(); + ~VIPRCalculator() {} + + void initialize(); +}; +#endif diff --git a/inc/VImageAnalyzer.h b/inc/VImageAnalyzer.h index b00fb6cb7..b4e80d390 100644 --- a/inc/VImageAnalyzer.h +++ b/inc/VImageAnalyzer.h @@ -8,9 +8,9 @@ #include "TTree.h" #include "TROOT.h" -#include -#include -#include +#include "VImageBaseAnalyzer.h" +#include "VImageParameterCalculation.h" +#include "VImageCleaning.h" #include #include diff --git a/inc/VImageAnalyzerData.h b/inc/VImageAnalyzerData.h index 13695dab3..1306d11cd 100644 --- a/inc/VImageAnalyzerData.h +++ b/inc/VImageAnalyzerData.h @@ -8,9 +8,9 @@ #include "TProfile2D.h" #include "TRandom3.h" -#include -#include -#include +#include "VImageAnalyzerHistograms.h" +#include "VSpecialChannel.h" +#include "VImageParameter.h" #include #include diff --git a/inc/VImageBaseAnalyzer.h b/inc/VImageBaseAnalyzer.h index 5d68d3b7d..59c357600 100644 --- a/inc/VImageBaseAnalyzer.h +++ b/inc/VImageBaseAnalyzer.h @@ -3,7 +3,7 @@ #ifndef VIMAGEBASEANALYZER_H #define VIMAGEBASEANALYZER_H -#include +#include "VEvndispData.h" #include "TTree.h" diff --git a/inc/VImageCleaning.h b/inc/VImageCleaning.h index d55fc4d1e..cbced6888 100644 --- a/inc/VImageCleaning.h +++ b/inc/VImageCleaning.h @@ -3,7 +3,7 @@ #ifndef VIMAGECLEANING_H #define VIMAGECLEANING_H -#include +#include "VEvndispData.h" #include #include "VImageCleaningRunParameter.h" @@ -35,16 +35,13 @@ class VImageCleaning bool kInitNNImageCleaning; bool kInitNNImgClnPerTelType[VDST_MAXTELTYPES]; const static unsigned int fIPRdim = 200; - bool NNoptNoTimeing; TObjArray* fProb4nnCurves; TObjArray* fProb3nnrelCurves; TObjArray* fProb2plus1Curves; TObjArray* fProb2nnCurves; TObjArray* fProbBoundCurves; TObjArray* fIPRgraphs; - //vector< vector< TObjArray* > > fIPRTSgraphs; - vector< TObjArray* > fIPRTSgraphs; - //TObjArray*** fIPRTSgraphs; + vector< float > fIPRgraphs_xmax; vector< vector< bool > > fifActiveNN; // [nteltypes][nngroups] bool ifActiveNN[VDST_MAXNNGROUPTYPES][VDST_MAXTELTYPES]; // if NN groups is searched in NN-image cleaning procedure int VALIDITY[VDST_MAXCHANNELS]; // Flags for pixels, accepted by nn-image cleaning. VALIDITY[i]=2-6 : core pixels, VALIDITY[i]>6 :boundary pixels @@ -57,32 +54,35 @@ class VImageCleaning bool setExplicitSampleTimeSlice; // Set the sample time slice and number of ADC bins to read explicitly float sampleTimeSlice; // Size of time slice in ns (usually 1 or 2 ns) unsigned int nBinsADC; // Number of ADC bins summed up, each bin the size of sampleTimeSlice + float fIPR_save_mincharge; + float fIPR_save_dT_from_probCurve; + unsigned int fIPR_save_telid; + double fIPR_save_ProbCurve_par1; + double fIPR_save_ProbCurve_par2; float INTENSITY[VDST_MAXCHANNELS]; // float TIMES[VDST_MAXCHANNELS]; // float** IPR; // IPR[TelType][ScanDim] scan. Not used TelType==0 is filled with DT values - int LocMin( int n, float* ptr, float& min ); - int LocMax( int n, float* ptr, float& max ); + void LocMin( int n, float* ptr, float& min ); + void LocMax( int n, float* ptr, float& max ); // main functions bool BoundarySearch( unsigned int TrigSimTelType, float thresh, TF1* fProbCurve, float refdT, int refvalidity, int idx ); unsigned int NNGroupSearchProbCurve( unsigned int TrigSimTelType, TF1* fProbCurve, float PreCut ); unsigned int NNGroupSearchProbCurveRelaxed( unsigned int TrigSimTelType, TF1* fProbCurve, float PreCut ); - bool NNChargeAndTimeCut( TGraph* IPR, TF1* fProbCurve, float charge, float dT, + bool NNChargeAndTimeCut( TGraph* IPR, float iIPR_max, TF1* fProbCurve, float charge, float dT, float iCoincWinLimit, bool bInvert = false ); void ScaleCombFactors( unsigned int TrigSimTelType, float scale ); void ResetCombFactors( unsigned int TrigSimTelType ); int ImageCleaningCharge( unsigned int TrigSimTelType ); bool InitNNImageCleaning(); bool InitNNImgClnPerTelType( unsigned int TrigSimTelType ); - bool InitNNImgClnPerTelTypeTimeSlice( unsigned int teltype, unsigned int ts ); void DiscardTimeOutlayers( unsigned int TrigSimTelType ); void DiscardLocalTimeOutlayers( float NNthresh[6] ); // use this function void DiscardIsolatedPixels(); void FillIPR( unsigned int TrigSimTelType ); void FillPreThresholds( TGraph* gipr, float NNthresh[6] ); // defines pre-search thresholds for nn-groups (below this threshold group is not searched) - TGraphErrors* GetIPRGraph( unsigned int TrigSimTelType, float ScanWidow ); void SetNeighborRings( unsigned short* VALIDITYBOUNDBUF, float* TIMESReSearch, float* REFTHRESH ); diff --git a/inc/VImageCleaningRunParameter.h b/inc/VImageCleaningRunParameter.h index 438bdd8e0..324236fe1 100644 --- a/inc/VImageCleaningRunParameter.h +++ b/inc/VImageCleaningRunParameter.h @@ -58,7 +58,6 @@ class VImageCleaningRunParameter vector< string > fNNOpt_Multiplicities; unsigned int fNNOpt_nRings; float fNNOpt_CoincWinLimit; - bool fNNOpt_ifNNoptNoTimeing; bool fNNOpt_ifExplicitSampleTimeSlice; float fNNOpt_sampleTimeSlice; unsigned int fNNOpt_nBinsADC; diff --git a/inc/VImageParameterCalculation.h b/inc/VImageParameterCalculation.h index c3f9d0f7f..496eded3d 100644 --- a/inc/VImageParameterCalculation.h +++ b/inc/VImageParameterCalculation.h @@ -8,10 +8,10 @@ #include #include -#include -#include -#include -#include +#include "VDetectorGeometry.h" +#include "VEvndispData.h" +#include "VHoughTransform.h" +#include "VImageParameter.h" #include "TError.h" #include "TMath.h" diff --git a/inc/VInstrumentResponseFunctionRunParameter.h b/inc/VInstrumentResponseFunctionRunParameter.h index e3588ccfd..bb1fac76f 100644 --- a/inc/VInstrumentResponseFunctionRunParameter.h +++ b/inc/VInstrumentResponseFunctionRunParameter.h @@ -36,6 +36,7 @@ class VInstrumentResponseFunctionRunParameter : public TNamed string fCutFileName; string fInstrumentEpoch; + string fInstrumentEpochATM; vector< unsigned int > fTelToAnalyse; // telescopes used in analysis (optional, not always filled) int fGammaHadronCutSelector; int fDirectionCutSelector; @@ -100,12 +101,16 @@ class VInstrumentResponseFunctionRunParameter : public TNamed ~VInstrumentResponseFunctionRunParameter() {} string getInstrumentEpoch( bool iMajor = false ); + string getInstrumentATMString() + { + return fInstrumentEpochATM; + } void print(); VMonteCarloRunHeader* readMCRunHeader(); bool readRunParameterFromTextFile( string iFile ); bool testRunparameters(); - ClassDef( VInstrumentResponseFunctionRunParameter, 16 ); + ClassDef( VInstrumentResponseFunctionRunParameter, 17 ); }; #endif diff --git a/inc/VNoiseFileReader.h b/inc/VNoiseFileReader.h index 95005d68a..2e7d351c8 100644 --- a/inc/VNoiseFileReader.h +++ b/inc/VNoiseFileReader.h @@ -3,7 +3,7 @@ #ifndef VNoiseFileReader_H #define VNoiseFileReader_H -#include +#include "VGrIsuReader.h" #include #include diff --git a/inc/VPedestalCalculator.h b/inc/VPedestalCalculator.h index fa2876e72..d6fa2de99 100644 --- a/inc/VPedestalCalculator.h +++ b/inc/VPedestalCalculator.h @@ -3,10 +3,10 @@ #ifndef VPEDESTALCALCULATOR_H #define VPEDESTALCALCULATOR_H -#include -#include -#include -#include +#include "VImageBaseAnalyzer.h" +#include "VGlobalRunParameter.h" +#include "VSkyCoordinatesUtilities.h" +#include "VIPRCalculator.h" #include "TDirectory.h" #include "TFile.h" @@ -48,8 +48,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer vector< vector< vector< float > > > fpedcal_mean; vector< vector< vector< float > > > fpedcal_mean2; vector< vector< vector< TH1F* > > > fpedcal_histo; - std::vector > copy_fpedcal_histo; - + vector< vector< float > > v_temp_pedEntries; vector< vector< float > > v_temp_ped; vector< vector< float > > v_temp_pedvar; @@ -75,13 +74,11 @@ class VPedestalCalculator : public VImageBaseAnalyzer vector< vector< vector< vector< float > > > > v_pedvar; vector< vector< vector< vector< float > > > > v_ped_median; vector< vector< vector< vector< float > > > > v_pedvar68; - - vector< vector< vector< TH1F* > > > fpedcal_histo_sw; - + VPedestalCalculator(); ~VPedestalCalculator() {} - void doAnalysis( bool iLowGain = false , VIPRCalculator *fIPRCalculator = 0 ); + void doAnalysis( bool iLowGain = false ); vector< TTree* > getPedestalTree() { return fTree; diff --git a/inc/VPlotAnasumHistograms.h b/inc/VPlotAnasumHistograms.h index 3ed72ac27..a324d430f 100644 --- a/inc/VPlotAnasumHistograms.h +++ b/inc/VPlotAnasumHistograms.h @@ -100,7 +100,8 @@ class VPlotAnasumHistograms : public VAnalysisUtilities, public VPlotUtilities, void plot_deadTimes(); void plot_mscPlots( int irebin = 2, double xmin = -2., double xmax = 4., string mscwfile = "" ); void plot_qualityHistograms( double iSourceStrength = 1., bool bUpper = true, int iMethod = 0 ); - TCanvas* plot_theta2( double t2min = 0., double t2max = 0.3, int irbin = 5 ); + TCanvas* plot_theta2( double t2min = 0., double t2max = 0.3, int irbin = 5, + double setYMax = -9999., double setYMin = -9999. ); void plot_theta2Correction(); void plot_UncorrelatedSkyPlots(); void plot_CorrelatedSkyPlots(); @@ -143,7 +144,7 @@ class VPlotAnasumHistograms : public VAnalysisUtilities, public VPlotUtilities, } bool setRunNumber( int iRun ); // select run for plotting - ClassDef( VPlotAnasumHistograms, 15 ); + ClassDef( VPlotAnasumHistograms, 16 ); }; #endif diff --git a/inc/VPlotCompareDataWithMC.h b/inc/VPlotCompareDataWithMC.h index 4dd409b3a..f9ee22e0f 100644 --- a/inc/VPlotCompareDataWithMC.h +++ b/inc/VPlotCompareDataWithMC.h @@ -38,6 +38,7 @@ class VPlotCompareDataWithMC : public VHistogramUtilities double fRelatePlotRange_min; double fRelatePlotRange_max; + int fScalingMethod; void drawMatchingTests( TH1D* h1, TH1D* h2, double xmin = -9999., double xmax = 9999. ); TF1* do_theta2Fit( TH1D* h, int icolor = 1, int istyle = 1 ); @@ -62,7 +63,7 @@ class VPlotCompareDataWithMC : public VHistogramUtilities void help(); void centroids(); - TCanvas* core_plots( int iRebin = 1, int iScaling = 1 ); + TCanvas* core_plots( int iRebin = 1 ); TCanvas* distance_plots(); TCanvas* emission_height( double iEmissionHeightMax = 20. ); void erecRatio_vs_energy_plots( int iTelescope = 1, int iRebin = 1, double xmin = 0., double xmax = 2. ); @@ -88,7 +89,7 @@ class VPlotCompareDataWithMC : public VHistogramUtilities double iSystematicCutCheck = -99., string iXVariable = "Erec", double y_min = -99., bool iPlotLogY = false ); TCanvas* single_telescope( int telid = -1 ); - TCanvas* single_telescope( int telid, string iPlot, bool iOneCanvas = true, int iScalingMethod = 1, int i_rebin = 1 ); + TCanvas* single_telescope( int telid, string iPlot, bool iOneCanvas = true, int i_rebin = 1 ); TCanvas* stereo_parameter(); void mva_parameter(); @@ -113,6 +114,7 @@ class VPlotCompareDataWithMC : public VHistogramUtilities fRelatePlotRange_min = iMin; fRelatePlotRange_max = iMax; } + void setScalingMethod( int iScalingMethod = 1 ); }; #endif diff --git a/inc/VPlotTMVAParameters.h b/inc/VPlotTMVAParameters.h deleted file mode 100644 index 61d5b97f6..000000000 --- a/inc/VPlotTMVAParameters.h +++ /dev/null @@ -1,47 +0,0 @@ -//! VPlotTMVAParameters plot results from TMVA optimization - -#ifndef VPlotTMVAParameters_H -#define VPlotTMVAParameters_H - -#include -#include -#include -#include -#include - -#include "TCanvas.h" -#include "TH1D.h" - -#include "VTMVAEvaluator.h" - -using namespace std; - -class VPlotTMVAParameters -{ - private: - - vector< string > fSubArrays; - string fDataDirectory; - - vector< TH1D* > hSignalEfficiency; - vector< TH1D* > hBackgroundEfficiency; - vector< TH1D* > hMVA; - - bool initializeHistograms( unsigned int iEnergyWeightFileIndex_min, unsigned int iEnergyWeightFileIndex_max, unsigned int iZenithWeightFileIndex_min, unsigned int iZenithWeightFileIndex_max ); - - public: - VPlotTMVAParameters(); - ~VPlotTMVAParameters() {} - - void initializeWeightFiles( string iDirectory, string iTMVADirectory, unsigned int iEnergyWeightFileIndex_min, unsigned int iEnergyWeightFileIndex_max, unsigned int iZenithWeightFileIndex_min, unsigned int iZenithWeightFileIndex_max, double iParticleNumberFile_Conversion_Rate_to_seconds = 60. ); - void plot( bool iPrint = false ); - void setDirectories( string iDataDirectory ) - { - fDataDirectory = iDataDirectory; - } - bool setSubArrays( string iSubarrayFile ); -}; - - - -#endif diff --git a/inc/VPlotTMVAParametersLinkDef.h b/inc/VPlotTMVAParametersLinkDef.h deleted file mode 100644 index cbce04275..000000000 --- a/inc/VPlotTMVAParametersLinkDef.h +++ /dev/null @@ -1,3 +0,0 @@ -#ifdef __CINT__ -#pragma link C++ class VPlotTMVAParameters++; -#endif diff --git a/inc/VRawDataReader.h b/inc/VRawDataReader.h index 1f3b29c19..6f2b016e2 100644 --- a/inc/VRawDataReader.h +++ b/inc/VRawDataReader.h @@ -7,8 +7,8 @@ #include #include #include -#include -#include +#include "VVirtualDataReader.h" +#include "VSimulationDataReader.h" #include #include diff --git a/inc/VReadRunParameter.h b/inc/VReadRunParameter.h index d448f10f9..97bcd9d55 100644 --- a/inc/VReadRunParameter.h +++ b/inc/VReadRunParameter.h @@ -15,10 +15,10 @@ #include "TSystem.h" #include "TTree.h" -#include -#include -#include -#include +#include "VGlobalRunParameter.h" +#include "VDBRunInfo.h" +#include "VEvndispRunParameter.h" +#include "VUtilities.h" class VReadRunParameter { diff --git a/inc/VSensitivityCalculator.h b/inc/VSensitivityCalculator.h index e134ba029..aef602abb 100644 --- a/inc/VSensitivityCalculator.h +++ b/inc/VSensitivityCalculator.h @@ -227,6 +227,7 @@ class VSensitivityCalculator : public TObject, public VPlotUtilities, public VHi TGraphAsymmErrors* getSensitivityGraphFromWPPhysFile( string bUnit, double iEnergyMin_TeV_lin, double iEnergyMax_TeV_lin, double dE_Log10 ); + void list_sensitivity_table( unsigned int iD ); void plot_guidingLines( double x, TGraph* g, bool iHours ); void plotEffectiveArea(); void plotDebugPlotsBackgroundParticleNumbers( vector< VDifferentialFlux > iDifferentialFlux, @@ -261,7 +262,8 @@ class VSensitivityCalculator : public TObject, public VPlotUtilities, public VHi TGraph* getObservationTimevsFluxGraph( unsigned int ID = 0 ); unsigned int listDataSets(); void listUnits(); - void list_sensitivity( unsigned int iD = 0 ); + void list_sensitivity( unsigned int iD = 0, bool latex_table_line = false, string iTitle = "" ); + void list_sensitivity_latex_table( unsigned int iD, string iTitle, double iSignalE = -1., double iBackgroundE = -1. ); TCanvas* plotCanvas_SensitivityvsEnergy( string bUnit, bool bIntegralSensitivity, bool bNewCanvas = false ); TCanvas* plotObservationTimevsFlux( unsigned int iD = 0, TCanvas* c = 0, int iLineColor = 1, double iLineWidth = 4., bool bGuidingLines = true ); void plotObservationTimevsFluxFromTextFile( TCanvas* c, string iTextFile, int iLineColor = 4, double iLineWidth = 1., int iLineStyle = 2 ); @@ -358,6 +360,6 @@ class VSensitivityCalculator : public TObject, public VPlotUtilities, public VHi fDebugParticleNumberFile = iFile; } - ClassDef( VSensitivityCalculator, 25 ); + ClassDef( VSensitivityCalculator, 26 ); }; #endif diff --git a/inc/VSimulationDataReader.h b/inc/VSimulationDataReader.h index b58c7fd08..0c85f44ff 100644 --- a/inc/VSimulationDataReader.h +++ b/inc/VSimulationDataReader.h @@ -12,7 +12,7 @@ #include #include -#include +#include "VMonteCarloRunHeader.h" #include #include #include diff --git a/inc/VStereoAnalysis.h b/inc/VStereoAnalysis.h index e0c4eb3cd..fa979a103 100644 --- a/inc/VStereoAnalysis.h +++ b/inc/VStereoAnalysis.h @@ -220,7 +220,7 @@ class VStereoAnalysis CData* fDataRun; TTree* fDataRunTree; TFile* fDataFile; - string fInstrumentEpoch; + string fInstrumentEpochMinor; vector< unsigned int > fTelToAnalyze; vector< VSkyCoordinates* > fAstro; //!< Astronomical source parameters for this analysis diff --git a/inc/VTMVAEvaluator.h b/inc/VTMVAEvaluator.h index 216e9cea5..5fb0c29eb 100644 --- a/inc/VTMVAEvaluator.h +++ b/inc/VTMVAEvaluator.h @@ -41,15 +41,17 @@ class VTMVAEvaluatorData : public TNamed { public: - unsigned int fCounter; // needed??? + string fTMVAName; string fTMVAFileName; string fTMVAFileNameXML; string fTMVAMethodTag; string fTMVAMethodTag_2; + unsigned int fEnergyBin; double fEnergyCut_Log10TeV_min; double fEnergyCut_Log10TeV_max; double fSpectralWeightedMeanEnergy_Log10TeV; + unsigned int fZenithBin; double fZenithCut_min; double fZenithCut_max; @@ -58,8 +60,6 @@ class VTMVAEvaluatorData : public TNamed double fTMVACutValue; bool fTMVAOptimumCutValueFound; double fSourceStrengthAtOptimum_CU; - double fAngularContainmentRadius; - double fAngularContainmentFraction; TMVA::Reader* fTMVAReader; //! @@ -67,7 +67,7 @@ class VTMVAEvaluatorData : public TNamed ~VTMVAEvaluatorData() {} void print(); - ClassDef( VTMVAEvaluatorData, 1 ); + ClassDef( VTMVAEvaluatorData, 3 ); }; /////////////////////////////////////////////////////////////////////////////// @@ -114,17 +114,11 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities double fOptimizationMinBackGroundEvents; double fOptimizationBackgroundAlpha; double fOptimizationObservingTime_h; - double fTMVAAngularContainmentThetaFixedMinRadius; - bool fTMVAIgnoreTheta2Cut; // ignore theta2 cut in TMVA - bool fTMVAThetaCutVariableSet; // check if TMVA provides a theta2 cut variable double fTMVA_EvaluationResult; // result from TVMA evaluator - bool fTMVA_OptimizeAngularContainment; // optimize angular containment (using angular resolution vs containment histograms - bool fSmoothAndInterpolateMVAValues; string fTMVAMethodName; - double fTMVAngularContainmentRadiusMax; // maximum angular containment radius (optimization scales relative to this value) double fTMVAErrorFraction_min; // remove bins from background efficiency curves with large errors double fSpectralIndexForEnergyWeighting; // used to calculate the spectral weighted mean of an energy bin @@ -137,24 +131,25 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities float fMLR; float fEmissionHeight; float fEmissionHeightChi2_log10; - unsigned int fEnergyReconstructionMethod; float fEChi2S; float fEChi2S_log10; float fdES; float fSizeSecondMax_log10; - float fTheta2; float fCoreDist; float fImages_Ttype[VDST_MAXTELESCOPES]; float fDispDiff; + float fDispDiff_log10; float fDummy; bool bPlotEfficiencyPlotsPerBin; + bool fPrintPlotting; TH1F* getEfficiencyHistogram( string iName, TFile* iF, string iMethodTag_2 ); - double getMeanEnergyAfterCut( TFile* f, double iCut, unsigned int iDataBin ); bool optimizeSensitivity( unsigned int iDataBin ); TGraph* fillfromGraph2D( TObject* i_G, double i_ze_min, double i_ze_max ); void fillTMVAEvaluatorResults(); + string getBDTFileName( string iWeightFileName, + unsigned int i_E_index, unsigned int i_Z_index, string iSuffix = "" ); unsigned int getDataBin(); unsigned int getDataBin( double iErec_log10TeV, double iZe ); double getSignalEfficiency( unsigned int iEbin, double iE_min, double iE_max, unsigned int iZbin, double iZ_min, double iZ_max ); @@ -163,26 +158,24 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities double getValueFromMap( map< unsigned int, double > iDataMap, double iDefaultData, unsigned int iEnergyBin, double iE_min_log10, double iE_max_log10, unsigned int iZenithBin, double iZ_min, double iZ_max, string iVariable ); vector< string > getTrainingVariables( string iFile, vector< bool >& iSpectator ); - void getOptimalAngularContainmentRadius( double effS, double effB, double Ndif, double Nof, - TH2D* iHAngContainment, double iEnergy_log10_TeV, - double& i_Signal_to_sqrtNoise, double& i_AngularContainmentRadius, - double& i_AngularContainmentFraction ); void plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSignal_to_sqrtNoise, TGraph* iGSignal_to_sqrtNoise_Smooth, TH1F* hEffS, TH1F* hEffB, - TGraph* iGSignalEvents, TGraph* iGBackgroundEvents, - TGraph* iGOpt_AngularContainmentRadius, TGraph* iGOpt_AngularContainmentFraction ); + TGraph* iGSignalEvents, TGraph* iGBackgroundEvents ); TGraph* readNonNoffGraphsFromFile( TFile* iF, double i_ze_min, double i_ze_max, bool bIsOn = true ); void reset(); - void smoothAndInterPolateMVAValue( TH1F*, TH1F*, unsigned int iE_min, unsigned int iE_max, unsigned int iZ_min, unsigned int iZ_max ); - + void smoothAndInterPolateMVAValue( TH1F*, TH1F*, + unsigned int iE_min, unsigned int iE_max, unsigned int iZ_min, unsigned int iZ_max ); + void smoothAndInterPolateMVAValue_EnergyOnly( TH1F*, TH1F* ); + void smoothAndInterPolateMVAValue_Energy_and_Zenith( TH1F*, TH1F*, + unsigned int iE_min, unsigned int iE_max, unsigned int iZ_min, unsigned int iZ_max ); + public: VTMVAEvaluator(); ~VTMVAEvaluator() {}; bool evaluate(); - TGraph* getOptimalTheta2Cut_Graph(); vector< double > getBackgroundEfficiency(); vector< bool > getOptimumCutValueFound(); vector< double > getSignalEfficiency(); @@ -192,36 +185,28 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities { return fTMVAEvaluatorResults; } - bool getTMVAThetaCutVariable() - { - return fTMVAThetaCutVariableSet; - } double getTMVA_EvaluationResult() { return fTMVA_EvaluationResult; } bool initializeWeightFiles( string iWeightFileName, unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, - unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax, double iEnergyStepSize = 0.2, string iInstrumentEpoch = "noepoch" ); + unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ); bool initializeDataStrutures( CData* iC ); bool IsZombie() { return fIsZombie; } TGraphAsymmErrors* plotSignalAndBackgroundEfficiencies( bool iLogY = true, double iYmin = 1.e-4, double iMVA_min = -1., double iMVA_max = 1. ); - void printAngularContainmentRadius(); + void printOptimizedMVACutValues( string iEpoch = "V6" ); void printSensitivityOptimizationParameters(); void printSignalEfficiency(); - void printSourceStrength_CU(); void setDebug( bool iB = false ) { fDebug = iB; } - void setIgnoreTheta2Cut( bool iB = false ) - { - fTMVAIgnoreTheta2Cut = iB; - } - void setSensitivityOptimizationParameters( double iSignificance = 5., double iMinEvents = 10., double iObservationTime_h = 50., - double iMinBackgroundRateRatio = 1. / 5, double iMinBackgroundEvents = 0. ) + void setSensitivityOptimizationParameters( + double iSignificance = 5., double iMinEvents = 10., double iObservationTime_h = 50., + double iMinBackgroundRateRatio = 1. / 5, double iMinBackgroundEvents = 0. ) { fOptimizationSourceSignificance = iSignificance; fOptimizationMinSignalEvents = iMinEvents; @@ -232,10 +217,6 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities void setSensitivityOptimizationFixedSignalEfficiency( double iOptimizationFixedSignalEfficiency = 1. ); void setSensitivityOptimizationMinSourceStrength( double iOptimizationMinSourceStrength = 0.001 ); - void setOptimizeAngularContainment( bool iO = true ) - { - fTMVA_OptimizeAngularContainment = iO; - } void setParticleNumberFile( string iParticleNumberFile = "", double iConversionFactor_to_seconds = 60. ) { fParticleNumberFileName = iParticleNumberFile; @@ -245,6 +226,10 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities { bPlotEfficiencyPlotsPerBin = iB; } + void setPrintPlotting( bool iPrintPlotting = false ) + { + fPrintPlotting = iPrintPlotting; + } void setSignalEfficiency( double iSignalEfficiency = -99. ); void setSignalEfficiency( map< unsigned int, double > iMSignalEfficiency ); void setSmoothAndInterPolateMVAValues( bool iS = true ) @@ -255,27 +240,15 @@ class VTMVAEvaluator : public TNamed, public VPlotUtilities { fSpectralIndexForEnergyWeighting = iS; } - void setTMVAAngularContainmentThetaFixedMinRadius( double iR = 0. ) - { - fTMVAAngularContainmentThetaFixedMinRadius = iR; - } - void setTMVAAngularContainmentRadiusMax( double iC = 0.68 ) - { - fTMVAngularContainmentRadiusMax = iC; - } void setTMVACutValue( double iE = -99. ); void setTMVACutValue( map< unsigned int, double > iMVA ); void setTMVAErrorFraction( double iTMVAErrorFraction_min = 0.2 ) { fTMVAErrorFraction_min = iTMVAErrorFraction_min; } - void setTMVAThetaCutVariable( bool iB = false ) - { - fTMVAThetaCutVariableSet = iB; - } void setTMVAMethod( string iMethodName = "BDT" ); - ClassDef( VTMVAEvaluator, 31 ); + ClassDef( VTMVAEvaluator, 33 ); }; #endif diff --git a/inc/VTMVARunData.h b/inc/VTMVARunData.h index 2c454ab7b..a5796b001 100644 --- a/inc/VTMVARunData.h +++ b/inc/VTMVARunData.h @@ -15,10 +15,12 @@ #include #include #include +#include #include #include #include +#include "VTableLookupRunParameter.h" #include "VTMVARunDataEnergyCut.h" #include "VTMVARunDataZenithCut.h" #include "VUtilities.h" @@ -34,9 +36,14 @@ class VTMVARunData : public TNamed bool fDebug; + bool fillEnergyCutData( + vector< double > iEnergyCut_Log10TeV_min, vector< double > iEnergyCut_Log10TeV_max ); + unsigned int getTrainOptionValue( string iVarName, unsigned int i_default ); + public: string fName; + string fRunOption; // run type bool fTrainGammaHadronSeparation; @@ -46,9 +53,7 @@ class VTMVARunData : public TNamed string fOutputFileName; string fOutputDirectoryName; vector< vector< TFile* > > fOutputFile; - - // training options - bool fCheckValidityOfInputVariables; + string fSelectedEventFileName; // training data double fSignalWeight; @@ -57,6 +62,8 @@ class VTMVARunData : public TNamed double fBackgroundWeight; vector< string > fBackgroundFileName; vector< TChain* > fBackgroundTree; + unsigned int fnTrain_Signal; + unsigned int fnTrain_Background; // list of training variables vector< string > fTrainingVariable; @@ -93,6 +100,7 @@ class VTMVARunData : public TNamed VTMVARunData(); ~VTMVARunData() {} void print(); + VTableLookupRunParameter* getTLRunParameter(); bool readConfigurationFile( char* ); bool openDataFiles(); void setDebug( bool iB = true ) @@ -103,8 +111,10 @@ class VTMVARunData : public TNamed { fName = iN; } + void shuffleFileVectors(); + void updateTrainingEvents( string iVarName, unsigned int iNEvents ); - ClassDef( VTMVARunData, 9 ); + ClassDef( VTMVARunData, 11 ); }; #endif diff --git a/inc/VVirtualDataReader.h b/inc/VVirtualDataReader.h index 382ef01e9..2541c03d1 100644 --- a/inc/VVirtualDataReader.h +++ b/inc/VVirtualDataReader.h @@ -8,7 +8,7 @@ #include #include #else -#include +#include "VDummyArrayTrigger.h" #endif #include diff --git a/src/VAnaSum.cpp b/src/VAnaSum.cpp index 61b9e5723..0ed7dfbe5 100644 --- a/src/VAnaSum.cpp +++ b/src/VAnaSum.cpp @@ -32,7 +32,14 @@ VAnaSum::VAnaSum( string i_datadir, unsigned int iAnalysisType ) check run mode */ -void VAnaSum::initialize( string i_LongListFilename, string i_ShortListFilename, int i_singletel, unsigned int iRunType, string i_outfile, int iRandomSeed, string iRunParameterfile ) +void VAnaSum::initialize( + string i_LongListFilename, + string i_ShortListFilename, + int i_singletel, + unsigned int iRunType, + string i_outfile, + int iRandomSeed, + string iRunParameterfile ) { char i_temp[2000]; char i_title[200]; diff --git a/src/VAnaSumRunParameter.cpp b/src/VAnaSumRunParameter.cpp index dec67cefd..48cd4988e 100644 --- a/src/VAnaSumRunParameter.cpp +++ b/src/VAnaSumRunParameter.cpp @@ -730,7 +730,7 @@ int VAnaSumRunParameter::loadShortFileList( string i_listfilename, string iDataD { cout << " VAnaSumRunParameter::loadShortFileList error: file with list of runs not found : " << i_listfilename << endl; cout << "exiting..." << endl; - exit( -1 ); + exit( EXIT_FAILURE ); } string is_line; string temp; @@ -745,84 +745,87 @@ int VAnaSumRunParameter::loadShortFileList( string i_listfilename, string iDataD { istringstream is_stream( is_line ); is_stream >> temp; - cout << "RUN NUMBER " << temp << endl; i_sT.fRunOn = atoi( temp.c_str() ); i_sT.fRunOff = atoi( temp.c_str() ); - // open mscw file and read out telescope participating in analysis - temp = iDataDir + "/" + temp + ".mscw.root"; - TFile iF( temp.c_str(), "READ" ); - if( iF.IsZombie() ) - { - cout << "VAnaSumRunParameter::loadShortFileList: error, data file not found: "; - cout << temp << endl; - exit( -1 ); - } - VEvndispRunParameter* iPar = ( VEvndispRunParameter* )iF.Get( "runparameterV2" ); - if( !iPar ) + if( !bTotalAnalysisOnly ) { - cout << "VAnaSumRunParameter::loadShortFileList: error, no run parameters found in: "; - cout << temp << endl; - exit( -1 ); - } - char hTelToAna[200]; - for( unsigned int i = 0; i < iPar->fTelToAnalyze.size(); i++ ) - { - if( i == 0 ) + // open mscw file and read out telescope participating in analysis + temp = iDataDir + "/" + temp + ".mscw.root"; + TFile iF( temp.c_str(), "READ" ); + if( iF.IsZombie() ) + { + cout << "VAnaSumRunParameter::loadShortFileList: error, data file not found: "; + cout << temp << endl; + exit( EXIT_FAILURE ); + } + VEvndispRunParameter* iPar = ( VEvndispRunParameter* )iF.Get( "runparameterV2" ); + if( !iPar ) + { + cout << "VAnaSumRunParameter::loadShortFileList: error, no run parameters found in: "; + cout << temp << endl; + exit( EXIT_FAILURE ); + } + char hTelToAna[200]; + for( unsigned int i = 0; i < iPar->fTelToAnalyze.size(); i++ ) + { + if( i == 0 ) + { + sprintf( hTelToAna, "%d", iPar->fTelToAnalyze[i] + 1 ); + } + else + { + string tmp_str = hTelToAna; + sprintf( hTelToAna, "%s%d", tmp_str.c_str(), iPar->fTelToAnalyze[i] + 1 ); + } + } + iF.Close(); + i_sT.fTelToAna = hTelToAna; + i_sT.fCutFile = fTMPL_CutFile; + i_sT.fSourceRadius = fTMPL_SourceRadius; + i_sT.fBackgroundModel = fTMPL_fBackgroundModel; + i_sT.fmaxradius = fTMPL_maxradius; + i_sT.fEffectiveAreaFile = fTMPL_EffectiveAreaFile; + if( i_sT.fTelToAna == "1234" ) { - sprintf( hTelToAna, "%d", iPar->fTelToAnalyze[i] + 1 ); + i_sT.fEffectiveAreaFile += ".root"; } else { - string tmp_str = hTelToAna; - sprintf( hTelToAna, "%s%d", tmp_str.c_str(), iPar->fTelToAnalyze[i] + 1 ); + i_sT.fEffectiveAreaFile += "_T" + i_sT.fTelToAna + ".root"; } - } - iF.Close(); - i_sT.fTelToAna = hTelToAna; - i_sT.fCutFile = fTMPL_CutFile; - i_sT.fSourceRadius = fTMPL_SourceRadius; - i_sT.fBackgroundModel = fTMPL_fBackgroundModel; - i_sT.fmaxradius = fTMPL_maxradius; - i_sT.fEffectiveAreaFile = fTMPL_EffectiveAreaFile; - if( i_sT.fTelToAna == "1234" ) - { - i_sT.fEffectiveAreaFile += ".root"; - } - else - { - i_sT.fEffectiveAreaFile += "_T" + i_sT.fTelToAna + ".root"; - } - i_sT.fAcceptanceFile = fTMPL_AcceptanceFile; - if( i_sT.fTelToAna == "1234" ) - { - i_sT.fAcceptanceFile += ".root"; - } - else - { - i_sT.fAcceptanceFile += "_T" + i_sT.fTelToAna + ".root"; - } - if( i_sT.fBackgroundModel == eRINGMODEL ) - { - i_sT.fRM_RingRadius = fTMPL_RM_RingRadius; - i_sT.fRM_RingWidth = fTMPL_RM_RingWidth; - } - else if( i_sT.fBackgroundModel == eREFLECTEDREGION ) - { - i_sT.fRE_distanceSourceOff = fTMPL_RE_distanceSourceOff; - i_sT.fRE_nMinoffsource = fTMPL_RE_nMinoffsource; - i_sT.fRE_nMaxoffsource = fTMPL_RE_nMaxoffsource; - } - else - { - cout << "VAnaSumRunParameter error: "; - cout << " unknown background model " << i_sT.fBackgroundModel << endl; - cout << "\t or" << endl; - cout << "VAnaSumRunParameter warning: "; - cout << " short runlist not implemented yet for this background model " << i_sT.fBackgroundModel << endl; + i_sT.fAcceptanceFile = fTMPL_AcceptanceFile; + if( i_sT.fTelToAna == "1234" ) + { + i_sT.fAcceptanceFile += ".root"; + } + else + { + i_sT.fAcceptanceFile += "_T" + i_sT.fTelToAna + ".root"; + } + if( i_sT.fBackgroundModel == eRINGMODEL ) + { + i_sT.fRM_RingRadius = fTMPL_RM_RingRadius; + i_sT.fRM_RingWidth = fTMPL_RM_RingWidth; + } + else if( i_sT.fBackgroundModel == eREFLECTEDREGION ) + { + i_sT.fRE_distanceSourceOff = fTMPL_RE_distanceSourceOff; + i_sT.fRE_nMinoffsource = fTMPL_RE_nMinoffsource; + i_sT.fRE_nMaxoffsource = fTMPL_RE_nMaxoffsource; + } + else + { + cout << "VAnaSumRunParameter error: "; + cout << " unknown background model " << i_sT.fBackgroundModel << endl; + cout << "\t or" << endl; + cout << "VAnaSumRunParameter warning: "; + cout << " short runlist not implemented yet for this background model " << i_sT.fBackgroundModel << endl; + } + + i_sT.f2DAcceptanceMode = f2DAcceptanceMode ; // USE2DACCEPTANCE } // fill the runlist vector - i_sT.f2DAcceptanceMode = f2DAcceptanceMode ; // USE2DACCEPTANCE fRunList.push_back( i_sT ); // fill the runlist map fMapRunList[i_sT.fRunOn] = fRunList.back(); @@ -1015,7 +1018,7 @@ int VAnaSumRunParameter::loadLongFileList( string i_listfilename, bool bShortLis cout << "VAnaSumRunParameter::loadLongFileList: error in run list: " << endl; cout << is_line << endl; cout << "invalid maximum distance " << i_sT.fmaxradius << endl; - exit( -1 ); + exit( EXIT_FAILURE ); } } // file for effective areas @@ -1024,27 +1027,35 @@ int VAnaSumRunParameter::loadLongFileList( string i_listfilename, bool bShortLis // cuts are in the effective area files if( fVersion >= 7 ) { - // check if IRF runparameters are consistent with ANASUM.runparameter file - checkAnasumParameter( i_sT.fEffectiveAreaFile ); - - i_sT.fCutFile = temp; - // source radius (actually (source radius)^2 ) - // (read theta2 cut from cut file) - if( !bTotalAnalysisOnly ) + if( i_sT.fEffectiveAreaFile.find( "IGNOREEFFECTIVEAREA" ) != string::npos ) { - readCutParameter( i_sT.fCutFile, i_sT.fSourceRadius, i_sT.fmaxradius ); + cout << "VAnaSumRunParameter::loadLongFileList warning: "; + cout << "ignore effective areas - cannot read cuts from effective area files" << endl; } else { - i_sT.fSourceRadius = 0.1; - i_sT.fmaxradius = 2.0; - } - if( i_sT.fSourceRadius <= 0. ) - { - cout << "VAnaSumRunParameter::loadLongFileList: error in run list: " << endl; - cout << is_line << endl; - cout << "invalid source radius " << i_sT.fSourceRadius << endl; - exit( -1 ); + // check if IRF runparameters are consistent with ANASUM.runparameter file + checkAnasumParameter( i_sT.fEffectiveAreaFile ); + + i_sT.fCutFile = temp; + // source radius (actually (source radius)^2 ) + // (read theta2 cut from cut file) + if( !bTotalAnalysisOnly ) + { + readCutParameter( i_sT.fCutFile, i_sT.fSourceRadius, i_sT.fmaxradius ); + } + else + { + i_sT.fSourceRadius = 0.1; + i_sT.fmaxradius = 2.0; + } + if( i_sT.fSourceRadius <= 0. ) + { + cout << "VAnaSumRunParameter::loadLongFileList: error in run list: " << endl; + cout << is_line << endl; + cout << "invalid source radius " << i_sT.fSourceRadius << endl; + exit( EXIT_FAILURE ); + } } } // background model dependend parameters @@ -1088,7 +1099,7 @@ int VAnaSumRunParameter::loadLongFileList( string i_listfilename, bool bShortLis is_stream >> temp; i_sT.fTE_mscl_max = atof( temp.c_str() ); cout << "DO NOT USE " << endl; - exit( 0 ); + exit( EXIT_SUCCESS ); } else if( i_sT.fBackgroundModel == eONOFF ) { diff --git a/src/VCalibrationData.cpp b/src/VCalibrationData.cpp index e10762d31..81443fd72 100644 --- a/src/VCalibrationData.cpp +++ b/src/VCalibrationData.cpp @@ -802,7 +802,7 @@ valarray& VCalibrationData::getPedvars( bool iLowGain, unsigned int iSW, cout << getPedvarsVTS_vector( iLowGain )[0].size(); } cout << endl; - exit( 0 ); + exit( EXIT_FAILURE ); } } ////////////////////////////////////////////////////////// diff --git a/src/VCalibrator.cpp b/src/VCalibrator.cpp index b4ba1f216..bcd71df02 100644 --- a/src/VCalibrator.cpp +++ b/src/VCalibrator.cpp @@ -17,6 +17,7 @@ VCalibrator::VCalibrator() fPedSingleOutFile = 0; fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements + fIPRAverageTel = false; } /* @@ -358,7 +359,9 @@ void VCalibrator::calculatePedestals( bool iLowGain ) this might be an ascii file and/or a root file */ -void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile, VIPRCalculator *fIPRCalculator ) +//MK test +void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile ) +//void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile, VIPRCalculator *fIPRCalculator ) { if( getDebugFlag() ) { @@ -506,18 +509,6 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul } } } - for (unsigned int ts = 0; ts < (fIPRCalculator->getStorageHist())[tel].size(); ts++){ - for (unsigned int p = 0; p < getNChannels(); p++){ - for(unsigned int sw = 0; sw < (fIPRCalculator->getStorageHist())[tel][ts][p].size(); sw++) - { - if (fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw) ){ - fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetName(Form( "hped_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw ) ); - fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetTitle( Form("hped_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw ) ); - fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->Write(); - } - } - } - } } iFileWritten[telType] = true; } @@ -557,8 +548,6 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul /////////////////////////////////////////////////////////////////// // calculate IPR graphs already at this point and write them to // the dst calibration file - // MK: adapt later - /* if( getRunParameter()->fCombineChannelsForPedestalCalculation && getRunParameter()->fPedestalSingleRootFile ) { @@ -591,14 +580,14 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul { // summation window int i_sw = j + 1; - cout << "I am actually calculating this IPR" << endl; + calculateIPRGraphs( fPedSingleOutFile->GetName(), i_sw, iTelType, i ); iTelDone[getTelType( i )] = true; } } } writeIPRgraphs( fPedSingleOutFile->GetName() ); - }*/ + } } @@ -1601,13 +1590,14 @@ void VCalibrator::writeTOffsets( bool iLowGain ) } } - -void VCalibrator::terminate( VPedestalCalculator* iP, VIPRCalculator *fIPRCalculator ) +//MK test +//void VCalibrator::terminate( VPedestalCalculator* iP, VIPRCalculator *fIPRCalculator ) +void VCalibrator::terminate( VPedestalCalculator* iP ) { - if( fRunPar->frunmode == 1 || fRunPar->frunmode == 6 ) { - writePeds( fRunPar->frunmode == 6, iP, !fRunPar->fPedestalSingleRootFile, fIPRCalculator ); + writePeds( fRunPar->frunmode == 6, iP, !fRunPar->fPedestalSingleRootFile ); + //writePeds( fRunPar->frunmode == 6, iP, !fRunPar->fPedestalSingleRootFile, fIPRCalculator ); } else if( fRunPar->frunmode == 2 || fRunPar->frunmode == 5 ) { @@ -1618,7 +1608,6 @@ void VCalibrator::terminate( VPedestalCalculator* iP, VIPRCalculator *fIPRCalcul { writeAverageTZeros( fRunPar->frunmode == 8 ); } - } @@ -1654,9 +1643,6 @@ void VCalibrator::readCalibrationData() getGains( true ) = getGains( false ); } } - else{ - - } // read average tzeros if( getRunParameter()->frunmode != 2 && getRunParameter()->frunmode != 5 @@ -3108,7 +3094,7 @@ void VCalibrator::readTOffsets( bool iLowGain ) } - +//MK test void VCalibrator::initialize(VIPRCalculator *fIPRCalculator ) { if( fDebug ) @@ -3219,8 +3205,6 @@ void VCalibrator::initialize(VIPRCalculator *fIPRCalculator ) { readCalibrationData(); } - else{ - } } // PE mode: set gains to 1 else @@ -3233,16 +3217,17 @@ void VCalibrator::initialize(VIPRCalculator *fIPRCalculator ) readGains( true ); } // read peds from DST file (for DST MC source file) - // MK take a look later - /*if( fRunPar->frunmode != 1 && ( fRunPar->fsourcetype == 7 || fRunPar->fsourcetype == 4 ) ) + if( fRunPar->frunmode != 1 && ( fRunPar->fsourcetype == 7 || fRunPar->fsourcetype == 4 ) ) { - readCalibrationDatafromDSTFiles( fRunPar->fsourcefile, fIPRCalculator ); - }*/ + readCalibrationDatafromDSTFiles( fRunPar->fsourcefile ); + } } // if needed: write IPR graphs to disk if( getRunParameter()->ifCreateIPRdatabase == true && getRunParameter()->ifReadIPRfromDatabase == false ) { - fIPRCalculator->writeIPRgraphs( hped_vec, ""); + //MK test + //fIPRCalculator->writeIPRgraphs( hped_vec, ""); + writeIPRgraphs(); } // initialize dead channel finder @@ -3259,19 +3244,13 @@ void VCalibrator::initialize(VIPRCalculator *fIPRCalculator ) && fRunPar->frunmode != 6 ) { cout << "MK calculating IPR graphs"<< endl; + //calculateIPRGraphs(); fIPRCalculator->calculateIPRGraphs(fPedFileNameC); + //calculateIPRGraphs(); } } } - -//void VCalibrator::calculateIPRGraphs(VIPRCalculator *fIPRCalculator, VPedestalCalculator *iP ) -//{ -// cout << "MK calculating IPR" << endl; -// fIPRCalculator->calculateIPRGraphs(fPedFileNameC, iP->getPedestalIPRHist()); -//} - - void VCalibrator::setCalibrationFileNames() { if( fDebug ) @@ -4009,49 +3988,559 @@ bool VCalibrator::readLowGainMultiplier( ) return true; } -unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( int iTelID, int iType ) + +/* + + read calibration data from DST file + +*/ +bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) { - if( iType == 1 || iType == 6 ) - { - return getNumberOfEventsUsedInCalibration( fNumberPedestalEvents, iTelID ); - } - else if( iType == 2 || iType == 5 ) - { - return getNumberOfEventsUsedInCalibration( fNumberGainEvents, iTelID ); - } - else if( iType == 7 || iType == 8 ) - { - return getNumberOfEventsUsedInCalibration( fNumberTZeroEvents, iTelID ); - } - return 0; + if( iDSTfile.size() == 0 ) + { + cout << "VCalibrator::readCalibrationDatafromDSTFiles: no DST file given" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + + TFile iF( iDSTfile.c_str() ); + if( iF.IsZombie() ) + { + cout << "VCalibrator::readCalibrationDatafromDSTFiles error while opening DST tree in " << iDSTfile << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + TTree* t = ( TTree* )iF.Get( "calibration" ); + if( !t ) + { + cout << "VCalibrator::readCalibrationDatafromDSTFiles warning: failed reading calibration tree from file " << iDSTfile << endl; + return false; + } + cout << "reading calibration data from dst file" << endl; + + int fTelID = 0; + unsigned int nPixel = 0; + unsigned int fnum_sumwindow = 1; + unsigned int fsumwindow[VDST_MAXSUMWINDOW]; + float fPed_high[VDST_MAXCHANNELS]; + float* fPedvar_high = new float[VDST_MAXCHANNELS * VDST_MAXSUMWINDOW]; + float fPed_low[VDST_MAXCHANNELS]; + float* fPedvar_low = new float[VDST_MAXCHANNELS * VDST_MAXSUMWINDOW]; + float fConv_high[VDST_MAXCHANNELS]; + float fConv_low[VDST_MAXCHANNELS]; + float ftzero[VDST_MAXCHANNELS]; + + for( unsigned int i = 0; i < VDST_MAXCHANNELS; i++ ) + { + ftzero[i] = -99.; + } + + t->SetBranchAddress( "TelID", &fTelID ); + t->SetBranchAddress( "NPixel", &nPixel ); + t->SetBranchAddress( "num_sumwindow", &fnum_sumwindow ); + t->SetBranchAddress( "sumwindow", fsumwindow ); + t->SetBranchAddress( "ped_high", fPed_high ); + // check if this is a old or new style pedvar tree + bool iPedVarTreeTypeNew = true; + if( t->GetLeaf( "pedvar_high" ) ) + { + string i_temp = ( string )t->GetLeaf( "pedvar_high" )->GetTitle(); + if( i_temp.find_first_of( "[" ) == i_temp.find_last_of( "[" ) ) + { + iPedVarTreeTypeNew = true; + } + else + { + iPedVarTreeTypeNew = false; + } + } + if( !iPedVarTreeTypeNew ) + { + cout << "VCalibrator::readCalibrationDatafromDSTFiles: old style DST file: warning: pedvars will not be set correctly" << endl; + cout << " (you might be able to proceed if you don't do FADC trace analysis and use the pedvars for the image cleaning" << endl; + } + t->SetBranchAddress( "pedvar_high", fPedvar_high ); + t->SetBranchAddress( "ped_low", fPed_low ); + t->SetBranchAddress( "pedvar_low", fPedvar_low ); + t->SetBranchAddress( "conv_high", fConv_high ); + t->SetBranchAddress( "conv_low", fConv_low ); + if( t->GetBranch( "tzero" ) ) + { + t->SetBranchAddress( "tzero", ftzero ); + } + + // reset histograms with pedestal distributions + if( getPedvarsDist() ) + { + getPedvarsDist()->Reset(); + } + if( getPedDist() ) + { + getPedDist()->Reset(); + } + if( getPedvarsLowGainDist() ) + { + getPedvarsLowGainDist()->Reset(); + } + if( getPedLowGainDist() ) + { + getPedLowGainDist()->Reset(); + } + + // histogram for average tzero calculation (per telescope type) + vector iTelType = getDetectorGeometry()->getTelType_list(); + vector< TH1D* > iH_averageTZero; + char hname[200]; + for( unsigned int i = 0; i < iTelType.size(); i++ ) + { + sprintf( hname, "iH_averageTZero_%d", i ); + iH_averageTZero.push_back( new TH1D( hname, "", 3 * ( int )getNSamples(), 0., ( float )getNSamples() ) ); + } + + if( getNTel() != ( unsigned int )t->GetEntries() ) + { + cout << "VCalibrator::readCalibrationDatafromDSTFiles error: mismatch in number of telescopes: " << endl; + cout << "\t expected: " << getNTel() << endl; + cout << "\t found: " << t->GetEntries() << endl; + exit( EXIT_FAILURE ); + } + // loop over all telescopes + for( int i = 0; i < t->GetEntries(); i++ ) + { + t->GetEntry( i ); + + setTelID( i ); + + // no calibration data available for this telescope + if( nPixel == 0 ) + { + continue; + } + + // pedestals + if( nPixel == getPeds( false ).size() ) + { + for( unsigned int p = 0; p < nPixel; p++ ) + { + getPeds( false )[p] = fPed_high[p]; + if( getPedDist() ) + { + getPedDist()->Fill( fPed_high[p] ); + } + } + } + else + { + cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile )"; + cout << " error: index out of range (peds, high gain): "; + cout << nPixel << "\t" << getPeds( false ).size(); + cout << " (telescope " << getTelID() + 1 << ")" << endl; + } + if( nPixel == getPeds( true ).size() ) + { + for( unsigned int p = 0; p < nPixel; p++ ) + { + getPeds( true )[p] = fPed_low[p]; + if( getPedLowGainDist() ) + { + getPedLowGainDist()->Fill( fPed_low[p] ); + } + } + } + else + { + cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile )"; + cout << "error: index out of range (peds, low gain): "; + cout << nPixel << "\t" << getPeds( true ).size(); + cout << " (telescope " << getTelID() + 1 << ")" << endl; + } + // pedvars + if( nPixel == getPedvars( false ).size() ) + { + for( unsigned int p = 0; p < nPixel; p++ ) + { + if( p < getPedvars( false ).size() ) + { + for( unsigned int s = 0; s < fnum_sumwindow; s++ ) + { + if( iPedVarTreeTypeNew ) + { + getPedvars( false, fsumwindow[s] )[p] = fPedvar_high[p * VDST_MAXSUMWINDOW + s]; + if( fsumwindow[s] == 1 ) + { + getPedrms( false ) = fPedvar_high[p * VDST_MAXSUMWINDOW + s]; + } + } + if( fsumwindow[s] == getSumWindow() && getPedvarsDist() ) + { + if( iPedVarTreeTypeNew ) + { + getPedvarsDist()->Fill( fPedvar_high[p * VDST_MAXSUMWINDOW + s] ); + } + } + } + } + } + } + else + { + cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; + cout << "index out of range (pedvars, high gain): "; + cout << nPixel << "\t" << getPedvars( false ).size(); + cout << " (telescope " << getTelID() + 1 << ")" << endl; + } + if( nPixel == getPedvars( true ).size() ) + { + for( unsigned int p = 0; p < nPixel; p++ ) + { + if( p < getPedvars( true ).size() ) + { + for( unsigned int s = 0; s < fnum_sumwindow; s++ ) + { + if( iPedVarTreeTypeNew ) + { + getPedvars( true, fsumwindow[s] )[p] = fPedvar_low[p * VDST_MAXSUMWINDOW + s]; + if( fsumwindow[s] == 1 ) + { + getPedrms( true ) = fPedvar_low[p * VDST_MAXSUMWINDOW + s]; + } + } + if( fsumwindow[s] == getSumWindow() && getPedvarsDist( true ) ) + { + if( iPedVarTreeTypeNew ) + { + getPedvarsDist( true )->Fill( fPedvar_low[p * VDST_MAXSUMWINDOW + s] ); + } + } + } + } + } + } + else + { + cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; + cout << "index out of range (pedvars, low gain): "; + cout << nPixel << "\t" << getPedvars( true ).size(); + cout << " (telescope " << getTelID() + 1 << ")" << endl; + } + //////////////// + // relative gains + if( nPixel == getGains( false ).size() ) + { + // mean conversion factor + float i_z = 0; + float i_meanC = 0; + for( unsigned int p = 0; p < nPixel; p++ ) + { + if( fConv_high[p] > 0. ) + { + i_z++; + i_meanC += fConv_high[p]; + } + } + if( i_z > 0. && i_meanC > 0. ) + { + i_meanC /= i_z; + } + else + { + i_meanC = 1.; + } + // calculate relative gain + for( unsigned int p = 0; p < nPixel; p++ ) + { + if( fConv_high[p] > 0. && !getRunParameter()->fIgnoreDSTGains ) + { + getGains( false )[p] = 1. / fConv_high[p]; + if( getGainDist( false ) ) + { + getGainDist( false )->Fill( i_meanC / fConv_high[p] ); + } + } + else + { + getGains( false )[p] = 1.; + } + } + } + else + { + cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; + cout << "index out of range (gains, high gain): "; + cout << nPixel << "\t" << getGains( false ).size(); + cout << " (telescope " << getTelID() + 1 << ")" << endl; + } + if( nPixel == getGains( true ).size() ) + { + // use high-gain conversion and understand differences between low and high gain as multiplication factor + for( unsigned int p = 0; p < nPixel; p++ ) + { + if( getGains( false )[p] > 0. && !getRunParameter()->fIgnoreDSTGains ) + { + getGains( true )[p] = getGains( false )[p]; + if( getGainDist( true ) ) + { + getGainDist( true )->Fill( getGains( true )[p] ); + } + setLowGainMultiplier_Trace( fConv_low[p] / fConv_high[p] ); //assumes fConv_low / fConv_high is the same for all pixels. Ok as long as we don't have low gain in cta. + } + else + { + getGains( true )[p] = 1.; + } + } + } + else + { + cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; + cout << "index out of range (gains, low gain): "; + cout << nPixel << "\t" << getGains( true ).size(); + cout << " (telescope " << getTelID() + 1 << ")" << endl; + } + //////////////// + // tzeros + if( nPixel == getAverageTZeros( false ).size() ) + { + double i_mean = 0.; + double i_nn = 0.; + // get teltype counter + unsigned int iTelTypeC = 0; + for( unsigned int t = 0; t < iTelType.size(); t++ ) + { + if( iTelType[t] == getDetectorGeometry()->getTelType()[i] ) + { + iTelTypeC = t; + break; + } + } + for( unsigned int p = 0; p < nPixel; p++ ) + { + getAverageTZeros( false )[p] = ftzero[p]; + // check if this pixel is inside the averateTZeroFiducialRadius + if( getRunParameter()->faverageTZeroFiducialRadius < 1. ) + { + double d = getDetectorGeometry()->getOuterEdgeDistance( p ); + if( d > 0.5 * getDetectorGeometry()->getFieldofView()[i] * getRunParameter()->faverageTZeroFiducialRadius ) + { + continue; + } + } + if( getAverageTZeros( false )[p] > -98. ) + { + i_mean += ftzero[p]; + i_nn++; + setAverageTZero( p, ftzero[p], false ); + if( iTelTypeC < iH_averageTZero.size() && iH_averageTZero[iTelTypeC] ) + { + iH_averageTZero[iTelTypeC]->Fill( ftzero[p] ); + } + } + } + } + else + { + cout << "bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) error: "; + cout << " index out of range (tzero, high gain): "; + cout << nPixel << "\t" << getAverageTZeros( false ).size(); + cout << " (telescope " << getTelID() + 1 << ")" << endl; + } + } + + //////////////////////////////////////////////////////////////////////////// + // get average tzero per telescope type + // use median, as outliers are expected + cout << "\t calculate average tzeros" << endl; + for( int i = 0; i < t->GetEntries(); i++ ) + { + t->GetEntry( i ); + + setTelID( i ); + + // no calibration data available for this telescope + if( nPixel == 0 ) + { + continue; + } + // get teltype counter + unsigned int iTelTypeC = 0; + for( unsigned int t = 0; t < iTelType.size(); t++ ) + { + if( iTelType[t] == getDetectorGeometry()->getTelType()[i] ) + { + iTelTypeC = t; + break; + } + } + if( iTelTypeC < iH_averageTZero.size() && iH_averageTZero[iTelTypeC] ) + { + if( iH_averageTZero[iTelTypeC]->GetEntries() > 0. ) + { + double i_a[] = { 0.5 }; + double i_b[] = { 0.0 }; + iH_averageTZero[iTelTypeC]->GetQuantiles( 1, i_b, i_a ); + setMeanAverageTZero( i_b[0], false ); + } + } + } + + //////////////////////////////////////////////////////////////////////////// + // read IPR graph from dst root file (for direct usage or creation of database ) + if( getRunParameter()->ifReadIPRfromDSTFile == true ) + { + cout << "\t reading IPR graphs for NN image cleaning from DST file" << endl; + for( int i = 0; i < t->GetEntries(); i++ ) + { + setTelID( i ); + readIPRGraph_from_DSTFile( iDSTfile, getSumWindow(), getTelType( i ) ); + } + } + else if( getRunParameter()->ifReadIPRfromDatabase == true || getRunParameter()->ifCreateIPRdatabase == true ) + { + cout << "\t reading IPR graphs for NN image cleaning" << endl; + for( int i = 0; i < t->GetEntries(); i++ ) + { + setTelID( i ); + calculateIPRGraphs( iDSTfile, getSumWindow(), getTelType( i ), i ); + } + } + else if( getRunParameter()->fIPRdatabase.Length() > 0 ) + { + cout << "\t IPR graphs for NN cleaning will be read from external database: "; + cout << getRunParameter()->fIPRdatabase << endl; + } + + iF.Close(); + return true; } +/* + * + * write IPR graphs to disk (one per telescope type) + * + */ +bool VCalibrator::writeIPRgraphs( string iFile ) +{ + TFile* fgraphs = 0; + if( iFile.size() == 0 ) + { + fgraphs = new TFile( getRunParameter()->fIPRdatabaseFile, "RECREATE" ); + } + else + { + fgraphs = new TFile( iFile.c_str(), "UPDATE" ); + } + if( fgraphs->IsZombie() ) + { + cout << "VCalibrator::writeIPRgraphs error opening IPR output file: " << endl; + cout << "\t" << fgraphs->GetName() << endl; + return false; + } + + // tree with conditions for these IRPs + TTree* header = new TTree( "IPRheader", "IPR parameters" ); + unsigned int sumwin = 0; // [FADC slices] + unsigned int Nsamples = 0; // [FADC slices] + float ROwin = 0.; // [ns] + float FADCslice = 0.; // [ns] + unsigned int SignalExtractor = 0; // [ Selected Extractor ] + header->Branch( "SignalExtractor", &SignalExtractor, "SignalExtractor/i" ); + header->Branch( "SummationWindow", &sumwin, "SummationWindow/i" ); + header->Branch( "Nsamples", &Nsamples, "Nsamples/i" ); + header->Branch( "FADCtimeSlice", &FADCslice, "FADCtimeSlice/F" ); + header->Branch( "ReadoutWindow", &ROwin, "ReadoutWindow/F" ); + + // one graph per telescope ID + map< ULong64_t, bool > iTelDone; + for( unsigned int i = 0; i < getDetectorGeometry()->getTelType_list().size(); i++ ) + { + iTelDone[getDetectorGeometry()->getTelType_list()[i]] = false; + } + + for( unsigned int i = 0; i < getNTel(); i++ ) + { + setTelID( i ); + if( iTelDone[getTelType( i )] ) + { + continue; + } + + if( hped_vec.find( getTelType( i ) ) == hped_vec.end() ) + { + continue; + } + + // loop over all summation windows + for( unsigned int j = 0; j < hped_vec[getTelType( i )].size(); j++ ) + { + // summation window + int i_sw = j + 1; + + TGraphErrors* g = getIPRGraph( i_sw, false ); + if( !g ) + { + continue; + } + SignalExtractor = getRunParameter()->fTraceIntegrationMethod.at( getTelID() ); + sumwin = i_sw; + Nsamples = getNSamples(); + FADCslice = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); //[ns] + ROwin = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * ( float )getNSamples(); // [ns] + + header->Fill(); + g->Write(); + } + + iTelDone[getTelType( i )] = true; + } + header->Write(); + fgraphs->Close(); + fgraphs->Delete(); + + return true; +} -unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( vector< int > iE, int iTelID ) -{ - if( iTelID > 0 && iTelID < ( int )iE.size() ) - { - return iE[iTelID]; - } - else - { - int iTot = 0; - int iN = 0; - for( unsigned int tel = 0; tel < getTeltoAna().size(); tel++ ) - { - if( tel < iE.size() ) - { - iTot += iE[tel]; - iN++; - } - } - if( iN > 0 ) - { - return iTot / iN; - } - } +unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( int iTelID, int iType ) +{ + if( iType == 1 || iType == 6 ) + { + return getNumberOfEventsUsedInCalibration( fNumberPedestalEvents, iTelID ); + } + else if( iType == 2 || iType == 5 ) + { + return getNumberOfEventsUsedInCalibration( fNumberGainEvents, iTelID ); + } + else if( iType == 7 || iType == 8 ) + { + return getNumberOfEventsUsedInCalibration( fNumberTZeroEvents, iTelID ); + } + return 0; +} - return 0; +unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( vector< int > iE, int iTelID ) +{ + if( iTelID > 0 && iTelID < ( int )iE.size() ) + { + return iE[iTelID]; + } + else + { + int iTot = 0; + int iN = 0; + for( unsigned int tel = 0; tel < getTeltoAna().size(); tel++ ) + { + if( tel < iE.size() ) + { + iTot += iE[tel]; + iN++; + } + } + if( iN > 0 ) + { + return iTot / iN; + } + } + + return 0; } unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( map< ULong64_t, int > iE, int iTelID ) @@ -4089,11 +4578,451 @@ unsigned int VCalibrator::getNumberOfEventsUsedInCalibration( map< ULong64_t, in return 0; } +/* + * calculate IPR graphs and write them to disk + * + * (loop over all telescopes) + * +*/ +bool VCalibrator::calculateIPRGraphs() +{ + for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) + { + setTelID( getTeltoAna()[i] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + if( fIPRAverageTel == false ) + { + calculateIPRGraphs( fPedFileNameC[getTeltoAna()[i]], getSumWindow(), getTelType( getTeltoAna()[i] ), i ); + } + else + { + copyIPRTelAveraged( getSumWindow(), getTeltoAna()[i], i ); + } + } + return true; +} /* - * Unecessary for veritas? Probably remove! + * calculate IPR graphs and write them to disk + * + * (this is done per telescope type) + * */ +bool VCalibrator::copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) +{ + + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[0] ); + TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[i_tel] ); + + if( !i_IPRGraph ) + { + cout << "VCalibrator::copyIPRTelAveraged: no IPR graph found for telescope type " << iTelType << endl; + return false; + } + if( !i_IPRGraph_Tel0 ) + { + cout << "VCalibrator::copyIPRTelAveraged: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; + return false; + } + + for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) + { + i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); + } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); + i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); + i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); + + return true; + +} + +bool VCalibrator::calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) +{ + TH1F* hIPR = ( TH1F* )initializeIPRAveraged( iSummationWindow, getTeltoAna()[i_tel] ); + TDirectory* iG_CurrentDirectory = gDirectory; + + // get an IPR graph + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + if( !i_IPRGraph ) + { + cout << "VCalibrator::calculateIPRGraphs info: no IPR graph found for telescope type " << iTelType << endl; + return false; + } + // check suffix of ped file + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile iPedFile( iPedFileName.c_str() ); + if( iPedFile.IsZombie() ) + { + cout << "VCalibrator::calculateIPRGraphs error reading IPR graphs from "; + cout << iPedFileName << endl; + return false; + } + // histograms with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << iTelType << ": "; + cout << "reading IPR histograms for summation window " << iSummationWindow; + cout << " from "; + cout << iPedFileName << endl; + + stringstream i_Directory( stringstream::in | stringstream::out ); + i_Directory << "distributions_" << iTelType; + if( iPedFile.Get( i_Directory.str().c_str() ) ) + { + iPedFile.cd( i_Directory.str().c_str() ); + } + + hIPR->Reset(); + + ////////////////////////////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream i_Pname( stringstream::in | stringstream::out ); + i_Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( i_Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + + int z = 0; + float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "Telescope " << iTelType << ": "; + cout << "VCalibrator::calculateIPRGraphs WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VCalibrator::calculateIPRGraphs(): fIPRAverageTel = " << fIPRAverageTel << endl; + hIPR = calculateIPRGraphAveraged( iSummationWindow ); + cout << "VCalibrator::calculateIPRGraphs norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VCalibrator::calculateIPRGraphs ERROR: no counts in IPR histogram !" << endl; + return false; + } + // convert to Rate + float nsToSec = 1E-9; + float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); + if( getSearchWindowLast() < getNSamples() ) + { + Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] + } + else + { + Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] + } + float convToHz = 1.; + if( nsToSec > 0. && Tsearch > 0. ) + { + convToHz /= ( nsToSec * Tsearch ); + } + else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) + { + // simple peak sensing: sim_telarray uses the maximum bin only + // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file + // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as + // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns + // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. + convToHz /= ( nsToSec + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); + } + + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convToHz * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convToHz * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", Tsearch, + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); + hIPR->Delete(); + + iPedFile.Close(); + + iG_CurrentDirectory->cd(); + + return true; +} + +TH1F* VCalibrator::initializeIPRAveraged( unsigned int iSummationWindow, unsigned int iTelType ) +{ + //get reference hpedPerTelescopeType for channel 1 + cout << "VCalibrator::initializeIPRAveraged initializing IPR graph for calculation of average of telescopes." << endl; + TH1F* hIPR = 0; + + + int TelType = getTelType( iTelType ); + string PedFile_name = fPedFileNameC[iTelType]; + + // check suffix of ped file + if( PedFile_name.find( ".root" ) == string::npos ) + { + PedFile_name += ".root"; + } + // open pedestal files + TFile PedFile( PedFile_name.c_str() ); + + if( PedFile.IsZombie() ) + { + cout << "VCalibrator::calculateIPRGraphsStatistics: error reading IPR graphs from "; + cout << PedFile_name << endl; + return hIPR; + } + + // histograms with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << TelType << ": "; + cout << "reading IPR histograms for summation window " << iSummationWindow; + cout << " from "; + cout << PedFile_name << endl; + + stringstream Directory( stringstream::in | stringstream::out ); + Directory << "distributions_" << TelType; + if( !PedFile.Get( Directory.str().c_str() ) ) + { + return hIPR; + } + + // get charge distribution for first channel as reference histogram + stringstream hIPRname( stringstream::in | stringstream::out ); + hIPRname << "distributions_" << TelType << "/hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << 1; + + //? + TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); + PedFile.Close(); + + if( !href ) + { + cout << " Error: cannot find IPR histogram " << hIPRname.str().c_str(); + cout << " in file:" << PedFile_name << " ... exiting " << endl; + return hIPR; + } + + + //summary histogram + if( getRunParameter()->fIgnoreDSTGains ) + { + // work in dc + hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); + cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; + return hIPR; + } + else + { + // work in pe + hIPR = new TH1F( "", "", 1000, 0., 100. ); + return hIPR; + } +} + +TH1F* VCalibrator::calculateIPRGraphAveraged( unsigned int iSummationWindow ) +{ + + TH1F* hIPR = ( TH1F* )initializeIPRAveraged( iSummationWindow, getTeltoAna()[0] ); + + for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) + { + setTelID( getTeltoAna()[teltype] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + string PedFile_name = fPedFileNameC[getTeltoAna()[teltype]]; + int TelType = getTelType( getTeltoAna()[teltype] ); + + if( PedFile_name.find( ".root" ) == string::npos ) + { + PedFile_name += ".root"; + } + // open pedestal files + TFile PedFile( PedFile_name.c_str() ); + if( PedFile.IsZombie() ) + { + cout << "VCalibrator::calculateIPRGraphAveraged error reading IPR graphs from "; + cout << PedFile_name << endl; + TH1F* hNull = 0; + return hNull; + } + // histograms with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "VCalibrator::calculateIPRGraphAveraged Telescope type " << TelType << ": "; + cout << "reading IPR histograms for summation window " << iSummationWindow; + cout << " from "; + cout << PedFile_name << endl; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << TelType; + cout << Directory.str().c_str() << endl; + if( PedFile.Get( Directory.str().c_str() ) ) + { + PedFile.cd( Directory.str().c_str() ); + } + else + { + cout << "VCalibrator::calculateIPRGraphAveraged no directory: " << Directory.str().c_str() << endl; + } + + /////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream HistName( stringstream::in | stringstream::out ); + HistName << "hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); + + + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream Pname( stringstream::in | stringstream::out ); + Pname << "hped_" << TelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + PedFile.Close(); + + } + hIPR->Scale( 1. / getTeltoAna().size() ); + float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "VCalibrator::calculateIPRGraphAveraged normalization of average IPR histogram " << norm; + cout << ". Returning IPR histogram." << endl; + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + cout << "VCalibrator::calculateIPRGraphAveraged WARNING: there is NOT enough statistics "; + cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; + return hIPR; + } + else + { + cout << "VCalibrator::calculateIPRGraphsStatistics: there is enough statistics to average over telescopes. " << endl; + return hIPR; + } +} + + bool VCalibrator::readIPRGraph_from_DSTFile( string iDSTFile, unsigned int iSummationWindow, ULong64_t iTelType ) { TDirectory* iG_CurrentDirectory = gDirectory; diff --git a/src/VDataMCComparision.cpp b/src/VDataMCComparision.cpp index 33a6996ad..8876f84d9 100644 --- a/src/VDataMCComparision.cpp +++ b/src/VDataMCComparision.cpp @@ -9,7 +9,8 @@ #include "VDataMCComparision.h" -VDataMCComparisionHistogramData::VDataMCComparisionHistogramData( string iName, string iHistogramType, unsigned int iTelescopeID ) +VDataMCComparisionHistogramData::VDataMCComparisionHistogramData( + string iName, string iHistogramType, unsigned int iTelescopeID ) { fVarName = iName; fHistogramType = iHistogramType; @@ -91,7 +92,9 @@ bool VDataMCComparisionHistogramData::initHistogram( string iXTitle, int iNbins, * fill comparison histograms as function of energy, ntubes, size, sizeHG, sizeLG * */ -void VDataMCComparisionHistogramData::fill( double iV, double iWeight, double iLogEnergy_TeV, int i_ntubes, double i_size, double i_fracLow ) +void VDataMCComparisionHistogramData::fill( + double iV, double iWeight, double iLogEnergy_TeV, + int i_ntubes, double i_size, double i_fracLow ) { if( fHis1D ) { @@ -121,7 +124,7 @@ void VDataMCComparisionHistogramData::fill( double iV, double iWeight, double iL //////////////////////////////////////////////////////////////////////////////////////// -VDataMCComparision::VDataMCComparision( string iname, int intel, bool iMVAValues ) +VDataMCComparision::VDataMCComparision( string iname, int intel ) { fNTel = intel; fName = iname; @@ -135,7 +138,8 @@ VDataMCComparision::VDataMCComparision( string iname, int intel, bool iMVAValues fData = 0; fCuts = 0; - fCalculateMVAValues = iMVAValues; + fCalculateMVAValues = false; + fEpochATM = ""; // spectral weighting (will be set later correctly, as it is run from MC run header) fSpectralWeight = new VSpectralWeight(); @@ -177,10 +181,14 @@ VDataMCComparision::VDataMCComparision( string iname, int intel, bool iMVAValues */ void VDataMCComparision::initialGammaHadronCuts() { + VGlobalRunParameter( true ); fCuts = new VGammaHadronCuts(); fCuts->initialize(); fCuts->resetCutValues(); + fCuts->setNTel( 4 ); + fCuts->setInstrumentEpoch( fEpochATM ); // HARDWIRED CUT FILE + // used for BDT comparision if( !fCuts->readCuts( "$VERITAS_EVNDISP_AUX_DIR/GammaHadronCutFiles/ANASUM.GammaHadron-Cut-NTel2-PointSource-Moderate-TMVA-BDT.dat" ) ) { cout << "exiting..." << endl; @@ -447,7 +455,6 @@ bool VDataMCComparision::setOnOffHistograms( VDataMCComparision* on, VDataMCComp hTel2D[j]->Add( on->hTel2D[j], off->hTel2D[j], 1., norm ); } - return true; } @@ -493,7 +500,7 @@ void VDataMCComparision::setEntries( TH2D* iH ) bool VDataMCComparision::fillHistograms( string ifile, int iSingleTelescopeCuts ) { // quality cuts - double fCoreMax_QC = 350; //350.; // cut on core distance + double fCoreMax_QC = 350; // cut on core distance int fNImages_min = 2; // minimum number of images per event // stereo cuts double theta2_cut = 0.035; // 0.35; @@ -512,13 +519,6 @@ bool VDataMCComparision::fillHistograms( string ifile, int iSingleTelescopeCuts double msl_max = 0.5; double msl_min = -1.2; - /* - double msw_max = 1.15; - double msw_min = 0.05; - double msl_max = 0.40; - double msl_min = 0.05; - */ - double size_min = 200.; double size2ndmax_min = 0.; @@ -786,7 +786,6 @@ bool VDataMCComparision::fillHistograms( string ifile, int iSingleTelescopeCuts } } - ///////////////////////////////////////////////////////// // --- apply theta2 cuts --- ///////////////////////////////////////////////////////// @@ -957,10 +956,16 @@ bool VDataMCComparision::fillHistograms( string ifile, int iSingleTelescopeCuts if( fCuts ) { fCuts->newEvent(); - fCuts->applyTMVACut( i ); - if( fCuts->getTMVA_EvaluationResult() > -90. && fHistoArray[EMVA] ) + // apply stereo quality cuts to ensure good response of TMV + if( fCuts->applyInsideFiducialAreaCut( true ) + && fCuts->applyStereoQualityCuts( 1, true, i, true ) ) { - fHistoArray[EMVA]->fill( fCuts->getTMVA_EvaluationResult(), weight, log10( fData->ErecS ) ); + fCuts->applyTMVACut( i ); + if( fCuts->getTMVA_EvaluationResult() > -90. && fHistoArray[EMVA] ) + { + fHistoArray[EMVA]->fill( + fCuts->getTMVA_EvaluationResult(), weight, log10( fData->ErecS ) ); + } } } } diff --git a/src/VEffectiveAreaCalculator.cpp b/src/VEffectiveAreaCalculator.cpp index f9d8fd20a..bd983816a 100644 --- a/src/VEffectiveAreaCalculator.cpp +++ b/src/VEffectiveAreaCalculator.cpp @@ -19,7 +19,7 @@ VEffectiveAreaCalculator::VEffectiveAreaCalculator( VInstrumentResponseFunctionR { cout << "VEffectiveAreaCalculator: no run parameters given" << endl; cout << "...exiting..." << endl; - exit( -1 ); + exit( EXIT_FAILURE ); } reset(); @@ -951,50 +951,61 @@ VEffectiveAreaCalculator::VEffectiveAreaCalculator( string iInputFile, double az fGDirectory = gDirectory; // test if input file with effective areas exists - iInputFile = VUtilities::testFileLocation( iInputFile, "EffectiveAreas", true ); - if( iInputFile.size() == 0 ) - { - exit( 0 ); - } - - TFile fIn( iInputFile.c_str() ); - if( fIn.IsZombie() ) - { - cout << "Error opening file with effective areas: " << iInputFile << endl; - exit( -1 ); - } - cout << "\t reading effective areas from " << fIn.GetName() << endl; - - // test which kind of file is available - // i) effective areas values for each energy bin (bEffectiveAreasareHistograms = true) - // ii) fit functions to effective area histograms (bEffectiveAreasareFunctions = true) - // (favorable, to avoid binning effects) - // - // prefer fit function over histograms - // - bEffectiveAreasareFunctions = false; - bEffectiveAreasareHistograms = false; - if( getEffectiveAreasFromFitFunction( ( TTree* )gDirectory->Get( "EffFit" ), azmin, azmax, iSpectralIndex ) ) + if( iInputFile.find( "IGNOREEFFECTIVEAREA" ) == string::npos ) { - bEffectiveAreasareFunctions = true; - } - else if( initializeEffectiveAreasFromHistograms( ( TTree* )gDirectory->Get( "fEffArea" ), - ( TH1D* )gDirectory->Get( "hEmc" ), - azmin, azmax, iSpectralIndex, ipedvar, - ( TTree* )gDirectory->Get( "fEffAreaH2F" ) ) ) - { - bEffectiveAreasareHistograms = true; + iInputFile = VUtilities::testFileLocation( iInputFile, "EffectiveAreas", true ); + if( iInputFile.size() == 0 ) + { + exit( EXIT_FAILURE ); + } } - if( !bEffectiveAreasareHistograms && !bEffectiveAreasareFunctions ) + if( iInputFile.find( "IGNOREEFFECTIVEAREA" ) != string::npos ) { - cout << "VEffectiveAreaCalculator ERROR: no effective areas found" << endl; + cout << "ignoring effective areas: "; cout << "all energy spectra will be invalid" << endl; bNOFILE = true; } - fIn.Close(); - if( fGDirectory ) + else { - fGDirectory->cd(); + TFile fIn( iInputFile.c_str() ); + if( fIn.IsZombie() ) + { + cout << "Error opening file with effective areas: " << iInputFile << endl; + exit( -1 ); + } + cout << "\t reading effective areas from " << fIn.GetName() << endl; + + // test which kind of file is available + // i) effective areas values for each energy bin (bEffectiveAreasareHistograms = true) + // ii) fit functions to effective area histograms (bEffectiveAreasareFunctions = true) + // (favorable, to avoid binning effects) + // + // prefer fit function over histograms + // + bEffectiveAreasareFunctions = false; + bEffectiveAreasareHistograms = false; + if( getEffectiveAreasFromFitFunction( ( TTree* )gDirectory->Get( "EffFit" ), azmin, azmax, iSpectralIndex ) ) + { + bEffectiveAreasareFunctions = true; + } + else if( initializeEffectiveAreasFromHistograms( ( TTree* )gDirectory->Get( "fEffArea" ), + ( TH1D* )gDirectory->Get( "hEmc" ), + azmin, azmax, iSpectralIndex, ipedvar, + ( TTree* )gDirectory->Get( "fEffAreaH2F" ) ) ) + { + bEffectiveAreasareHistograms = true; + } + if( !bEffectiveAreasareHistograms && !bEffectiveAreasareFunctions ) + { + cout << "VEffectiveAreaCalculator ERROR: no effective areas found" << endl; + cout << "all energy spectra will be invalid" << endl; + bNOFILE = true; + } + fIn.Close(); + if( fGDirectory ) + { + fGDirectory->cd(); + } } } @@ -2067,7 +2078,7 @@ bool VEffectiveAreaCalculator::fill( TH1D* hE0mc, CData* d, } // reset unique event counter fUniqueEventCounter.clear(); - int iSuccessfullEventStatistics = 0; + Long64_t iSuccessfullEventStatistics = 0; ////////////////////////////////////////////////////////////////// // print some run information @@ -2350,34 +2361,10 @@ bool VEffectiveAreaCalculator::fill( TH1D* hE0mc, CData* d, hEcutSub[6]->Fill( eMC, 1. ); } - // unique event counter - // (make sure that map doesn't get too big) - if( !bDirectionCut && iSuccessfullEventStatistics >= 0 ) + if( !bDirectionCut ) { iSuccessfullEventStatistics++; - /* This was removed in v502, is it necessary? - if( fUniqueEventCounter.size() < 100000 ) - { - unsigned int iUIEnergy = ( unsigned int )( d->MCe0 * 1.e5 ); - if( fUniqueEventCounter.find( iUIEnergy ) != fUniqueEventCounter.end() ) - { - fUniqueEventCounter[iUIEnergy]++; - } - else - { - fUniqueEventCounter[iUIEnergy] = 1; - } - } - else - { - iSuccessfullEventStatistics *= -1; - } - */ - } - else - { - iSuccessfullEventStatistics--; } // loop over all az bins @@ -2804,25 +2791,6 @@ bool VEffectiveAreaCalculator::fill( TH1D* hE0mc, CData* d, } fCuts->printCutStatistics(); - - // print out uniqueness of events - /* cout << "event statistics: " << endl; - if( iSuccessfullEventStatistics > 0 ) - { - map< unsigned int, unsigned short int>::iterator it; - for( it = fUniqueEventCounter.begin(); it != fUniqueEventCounter.end(); it++ ) - { - if( (*it).second > 1 ) - { - cout << "\t multiple event after cuts at " << (double)((*it).first)/1.e5 << " TeV, used " << (*it).second << " times" << endl; - } - } - } - else iSuccessfullEventStatistics *= -1; */ - if( iSuccessfullEventStatistics < 0 ) - { - iSuccessfullEventStatistics *= -1; - } cout << "\t total number of events after cuts: " << iSuccessfullEventStatistics << endl; return true; diff --git a/src/VEnergyThreshold.cpp b/src/VEnergyThreshold.cpp index 5e3451815..820d3ad31 100644 --- a/src/VEnergyThreshold.cpp +++ b/src/VEnergyThreshold.cpp @@ -37,7 +37,7 @@ iii) plot energy thresholds // create a new instance, open the data file VEnergyThreshold a( 0.0, "myOutputFile.root" ); -// plot everything (for ze=20, wobble offset=0.5 deg, noise = 150, index = 2.4, az bin = 16) +// plot everything (for ze=20, wobble offset=0.5 deg, noise = 150, az bin = 16) a.plot_energyThresholds( "E_diffmax", 20., 0.5, 150, 2.4, 16 ); Energy thresholds are defined (currently) in 3 ways: @@ -141,17 +141,32 @@ bool VEnergyThreshold::openEffectiveAreaFile( string iname ) cout << "VEnergyThreshold::openEffectiveAreaFile " << iname << endl; } - TChain* f = new TChain( "fEffArea" ); - f->Add( iname.c_str() ); - if( f->GetListOfFiles()->GetEntries() == 0 ) + fEffArea = new TChain( "fEffAreaH2F" ); + fEffArea->Add( iname.c_str() ); + if( fEffArea->GetListOfFiles()->GetEntries() == 0 ) { - cout << "error opening " << iname << "(" << f->GetListOfFiles()->GetEntries() << ")" << endl; + cout << "error opening " << iname << "(" << fEffArea->GetListOfFiles()->GetEntries() << ")" << endl; return false; } - fEffArea = new CEffArea( f ); cout << "reading effective areas from " << iname << endl; - cout << "total number of effective areas: " << f->GetEntries() << endl; + cout << "total number of effective areas: " << fEffArea->GetEntries() << endl; + + fEffArea->SetBranchAddress( "ze", &fze ); + fEffArea->SetBranchAddress( "az", &fAzBin ); + fEffArea->SetBranchAddress( "azMin", &fAzMin ); + fEffArea->SetBranchAddress( "azMax", &fAzMax ); + fEffArea->SetBranchAddress( "Woff", &fWoff ); + fEffArea->SetBranchAddress( "noise", &fTNoise ); + fEffArea->SetBranchAddress( "pedvar", &fTPedvar ); + nbins = 0; + fEffArea->SetBranchAddress( "nbins", &nbins ); + fEffArea->SetBranchAddress( "e0", e0 ); + fEffArea->SetBranchAddress( "eff", eff ); + nbins_esys = 0; + fEffArea->SetBranchAddress( "nbins_esys", &nbins_esys ); + fEffArea->SetBranchAddress( "e0_esys", e0_esys ); + fEffArea->SetBranchAddress( "esys_rel", esys_rel ); return true; } @@ -196,13 +211,9 @@ bool VEnergyThreshold::calculateEnergyThreshold( bool bFit, int nentries ) } } - if( nentries < 0 ) + if( nentries < 0 || nentries > fEffArea->GetEntries() ) { - nentries = fEffArea->fChain->GetEntries(); - } - if( nentries > fEffArea->fChain->GetEntries() ) - { - nentries = fEffArea->fChain->GetEntries(); + nentries = fEffArea->GetEntries(); } for( int i = 0; i < nentries; i++ ) { @@ -228,63 +239,56 @@ bool VEnergyThreshold::calculateEnergyThreshold( bool bFit, int nentries ) feff_500GeV = 0.; feff_1TeV = 0.; - copyEntry(); - - TH1D* hLin = fEffArea->hEcut500; - if( hLin ) + if( nbins > 1 ) { - feth = getEnergyThreshold( hLin, true, bFit ); - } - else - { - if( fEffArea->nbins > 1 ) + double idE = e0[1] - e0[0]; + TH1D hLin( "hLin", "", nbins, + e0[0] - idE, + e0[nbins - 1] + idE ); + for( int b = 0; b < nbins; b++ ) { - double idE = fEffArea->e0[1] - fEffArea->e0[0]; - TH1D hLin( "hLin", "", fEffArea->nbins, - fEffArea->e0[0] - idE, - fEffArea->e0[fEffArea->nbins - 1] + idE ); - for( int b = 0; b < fEffArea->nbins; b++ ) - { - hLin.SetBinContent( b + 1, fEffArea->e0[b], - fEffArea->eff[b] * - TMath::Power( TMath::Power( 10., fEffArea->e0[b] ), - -1.*fEffArea->index ) ); - } - feth = getEnergyThreshold( &hLin, true, bFit ); + hLin.SetBinContent( b + 1, e0[b], + eff[b] * + TMath::Power( TMath::Power( 10., e0[b] ), + -1.*2.4 ) ); } + feth = getEnergyThreshold( &hLin, true, bFit ); } - TProfile* hSys = fEffArea->hEsysMCRelative; - if( hSys ) - { - fesys_10p = getEnergy_maxSystematic( hSys, 0.10 ); - fesys_15p = getEnergy_maxSystematic( hSys, 0.15 ); - fesys_20p = getEnergy_maxSystematic( hSys, 0.20 ); - } - TGraph* hG = fEffArea->gEffAreaRec; - if( !hG ) + if( nbins_esys > 1 ) { - hG = new TGraph( 1 ); - for( int b = 0; b < fEffArea->nbins; b++ ) + vector< double > x; + vector< double > y; + for( int b = 0; b < nbins_esys; b++ ) { - hG->SetPoint( b, fEffArea->e0[b], fEffArea->eff[b] ); + if( TMath::Abs( esys_rel[b] ) > 1.e-3 ) + { + x.push_back( e0_esys[b] ); + y.push_back( esys_rel[b] ); + } } - feff_300GeV = hG->Eval( log10( 0.3 ) ); - feff_500GeV = hG->Eval( log10( 0.5 ) ); - feff_1TeV = hG->Eval( log10( 1. ) ); + fesys_10p = getEnergy_maxSystematic( x, y, 0.10 ); + fesys_15p = getEnergy_maxSystematic( x, y, 0.15 ); + fesys_20p = getEnergy_maxSystematic( x, y, 0.20 ); } - if( hG ) + TGraph* gEffAreaRec = new TGraph( 1 ); + for( int b = 0; b < nbins; b++ ) { - feffFract_05p = getEnergy_MaxEffectiveAreaFraction( hG, 0.05 ); - feffFract_10p = getEnergy_MaxEffectiveAreaFraction( hG, 0.10 ); - feffFract_20p = getEnergy_MaxEffectiveAreaFraction( hG, 0.20 ); - feffFract_50p = getEnergy_MaxEffectiveAreaFraction( hG, 0.50 ); - feffFract_90p = getEnergy_MaxEffectiveAreaFraction( hG, 0.90 ); - delete hG; + gEffAreaRec->SetPoint( b, e0[b], eff[b] ); } - if( TMath::Abs( fEffArea->index - 2.4 ) < 1.e-3 && TMath::Abs( fEffArea->azMax - 1000. ) < 1.e-3 ) + feff_300GeV = gEffAreaRec->Eval( log10( 0.3 ) ); + feff_500GeV = gEffAreaRec->Eval( log10( 0.5 ) ); + feff_1TeV = gEffAreaRec->Eval( log10( 1. ) ); + feffFract_05p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.05 ); + feffFract_10p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.10 ); + feffFract_20p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.20 ); + feffFract_50p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.50 ); + feffFract_90p = getEnergy_MaxEffectiveAreaFraction( gEffAreaRec, 0.90 ); + delete gEffAreaRec; + + if( TMath::Abs( fAzMax - 1000. ) < 1.e-3 ) { - cout << "Threshold for index " << fEffArea->index << ": "; + cout << "Threshold : "; cout << feth << " TeV, 10\% sys: " << fesys_10p << endl; } fTreeEth->Fill(); @@ -292,45 +296,34 @@ bool VEnergyThreshold::calculateEnergyThreshold( bool bFit, int nentries ) return true; } - -/*! - calculate lower energy threshold from systematics: - (interpolate between two closest values) -*/ -double VEnergyThreshold::getEnergy_maxSystematic( TObject* h, double iSys ) +double VEnergyThreshold::getEnergy_maxSystematic( TGraphErrors* g, double iSys ) { - if( !h ) + if( !g ) { return 0.; } vector< double > x; vector< double > y; - - if( strcmp( "TProfile", h->ClassName() ) == 0 ) + double e = 0.; + double s = 0.; + for( int b = 0; b < g->GetN(); b++ ) { - TProfile* p = ( TProfile* )h; - for( int i = 1; i < p->GetNbinsX(); i++ ) + g->GetPoint( b, e, s ); + if( TMath::Abs( s ) > 1.e-3 ) { - if( p->GetBinError( i ) < 0.001 ) - { - continue; - } - x.push_back( p->GetBinCenter( i ) ); - y.push_back( p->GetBinContent( i ) ); + x.push_back( e ); + y.push_back( s ); } } - else if( strcmp( "TGraphErrors", h->ClassName() ) == 0 ) - { - double a, b; - TGraphErrors* g = ( TGraphErrors* )h; - for( int i = 0; i < g->GetN(); i++ ) - { - g->GetPoint( i, a, b ); - x.push_back( a ); - y.push_back( b ); - } - } - + return getEnergy_maxSystematic( x, y, iSys ); +} + +/*! + calculate lower energy threshold from systematics: + (interpolate between two closest values) +*/ +double VEnergyThreshold::getEnergy_maxSystematic( vector< double > x, vector< double > y, double iSys ) +{ double x1, x2, y1, y2, a, b; for( unsigned int i = 0; i < x.size(); i++ ) @@ -425,22 +418,6 @@ double VEnergyThreshold::getEnergyThreshold( TH1D* h, bool bLogEnergyAxis, bool } -void VEnergyThreshold::copyEntry() -{ - fze = fEffArea->ze; - fAzBin = fEffArea->az; - fAzMin = fEffArea->azMin; - fAzMax = fEffArea->azMax; - fXoff = fEffArea->Xoff; - fYoff = fEffArea->Yoff; - fWoff = fEffArea->Woff; - fTNoise = fEffArea->noise; - fTNoisePE = fEffArea->noisePE; - fTPedvar = fEffArea->pedvar; - fSpectralIndex = fEffArea->index; -} - - bool VEnergyThreshold::setUpThresholdTree() { if( fDebug ) @@ -466,29 +443,25 @@ bool VEnergyThreshold::setUpThresholdTree() fOutFile->cd(); fTreeEth = new TTree( "fTreeEth", "thresholds in energy reconstruction" ); - fTreeEth->Branch( "ze", &fze, "ze/D" ); - fTreeEth->Branch( "az", &fAzBin, "az/I" ); - fTreeEth->Branch( "azMin", &fAzMin, "azMin/D" ); - fTreeEth->Branch( "azMax", &fAzMax, "azMax/D" ); - fTreeEth->Branch( "Xoff", &fXoff, "Xoff/D" ); - fTreeEth->Branch( "Yoff", &fYoff, "Yoff/D" ); - fTreeEth->Branch( "Woff", &fWoff, "Woff/D" ); - fTreeEth->Branch( "noise", &fTNoise, "noise/I" ); - fTreeEth->Branch( "noisePE", &fTNoisePE, "noisePE/D" ); - fTreeEth->Branch( "pedvar", &fTPedvar, "pedvar/D" ); - fTreeEth->Branch( "index", &fSpectralIndex, "index/D" ); - fTreeEth->Branch( "E_diffmax", &feth, "E_diffmax/D" ); - fTreeEth->Branch( "E_sys10p", &fesys_10p, "E_sys10p/D" ); - fTreeEth->Branch( "E_sys15p", &fesys_15p, "E_sys15p/D" ); - fTreeEth->Branch( "E_sys20p", &fesys_20p, "E_sys20p/D" ); - fTreeEth->Branch( "E_effFract_05p", &feffFract_05p, "E_effFract_05p/D" ); - fTreeEth->Branch( "E_effFract_10p", &feffFract_10p, "E_effFract_10p/D" ); - fTreeEth->Branch( "E_effFract_20p", &feffFract_20p, "E_effFract_20p/D" ); - fTreeEth->Branch( "E_effFract_50p", &feffFract_50p, "E_effFract_50p/D" ); - fTreeEth->Branch( "E_effFract_90p", &feffFract_90p, "E_effFract_90p/D" ); - fTreeEth->Branch( "EffArea_300GeV", &feff_300GeV, "EffArea_300GeV/D" ); - fTreeEth->Branch( "EffArea_500GeV", &feff_500GeV, "EffArea_500GeV/D" ); - fTreeEth->Branch( "EffArea_1TeV", &feff_1TeV, "EffArea_1TeV/D" ); + fTreeEth->Branch( "ze", &fze, "ze/F" ); + fTreeEth->Branch( "az", &fAzBin, "az/s" ); + fTreeEth->Branch( "azMin", &fAzMin, "azMin/F" ); + fTreeEth->Branch( "azMax", &fAzMax, "azMax/F" ); + fTreeEth->Branch( "Woff", &fWoff, "Woff/F" ); + fTreeEth->Branch( "noise", &fTNoise, "noise/s" ); + fTreeEth->Branch( "pedvar", &fTPedvar, "pedvar/F" ); + fTreeEth->Branch( "E_diffmax", &feth, "E_diffmax/F" ); + fTreeEth->Branch( "E_sys10p", &fesys_10p, "E_sys10p/F" ); + fTreeEth->Branch( "E_sys15p", &fesys_15p, "E_sys15p/F" ); + fTreeEth->Branch( "E_sys20p", &fesys_20p, "E_sys20p/F" ); + fTreeEth->Branch( "E_effFract_05p", &feffFract_05p, "E_effFract_05p/F" ); + fTreeEth->Branch( "E_effFract_10p", &feffFract_10p, "E_effFract_10p/F" ); + fTreeEth->Branch( "E_effFract_20p", &feffFract_20p, "E_effFract_20p/F" ); + fTreeEth->Branch( "E_effFract_50p", &feffFract_50p, "E_effFract_50p/F" ); + fTreeEth->Branch( "E_effFract_90p", &feffFract_90p, "E_effFract_90p/F" ); + fTreeEth->Branch( "EffArea_300GeV", &feff_300GeV, "EffArea_300GeV/F" ); + fTreeEth->Branch( "EffArea_500GeV", &feff_500GeV, "EffArea_500GeV/F" ); + fTreeEth->Branch( "EffArea_1TeV", &feff_1TeV, "EffArea_1TeV/F" ); return true; } @@ -589,7 +562,7 @@ double VEnergyThreshold::interpolateEnergyThreshold( VRunList* iRunData ) } -void VEnergyThreshold::plot_energyThresholds( string var, double ze, double woff, int noise, double index, int az, bool bPlot, string plot_option ) +void VEnergyThreshold::plot_energyThresholds( string var, double ze, double woff, int noise, int az, bool bPlot, string plot_option ) { if( !fTreeEth ) { @@ -612,44 +585,36 @@ void VEnergyThreshold::plot_energyThresholds( string var, double ze, double woff vector< string > iName; vector< string > iTitle; - // energy threshold vs spectral index - iName.push_back( "spectral index" ); - iDraw.push_back( var + "*1.e3:index" ); - sprintf( hname, "az == %d && noise == %d && TMath::Abs( ze - %f ) < 0.1 && TMath::Abs( Woff - %f ) < 0.05", az, noise, ze, woff ); - iCut.push_back( hname ); - sprintf( hname, "ze=%d deg, woff = %.2f deg, noise level = %d", ( int )ze, woff, noise ); - iTitle.push_back( hname ); - // energy threshold vs zenith angle iName.push_back( "zenith angle [deg]" ); iDraw.push_back( var + "*1.e3:ze" ); - sprintf( hname, "az == %d && noise == %d && TMath::Abs( index - %f ) < 0.1 && TMath::Abs( Woff - %f ) < 0.05", az, noise, index, woff ); + sprintf( hname, "az == %d && noise == %d && TMath::Abs( Woff - %f ) < 0.05", az, noise, woff ); iCut.push_back( hname ); - sprintf( hname, "woff = %.2f deg, noise level = %d, spectral index = %.1f", woff, noise, index ); + sprintf( hname, "woff = %.2f deg, noise level = %d", woff, noise ); iTitle.push_back( hname ); // energy threshold vs wobble offsets iName.push_back( "wobble offset [deg]" ); iDraw.push_back( var + "*1.e3:Woff" ); - sprintf( hname, "az == %d && noise == %d && TMath::Abs( index - %f ) < 0.1 && TMath::Abs( ze - %f ) < 0.05", az, noise, index, ze ); + sprintf( hname, "az == %d && noise == %d && TMath::Abs( ze - %f ) < 0.05", az, noise, ze ); iCut.push_back( hname ); - sprintf( hname, "ze=%d deg, noise level = %d, spectral index = %.1f", ( int )ze, noise, index ); + sprintf( hname, "ze=%d deg, noise level = %d", ( int )ze, noise ); iTitle.push_back( hname ); // energy threshold vs pedestal variations iName.push_back( "pedestal variation" ); iDraw.push_back( var + "*1.e3:pedvar" ); - sprintf( hname, "az == %d && TMath::Abs( Woff - %f ) < 0.05 && TMath::Abs( index - %f ) < 0.1 && TMath::Abs( ze - %f ) < 0.05", az, woff, index, ze ); + sprintf( hname, "az == %d && TMath::Abs( Woff - %f ) < 0.05 && TMath::Abs( ze - %f ) < 0.05", az, woff, ze ); iCut.push_back( hname ); - sprintf( hname, "ze=%d deg, woff = %.2f deg, spectral index = %.1f", ( int )ze, woff, index ); + sprintf( hname, "ze=%d deg, woff = %.2f deg", ( int )ze, woff ); iTitle.push_back( hname ); // energy threshold vs azimuth angle iName.push_back( "azimuth angle [deg]" ); iDraw.push_back( var + "*1.e3:azMin+30." ); - sprintf( hname, "az != 16 && noise == %d && TMath::Abs( Woff - %f ) < 0.05 && TMath::Abs( index - %f ) < 0.1 && TMath::Abs( ze - %f ) < 0.05", noise, woff, index, ze ); + sprintf( hname, "az != 16 && noise == %d && TMath::Abs( Woff - %f ) < 0.05 && TMath::Abs( ze - %f ) < 0.05", noise, woff, ze ); iCut.push_back( hname ); - sprintf( hname, "ze=%d deg, woff = %.2f deg, noise level = %d, spectral index = %.1f", ( int )ze, woff, noise, index ); + sprintf( hname, "ze=%d deg, woff = %.2f deg, noise level = %d", ( int )ze, woff, noise ); iTitle.push_back( hname ); TCanvas* c = 0; diff --git a/src/VEventLoop.cpp b/src/VEventLoop.cpp index 4c2b4133c..cc495d58a 100644 --- a/src/VEventLoop.cpp +++ b/src/VEventLoop.cpp @@ -135,9 +135,6 @@ VEventLoop::VEventLoop( VEvndispRunParameter* irunparameter ) // reset cut strings and variables resetRunOptions(); - - //add if statement: if ipr should be in time slices - fIPRTimeSlices = true; } @@ -278,12 +275,16 @@ bool VEventLoop::initEventLoop( string iFileName ) unsigned int i_counter = 0; for( ;; ) { - i_tempReader.getNextEvent(); + if( !i_tempReader.getNextEvent() ) + { + break; + } for( unsigned int i = 0; i < fRunPar->fTelToAnalyze.size(); i++ ) { i_tempReader.setTelescopeID( fRunPar->fTelToAnalyze[i] ); // set number of samples - if( i_tempReader.getNumSamples() > 4 ) + // (require at least 10 samples for any reasonable analysis) + if( i_tempReader.getNumSamples() > 9 ) { setNSamples( fRunPar->fTelToAnalyze[i], i_tempReader.getNumSamples() ); i_nSampleSet[i] = true; @@ -322,22 +323,18 @@ bool VEventLoop::initEventLoop( string iFileName ) } } i_counter++; - if( i_counter == 1000 ) + if( i_counter == 10000 ) { - cout << "VEventLoop warning: could not find number of samples in the first 1000 events"; + cout << "VEventLoop warning: could not find number of samples in the first 10000 events"; cout << " (this is normal for runs with event losses at the beginning)" << endl; } - if( i_counter > 999999 ) - { - cout << "VEventLoop warning: could not find number of samples in the first 999999 events" << endl; - break; - } } - if( getNSamples() == 0 || i_counter > 99999 ) + // if( getNSamples() == 0 || i_counter > 9999998 ) + if( getNSamples() == 0 ) { cout << "VEventLoop::initEventLoop error: could not find any telescope events to determine sample length" << endl; cout << "exiting..." << endl; - exit( -1 ); + exit( EXIT_FAILURE ); } cout << "Found consistent number of samples in vbf file after " << i_counter + 1 << " event(s): "; for( unsigned int i = 0; i < fRunPar->fTelToAnalyze.size(); i++ ) @@ -479,17 +476,16 @@ bool VEventLoop::initEventLoop( string iFileName ) // initialize analyzers (output files are created as well here) initializeAnalyzers(); - if( fIPRCalculator ){ cout << "initializing IPR calculator" << endl; fIPRCalculator->initialize(); - } - + } // create calibrators, analyzers, etc. at first event if( fCalibrator ) { - fCalibrator->initialize(fIPRCalculator); + fCalibrator->initialize(fIPRCalculator ); } + // initialize pedestal calculator if( fPedestalCalculator && fRunPar->fPedestalsInTimeSlices ) { @@ -829,7 +825,7 @@ void VEventLoop::shutdown() } if( fCalibrator ) { - fCalibrator->terminate( iP , fIPRCalculator); + fCalibrator->terminate( iP ); } } // write data summary @@ -1022,14 +1018,6 @@ bool VEventLoop::nextEvent() else { cout << "!!! void VEventLoop::nextEvent(): no next event (end of file)" << endl; - for (int tel =0; tel < fIPRCalculator->getStorageHist().size(); tel++){ - for (int ts =0; ts < fIPRCalculator->getStorageHist()[tel].size(); ts++){ - for (int p =0; p < fIPRCalculator->getStorageHist()[tel][ts].size(); p++){ - for (int sw =0; sw < fIPRCalculator->getStorageHist()[tel][ts][p].size(); sw++){ - fIPRCalculator->checkHistEmpty(tel, ts, p, sw); - }}}} - - // if the display is run in the loop mode, goto event 0 and start again if( fRunPar->floopmode ) { @@ -1138,7 +1126,6 @@ int VEventLoop::analyzeEvent() cout << "\t now at event " << getEventNumber() << endl; cout << "----------------------------------------" << endl; } - // analysis is running fAnalyzeMode = true; int i_cut = 0; @@ -1309,6 +1296,7 @@ int VEventLoop::analyzeEvent() // analysis case R_ANA: // analysis mode // ignore pedestal events (important for VBF only) + cout << getEventNumber() << endl; #ifndef NOVBF if( fReader->getATEventType() != VEventType::PED_TRIGGER ) #endif @@ -1469,7 +1457,7 @@ int VEventLoop::analyzeEvent() setTelID( fRunPar->fTelToAnalyze[i] ); if( fRunPar->fPedestalsInTimeSlices && !fReader->wasLossyCompressed() ) { - fPedestalCalculator->doAnalysis( fRunMode == R_PEDLOW, fIPRCalculator ); + fPedestalCalculator->doAnalysis( fRunMode == R_PEDLOW ); } } } diff --git a/src/VEvndispRunParameter.cpp b/src/VEvndispRunParameter.cpp index 680e4edfe..fbb148653 100644 --- a/src/VEvndispRunParameter.cpp +++ b/src/VEvndispRunParameter.cpp @@ -197,7 +197,7 @@ VEvndispRunParameter::VEvndispRunParameter( bool bSetGlobalParameter ) : VGlobal ftraceamplitudecorrectionFile = ""; ftracefit = -1.; ftracefitfunction = "ev"; - freconstructionparameterfile = "EVNDISP.reconstruction.runparameter.v4x"; + freconstructionparameterfile = "EVNDISP.reconstruction.runparameter.AP.v4x"; //////////////////////////////////////////////////////////////////////////////// // pulse timing (fraction of maximum where times are determined) @@ -1048,3 +1048,12 @@ unsigned int VEvndispRunParameter::getAtmosphereID( bool iUpdateInstrumentEpoch return fAtmosphereID; } + +string VEvndispRunParameter::getInstrumentATMString() +{ + ostringstream i_temp; + i_temp << getInstrumentEpoch( false ); + i_temp << "_ATM" << getAtmosphereID(); + + return i_temp.str(); +} diff --git a/src/VGammaHadronCuts.cpp b/src/VGammaHadronCuts.cpp index 5cd3c4b9f..2abee2b7b 100644 --- a/src/VGammaHadronCuts.cpp +++ b/src/VGammaHadronCuts.cpp @@ -92,7 +92,6 @@ VGammaHadronCuts::VGammaHadronCuts() fTMVAWeightFileIndex_Emax = 0; fTMVAWeightFileIndex_Zmin = 0; fTMVAWeightFileIndex_Zmax = 0; - fTMVAEnergyStepSize = 0.2; fTMVAWeightFile = ""; fTMVASignalEfficiency.clear(); fTMVA_MVACut.clear(); @@ -386,7 +385,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) if( fNTel == 0 || fNTel > 10 ) { cout << "VGammaHadronCuts::readCuts warning: cut identifier " << temp << " ignored for "; - cout << "current telescope configuration ( " << fNTel << "telescopes)" << endl; + cout << "current telescope configuration ( " << fNTel << " telescopes)" << endl; continue; } // calculate how many possible telescope combinations exist (16 for 4 telescopes) @@ -415,7 +414,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) if( !( is_stream >> std::ws ).eof() ) { is_stream >> temp; - if( temp != fInstrumentEpoch ) + if( fInstrumentEpoch.size() > 1 && temp != fInstrumentEpoch.substr( 0, 2 ) ) { i_useTheseCuts = false; } @@ -563,7 +562,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) if( !( is_stream >> std::ws ).eof() ) { is_stream >> temp; - if( temp == fInstrumentEpoch ) + if( fInstrumentEpoch.size() > 1 && temp == fInstrumentEpoch.substr( 0, 2 ) ) { fCut_SizeSecondMax_min = isize_min; fCut_SizeSecondMax_max = isize_max; @@ -595,7 +594,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) if( !( is_stream >> std::ws ).eof() ) { is_stream >> temp; - if( temp == fInstrumentEpoch ) + if( fInstrumentEpoch.size() > 0 && temp == fInstrumentEpoch.substr( 0, 2 ) ) { while( !( is_stream >> std::ws ).eof() ) { @@ -620,19 +619,17 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) { is_stream >> fTMVAWeightFileIndex_Zmax; } - if( !( is_stream >> std::ws ).eof() ) - { - if( !( is_stream >> fTMVAEnergyStepSize ) ) - { - cout << "VGammaHadronCuts::readCuts: missing TMVAPARAMETER energy step size " << endl; - break; - } - } string iWeightFileDirectory; if( !( is_stream >> std::ws ).eof() ) { is_stream >> iWeightFileDirectory; } + if( fInstrumentEpoch.size() > 1 ) + { + iWeightFileDirectory.replace( + iWeightFileDirectory.find( fInstrumentEpoch.substr( 0, 1 ) ), + 2, fInstrumentEpoch ); + } string iWeightFileName; if( !( is_stream >> std::ws ).eof() ) { @@ -642,7 +639,7 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) // check of path name is complete if( gSystem->AccessPathName( fTMVAWeightFile.c_str() ) ) { - fTMVAWeightFile = VGlobalRunParameter::getDirectory_EVNDISPAnaData() + fTMVAWeightFile; + fTMVAWeightFile = VGlobalRunParameter::getDirectory_EVNDISPAnaDataTMP() + fTMVAWeightFile; if( gSystem->AccessPathName( fTMVAWeightFile.c_str() ) ) { cout << "VGammaHadronCuts::readCuts error,"; @@ -656,11 +653,6 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) break; } } - else if( iPrint != 0 ) - { - cout << "VGammaHadronCuts::readCuts: skipping TMVAPARAMETER due to epoch mismatch:"; - cout << " required: " << fInstrumentEpoch << ", is: " << temp << endl; - } } } else if( iCutVariable == "TMVACUTS" ) @@ -752,7 +744,6 @@ bool VGammaHadronCuts::readCuts( string i_cutfilename, int iPrint ) } } } - //////////////////////////////////////////////////////////////////////////////////////////////////// } //////////////////////////////////////////////////////////////////////////////////////////////////// // direction cut values @@ -897,26 +888,6 @@ void VGammaHadronCuts::printDirectionCuts() cout << "VGammaHadronCuts::printDirectionCuts WARNING: no function found" << endl; } } - // theta cut using TMVA - else if( fDirectionCutSelector == 4 ) - { - cout << "Direction cut from TMVA angular containment optimizer" << endl; - } - else if( fDirectionCutSelector == 3 || fDirectionCutSelector == 5 ) - { - cout << "Direction cut from TMVA " << endl; - if( fDirectionCutSelector == 3 ) - { - cout << "using TMVA evaluator (part of gamma/hadron cuts)" << endl; - } - if( fDirectionCutSelector == 5 ) - { - if( fDirectionCutSelector == 5 && getTheta2Cut_TMVA_max() ) - { - getTheta2Cut_TMVA_max()->Print(); - } - } - } cout << "Direction cut scale factor " << fAngRes_ScalingFactor; cout << ", minimum : " << fAngRes_AbsoluteMinimum << " [deg] "; cout << ", maximum : " << fAngRes_AbsoluteMaximum << " [deg]" << endl; @@ -960,23 +931,23 @@ void VGammaHadronCuts::printCutSummary() { cout << "Shape cuts: "; cout << fCut_MSCW_min << " < MSCW < " << fCut_MSCW_max; - cout << ", " << fCut_MSCL_min << " < MSCL < " << fCut_MSCL_max << ", "; + cout << ", " << fCut_MSCL_min << " < MSCL < " << fCut_MSCL_max << endl; } // mean cuts else if( fGammaHadronCutSelector % 10 == 1 ) { cout << "Shape cuts: "; cout << fCut_MeanImageWidth_min << " < mean width < " << fCut_MeanImageWidth_max; - cout << ", " << fCut_MeanImageLength_min << " < mean length < " << fCut_MeanImageLength_max << ", "; + cout << ", " << fCut_MeanImageLength_min << " < mean length < " << fCut_MeanImageLength_max << endl; } // mean scaled cuts else if( fGammaHadronCutSelector % 10 == 3 ) { cout << "Shape cuts: "; cout << fCut_MSW_min << " < MWR < " << fCut_MSW_max; - cout << ", " << fCut_MSL_min << " < MLR < " << fCut_MSL_max << ", "; + cout << ", " << fCut_MSL_min << " < MLR < " << fCut_MSL_max << endl; } - cout << "average core distance < " << fCut_AverageCoreDistanceToTelescopes_max << " m"; + cout << "Average core distance < " << fCut_AverageCoreDistanceToTelescopes_max << " m"; cout << " (max distance to telescopes (mintel) " << fCut_MinimumCoreDistanceToTelescopes_max << " m)"; // probability cuts if( fGammaHadronCutSelector / 10 >= 1 && fGammaHadronCutSelector / 10 <= 3 ) @@ -1687,7 +1658,9 @@ void VGammaHadronCuts::initializeCuts( int irun, string iFile ) // TMVA cuts else if( useTMVACuts() ) { - if( !initTMVAEvaluator( fTMVAWeightFile, fTMVAWeightFileIndex_Emin, fTMVAWeightFileIndex_Emax, fTMVAWeightFileIndex_Zmin, fTMVAWeightFileIndex_Zmax, fTMVAEnergyStepSize ) ) + if( !initTMVAEvaluator( fTMVAWeightFile, + fTMVAWeightFileIndex_Emin, fTMVAWeightFileIndex_Emax, + fTMVAWeightFileIndex_Zmin, fTMVAWeightFileIndex_Zmax ) ) { cout << "VGammaHadronCuts::initializeCuts: failed setting TMVA reader for " << fTMVAWeightFile; cout << "(" << fTMVAWeightFileIndex_Emin << "," << fTMVAWeightFileIndex_Emax << ")" << endl; @@ -1716,23 +1689,18 @@ void VGammaHadronCuts::initializeCuts( int irun, string iFile ) } } -bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, unsigned int iTMVAWeightFileIndex_Emin, unsigned int iTMVAWeightFileIndex_Emax, - unsigned int iTMVAWeightFileIndex_Zmin, unsigned int iTMVAWeightFileIndex_Zmax, double iTMVAEnergy_StepSize ) +/* + * initialize TMVA evaluator + * + */ +bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, + unsigned int iTMVAWeightFileIndex_Emin, unsigned int iTMVAWeightFileIndex_Emax, + unsigned int iTMVAWeightFileIndex_Zmin, unsigned int iTMVAWeightFileIndex_Zmax ) { TDirectory* cDir = gDirectory; fTMVAEvaluator = new VTMVAEvaluator(); - //EP turn off theta2 optimization except for TMVA direction cut selector flags - if( fDirectionCutSelector == 3 || fDirectionCutSelector == 4 || fDirectionCutSelector == 5 ) - { - fTMVAEvaluator->setOptimizeAngularContainment( true ); - } - else - { - fTMVAEvaluator->setOptimizeAngularContainment( false ); - } - fTMVAEvaluator->setDebug( fDebug ); // smoothing of MVA values fTMVAEvaluator->setSmoothAndInterPolateMVAValues( true ); @@ -1745,7 +1713,8 @@ bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, unsigned int iTMVAWe fTMVAOptimizeSignalEfficiencyObservationTime_h, 1. / 5. ); fTMVAEvaluator->setSensitivityOptimizationFixedSignalEfficiency( fTMVAFixedSignalEfficiencyMax ); - fTMVAEvaluator->setParticleNumberFile( fTMVAOptimizeSignalEfficiencyParticleNumberFile, fTMVAParticleNumberFile_Conversion_Rate_to_seconds ); + fTMVAEvaluator->setParticleNumberFile( + fTMVAOptimizeSignalEfficiencyParticleNumberFile, fTMVAParticleNumberFile_Conversion_Rate_to_seconds ); fTMVAEvaluator->setSensitivityOptimizationMinSourceStrength( fTMVAMinSourceStrength ); } // set a constant signal efficiency @@ -1767,10 +1736,9 @@ bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, unsigned int iTMVAWe exit( EXIT_FAILURE ); } fTMVAEvaluator->setTMVAMethod( fTMVA_MVAMethod ); - fTMVAEvaluator->setTMVAAngularContainmentThetaFixedMinRadius( fTMVAFixedThetaCutMin ); // read MVA weight files; set MVA cut values (e.g. find optimal values) if( !fTMVAEvaluator->initializeWeightFiles( iTMVAFile, iTMVAWeightFileIndex_Emin, iTMVAWeightFileIndex_Emax, - iTMVAWeightFileIndex_Zmin, iTMVAWeightFileIndex_Zmax, iTMVAEnergy_StepSize, fInstrumentEpoch ) ) + iTMVAWeightFileIndex_Zmin, iTMVAWeightFileIndex_Zmax ) ) { cout << "VGammaHadronCuts::initTMVAEvaluator: error while initializing TMVA weight files" << endl; cout << "exiting... " << endl; @@ -1779,22 +1747,6 @@ bool VGammaHadronCuts::initTMVAEvaluator( string iTMVAFile, unsigned int iTMVAWe fTMVAEvaluatorResults = fTMVAEvaluator->getTMVAEvaluatorResults(); fTMVAEvaluator->printSignalEfficiency(); - fTMVAEvaluator->printAngularContainmentRadius(); - - if( fDirectionCutSelector == 3 ) - { - fTMVAEvaluator->setIgnoreTheta2Cut( false ); - } - else - { - fTMVAEvaluator->setIgnoreTheta2Cut( true ); - } - fEnergyDependentCut[ "TMVABoxCut_Theta2_max" ] = fTMVAEvaluator->getOptimalTheta2Cut_Graph(); - if( getTheta2Cut_TMVA_max() ) - { - cout << "VGammaHadronCuts::initTMVAEvaluator: found theta2_max graph from TMVA" << endl; - getTheta2Cut_TMVA_max()->SetName( "TMVAtheta2" ); - } if( cDir ) { @@ -2239,40 +2191,6 @@ double VGammaHadronCuts::getTheta2Cut_max( double e ) theta_cut_max = getEnergyDependentCut( e, getTheta2Cut_IRF_Max(), true ); } - ///////////////////////////////////////////// - // use TMVA determined cut - else if( fDirectionCutSelector == 3 ) - { - theta_cut_max = -1.; - } - // optimal theta2 cut - else if( fDirectionCutSelector == 4 && fTMVAEvaluator ) - { - theta_cut_max = fTMVAEvaluator->getOptimalTheta2Cut( e ); - if( theta_cut_max > 0. ) - { - theta_cut_max = TMath::Sqrt( theta_cut_max ); - } - else - { - theta_cut_max = 0.; - } - } - ///////////////////////////////////////////// - // use a graph with theta2 cuts - else if( fDirectionCutSelector == 5 && getTheta2Cut_TMVA_max() ) - { - theta_cut_max = getEnergyDependentCut( e, getTheta2Cut_TMVA_max(), true, true ); - if( theta_cut_max < 0. ) - { - theta_cut_max = 0.; - } - // set minimum theta2 cut - if( theta_cut_max < fTMVAFixedThetaCutMin ) - { - theta_cut_max = fTMVAFixedThetaCutMin; - } - } } // apply scale factors diff --git a/src/VGlobalRunParameter.cpp b/src/VGlobalRunParameter.cpp index cab9ceff3..f8db071e5 100644 --- a/src/VGlobalRunParameter.cpp +++ b/src/VGlobalRunParameter.cpp @@ -184,7 +184,7 @@ bool VGlobalRunParameter::setDirectories() cout << "VGlobalRunParameter::setDirectories(): cannot find directory with EVNDISP aux data" << endl; cout << "\t looking for " << fEVNDISPAnaDataDirectory << endl; cout << "\t is environmental variable $VERITAS_EVNDISP_AUX_DIR set?" << endl; - cout << "\t (see README/INSTALL)" << endl; + cout << "\t (see INSTALL.md)" << endl; cout << "exiting..." << endl; exit( EXIT_FAILURE ); } @@ -218,11 +218,26 @@ bool VGlobalRunParameter::setDirectories() cout << "VGlobalRunParameter::setDirectories(): cannot find directory for EVNDISP output data" << endl; cout << "\t looking for " << fEVNDISPOutputDirectory << endl; cout << "\t is environmental variable $VERITAS_USER_DATA_DIR set?" << endl; - cout << "\t (see README/INSTALL)" << endl; + cout << "\t (see INSTALL.md)" << endl; cout << "exiting..." << endl; exit( EXIT_FAILURE ); } + ////////////////////////////////////////////////////////////////////// + // some scripts require a temporary directory for auxiliary files + // if note set: use fEVNDISPAnaDataDirectory + // important: no access control here + const char* vtmp_aux = gSystem->Getenv( "VERITAS_EVNDISP_TMP_AUX_DIR" ); + if( vtmp_aux ) + { + fEVNDISPAnaDataDirectory_tmp = vtmp_aux; + fEVNDISPAnaDataDirectory_tmp += "/"; + } + else + { + fEVNDISPAnaDataDirectory_tmp = fEVNDISPAnaDataDirectory; + } + return true; } @@ -314,6 +329,10 @@ void VGlobalRunParameter::printGlobalRunParameter() if( fEVNDISPAnaDataDirectory.size() > 0 ) { cout << " for EVNDISP aux data: \t\t" << fEVNDISPAnaDataDirectory << endl; + if( fEVNDISPAnaDataDirectory_tmp != fEVNDISPAnaDataDirectory ) + { + cout << " for temporary EVNDISP aux data: \t\t" << fEVNDISPAnaDataDirectory_tmp << endl; + } } if( fVBFRawDataDirectory.size() > 0 ) { @@ -346,6 +365,7 @@ string VGlobalRunParameter::fEVNDISP_VERSION = "v.4.90"; string VGlobalRunParameter::fDBServer = ""; string VGlobalRunParameter::fRawDataServer = ""; string VGlobalRunParameter::fEVNDISPAnaDataDirectory = ""; +string VGlobalRunParameter::fEVNDISPAnaDataDirectory_tmp = ""; string VGlobalRunParameter::fEVNDISPCalibrationDataDirectory = ""; string VGlobalRunParameter::fVBFRawDataDirectory = ""; string VGlobalRunParameter::fEVNDISPOutputDirectory = ""; diff --git a/src/VIPRCalculator.cpp b/src/VIPRCalculator.cpp index deb774d78..a1aed9bdc 100644 --- a/src/VIPRCalculator.cpp +++ b/src/VIPRCalculator.cpp @@ -7,9 +7,9 @@ VIPRCalculator::VIPRCalculator() { - fIPRTimeSlices = true; + fIPRTimeSlices = true; fIPRAverageTel = false; - fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements + fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements } void VIPRCalculator::initialize() @@ -28,721 +28,454 @@ void VIPRCalculator::initialize() exit( EXIT_FAILURE ); } - -} - -void VIPRCalculator::definePedestalFile( std::vector fPedFileNameC ) -{ - fPedFile = fPedFileNameC; -} - - -TFile* VIPRCalculator::initializePedestalFile( int i_tel ) -{ - string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); - if( iPedFileName.find( ".root" ) == string::npos ) - { - iPedFileName += ".root"; - } - // open pedestal files - TFile* iPedFile = new TFile( iPedFileName.c_str() ); - if( iPedFile->IsZombie() ) - { - cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; - cout << iPedFileName << endl; - return nullptr; - } - // fpedcal_histo_storagegrams with IPR distributions are either - // i) in a directory called distributions_TelType - // ii) in the current directory - cout << "Telescope type " << getTelType( getTeltoAna()[i_tel] ) << ": "; - cout << "reading IPR histograms for summation window " << getSumWindow(); - cout << " from "; - cout << iPedFileName << endl; - return iPedFile; - -} - -float VIPRCalculator::getTsearch() -{ - float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); - if( getSearchWindowLast() < getNSamples() ) - { - Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] - } - else - { - Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] - } - return Tsearch; -} - -float VIPRCalculator::convertRate( unsigned int i_tel) -{ - // convert to Rate - float nsToSec = 1E-9; - float convToHz = 1.; - if( nsToSec > 0. && getTsearch() > 0. ) - { - convToHz /= ( nsToSec * getTsearch() ); - } - else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice - && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 - && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) - { - // simple peak sensing: sim_telarray uses the maximum bin only - // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file - // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as - // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns - // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. - convToHz /= ( nsToSec - * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice - * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); - } - return convToHz; - -} - - -/* - HANDLING OF IPR FOR NO TIME SLICE CASE - -*/ - -TH1F* VIPRCalculator::initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ) -{ - int iTelType = getTelType( getTeltoAna()[i_tel] ); - //get reference hpedPerTelescopeType for channel 1 - cout << "VIPRCalculator::initializeIPRHistogram initializing IPR graph for calculation of average of telescopes." << endl; - TH1F* hIPR = 0; - - TFile* iPedFile = (TFile*)initializePedestalFile( i_tel ); - if( iPedFile == nullptr ) - { - return hIPR; - } - - // fpedcal_histo_storagegrams with IPR distributions are either - // i) in a directory called distributions_TelType - // ii) in the current directory - //cout << "VIPRCalculator::initializeIPRHistogram Telescope type:" << iTelType << endl; - //cout << "reading IPR histograms for summation window " << iSummationWindow; - - stringstream Directory( stringstream::in | stringstream::out ); - Directory << "distributions_" << iTelType; - if( !iPedFile->Get( Directory.str().c_str() ) ) - { - return hIPR; - } - - // get charge distribution for first channel as reference fpedcal_histo_storagegram - stringstream hIPRname( stringstream::in | stringstream::out ); - hIPRname << "distributions_" << iTelType << "/hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << 1; - - //? - TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); - iPedFile->Close(); - - if( !href ) - { - cout << " Error: cannot find IPR histogram" << hIPRname.str().c_str(); - return hIPR; - } - //summary fpedcal_histo_storagegram - if( getRunParameter()->fIgnoreDSTGains ) - { - // work in dc - hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); - cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; - return hIPR; - } - else - { - // work in pe - hIPR = new TH1F( "", "", 1000, 0., 100. ); - return hIPR; - } -} - -TH1F* VIPRCalculator::FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel) -{ - int iTelType = getTelType( getTeltoAna()[i_tel] ); - TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, i_tel ); - // check suffix of ped file - TFile* iPedFile = (TFile*)initializePedestalFile( i_tel ); - - stringstream i_Directory( stringstream::in | stringstream::out ); - i_Directory << "distributions_" << iTelType; - if( iPedFile->Get( i_Directory.str().c_str() ) ) - { - iPedFile->cd( i_Directory.str().c_str() ); - } - - float i_gainCorrect = 1.; - //hIPR->Reset(); - // //float i_gainCorrect = 1.; - for( unsigned int i = 0; i < getNChannels(); i++ ) - { - if( getDetectorGeometry()->getAnaPixel()[i] > 0 - && i < getDead().size() && !getDead()[i] ) - { - stringstream i_Hname( stringstream::in | stringstream::out ); - i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; - TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); - if( h ) - { - float ped = 0; - // default: pedestals are subtracted here - // (for combined channel analysis: charges are filled already pedestal subtracted) - // apply relative gain correction to integrated charges - if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) - { - ped = getPeds()[i]; - } - for( int j = 1; j <= h->GetNbinsX(); j++ ) - { - if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) - { - i_gainCorrect = getGains()[i]; - if( getHIGHQE_gainfactor( i ) > 0. ) - { - i_gainCorrect *= getHIGHQE_gainfactor( i ); - } - if( i_gainCorrect > 0. ) - { - hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); - } - } - } - } - } - } - iPedFile->Close(); - return hIPR; -} - -/* -IN CASE IPR IS GIVEN AS AVERAGE OF TELESCOPES, FOR TEL > 0 COPY IPR CALCULATED FOR TEL = 0. -*/ - -bool VIPRCalculator::copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ) -{ - int iTelType = getTelType( getTeltoAna()[i_tel] ); - TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); - - setTelID( getTeltoAna()[0] ); - TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); - - setTelID( getTeltoAna()[i_tel] ); - - if( !i_IPRGraph ) - { - cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << iTelType << endl; - return false; - } - if( !i_IPRGraph_Tel0 ) - { - cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; - return false; - } - - for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) - { - i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); - } - - i_IPRGraph->SetMinimum( 1 ); - i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); - i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); - i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); - i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", iTelType, iSummationWindow ) ); - - return true; } -TH1F* VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ) +void VIPRCalculator::definePedestalFile( std::vector fPedFileNameCalibrator ) { - - TH1F* hIPR = ( TH1F* )initializeIPRHistogram(iSummationWindow , 0); - int iTelType = getTelType( getTeltoAna()[i_tel] ); - - for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) - { - setTelID( getTeltoAna()[teltype] ); - - // first find dead channels - // (ignore low gains here) - findDeadChans( false ); - // calculate IPR graphs - TFile* iPedFile = (TFile*)initializePedestalFile( teltype ); - if( iPedFile == nullptr ) - { - cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices error reading IPR graphs from pedestal file "; - TH1F* hNull = 0; - return hNull; - } - - // fpedcal_histo_storagegrams with IPR distributions are either - // i) in a directory called distributions_TelType - // ii) in the current directory - cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices Telescope type " << iTelType << ": "; - stringstream Directory( stringstream::in | stringstream::out ); - Directory.str( std::string() ); - Directory << "distributions_" << iTelType; - if( iPedFile->Get( Directory.str().c_str() ) ) - { - iPedFile->cd( Directory.str().c_str() ); - } - else - { - cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices no directory: " << Directory.str().c_str() << endl; - } - - /////////////////////////// - // average over all channels in one telescope - float i_gainCorrect = 1.; - for( unsigned int i = 0; i < getNChannels(); i++ ) - { - if( getDetectorGeometry()->getAnaPixel()[i] > 0 - && i < getDead().size() && !getDead()[i] ) - { - stringstream HistName( stringstream::in | stringstream::out ); - HistName << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; - TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); - - - if( h ) - { - float ped = 0; - // default: pedestals are subtracted here - // (for combined channel analysis: charges are filled already pedestal subtracted) - // apply relative gain correction to integrated charges - if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) - { - ped = getPeds()[i]; - } - // special treatment for ASTRI telescopes - else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) - { - stringstream Pname( stringstream::in | stringstream::out ); - Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; - TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); - if( hP ) - { - ped = hP->GetMean(); - } - } - for( int j = 1; j <= h->GetNbinsX(); j++ ) - { - if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) - { - if( i == 0){cout << "gain : " << getGains()[i] << endl;} - i_gainCorrect = getGains()[i]; - if( getHIGHQE_gainfactor( i ) > 0. ) - { - i_gainCorrect *= getHIGHQE_gainfactor( i ); - } - if( i_gainCorrect > 0. ) - { - hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); - } - } - } - } - } - } - iPedFile->Close(); - - } - hIPR->Scale( 1. / getTeltoAna().size() ); - float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); - cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices normalization of average IPR fpedcal_histo_storagegram " << norm; - if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts - { - cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices WARNING: there is NOT enough statistics "; - cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; - return hIPR; - } - else - { - cout << "VIPRCalculator::calculateIPRGraphsAveragedNoTimeSlices: there is enough statistics to average over telescopes. " << endl; - return hIPR; - } -} - -TGraphErrors* VIPRCalculator::updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow) -{ - - TGraphErrors* i_IPRGraph = new TGraphErrors( 1 ); - i_IPRGraph->SetTitle( "" ); - - int z = 0; - float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); - for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) - { - if( hIPR->GetBinContent( i ) > 5 ) - { - double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; - double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; - double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); - double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); - - i_IPRGraph->SetPoint( z, charge_pe, val ); - i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); - z++; - } - } - i_IPRGraph->SetMinimum( 1 ); - i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), - getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); - if( getRunParameter()->fIgnoreDSTGains ) - { - i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); - } - else - { - i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); - } - i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); - i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )getTelType( getTeltoAna()[i_tel] ), iSummationWindow ) ); - return i_IPRGraph; + for( unsigned int i = 0; i < fPedFileNameCalibrator.size() ; i++) + { + fPedFileNameC.push_back(fPedFileNameCalibrator[i]); + } } -bool VIPRCalculator::calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ) +bool VIPRCalculator::calculateIPRGraphs(std::vector fPedFileNameCalibrator ) { - TDirectory* iG_CurrentDirectory = gDirectory; - // get an IPR graph - TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); - if( !i_IPRGraph ) - { - cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices info: no IPR graph found for telescope type " << getTelType( getTeltoAna()[i_tel] ) << endl; - return false; - } - - ////////////////////////////////////////////////// - // average over all channels in one telescope - - TH1F *hIPR = (TH1F*)FillIPRHistogram( iSummationWindow, i_tel); - float norm = 0; - if (hIPR) + definePedestalFile(fPedFileNameCalibrator); + for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) { - norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); - cout << "norm: " << norm << endl; + setTelID( getTeltoAna()[i] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + if( fIPRAverageTel == false ) + { + calculateIPRGraphs( fPedFileNameC[getTeltoAna()[i]], getSumWindow(), getTelType( getTeltoAna()[i] ), i ); + } + else + { + copyIPRTelAveraged( getSumWindow(), getTeltoAna()[i], i ); + } } - if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts - { - fIPRAverageTel = true; - cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices WARNING: too few statistics to measure IPR curves "; - cout << "(total counts available: " << norm << ", "; - cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; - cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; - cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; - hIPR = calculateIPRGraphAveragedNoTimeSlices( iSummationWindow, i_tel ); - cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; - } - if( norm == 0 ) - { - cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; - return false; - } - i_IPRGraph = (TGraphErrors*)updateIPRGraph(hIPR, i_tel, iSummationWindow); - hIPR->Delete(); - iG_CurrentDirectory->cd(); - return true; + return true; } - /* + * calculate IPR graphs and write them to disk + * + * (this is done per telescope type) + * + */ - HANDLE IPR CALCULATION IF ASKED FOR IN TIME SLICES - -*/ - -void VIPRCalculator::checkHistEmpty(const int telID, const int ts, const int pixel, const int sw) +bool VIPRCalculator::copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) { - if (fpedcal_histo_storage[telID][ts][pixel][sw]->GetEntries() != 0) + + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[0] ); + TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[i_tel] ); + + if( !i_IPRGraph ) { - cout << "MK " << telID << " " << ts << " " << pixel << " " << sw << " " << fpedcal_histo_storage[telID][ts][pixel][sw]->GetEntries() << endl; + cout << "VIPRCalculator::copyIPRTelAveraged: no IPR graph found for telescope type " << iTelType << endl; + return false; } -} - -vector>>> VIPRCalculator::getStorageHist() -{ - return fpedcal_histo_storage; -} - -void VIPRCalculator::fillIPRPedestalHisto(){ - fpedcal_histo_storage.resize(getTeltoAna().size()); -} - -void VIPRCalculator::fillIPRPedestalHisto(const int telID, const vector>>& fpedcal_histo ) -{ - fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); -} - - -TH1F* VIPRCalculator::getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw){ - - if (fpedcal_histo_storage.empty()){cout << "empty" << endl;} - if(fpedcal_histo_storage[telID][ts][pixel][sw]) + if( !i_IPRGraph_Tel0 ) { - return fpedcal_histo_storage[telID][ts][pixel][sw]; + cout << "VIPRCalculator::copyIPRTelAveraged: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; + return false; } - else + + for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) { - return nullptr; + i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); + i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); + i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); + + return true; + } -//needs sliding window fpedcal_histo_storagegram!! -bool VIPRCalculator::calculateIPRGraphsTimeSlices(const int TimeSlice, const int iSummationWindow, const int i_tel ) +bool VIPRCalculator::calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) { - int iTelType = getTelType( getTeltoAna()[i_tel] ); + TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, getTeltoAna()[i_tel] ); TDirectory* iG_CurrentDirectory = gDirectory; - TGraphErrors* i_IPRGraph = getIPRGraphTimeSlice( true, TimeSlice ); - - TFile* iPedFile = (TFile*)initializePedestalFile( i_tel ); - if(iPedFile == nullptr) + + // get an IPR graph + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + if( !i_IPRGraph ) { - cout << "VIPRCalculator::calculateIPRGraphsTimeSlices could not open pedestal file for telescope: " << iTelType; + cout << "VIPRCalculator::calculateIPRGraphs info: no IPR graph found for telescope type " << iTelType << endl; return false; } - - cout << "VIPRCalculator::calculateIPRGraphsTimeSlices for Telescope type " << iTelType << ": "; - stringstream Directory( stringstream::in | stringstream::out ); - Directory.str( std::string() ); - Directory << "distributions_" << iTelType; - if( iPedFile->Get( Directory.str().c_str() ) ) + // check suffix of ped file + if( iPedFileName.find( ".root" ) == string::npos ) { - iPedFile->cd( Directory.str().c_str() ); + iPedFileName += ".root"; } - else + // open pedestal files + TFile iPedFile( iPedFileName.c_str() ); + if( iPedFile.IsZombie() ) { - cout << "VIPRCalculator::calculateIPRGraphsTimeSlices no directory: " << Directory.str().c_str() << endl; + cout << "VIPRCalculator::calculateIPRGraphs error reading IPR graphs from "; + cout << iPedFileName << endl; + return false; } + // histograms with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << iTelType << ": "; + cout << "reading IPR histograms for summation window " << iSummationWindow; + cout << " from "; + cout << iPedFileName << endl; - //Simplify: always do this in digital counts. No need to check for initialization. - TH1F *hIPR = new TH1F( "", "", 1000, 0., 100. ); - float i_gainCorrect = 1.; + stringstream i_Directory( stringstream::in | stringstream::out ); + i_Directory << "distributions_" << iTelType; + if( iPedFile.Get( i_Directory.str().c_str() ) ) + { + iPedFile.cd( i_Directory.str().c_str() ); + } + hIPR->Reset(); + + ////////////////////////////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; for( unsigned int i = 0; i < getNChannels(); i++ ) { - if( getDetectorGeometry()->getAnaPixel()[i] > 0 && i < getDead().size() && !getDead()[i] ) + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) { - stringstream i_Hname( stringstream::in | stringstream::out ); - i_Hname << "hped_Tel" << iTelType << "_TS" << TimeSlice << "_Pix" << i << "_SW" << iSummationWindow; - TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); - - if(h) + i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + + if( h ) { float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) { - ped = getCalData()->getPedsTS_vector( false )[TimeSlice][i]; + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream i_Pname( stringstream::in | stringstream::out ); + i_Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( i_Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } } - for( unsigned int j = 1; j <= h->GetNbinsX(); j++ ) - { + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) - { - i_gainCorrect = getGains()[i]; - if( getHIGHQE_gainfactor( i ) > 0. ) - { - i_gainCorrect *= getHIGHQE_gainfactor( i ); - } - if( i_gainCorrect > 0. ) - { - //hIPR->Fill( ( h[i_tel][TimeSlice][i][iSummationWindow]->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h[i_tel][TimeSlice][i][iSummationWindow]->GetBinContent( j ) ); - hIPR->Fill( ( h->GetBinCenter( 0 ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( 0 ) ); - } - } - } + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } } } } - int z = 0; - float norm = 0; - if (hIPR) - { - norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); - cout << "norm: " << norm << endl; - } - if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts - { - fIPRAverageTel = true; - cout << "VIPRCalculator::calculateIPRGraphTimeSlices WARNING: too few statistics to measure IPR curves "; - cout << "(total counts available: " << norm << ", "; - cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; - cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; - cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; - //hIPR = calculateIPRGraphAveragedNoTimeSlices( fPedFileNameC , iSummationWindow, i_tel ); - cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; - } - if( norm == 0 ) - { - cout << "VIPRCalculator::calculateIPRGraphsTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; - return false; - } - - for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) - { - if( hIPR->GetBinContent( i ) > 5 ) - { - double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; - double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; - double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); - double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); - - i_IPRGraph->SetPoint( z, charge_pe, val ); - i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); - z++; - } - } - i_IPRGraph->SetMinimum( 1 ); - i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), - getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); - if( getRunParameter()->fIgnoreDSTGains ) - { - i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); - } - else - { - i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); - } - i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); - i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d_TS%d", iTelType, iSummationWindow, TimeSlice ) ); - hIPR->Delete(); - iPedFile->Close(); - iG_CurrentDirectory->cd(); - - return true; - -} - -/* - * calculate IPR graphs and write them to disk - * - * (loop over all telescopes) - * -*/ - -bool VIPRCalculator::calculateIPRGraphs(std::vector fPedFileNameC) -{ - - definePedestalFile(fPedFileNameC); - for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) - { - setTelID( getTeltoAna()[i] ); - - // first find dead channels - // (ignore low gains here) - findDeadChans( false ); - // calculate IPR graphs - if( fIPRAverageTel == false ) - { - calculateIPRGraphsNoTimeSlices( getSumWindow(), i ); - } - else - { - copyIPRInitialized( getSumWindow(), i ); - } - - if(fIPRTimeSlices){ - for (unsigned int ts = 0 ; ts < getCalData()->getPedsTS_vector( false ).size() ; ts++ ) - { - cout << "MK ts: " << getCalData()->getPedsTS_vector( false ).size() << endl; - calculateIPRGraphsTimeSlices( ts, getSumWindow(), i); - } + + int z = 0; + float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "Telescope " << iTelType << ": "; + cout << "VIPRCalculator::calculateIPRGraphs WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphs(): fIPRAverageTel = " << fIPRAverageTel << endl; + hIPR = calculateIPRGraphAveraged( iSummationWindow ); + cout << "VIPRCalculator::calculateIPRGraphs norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphs ERROR: no counts in IPR histogram !" << endl; + return false; + } + // convert to Rate + float nsToSec = 1E-9; + float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); + if( getSearchWindowLast() < getNSamples() ) + { + Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] + } + else + { + Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] + } + float convToHz = 1.; + if( nsToSec > 0. && Tsearch > 0. ) + { + convToHz /= ( nsToSec * Tsearch ); + } + else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) + { + // simple peak sensing: sim_telarray uses the maximum bin only + // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file + // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as + // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns + // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. + convToHz /= ( nsToSec + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); + } + + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convToHz * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convToHz * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; } - } - return true; + } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", Tsearch, + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); + hIPR->Delete(); + + iPedFile.Close(); + + iG_CurrentDirectory->cd(); + + return true; } - -/* - * - * write IPR graphs to disk (one per telescope type) - * - */ -bool VIPRCalculator::writeIPRgraphs( map>> &hped_vec, string iFile ) +TH1F* VIPRCalculator::initializeIPRHistogram( unsigned int iSummationWindow, unsigned int iTelType ) { - TFile* fgraphs = 0; - if( iFile.size() == 0 ) + //get reference hpedPerTelescopeType for channel 1 + cout << "VIPRCalculator::initializeIPRHistogram initializing IPR graph for calculation of average of telescopes." << endl; + TH1F* hIPR = 0; + + + int TelType = getTelType( iTelType ); + string PedFile_name = fPedFileNameC[iTelType]; + + // check suffix of ped file + if( PedFile_name.find( ".root" ) == string::npos ) { - fgraphs = new TFile( getRunParameter()->fIPRdatabaseFile, "RECREATE" ); + PedFile_name += ".root"; } - else + // open pedestal files + TFile PedFile( PedFile_name.c_str() ); + + if( PedFile.IsZombie() ) + { + cout << "VIPRCalculator::calculateIPRGraphsStatistics: error reading IPR graphs from "; + cout << PedFile_name << endl; + return hIPR; + } + + // histograms with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << TelType << ": "; + cout << "reading IPR histograms for summation window " << iSummationWindow; + cout << " from "; + cout << PedFile_name << endl; + + stringstream Directory( stringstream::in | stringstream::out ); + Directory << "distributions_" << TelType; + if( !PedFile.Get( Directory.str().c_str() ) ) { - fgraphs = new TFile( iFile.c_str(), "UPDATE" ); + return hIPR; } - if( fgraphs->IsZombie() ) + + // get charge distribution for first channel as reference histogram + stringstream hIPRname( stringstream::in | stringstream::out ); + hIPRname << "distributions_" << TelType << "/hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << 1; + + //? + TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); + PedFile.Close(); + + if( !href ) { - cout << "VIPRCalculator::writeIPRgraphs error opening IPR output file: " << endl; - cout << "\t" << fgraphs->GetName() << endl; - return false; + cout << " Error: cannot find IPR histogram " << hIPRname.str().c_str(); + cout << " in file:" << PedFile_name << " ... exiting " << endl; + return hIPR; } - // tree with conditions for these IRPs - TTree* header = new TTree( "IPRheader", "IPR parameters" ); - unsigned int sumwin = 0; // [FADC slices] - unsigned int Nsamples = 0; // [FADC slices] - float ROwin = 0.; // [ns] - float FADCslice = 0.; // [ns] - unsigned int SignalExtractor = 0; // [ Selected Extractor ] - header->Branch( "SignalExtractor", &SignalExtractor, "SignalExtractor/i" ); - header->Branch( "SummationWindow", &sumwin, "SummationWindow/i" ); - header->Branch( "Nsamples", &Nsamples, "Nsamples/i" ); - header->Branch( "FADCtimeSlice", &FADCslice, "FADCtimeSlice/F" ); - header->Branch( "ReadoutWindow", &ROwin, "ReadoutWindow/F" ); - // one graph per telescope ID - map< ULong64_t, bool > iTelDone; - for( unsigned int i = 0; i < getDetectorGeometry()->getTelType_list().size(); i++ ) + //summary histogram + if( getRunParameter()->fIgnoreDSTGains ) + { + // work in dc + hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); + cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; + return hIPR; + } + else { - iTelDone[getDetectorGeometry()->getTelType_list()[i]] = false; + // work in pe + hIPR = new TH1F( "", "", 1000, 0., 100. ); + return hIPR; } +} + +TH1F* VIPRCalculator::calculateIPRGraphAveraged( unsigned int iSummationWindow ) +{ + + TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, getTeltoAna()[0] ); - for( unsigned int i = 0; i < getNTel(); i++ ) + for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) { - setTelID( i ); - if( iTelDone[getTelType( i )] ) + setTelID( getTeltoAna()[teltype] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + string PedFile_name = fPedFileNameC[getTeltoAna()[teltype]]; + int TelType = getTelType( getTeltoAna()[teltype] ); + + if( PedFile_name.find( ".root" ) == string::npos ) { - continue; + PedFile_name += ".root"; } - - if( hped_vec.find( getTelType( i ) ) == hped_vec.end() ) + // open pedestal files + TFile PedFile( PedFile_name.c_str() ); + if( PedFile.IsZombie() ) { - continue; + cout << "VIPRCalculator::calculateIPRGraphAveraged error reading IPR graphs from "; + cout << PedFile_name << endl; + TH1F* hNull = 0; + return hNull; + } + // histograms with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "VIPRCalculator::calculateIPRGraphAveraged Telescope type " << TelType << ": "; + cout << "reading IPR histograms for summation window " << iSummationWindow; + cout << " from "; + cout << PedFile_name << endl; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << TelType; + cout << Directory.str().c_str() << endl; + if( PedFile.Get( Directory.str().c_str() ) ) + { + PedFile.cd( Directory.str().c_str() ); + } + else + { + cout << "VIPRCalculator::calculateIPRGraphAveraged no directory: " << Directory.str().c_str() << endl; } - // loop over all summation windows - for( unsigned int j = 0; j < hped_vec[getTelType( i )].size(); j++ ) + /////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) { - // summation window - int i_sw = j + 1; - - TGraphErrors* g = getIPRGraph( i_sw, false ); - if( !g ) + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) { - continue; + stringstream HistName( stringstream::in | stringstream::out ); + HistName << "hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); + + + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream Pname( stringstream::in | stringstream::out ); + Pname << "hped_" << TelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } } - SignalExtractor = getRunParameter()->fTraceIntegrationMethod.at( getTelID() ); - sumwin = i_sw; - Nsamples = getNSamples(); - FADCslice = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); //[ns] - ROwin = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * ( float )getNSamples(); // [ns] - - header->Fill(); - g->Write(); } + PedFile.Close(); - iTelDone[getTelType( i )] = true; } - header->Write(); - fgraphs->Close(); - fgraphs->Delete(); - - return true; + hIPR->Scale( 1. / getTeltoAna().size() ); + float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "VIPRCalculator::calculateIPRGraphAveraged normalization of average IPR histogram " << norm; + cout << ". Returning IPR histogram." << endl; + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + cout << "VIPRCalculator::calculateIPRGraphAveraged WARNING: there is NOT enough statistics "; + cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; + return hIPR; + } + else + { + cout << "VIPRCalculator::calculateIPRGraphsStatistics: there is enough statistics to average over telescopes. " << endl; + return hIPR; + } } + diff --git a/src/VIPRCalculator.cpp.bak b/src/VIPRCalculator.cpp.bak new file mode 100644 index 000000000..4c233c0fa --- /dev/null +++ b/src/VIPRCalculator.cpp.bak @@ -0,0 +1,830 @@ +/*! \class IPRCalculator + * \brief calculation and save IPR GRAPH + * + * */ + +#include "VIPRCalculator.h" + +VIPRCalculator::VIPRCalculator() +{ + fIPRTimeSlices = true; + fIPRAverageTel = false; + fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements +} + +void VIPRCalculator::initialize() +{ + if( fDebug ) + { + cout << "VIPRCalculator::initialize()" << endl; + } + + // set the data readers + initializeDataReader(); + if( !initializeDataReader() ) + { + cout << "VIPRCalculator::initialize, error: cannot initialize data readers" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + + +} + +void VIPRCalculator::definePedestalFile( std::vector fPedFileNameC ) +{ + fPedFile = fPedFileNameC; +} + + +TFile* VIPRCalculator::initializePedestalFile( int i_tel ) +{ + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return nullptr; + } + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << getTelType( getTeltoAna()[i_tel] ) << ": "; + cout << "reading IPR histograms for summation window " << getSumWindow(); + cout << " from "; + cout << iPedFileName << endl; + return iPedFile; + +} + +float VIPRCalculator::getTsearch() +{ + float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); + if( getSearchWindowLast() < getNSamples() ) + { + Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] + } + else + { + Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] + } + return Tsearch; +} + +float VIPRCalculator::convertRate( unsigned int i_tel) +{ + // convert to Rate + float nsToSec = 1E-9; + float convToHz = 1.; + if( nsToSec > 0. && getTsearch() > 0. ) + { + convToHz /= ( nsToSec * getTsearch() ); + } + else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) + { + // simple peak sensing: sim_telarray uses the maximum bin only + // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file + // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as + // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns + // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. + convToHz /= ( nsToSec + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); + } + return convToHz; + +} + + +/* + HANDLING OF IPR FOR NO TIME SLICE CASE + +*/ + +TH1F* VIPRCalculator::initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + //get reference hpedPerTelescopeType for channel 1 + cout << "VIPRCalculator::initializeIPRHistogram initializing IPR graph for calculation of average of telescopes." << endl; + TH1F* hIPR = 0; + + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return hIPR; + } + + stringstream Directory( stringstream::in | stringstream::out ); + Directory << "distributions_" << iTelType; + if( !iPedFile->Get( Directory.str().c_str() ) ) + { + return hIPR; + } + + // get charge distribution for first channel as reference fpedcal_histo_storagegram + stringstream hIPRname( stringstream::in | stringstream::out ); + hIPRname << "distributions_" << iTelType << "/hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << 1; + + //? + TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); + iPedFile->Close(); + + if( !href ) + { + cout << " Error: cannot find IPR histogram" << hIPRname.str().c_str(); + return hIPR; + } + //summary fpedcal_histo_storagegram + if( getRunParameter()->fIgnoreDSTGains ) + { + // work in dc + hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); + cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; + return hIPR; + } + else + { + // work in pe + hIPR = new TH1F( "", "", 1000, 0., 100. ); + return hIPR; + } +} + +TH1F* VIPRCalculator::FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, i_tel ); + // check suffix of ped file + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return hIPR; + } + + stringstream i_Directory( stringstream::in | stringstream::out ); + i_Directory << "distributions_" << iTelType; + if( iPedFile->Get( i_Directory.str().c_str() ) ) + { + iPedFile->cd( i_Directory.str().c_str() ); + } + + float i_gainCorrect = 1.; + //hIPR->Reset(); + // //float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + iPedFile->Close(); + return hIPR; +} + +/* +IN CASE IPR IS GIVEN AS AVERAGE OF TELESCOPES, FOR TEL > 0 COPY IPR CALCULATED FOR TEL = 0. +*/ + +bool VIPRCalculator::copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[0] ); + TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[i_tel] ); + + if( !i_IPRGraph ) + { + cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << iTelType << endl; + return false; + } + if( !i_IPRGraph_Tel0 ) + { + cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; + return false; + } + + for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) + { + i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); + } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); + i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); + i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", iTelType, iSummationWindow ) ); + + return true; + +} + +TH1F* VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ) +{ + + TH1F* hIPR = ( TH1F* )initializeIPRHistogram(iSummationWindow , 0); + int iTelType = getTelType( getTeltoAna()[i_tel] ); + + for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) + { + setTelID( getTeltoAna()[teltype] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + // TFile* iPedFile = (TFile*)initializePedestalFile( teltype ); + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return nullptr; + } + + if( iPedFile == nullptr ) + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices error reading IPR graphs from pedestal file "; + TH1F* hNull = 0; + return hNull; + } + + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices Telescope type " << iTelType << ": "; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << iTelType; + if( iPedFile->Get( Directory.str().c_str() ) ) + { + iPedFile->cd( Directory.str().c_str() ); + } + else + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices no directory: " << Directory.str().c_str() << endl; + } + + /////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream HistName( stringstream::in | stringstream::out ); + HistName << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); + + + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream Pname( stringstream::in | stringstream::out ); + Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + if( i == 0){cout << "gain : " << getGains()[i] << endl;} + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + iPedFile->Close(); + + } + hIPR->Scale( 1. / getTeltoAna().size() ); + float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices normalization of average IPR fpedcal_histo_storagegram " << norm; + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices WARNING: there is NOT enough statistics "; + cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; + return hIPR; + } + else + { + cout << "VIPRCalculator::calculateIPRGraphsAveragedNoTimeSlices: there is enough statistics to average over telescopes. " << endl; + return hIPR; + } +} + +TGraphErrors* VIPRCalculator::updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow) +{ + + TGraphErrors* i_IPRGraph = new TGraphErrors( 1 ); + i_IPRGraph->SetTitle( "" ); + + int z = 0; + float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )getTelType( getTeltoAna()[i_tel] ), iSummationWindow ) ); + return i_IPRGraph; +} + +bool VIPRCalculator::calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ) +{ + TDirectory* iG_CurrentDirectory = gDirectory; + + // get an IPR graph + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + if( !i_IPRGraph ) + { + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices info: no IPR graph found for telescope type " << getTelType( getTeltoAna()[i_tel] ) << endl; + return false; + } + + ////////////////////////////////////////////////// + // average over all channels in one telescope + TH1F *hIPR = 0; +// TH1F *hIPR = (TH1F*)FillIPRHistogram( iSummationWindow, i_tel); + float norm = 0; + if (hIPR) + { + norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "norm: " << norm << endl; + } + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; + hIPR = calculateIPRGraphAveragedNoTimeSlices( iSummationWindow, i_tel ); + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; + return false; + } + //i_IPRGraph = (TGraphErrors*)updateIPRGraph(hIPR, i_tel, iSummationWindow); + + int z = 0; + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )getTelType( getTeltoAna()[i_tel] ), iSummationWindow ) ); + hIPR->Delete(); + iG_CurrentDirectory->cd(); + return true; +} + + +/* + + HANDLE IPR CALCULATION IF ASKED FOR IN TIME SLICES + +*/ + +void VIPRCalculator::checkHistEmpty(const int telID, const int ts, const int pixel, const int sw) +{ + if (fpedcal_histo_storage[telID][ts][pixel][sw]->GetEntries() != 0) + { + cout << "MK " << telID << " " << ts << " " << pixel << " " << sw << " " << fpedcal_histo_storage[telID][ts][pixel][sw]->GetEntries() << endl; + } +} + +vector>>> VIPRCalculator::getStorageHist() +{ + return fpedcal_histo_storage; +} + +void VIPRCalculator::fillIPRPedestalHisto(){ + fpedcal_histo_storage.resize(getTeltoAna().size()); +} + +void VIPRCalculator::fillIPRPedestalHisto(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ) +{ + fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); + if(false) + { + vector< vector< TH1F* > > v1; + for (int p = 0 ; p < getNChannels(); p++) + { + vector< TH1F* > v2; + for (int sw = 0 ; sw < 3; sw++) + { + if( fpedcal_histo[telID][p][sw] ) + { + v2.push_back( (TH1F*)fpedcal_histo[telID][p][sw]->Clone() ) ; + } + } + v1.push_back(v2); + v2.clear(); + } + fpedcal_histo_storage[telID].push_back(v1); + v1.clear(); + } +} + +void VIPRCalculator::clearHistos() +{ + fpedcal_histo_storage.clear(); + //vector>>>().swap(fpedcal_histo_storage); + +} + +TH1F* VIPRCalculator::getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw){ + + if (fpedcal_histo_storage.empty()){cout << "empty" << endl;} + if(fpedcal_histo_storage[telID][ts][pixel][sw]) + { + return fpedcal_histo_storage[telID][ts][pixel][sw]; + } + else + { + return nullptr; + } +} + +//needs sliding window fpedcal_histo_storagegram!! +bool VIPRCalculator::calculateIPRGraphsTimeSlices(const int TimeSlice, const int iSummationWindow, const int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TDirectory* iG_CurrentDirectory = gDirectory; + TGraphErrors* i_IPRGraph = getIPRGraphTimeSlice( true, TimeSlice ); + + TFile* iPedFile = (TFile*)initializePedestalFile( i_tel ); + if(iPedFile == nullptr) + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices could not open pedestal file for telescope: " << iTelType; + return false; + } + + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices for Telescope type " << iTelType << ": "; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << iTelType; + if( iPedFile->Get( Directory.str().c_str() ) ) + { + iPedFile->cd( Directory.str().c_str() ); + } + else + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices no directory: " << Directory.str().c_str() << endl; + } + /* + //Simplify: always do this in digital counts. No need to check for initialization. + TH1F *hIPR = new TH1F( "", "", 1000, 0., 100. ); + float i_gainCorrect = 1.; + + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 && i < getDead().size() && !getDead()[i] ) + { + + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hped_Tel" << iTelType << "_TS" << TimeSlice << "_Pix" << i << "_SW" << iSummationWindow; + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + + if(h) + { + float ped = 0; + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getCalData()->getPedsTS_vector( false )[TimeSlice][i]; + } + for( unsigned int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + //hIPR->Fill( ( h[i_tel][TimeSlice][i][iSummationWindow]->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h[i_tel][TimeSlice][i][iSummationWindow]->GetBinContent( j ) ); + hIPR->Fill( ( h->GetBinCenter( 0 ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( 0 ) ); + } + } + } + } + } + } + int z = 0; + float norm = 0; + if (hIPR) + { + norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "norm: " << norm << endl; + } + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "VIPRCalculator::calculateIPRGraphTimeSlices WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; + //hIPR = calculateIPRGraphAveragedNoTimeSlices( fPedFileNameC , iSummationWindow, i_tel ); + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; + return false; + } + + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d_TS%d", iTelType, iSummationWindow, TimeSlice ) ); + hIPR->Delete(); + iPedFile->Close(); + iG_CurrentDirectory->cd(); */ + iPedFile->Close(); + return true; + +} + +/* + * calculate IPR graphs and write them to disk + * + * (loop over all telescopes) + * +*/ + +bool VIPRCalculator::calculateIPRGraphs(std::vector fPedFileNameC) +{ + + definePedestalFile(fPedFileNameC); + for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) + { + setTelID( getTeltoAna()[i] ); + cout << "11111111111" << endl; + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + if( fIPRAverageTel == false ) + { + calculateIPRGraphsNoTimeSlices( getSumWindow(), i ); + } + else + { + copyIPRInitialized( getSumWindow(), i ); + } + + /*if(false){ + for (unsigned int ts = 0 ; ts < getCalData()->getPedsTS_vector( false ).size() ; ts++ ) + { + cout << "MK ts: " << getCalData()->getPedsTS_vector( false ).size() << endl; + calculateIPRGraphsTimeSlices( ts, getSumWindow(), i); + } + }*/ + } + return true; +} + + +/* + * + * write IPR graphs to disk (one per telescope type) + * + */ +bool VIPRCalculator::writeIPRgraphs( map>> &hped_vec, string iFile ) +{ + TFile* fgraphs = 0; + if( iFile.size() == 0 ) + { + fgraphs = new TFile( getRunParameter()->fIPRdatabaseFile, "RECREATE" ); + } + else + { + fgraphs = new TFile( iFile.c_str(), "UPDATE" ); + } + if( fgraphs->IsZombie() ) + { + cout << "VIPRCalculator::writeIPRgraphs error opening IPR output file: " << endl; + cout << "\t" << fgraphs->GetName() << endl; + return false; + } + + // tree with conditions for these IRPs + TTree* header = new TTree( "IPRheader", "IPR parameters" ); + unsigned int sumwin = 0; // [FADC slices] + unsigned int Nsamples = 0; // [FADC slices] + float ROwin = 0.; // [ns] + float FADCslice = 0.; // [ns] + unsigned int SignalExtractor = 0; // [ Selected Extractor ] + header->Branch( "SignalExtractor", &SignalExtractor, "SignalExtractor/i" ); + header->Branch( "SummationWindow", &sumwin, "SummationWindow/i" ); + header->Branch( "Nsamples", &Nsamples, "Nsamples/i" ); + header->Branch( "FADCtimeSlice", &FADCslice, "FADCtimeSlice/F" ); + header->Branch( "ReadoutWindow", &ROwin, "ReadoutWindow/F" ); + + // one graph per telescope ID + map< ULong64_t, bool > iTelDone; + for( unsigned int i = 0; i < getDetectorGeometry()->getTelType_list().size(); i++ ) + { + iTelDone[getDetectorGeometry()->getTelType_list()[i]] = false; + } + + for( unsigned int i = 0; i < getNTel(); i++ ) + { + setTelID( i ); + if( iTelDone[getTelType( i )] ) + { + continue; + } + + if( hped_vec.find( getTelType( i ) ) == hped_vec.end() ) + { + continue; + } + + // loop over all summation windows + for( unsigned int j = 0; j < hped_vec[getTelType( i )].size(); j++ ) + { + // summation window + int i_sw = j + 1; + + TGraphErrors* g = getIPRGraph( i_sw, false ); + if( !g ) + { + continue; + } + SignalExtractor = getRunParameter()->fTraceIntegrationMethod.at( getTelID() ); + sumwin = i_sw; + Nsamples = getNSamples(); + FADCslice = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); //[ns] + ROwin = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * ( float )getNSamples(); // [ns] + + header->Fill(); + g->Write(); + } + + iTelDone[getTelType( i )] = true; + } + header->Write(); + fgraphs->Close(); + fgraphs->Delete(); + + return true; +} diff --git a/src/VImageBaseAnalyzer.cpp b/src/VImageBaseAnalyzer.cpp index 6546918e8..8e61f0053 100644 --- a/src/VImageBaseAnalyzer.cpp +++ b/src/VImageBaseAnalyzer.cpp @@ -863,17 +863,6 @@ void VImageBaseAnalyzer::findDeadChans( bool iLowGain, bool iFirst ) } // reset dead channel vector - /* - // this is duplicated code, simplify - if( fRunPar->fMCNdead && iFirst ) - { - setDead( false, iLowGain ); - } - else - { - setDead( false, iLowGain ); - } - */ setDead( false, iLowGain ); // get mean and rms of pedvar diff --git a/src/VImageCleaning.cpp b/src/VImageCleaning.cpp index b483140c6..27d52a18a 100644 --- a/src/VImageCleaning.cpp +++ b/src/VImageCleaning.cpp @@ -22,21 +22,8 @@ VImageCleaning::VImageCleaning( VEvndispData* iData ) if( fData && fData->getImageCleaningParameter()->getImageCleaningMethod() == "TIMENEXTNEIGHBOUR" ) { kInitNNImageCleaning = InitNNImageCleaning(); - cout << "1" << endl; - //if ( fIPRTimeSlices ) - if ( true ) - { - fIPRTSgraphs.resize(VDST_PEDTIMESLICES); - for (unsigned int i = 0; i < fIPRTSgraphs.size(); ++i) { - //fIPRTSgraphs[i].push_back(new TObjArray( VDST_MAXTELTYPES )); - fIPRTSgraphs[i] = new TObjArray( VDST_MAXTELTYPES ); - } - cout << typeid(fIPRTSgraphs[0]).name() << endl; - cout << "finished resizing" << endl; - } - fIPRgraphs = new TObjArray( VDST_MAXTELTYPES ); - + fIPRgraphs_xmax.assign( VDST_MAXTELTYPES, 0. ); } fWriteGraphToFileRecreate = true; @@ -48,6 +35,11 @@ VImageCleaning::VImageCleaning( VEvndispData* iData ) fMinRate[i] = 0.; fifActiveNN.push_back( i_tempB ); } + fIPR_save_mincharge = -99.; + fIPR_save_dT_from_probCurve = -99.; + fIPR_save_telid = 99; + fIPR_save_ProbCurve_par1 = -99.; + fIPR_save_ProbCurve_par2 = -99.; } @@ -357,49 +349,41 @@ void VImageCleaning::cleanImagePedvarsTimeDiff( VImageCleaningRunParameter* iIma // preliminary /* - * calculate maximum and position of maximum - * in a float array + * calculate maximum of a float array */ -int VImageCleaning::LocMax( int n, float* ptr, float& max ) +void VImageCleaning::LocMax( int n, float* ptr, float& max ) { if( n <= 0 ) { - return -1; + return; } max = ptr[0]; - Int_t xmax = 0; for( Int_t i = 1; i < n; i++ ) { if( max < ptr[i] ) { max = ptr[i]; - xmax = i; } } - return xmax; } /* - * calculate minimum and position of minimum - * in a float array + * calculate minimum of a float array */ -int VImageCleaning::LocMin( int n, float* ptr, float& min ) //ptr[i]>0 +void VImageCleaning::LocMin( int n, float* ptr, float& min ) //ptr[i]>0 { if( n <= 0 ) { - return -1; + return; } min = ptr[0]; - Int_t xmin = 0; for( Int_t i = 1; i < n; i++ ) { if( min > ptr[i] ) { min = ptr[i]; - xmin = i; } } - return xmin; } //***************************************************************************************************** @@ -440,36 +424,6 @@ bool VImageCleaning::InitNNImageCleaning() } -/* - * Initialize IPR graph per telescope and time slice - */ - -bool VImageCleaning::InitNNImgClnPerTelTypeTimeSlice( unsigned int teltype, unsigned int ts ) -{ - - TGraphErrors* IPRgraph = NULL; - IPRgraph = fData->getIPRGraphTimeSlice( false, ts ); - if( IPRgraph ) - { - cout << "\t found graph: " << IPRgraph->GetName() << endl; - IPRgraph->SetName( Form( "IPRchargeTelType%dTS%d", teltype, ts ) ); - } - else - { - cout << "VImageCleaning::InitNNImgClnPerTelTypeTimeSlice( int type ) ERROR: IPR graph is NULL for teltype " << teltype << " and time slice " << ts << " !!!" << endl; - ////printDataError( "" ); - } - //*** - if(fIPRTSgraphs[ts]){ - fIPRTSgraphs[ts]->AddAt(IPRgraph, teltype); - } - //cout << "IPR for TelType (TrigSim, TIMENEXTNEIGHBOUR): " << teltype << " read: " << IPRgraph->GetName(); - cout << endl; - return true; - -} - - /* get IPR graphs from different sources (files), calculate probability contours @@ -478,28 +432,12 @@ bool VImageCleaning::InitNNImgClnPerTelType( unsigned int teltype ) { // reading IPR graphs TGraphErrors* IPRgraph = NULL; - // get ready filled IPR from DST or pedestal file - if( fData->getRunParameter()->ifReadIPRfromDSTFile ) - { - cout << "VImageCleaning::InitNNImgClnPerTelType( int type ): getting IPR graph for (simtel) teltype: "; - cout << teltype << " (type " << ( int )fData->getTelType( fData->getTelID() ); - cout << ", summation window " << fData->getSumWindow() << ") from DST file" << endl; - - - IPRgraph = fData->getIPRGraph(); - - if( IPRgraph ) - { - cout << "\t found graph: " << IPRgraph->GetName() << endl; - } - } - else if( !fData->getRunParameter()->ifReadIPRfromDatabase ) + if( !fData->getRunParameter()->ifReadIPRfromDatabase ) { cout << "VImageCleaning::InitNNImgClnPerTelType( int type ): getting IPR graph for teltype: "; cout << teltype << " from external file (ped or DST file)" << endl; IPRgraph = fData->getIPRGraph(); - if( IPRgraph ) { IPRgraph->SetName( Form( "IPRchargeTelType%d", teltype ) ); @@ -521,6 +459,17 @@ bool VImageCleaning::InitNNImgClnPerTelType( unsigned int teltype ) printDataError( "" ); } fIPRgraphs->AddAt( IPRgraph, teltype ); + if( teltype < fIPRgraphs_xmax.size() ) + { + fIPRgraphs_xmax[teltype] = IPRgraph->GetXaxis()->GetXmax(); + } + else + { + cout << "Error filling IPR graphs required for NN cleaning "; + cout << "(" << teltype << ")" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } cout << "IPR for TelType (TrigSim, TIMENEXTNEIGHBOUR): " << teltype << " read: " << IPRgraph->GetName(); cout << endl; @@ -567,7 +516,7 @@ bool VImageCleaning::InitNNImgClnPerTelType( unsigned int teltype ) // number of combinations // (this number is scaled to the size of the camera later) float CombFactor[5] = {60000.*20., 950000., 130000., 12000., 2.}; //for 2400 pixels - float ChargeMax = IPRgraph->GetXaxis()->GetXmax(); + float ChargeMax = fIPRgraphs_xmax[teltype]; // define rate contour functions fProb4nnCurves->AddAt( defineRateContourFunction( teltype, "ProbCurve4nn", fMinRate, 4, CombFactor[0], 0, ChargeMax ), ( int )teltype ); @@ -577,7 +526,7 @@ bool VImageCleaning::InitNNImgClnPerTelType( unsigned int teltype ) fProbBoundCurves->AddAt( defineRateContourBoundFunction( teltype, "ProbCurveBound", fMinRate, 4.0, CombFactor[4], 0, ChargeMax ), ( int )teltype ); cout << "Fake image probability: " << fFakeImageProb << " NgroupTypes: " << NgroupTypes; - cout << " teltype " << teltype << " ChargeMax:" << IPRgraph->GetXaxis()->GetXmax() << " Min rate: " << fMinRate; + cout << " teltype " << teltype << " ChargeMax:" << ChargeMax << " Min rate: " << fMinRate; cout << std::endl; ///////////////////////////////////////////////////////////////////////// @@ -590,7 +539,6 @@ bool VImageCleaning::InitNNImgClnPerTelType( unsigned int teltype ) iFileN = "RECREATE"; } ostringstream i_NNGraphFileName; - cout << "MK name " << gSystem->DirName( fData->getRunParameter()->foutputfileName.c_str() ) << endl; i_NNGraphFileName << gSystem->DirName( fData->getRunParameter()->foutputfileName.c_str() ); i_NNGraphFileName << "/" << fData->getRunParameter()->frunnumber << ".IPR.root"; TFile* fgraphs = new TFile( i_NNGraphFileName.str().c_str(), iFileN.c_str() ); @@ -637,14 +585,13 @@ void VImageCleaning::writeProbabilityCurve( TGraph* iIPR, TF1* iProb, double iRa { return; } - TSpline* spl = NULL; TGraph* iGPP = new TGraph( iIPR->GetN() ); double x = 0.; double y = 0.; for( int i = 0; i < iIPR->GetN(); i++ ) { iIPR->GetPoint( i, x, y ); - float valIPR = iIPR->Eval( x, spl, "" ); + float valIPR = iIPR->Eval( x, 0, "" ); if( valIPR < 100. ) { valIPR = 100.; @@ -710,6 +657,7 @@ bool VImageCleaning::BoundarySearch( unsigned int teltype, float thresh, TF1* fP cout << "VImageCleaning::BoundarySearch error, no IPR graph for telescope type " << teltype << endl; return 0; } + float iIPR_max = fIPRgraphs_xmax[teltype]; // float TimeForReSearch = 0.; bool iffound = false; @@ -739,7 +687,7 @@ bool VImageCleaning::BoundarySearch( unsigned int teltype, float thresh, TF1* fP float mincharge = 0; LocMin( 2, charges, mincharge ); - if( NNChargeAndTimeCut( iIPR, fProbCurve, mincharge, maxtime, CoincWinLimit, true ) + if( NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurve, mincharge, maxtime, CoincWinLimit, true ) && VALIDITY[idx] > 0.5 ) { if( VALIDITYBOUND[idx] != refvalidity ) @@ -763,7 +711,7 @@ bool VImageCleaning::BoundarySearch( unsigned int teltype, float thresh, TF1* fP charges[1] = INTENSITY[idx2]; LocMin( 2, charges, mincharge ); - if( NNChargeAndTimeCut( iIPR, fProbCurve, mincharge, maxtime, CoincWinLimit, true ) + if( NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurve, mincharge, maxtime, CoincWinLimit, true ) && VALIDITY[idx2] > 0.5 ) { VALIDITYBOUND[idx2] = refvalidity; @@ -796,6 +744,7 @@ unsigned int VImageCleaning::NNGroupSearchProbCurve( unsigned int type, TF1* fPr cout << "VImageCleaning::NNGroupSearchProbCurve error, no IPR graph for telescope type " << type << endl; return 0; } + float iIPR_max = fIPRgraphs_xmax[type]; // (GM) unclear why this is hardwired here int NSBpix = 5; @@ -839,7 +788,7 @@ unsigned int VImageCleaning::NNGroupSearchProbCurve( unsigned int type, TF1* fPr LocMin( 2, charges, mincharge ); // apply charge and time cut - if( !NNChargeAndTimeCut( iIPR, fProbCurve, mincharge, dT, CoincWinLimit ) ) + if( !NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurve, mincharge, dT, CoincWinLimit ) ) { continue; } @@ -954,7 +903,7 @@ unsigned int VImageCleaning::NNGroupSearchProbCurve( unsigned int type, TF1* fPr float maxtime = 1E6; LocMax( 2, times2, maxtime ); // apply charge and time cut - if( !NNChargeAndTimeCut( iIPR, fProbCurve, mincharge, maxtime, CoincWinLimit ) ) + if( !NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurve, mincharge, maxtime, CoincWinLimit ) ) { continue; } @@ -995,7 +944,7 @@ unsigned int VImageCleaning::NNGroupSearchProbCurve( unsigned int type, TF1* fPr LocMax( 4, times3, maxtime ); // apply charge and time cut - if( !NNChargeAndTimeCut( iIPR, fProbCurve, mincharge, maxtime, CoincWinLimit ) ) + if( !NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurve, mincharge, maxtime, CoincWinLimit ) ) { continue; } @@ -1058,42 +1007,55 @@ unsigned int VImageCleaning::NNGroupSearchProbCurve( unsigned int type, TF1* fPr * apply cut in charge and time space * */ -bool VImageCleaning::NNChargeAndTimeCut( TGraph* iIPR, TF1* fProbCurve, - float mincharge, float dT, - float iCoincWinLimit, - bool bInvert ) +bool VImageCleaning::NNChargeAndTimeCut( + TGraph* iIPR, float iIPR_max, TF1* fProbCurve, + float mincharge, float dT, + float iCoincWinLimit, + bool bInvert ) { if( !iIPR || !fProbCurve ) { return false; } - TSpline* spl = NULL; - - // get expected NSB frequency for this charge - float valIPR = iIPR->Eval( mincharge, spl, "" ); - if( valIPR < 100. || mincharge > iIPR->GetXaxis()->GetXmax() ) + float valDT = 0.; + // use previous result if charge and all other + // parameter are the same + if( fIPR_save_mincharge > -90. + && fIPR_save_telid == fData->getTelID() + && TMath::Abs( fIPR_save_ProbCurve_par1 - fProbCurve->GetParameter( 1 ) ) < 1.e-3 + && TMath::Abs( fIPR_save_ProbCurve_par2 - fProbCurve->GetParameter( 2 ) ) < 1.e-3 + && TMath::Abs( fIPR_save_mincharge - mincharge ) < 1.e-3 ) { - valIPR = 100.; // Hz + valDT = fIPR_save_dT_from_probCurve; } - - // fix dT to the maximum coincidence limit for no-time cleaning - if( NNoptNoTimeing ) + else { - dT = CoincWinLimit; + // get expected NSB frequency for this charge + float valIPR = iIPR->Eval( mincharge, 0, "" ); + if( valIPR < 100. || mincharge > iIPR_max ) + { + valIPR = 100.; // Hz + } + valDT = fProbCurve->Eval( valIPR ); + fIPR_save_dT_from_probCurve = valDT; + fIPR_save_mincharge = mincharge; + fIPR_save_telid = fData->getTelID(); + fIPR_save_ProbCurve_par1 = fProbCurve->GetParameter( 1 ); + fIPR_save_ProbCurve_par2 = fProbCurve->GetParameter( 2 ); } // apply cut in deltaT // (note cut on maximum coincidence limit (given in the cleaning parameter file)) if( !bInvert ) { - if( dT > iCoincWinLimit || dT > fProbCurve->Eval( valIPR ) ) + if( dT > iCoincWinLimit || dT > valDT ) { return false; } } else { - if( dT < iCoincWinLimit && dT < fProbCurve->Eval( valIPR ) ) + if( dT < iCoincWinLimit && dT < valDT ) { return true; } @@ -1124,6 +1086,9 @@ unsigned int VImageCleaning::NNGroupSearchProbCurveRelaxed( unsigned int teltype cout << "VImageCleaning::NNGroupSearchProbCurveRelaxed error, no IPR graph for telescope type " << teltype << endl; return 0; } + float iIPR_max = fIPRgraphs_xmax[teltype]; + fIPR_save_mincharge = -99.; + fIPR_save_dT_from_probCurve = -99.; int NNcnt = 1; float dT = 0.; @@ -1164,14 +1129,14 @@ unsigned int VImageCleaning::NNGroupSearchProbCurveRelaxed( unsigned int teltype LocMin( 2, charges, mincharge ); // apply charge and time cut - if( !NNChargeAndTimeCut( iIPR, fProbCurve, mincharge, dT, CoincWinLimit ) ) + if( !NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurve, mincharge, dT, CoincWinLimit ) ) { continue; } ////////////////////////////////////////// float maxtime = 1E6; - if( NNChargeAndTimeCut( iIPR, fProbCurve, mincharge, dT, 1.e6, true ) + if( NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurve, mincharge, dT, 1.e6, true ) && VALIDITY[PixNum2] > 0.5 && INTENSITY[PixNum2] > PreCut ) { pix1 = PixNum; @@ -1190,7 +1155,7 @@ unsigned int VImageCleaning::NNGroupSearchProbCurveRelaxed( unsigned int teltype float times2[3] = { dT, dt2, dt3}; LocMax( 3, times2, maxtime ); - if( NNChargeAndTimeCut( iIPR, fProbCurve, mincharge, maxtime, 1.e6, true ) ) + if( NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurve, mincharge, maxtime, 1.e6, true ) ) { NNcnt++; } @@ -1253,7 +1218,7 @@ unsigned int VImageCleaning::NNGroupSearchProbCurveRelaxed( unsigned int teltype }; LocMax( 4, times3, maxtimeloc ); - if( NNChargeAndTimeCut( iIPR, fProbCurve, minchargeloc, maxtimeloc, CoincWinLimit, true ) ) + if( NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurve, minchargeloc, maxtimeloc, CoincWinLimit, true ) ) { NNcnt++; pix4 = testpixnum; @@ -1364,6 +1329,11 @@ void VImageCleaning::DiscardLocalTimeOutlayers( float NNthresh[6] ) } nimagepix++; } + // don't do anything for small images + if( nimagepix <= 4 ) + { + return; + } // assume all pixels have same radius! Double_t diam = 2.*fData->getDetectorGeo()->getTubeRadius()[1]; if( diam <= 0. ) @@ -1418,12 +1388,6 @@ void VImageCleaning::DiscardLocalTimeOutlayers( float NNthresh[6] ) } } //****************************************************************** - // don't do anything for small images - if( nimagepix <= 4 ) - { - return; - } - //****************************************************************** // loop over accepted pixels float SNRlimit = 5.0; float radicand = 0.; @@ -1828,7 +1792,7 @@ int VImageCleaning::ImageCleaningCharge( unsigned int teltype ) cout << "VImageCleaning::ImageCleaningCharge error, no IPR graph for telescope type " << teltype << endl; return 0; } - TSpline* spl = NULL; + float iIPR_max = fIPRgraphs_xmax[teltype]; for( Int_t iRing = 0; iRing < 1; iRing++ ) { @@ -1926,14 +1890,14 @@ int VImageCleaning::ImageCleaningCharge( unsigned int teltype ) LocMin( 2, charges, refth ); fProbCurveBound->SetParameter( 2, 2.*nfirstringpix ); - Double_t valIPRref = iIPR->Eval( charge, spl, "" ); - if( valIPRref < 100. || charge >= iIPR->GetXaxis()->GetXmax() ) + Double_t valIPRref = iIPR->Eval( charge, 0, "" ); + if( valIPRref < 100. || charge >= iIPR_max ) { valIPRref = 100.; } fProbCurveBound->SetParameter( 1, valIPRref ); - if( NNChargeAndTimeCut( iIPR, fProbCurveBound, refth, dT, 0.6 * CoincWinLimit, true ) ) + if( NNChargeAndTimeCut( iIPR, iIPR_max, fProbCurveBound, refth, dT, 0.6 * CoincWinLimit, true ) ) { VALIDITY[idx] = iRing + 7; } @@ -2032,7 +1996,6 @@ void VImageCleaning::cleanNNImageFixed( VImageCleaningRunParameter* iImageCleani // Init options for NN cleaning nRings = iImageCleaningParameters->fNNOpt_nRings; CoincWinLimit = iImageCleaningParameters->fNNOpt_CoincWinLimit; - NNoptNoTimeing = iImageCleaningParameters->fNNOpt_ifNNoptNoTimeing; setExplicitSampleTimeSlice = iImageCleaningParameters->fNNOpt_ifExplicitSampleTimeSlice; sampleTimeSlice = iImageCleaningParameters->fNNOpt_sampleTimeSlice; nBinsADC = iImageCleaningParameters->fNNOpt_nBinsADC; @@ -2045,7 +2008,6 @@ void VImageCleaning::cleanNNImageFixed( VImageCleaningRunParameter* iImageCleani fifActiveNN[teltype] = iImageCleaningParameters->fNNOpt_ActiveNN; } // initiate probability contours - InitNNImgClnPerTelTypeTimeSlice( 0, 0 ); kInitNNImgClnPerTelType[teltype] = InitNNImgClnPerTelType( teltype ); } @@ -2064,18 +2026,10 @@ void VImageCleaning::cleanNNImageFixed( VImageCleaningRunParameter* iImageCleani && !fData->getDead( fData->getHiLo()[i] )[i] ) { INTENSITY[i] = fData->getFADCtoPhe()[i] * fData->getSums()[i]; - //(first option is for tests of impact of timing) - if( NNoptNoTimeing ) - { - TIMES[i] = 0.; - } - else - { - // trace times are corrected for flasher determined time offsets - TIMES[i] = fData->getPulseTime( true )[i] * FADCslice; - } + // trace times are corrected for flasher determined time offsets + TIMES[i] = fData->getPulseTime( true )[i] * FADCslice; // make sure that pixels without timing are ignored - if( TIMES[i] <= -500 && !NNoptNoTimeing ) + if( TIMES[i] <= -500 ) { INTENSITY[i] = 0; } @@ -2228,39 +2182,6 @@ void VImageCleaning::FillIPR( unsigned int teltype ) //tel type } } -TGraphErrors* VImageCleaning::GetIPRGraph( unsigned int teltype, float ScanWindow ) -{ - float RATES[fIPRdim], RATESERR[fIPRdim]; - float RATESX[fIPRdim], RATESXERR[fIPRdim]; - - for( unsigned int i = 0; i < fIPRdim; i++ ) - { - RATES[i] = IPR[teltype][i]; - float ConvToHz = ( ScanWindow * IPR[teltype][0] ) / 1E9; - if( ConvToHz < 0.9E-9 ) - { - break; - } - RATES[i] /= ConvToHz; - RATESX[i] = IPR[0][i]; - RATESERR[i] = sqrt( RATES[i] * ConvToHz ) / ConvToHz; - //RATESXERR[i]=0.1*float(i)/float(res); - RATESXERR[i] = 0.; - } - TGraphErrors* gRate = new TGraphErrors( fIPRdim, RATESX, RATES, RATESXERR, RATESERR ); - gRate->SetTitle( "IPRcharge" ); - gRate->SetName( "IPRcharge" ); - gRate->GetXaxis()->SetTitle( "Threshold, FADC" ); - gRate->GetYaxis()->SetTitle( "Rate, Hz" ); - gRate->SetMinimum( 1 ); - - TFile* fgraph = new TFile( "$CTA_USER_DATA_DIR/TestIPRtrunk.root", "RECREATE" ); - gRate->Write(); - fgraph->Close(); - std::cout << "[TriggerAnalogueSummation::GetIPRGraph()]: graph root file written:" << fgraph->GetName() << std::endl; - return gRate; -} - // end of NN image cleaning //***************************************************************************************************** diff --git a/src/VImageCleaningRunParameter.cpp b/src/VImageCleaningRunParameter.cpp index d17a69b3c..917e148d1 100644 --- a/src/VImageCleaningRunParameter.cpp +++ b/src/VImageCleaningRunParameter.cpp @@ -49,7 +49,6 @@ VImageCleaningRunParameter::VImageCleaningRunParameter( string iName ) fNNOpt_nRings = 3; fNNOpt_CoincWinLimit = 8; - fNNOpt_ifNNoptNoTimeing = false; fNNOpt_ifExplicitSampleTimeSlice = false; fNNOpt_sampleTimeSlice = 1; fNNOpt_nBinsADC = 25; @@ -84,14 +83,7 @@ void VImageCleaningRunParameter::print() cout << endl; cout << "\t\t Maximum number of rings to be searched for boundary pixels - " << fNNOpt_nRings << endl; cout << "\t\t Maximal coincidence window allowed between neighbouring pixels for any NN group - " << fNNOpt_CoincWinLimit << " [ns]" << endl; - if( fNNOpt_ifNNoptNoTimeing ) - { - cout << "\t\t Ignore timing information in NN image cleaning" << endl; - } - else - { - cout << "\t\t Use timing information in NN image cleaning" << endl; - } + cout << "\t\t Use timing information in NN image cleaning" << endl; if( fNNOpt_ifExplicitSampleTimeSlice ) { cout << "\t\t set sample time slice and number of ADC bins explicitly:" << endl; diff --git a/src/VInstrumentResponseFunctionRunParameter.cpp b/src/VInstrumentResponseFunctionRunParameter.cpp index 9694a9295..5b0b2093a 100644 --- a/src/VInstrumentResponseFunctionRunParameter.cpp +++ b/src/VInstrumentResponseFunctionRunParameter.cpp @@ -16,7 +16,7 @@ VInstrumentResponseFunctionRunParameter::VInstrumentResponseFunctionRunParameter fSpectralIndexMin = 2.0; fSpectralIndexStep = 0.1; - fEnergyReconstructionMethod = 0; + fEnergyReconstructionMethod = 1; fEnergyAxisBins_log10 = 60; fIgnoreEnergyReconstructionQuality = false; @@ -471,6 +471,7 @@ bool VInstrumentResponseFunctionRunParameter::readRunParameters( string ifilenam { fObservatory = i_runPara->getObservatory(); fInstrumentEpoch = i_runPara->fInstrumentEpoch; + fInstrumentEpochATM = i_runPara->getInstrumentATMString(); fTelToAnalyse = i_runPara->fTelToAnalyze; } else @@ -478,6 +479,7 @@ bool VInstrumentResponseFunctionRunParameter::readRunParameters( string ifilenam cout << "VInstrumentResponseFunctionRunParameter::readRunParameters() warning: cannot read instrument epoch and active telecopes from MC event file" << endl; cout << "this might lead to a wrong choice in the gamma/hadron cuts - please check" << endl; fInstrumentEpoch = "NOT_FOUND"; + fInstrumentEpochATM = "NOT_FOUND"; } // get NSB (pedvar) level VTableLookupRunParameter* fR = ( VTableLookupRunParameter* )iFile->Get( "TLRunParameter" ); @@ -606,7 +608,9 @@ void VInstrumentResponseFunctionRunParameter::print() } if( fInstrumentEpoch != "NOT_SET" ) { - cout << "Instrument epoch: " << fInstrumentEpoch << endl; + cout << "Instrument epoch: " << fInstrumentEpoch; + cout << " (" << fInstrumentEpochATM << ")"; + cout << endl; } else { diff --git a/src/VMonteCarloRateCalculator.cpp b/src/VMonteCarloRateCalculator.cpp index 4868d99f0..d9e349731 100644 --- a/src/VMonteCarloRateCalculator.cpp +++ b/src/VMonteCarloRateCalculator.cpp @@ -38,7 +38,6 @@ VMonteCarloRateCalculator::VMonteCarloRateCalculator( string ifile ) fMCTree->SetBranchAddress( "noise", &fnoise ); fMCTree->SetBranchAddress( "nrates", &fnrates ); fMCTree->SetBranchAddress( "MCrate", fMCrate ); - } @@ -129,9 +128,10 @@ double VMonteCarloRateCalculator::getMonteCarloRate( vector< double >& e, vector if( bDebug ) { cout << "VMonteCarloRateCalculator::getMonteCarloRate " << e.size() << "\t" << eff.size() << endl; - cout << "\t Gamma " << i_gamma << " phi: " << i_phi << " E0: " << iE0; + cout << "\t Gamma " << i_gamma; + cout << scientific << " phi: " << i_phi << fixed << " E0: " << iE0; cout << " EMin: " << iEMin << " EMax: " << iEMax; - cout << "Rate [1/s]: " << iTot << " Rate [1/min]: " << iTot * 60. << endl; + cout << " Rate [1/s]: " << iTot << " Rate [1/min]: " << iTot * 60. << endl; } if( e.size() != eff.size() || e.size() <= 2 ) { diff --git a/src/VPedestalCalculator.cpp b/src/VPedestalCalculator.cpp index 1ba7fb709..7a04e99e5 100644 --- a/src/VPedestalCalculator.cpp +++ b/src/VPedestalCalculator.cpp @@ -16,6 +16,7 @@ VPedestalCalculator::VPedestalCalculator() fSumWindow = 24; fNPixel = 500; fSumFirst = 0; + bCalibrationRun = false; } @@ -75,9 +76,9 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe reset(); // pedestal histogram binning - int i_hist_nbin = 1500.; + int i_hist_nbin = 2000.; float i_hist_xmin = 0.; - float i_hist_xmax = 750.; + float i_hist_xmax = 2000.; // set up the trees TDirectory* iDir = gDirectory; @@ -163,7 +164,7 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe // initialise the pedvars variables iped_cal2.clear(); - iped_histo.clear(); + iped_histo2.clear(); for( unsigned int p = 0; p < fNPixel; p++ ) { iped_cal.clear(); @@ -171,7 +172,7 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe for( int w = 0; w < fSumWindow; w++ ) { iped_cal.push_back( 0. ); - sprintf( hname, "hped_cal_%d_%d_%d", i, p, w ); + sprintf( hname, "hped_cal_%d_%d_%d", t + 1, p, w ); iped_histo.push_back( new TH1F( hname, "", i_hist_nbin, i_hist_xmin, i_hist_xmax ) ); @@ -183,8 +184,7 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe fpedcal_mean.push_back( iped_cal2 ); fpedcal_mean2.push_back( iped_cal2 ); fpedcal_histo.push_back( iped_histo2 ); - fpedcal_histo_sw.push_back( iped_histo2 ); - + // define the time vector fTimeVec.push_back( 0 ); NTimeSlices.push_back( 0 ); @@ -195,6 +195,7 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe { cout << "END: VPedestalCalculator::initialize " << endl; } + return true; } @@ -251,7 +252,6 @@ void VPedestalCalculator::fillTimeSlice( unsigned int telID ) fpedcal_n[telID][p][w] = 0.; fpedcal_mean[telID][p][w] = 0.; fpedcal_mean2[telID][p][w] = 0.; - fpedcal_histo_sw[telID][p][w]->Reset(); fpedcal_histo[telID][p][w]->Reset(); } // deroate the pixel coordinates @@ -278,7 +278,7 @@ void VPedestalCalculator::fillTimeSlice( unsigned int telID ) } -void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalculator ) +void VPedestalCalculator::doAnalysis( bool iLowGain ) { double t = getEventTime(); // get right index for tel id @@ -291,6 +291,7 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula break; } } + // temporary vectors if( telID < fTimeVec.size() ) { @@ -304,21 +305,12 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula else if( t - fTimeVec[telID] > fLengthofTimeSlice ) { time = t; - if (NTimeSlices[telID] == 0 and telID == 0){ - fIPRCalculator->fillIPRPedestalHisto(); - } - - NTimeSlices[telID]+=1; - - fIPRCalculator->fillIPRPedestalHisto(telID, fpedcal_histo); fillTimeSlice( telID ); - fTimeVec[telID] = t; } // if( t - fTimeVec[telID] > fLengthofTimeSlice ) /////////////////////////////////////////////////////// double i_tr_sum = 0.; - double i_tr_sum_sw = 0.; // calculate the sums (don't use calcsums because it overwrites getSums() ) // and fill the histograms for( unsigned int i = 0; i < getNChannels(); i++ ) @@ -354,15 +346,10 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula { // calculate trace sum i_tr_sum = fTraceHandler->getTraceSum( fSumFirst, fSumFirst + ( w + 1 ), true, 1 ); - i_tr_sum_sw = fTraceHandler->getTraceSum( fSumFirst, fSumFirst + ( w + 1 ), false, 1 ); if( i_tr_sum > 0. && i_tr_sum < 50.*( w + 1 ) ) { if( chanID < fpedcal_n[telID].size() && w < fpedcal_n[telID][chanID].size() ) { - if( i_tr_sum_sw > 0. && i_tr_sum_sw < 50.*( w + 1 ) ) - { - fpedcal_histo_sw[telID][chanID][w]->Fill( i_tr_sum_sw ); - } fpedcal_n[telID][chanID][w]++; fpedcal_mean[telID][chanID][w] += i_tr_sum; fpedcal_mean2[telID][chanID][w] += i_tr_sum * i_tr_sum; @@ -394,6 +381,7 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula } // if( telID < fTree.size() && fTree[telID] && telID < fTimeVec.size() ) } + void VPedestalCalculator::terminate( bool iWrite, bool iDebug_IO ) { if( iWrite ) diff --git a/src/VPlotAnasumHistograms.cpp b/src/VPlotAnasumHistograms.cpp index 1668784bd..5eb06115b 100644 --- a/src/VPlotAnasumHistograms.cpp +++ b/src/VPlotAnasumHistograms.cpp @@ -645,10 +645,9 @@ void VPlotAnasumHistograms::plot_CorrelatedSkyPlots() * * */ -TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irbin ) +TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irbin, double setYMax, double setYMin ) { // int iPlotPSF = 0; - double setYMax = -1.; char hname[200]; char htitle[200]; @@ -664,28 +663,23 @@ TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irb // canvas that will contain the theta2 and the theta2_diff plots TCanvas* c_t2 = 0; + TCanvas* c_t2_diff = 0; if( htheta2_diff && htheta2_on && htheta2_off ) { sprintf( hname, "c_t2_%d", fRunNumber ); sprintf( htitle, "theta2 (run %d)", fRunNumber ); - c_t2 = new TCanvas( hname, htitle, 10, 10, 900, 400 ); - c_t2->Divide( 2, 1 ); - //c_t2->SetLeftMargin( 0.12 ); + c_t2 = new TCanvas( hname, htitle, 10, 10, 400, 400 ); + sprintf( hname, "c_t2_diff_%d", fRunNumber ); + c_t2_diff = new TCanvas( hname, htitle, 410, 10, 400, 400 ); + c_t2_diff->SetLeftMargin( 0.12 ); - c_t2->cd( 1 ); + c_t2->cd(); htheta2_on->SetXTitle( "#Theta^{2} [deg^{2}]" ); htheta2_on->SetTitle( "" ); htheta2_off->SetTitle( "#Theta^{2} Histogram" ); htheta2_off->SetTitle( "" ); - if( setYMax < 0. ) - { - htheta2_off->SetMaximum( htheta2_on->GetMaximum() * 1.1 ); - } - else - { - htheta2_off->SetMaximum( setYMax ); - } + htheta2_off->SetMaximum( htheta2_on->GetMaximum() * 1.1 ); sprintf( hname, "Number of events / %.3f deg^{2}", htheta2_off->GetXaxis()->GetBinWidth( 2 ) ); htheta2_on->SetYTitle( hname ); htheta2_off->SetYTitle( hname ); @@ -716,15 +710,24 @@ TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irb } } - c_t2->cd( 2 ); - htheta2_diff->SetFillColor( 8 ); + c_t2_diff->cd(); + htheta2_diff->SetFillColor( 418 ); htheta2_diff->SetXTitle( "#Theta^{2} [deg^{2}]" ); htheta2_diff->SetTitle( "" ); sprintf( hname, "Number of events / %.3f deg^{2}", htheta2_diff->GetXaxis()->GetBinWidth( 2 ) ); htheta2_diff->SetYTitle( hname ); - htheta2_diff->GetYaxis()->SetTitleOffset( 1.4 ); - setHistogramPlottingStyle( htheta2_diff, 1, 2, 1, 1, irbin, 1001 ); + htheta2_diff->GetYaxis()->SetTitleOffset( 1.6 ); + setHistogramPlottingStyle( htheta2_diff, 418, 2, 1, 1, irbin, 1001 ); htheta2_diff->SetAxisRange( t2min, t2max ); + if( setYMax > -999. ) + { + htheta2_diff->SetMaximum( setYMax ); + } + if( setYMin > -999. ) + { + htheta2_diff->SetMinimum( setYMin ); + } + htheta2_diff->Draw( "hist e" ); @@ -757,7 +760,7 @@ TCanvas* VPlotAnasumHistograms::plot_theta2( double t2min, double t2max, int irb cout << "histograms not found" << endl; } - return c_t2; + return c_t2_diff; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/VPlotCompareDataWithMC.cpp b/src/VPlotCompareDataWithMC.cpp index fedea67ed..7b3ce5f8b 100644 --- a/src/VPlotCompareDataWithMC.cpp +++ b/src/VPlotCompareDataWithMC.cpp @@ -13,6 +13,7 @@ VPlotCompareDataWithMC::VPlotCompareDataWithMC( string iFile ) setNTel(); setPrintName(); setRelativePlotRange(); + setScalingMethod(); fDataFileName = iFile; fDataFile = 0; @@ -127,15 +128,28 @@ void VPlotCompareDataWithMC::plotLegend( TH1D* hsims, TH1D* hdiff, double x0 ) iLegend->Draw(); } +void VPlotCompareDataWithMC::setScalingMethod( int iScalingMethod ) +{ + if( iScalingMethod > 0 && iScalingMethod < 4 ) + { + fScalingMethod = iScalingMethod; + return; + } + cout << "Error setting scaling method; should be in [1,3]" << endl; + cout << "Exiting..." << endl; + exit( EXIT_FAILURE ); +} + + /*! get scale factor between simulations and data - bContents = 1: scale to same contents - bContents = 2: scale to same maximum value - bContents = 3: scale to same maximum value (three bins around maximum) + iScalingMethod = 1: scale to same contents + iScalingMethod = 2: scale to same maximum value + iScalingMethod = 3: scale to same maximum value (three bins around maximum) */ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_sims, double& s_diff, - int bContents, double xmin, double xmax ) + int iScalingMethod, double xmin, double xmax ) { if( !h_sims || !h_diff ) { @@ -144,7 +158,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s double z = 0.; //////////////////////////////////// // scale to same contents (integral) - if( bContents == 1 ) + if( iScalingMethod == 1 ) { int i_min = 1; int i_max = h_sims->GetNbinsX(); @@ -174,7 +188,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s } for( int i = i_min; i <= i_max; i++ ) { - if( h_diff->GetBinContent( i ) > 0 ) + // if( h_diff->GetBinContent( i ) > 0 ) { z += h_diff->GetBinContent( i ); } @@ -189,7 +203,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s } ////////////////////////////////// // scale to same maximum - else if( bContents == 2 ) + else if( iScalingMethod == 2 ) { s_sims = h_sims->GetMaximum(); z = h_diff->GetMaximum(); @@ -202,7 +216,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s } ////////////////////////////////// // scale to peak (three bins around maximum) - else if( bContents == 3 ) + else if( iScalingMethod == 3 ) { int imaxbin = h_sims->GetMaximumBin(); s_sims = h_sims->GetBinContent( imaxbin ); @@ -243,7 +257,7 @@ void VPlotCompareDataWithMC::getScaling( TH1D* h_sims, TH1D* h_diff, double& s_s } void VPlotCompareDataWithMC::getScaling( double& s_sims, double& s_diff, string his, - int bContents, double xmin, double xmax ) + int iScalingMethod, double xmin, double xmax ) { if( fDataFile == 0 ) { @@ -253,15 +267,15 @@ void VPlotCompareDataWithMC::getScaling( double& s_sims, double& s_diff, string return; } cout << "scale on histograms " << his << ", scale to"; - if( bContents == 1 ) + if( iScalingMethod == 1 ) { cout << " histogram contents" << endl; } - else if( bContents == 2 ) + else if( iScalingMethod == 2 ) { cout << " histogram maximum" << endl; } - else if( bContents == 3 ) + else if( iScalingMethod == 3 ) { cout << " histogram maximum (peak)" << endl; } @@ -279,7 +293,7 @@ void VPlotCompareDataWithMC::getScaling( double& s_sims, double& s_diff, string return; } - getScaling( h_sims, h_diff, s_sims, s_diff, bContents, xmin, xmax ); + getScaling( h_sims, h_diff, s_sims, s_diff, fScalingMethod, xmin, xmax ); } @@ -494,7 +508,7 @@ void VPlotCompareDataWithMC::multiplicity_plots() // get the scaling between simulations and data double s_sims = 1.; double s_diff = 1.; - getScaling( s_sims, s_diff, "NImages", 1 ); + getScaling( s_sims, s_diff, "NImages", fScalingMethod ); char hname[600]; char htitle[600]; @@ -610,7 +624,7 @@ TCanvas* VPlotCompareDataWithMC::plot_singleCanvas( string iHistoName, string iC // get the scaling between simulations and data double s_sims = 1.; double s_diff = 1.; - getScaling( s_sims, s_diff, iScalingVariable, 1, -9999., iHistoXAxisMax ); + getScaling( s_sims, s_diff, iScalingVariable, fScalingMethod, -9999., iHistoXAxisMax ); sprintf( hname, "c%s_%s", iHistoName.c_str(), fDataFileName.c_str() ); sprintf( htitle, "%s (%s)", iCanvasTitle.c_str(), fDataFileName.c_str() ); @@ -824,7 +838,8 @@ TCanvas* VPlotCompareDataWithMC::plot_energyDependentDistributions( string iVari TH1D* hDiff = h_diff->ProjectionY( hname, i, i ); setHistogramAtt( hDiff, 1, 1, 1, 21, iRebin ); - getScaling( hSims, hDiff, s_sims, s_diff, 3 ); + // getScaling( hSims, hDiff, s_sims, s_diff, 3 ); + getScaling( hSims, hDiff, s_sims, s_diff, fScalingMethod ); if( hSims->GetEntries() > 0 ) { hSims->Scale( s_sims ); @@ -1013,7 +1028,7 @@ TCanvas* VPlotCompareDataWithMC::stereo_parameter() // get the scaling between simulations and data double s_sims = 1.; double s_diff = 1.; - getScaling( s_sims, s_diff, "theta2", 1 ); + getScaling( s_sims, s_diff, "theta2", fScalingMethod ); ht2_sims->Scale( s_sims ); ht2_diff->Scale( s_diff ); @@ -1045,7 +1060,7 @@ TCanvas* VPlotCompareDataWithMC::stereo_parameter() TH1D* hlt2_diff = ( TH1D* )fDataFile->Get( "hltheta2_DIFF" ); setHistogramAtt( hlt2_diff, 1, 3, 1, 25, 1 ); - getScaling( s_sims, s_diff, "ltheta2", 2 ); + getScaling( s_sims, s_diff, "ltheta2", fScalingMethod ); hlt2_sims->Scale( s_sims ); hlt2_diff->Scale( s_diff ); @@ -1077,7 +1092,7 @@ TCanvas* VPlotCompareDataWithMC::stereo_parameter() setHistogramAtt( hmscw_diff, 1, 1, 1, 25, 2 ); hmscw_sims->SetAxisRange( -1., 1. ); - getScaling( s_sims, s_diff, "MSCW", 2, -0.5, 0.5 ); + getScaling( s_sims, s_diff, "MSCW", fScalingMethod, -0.5, 0.5 ); if( hmscw_sims->GetEntries() > 0 ) { hmscw_sims->Scale( s_sims ); @@ -1118,7 +1133,7 @@ TCanvas* VPlotCompareDataWithMC::stereo_parameter() hmscl_diff->SetStats( 0 ); hmscl_sims->SetAxisRange( -1., 1. ); - getScaling( s_sims, s_diff, "MSCL", 1, -0.75, 0.75 ); + getScaling( s_sims, s_diff, "MSCL", fScalingMethod, -0.75, 0.75 ); if( hmscl_sims->GetEntries() > 0 ) { hmscl_sims->Scale( s_sims ); @@ -1199,7 +1214,7 @@ void VPlotCompareDataWithMC::mva_parameter() double error_diff = 0.; hmva_sims->SetAxisRange( -1., 1. ); - getScaling( s_sims, s_diff, "MVA", 1, -0.75, 0.75 ); + getScaling( s_sims, s_diff, "MVA", fScalingMethod, -0.75, 0.75 ); if( hmva_sims->GetEntries() > 0 ) { hmva_sims->Scale( s_sims ); @@ -1251,7 +1266,7 @@ void VPlotCompareDataWithMC::mva_parameter() * horrible code...programmer doesn't know what a loop is */ -TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin, int iScaling ) +TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin ) { if( !fDataFile ) { @@ -1293,7 +1308,7 @@ TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin, int iScaling ) double nSims = 0.; double nDiff = 0.; - getScaling( nSims, nDiff, "Xcore", iScaling ); + getScaling( nSims, nDiff, "Xcore", fScalingMethod ); hXcore_diff->Scale( nDiff ); hXcore_sims->Scale( nSims ); @@ -1332,7 +1347,7 @@ TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin, int iScaling ) hYcore_sims->SetAxisRange( -250., 250. ); hYcore_on->SetAxisRange( -250., 250. ); - getScaling( nSims, nDiff, "Ycore", iScaling ); + getScaling( nSims, nDiff, "Ycore", fScalingMethod ); hYcore_diff->Scale( nDiff ); hYcore_sims->Scale( nSims ); @@ -1363,7 +1378,7 @@ TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin, int iScaling ) setHistogramAtt( hArrayEl_diff, 1, 1, 1, 21, iRebin ); hArrayEl_sims->SetAxisRange( 40., 90. ); hArrayEl_on->SetAxisRange( 40., 90. ); - getScaling( nSims, nDiff, "ArrayEl", iScaling ); + getScaling( nSims, nDiff, "ArrayEl", fScalingMethod ); hArrayEl_diff->Scale( nDiff ); hArrayEl_sims->Scale( nSims ); @@ -1390,7 +1405,7 @@ TCanvas* VPlotCompareDataWithMC::core_plots( int iRebin, int iScaling ) setHistogramAtt( hArrayAz_on, 3, 1, 1, 20, 1 ); setHistogramAtt( hArrayAz_off, 4, 1, 1, 20, 1 ); setHistogramAtt( hArrayAz_diff, 1, 1, 1, 21, 1 ); - getScaling( nSims, nDiff, "ArrayAz", iScaling ); + getScaling( nSims, nDiff, "ArrayAz", fScalingMethod ); hArrayAz_diff->Scale( nDiff ); hArrayAz_sims->Scale( nSims ); @@ -1612,7 +1627,7 @@ TCanvas* VPlotCompareDataWithMC::distance_plots() sprintf( hname, "r_%u", i + 1 ); - getScaling( s_sims, s_diff, hname, 1 ); + getScaling( s_sims, s_diff, hname, fScalingMethod ); if( hR_sims[i]->GetEntries() > 0 ) { hR_sims[i]->Scale( s_sims ); @@ -1739,8 +1754,7 @@ TCanvas* VPlotCompareDataWithMC::single_telescope( int telid ) return c; } -TCanvas* VPlotCompareDataWithMC::single_telescope( int telid, string iPlot, bool iOneCanvas, - int iScalingMethod, int i_rebin ) +TCanvas* VPlotCompareDataWithMC::single_telescope( int telid, string iPlot, bool iOneCanvas, int i_rebin ) { if( iPlot != "SIMSDIFF" && iPlot != "ONOFF" && iPlot != "REL" ) @@ -1761,7 +1775,7 @@ TCanvas* VPlotCompareDataWithMC::single_telescope( int telid, string iPlot, bool double s_diff = 1.; char htitle[600]; sprintf( htitle, "width_%d", telid ); - getScaling( s_sims, s_diff, htitle, iScalingMethod ); + getScaling( s_sims, s_diff, htitle, fScalingMethod ); ////////////////////////////////////// // histogram names to be plotted @@ -1923,7 +1937,7 @@ TCanvas* VPlotCompareDataWithMC::single_telescope( int telid, string iPlot, bool hon->Rebin( f_rebin[j] ); hoff->Rebin( f_rebin[j] ); sprintf( htitle, "%s_%d", hname[j].c_str(), telid ); - getScaling( s_sims, s_diff, htitle, iScalingMethod ); + getScaling( s_sims, s_diff, htitle, fScalingMethod ); // normalize sims histograms to data histograms hsims->Scale( s_sims ); if( TMath::Abs( s_diff - 1. ) > 1.e-2 ) @@ -2156,7 +2170,7 @@ void VPlotCompareDataWithMC::msc_plots( char* offFile, char* helium, char* proto // get the scaling between simulations and data double s_sims = 1.; double s_diff = 1.; - getScaling( s_sims, s_diff, ivar.c_str(), true ); + getScaling( s_sims, s_diff, ivar.c_str(), fScalingMethod ); hMSC_sims->SetAxisRange( xmin, xmax ); if( hMSC_sims->GetEntries() > 0 ) { @@ -2352,6 +2366,16 @@ void VPlotCompareDataWithMC::plot( string iPrintName ) { cP->Print( hname ); } + cP = plot_energyDependentDistributions( "MVA", 1, -0.75, 0.75, "SIMSDIFF" ); + if( cP ) + { + cP->Print( hname ); + } + cP = plot_energyDependentDistributions( "MVA", 1, -0.75, 0.75, "CUMU" ); + if( cP ) + { + cP->Print( hname ); + } // telescope dependent plots for( unsigned int i = 1; i <= 4; i++ ) { @@ -2539,7 +2563,7 @@ void VPlotCompareDataWithMC::plot( string iPrintName ) } for( unsigned int i = 1; i <= 4; i++ ) { - cP = plot_energyDependentDistributions( "disp", 2, -2.5, 2.5, "SIMSDIFF", i, -99., "Erec" ); + cP = plot_energyDependentDistributions( "disp", 2, -2., 2., "SIMSDIFF", i, -99., "Erec" ); if( cP ) { cP->Print( hname ); @@ -2547,7 +2571,7 @@ void VPlotCompareDataWithMC::plot( string iPrintName ) } for( unsigned int i = 1; i <= 4; i++ ) { - cP = plot_energyDependentDistributions( "disp", 2, -2.5, 2.5, "SIMSDIFF", i, -99., "size" ); + cP = plot_energyDependentDistributions( "disp", 2, -2., 2., "SIMSDIFF", i, -99., "size" ); if( cP ) { cP->Print( hname ); @@ -2555,7 +2579,7 @@ void VPlotCompareDataWithMC::plot( string iPrintName ) } for( unsigned int i = 1; i <= 4; i++ ) { - cP = plot_energyDependentDistributions( "disp", 2, -2.5, 2.5, "SIMSDIFF", i, -99., "ntubes" ); + cP = plot_energyDependentDistributions( "disp", 2, -2., 2., "SIMSDIFF", i, -99., "ntubes" ); if( cP ) { cP->Print( hname ); diff --git a/src/VPlotInstrumentResponseFunction.cpp b/src/VPlotInstrumentResponseFunction.cpp index 2320dbb36..9acd19f50 100644 --- a/src/VPlotInstrumentResponseFunction.cpp +++ b/src/VPlotInstrumentResponseFunction.cpp @@ -439,19 +439,19 @@ void VPlotInstrumentResponseFunction::plotEnergyReconstructionMatrix( unsigned i } char hname[200]; - char htitle[200]; sprintf( hname, "cEA_Ematrix_%d_%d_%d_%d", iDataSetID, bFineBinning, bQualityCuts, bInterPol ); - sprintf( htitle, "energy reconstruction matrix (%d,%d)", iDataSetID, bInterPol ); + ostringstream htitle; + htitle << "energy reconstruction matrix (" << iDataSetID << "," << bInterPol << ")"; if( bFineBinning ) { - sprintf( htitle, "%s (fine binning)", htitle ); + htitle << " (fine binning)"; } if( bQualityCuts ) { - sprintf( htitle, "%s, QC", htitle ); + htitle << " , QC"; } - TCanvas* iEnergyReconstructionMatrixCanvas = new TCanvas( hname, htitle, 610, 10, fCanvasSize_X, fCanvasSize_Y ); + TCanvas* iEnergyReconstructionMatrixCanvas = new TCanvas( hname, htitle.str().c_str(), 610, 10, fCanvasSize_X, fCanvasSize_Y ); iEnergyReconstructionMatrixCanvas->SetGridx( 0 ); iEnergyReconstructionMatrixCanvas->SetGridy( 0 ); iEnergyReconstructionMatrixCanvas->SetLeftMargin( 0.11 ); diff --git a/src/VPlotTMVAParameters.cpp b/src/VPlotTMVAParameters.cpp deleted file mode 100644 index c7c11ce57..000000000 --- a/src/VPlotTMVAParameters.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* \class VPlotTMVAParameters - - plot signal and background efficiency, and MVA cut variable for different - subarrays from TMVA output files - - Example: - - .L lib/libVAnaSum.so - VPlotTMVAParameters a; - a.setSubArrays( "scripts/CTA/subArray.prod1-red.list"); - a.setDirectories( "$CTA_USER_DATA_DIR/analysis/AnalysisData/cta-ultra3/EffectiveArea-ID2-d20130415/QualityCuts001CU/" ); - a.initializeWeightFiles( "$CTA_USER_DATA_DIR/analysis/AnalysisData/cta-ultra3/", "TMVA/BDT-ID2-d20130415-0.0/BDT_", 0, 8 ); - -*/ - -#include "VPlotTMVAParameters.h" - -VPlotTMVAParameters::VPlotTMVAParameters() -{ - fDataDirectory = ""; -} - -void VPlotTMVAParameters::plot( bool iPrint ) -{ - char hname[2000]; - char htitle[2000]; - - for( unsigned int i = 0; i < hSignalEfficiency.size(); i++ ) - { - - // signal and background efficiency - sprintf( hname, "cTMVA_S_BC_%d", i ); - sprintf( htitle, "signal/background efficiency distribution (energy/zenith bin %d)", i ); - TCanvas* c = new TCanvas( hname, htitle, 100 + i * 20, 100 + i * 20, 400, 400 ); - c->SetGridx( 0 ); - c->SetGridy( 0 ); - - if( hSignalEfficiency[i] ) - { - hSignalEfficiency[i]->Draw(); - cout << "Signal efficiency in energy/zenith bin " << i << ": "; - cout << hSignalEfficiency[i]->GetMean() << " +- " << hSignalEfficiency[i]->GetRMS() << endl; - } - if( i < hBackgroundEfficiency.size() && hBackgroundEfficiency[i] && hBackgroundEfficiency[i]->GetEntries() > 0 ) - { - hBackgroundEfficiency[i]->Draw( "same" ); - cout << "\t Background efficiency in energy/zenith bin " << i << ": "; - cout << hBackgroundEfficiency[i]->GetMean() << " +- " << hBackgroundEfficiency[i]->GetRMS() << endl; - } - if( iPrint ) - { - sprintf( hname, "efficiency-%d.eps", i ); - c->Print( hname ); - } - - - // MVA cut variable - sprintf( hname, "cTMVA_MVA_%d", i ); - sprintf( htitle, "MVA cut variable(energy/zenith bin %d)", i ); - TCanvas* d = new TCanvas( hname, htitle, 600 + i * 20, 100 + i * 20, 400, 400 ); - d->SetGridx( 0 ); - d->SetGridy( 0 ); - - if( i < hMVA.size() ) - { - hMVA[i]->Draw(); - cout << "\t MVA cut in energy/zenith bin " << i << ": "; - cout << hMVA[i]->GetMean() << " +- " << hMVA[i]->GetRMS() << endl; - } - if( iPrint ) - { - sprintf( hname, "mva-%d.eps", i ); - d->Print( hname ); - } - } -} - -bool VPlotTMVAParameters::initializeHistograms( unsigned int iEnergyWeightFileIndex_min, unsigned int iEnergyWeightFileIndex_max, unsigned int iZenithWeightFileIndex_min, unsigned int iZenithWeightFileIndex_max ) -{ - char hname[2000]; - - hSignalEfficiency.clear(); - hBackgroundEfficiency.clear(); - hMVA.clear(); - - for( unsigned int i = iEnergyWeightFileIndex_min; i <= iEnergyWeightFileIndex_max; i++ ) - { - for( unsigned int j = iZenithWeightFileIndex_min; j <= iEnergyWeightFileIndex_max; j++ ) - { - sprintf( hname, "hSignalEfficiency_%d_%d", i, j ); - hSignalEfficiency.push_back( new TH1D( hname, "", 100, 0., 1. ) ); - hSignalEfficiency.back()->SetXTitle( "efficiency" ); - hSignalEfficiency.back()->SetLineWidth( 2 ); - - sprintf( hname, "hBackgroundEfficiency_%d_%d", i, j ); - hBackgroundEfficiency.push_back( new TH1D( hname, "", 100, 0., 1. ) ); - hBackgroundEfficiency.back()->SetXTitle( "efficiency" ); - hBackgroundEfficiency.back()->SetLineWidth( 2 ); - hBackgroundEfficiency.back()->SetLineColor( 2 ); - - sprintf( hname, "hMVA_%d_%d", i, j ); - hMVA.push_back( new TH1D( hname, "", 100, -1., 1. ) ); - hMVA.back()->SetXTitle( "MVA variable" ); - hMVA.back()->SetLineWidth( 2 ); - hMVA.back()->SetLineColor( 4 ); - } - } - - return true; -} - -void VPlotTMVAParameters::initializeWeightFiles( string iDirectory, string iTMVADirectory, unsigned int iEnergyWeightFileIndex_min, unsigned int iEnergyWeightFileIndex_max, unsigned int iZenithWeightFileIndex_min, unsigned int iZenithWeightFileIndex_max, double iParticleNumberFile_Conversion_Rate_to_seconds ) -{ - if( !initializeHistograms( iEnergyWeightFileIndex_min, iEnergyWeightFileIndex_max, iZenithWeightFileIndex_min, iZenithWeightFileIndex_max ) ) - { - cout << "VPlotTMVAParameters::initializeWeightFiles error initializing histograms" << endl; - return; - } - - // loop over all sub arrays, get efficiency from optimization and fill them into histograms - char hname[2000]; - for( unsigned int i = 0; i < fSubArrays.size(); i++ ) - { - VTMVAEvaluator a; - sprintf( hname, "%s/ParticleNumbers.%s.00.root", fDataDirectory.c_str(), fSubArrays[i].c_str() ); - a.setParticleNumberFile( hname, iParticleNumberFile_Conversion_Rate_to_seconds ); - sprintf( hname, "%s/%s/%s", iDirectory.c_str(), fSubArrays[i].c_str(), iTMVADirectory.c_str() ); - a.initializeWeightFiles( hname, iEnergyWeightFileIndex_min, iEnergyWeightFileIndex_max, iZenithWeightFileIndex_min, iZenithWeightFileIndex_max ); - - for( unsigned int j = 0; j < a.getOptimumCutValueFound().size(); j++ ) - { - if( a.getOptimumCutValueFound()[j] ) - { - if( j < a.getSignalEfficiency().size() && j < hSignalEfficiency.size() && hSignalEfficiency[j] ) - { - hSignalEfficiency[j]->Fill( a.getSignalEfficiency()[j] ); - } - if( j < a.getBackgroundEfficiency().size() && j < hBackgroundEfficiency.size() && hBackgroundEfficiency[j] ) - { - hBackgroundEfficiency[j]->Fill( a.getBackgroundEfficiency()[j] ); - } - if( j < a.getTMVACutValue().size() && j < hMVA.size() && hMVA[j] ) - { - hMVA[j]->Fill( a.getTMVACutValue()[j] ); - } - } - } - } -} - -bool VPlotTMVAParameters::setSubArrays( string iFileTxt ) -{ - fSubArrays.clear(); - - ifstream is; - is.open( iFileTxt.c_str(), ifstream::in ); - if( !is ) - { - return false; - } - - string is_line; - while( getline( is, is_line ) ) - { - fSubArrays.push_back( is_line ); - } - - if( fSubArrays.size() == 0 ) - { - cout << "VPlotTMVAParameters::setSubArrays: no arrays found" << endl; - cout << "\t " << iFileTxt << endl; - return false; - } - - cout << "found " << fSubArrays.size() << " sub arrays" << endl; - - return true; -} - diff --git a/src/VReadRunParameter.cpp b/src/VReadRunParameter.cpp index 161dc729d..9ccf3f0b0 100644 --- a/src/VReadRunParameter.cpp +++ b/src/VReadRunParameter.cpp @@ -2,7 +2,7 @@ \brief read command line parameters and do some tests for consistency evndisp -help gives an overview of the most important parameters - all parameters are listed in README/README.EVNDISP.commandline + all parameters are listed in docs/EVNDISP.commandline.md */ @@ -779,7 +779,6 @@ bool VReadRunParameter::readCommandline( int argc, char* argv[] ) { fRunPara->foutputfileName = ""; } - cout << fRunPara->foutputfileName.c_str() << endl; } else if( iTemp.find( "highres" ) < iTemp.size() ) { @@ -1536,10 +1535,10 @@ void VReadRunParameter::printHelp() cout << endl; if( gSystem->Getenv( "EVNDISPSYS" ) ) { - int syst_ret = system( "cat $EVNDISPSYS/README/README.EVNDISP" ); + int syst_ret = system( "cat $EVNDISPSYS/docs/EVNDISP.commandline.md" ); if( syst_ret == -1 ) { - cout << "VReadRunParameter::printHelp() error: could not find helper file in README directory" << endl; + cout << "VReadRunParameter::printHelp() error: could not find helper file in docs directory" << endl; } } else @@ -1555,9 +1554,7 @@ void VReadRunParameter::setDirectories() // outputfilename //suppress output file for peds gain/toffset low gain/toffset lpeds DSTs - cout << fRunPara->foutputfileName << endl; - //if( fRunPara->frunmode == 1 || fRunPara->frunmode == 2 || fRunPara->frunmode == 5 || fRunPara->frunmode == 6 || fRunPara->frunmode == 4 ) - if( fRunPara->frunmode == 2 || fRunPara->frunmode == 5 || fRunPara->frunmode == 6 || fRunPara->frunmode == 4 ) + if( fRunPara->frunmode == 1 || fRunPara->frunmode == 2 || fRunPara->frunmode == 5 || fRunPara->frunmode == 6 || fRunPara->frunmode == 4 ) { fRunPara->foutputfileName = "-1"; } diff --git a/src/VSensitivityCalculator.cpp b/src/VSensitivityCalculator.cpp index 2daac0541..605406fa8 100644 --- a/src/VSensitivityCalculator.cpp +++ b/src/VSensitivityCalculator.cpp @@ -495,7 +495,7 @@ vector< TGraph* > VSensitivityCalculator::getCrabSpectrum( vector< double > i_fC if( fEnergySpectrumfromLiterature == 0 ) { char hname[800]; - char hname2[800]; + ostringstream hname2; unsigned int i_CrabSpectrum_ID = 1; // NOTE: hardwired to 1! // Whipple Crab spectrum (1989) @@ -519,17 +519,19 @@ vector< TGraph* > VSensitivityCalculator::getCrabSpectrum( vector< double > i_fC } if( bUnit == "PFLUX" ) { - sprintf( hname2, "%s", hname ); + hname2 << hname; } else if( bUnit == "ENERGY" ) { - sprintf( hname2, "%s * 1.e12 * x * x * %e", hname, fConstant_Flux_To_Ergs ); + hname2 << hname << " * 1.e12 * x * x * " << scientific << fConstant_Flux_To_Ergs; } else { - sprintf( hname2, "%f", 1. ); + hname2.clear(); + hname2.str( std::string() ); + hname2 << "1."; } - i_fFunCrabFlux = new TF1( "i_fFunCrabFlux", hname2, TMath::Power( 10., fEnergy_min_Log ), 10000. ); + i_fFunCrabFlux = new TF1( "i_fFunCrabFlux", hname2.str().c_str(), TMath::Power( 10., fEnergy_min_Log ), 10000. ); } // use spectrum from text file else @@ -1355,7 +1357,7 @@ TCanvas* VSensitivityCalculator::plotObservationTimevsFlux( unsigned int iD, TCa } -void VSensitivityCalculator::list_sensitivity( unsigned int iD ) +void VSensitivityCalculator::list_sensitivity( unsigned int iD, bool print_latex_table_line, string iTitle ) { if( !checkDataSet( iD, "plotObservationTimevsFlux" ) ) { @@ -1364,6 +1366,18 @@ void VSensitivityCalculator::list_sensitivity( unsigned int iD ) calculateObservationTimevsFlux( iD ); + if( print_latex_table_line ) + { + list_sensitivity_latex_table( iD, iTitle ); + } + else + { + list_sensitivity_table( iD ); + } +} + +void VSensitivityCalculator::list_sensitivity_table( unsigned int iD ) +{ cout << " Flux time time" << endl; cout << " [Crab Units] [min] [h]" << endl; cout << " ========================================" << endl; @@ -1380,6 +1394,42 @@ void VSensitivityCalculator::list_sensitivity( unsigned int iD ) cout << " events, and using Li & Ma formula " << fLiAndMaEqu << ")" << endl; } +void VSensitivityCalculator::list_sensitivity_latex_table( + unsigned int iD, string iTitle, + double iSignalE, double iBackgroundE ) +{ + cout << "LATEXLINE "; + cout << iTitle << " & "; + if( iSignalE > 0. ) + { + cout << fData[iD].fSignal << " \\pm " << iSignalE << " & "; + } + else + { + cout << fData[iD].fSignal << " & "; + } + if( iBackgroundE > 0. ) + { + cout << fData[iD].fBackground << " \\pm " << iBackgroundE << " & "; + } + else + { + cout << fData[iD].fBackground << " & "; + } + // assume that 10 and 1% values are in source strength vectors + for( unsigned int i = 0; i < fSourceStrength.size(); i++ ) + { + if( TMath::Abs( fSourceStrength[i] - 0.1 ) < 1.e-7 ) + { + cout << setprecision( 3 ) << fGraphObsvsTime[iD]->Eval( fSourceStrength[i] ) * 60. << " & "; + } + if( TMath::Abs( fSourceStrength[i] - 0.01 ) < 1.e-7 ) + { + cout << setprecision( 3 ) << fGraphObsvsTime[iD]->Eval( fSourceStrength[i] ) << " "; + } + } + cout << "\\\\" << endl; +} double VSensitivityCalculator::calculateObservationTimevsFlux( unsigned int iD ) { diff --git a/src/VStereoAnalysis.cpp b/src/VStereoAnalysis.cpp index 574cca6b1..67e977e13 100644 --- a/src/VStereoAnalysis.cpp +++ b/src/VStereoAnalysis.cpp @@ -11,7 +11,7 @@ VStereoAnalysis::VStereoAnalysis( bool ion, string i_hsuffix, VAnaSumRunParamete fDebug = false; fDataFile = 0; - fInstrumentEpoch = "NOT_SET"; + fInstrumentEpochMinor = "NOT_SET"; fDirTot = iDirTot; fDirTotRun = iDirRun; bTotalAnalysisOnly = iTotalAnalysisOnly; @@ -848,34 +848,38 @@ void VStereoAnalysis::writeHistograms( bool bOn ) // copy effective areas and radial acceptance to anasum output file if( bOn ) { - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveArea ); - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gTimeBinnedMeanEffectiveArea ); - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEsys_MC ); - - // Both MC and REC effective areas are required for Binned Likelihood analysis - if( fRunPara->fLikelihoodAnalysis ) + if( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile != "IGNOREEFFECTIVEAREA" + && fRunPara->fRunList[fHisCounter].fEffectiveAreaFile != "IGNOREIRF" ) { - if( gMeanEffectiveAreaMC ) + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveArea ); + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gTimeBinnedMeanEffectiveArea ); + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEsys_MC ); + + // Both MC and REC effective areas are required for Binned Likelihood analysis + if( fRunPara->fLikelihoodAnalysis ) { - // (SOB) When nOn = 0 gMeanEffectiveAreaMC_on(E) = 0 - // VLikelihoodFitter will check gMeanEffectiveAreaMC_on::integral > 1 - gMeanEffectiveAreaMC->SetTitle( "gMeanEffectiveAreaMC_on" ); - gMeanEffectiveAreaMC->SetName( "gMeanEffectiveAreaMC_on" ); - - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveAreaMC ); + if( gMeanEffectiveAreaMC ) + { + // When nOn = 0 gMeanEffectiveAreaMC_on(E) = 0 + // VLikelihoodFitter will check gMeanEffectiveAreaMC_on::integral > 1 + gMeanEffectiveAreaMC->SetTitle( "gMeanEffectiveAreaMC_on" ); + gMeanEffectiveAreaMC->SetName( "gMeanEffectiveAreaMC_on" ); + + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveAreaMC ); + } + if( hResponseMatrix ) + { + hResponseMatrix->SetTitle( "hResponseMatrix_on" ); + hResponseMatrix->SetName( "hResponseMatrix_on" ); + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", hResponseMatrix ); + } } - if( hResponseMatrix ) + if( fRunPara->fRunList[fHisCounter].fAcceptanceFile.size() > 0 + && fRunPara->fRunList[fHisCounter].fAcceptanceFile != "IGNOREACCEPTANCE" ) { - hResponseMatrix->SetTitle( "hResponseMatrix_on" ); - hResponseMatrix->SetName( "hResponseMatrix_on" ); - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", hResponseMatrix ); + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fAcceptanceFile, "RadialAcceptances", 0 ); } } - if( fRunPara->fRunList[fHisCounter].fAcceptanceFile.size() > 0 - && fRunPara->fRunList[fHisCounter].fAcceptanceFile != "IGNOREACCEPTANCE" ) - { - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fAcceptanceFile, "RadialAcceptances", 0 ); - } } else { @@ -890,11 +894,15 @@ void VStereoAnalysis::writeHistograms( bool bOn ) sprintf( hname, "%s_off", gTimeBinnedMeanEffectiveArea->GetName() ); gTimeBinnedMeanEffectiveArea->SetName( hname ); } - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveArea ); - fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gTimeBinnedMeanEffectiveArea ); + if( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile != "IGNOREEFFECTIVEAREA" + && fRunPara->fRunList[fHisCounter].fEffectiveAreaFile != "IGNOREIRF" ) + { + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gMeanEffectiveArea ); + fHisto[fHisCounter]->writeObjects( fRunPara->fRunList[fHisCounter].fEffectiveAreaFile, "EffectiveAreas", gTimeBinnedMeanEffectiveArea ); + } // Both MC and REC effective areas are required for Binned Likelihood analysis - // (SOB) A set of Off MC effective areas and response matrix are used as a back up + // A set of Off MC effective areas and response matrix are used as a back up // If zero On counts the Off set will be used if( fRunPara->fLikelihoodAnalysis ) { @@ -1789,8 +1797,10 @@ void VStereoAnalysis::setCuts( VAnaSumRunParameterDataClass iL, int irun ) { if( iL.fCutFile != "" ) { - // read cuts from root file - if( iL.fCutFile.find( ".root" ) != string::npos ) + // read cuts from effective area root file + if( iL.fCutFile.find( ".root" ) != string::npos + && iL.fCutFile.find( "IGNOREEFFECTIVEAREA" ) == string::npos + && iL.fCutFile.find( "IGNOREIRF" ) == string::npos ) { string iEffFile = VUtilities::testFileLocation( iL.fCutFile, "EffectiveAreas", true ); @@ -1811,13 +1821,14 @@ void VStereoAnalysis::setCuts( VAnaSumRunParameterDataClass iL, int irun ) exit( EXIT_FAILURE ); } fCuts = iC; + cout << "Reading gamma/hadron cuts from effective area file " << iEffFile << endl; iF->Close(); } // read cuts from text file else { fCuts->setNTel( iL.fMaxTelID ); - fCuts->setInstrumentEpoch( fInstrumentEpoch ); + fCuts->setInstrumentEpoch( fInstrumentEpochMinor ); fCuts->setTelToAnalyze( fTelToAnalyze ); fCuts->readCuts( iL.fCutFile ); fCuts->setTheta2Cut( iL.fSourceRadius ); @@ -1964,7 +1975,7 @@ CData* VStereoAnalysis::getDataFromFile( int i_runNumber ) VEvndispRunParameter* i_runPara = ( VEvndispRunParameter* )fDataFile->Get( "runparameterV2" ); if( i_runPara ) { - fInstrumentEpoch = i_runPara->getInstrumentEpoch( true ); + fInstrumentEpochMinor = i_runPara->getInstrumentATMString(); fTelToAnalyze = i_runPara->fTelToAnalyze; } else @@ -1972,7 +1983,7 @@ CData* VStereoAnalysis::getDataFromFile( int i_runNumber ) cout << "VStereoAnalysis::getDataFromFile() warning: epoch of current file " << endl; cout << "and active telescope combination cannot be determined; " << endl; cout << "this might lead to a wrong choice in the gamma/hadron cuts - please check" << endl; - fInstrumentEpoch = "NOT_FOUND"; + fInstrumentEpochMinor = "NOT_FOUND"; } } return c; diff --git a/src/VStereoHistograms.cpp b/src/VStereoHistograms.cpp index 845d61298..f59eb06e8 100644 --- a/src/VStereoHistograms.cpp +++ b/src/VStereoHistograms.cpp @@ -897,7 +897,10 @@ void VStereoHistograms::writeObjects( string iFile, string iDirectory, TObject* } wDir = gDirectory; - iFile = VUtilities::testFileLocation( iFile, iDirectory, true ); + if( iFile.find( "IGNOREEFFECTIVEAREA" ) == string::npos ) + { + iFile = VUtilities::testFileLocation( iFile, iDirectory, true ); + } if( iFile.size() == 0 ) { iDir->cd(); diff --git a/src/VTMVAEvaluator.cpp b/src/VTMVAEvaluator.cpp index 80a046b24..1b67aa745 100644 --- a/src/VTMVAEvaluator.cpp +++ b/src/VTMVAEvaluator.cpp @@ -1,10 +1,6 @@ /*! \class VTMVAEvaluator \brief use a TMVA weight file for energy dependent gamma/hadron separation - TODO list - - - test theta2(E) optimization - */ #include "VTMVAEvaluator.h" @@ -31,14 +27,13 @@ void VTMVAEvaluator::reset() fMLR = 0.; fEmissionHeight = 0.; fEmissionHeightChi2_log10 = 0.; - fEnergyReconstructionMethod = 1; fEChi2S = 0.; fEChi2S_log10 = 0.; fdES = 0.; fSizeSecondMax_log10 = 0; - fTheta2 = 0.; fCoreDist = 0.; fDispDiff = 0.; + fDispDiff_log10 = 0.; fDummy = 0.; for( int i = 0; i < VDST_MAXTELESCOPES; i++ ) { @@ -47,19 +42,15 @@ void VTMVAEvaluator::reset() setTMVACutValue(); setSignalEfficiency(); - setIgnoreTheta2Cut(); setSpectralIndexForEnergyWeighting(); setParticleNumberFile(); setPlotEfficiencyPlotsPerBin(); + setPrintPlotting(); setSensitivityOptimizationParameters(); setSensitivityOptimizationFixedSignalEfficiency(); setSensitivityOptimizationMinSourceStrength(); - setTMVAAngularContainmentThetaFixedMinRadius(); setTMVAMethod(); - // default: don't expect that the theta2 cut is performed here - setTMVAThetaCutVariable( false ); setTMVAErrorFraction(); - setTMVAAngularContainmentRadiusMax(); fTMVA_EvaluationResult = -99.; fTMVACutValueNoVec = -99.; @@ -129,14 +120,39 @@ vector< string > VTMVAEvaluator::getTrainingVariables( string iXMLFile, vector< return iVar; } +/* + * return BDT file name + * +*/ +string VTMVAEvaluator::getBDTFileName( string iWeightFileName, unsigned int i_E_index, unsigned int i_Z_index, string iSuffix ) +{ + ostringstream iFullFileName; + if( iWeightFileName.size() > 0 ) + { + iFullFileName << iWeightFileName; + } + else + { + iFullFileName << fTMVAMethodName; + } + iFullFileName << "_" << i_E_index; + iFullFileName << "_" << i_Z_index; + if( iSuffix.find( "xml" ) != string::npos ) + { + iFullFileName << "_" << fTMVAMethodName; + } + iFullFileName << iSuffix; + return iFullFileName.str(); +} + /* initialize TMVA readers */ -bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, - unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax, - double iEnergyStepSize, string iInstrumentEpoch ) +bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, + unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, + unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ) { ////////////////////////////// // sanity checks @@ -182,137 +198,110 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int unsigned int jMinMissingBin = 0; for( unsigned int j = 0; j < iNbinZ; j++ ) { - ostringstream iFullFileName; - ostringstream iFullFileNameXML; - iFullFileName << iWeightFileName << "_" << iWeightFileIndex_Emin + i; - // backwards compatibility with CTA - if( iInstrumentEpoch != "noepoch" && iInstrumentEpoch != "CTA" ) - { - iFullFileName << "_" << iWeightFileIndex_Zmin + j; - } - iFullFileName << ".root"; - iFullFileNameXML << iWeightFileName << "_" << iWeightFileIndex_Emin + i; - if( iInstrumentEpoch != "noepoch" && iInstrumentEpoch != "CTA" ) - { - iFullFileNameXML << "_" << iWeightFileIndex_Zmin + j; - } - iFullFileNameXML << "_" << fTMVAMethodName << "_0.weights.xml"; - TFile iF( iFullFileName.str().c_str() ); + string iTMVAName = getBDTFileName( "", + iWeightFileIndex_Emin + i, iWeightFileIndex_Zmin + j ); + string iFullFileName = getBDTFileName( iWeightFileName, + iWeightFileIndex_Emin + i, iWeightFileIndex_Zmin + j, ".root" ); + string iFullFileNameXML = getBDTFileName( iWeightFileName, + iWeightFileIndex_Emin + i, iWeightFileIndex_Zmin + j, "_0.weights.xml" ); + bool bGoodRun = true; VTMVARunDataEnergyCut* iEnergyData = 0; VTMVARunDataZenithCut* iZenithData = 0; - if( iF.IsZombie() ) + if( gSystem->AccessPathName( iFullFileName.c_str() ) ) { bGoodRun = false; } else { - iEnergyData = ( VTMVARunDataEnergyCut* )iF.Get( "fDataEnergyCut" ); - iZenithData = ( VTMVARunDataZenithCut* )iF.Get( "fDataZenithCut" ); - if( !iEnergyData ) - { - cout << "No energy cut data: setting goodrun to false" << endl; - bGoodRun = false; - } - // backwards compatibility - if( !iZenithData && iInstrumentEpoch != "noepoch" && iInstrumentEpoch != "CTA" ) + TFile iF( iFullFileName.c_str() ); + if( iF.IsZombie() ) { - cout << "No zenith cut data: "; - cout << " setting goodrun to false" << endl; bGoodRun = false; } - // signal efficiency - sprintf( hname, "Method_%s/%s_0/MVA_%s_0_effS", fTMVAMethodName.c_str(), fTMVAMethodName.c_str(), fTMVAMethodName.c_str() ); - - if( !iF.Get( hname ) ) - { - cout << "No signal efficiency histogram found (" << hname << ")" << endl; - bGoodRun = false; - } - } - // allow that first files are missing (this happens when there are no training events in the first energy bins) - if( !bGoodRun ) - { - if( i == iMinMissingBin || j == jMinMissingBin ) + else { - cout << "VTMVAEvaluator::initializeWeightFiles() warning: TMVA root file not found or incomplete file (" << i << ") " << endl; - cout << iFullFileName.str() << endl; - if( i == iMinMissingBin ) + iEnergyData = ( VTMVARunDataEnergyCut* )iF.Get( "fDataEnergyCut" ); + iZenithData = ( VTMVARunDataZenithCut* )iF.Get( "fDataZenithCut" ); + if( !iEnergyData || !iZenithData ) { - cout << " assume this is a low-energy empty bin (bin number " << i << ";"; - cout << " number of missing bins: " << iMinMissingBin + 1 << ")" << endl; - iMinMissingBin++; + cout << " No energy or zenith cut data" << endl; + bGoodRun = false; } - if( j == jMinMissingBin ) + // signal efficiency + sprintf( hname, "Method_%s/%s_0/MVA_%s_0_effS", + fTMVAMethodName.c_str(), fTMVAMethodName.c_str(), fTMVAMethodName.c_str() ); + + if( !iF.Get( hname ) ) { - cout << " assume this is a zenith empty bin (bin number " << j << ";"; - cout << " number of missing bins: " << jMinMissingBin + 1 << ")" << endl; + cout << " No signal efficiency histogram found (" << hname << ")" << endl; + bGoodRun = false; } - continue; } - else if( i == ( iWeightFileIndex_Emax ) || j == ( iWeightFileIndex_Zmax ) ) + // allow that first files are missing + // (this happens when there are no training events in the first energy or zenith bins) + if( !bGoodRun ) { - cout << "VTMVAEvaluator::initializeWeightFiles() warning: TMVA root file not found " << iFullFileName.str() << endl; - if( i == ( iWeightFileIndex_Emax ) ) + if( i == iMinMissingBin || j == jMinMissingBin ) { - cout << " assume this is a high-energy empty bin (bin number " << i << ")" << endl; - iNbinE--; - iWeightFileIndex_Emax--; + cout << "VTMVAEvaluator::initializeWeightFiles() warning: "; + cout << "TMVA root file not found or incomplete file (" << i << ") " << endl; + cout << iFullFileName << endl; + if( i == iMinMissingBin ) + { + cout << " assume this is a low-energy empty bin (bin number " << i << ";"; + cout << " number of missing energy bins: " << iMinMissingBin + 1 << ")" << endl; + iMinMissingBin++; + } + if( j == jMinMissingBin ) + { + cout << " assume this is a zenith empty bin (bin number " << j << ";"; + cout << " number of missing zenith bins: " << jMinMissingBin + 1 << ")" << endl; + jMinMissingBin++; + } + continue; } - if( j == ( iWeightFileIndex_Zmax ) ) + else if( i == ( iWeightFileIndex_Emax ) || j == ( iWeightFileIndex_Zmax ) ) { - cout << " assume this is a high-zenith empty bin (bin number " << j << ")" << endl; - iNbinZ--; - iWeightFileIndex_Zmax--; + cout << "VTMVAEvaluator::initializeWeightFiles(): TMVA root file not found " << iFullFileName << endl; + if( i == ( iWeightFileIndex_Emax ) ) + { + cout << " assume this is a high-energy empty bin (bin number " << i << ")" << endl; + } + if( j == ( iWeightFileIndex_Zmax ) ) + { + cout << " assume this is a high-zenith empty bin (bin number " << j << ")" << endl; + } + continue; + } + else + { + cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while initializing energies from TMVA root file "; + cout << iFullFileName << endl; + cout << "(this might be not a problem if the sensitive energy range of the given array is relatively small)" << endl; + continue; } - continue; } - else + if( !iEnergyData ) { - cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while initializing energies from TMVA root file "; - cout << iFullFileName.str() << endl; - cout << "(this might be not a problem if the sensitive energy range of the given array is relatively small)" << endl; - continue; + cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while reading energies from TMVA root file "; + cout << iFullFileName << endl; + fIsZombie = true; + return false; } - } - if( !iEnergyData ) - { - cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while reading energies from TMVA root file "; - cout << iFullFileName.str() << endl; - fIsZombie = true; - return false; - } - /* if( !iZenithData ) - { - cout << "VTMVAEvaluator::initializeWeightFiles: warning: problem while reading zeniths from TMVA root file "; - cout << iFullFileName.str() << endl; - fIsZombie = true; - return false; - } */ - // form here on: expect a good TMVA file - // initialize one value per energy/zenith bin - - // set energy binning: - // - one VTMVAEvaluatorData per energy bin - // - bins are set for the energy interval read from the root file: - // [iEnergyData->fEnergyCut_Log10TeV_min, iEnergyData->fEnergyCut_Log10TeV_max] - // - sub-bins given by iEnergyStepSize; - double e = iEnergyData->fEnergyCut_Log10TeV_min; - do - { + // form here on: expect a good TMVA file + // initialize one value per energy/zenith bin + + // set energy binning: + // - one VTMVAEvaluatorData per energy bin + // - bins are set for the energy interval read from the root file: + // [iEnergyData->fEnergyCut_Log10TeV_min, iEnergyData->fEnergyCut_Log10TeV_max] // central data element for this energy bin fTMVAData.push_back( new VTMVAEvaluatorData() ); - // find e_min and e_max - fTMVAData.back()->fEnergyCut_Log10TeV_min = e; - if( iEnergyStepSize > 0. ) - { - fTMVAData.back()->fEnergyCut_Log10TeV_max = e + iEnergyStepSize; - } - else - { - fTMVAData.back()->fEnergyCut_Log10TeV_max = iEnergyData->fEnergyCut_Log10TeV_max; - } - e = fTMVAData.back()->fEnergyCut_Log10TeV_max; + fTMVAData.back()->fEnergyBin = i; + fTMVAData.back()->fZenithBin = j; + fTMVAData.back()->fEnergyCut_Log10TeV_min = iEnergyData->fEnergyCut_Log10TeV_min; + fTMVAData.back()->fEnergyCut_Log10TeV_max = iEnergyData->fEnergyCut_Log10TeV_max; // calculate spectral weighted mean energy fTMVAData.back()->fSpectralWeightedMeanEnergy_Log10TeV = @@ -347,37 +336,22 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int fTMVAData.back()->fBackgroundEfficiency = -99.; fTMVAData.back()->fTMVAOptimumCutValueFound = false; fTMVAData.back()->fSourceStrengthAtOptimum_CU = 0.; - fTMVAData.back()->fAngularContainmentRadius = -99.; - fTMVAData.back()->fAngularContainmentFraction = -99.; sprintf( hname, "bin %d, %.2f < log10(E) < %.2f, %.2f < Ze < %.2f)", ( int )( fTMVAData.size() - 1 ), fTMVAData.back()->fEnergyCut_Log10TeV_min, fTMVAData.back()->fEnergyCut_Log10TeV_max, fTMVAData.back()->fZenithCut_min, fTMVAData.back()->fZenithCut_max ); fTMVAData.back()->SetTitle( hname ); - sprintf( hname, "MVA%d%d", i, j ); + sprintf( hname, "%d%d", i, j ); fTMVAData.back()->fTMVAMethodTag = hname; - if( iNbinZ > 1 ) - { - sprintf( hname, "%d_%d", i, j ); - } - else - { - sprintf( hname, "%d", i ); - } - + sprintf( hname, "%d_%d", i, j ); fTMVAData.back()->fTMVAMethodTag_2 = hname; - fTMVAData.back()->fTMVAFileName = iFullFileName.str(); - fTMVAData.back()->fTMVAFileNameXML = iFullFileNameXML.str(); + fTMVAData.back()->fTMVAName = iTMVAName; + fTMVAData.back()->fTMVAFileName = iFullFileName; + fTMVAData.back()->fTMVAFileNameXML = iFullFileNameXML; - if( iEnergyStepSize < 0. ) - { - break; - } + iF.Close(); } - while( e < ( iEnergyData->fEnergyCut_Log10TeV_max - 0.0001 ) ); - - iF.Close(); }//end loop on zenith bins }//end loop on energy bins @@ -460,15 +434,6 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int { fTMVAData[b]->fTMVAReader->AddVariable( "dE", &fdES ); } - else if( iTrainingVariables[t] == "EChi2" && !iVariableIsASpectator[t] ) - { - fTMVAData[b]->fTMVAReader->AddVariable( "EChi2", &fEChi2S ); - fEnergyReconstructionMethod = 0; - } - else if( iTrainingVariables[t] == "log10(EChi2)" && !iVariableIsASpectator[t] ) - { - fTMVAData[b]->fTMVAReader->AddVariable( "log10(EChi2)", &fEChi2S_log10 ); - } else if( iTrainingVariables[t] == "dES" && !iVariableIsASpectator[t] ) { fTMVAData[b]->fTMVAReader->AddVariable( "dES", &fdES ); @@ -480,17 +445,11 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int else if( iTrainingVariables[t] == "EChi2S" && !iVariableIsASpectator[t] ) { fTMVAData[b]->fTMVAReader->AddVariable( "EChi2S", &fEChi2S ); - fEnergyReconstructionMethod = 1; } else if( iTrainingVariables[t] == "log10(EChi2S)" && !iVariableIsASpectator[t] ) { fTMVAData[b]->fTMVAReader->AddVariable( "log10(EChi2S)", &fEChi2S_log10 ); } - else if( iTrainingVariables[t] == "(Xoff*Xoff+Yoff*Yoff)" && !iVariableIsASpectator[t] ) - { - fTMVAData[b]->fTMVAReader->AddVariable( "(Xoff*Xoff+Yoff*Yoff)", &fTheta2 ); - setTMVAThetaCutVariable( true ); - } else if( iTrainingVariables[t] == "sqrt(Xcore*Xcore+Ycore*Ycore)" && !iVariableIsASpectator[t] ) { fTMVAData[b]->fTMVAReader->AddVariable( "sqrt(Xcore*Xcore+Ycore*Ycore)", &fCoreDist ); @@ -499,6 +458,10 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int { fTMVAData[b]->fTMVAReader->AddVariable( "DispDiff", &fDispDiff ); } + else if( iTrainingVariables[t] == "log10(DispDiff)" && !iVariableIsASpectator[t] ) + { + fTMVAData[b]->fTMVAReader->AddVariable( "log10(DispDiff)", &fDispDiff_log10 ); + } // Note: assume not more then 3 different telescope types else if( iTrainingVariables[t] == "NImages_Ttype[0]" && !iVariableIsASpectator[t] ) { @@ -530,7 +493,9 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int cout << endl; } } - if( !fTMVAData[b]->fTMVAReader->BookMVA( fTMVAData[b]->fTMVAMethodTag_2.c_str(), fTMVAData[b]->fTMVAFileNameXML.c_str() ) ) + if( !fTMVAData[b]->fTMVAReader->BookMVA( + fTMVAData[b]->fTMVAMethodTag_2.c_str(), + fTMVAData[b]->fTMVAFileNameXML.c_str() ) ) { cout << "VTMVAEvaluator::initializeWeightFiles: error while initializing TMVA reader from weight file "; cout << fTMVAData[b]->fTMVAFileNameXML << endl; @@ -558,7 +523,9 @@ bool VTMVAEvaluator::initializeWeightFiles( string iWeightFileName, unsigned int // smooth and interpolate if( fParticleNumberFileName.size() > 0 && fSmoothAndInterpolateMVAValues ) { - smoothAndInterPolateMVAValue( 0, 0, iWeightFileIndex_Emin, iWeightFileIndex_Emax, iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); + smoothAndInterPolateMVAValue( 0, 0, + iWeightFileIndex_Emin, iWeightFileIndex_Emax, + iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); } // print some info to screen @@ -733,33 +700,16 @@ bool VTMVAEvaluator::evaluate() { fEmissionHeightChi2_log10 = -10.; // !!! not clear what the best value is } - // fill according of energy reconstruction method - if( fEnergyReconstructionMethod == 0 ) + fEChi2S = fData->EChi2S; + if( fEChi2S > 0. ) { - fEChi2S = fData->EChi2; - if( fEChi2S > 0. ) - { - fEChi2S_log10 = TMath::Log10( fEChi2S ); - } - else - { - fEChi2S_log10 = 0.; // !!! not clear what the best value is - } - fdES = fData->dE; + fEChi2S_log10 = TMath::Log10( fEChi2S ); } else { - fEChi2S = fData->EChi2S; - if( fEChi2S > 0. ) - { - fEChi2S_log10 = TMath::Log10( fEChi2S ); - } - else - { - fEChi2S_log10 = 0.; // !!! not clear what the best value is - } - fdES = fData->dES; + fEChi2S_log10 = 0.; // !!! not clear what the best value is } + fdES = fData->dES; fSizeSecondMax_log10 = fData->SizeSecondMax; if( fSizeSecondMax_log10 > 0. ) { @@ -769,17 +719,16 @@ bool VTMVAEvaluator::evaluate() { fSizeSecondMax_log10 = 0.; // !!! not clear what the best value is } - // for no theta2: set this value extremely small - if( fTMVAIgnoreTheta2Cut ) + fCoreDist = sqrt( fData->Xcore * fData->Xcore + fData->Ycore * fData->Ycore ); + fDispDiff = fData->DispDiff; + if( fDispDiff > 0. ) { - fTheta2 = 1.e-30; + fDispDiff_log10 = log10( fDispDiff ); } else { - fTheta2 = fData->Xoff * fData->Xoff + fData->Yoff * fData->Yoff; + fDispDiff_log10 = 0.; // !!! not clear what the best value is } - fCoreDist = sqrt( fData->Xcore * fData->Xcore + fData->Ycore * fData->Ycore ); - fDispDiff = fData->DispDiff; if( fData->NTtype < VDST_MAXTELESCOPES ) { for( int i = 0; i < fData->NTtype; i++ ) @@ -810,14 +759,26 @@ bool VTMVAEvaluator::evaluate() // evaluate MVA for this event fTMVA_EvaluationResult = fTMVAData[iDataBin]->fTMVAReader->EvaluateMVA( fTMVAData[iDataBin]->fTMVAMethodTag_2 ); + // apply MVA cut - if( fTMVA_EvaluationResult < fTMVAData[iDataBin]->fTMVACutValue ) + bool i_useTMVAGraph = false; + // interpolate cuts + if( i_useTMVAGraph ) { - return false; + // TMPTMPTMP to be implemented + cout << "NOT IMPLEMENTED" << endl; } + // no interpolation applied else { - return true; + if( fTMVA_EvaluationResult < fTMVAData[iDataBin]->fTMVACutValue ) + { + return false; + } + else + { + return true; + } } } return false; @@ -830,27 +791,11 @@ bool VTMVAEvaluator::evaluate() */ unsigned int VTMVAEvaluator::getDataBin() { - if( !fData ) - { - return 9999; - } - - double ze = fData->Ze; - double iErec = 0; - if( fEnergyReconstructionMethod == 0 && fData->Erec > 0 ) - { - iErec = log10( fData->Erec ); - } - else if( fEnergyReconstructionMethod == 1 && fData->ErecS > 0 ) - { - iErec = log10( fData->ErecS ); - } - else + if( !fData || fData->ErecS <= 0 ) { return 9999; } - - return getDataBin( iErec, ze ); + return getDataBin( log10( fData->ErecS ), fData->Ze ); } @@ -867,9 +812,11 @@ unsigned int VTMVAEvaluator::getDataBin( double iErec, double iZe ) if( ( iZe > fTMVAData[i]->fZenithCut_min && iZe <= fTMVAData[i]->fZenithCut_max ) || iZe < -998. ) { // mean energy of this energy bin (possibly spectral weighted) - iMeanEnergy = VMathsandFunctions::getMeanEnergyInBin( 2, fTMVAData[i]->fEnergyCut_Log10TeV_min, - fTMVAData[i]->fEnergyCut_Log10TeV_max, - fSpectralIndexForEnergyWeighting ); + iMeanEnergy = VMathsandFunctions::getMeanEnergyInBin( + 2, + fTMVAData[i]->fEnergyCut_Log10TeV_min, + fTMVAData[i]->fEnergyCut_Log10TeV_max, + fSpectralIndexForEnergyWeighting ); // check which energy bin is closest if( TMath::Abs( iMeanEnergy - iErec ) < i_Diff_Energy ) { @@ -883,8 +830,8 @@ unsigned int VTMVAEvaluator::getDataBin( double iErec, double iZe ) { cout << "VTMVAEvaluator::getDataBin: " << iBin << endl; fTMVAData[iBin]->print(); - cout << "\t mean energy " << iMeanEnergy_min; - cout << ", log10 energy " << iErec << "\t" << i_Diff_Energy ; + cout << "\t closest mean energy " << iMeanEnergy_min; + cout << ", log10 energy_tested " << iErec << ", distance: " << i_Diff_Energy ; cout << "\t" << fSpectralIndexForEnergyWeighting << endl; } @@ -904,70 +851,12 @@ bool VTMVAEvaluator::initializeDataStrutures( CData* iC ) return true; } -/* - - get energy dependent theta2 cut - -*/ -double VTMVAEvaluator::getOptimalTheta2Cut( double iEnergy_log10TeV, double iZe ) -{ - if( fTMVAData.size() == 0 ) - { - cout << "VTMVAEvaluator::getOptimalTheta2Cut error: empty data vector" << endl; - return -99.; - } - - unsigned int iDataBin = getDataBin( iEnergy_log10TeV, iZe ); - - if( iDataBin < fTMVAData.size() ) - { - return ( fTMVAData[iDataBin]->fAngularContainmentRadius * fTMVAData[iDataBin]->fAngularContainmentRadius ); - } - - return 0.; -} - -/* - return a graph with all the theta2 cuts - - (is a memory leak...) - -*/ -TGraph* VTMVAEvaluator::getOptimalTheta2Cut_Graph() -{ - if( fTMVAData.size() == 0 ) - { - cout << "VTMVAEvaluator::getOptimalTheta2Cut_Graph error: empty data vector" << endl; - return 0; - } - - // sort - map< double, double > i_AngContaint; - for( unsigned int i = 0; i < fTMVAData.size(); i++ ) - { - if( fTMVAData[i] && fTMVAData[i]->fAngularContainmentRadius > 1.e-10 ) - { - i_AngContaint[0.5 * ( fTMVAData[i]->fEnergyCut_Log10TeV_min + fTMVAData[i]->fEnergyCut_Log10TeV_max )] = fTMVAData[i]->fAngularContainmentRadius; - } - } - - // fill the graph - energy is at the spectral weighted energy - TGraph* g = new TGraph( 1 ); - unsigned int z = 0; - for( map::iterator it = i_AngContaint.begin(); it != i_AngContaint.end(); ++it ) - { - g->SetPoint( z, it->first, it->second ); - z++; - } - - return g; -} - /* * plot signal and background efficiencies * */ -TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( bool iLogY, double iYmin, double iMVA_min, double iMVA_max ) +TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( + bool iLogY, double iYmin, double iMVA_min, double iMVA_max ) { if( fTMVAData.size() == 0 ) { @@ -995,45 +884,44 @@ TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( bool iLo continue; } - if( fTMVAData[i]->fSignalEfficiency > 0. && fTMVAData[i]->fBackgroundEfficiency > 0. ) + if( fTMVAData[i]->fSignalEfficiency < 0. || fTMVAData[i]->fBackgroundEfficiency < 0. ) { - if( fTMVAData[i]->fTMVAOptimumCutValueFound ) - { - igSignal->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fSignalEfficiency ); - igSignal->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igSignal->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - igBck->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fBackgroundEfficiency ); - igBck->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igBck->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - igCVa->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); - igCVa->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igCVa->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - z_opt++; - } - else if( fTMVAData[i]->fTMVACutValue > -90. ) - { - igSignalOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fSignalEfficiency ); - igSignalOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igSignalOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - igBckOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fBackgroundEfficiency ); - igBckOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igBckOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - igCVaOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); - igCVaOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); - igCVaOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - - z_noOpt++; - } + cout << "VTMVAEvaluator::plotSignalAndBackgroundEfficiencies: "; + cout << "signal / background efficiency histograms not found " << endl; + cout << fTMVAData[i]->fSignalEfficiency << "\t" << fTMVAData[i]->fBackgroundEfficiency << endl; + continue; } - else + if( fTMVAData[i]->fTMVAOptimumCutValueFound ) { - cout << "VTMVAEvaluator::plotSignalAndBackgroundEfficiencies: signal / background efficiency histograms not found " << endl; - cout << fTMVAData[i]->fSignalEfficiency << "\t" << fTMVAData[i]->fBackgroundEfficiency << endl; + igSignal->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fSignalEfficiency ); + igSignal->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igSignal->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + igBck->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fBackgroundEfficiency ); + igBck->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igBck->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + igCVa->SetPoint( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); + igCVa->SetPointEXlow( z_opt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igCVa->SetPointEXhigh( z_opt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + z_opt++; + } + else if( fTMVAData[i]->fTMVACutValue > -90. ) + { + igSignalOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fSignalEfficiency ); + igSignalOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igSignalOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + igBckOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fBackgroundEfficiency ); + igBckOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igBckOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + igCVaOpt->SetPoint( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); + igCVaOpt->SetPointEXlow( z_noOpt, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV - fTMVAData[i]->fEnergyCut_Log10TeV_min ); + igCVaOpt->SetPointEXhigh( z_noOpt, fTMVAData[i]->fEnergyCut_Log10TeV_max - fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + + z_noOpt++; } if( fTMVAData[i]->fBackgroundEfficiency < iMinBck ) { @@ -1042,7 +930,8 @@ TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( bool iLo } // plot everything - TCanvas* iCanvas = new TCanvas( "cSignalAndBackgroundEfficiencies", "signal and background efficiencies", 10, 10, 400, 400 ); + TCanvas* iCanvas = new TCanvas( "cSignalAndBackgroundEfficiencies", "signal and background efficiencies", + 10, 10, 400, 400 ); iCanvas->SetGridx( 0 ); iCanvas->SetGridy( 0 ); iCanvas->SetLeftMargin( 0.13 ); @@ -1102,6 +991,10 @@ TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( bool iLo { igBckOpt->Draw( "pl" ); } + if( fPrintPlotting ) + { + iCanvas->Print( "MVA-SignalBackgroundEfficiency.pdf" ); + } // plot MVA cut value if( igCVa ) @@ -1124,6 +1017,10 @@ TGraphAsymmErrors* VTMVAEvaluator::plotSignalAndBackgroundEfficiencies( bool iLo setGraphPlottingStyle( igCVaOpt, 1, 1., 24 ); igCVaOpt->Draw( "p" ); } + if( fPrintPlotting ) + { + iCVACanvas->Print( "MVA-MVACut.pdf" ); + } } return igCVa; @@ -1156,44 +1053,6 @@ void VTMVAEvaluator::setTMVACutValue( double iE ) fTMVACutValueNoVec = iE; } -void VTMVAEvaluator::printSourceStrength_CU() -{ - for( unsigned int i = 0; i < fTMVAData.size(); i++ ) - { - if( fTMVAData[i] ) - { - cout << "E [" << showpoint << setprecision( 3 ) << fTMVAData[i]->fEnergyCut_Log10TeV_min << "," << fTMVAData[i]->fEnergyCut_Log10TeV_max << "] TeV"; - cout << " (bin " << i << "):\t "; - cout << fTMVAData[i]->fSourceStrengthAtOptimum_CU << " CU " << endl; - } - } -} - -void VTMVAEvaluator::printAngularContainmentRadius() -{ - if( fTMVAData.size() == 0 ) - { - return; - } - - cout << endl; - cout << "======================= VTMVAEvaluator: energy dependent optimal containment radius cut =======================" << endl; - for( unsigned int i = 0; i < fTMVAData.size(); i++ ) - { - if( fTMVAData[i] ) - { - cout << "E [" << showpoint << setprecision( 3 ) << fTMVAData[i]->fEnergyCut_Log10TeV_min << "," << fTMVAData[i]->fEnergyCut_Log10TeV_max << "] TeV"; - cout << ", Ze [" << fTMVAData[i]->fZenithCut_min << "," << fTMVAData[i]->fZenithCut_max << "] deg"; - cout << " (bin " << i << "):\t "; - cout << fTMVAData[i]->fAngularContainmentRadius << " [deg], "; - cout << "T^2: " << fTMVAData[i]->fAngularContainmentRadius* fTMVAData[i]->fAngularContainmentRadius << " [deg^2], "; - cout << fTMVAData[i]->fAngularContainmentFraction << "%"; - cout << endl; - } - } - cout << noshowpoint << endl; -} - void VTMVAEvaluator::printSignalEfficiency() { if( fTMVAData.size() == 0 ) @@ -1207,7 +1066,8 @@ void VTMVAEvaluator::printSignalEfficiency() { if( fTMVAData[i] ) { - cout << "E [" << showpoint << setprecision( 3 ) << fTMVAData[i]->fEnergyCut_Log10TeV_min << "," << fTMVAData[i]->fEnergyCut_Log10TeV_max << "] TeV"; + cout << "E [" << showpoint << setprecision( 3 ); + cout << fTMVAData[i]->fEnergyCut_Log10TeV_min << "," << fTMVAData[i]->fEnergyCut_Log10TeV_max << "] TeV"; cout << ", Ze [" << fTMVAData[i]->fZenithCut_min << "," << fTMVAData[i]->fZenithCut_max << "] deg"; cout << " (bin " << i << "):\t "; cout << fTMVAData[i]->fSignalEfficiency; @@ -1233,11 +1093,30 @@ void VTMVAEvaluator::printSignalEfficiency() cout << noshowpoint << endl; } +/* + * print MVA cut values after optimization to be used + * in gamma/hadron cuts files + */ +void VTMVAEvaluator::printOptimizedMVACutValues( string iEpoch ) +{ + cout << "Printing Optimised cuts for gamma/hadron cut values" << endl; + cout << "\t this is only correct for an energyStepSize of -1" << endl; + cout << "* TMVA_MVACut " << iEpoch; + for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + { + cout << " " << fTMVAData[i]->fTMVAMethodTag; + cout << " " << fTMVAData[i]->fTMVACutValue; + } + cout << endl; + cout << "(first digit: energy bin, second digit: zenith bin)" << endl; +} + /* calculate the optimal signal to noise ratio for a given particle number spectrum - this routine is possible too complicated + this routine is possibly too complicated + - main problem is how to deal with low statistics bins */ @@ -1270,8 +1149,14 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) } cout << "TVMAEvaluator::optimizeSensitivity reading: " << fParticleNumberFileName << endl; // get the NOn (signal + background) and NOff (background) graphs - TGraph* i_on = readNonNoffGraphsFromFile( &iPN, fTMVAData[iDataBin]->fZenithCut_min, fTMVAData[iDataBin]->fZenithCut_max, true ); - TGraph* i_of = readNonNoffGraphsFromFile( &iPN, fTMVAData[iDataBin]->fZenithCut_min, fTMVAData[iDataBin]->fZenithCut_max, false ); + TGraph* i_on = readNonNoffGraphsFromFile( + &iPN, + fTMVAData[iDataBin]->fZenithCut_min, fTMVAData[iDataBin]->fZenithCut_max, + true ); + TGraph* i_of = readNonNoffGraphsFromFile( + &iPN, + fTMVAData[iDataBin]->fZenithCut_min, fTMVAData[iDataBin]->fZenithCut_max, + false ); if( !i_on || !i_of ) { cout << "VTVMAEvaluator::optimizeSensitivity error:" << endl; @@ -1279,19 +1164,6 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) cout << i_on << "\t" << i_of << endl; return false; } - // angular containment histogram - // (optional, only needed when containment radius is also optimized) - TH2D* iHAngContainment = ( TH2D* )iPN.Get( "AngResCumulative" ); - if( iHAngContainment ) - { - cout << "TVMAEvaluator::optimizeSensitivity: found angular containment histogram ("; - cout << fTMVAngularContainmentRadiusMax << "%)"; - cout << endl; - } - else - { - cout << "TVMAEvaluator::optimizeSensitivity no angular containment histogram found" << endl; - } ////////////////////////////////////////////////////// // get mean energy of the considered bins @@ -1344,10 +1216,11 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) // // Convert the observing time in seconds as the particle rate is given in 1/seconds // Get the value of the middle of the energy and zenith angle bin - // TODODODODO minutes or seconds? - Non = i_on->Eval( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) * fOptimizationObservingTime_h * fParticleNumberFile_Conversion_Rate_to_seconds; - Nof = i_of->Eval( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) * fOptimizationObservingTime_h * fParticleNumberFile_Conversion_Rate_to_seconds; - + Non = i_on->Eval( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) + * fOptimizationObservingTime_h * fParticleNumberFile_Conversion_Rate_to_seconds; + Nof = i_of->Eval( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) + * fOptimizationObservingTime_h * fParticleNumberFile_Conversion_Rate_to_seconds; + if( Nof < 0. ) { Nof = 0.; @@ -1357,11 +1230,14 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) cout << "VTVMAEvaluator::optimizeSensitivity event numbers: "; cout << " non = " << Non; cout << " noff = " << Nof; - cout << " ndif = " << Ndif << " (1 CU)" << endl; + cout << " ndiff = " << Ndif << " (1 CU)" << endl; cout << "VTVMAEvaluator::optimizeSensitivity event numbers: "; cout << " (data bin " << iDataBin; - cout << ", weighted mean energy " << TMath::Power( 10., fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) << " [TeV], "; - cout << fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV << ")"; + cout << ", weighted mean energy "; + cout << TMath::Power( 10., fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ) << " [TeV], "; + cout << fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV << "), "; + cout << " Ebin [" << fTMVAData[iDataBin]->fEnergyCut_Log10TeV_min; + cout << ", " << fTMVAData[iDataBin]->fEnergyCut_Log10TeV_max << "]"; cout << endl; /////////////////////////////////////////////////////////////////// @@ -1385,84 +1261,35 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) cout << effS << "\t" << effB << endl; return false; } - // evaluate errors on determination of background cut efficiency and remove bins with large errors - char hname[800]; - sprintf( hname, "Method_%s/%s_0/MVA_%s_0_B", fTMVAMethodName.c_str(), - fTMVAMethodName.c_str(), fTMVAMethodName.c_str() ); - TH1F* effB_counts = ( TH1F* )iTMVAFile.Get( hname ); - if( effB_counts ) - { - double iMaxMVACutValue = -1.; - for( int i = effB_counts->GetNbinsX() - 1; i > 0; i-- ) - { - if( effB_counts->GetBinContent( i ) > 0. ) - { - if( effB_counts->GetBinError( i ) / effB_counts->GetBinContent( i ) > fTMVAErrorFraction_min ) - { - iMaxMVACutValue = effB_counts->GetBinCenter( i ); - } - else - { - break; - } - } - } - if( iMaxMVACutValue > 0. ) - { - cout << "VTVMAEvaluator::optimizeSensitivity() removing low significance bins from background efficiency curve ("; - cout << fTMVAErrorFraction_min << ", " << iMaxMVACutValue << ")" << endl; - for( int i = 1; i <= effB->GetNbinsX(); i++ ) - { - if( effB->GetBinCenter( i ) > iMaxMVACutValue ) - { - effB->SetBinContent( i, 0. ); - } - } - } - } - else - { - cout << "VTVMAEvaluator::optimizeSensitivity() no background efficiency histogram found" << endl; - } - - cout << "VTVMAEvaluator::optimizeSensitivity() optimization parameters: "; - cout << "maximum signal efficiency is " << fOptimizationFixedSignalEfficiency << " minimum source strength is " << fOptimizationMinSourceStrength << endl; - cout << " (alpha: " << fOptimizationBackgroundAlpha << ")" << endl; - ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // optimization starts here ////////////////////////////////////////////////////////////////////////// double i_Signal_to_sqrtNoise = 0.; - double i_AngularContainmentRadius = 0.; - double i_AngularContainmentFraction = 0.; double i_TMVACutValue_AtMaximum = -99.; double i_SourceStrength_atMaximum = 0.; double i_SignalEfficiency_AtMaximum = -99.; double i_BackgroundEfficiency_AtMaximum = -99.; double i_Signal_to_sqrtNoise_atMaximum = 0.; - double i_AngularContainmentRadiusAtMaximum = 0.; - double i_AngularContainmentFractionAtMaximum = 0.; TGraph* iGSignal_to_sqrtNoise = 0; TGraph* iGSignalEvents = 0; TGraph* iGBackgroundEvents = 0; TGraph* iGSignal_to_sqrtNoise_Smooth = 0; - TGraph* iGOpt_AngularContainmentRadius = 0; - TGraph* iGOpt_AngularContainmentFraction = 0; ////////////////////////////////////////////////////// // loop over different source strengths (in Crab Units) // (hardwired: start at 0.001 CU to 30 CU) - unsigned int iSourceStrengthStepSizeN = ( unsigned int )( ( log10( 30. ) - log10( fOptimizationMinSourceStrength ) ) / 0.005 ); + unsigned int iSourceStrengthStepSizeN = + ( unsigned int )( ( log10( 30. ) - log10( fOptimizationMinSourceStrength ) ) / 0.005 ); cout << "VTVMAEvaluator::optimizeSensitivity(), source strength steps: " << iSourceStrengthStepSizeN << endl; for( unsigned int s = 0; s < iSourceStrengthStepSizeN; s++ ) { double iSourceStrength = log10( fOptimizationMinSourceStrength ) + s * 0.005; iSourceStrength = TMath::Power( 10., iSourceStrength ); - // source events + // source (excess) events Ndif = ( Non - Nof ) * iSourceStrength; // first quick pass to see if there is a change of reaching the required fOptimizationSourceSignificance @@ -1475,9 +1302,10 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) { if( fOptimizationBackgroundAlpha > 0. ) { - i_Signal_to_sqrtNoise = VStatistics::calcSignificance( effS->GetBinContent( i ) * Ndif + effB->GetBinContent( i ) * Nof, - effB->GetBinContent( i ) * Nof / fOptimizationBackgroundAlpha, - fOptimizationBackgroundAlpha ); + i_Signal_to_sqrtNoise = VStatistics::calcSignificance( + effS->GetBinContent( i ) * Ndif + effB->GetBinContent( i ) * Nof, + effB->GetBinContent( i ) * Nof / fOptimizationBackgroundAlpha, + fOptimizationBackgroundAlpha ); // check significance criteria if( i_Signal_to_sqrtNoise > fOptimizationSourceSignificance ) { @@ -1500,22 +1328,15 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) ////////////////////////////////////////////////////// // now loop over signal and background efficiency levels i_Signal_to_sqrtNoise = 0.; - i_AngularContainmentRadius = 0.; - i_AngularContainmentFraction = 0.; - i_TMVACutValue_AtMaximum = -99.; i_SourceStrength_atMaximum = 0.; i_SignalEfficiency_AtMaximum = -99.; i_BackgroundEfficiency_AtMaximum = -99.; i_Signal_to_sqrtNoise_atMaximum = 0.; - i_AngularContainmentRadiusAtMaximum = 0.; - i_AngularContainmentFractionAtMaximum = 0.; iGSignal_to_sqrtNoise = new TGraph( 1 ); iGSignalEvents = new TGraph( 1 ); iGBackgroundEvents = new TGraph( 1 ); - iGOpt_AngularContainmentRadius = new TGraph( 1 ); - iGOpt_AngularContainmentFraction = new TGraph( 1 ); int z = 0; int z_SB = 0; @@ -1526,28 +1347,15 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) { if( fOptimizationBackgroundAlpha > 0. ) { - if( iHAngContainment && fTMVA_OptimizeAngularContainment ) - { - getOptimalAngularContainmentRadius( effS->GetBinContent( i ), effB->GetBinContent( i ), Ndif, Nof, - iHAngContainment, fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV, - i_Signal_to_sqrtNoise, i_AngularContainmentRadius, i_AngularContainmentFraction ); - } - else - { - i_Signal_to_sqrtNoise = VStatistics::calcSignificance( effS->GetBinContent( i ) * Ndif + effB->GetBinContent( i ) * Nof, + // optimize signal/sqrt(noise) + i_Signal_to_sqrtNoise = VStatistics::calcSignificance( + effS->GetBinContent( i ) * Ndif + effB->GetBinContent( i ) * Nof, effB->GetBinContent( i ) * Nof / fOptimizationBackgroundAlpha, fOptimizationBackgroundAlpha ); - i_AngularContainmentRadius = VHistogramUtilities::interpolateTH2D( iHAngContainment, - fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV, - fTMVAngularContainmentRadiusMax ); - i_AngularContainmentFraction = fTMVAngularContainmentRadiusMax; - } } else { i_Signal_to_sqrtNoise = 0.; - i_AngularContainmentRadius = 0.; - i_AngularContainmentFraction = fTMVAngularContainmentRadiusMax; } if( fDebug ) { @@ -1580,12 +1388,9 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) if( iGSignal_to_sqrtNoise && i_Signal_to_sqrtNoise > 1.e-2 ) { iGSignal_to_sqrtNoise->SetPoint( z, effS->GetBinCenter( i ), i_Signal_to_sqrtNoise ); - iGOpt_AngularContainmentRadius->SetPoint( z, effS->GetBinCenter( i ), i_AngularContainmentRadius ); - iGOpt_AngularContainmentFraction->SetPoint( z, effS->GetBinCenter( i ), i_AngularContainmentFraction ); if( fDebug ) { - cout << "\t SET " << z << "\t" << effS->GetBinCenter( i ) << "\t" << i_Signal_to_sqrtNoise << "\t"; - cout << i_AngularContainmentRadius << "\t" << i_AngularContainmentFraction << endl; + cout << "\t SET " << z << "\t" << effS->GetBinCenter( i ) << "\t" << i_Signal_to_sqrtNoise << endl; } z++; } @@ -1596,6 +1401,8 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) } } } // END loop over all signal efficiency bins + ///////////////////////// + // determine position of maximum significance // fill a histogram from these values, smooth it, and determine position of maximum significance double i_xmax = -99.; if( iGSignal_to_sqrtNoise ) @@ -1614,8 +1421,8 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) i_ymax = y; i_xmax = x; } - // stop after first maximim (makes maximum research more robust to fluctuations of the - // background efficiency + // stop after first maximum (makes maximum research more robust to fluctuations of the + // background efficiency) else if( y < i_ymax ) { break; @@ -1626,8 +1433,6 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) i_TMVACutValue_AtMaximum = i_xmax; i_Signal_to_sqrtNoise_atMaximum = i_ymax; i_SourceStrength_atMaximum = iSourceStrength; - i_AngularContainmentRadiusAtMaximum = iGOpt_AngularContainmentRadius->Eval( i_xmax ); - i_AngularContainmentFractionAtMaximum = iGOpt_AngularContainmentFraction->Eval( i_xmax ); } /////////////////////////////////////////////////////// // check if value if really at the optimum or if information is missing from background efficiency curve @@ -1698,14 +1503,6 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) { delete iGSignal_to_sqrtNoise_Smooth; } - if( iGOpt_AngularContainmentRadius ) - { - delete iGOpt_AngularContainmentRadius; - } - if( iGOpt_AngularContainmentFraction ) - { - delete iGOpt_AngularContainmentFraction; - } } } // end of loop over source strength /////////////////////////////////////////////////////////////////////// @@ -1728,15 +1525,14 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) { i_TMVACutValue_AtMaximum = effS->GetBinCenter( i ); i_BackgroundEfficiency_AtMaximum = effB->GetBinContent( i ); - i_AngularContainmentRadiusAtMaximum = iGOpt_AngularContainmentRadius->Eval( i_TMVACutValue_AtMaximum ); - i_AngularContainmentFractionAtMaximum = iGOpt_AngularContainmentFraction->Eval( i_TMVACutValue_AtMaximum ); break; } } } - i_SignalEfficiency_AtMaximum = fOptimizationFixedSignalEfficiency; cout << "VTMVAEvaluator::optimizeSensitivity: setting signal efficiency to "; - cout << fOptimizationFixedSignalEfficiency << endl; + cout << fOptimizationFixedSignalEfficiency; + cout << " (from " << i_SignalEfficiency_AtMaximum << ")" << endl; + i_SignalEfficiency_AtMaximum = fOptimizationFixedSignalEfficiency; } else { @@ -1747,292 +1543,249 @@ bool VTMVAEvaluator::optimizeSensitivity( unsigned int iDataBin ) } cout << "\t MVA parameter: " << i_TMVACutValue_AtMaximum; cout << ", background efficiency: " << i_BackgroundEfficiency_AtMaximum << endl; - cout << "\t angular containment is " << i_AngularContainmentFractionAtMaximum * 100. << "%, radius "; - cout << i_AngularContainmentRadiusAtMaximum << " [deg]"; - if( iHAngContainment ) - { - cout << " (scaled from " << iHAngContainment->GetBinContent( iHAngContainment->GetXaxis()->FindBin( fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV ), - iHAngContainment->GetYaxis()->FindBin( fTMVAngularContainmentRadiusMax ) ); - cout << " [deg], " << fTMVAngularContainmentRadiusMax * 100. << "%)"; - } - cout << endl; //////////////////////////////////////////////////////////////// - // get mean energy for this bin - double iMeanEnergyAfterCuts = getMeanEnergyAfterCut( &iTMVAFile, i_TMVACutValue_AtMaximum, iDataBin ); - cout << "Mean energy after cuts [TeV]: " << iMeanEnergyAfterCuts << endl; - // fill results into data vectors fTMVAData[iDataBin]->fSignalEfficiency = i_SignalEfficiency_AtMaximum; fTMVAData[iDataBin]->fBackgroundEfficiency = i_BackgroundEfficiency_AtMaximum; fTMVAData[iDataBin]->fTMVACutValue = i_TMVACutValue_AtMaximum; fTMVAData[iDataBin]->fSourceStrengthAtOptimum_CU = i_SourceStrength_atMaximum; - if( iMeanEnergyAfterCuts > 0. ) - { - fTMVAData[iDataBin]->fSpectralWeightedMeanEnergy_Log10TeV = log10( iMeanEnergyAfterCuts ); - } - fTMVAData[iDataBin]->fAngularContainmentRadius = i_AngularContainmentRadiusAtMaximum; - fTMVAData[iDataBin]->fAngularContainmentFraction = i_AngularContainmentFractionAtMaximum; // plot optimziation procedure and event numbers if( bPlotEfficiencyPlotsPerBin ) { plotEfficiencyPlotsPerBin( iDataBin, iGSignal_to_sqrtNoise, iGSignal_to_sqrtNoise_Smooth, - effS, effB, iGSignalEvents, iGBackgroundEvents, - iGOpt_AngularContainmentRadius, iGOpt_AngularContainmentFraction ); + effS, effB, iGSignalEvents, iGBackgroundEvents ); } return true; } -/* +/* smoothing of optimal cut value vs energy curves - missing (non-optimized) are interpolated - - note: signal and background efficiencies are not updated + (energy axis only) */ -void VTMVAEvaluator::smoothAndInterPolateMVAValue( TH1F* effS, TH1F* effB, unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ) +void VTMVAEvaluator::smoothAndInterPolateMVAValue_EnergyOnly( + TH1F* effS, TH1F* effB ) { - if( fTMVAData.size() == 0 ) - { - return; - } - - cout << "Smooth and interpolate MVA cut values" << endl; - int z = 0; - - // take zenith angle dependence into account - unsigned int Ebins = iWeightFileIndex_Emax - iWeightFileIndex_Emin + 1; - unsigned int ZEbins = iWeightFileIndex_Zmax - iWeightFileIndex_Zmin + 1; - - // only energy dependent - if( ZEbins == 1 ) + // fill graph to be smoothed + TGraph* iG = new TGraph( 1 ); + for( unsigned int i = 0; i < fTMVAData.size(); i++ ) { - // fill graph to be smoothed - TGraph* iG = new TGraph( 1 ); - for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + if( fTMVAData[i] ) { - if( fTMVAData[i] ) + if( fTMVAData[i]->fTMVAOptimumCutValueFound ) { - if( fTMVAData[i]->fTMVAOptimumCutValueFound ) - { - iG->SetPoint( z, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); - z++; - } + iG->SetPoint( z, fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV, fTMVAData[i]->fTMVACutValue ); + z++; } } - // smooth graph - TGraph* iGout = new TGraph( 1 ); - TGraphSmooth* iGSmooth = new TGraphSmooth( "t" ); - iGout = ( TGraph* )iGSmooth->SmoothKern( iG, "normal", 0.5, 100 ); - //iGout = ( TGraph* )iGSmooth->SmoothLowess( iG, " ", 0.90 ); - - // fill smoothed and interpolated values into MVA vector - // set all points to 'optimized' - for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + } + // smooth graph + TGraph* iGout = new TGraph( 1 ); + TGraphSmooth* iGSmooth = new TGraphSmooth( "t" ); + iGout = ( TGraph* )iGSmooth->SmoothKern( iG, "normal", 0.5, 100 ); + + // fill smoothed and interpolated values into MVA vector + // set all points to 'optimized' + for( unsigned int i = 0; i < fTMVAData.size(); i++ ) + { + if( fTMVAData[i] ) { - if( fTMVAData[i] ) + cout << "\t TMVA values: unsmoothed at "; + cout << TMath::Power( 10., fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + cout << " TeV, \t" << fTMVAData[i]->fTMVACutValue; + fTMVAData[i]->fTMVACutValue = iGout->Eval( fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); + cout << ", smoothed " << fTMVAData[i]->fTMVACutValue; + if( !fTMVAData[i]->fTMVAOptimumCutValueFound ) { - cout << "\t TMVA values: unsmoothed at " << TMath::Power( 10., fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - cout << " TeV, \t" << fTMVAData[i]->fTMVACutValue; - fTMVAData[i]->fTMVACutValue = iGout->Eval( fTMVAData[i]->fSpectralWeightedMeanEnergy_Log10TeV ); - cout << ", smoothed " << fTMVAData[i]->fTMVACutValue; - if( !fTMVAData[i]->fTMVAOptimumCutValueFound ) - { - cout << " (interpolated non-optimal value)"; - } - cout << " (" << i << ")" << endl; - fTMVAData[i]->fTMVAOptimumCutValueFound = true; - - // get efficiency histograms - TFile iTMVAFile( fTMVAData[i]->fTMVAFileName.c_str() ); - TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[i]->fTMVAMethodTag_2 ); - TH1F* effB = getEfficiencyHistogram( "effB", &iTMVAFile, fTMVAData[i]->fTMVAMethodTag_2 ); - - if( effS ) - { - fTMVAData[i]->fSignalEfficiency = effS->GetBinContent( effS->FindBin( fTMVAData[i]->fTMVACutValue ) ); - cout << "eff S " << fTMVAData[i]->fSignalEfficiency << endl; - } - if( effB ) + cout << " (interpolated non-optimal value)"; + } + cout << " (" << i << ")" << endl; + fTMVAData[i]->fTMVAOptimumCutValueFound = true; + + // get efficiency histograms + TFile iTMVAFile( fTMVAData[i]->fTMVAFileName.c_str() ); + TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[i]->fTMVAMethodTag_2 ); + TH1F* effB = getEfficiencyHistogram( "effB", &iTMVAFile, fTMVAData[i]->fTMVAMethodTag_2 ); + + if( effS ) + { + fTMVAData[i]->fSignalEfficiency = effS->GetBinContent( effS->FindBin( fTMVAData[i]->fTMVACutValue ) ); + } + if( effB ) + { + fTMVAData[i]->fBackgroundEfficiency = effB->GetBinContent( effB->FindBin( fTMVAData[i]->fTMVACutValue ) ); + // background efficiency might be zero -> fill it with first non-zero value + if( fTMVAData[i]->fBackgroundEfficiency < 1.e-8 ) { - fTMVAData[i]->fBackgroundEfficiency = effB->GetBinContent( effB->FindBin( fTMVAData[i]->fTMVACutValue ) ); - // background efficiency might be zero -> fill it with first non-zero value - if( fTMVAData[i]->fBackgroundEfficiency < 1.e-8 ) + int iS = effB->FindBin( fTMVAData[i]->fTMVACutValue ); + for( int j = iS; j > 0; j-- ) { - int iS = effB->FindBin( fTMVAData[i]->fTMVACutValue ); - for( int j = iS; j > 0; j-- ) + if( effB->GetBinContent( j ) > 0. ) { - if( effB->GetBinContent( j ) > 0. ) - { - fTMVAData[i]->fBackgroundEfficiency = effB->GetBinContent( j ); - break; - } + fTMVAData[i]->fBackgroundEfficiency = effB->GetBinContent( j ); + break; } } } } } } - // energy and zenith angle dependent - else +} + +/* + + smoothing of optimal cut value vs energy curves + + (energy and zenith angle dependent) + +*/ +void VTMVAEvaluator::smoothAndInterPolateMVAValue_Energy_and_Zenith( + TH1F* effS, TH1F* effB, + unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, + unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ) +{ + + unsigned int Ebins = iWeightFileIndex_Emax - iWeightFileIndex_Emin + 1; + unsigned int ZEbins = iWeightFileIndex_Zmax - iWeightFileIndex_Zmin + 1; + + // 2D histogram to be smoothed (energy and zenith angle dependence) + TH2D* iH2 = new TH2D( "h1", "Smooth cut values", + Ebins, iWeightFileIndex_Emin, iWeightFileIndex_Emax, + ZEbins, iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); + Double_t effS_value[Ebins * ZEbins]; + for( unsigned int l = 0; l < fTMVAData.size(); l++ ) { - TH2D* iH2 = new TH2D( "h1", "Smooth cut values", Ebins, iWeightFileIndex_Emin, iWeightFileIndex_Emax, ZEbins, iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); - // fill 2D histogram to be smoothed (energy and zenith angle dependence) - Double_t effS_value[Ebins * ZEbins]; - for( unsigned int l = 0; l < fTMVAData.size(); l++ ) + if( fTMVAData[l] ) { - if( fTMVAData[l] ) + TFile iTMVAFile( fTMVAData[l]->fTMVAFileName.c_str() ); + if( iTMVAFile.IsZombie() ) { - TFile iTMVAFile( fTMVAData[l]->fTMVAFileName.c_str() ); - TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[l]->fTMVAMethodTag_2 ); - effS_value[l] = effS->GetBinContent( effS->FindBin( fTMVAData[l]->fTMVACutValue ) ); + cout << "VTMVAEvaluator: error reading file with cut efficiencies: "; + cout << fTMVAData[l]->fTMVAFileName << endl; + cout << "Exiting..." << endl; + exit( EXIT_FAILURE ); } + TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[l]->fTMVAMethodTag_2 ); + effS_value[l] = effS->GetBinContent( effS->FindBin( fTMVAData[l]->fTMVACutValue ) ); + } + } + for( unsigned int z = 0; z < fTMVAData.size(); z++ ) + { + if( !fTMVAData[z] ) + { + continue; + cout << "VTMVAEvaluator: error reading file with cut efficiencies for bins: "; + cout << ", entry " << z << endl; + cout << "Exiting..." << endl; + exit( EXIT_FAILURE ); } - for( unsigned int i = 0; i < Ebins; i++ ) + // get signal efficiency histograms and cut values + TFile iTMVAFile( fTMVAData[z]->fTMVAFileName.c_str() ); + TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[z]->fTMVAMethodTag_2 ); + if( fTMVAData[z]->fTMVAOptimumCutValueFound ) { - for( unsigned int j = 0; j < ZEbins; j++ ) + iH2->SetBinContent( fTMVAData[z]->fEnergyBin, fTMVAData[z]->fZenithBin, fTMVAData[z]->fTMVACutValue ); + } + // bins without optimal cut value and not in highest energy bin + else if( !fTMVAData[z]->fTMVAOptimumCutValueFound + && ( fTMVAData[z]->fZenithBin < ZEbins ) + && ( fTMVAData[z]->fEnergyBin != Ebins - 1 ) ) + { + for( int k = 0; k < effS->GetNbinsX(); k++ ) { - if( fTMVAData[z] ) + // search for similar cut efficiency in neighbouring bin + unsigned int i_alt_index = z + 1; + if( z > 0 ) { - // get signal efficiency histograms and cut values - TFile iTMVAFile( fTMVAData[z]->fTMVAFileName.c_str() ); - TH1F* effS = getEfficiencyHistogram( "effS", &iTMVAFile, fTMVAData[z]->fTMVAMethodTag_2 ); - if( fTMVAData[z]->fTMVAOptimumCutValueFound ) - { - iH2->SetBinContent( i, j, fTMVAData[z]->fTMVACutValue ); - } - // bins without optimal cut value and not in highest energy bin - else if( !fTMVAData[z]->fTMVAOptimumCutValueFound && ( j < ZEbins ) && ( i != Ebins - 1 ) ) - { - for( int k = 0; k < effS->GetNbinsX(); k++ ) - { - if( TMath::Abs( effS->GetBinContent( k ) - effS_value[z - 1] ) < 0.001 ) - { - fTMVAData[z]->fTMVACutValue = effS->GetBinCenter( k ); - effS_value[z] = effS->GetBinContent( k ); - } - } - } - // bins without optimal cut value and in highest energy bin - else if( !fTMVAData[z]->fTMVAOptimumCutValueFound && ( j < ZEbins ) && ( i == Ebins - 1 ) ) + i_alt_index = z - 1; + } + if( i_alt_index < fTMVAData.size() + && TMath::Abs( effS->GetBinContent( k ) - effS_value[i_alt_index] ) < 0.001 ) + { + fTMVAData[z]->fTMVACutValue = effS->GetBinCenter( k ); + effS_value[z] = effS->GetBinContent( k ); + } + } + } + // bins without optimal cut value and in highest energy bin + else if( !fTMVAData[z]->fTMVAOptimumCutValueFound + && ( fTMVAData[z]->fZenithBin < ZEbins ) && ( fTMVAData[z]->fEnergyBin == Ebins - 1 ) ) + { + for( unsigned int l = 0; l < ZEbins; l++ ) + { + if( effS_value[fTMVAData.size() - l] > 1.e-10 ) + { + for( int k = 0; k < effS->GetNbinsX(); k++ ) { - for( unsigned int l = 0; l < ZEbins; l++ ) + if( TMath::Abs( effS->GetBinContent( k ) - effS_value[fTMVAData.size() - l] ) < 0.0001 ) { - if( effS_value[fTMVAData.size() - l] > 1.e-10 ) - { - for( int k = 0; k < effS->GetNbinsX(); k++ ) - { - if( TMath::Abs( effS->GetBinContent( k ) - effS_value[fTMVAData.size() - l] ) < 0.0001 ) - { - fTMVAData[z]->fTMVACutValue = effS->GetBinCenter( k ); - effS_value[z] = effS->GetBinContent( k ); - } - } - } + fTMVAData[z]->fTMVACutValue = effS->GetBinCenter( k ); + effS_value[z] = effS->GetBinContent( k ); } } - if( fTMVAData[z]->fTMVACutValue == -99 ) - { - cout << "Error: no optimal cut value found for this bin" << endl; - } - cout << "\t TMVA values: at " << TMath::Power( 10., fTMVAData[z]->fSpectralWeightedMeanEnergy_Log10TeV ); - cout << " TeV, \t" << fTMVAData[z]->fTMVACutValue; - if( !fTMVAData[z]->fTMVAOptimumCutValueFound ) - { - cout << " (interpolated non-optimal value)"; - } - cout << ", signal efficiency: " << effS_value[z]; - cout << " (" << z << ")" << endl; } - z++; } - } - - // smooth the histogram and draw it - /* - iH2->Smooth(); - iH2->Draw("colz"); - int t = 0; - for( unsigned int i = 0; i < Ebins; i++ ) + if( fTMVAData[z]->fTMVACutValue == -99 ) { - for( unsigned int j = 0; j < ZEbins; j++ ) - { - - cout << "\t TMVA values: unsmoothed at " << TMath::Power( 10., fTMVAData[t]->fSpectralWeightedMeanEnergy_Log10TeV ); - cout << " TeV, \t" << fTMVAData[t]->fTMVACutValue; - cout << ", smoothed " << iH2->GetBinContent( i, j, fTMVAData[t]->fTMVACutValue); - if( !fTMVAData[t]->fTMVAOptimumCutValueFound ) - { - cout << " (interpolated non-optimal value)"; - } - cout << " (" << t << ")" << endl; - t++; - } - }*/ + cout << "Error: no optimal cut value found for this bin" << endl; + } + cout << "\t TMVA values: at " << TMath::Power( 10., fTMVAData[z]->fSpectralWeightedMeanEnergy_Log10TeV ); + cout << " TeV, \t" << fTMVAData[z]->fTMVACutValue; + if( !fTMVAData[z]->fTMVAOptimumCutValueFound ) + { + cout << " (interpolated non-optimal value)"; + } + cout << ", signal efficiency: " << effS_value[z]; + cout << " (" << z << ")" << endl; + } } } -void VTMVAEvaluator::getOptimalAngularContainmentRadius( double effS, double effB, double Ndif, double Nof, - TH2D* iHAngContainment, double iEnergy_log10_TeV, - double& i_Signal_to_sqrtNoise, double& i_AngularContainmentRadius, - double& i_AngularContainmentFraction ) +/* + + smoothing of optimal cut value vs energy curves + + missing (non-optimized) are interpolated + + note: signal and background efficiencies are not updated + +*/ +void VTMVAEvaluator::smoothAndInterPolateMVAValue( + TH1F* effS, TH1F* effB, + unsigned int iWeightFileIndex_Emin, unsigned int iWeightFileIndex_Emax, + unsigned int iWeightFileIndex_Zmin, unsigned int iWeightFileIndex_Zmax ) { - i_AngularContainmentFraction = 0.; - i_Signal_to_sqrtNoise = -99.; - i_AngularContainmentRadius = -99.; - if( !iHAngContainment || fOptimizationBackgroundAlpha <= 0 ) + if( fTMVAData.size() == 0 ) { return; } - double iR_Max = VHistogramUtilities::interpolateTH2D( iHAngContainment, iEnergy_log10_TeV, fTMVAngularContainmentRadiusMax ); - // find containment radius giving maximum significance - double iC = 0.; - double iR = 0.; - double iOn = 0.; - double iOff = 0.; - double iSigma = 0.; - for( int i = 1; i < iHAngContainment->GetNbinsY(); i++ ) + cout << "Smooth and interpolate MVA cut values" << endl; + + ////////////////////////////////////////////// + // energy dependent TMVA cut optimization only + if( iWeightFileIndex_Zmax == iWeightFileIndex_Zmin ) { - iC = iHAngContainment->GetYaxis()->GetBinLowEdge( i ); - iR = VHistogramUtilities::interpolateTH2D( iHAngContainment, iEnergy_log10_TeV, iHAngContainment->GetYaxis()->GetBinLowEdge( i ) ); - - if( iC > fTMVAngularContainmentRadiusMax ) - { - iR = iR_Max; - iC = fTMVAngularContainmentRadiusMax; - } - // make sure that containment cut is not getting too small - if( iR < fTMVAAngularContainmentThetaFixedMinRadius ) - { - continue; - } - - // gamma point source - iOn = effS * Ndif * iC / fTMVAngularContainmentRadiusMax; - iOn += effB * Nof * iR * iR / iR_Max / iR_Max; - iOff = effB * Nof / fOptimizationBackgroundAlpha * iR * iR / iR_Max / iR_Max; - - iSigma = VStatistics::calcSignificance( iOn, iOff, fOptimizationBackgroundAlpha ); - - if( iSigma >= i_Signal_to_sqrtNoise ) - { - i_Signal_to_sqrtNoise = iSigma; - i_AngularContainmentRadius = iR; - i_AngularContainmentFraction = iC; - } + smoothAndInterPolateMVAValue_EnergyOnly( effS, effB ); + } + // energy and zenith angle dependent + else + { + smoothAndInterPolateMVAValue_Energy_and_Zenith( + effS, effB, + iWeightFileIndex_Emin, iWeightFileIndex_Emax, + iWeightFileIndex_Zmin, iWeightFileIndex_Zmax ); } } - void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSignal_to_sqrtNoise, TGraph* iGSignal_to_sqrtNoise_Smooth, TH1F* hEffS, TH1F* hEffB, - TGraph* iGSignalEvents, TGraph* iGBackgroundEvents, - TGraph* iGOpt_AngularContainmentRadius, TGraph* iGOpt_AngularContainmentFraction ) + TGraph* iGSignalEvents, TGraph* iGBackgroundEvents ) { char hname[800]; char htitle[800]; @@ -2067,6 +1820,7 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig hEffB->SetTitle( "" ); hEffB->SetLineColor( 2 ); hEffB->SetLineWidth( 3 ); + hEffB->SetLineStyle( 9 ); hEffB->DrawCopy( "same" ); } @@ -2077,6 +1831,12 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig iL->SetLineWidth( 3 ); iL->Draw(); } + + if( fPrintPlotting ) + { + sprintf( hname, "MVAOpt-SignalBackgroundEfficiency-%s.pdf", fTMVAData[iBin]->fTMVAName.c_str() ); + iCanvas->Print( hname ); + } } // signal to noise @@ -2085,21 +1845,28 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig sprintf( hname, "cSignalToSqrtNoise_%d", iBin ); sprintf( htitle, "signal / sqrt( noise ) (%s)", fTMVAData[iBin]->GetTitle() ); TCanvas* iCanvas = new TCanvas( hname, htitle, 425, 10 + iBin * 30, 400, 400 ); - iCanvas->SetLeftMargin( 0.13 ); + iCanvas->SetLeftMargin( 0.12 ); iCanvas->SetGridx( 0 ); iCanvas->SetGridy( 0 ); + sprintf( hname, "hSignalToSqrtNoise_%d", iBin ); + TH1F* iSignal_to_sqrtNoise = new TH1F( hname, "", 100, -1., 1. ); + iSignal_to_sqrtNoise->SetMinimum( 0. ); + iSignal_to_sqrtNoise->SetMaximum( 6. ); + iSignal_to_sqrtNoise->SetXTitle( "MVA value #Tau" ); + iSignal_to_sqrtNoise->SetYTitle( "significance" ); + iSignal_to_sqrtNoise->GetYaxis()->SetTitleOffset( 1.3 ); + iSignal_to_sqrtNoise->SetStats( 0 ); + iSignal_to_sqrtNoise->Draw(); + iGSignal_to_sqrtNoise->SetTitle( "" ); - setGraphPlottingStyle( iGSignal_to_sqrtNoise, 1, 1., 20 ); + setGraphPlottingStyle( iGSignal_to_sqrtNoise, 4, 1., 20, 0.5, 0, 1 ); - iGSignal_to_sqrtNoise->Draw( "apl" ); - iGSignal_to_sqrtNoise->GetHistogram()->GetYaxis()->SetTitleOffset( 1.5 ); - iGSignal_to_sqrtNoise->GetHistogram()->SetXTitle( "MVA value #Tau" ); - iGSignal_to_sqrtNoise->GetHistogram()->SetYTitle( "significance" ); + iGSignal_to_sqrtNoise->Draw( "pl" ); if( iGSignal_to_sqrtNoise_Smooth ) { - setGraphPlottingStyle( iGSignal_to_sqrtNoise_Smooth, 2, 2. ); + setGraphPlottingStyle( iGSignal_to_sqrtNoise_Smooth, 2, 1., 20, 0.5 ); iGSignal_to_sqrtNoise_Smooth->Draw( "pl" ); } @@ -2110,6 +1877,11 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig iL->SetLineStyle( 2 ); iL->Draw(); } + if( fPrintPlotting ) + { + sprintf( hname, "MVAOpt-SignalToSqrtNoise-%s.pdf", fTMVAData[iBin]->fTMVAName.c_str() ); + iCanvas->Print( hname ); + } } // signal and background events numbers @@ -2173,93 +1945,6 @@ void VTMVAEvaluator::plotEfficiencyPlotsPerBin( unsigned int iBin, TGraph* iGSig } } - // angular containment radius - if( iGOpt_AngularContainmentRadius ) - { - sprintf( hname, "cCR_%d", iBin ); - sprintf( htitle, "containment radius (%s)", fTMVAData[iBin]->GetTitle() ); - TCanvas* iCanvas = new TCanvas( hname, htitle, 750, 10 + iBin * 30, 400, 400 ); - iCanvas->SetLeftMargin( 0.13 ); - iCanvas->SetGridx( 0 ); - iCanvas->SetGridy( 0 ); - - sprintf( hname, "hBC_%d", iBin ); - TH1D* hnull = new TH1D( hname, "", 100, -1., 1. ); - hnull->SetXTitle( "cut value" ); - hnull->SetYTitle( "containment radius [deg]" ); - hnull->SetMinimum( 1.e-3 ); - double x = 0.; - double y = 0.; - double y_max = 0.; - for( int i = 0; i < iGOpt_AngularContainmentRadius->GetN(); i++ ) - { - iGOpt_AngularContainmentRadius->GetPoint( i, x, y ); - if( y > y_max ) - { - y_max = y; - } - } - if( y_max < 1.e-3 ) - { - y_max = 1.; - } - hnull->SetMaximum( y_max * 1.5 ); - hnull->SetStats( 0 ); - hnull->GetYaxis()->SetTitleOffset( 1.5 ); - hnull->DrawCopy(); - - setGraphPlottingStyle( iGOpt_AngularContainmentRadius, 1, 1., 20 ); - iGOpt_AngularContainmentRadius->Draw( "pl" ); - if( iBin < fTMVAData.size() && fTMVAData[iBin] ) - { - TLine* iL = new TLine( fTMVAData[iBin]->fTMVACutValue, hnull->GetMinimum(), fTMVAData[iBin]->fTMVACutValue, y_max * 1.5 ); - iL->SetLineStyle( 2 ); - iL->SetLineWidth( 3 ); - iL->Draw(); - } - } - // angular containment fraction - if( iGOpt_AngularContainmentFraction ) - { - sprintf( hname, "cCF_%d", iBin ); - sprintf( htitle, "containment fraction (%s)", fTMVAData[iBin]->GetTitle() ); - TCanvas* iCanvas = new TCanvas( hname, htitle, 750, 10 + iBin * 30, 400, 400 ); - iCanvas->SetLeftMargin( 0.13 ); - iCanvas->SetGridx( 0 ); - iCanvas->SetGridy( 0 ); - - sprintf( hname, "hBF_%d", iBin ); - TH1D* hnull = new TH1D( hname, "", 100, -1., 1. ); - hnull->SetXTitle( "cut value" ); - hnull->SetYTitle( "containment fraction" ); - hnull->SetMinimum( 1.e-3 ); - double x = 0.; - double y = 0.; - double y_max = 0.; - for( int i = 0; i < iGOpt_AngularContainmentFraction->GetN(); i++ ) - { - iGOpt_AngularContainmentFraction->GetPoint( i, x, y ); - if( y > y_max ) - { - y_max = y; - } - } - hnull->SetMaximum( y_max * 1.5 ); - hnull->SetStats( 0 ); - hnull->GetYaxis()->SetTitleOffset( 1.5 ); - hnull->DrawCopy(); - - setGraphPlottingStyle( iGOpt_AngularContainmentFraction, 1, 1., 20 ); - iGOpt_AngularContainmentFraction->Draw( "pl" ); - if( iBin < fTMVAData.size() && fTMVAData[iBin] ) - { - TLine* iL = new TLine( fTMVAData[iBin]->fTMVACutValue, hnull->GetMinimum(), fTMVAData[iBin]->fTMVACutValue, y_max * 1.5 ); - iL->SetLineStyle( 2 ); - iL->SetLineWidth( 3 ); - iL->Draw(); - } - } - } void VTMVAEvaluator::setTMVAMethod( string iMethodName ) @@ -2316,6 +2001,10 @@ double VTMVAEvaluator::getValueFromMap( map< unsigned int, double > iDataMap, do return -1.; } +/* + * return signal efficiency at a given energy + * + */ double VTMVAEvaluator::getSignalEfficiency( unsigned int iEnergyBin, double iE_min_log10, double iE_max_log10, unsigned int iZenithBin, double iZ_min, double iZ_max ) { return getValueFromMap( fSignalEfficiencyMap, fSignalEfficiencyNoVec, iEnergyBin, iE_min_log10, iE_max_log10, iZenithBin, iZ_min, iZ_max, "SignalEfficiency" ); @@ -2335,68 +2024,8 @@ void VTMVAEvaluator::printSensitivityOptimizationParameters() cout << "\t" << fOptimizationSourceSignificance << " minimum significance" << endl; cout << "\t" << fOptimizationMinSignalEvents << " minimum number of on events" << endl; cout << "\t" << fOptimizationBackgroundAlpha << " signal to background area ratio" << endl; -} - -/* - * calculate mean energy in an energy bin after applying MVA cuts - * (use training tree TrainTree out of e.g. BDT file for this) - */ -double VTMVAEvaluator::getMeanEnergyAfterCut( TFile* f, double iCut, unsigned int iDataBin ) -{ - if( !f ) - { - return -99.; - } - if( iDataBin >= fTMVAData.size() || !fTMVAData[iDataBin] ) - { - return -99.; - } - double iEmin = TMath::Power( 10., fTMVAData[iDataBin]->fEnergyCut_Log10TeV_min ); - double iEmax = TMath::Power( 10., fTMVAData[iDataBin]->fEnergyCut_Log10TeV_max ); - TTree* t = ( TTree* )f->Get( "TrainTree" ); - if( !t ) - { - cout << "VTMVAEvaluator::getMeanEnergyAfterCut(): test tree not found in " << f->GetName() << endl; - return -99.; - } - float iErec = 0.; - float iMVA = 0.; - int classID = 0;; - t->SetBranchAddress( "ErecS", &iErec ); - ostringstream iCutName; - // variable names changed with time - keep backwards compatibility - iCutName << fTMVAMethodName << "_" << fTMVAData[iDataBin]->fTMVAMethodTag_2; - if( t->GetBranchStatus( iCutName.str().c_str() ) ) - { - t->SetBranchAddress( iCutName.str().c_str(), &iMVA ); - } - else - { - iCutName.clear(); - iCutName.str( std::string() ); - iCutName << fTMVAMethodName << "_0"; - t->SetBranchAddress( iCutName.str().c_str(), &iMVA ); - } - t->SetBranchAddress( "classID", &classID ); - - float n = 0.; - float m = 0.; - for( int i = 0; i < t->GetEntries(); i++ ) - { - t->GetEntry( i ); - - if( classID == 0 && iErec > 0. && iErec > iEmin && iErec < iEmax && iMVA > iCut ) - { - m += iErec; - n++; - } - } - if( n > 0. ) - { - return m / n; - } - - return -99.; + cout << "\t" << fOptimizationFixedSignalEfficiency << " maximum signal efficiency" << endl; + cout << "\t" << fOptimizationMinSourceStrength << " minimum source strength" << endl; } vector< double > VTMVAEvaluator::getBackgroundEfficiency() @@ -2456,7 +2085,8 @@ vector< bool > VTMVAEvaluator::getOptimumCutValueFound() * interpolates between zenith range and return a TGraph * */ -TGraph* VTMVAEvaluator::readNonNoffGraphsFromFile( TFile* iF, double i_ze_min, double i_ze_max, bool bIsOn ) +TGraph* VTMVAEvaluator::readNonNoffGraphsFromFile( + TFile* iF, double i_ze_min, double i_ze_max, bool bIsOn ) { if( !iF && iF->IsZombie() ) { @@ -2466,10 +2096,6 @@ TGraph* VTMVAEvaluator::readNonNoffGraphsFromFile( TFile* iF, double i_ze_min, d if( bIsOn ) { i_N = iF->Get( "gONRate" ); - if( !i_N ) - { - i_N = iF->Get( "gSignalRate" ); - } } else { @@ -2516,13 +2142,16 @@ TGraph* VTMVAEvaluator::fillfromGraph2D( TObject* i_G, double i_ze_min, double i VTMVAEvaluatorData::VTMVAEvaluatorData() { - fCounter = 0; + fTMVAName = ""; fTMVAFileName = ""; fTMVAFileNameXML = ""; fTMVAMethodTag = ""; + fTMVAMethodTag_2 = ""; + fEnergyBin = 0; fEnergyCut_Log10TeV_min = -99.; fEnergyCut_Log10TeV_max = -99.; fSpectralWeightedMeanEnergy_Log10TeV = -99.; + fZenithBin = 0; fZenithCut_min = -99.; fZenithCut_max = -99.; @@ -2531,8 +2160,6 @@ VTMVAEvaluatorData::VTMVAEvaluatorData() fTMVACutValue = -99.; fTMVAOptimumCutValueFound = false; fSourceStrengthAtOptimum_CU = -99.; - fAngularContainmentRadius = -99.; - fAngularContainmentFraction = -99.; // transients fTMVAReader = 0; @@ -2541,8 +2168,8 @@ VTMVAEvaluatorData::VTMVAEvaluatorData() void VTMVAEvaluatorData::print() { cout << "\t file " << fTMVAFileName << endl; - cout << "\t energy bin [" << fEnergyCut_Log10TeV_min << "," << fEnergyCut_Log10TeV_max << "] (mean energy " << fSpectralWeightedMeanEnergy_Log10TeV << ")"; + cout << "\t energy bin [" << fEnergyCut_Log10TeV_min << "," << fEnergyCut_Log10TeV_max << "] "; + cout << "(mean energy " << fSpectralWeightedMeanEnergy_Log10TeV << ")"; cout << ", zenith bin [" << fZenithCut_min << "," << fZenithCut_max << "]"; cout << endl; } - diff --git a/src/VTMVARunData.cpp b/src/VTMVARunData.cpp index ffac166c2..6f167dd33 100644 --- a/src/VTMVARunData.cpp +++ b/src/VTMVARunData.cpp @@ -7,18 +7,20 @@ VTMVARunData::VTMVARunData() { - setDebug(); + setDebug( false ); fName = "noname"; + fRunOption = "TRAIN"; fTrainGammaHadronSeparation = true; fTrainReconstructionQuality = false; // in development: please ignore - fCheckValidityOfInputVariables = true; - fOutputDirectoryName = ""; fOutputFileName = ""; + fnTrain_Signal = 0; + fnTrain_Background = 0; + fQualityCuts = "1"; fQualityCutsBkg = "1"; fMCxyoffCut = "1"; @@ -29,6 +31,7 @@ VTMVARunData::VTMVARunData() fBackgroundWeight = 1.; fMinSignalEvents = 50; fMinBackgroundEvents = 0; + fSelectedEventFileName = ""; fNTtype = -1; @@ -112,12 +115,12 @@ bool VTMVARunData::openDataFiles() { if( fSignalTree[k] ) { - fSignalTree[k]->Draw( ">>+signalList", - fQualityCuts - && fMCxyoffCut && - fEnergyCutData[i]->fEnergyCut && - fZenithCutData[j]->fZenithCut, - "entrylist" ); + fSignalTree[k]->Draw( ">>+signalList", + fQualityCuts + && fMCxyoffCut && + fEnergyCutData[i]->fEnergyCut && + fZenithCutData[j]->fZenithCut, + "entrylist" ); i_j_SignalList = ( TEntryList* )gDirectory->Get( "signalList" ); } } @@ -128,7 +131,7 @@ bool VTMVARunData::openDataFiles() cout << i_j_SignalList->GetN() << "\t required > " << fMinSignalEvents << endl; cout << " (cuts are " << fQualityCuts << "&&" << fMCxyoffCut; cout << "&&" << fEnergyCutData[i]->fEnergyCut << "&&" << fZenithCutData[j]->fZenithCut; - cout << ")" << endl; + cout << ")" << endl; if( i_j_SignalList->GetN() < fMinSignalEvents ) { iEnoughEvents = false; @@ -144,15 +147,15 @@ bool VTMVARunData::openDataFiles() if( fMCxyoffCutSignalOnly ) // Do we need this? { fBackgroundTree[k]->Draw( ">>+BackgroundList", fQualityCuts && fQualityCutsBkg - && fMCxyoffCut && fEnergyCutData[i]->fEnergyCut - && fZenithCutData[j]->fZenithCut, "entrylist" ); + && fMCxyoffCut && fEnergyCutData[i]->fEnergyCut + && fZenithCutData[j]->fZenithCut, "entrylist" ); i_j_BackgroundList = ( TEntryList* )gDirectory->Get( "BackgroundList" ); } else if( fBackgroundTree[k] ) { fBackgroundTree[k]->Draw( ">>+BackgroundList", fQualityCuts && fQualityCutsBkg - && fMCxyoffCut && fEnergyCutData[i]->fEnergyCut - && fZenithCutData[j]->fZenithCut, "entrylist" ); + && fMCxyoffCut && fEnergyCutData[i]->fEnergyCut + && fZenithCutData[j]->fZenithCut, "entrylist" ); i_j_BackgroundList = ( TEntryList* )gDirectory->Get( "BackgroundList" ); } } @@ -163,7 +166,7 @@ bool VTMVARunData::openDataFiles() cout << "\t required > " << fMinBackgroundEvents << endl; cout << " (cuts are " << fQualityCuts << "&&" << fQualityCutsBkg << "&&" << fMCxyoffCut; cout << "&&" << fEnergyCutData[i]->fEnergyCut << "&&" << fZenithCutData[j]->fZenithCut; - cout << ")" << endl; + cout << ")" << endl; if( i_j_BackgroundList->GetN() < fMinBackgroundEvents ) { iEnoughEvents = false; @@ -198,36 +201,42 @@ bool VTMVARunData::openDataFiles() if( fEnergyCutData.size() > 1 && fZenithCutData.size() > 1 ) { iTempS << fOutputDirectoryName << "/" << fOutputFileName; - iTempS << "_" << i << "_" << j << ".root"; // append a _# at the file name + iTempS << "_" << i << "_" << j << ".root"; // append a _# at the file name iTempS2 << fOutputFileName << "_" << i << "_" << j; } else if( fEnergyCutData.size() > 1 && fZenithCutData.size() <= 1 ) { iTempS << fOutputDirectoryName << "/" << fOutputFileName; - iTempS << "_" << i << ".root"; // append a _# at the file name + iTempS << "_" << i << ".root"; // append a _# at the file name iTempS2 << fOutputFileName << "_" << i; } else if( fZenithCutData.size() > 1 && fEnergyCutData.size() <= 1 ) { iTempS << fOutputDirectoryName << "/" << fOutputFileName; - iTempS << "_0_" << j << ".root"; // append a _# at the file name + iTempS << "_0_" << j << ".root"; // append a _# at the file name iTempS2 << fOutputFileName << "_0_" << i; } else { - iTempS << fOutputDirectoryName << "/" << fOutputFileName << ".root"; + iTempS << fOutputDirectoryName << "/" << fOutputFileName; + fSelectedEventFileName = iTempS.str() + "_preselect.root"; + if( fRunOption == "WRITETRAININGEVENTS" ) + { + iTempS << "_preselect"; + } + iTempS << ".root"; iTempS2 << fOutputFileName; } output_zenith.push_back( new TFile( iTempS.str().c_str(), "RECREATE" ) ); if( output_zenith.back()->IsZombie() ) { cout << "VTMVARunData::openDataFiles() error creating output file "; - cout << output_zenith.back()->GetName() << endl; + cout << output_zenith.back()->GetName() << endl; cout << "aborting..." << endl; return false; } output_zenith.back()->SetTitle( iTempS2.str().c_str() ); - if( i < fEnergyCutData.size() && fEnergyCutData[i] ) + if( i < fEnergyCutData.size() && fEnergyCutData[i] ) { fEnergyCutData[i]->Write(); } @@ -235,7 +244,7 @@ bool VTMVARunData::openDataFiles() { fZenithCutData[j]->Write(); } - output_zenith.back()->Write(); + output_zenith.back()->Write(); } fOutputFile.push_back( output_zenith ); } @@ -249,6 +258,42 @@ bool VTMVARunData::openDataFiles() return true; } +/* + * read a unsigned int from the TMVA option string + * + */ +unsigned int VTMVARunData::getTrainOptionValue( string iVarName, unsigned int i_default ) +{ + if( fPrepareTrainingOptions.find( iVarName ) == string::npos ) + { + return i_default; + } + size_t s_0 = fPrepareTrainingOptions.find( iVarName ) + iVarName.size() + 1; + size_t s_1 = fPrepareTrainingOptions.find( ":", s_0 ); + + return ( unsigned int )atoi( fPrepareTrainingOptions.substr( s_0, s_1 - s_0 ).c_str() ); +} + + +/* + * update number of training events, if lower than requested + * + */ +void VTMVARunData::updateTrainingEvents( string iVarName, unsigned int iNEvents ) +{ + unsigned int i_requested_nevents = getTrainOptionValue( iVarName, 0 ); + + size_t s_0 = fPrepareTrainingOptions.find( iVarName ) + iVarName.size() + 1; + size_t s_1 = fPrepareTrainingOptions.find( ":", s_0 ); + + if( iNEvents < i_requested_nevents ) + { + cout << "WARNING: changing " << iVarName << " from "; + cout << i_requested_nevents << " to " << iNEvents << endl; + fPrepareTrainingOptions.replace( s_0, s_1 - s_0, std::to_string( iNEvents ) ); + } +} + /*! print run information to screen */ @@ -332,17 +377,20 @@ void VTMVARunData::print() { cout << "energy reconstruction method " << fEnergyCutData[0]->fEnergyReconstructionMethod << endl; } - cout << "signal data file(s): " << endl; - for( unsigned int i = 0; i < fSignalFileName.size(); i++ ) + if( fRunOption == "WRITETRAININGEVENTS" ) { - cout << "\t" << fSignalFileName[i] << endl; - } - if( !fTrainReconstructionQuality ) - { - cout << "background data file(s): " << endl; - for( unsigned int i = 0; i < fBackgroundFileName.size(); i++ ) + cout << "signal data file(s): " << endl; + for( unsigned int i = 0; i < fSignalFileName.size(); i++ ) + { + cout << "\t" << fSignalFileName[i] << endl; + } + if( !fTrainReconstructionQuality ) { - cout << "\t" << fBackgroundFileName[i] << endl; + cout << "background data file(s): " << endl; + for( unsigned int i = 0; i < fBackgroundFileName.size(); i++ ) + { + cout << "\t" << fBackgroundFileName[i] << endl; + } } } cout << "output file: " << fOutputFileName << " (" << fOutputDirectoryName << ")" << endl; @@ -527,7 +575,8 @@ bool VTMVARunData::readConfigurationFile( char* iC ) { fPrepareTrainingOptions = is_stream.str().substr( is_stream.tellg(), is_stream.str().size() ).c_str(); fPrepareTrainingOptions = VUtilities::removeSpaces( fPrepareTrainingOptions ); - // remove all spaces + fnTrain_Signal = getTrainOptionValue( "nTrain_Signal", 0 ); + fnTrain_Background = getTrainOptionValue( "nTrain_Background", 0 ); } else { @@ -535,16 +584,6 @@ bool VTMVARunData::readConfigurationFile( char* iC ) return false; } } - // check event validity - if( temp == "CHECKEVENTVALIDITY" ) - { - if( !( is_stream >> std::ws ).eof() ) - { - int iT = 0; - is_stream >> iT; - fCheckValidityOfInputVariables = ( bool )iT; - } - } // signal weight if( temp == "SIGNALWEIGHT" ) { @@ -617,18 +656,29 @@ bool VTMVARunData::readConfigurationFile( char* iC ) } } // energy bins - if( temp == "ENERGYBINS" ) + if( temp == "ENERGYBINEDGES" ) { vector< double > iEnergyCut_Log10TeV_min; vector< double > iEnergyCut_Log10TeV_max; - vector< TCut > iEnergyCut; - // energy reconstruction method (should be 1, unless you know it better) - unsigned int iEMethod; - if( !( is_stream >> std::ws ).eof() ) + // read in energy bin + while( !( is_stream >> std::ws ).eof() ) { - is_stream >> iEMethod; + double iT = 0.; + is_stream >> iT; + iEnergyCut_Log10TeV_min.push_back( iT ); + is_stream >> iT; + iEnergyCut_Log10TeV_max.push_back( iT ); } + if( !fillEnergyCutData( iEnergyCut_Log10TeV_min, iEnergyCut_Log10TeV_max ) ) + { + return false; + } + } + if( temp == "ENERGYBINS" ) + { + vector< double > iEnergyCut_Log10TeV_min; + vector< double > iEnergyCut_Log10TeV_max; // read in energy bin while( !( is_stream >> std::ws ).eof() ) @@ -639,12 +689,6 @@ bool VTMVARunData::readConfigurationFile( char* iC ) } // sort sort( iEnergyCut_Log10TeV_min.begin(), iEnergyCut_Log10TeV_min.end() ); - // check sanity - if( iEnergyCut_Log10TeV_min.size() < 2 ) - { - cout << "VTMVARunData::readConfigurationFile error: need at least two energy bins " << iEnergyCut_Log10TeV_min.size() << endl; - return false; - } // fill maximum bins for( unsigned int i = 1; i < iEnergyCut_Log10TeV_min.size(); i++ ) { @@ -652,31 +696,9 @@ bool VTMVARunData::readConfigurationFile( char* iC ) } // remove last minimum iEnergyCut_Log10TeV_min.pop_back(); - // fill cuts - for( unsigned int i = 0; i < iEnergyCut_Log10TeV_min.size(); i++ ) - { - ostringstream iCut; - if( iEMethod == 0 ) - { - iCut << "Erec>0.&&" << iEnergyCut_Log10TeV_min[i] << "0.&&" << iEnergyCut_Log10TeV_min[i] << "SetName( "fDataEnergyCut" ); - fEnergyCutData.back()->fEnergyCutBin = 0; - fEnergyCutData.back()->fEnergyCut_Log10TeV_min = iEnergyCut_Log10TeV_min[i]; - fEnergyCutData.back()->fEnergyCut_Log10TeV_max = iEnergyCut_Log10TeV_max[i]; - fEnergyCutData.back()->fEnergyCut = iEnergyCut[i]; - fEnergyCutData.back()->fEnergyReconstructionMethod = iEMethod; + return false; } } // zenith angle bins (in [deg]) @@ -698,7 +720,8 @@ bool VTMVARunData::readConfigurationFile( char* iC ) // check sanity if( iZenithCut_min.size() < 2 ) { - cout << "VTMVARunData::readConfigurationFile error: need at least one zenith bin " << iZenithCut_min.size() << endl; + cout << "VTMVARunData::readConfigurationFile error: need at least one zenith bin "; + cout << iZenithCut_min.size() << endl; return false; } // fill maximum bins @@ -746,3 +769,63 @@ bool VTMVARunData::readConfigurationFile( char* iC ) return true; } +void VTMVARunData::shuffleFileVectors() +{ + std::random_device rd; + std::mt19937 g( rd() ); + std::shuffle( fSignalFileName.begin(), fSignalFileName.end(), g ); + std::shuffle( fBackgroundFileName.begin(), fBackgroundFileName.end(), g ); +} + +VTableLookupRunParameter* VTMVARunData::getTLRunParameter() +{ + TDirectory* iG_CurrentDirectory = gDirectory; + if( fSignalFileName.size() > 0 ) + { + TFile* iF = new TFile( fSignalFileName[0].c_str() ); + if( iF->IsZombie() ) + { + cout << "Error reading run parameters from "; + cout << fSignalFileName[0] << endl; + return 0; + } + VTableLookupRunParameter* iP = ( VTableLookupRunParameter* )iF->Get( "TLRunParameter" ); + iG_CurrentDirectory->cd(); + return iP; + } + return 0; +} + +bool VTMVARunData::fillEnergyCutData( + vector< double > iEnergyCut_Log10TeV_min, + vector< double > iEnergyCut_Log10TeV_max ) +{ + // check sanity + if( iEnergyCut_Log10TeV_min.size() < 1 ) + { + cout << "VTMVARunData::readConfigurationFile error: need at least two energy bins "; + cout << iEnergyCut_Log10TeV_min.size() << endl; + return false; + } + vector< TCut > iEnergyCut; + // fill cuts + for( unsigned int i = 0; i < iEnergyCut_Log10TeV_min.size(); i++ ) + { + ostringstream iCut; + iCut << "ErecS>0.&&" << iEnergyCut_Log10TeV_min[i]; + iCut << "SetName( "fDataEnergyCut" ); + fEnergyCutData.back()->fEnergyCutBin = 0; + fEnergyCutData.back()->fEnergyCut_Log10TeV_min = iEnergyCut_Log10TeV_min[i]; + fEnergyCutData.back()->fEnergyCut_Log10TeV_max = iEnergyCut_Log10TeV_max[i]; + fEnergyCutData.back()->fEnergyCut = iEnergyCut[i]; + } + return true; +} diff --git a/src/VTMVARunDataEnergyCut.cpp b/src/VTMVARunDataEnergyCut.cpp index e86d97acb..b458ca474 100644 --- a/src/VTMVARunDataEnergyCut.cpp +++ b/src/VTMVARunDataEnergyCut.cpp @@ -1,7 +1,6 @@ /*! \class VTMVARunDataEnergyCut \brief VTMVARunDataEnergyCut data class for TMVA energy cuts - */ #include "VTMVARunDataEnergyCut.h" @@ -23,5 +22,3 @@ void VTMVARunDataEnergyCut::print() cout << " method " << fEnergyReconstructionMethod << endl; cout << "\t cuts: " << fEnergyCut.GetTitle() << endl; } - - diff --git a/src/VTS.calculateCrabRateFromMC.cpp b/src/VTS.calculateCrabRateFromMC.cpp deleted file mode 100644 index a366146f5..000000000 --- a/src/VTS.calculateCrabRateFromMC.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/*! \file VTS.calculateCrabRateFromMC.cpp - \brief calculate gamma ray rate from Crab Nebula with effective areas from MC - - - -*/ - -#include "TF1.h" -#include "TFile.h" -#include "TTree.h" - -#include "CEffArea.h" -#include "VGlobalRunParameter.h" -#include "VMonteCarloRateCalculator.h" -#include "VEnergySpectrumfromLiterature.h" - -#include -#include - - -using namespace std; - -int main( int argc, char* argv[] ) -{ - const double index = 2.4; - bool bDebug = false; - - cout << endl; - cout << "VTS.calculateCrabRateFromMC (" << VGlobalRunParameter::getEVNDISP_VERSION() << ")" << endl; - cout << "--------------------------------" << endl; - if( argc != 4 ) - { - cout << "VTS.calculateCrabRateFromMC " << endl; - cout << endl; - exit( 0 ); - } - cout << endl; - cout << "selecting effective areas with spectral index " << index << endl; - - string ieff = argv[1]; - string ioffile = argv[2]; - // energy threshold - double fEnergyThreshold = atof( argv[3] ); - cout << "energy threshold: " << fEnergyThreshold << " TeV" << endl; - if( fEnergyThreshold < 1.e-2 ) - { - fEnergyThreshold = 1.e-2; // take care of log(fEnergyThreshold) - } - - double ze = 0.; - int az = 0; - double Woff = 0.; - int noise = 0; - double pedvar = 0.; - unsigned int nrates = 0; - double MCrate[1000]; - - TFile* f1 = new TFile( ioffile.c_str(), "RECREATE" ); - if( f1->IsZombie() ) - { - cout << "error opening output file: " << ioffile << endl; - exit( 0 ); - } - TTree* fMC = new TTree( "fMCRate", "MC rate predictions" ); - fMC->Branch( "ze", &ze, "ze/D" ); - fMC->Branch( "az", &az, "az/I" ); - fMC->Branch( "Woff", &Woff, "Woff/D" ); - fMC->Branch( "noise", &noise, "noise/I" ); - fMC->Branch( "pedvar", &pedvar, "pedvar/D" ); - fMC->Branch( "nrates", &nrates, "nrates/i" ); - fMC->Branch( "MCrate", MCrate, "MCrate[nrates]/D" ); - - TFile* f = new TFile( ieff.c_str() ); - if( f->IsZombie() ) - { - cout << "error opening file with effective areas: " << ieff << endl; - exit( 0 ); - } - TTree* t = ( TTree* )gDirectory->Get( "fEffArea" ); - if( !t ) - { - exit( 0 ); - } - CEffArea* c = new CEffArea( t ); - - // Crab Nebula Spectra - vector< unsigned int > fID; - fID.push_back( 1 ); // Whipple - fID.push_back( 5 ); // HEGRA - /* fID.push_back( 2 ); // H.E.S.S. - fID.push_back( 5 ); // HEGRA - fID.push_back( 6 ); // MAGIC */ - vector< VEnergySpectrumfromLiterature* > fESpecFun; - char hname[2000]; - VGlobalRunParameter* fRunParameter = new VGlobalRunParameter(); - sprintf( hname, "%s/AstroData/TeV_data/EnergySpectrum_literatureValues_CrabNebula.dat", fRunParameter->getDirectory_EVNDISPAnaData().c_str() ); - VEnergySpectrumfromLiterature* fESpec = new VEnergySpectrumfromLiterature( hname ); - if( fESpec->isZombie() ) - { - exit( -1 ); - } - for( unsigned int i = 0; i < fID.size(); i++ ) - { - fESpecFun.push_back( fESpec ); - } - - // error checks - if( fESpecFun.size() != fID.size() ) - { - cout << "Error: vector mismatch - check code" << endl; - exit( -1 ); - } - - // print everything - for( unsigned int i = 0; i < fESpecFun.size(); i++ ) - { - if( fESpecFun[i] ) - { - fESpecFun[i]->listValues( fID[i] ); - } - } - - // rate calculator - VMonteCarloRateCalculator* fMCR = new VMonteCarloRateCalculator(); - - cout << endl; - cout << "reading " << c->fChain->GetEntries() << " effective areas " << endl; - - // loop over all effective areas and calculate expected rates - unsigned int iN = c->fChain->GetEntries(); - for( unsigned int i = 0; i < iN; i++ ) - { - c->GetEntry( i ); - - if( TMath::Abs( c->index - index ) > 1.e-2 ) - { - continue; - } - if( i % 5000 == 0 ) - { - cout << "now at entry " << i << endl; - } - - ze = c->ze; - az = c->az; - Woff = c->Woff; - noise = c->noise; - pedvar = c->pedvar; - - vector< double > fenergy; - vector< double > feffectivearea; - for( int e = 0; e < c->nbins; e++ ) - { - fenergy.push_back( c->e0[e] ); - feffectivearea.push_back( c->eff[e] ); - } - - // hardwire Whipple spectrum (much faster than outer functino call) - nrates = 1; - MCrate[0] = fMCR->getMonteCarloRate( fenergy, feffectivearea, -2.440, 3.250e-11, 1., fEnergyThreshold, 1.e7, bDebug ); - /* for( unsigned int t = 0; t < fESpecFun.size(); t++ ) - { - MCrate[t] = fMCR->getMonteCarloRate( fenergy, feffectivearea, fESpecFun[t], fID[t], fEnergyThreshold, 1.e7, bDebug ); - if( bDebug ) cout << "MC Rate " << ze << "\t" << MCrate[t] << endl; - } */ - fMC->Fill(); - } - cout << endl; - cout << "writing results to " << f1->GetName() << endl; - f1->cd(); - fMC->Write(); - f1->Close(); -} diff --git a/src/VTS.getRunListFromDB.cpp b/src/VTS.getRunListFromDB.cpp index 328a8dff1..c0acee688 100644 --- a/src/VTS.getRunListFromDB.cpp +++ b/src/VTS.getRunListFromDB.cpp @@ -254,8 +254,12 @@ void parseOptions( int argc, char* argv[] ) if( gSystem->Getenv( "EVNDISPSYS" ) ) { char readme[500]; - sprintf( readme, "cat %s/README/README.GETRUNLIST", ENV ); - system( readme ); + sprintf( readme, "cat %s/docs/GETRUNLIST.md", ENV ); + int sys_ret = system( readme ); + if( sys_ret == -1 ) + { + cout << "error reading " << readme << endl; + } } else { diff --git a/src/VTableLookupDataHandler.cpp b/src/VTableLookupDataHandler.cpp index 40f4fdbcd..61d0b2f9a 100644 --- a/src/VTableLookupDataHandler.cpp +++ b/src/VTableLookupDataHandler.cpp @@ -291,7 +291,7 @@ bool VTableLookupDataHandler::getNextEvent( bool bShort ) int VTableLookupDataHandler::fillNextEvent( bool bShort ) { /////////////////////////////////////////////////////////////////////////////// - // read partical event for quick reconstruction quality assessment + // read partial event for quick reconstruction quality assessment if( !fshowerpars->GetEntry( fEventCounter ) ) { return -1; @@ -1913,10 +1913,10 @@ void VTableLookupDataHandler::writeDeadTimeHistograms() TDirectoryFile* iDeadtimeDirectory = ( TDirectoryFile* )f->Get( "deadTimeHistograms" ); if( iDeadtimeDirectory ) { + fDeadTime->readHistograms( iDeadtimeDirectory ); fDeadTime->calculateDeadTime(); fDeadTime->printDeadTime(); fDeadTime->writeHistograms(); - fDeadTime->readHistograms( iDeadtimeDirectory ); } } } diff --git a/src/VTableLookupRunParameter.cpp b/src/VTableLookupRunParameter.cpp index 61d01dffc..9809779b5 100644 --- a/src/VTableLookupRunParameter.cpp +++ b/src/VTableLookupRunParameter.cpp @@ -488,10 +488,10 @@ void VTableLookupRunParameter::printHelp() { if( gSystem->Getenv( "EVNDISPSYS" ) ) { - int syst_ret = system( "cat $EVNDISPSYS/README/README.MSCW_ENERGY" ); + int syst_ret = system( "cat $EVNDISPSYS/docs/MSCW_ENERGY.md" ); if( syst_ret == -1 ) { - cout << "VTableLookupRunParameter::printHelp() error: could not find helper file in README directory" << endl; + cout << "VTableLookupRunParameter::printHelp() error: could not find helper file in docs directory" << endl; } } else diff --git a/src/anasum.cpp b/src/anasum.cpp index 5612c8dac..8d0bff9e2 100644 --- a/src/anasum.cpp +++ b/src/anasum.cpp @@ -175,9 +175,9 @@ int parseOptions( int argc, char* argv[] ) case 'h': if( gSystem->Getenv( "EVNDISPSYS" ) ) { - if( system( "cat $EVNDISPSYS/README/README.ANASUM" ) != 0 ) + if( system( "cat $EVNDISPSYS/docs/ANASUM.md" ) != 0 ) { - cout << "error reading README" << endl; + cout << "error reading docs" << endl; } } else diff --git a/src/calculateCrabRateFromMC.cpp b/src/calculateCrabRateFromMC.cpp new file mode 100644 index 000000000..c2ebe7c40 --- /dev/null +++ b/src/calculateCrabRateFromMC.cpp @@ -0,0 +1,570 @@ +/*! \file VTS.calculateCrabRateFromMC.cpp + \brief calculate gamma ray rate from Crab Nebula with effective areas from MC + + + +*/ + +#include "TF1.h" +#include "TFile.h" +#include "TGraph2DErrors.h" +#include "TProfile2D.h" +#include "TTree.h" + +#include "CEffArea.h" +#include "VGlobalRunParameter.h" +#include "VMonteCarloRateCalculator.h" + +#include +#include +#include + + +using namespace std; + +/* + * fill profile histogram with a new rate entry + * + */ +void fill_profilehistogram_for_TMVA( + TProfile2D* fMCRates_TMVA, + double i_E, double i_Ze, double iRate ) +{ + if( fMCRates_TMVA && iRate > 0. ) + { + fMCRates_TMVA->Fill( i_E, i_Ze, iRate ); + } +} + +/* + * read zenith bin vector from MC tree + * + */ +vector< double > read_zenith_bins( string fEffAreaFile ) +{ + TFile* f = new TFile( fEffAreaFile.c_str() ); + if( f->IsZombie() ) + { + cout << "error opening file with effective areas " << fEffAreaFile << endl; + exit( EXIT_FAILURE ); + } + TTree* t = ( TTree* )gDirectory->Get( "fEffAreaH2F" ); + if( !t ) + { + cout << "error reading effective area tree from " << fEffAreaFile << endl; + exit( EXIT_FAILURE ); + } + float ze = 0.; + t->SetBranchAddress( "ze", &ze ); + // - read unique vector of zenith angles + vector< double > tmp_zebins; + for( unsigned int i = 0; i < t->GetEntries(); i++ ) + { + t->GetEntry( i ); + bool bFound = false; + for( unsigned int z = 0; z < tmp_zebins.size(); z++ ) + { + if( TMath::Abs( ze - tmp_zebins[z] ) < 1.e-1 ) + { + bFound = true; + break; + } + } + if( !bFound ) + { + tmp_zebins.push_back( ze ); + } + } + tmp_zebins.push_back( tmp_zebins.back() + 10. ); + vector< double > tmp_zebin_edges; + tmp_zebin_edges.push_back( 0. ); + for( unsigned int z = 1; z < tmp_zebins.size(); z++ ) + { + tmp_zebin_edges.push_back( 0.5 * ( tmp_zebins[z] + tmp_zebins[z - 1] ) ); + } + cout << "Zenith bins: "; + for( unsigned int z = 0; z < tmp_zebin_edges.size(); z++ ) + { + cout << tmp_zebin_edges[z] << ", "; + } + cout << endl; + + f->Close(); + + return tmp_zebin_edges; +} + +vector< pair< double, double > > read_energy_minmax_pairs( + vector< double > tmp_ebins_histo, string iEnergyKeyWord ) +{ + vector< pair< double, double > > e; + if( tmp_ebins_histo.size() > 1 ) + { + if( iEnergyKeyWord == "ENERGYBINS" ) + { + for( unsigned int i = 0; i < tmp_ebins_histo.size() - 1; i++ ) + { + e.push_back( make_pair( tmp_ebins_histo[i], tmp_ebins_histo[i + 1] ) ); + } + } + else + { + for( unsigned int i = 0; i < tmp_ebins_histo.size(); i += 2 ) + { + e.push_back( make_pair( tmp_ebins_histo[i], tmp_ebins_histo[i + 1] ) ); + } + } + } + return e; +} + + +/* + * read energy bin vector from TMVA run parameter file + * + * ENERGYBINEDGES -1.5 -0.5 -1. 0. -0.5 0.5 0.0 1. 0.5 2.0 + * ENERGYBINS -1.50 -0.75 -0.25 0.5 2.0 + */ +vector< double > read_energy_bins( + string iTMVAParameterFile, + string iEnergyKeyWord ) +{ + vector< double > tmp_e; + ifstream is( iTMVAParameterFile.c_str(), ifstream::in ); + if( !is ) + { + cout << "Error reading energy bins from TMVA run parameter file" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + string is_line; + string temp; + while( getline( is, is_line ) ) + { + if( is_line.size() == 0 ) + { + continue; + } + istringstream is_stream( is_line ); + if( ( is_stream >> std::ws ).eof() ) + { + continue; + } + is_stream >> temp; + if( temp != "*" ) + { + continue; + } + is_stream >> temp; + if( temp == iEnergyKeyWord ) + { + while( !( is_stream >> std::ws ).eof() ) + { + double iT = 0.; + is_stream >> iT; + tmp_e.push_back( iT ); + } + } + } + is.close(); + + return tmp_e; +} + +/* + * convert overlapping pairs of energy bin definitions to non-overlapping + * for histogram definition + * Energy bins (rate calculation): [-1.5, -0.5], [-1, 0], [-0.5, 0.5], [0, 1], [0.5, 2], +*/ +vector< double > read_energy_histo( vector< pair< double, double >> ebins ) +{ + vector< double > e; + if( ebins.size() == 0 ) + { + return e; + } + e.push_back( ebins[0].first ); + for( unsigned int i = 0; i < ebins.size() - 1; i++ ) + { + e.push_back( 0.5 * ( ebins[i].first + ebins[i + 1].second ) ); + } + e.push_back( ebins.back().second ); + + return e; +} + +/* + initialize profile histograms rates as function of energy and zenith angle + - entry 0: MC rates from the Crab nebula + +*/ +vector< TProfile2D* > initializeRateProfileHistos( + string fEffAreaFile, string fTMVAParameterFile, vector< double > tmp_ebins ) +{ + vector< TProfile2D* > h; + + vector< double > tmp_zebin_edges = read_zenith_bins( fEffAreaFile ); + + double* ie = &tmp_ebins[0]; + double* iz = &tmp_zebin_edges[0]; + h.push_back( new TProfile2D( + "MCRatesTMVA", "", + ( int )tmp_ebins.size() - 1, ie, + ( int )tmp_zebin_edges.size() - 1, iz ) ); + h.back()->SetXTitle( "log_{10} Energy/TeV" ); + h.back()->SetYTitle( "zenith angle (deg)" ); + h.back()->SetZTitle( "rate from Crab Nebula (1/min)" ); + + h.push_back( new TProfile2D( + "BackgroundRatesTMVA", "", + ( int )tmp_ebins.size() - 1, ie, + ( int )tmp_zebin_edges.size() - 1, iz ) ); + h.back()->SetXTitle( "log_{10} Energy/TeV" ); + h.back()->SetYTitle( "zenith angle (deg)" ); + h.back()->SetZTitle( "background rate (1/min)" ); + + return h; +} + +/* + * fill MC rates from effective area trees + * + */ +TTree* fillMCRates( + string fEffAreaFile, + TProfile2D* h, + double fEnergyThreshold, + double fDeadTime, + vector< pair< double, double > > ebins ) +{ + float ze = 0.; + int az = 0; + float Woff = 0.; + int noise = 0; + float pedvar = 0.; + float MCrate; + + TTree* fMC = new TTree( "fMCRate", "MC rate predictions" ); + fMC->Branch( "ze", &ze, "ze/F" ); + fMC->Branch( "az", &az, "az/I" ); + fMC->Branch( "Woff", &Woff, "Woff/F" ); + fMC->Branch( "noise", &noise, "noise/I" ); + fMC->Branch( "pedvar", &pedvar, "pedvar/F" ); + fMC->Branch( "MCrate", &MCrate, "MCrate/F" ); + + TFile* f = new TFile( fEffAreaFile.c_str() ); + if( f->IsZombie() ) + { + cout << "error opening file with effective areas " << fEffAreaFile << endl; + exit( EXIT_FAILURE ); + } + TTree* t = ( TTree* )gDirectory->Get( "fEffAreaH2F" ); + if( !t ) + { + cout << "error reading effective area tree from " << fEffAreaFile << endl; + exit( EXIT_FAILURE ); + } + UShort_t t_az = 0; + UShort_t t_noise = 0; + UShort_t t_nbins = 0; + float t_e0[1000]; + float t_eff[1000]; + t->SetBranchAddress( "ze", &ze ); + t->SetBranchAddress( "az", &t_az ); + t->SetBranchAddress( "Woff", &Woff ); + t->SetBranchAddress( "noise", &t_noise ); + t->SetBranchAddress( "pedvar", &pedvar ); + t->SetBranchAddress( "nbins", &t_nbins ); + t->SetBranchAddress( "e0", t_e0 ); + t->SetBranchAddress( "eff", t_eff ); + + // rate calculator + VMonteCarloRateCalculator* fMCR = new VMonteCarloRateCalculator(); + // hardwired Whipple spectrum + double fWhippleNorm = 3.250e-11; + double fWhippleIndex = -2.440; + + // loop over all effective areas and calculate expected rates + unsigned int iN = t->GetEntries(); + + cout << "reading " << iN << " effective areas from "; + cout << fEffAreaFile << endl; + cout << endl; + for( unsigned int i = 0; i < iN; i++ ) + { + t->GetEntry( i ); + + az = ( int )t_az; + noise = ( int )t_noise; + + vector< double > fenergy; + vector< double > feffectivearea; + for( int e = 0; e < t_nbins; e++ ) + { + fenergy.push_back( t_e0[e] ); + feffectivearea.push_back( t_eff[e] ); + } + + MCrate = fMCR->getMonteCarloRate( + fenergy, feffectivearea, + fWhippleIndex, fWhippleNorm, 1., fEnergyThreshold, 1.e7, false ); + MCrate *= ( 1. - fDeadTime / 100. ); + fMC->Fill(); + + for( unsigned int e = 0; e < ebins.size(); e++ ) + { + fill_profilehistogram_for_TMVA( + h, + 0.5 * ( ebins[e].first + ebins[e].second ), + ze, + fMCR->getMonteCarloRate( + fenergy, feffectivearea, + fWhippleIndex, fWhippleNorm, 1., + TMath::Power( 10., ebins[e].first ), + TMath::Power( 10., ebins[e].second ), + false ) * ( 1. - fDeadTime / 100. ) ); + } + } + f->Close(); + return fMC; +} + +/* + * read list of runs + * +*/ +vector< string > read_run_list( string iRunList ) +{ + vector< string > i_runs; + ifstream is( iRunList.c_str(), ifstream::in ); + if( !is ) + { + cout << "Error reading run list of background files" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + string is_line; + while( getline( is, is_line ) ) + { + i_runs.push_back( is_line ); + } + cout << "Found list with " << i_runs.size() << " background runs" << endl; + + return i_runs; +} + +/* + * fill background rates for a given run + * + * assume that anasum files contain a single run only (!!) + */ +void fillBackgroundRates_perRun( + string i_runFileName, + TProfile2D* h, + vector< pair< double, double > > ebins ) +{ + TFile* f = new TFile( i_runFileName.c_str() ); + if( f->IsZombie() ) + { + cout << "Background rate file not found: " << i_runFileName << endl; + return; + } + TTree* t = ( TTree* )f->Get( "total_1/stereo/tRunSummary" ); + if( !t ) + { + cout << "Background rate file incomplete (missing tRunSummary tree): " << i_runFileName << endl; + return; + } + int runOn = 0; + double elevationOff = 0.; + double OffNorm = 0.; + double NOff = 0.; + double tOff = 0.; + t->SetBranchAddress( "runOn", &runOn ); + t->SetBranchAddress( "elevationOff", &elevationOff ); + t->SetBranchAddress( "OffNorm", &OffNorm ); + t->SetBranchAddress( "tOff", &tOff ); + t->SetBranchAddress( "NOff", &NOff ); + t->GetEntry( 0 ); + // skip runs shorter than 10 min + if( tOff < 600. || NOff < 0.01 ) + { + cout << "\t skipping short run " << runOn << " (run length " << tOff << "s)" << endl; + f->Close(); + return; + } + cout << "RUN " << elevationOff << ", " << tOff << ", " << OffNorm; + cout << ", " << elevationOff << ", " << NOff << ", " << runOn << endl; + stringstream iTemp; + iTemp << "run_" << runOn << "/stereo/energyHistograms/herecCounts_off"; + TH1D* hOff = ( TH1D* )f->Get( iTemp.str().c_str() ); + if( !hOff ) + { + cout << "Background rate file incomplete (missing off histogram)" << i_runFileName << endl; + return; + } + for( unsigned int e = 0; e < ebins.size(); e++ ) + { + int i_binStart = hOff->GetXaxis()->FindBin( ebins[e].first ); + int i_binStop = hOff->GetXaxis()->FindBin( ebins[e].second ); + double iR = 0.; + for( int b = i_binStart; b <= i_binStop; b++ ) + { + iR += hOff->GetBinContent( b ); + } + if( tOff > 0. && iR > 0. ) + { + h->Fill( + 0.5 * ( ebins[e].first + ebins[e].second ), + 90. - elevationOff, + iR * OffNorm / tOff * 60. ); + } + } + + f->Close(); +} + + +/* + * fill background rates from anasum files + * + */ +void fillBackgroundRates( string iRunList, TProfile2D* h, vector< pair< double, double > > ebins ) +{ + vector< string > i_runs = read_run_list( iRunList ); + + for( unsigned int i = 0; i < i_runs.size(); i++ ) + { + fillBackgroundRates_perRun( i_runs[i], h, ebins ); + } +} + +/* + * convert 2D histograms to 2D graphs + * + */ +TGraph2DErrors* getTGraph2D( vector< TProfile2D* > h, string iGraphName ) +{ + TGraph2DErrors* i_g = new TGraph2DErrors( 1 ); + i_g->SetName( iGraphName.c_str() ); + if( iGraphName == "gONRate" ) + { + i_g->SetTitle( "signal + background rate (1/s)" ); + } + else + { + i_g->SetTitle( "background rate (1/s)" ); + } + unsigned int z = 0; + for( int b_x = 1; b_x <= h[1]->GetNbinsX(); b_x++ ) + { + for( int b_y = 1; b_y <= h[1]->GetNbinsY(); b_y++ ) + { + double i_z = h[1]->GetBinContent( b_x, b_y ); + if( iGraphName == "gONRate" ) + { + i_z += h[0]->GetBinContent( b_x, b_y ); + } + // expect rate graphs in 1./s + i_g->SetPoint( + z, + h[1]->GetXaxis()->GetBinCenter( b_x ), + h[1]->GetYaxis()->GetBinCenter( b_y ), + i_z / 60. ); + i_g->SetPointError( z, 0., 0., 0. ); + z++; + } + } + return i_g; +} + + +int main( int argc, char* argv[] ) +{ + cout << endl; + cout << "calculateCrabRateFromMC (" << VGlobalRunParameter::getEVNDISP_VERSION() << ")" << endl; + cout << "--------------------------------" << endl; + if( argc != 6 ) + { + cout << "VTS.calculateCrabRateFromMC "; + cout << " "; + cout << ""; + cout << endl << endl; + exit( EXIT_SUCCESS ); + } + cout << endl; + + string fEffAreaFile = argv[1]; + string ioffile = argv[2]; + double fDeadTime = atof( argv[3] ); + cout << "dead time (%): " << fDeadTime << endl; + double fEnergyThreshold = 0.01; + cout << "energy threshold (hardwired): " << fEnergyThreshold << " TeV" << endl; + if( fEnergyThreshold < 1.e-2 ) + { + fEnergyThreshold = 1.e-2; // take care of log(fEnergyThreshold) + } + string fTMVAParameterFile = argv[4]; + string fBackgroundRunList = argv[5]; + + cout << "Note! Hardwired Whipple spectrum (power law)" << endl; + + TFile* f1 = new TFile( ioffile.c_str(), "RECREATE" ); + if( f1->IsZombie() ) + { + cout << "error opening output file: " << ioffile << endl; + exit( EXIT_SUCCESS ); + } + // two types of energy binning + // - for rate integration (possibly overlapping bins used for TMVA + // training and evaluation) + // - for histogram definition (non-overlapping) + vector< double > tmp_ebins_histo = read_energy_bins( fTMVAParameterFile, "ENERGYBINS" ); + vector< pair< double, double > > tmp_ebins; + if( tmp_ebins_histo.size() > 0 ) + { + tmp_ebins = read_energy_minmax_pairs( tmp_ebins_histo, "ENERGYBINS" ); + } + else + { + tmp_ebins = read_energy_minmax_pairs( + read_energy_bins( fTMVAParameterFile, "ENERGYBINEDGES" ), "ENERGYBINEDGES" ); + tmp_ebins_histo = read_energy_histo( tmp_ebins ); + } + + cout << "Energy bins (rate calculation): "; + for( unsigned int i = 0; i < tmp_ebins.size(); i++ ) + { + cout << "[" << tmp_ebins[i].first << ", " << tmp_ebins[i].second << "], "; + } + cout << endl; + cout << "Energy bins (histogram): "; + for( unsigned int e = 0; e < tmp_ebins_histo.size(); e++ ) + { + cout << tmp_ebins_histo[e] << ", "; + } + cout << endl; + + vector< TProfile2D* > hRateProfileHisto = initializeRateProfileHistos( + fEffAreaFile, fTMVAParameterFile, tmp_ebins_histo ); + + TTree* fMC = fillMCRates( + fEffAreaFile, hRateProfileHisto[0], + fEnergyThreshold, fDeadTime, + tmp_ebins ); + + fillBackgroundRates( + fBackgroundRunList, hRateProfileHisto[1], tmp_ebins ); + + cout << "writing results to " << f1->GetName() << endl; + f1->cd(); + fMC->Write(); + for( unsigned int i = 0; i < hRateProfileHisto.size(); i++ ) + { + hRateProfileHisto[i]->Write(); + } + getTGraph2D( hRateProfileHisto, "gONRate" )->Write(); + getTGraph2D( hRateProfileHisto, "gBGRate" )->Write(); + f1->Close(); +} diff --git a/src/combineEffectiveAreas.cpp b/src/combineEffectiveAreas.cpp index f6588b3a8..d93ed4fd8 100644 --- a/src/combineEffectiveAreas.cpp +++ b/src/combineEffectiveAreas.cpp @@ -455,7 +455,11 @@ void write_log_files( vector< string > file_list, string outputfile ) i_sys << outputfile << ".combine.log"; cout << "merge log files into " << i_sys.str() << endl; - system( i_sys.str().c_str() ); + int sys_ret = system( i_sys.str().c_str() ); + if( sys_ret == -1 ) + { + cout << "Error executing system command " << i_sys.str() << endl; + } cout << "done.." << endl; } diff --git a/src/compareDatawithMC.cpp b/src/compareDatawithMC.cpp index 8b7fb2161..c634f135f 100644 --- a/src/compareDatawithMC.cpp +++ b/src/compareDatawithMC.cpp @@ -208,7 +208,8 @@ int main( int argc, char* argv[] ) cout << "(e.g. from Crab Nebula or Mrk 421 observations)" << endl; cout << endl; cout << endl; - cout << "compareDatawithMC [BDT gamma/hadron cuts] [shower max zenith angle (default=20deg)]" << endl; + cout << "compareDatawithMC "; + cout << "[BDT gamma/hadron cuts] [epoch_ATM] [shower max zenith angle (default=20deg)]" << endl; cout << endl; cout << "\t input file list: see example file COMPAREMC.runparameter in the parameter files directory" << endl; cout << "\t cuts: " << endl; @@ -234,19 +235,17 @@ int main( int argc, char* argv[] ) readInputfile( fInputFile ); int fSingleTelescopeCuts = atoi( argv[2] ); - string fOutputfile = argv[3]; bool fCalculateMVACut = false; - if( argc > 4 && atoi( argv[4] ) == 1 ) { fCalculateMVACut = true; } - double fShowerMaxZe_deg = 20.; + string fEpochATM = ""; if( argc > 5 ) { - fShowerMaxZe_deg = atof( argv[5] ); + fEpochATM = argv[5]; } // test number of telescopes @@ -267,7 +266,6 @@ int main( int argc, char* argv[] ) } } } - // -------- end of reading input parameters TH1D* hAzOn = 0; @@ -280,10 +278,9 @@ int main( int argc, char* argv[] ) { if( fInputData[i].fType == "ON" ) { - VDataMCComparision iTemp( fInputData[i].fType, fInputData[i].fNTelescopes, fCalculateMVACut ); + VDataMCComparision iTemp( fInputData[i].fType, fInputData[i].fNTelescopes ); iTemp.setAzRange( fInputData[i].fAz_deg_min, fInputData[i].fAz_deg_max ); iTemp.setZeRange( fInputData[i].fZe_deg_min, fInputData[i].fZe_deg_max ); - iTemp.setShowerMaximZe_deg( fShowerMaxZe_deg ); hAzOn = iTemp.getAzimuthWeightingHistogram( fInputData[i].fFileName ); if( hAzOn ) { @@ -311,14 +308,19 @@ int main( int argc, char* argv[] ) { cout << fInputData[i].fType << endl; cout << "----" << endl; - fStereoCompare.push_back( new VDataMCComparision( fInputData[i].fType, fInputData[i].fNTelescopes, fCalculateMVACut ) ); + fStereoCompare.push_back( new VDataMCComparision( fInputData[i].fType, fInputData[i].fNTelescopes ) ); + if( fCalculateMVACut ) + { + fStereoCompare.back()->setTMVABDTComparision( fEpochATM ); + } fStereoCompare.back()->setAzRange( fInputData[i].fAz_deg_min, fInputData[i].fAz_deg_max ); fStereoCompare.back()->setZeRange( fInputData[i].fZe_deg_min, fInputData[i].fZe_deg_max ); // get telescope coordinates fStereoCompare.back()->resetTelescopeCoordinates(); for( int t = 0; t < fInputData[i].fNTelescopes; t++ ) { - if( !fStereoCompare.back()->setTelescopeCoordinates( fInputData[i].fTelX[t], fInputData[i].fTelY[t], fInputData[i].fTelZ[t] ) ) + if( !fStereoCompare.back()->setTelescopeCoordinates( + fInputData[i].fTelX[t], fInputData[i].fTelY[t], fInputData[i].fTelZ[t] ) ) { exit( EXIT_FAILURE ); } @@ -351,7 +353,7 @@ int main( int argc, char* argv[] ) // calculate difference histograms cout << "DIFF" << endl; cout << "----" << endl; - VDataMCComparision* fDiff = new VDataMCComparision( "DIFF", iNT, fCalculateMVACut ); + VDataMCComparision* fDiff = new VDataMCComparision( "DIFF", iNT ); // assume 5 background regions fDiff->setOnOffHistograms( fStereoCompareOn, fStereoCompareOff, 1. / 5. ); fDiff->writeHistograms( fOutputfile ); diff --git a/src/makeEffectiveArea.cpp b/src/makeEffectiveArea.cpp index cd36c1afc..c37cd88d0 100644 --- a/src/makeEffectiveArea.cpp +++ b/src/makeEffectiveArea.cpp @@ -66,10 +66,10 @@ int main( int argc, char* argv[] ) cout << endl; if( gSystem->Getenv( "EVNDISPSYS" ) ) { - int i_s = system( "cat $EVNDISPSYS/README/README.EFFECTIVEAREA" ); + int i_s = system( "cat $EVNDISPSYS/docs/EFFECTIVEAREA.md" ); if( i_s == -1 ) { - cout << "error: README/README.EFFECTIVEAREA not found" << endl; + cout << "error: docs/EFFECTIVEAREA.md not found" << endl; } } else @@ -94,7 +94,7 @@ int main( int argc, char* argv[] ) fRunPara->print(); ///////////////////////////////////////////////////////////////// - // open output file and write results to dist + // open output file and write results to disk TFile* fOutputfile = new TFile( fOutputfileName.c_str(), "RECREATE" ); if( fOutputfile->IsZombie() ) { @@ -108,7 +108,7 @@ int main( int argc, char* argv[] ) VGammaHadronCuts* fCuts = new VGammaHadronCuts(); fCuts->initialize(); fCuts->setNTel( fRunPara->telconfig_ntel, fRunPara->telconfig_arraycentre_X, fRunPara->telconfig_arraycentre_Y ); - fCuts->setInstrumentEpoch( fRunPara->getInstrumentEpoch( true ) ); + fCuts->setInstrumentEpoch( fRunPara->getInstrumentATMString() ); fCuts->setTelToAnalyze( fRunPara->fTelToAnalyse ); if( !fCuts->readCuts( fRunPara->fCutFileName, 2 ) ) { @@ -246,7 +246,7 @@ int main( int argc, char* argv[] ) if( fMC_histo ) { fMC_histo->matchDataVectors( fRunPara->fAzMin, fRunPara->fAzMax, fRunPara->fSpectralIndex ); - fMC_histo->print(); + // fMC_histo->print(); } else { diff --git a/src/makeRadialAcceptance.cpp b/src/makeRadialAcceptance.cpp index c5c70e890..6db1ce7f7 100644 --- a/src/makeRadialAcceptance.cpp +++ b/src/makeRadialAcceptance.cpp @@ -92,7 +92,7 @@ int main( int argc, char* argv[] ) // read gamma/hadron cuts from cut file VGammaHadronCuts* fCuts = new VGammaHadronCuts(); - fCuts->setInstrumentEpoch( fInstrumentEpoch ); + // fCuts->setInstrumentEpoch( fInstrumentEpoch ); fCuts->setTelToAnalyze( teltoana ); fCuts->setNTel( ntel ); if( cutfilename.size() > 0 ) @@ -180,10 +180,12 @@ int main( int argc, char* argv[] ) } } + // loop over all files and fill acceptances for( unsigned int i = 0; i < fRunPara->fRunList.size(); i++ ) { sprintf( ifile, "%s/%d.mscw.root", datadir.c_str(), fRunPara->fRunList[i].fRunOff ); - cout << "now chaining " << ifile << " (wobble offset " << -1.*fRunPara->fRunList[i].fWobbleNorth << ", " << fRunPara->fRunList[i].fWobbleWest << ")" << endl; + cout << "now chaining " << ifile; + cout << " (wobble offset " << -1.*fRunPara->fRunList[i].fWobbleNorth << ", " << fRunPara->fRunList[i].fWobbleWest << ")" << endl; // test if file exists TFile fTest( ifile ); if( fTest.IsZombie() ) @@ -197,31 +199,34 @@ int main( int argc, char* argv[] ) // Check number of telescopes in run VEvndispRunParameter* iParV2 = ( VEvndispRunParameter* )fTest.Get( "runparameterV2" ); - if( iParV2 ) + if( !iParV2 ) { - cout << "Testing telescope multiplicity " << teltoanastring << endl; - if( teltoana.size() != iParV2->fTelToAnalyze.size() || !equal( teltoana.begin(), teltoana.end(), iParV2->fTelToAnalyze.begin() ) ) + cout << "Error reading run parameters " << endl; + continue; + } + cout << "Testing telescope multiplicity " << teltoanastring << endl; + if( teltoana.size() != iParV2->fTelToAnalyze.size() || !equal( teltoana.begin(), teltoana.end(), iParV2->fTelToAnalyze.begin() ) ) + { + cout << endl; + cout << "error: Requested telescopes " << teltoanastring << " do not equal telescopes in run " << ifile << endl; + cout << "PAR "; + for( unsigned int i = 0; i < iParV2->fTelToAnalyze.size(); i++ ) { - cout << endl; - cout << "error: Requested telescopes " << teltoanastring << " do not equal telescopes in run " << ifile << endl; - cout << "PAR "; - for( unsigned int i = 0; i < iParV2->fTelToAnalyze.size(); i++ ) - { - cout << iParV2->fTelToAnalyze[i] << " "; - } - cout << endl; - cout << "USER "; - for( unsigned int i = 0; i < teltoana.size(); i++ ) - { - cout << teltoana[i] << " "; - } - cout << endl; - cout << "\t" << teltoana.size() << "\t" << iParV2->fTelToAnalyze.size() << endl; - exit( EXIT_FAILURE ); + cout << iParV2->fTelToAnalyze[i] << " "; } + cout << endl; + cout << "USER "; + for( unsigned int i = 0; i < teltoana.size(); i++ ) + { + cout << teltoana[i] << " "; + } + cout << endl; + cout << "\t" << teltoana.size() << "\t" << iParV2->fTelToAnalyze.size() << endl; + exit( EXIT_FAILURE ); } // set gamma/hadron cuts + fCuts->setInstrumentEpoch( iParV2->getInstrumentATMString() ); fCuts->initializeCuts( fRunPara->fRunList[i].fRunOff, datadir ); // pointer to data tree fCuts->setDataTree( d ); diff --git a/src/printRunParameter.cpp b/src/printRunParameter.cpp index 231258562..5099e2f25 100644 --- a/src/printRunParameter.cpp +++ b/src/printRunParameter.cpp @@ -105,6 +105,8 @@ bool readRunParameter( TFile* fIn, string iPara ) { cout << fPar->fTelToAnalyze[i] + 1; } + cout << "\t" << fPar->fRunDuration; + cout << "\t" << fPar->fTargetName; cout << endl; } @@ -135,8 +137,11 @@ bool readWobbleOffset( TFile* fIn, bool printInteger ) return false; } - -bool readMeanElevation( TFile* fIn ) +/* + * read mean elevation or zenith + * + */ +bool readMeanElevation( TFile* fIn, bool print_zenith = false ) { if( !fIn ) { @@ -211,7 +216,14 @@ bool readMeanElevation( TFile* fIn ) if( iMeanN > 0. ) { iMean_f /= iMeanN; - cout << "Average elevation: " << iMean_f << endl; + if( print_zenith ) + { + cout << "Average zenith angle: " << 90. - iMean_f << endl; + } + else + { + cout << "Average elevation: " << iMean_f << endl; + } } } else @@ -294,6 +306,7 @@ int main( int argc, char* argv[] ) cout << " -runinfo print relevant run info in one line" << endl; cout << " -updated-runinfo print relevant run info in one line (update epoch from VERITAS.Epochs.runparameter)" << endl; cout << " -elevation print (rough) average elevation" << endl; + cout << " -zenith print (rough) average zenith angle" << endl; cout << " -wobble print wobble offset" << endl; cout << " -wobbleInt print wobble offset (as integer, x100)" << endl; cout << endl; @@ -328,6 +341,10 @@ int main( int argc, char* argv[] ) { readMeanElevation( fIn ); } + else if( fOption.find( "-zenith" ) != string::npos ) + { + readMeanElevation( fIn, true ); + } else if( fOption.find( "-wobble" ) != string::npos ) { readWobbleOffset( fIn, ( fOption.find( "-wobbleInt" ) != string::npos ) ); diff --git a/src/trainTMVAforAngularReconstruction.cpp b/src/trainTMVAforAngularReconstruction.cpp index c96c0896e..4185aa35b 100644 --- a/src/trainTMVAforAngularReconstruction.cpp +++ b/src/trainTMVAforAngularReconstruction.cpp @@ -175,7 +175,7 @@ bool trainTMVA( string iOutputDir, float iTrainTest, dataloader->AddVariable( "asym", 'F' ); dataloader->AddVariable( "loss", 'F' ); dataloader->AddVariable( "dist", 'F' ); - dataloader->AddVariable( "fui" , 'F' ); + dataloader->AddVariable( "fui", 'F' ); if( iTargetML.find( "DispEnergy" ) != string::npos && !iSingleTelescopeAnalysis ) { dataloader->AddVariable( "EHeight", 'F' ); @@ -549,7 +549,7 @@ bool writeTrainingFile( const string iInputFile, ULong64_t iTelType, fMapOfTrainingTree[i_tel.TelType]->Branch( "length", &length, "length/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "wol", &wol, "wol/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "dist", &dist, "dist/F" ); - fMapOfTrainingTree[i_tel.TelType]->Branch( "fui" , &fui , "fui/F" ); + fMapOfTrainingTree[i_tel.TelType]->Branch( "fui", &fui, "fui/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "tgrad_x", &tgrad_x, "tgrad_x/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "meanPedvar_Image", &meanPedvar_Image, "meanPedvar_Image/F" ); fMapOfTrainingTree[i_tel.TelType]->Branch( "Fitstat", &Fitstat, "Fitstat/I" ); diff --git a/src/trainTMVAforGammaHadronSeparation.cpp b/src/trainTMVAforGammaHadronSeparation.cpp index 5da073dd8..67aedbbef 100644 --- a/src/trainTMVAforGammaHadronSeparation.cpp +++ b/src/trainTMVAforGammaHadronSeparation.cpp @@ -29,115 +29,200 @@ using namespace std; bool train( VTMVARunData* iRun, unsigned int iEnergyBin, unsigned int iZenithBin, bool iGammaHadronSeparation ); bool trainGammaHadronSeparation( VTMVARunData* iRun, unsigned int iEnergyBin, unsigned int iZenithBin ); bool trainReconstructionQuality( VTMVARunData* iRun, unsigned int iEnergyBin, unsigned int iZenithBin ); +TTree* prepareSelectedEventsTree( VTMVARunData* iRun, TCut iCut, bool iSignal ); -/* - check if a training variable is constant - - (constant variables are removed from set of training variables) - - return values: - -1: value is variable - 0-N: value is constant (array identifier) - -*/ -double checkIfVariableIsConstant( VTMVARunData* iRun, TCut iCut, string iVariable, bool iSignal, bool iSplitBlock ) +/* + * prepare training / testing trees with reduced number of events + * + * - apply pre-cuts here + * - copy only variables which are needed for TMVA into new tree + * - delete full trees (IMPORTANT) + * + */ +TTree* prepareSelectedEventsTree( VTMVARunData* iRun, TCut iCut, + bool iSignal ) { - char hname[2000]; - TH1D* h = 0; - cout << "initializing TMVA variables: checking"; - if( iSignal ) - { - cout << " signal"; - } - else + if( !iRun ) { - cout << " background"; + return 0; } - cout << " variable " << iVariable << " for consistency " << endl; vector< TChain* > iTreeVector; + string iDataTree_reducedName; if( iSignal ) { + cout << "Preparing reduced signal trees" << endl; iTreeVector = iRun->fSignalTree; + iDataTree_reducedName = "data_signal"; } else { + cout << "Preparing reduced background trees" << endl; iTreeVector = iRun->fBackgroundTree; + iDataTree_reducedName = "data_background"; } + // reduced tree (and name) + TTree* iDataTree_reduced = 0; + // list of variables copied. + // must include at least the variables used for the training + Double_t Ze = 0.; + Double_t Az = 0.; + Double_t WobbleN = 0; + Double_t WobbleE = 0; + Double_t MSCW = 0.; + Double_t MSCL = 0.; + Double_t ErecS = 0.; + Double_t EChi2S = 0.; + Double_t Xcore = 0.; + Double_t Ycore = 0.; + Double_t Xoff_derot = 0.; + Double_t Yoff_derot = 0.; + Int_t NImages = 0; + Float_t EmissionHeight = 0.; + Float_t EmissionHeightChi2 = 0.; + Double_t SizeSecondMax = 0.; + Double_t DispDiff = 0.; + Double_t MCe0 = 0.; + iDataTree_reduced = new TTree( iDataTree_reducedName.c_str(), iDataTree_reducedName.c_str() ); + iDataTree_reduced->Branch( "Ze", &Ze, "Ze/D" ); + iDataTree_reduced->Branch( "Az", &Az, "Az/D" ); + iDataTree_reduced->Branch( "WobbleN", &WobbleN, "WobbleN/D" ); + iDataTree_reduced->Branch( "WobbleE", &WobbleE, "WobbleE/D" ); + iDataTree_reduced->Branch( "MSCW", &MSCW, "MSCW/D" ); + iDataTree_reduced->Branch( "MSCL", &MSCL, "MSCL/D" ); + iDataTree_reduced->Branch( "ErecS", &ErecS, "ErecS/D" ); + iDataTree_reduced->Branch( "EChi2S", &EChi2S, "EChi2S/D" ); + iDataTree_reduced->Branch( "Xcore", &Xcore, "Xcore/D" ); + iDataTree_reduced->Branch( "Ycore", &Ycore, "Ycore/D" ); + iDataTree_reduced->Branch( "Xoff_derot", &Xoff_derot, "Xoff_derot/D" ); + iDataTree_reduced->Branch( "Yoff_derot", &Yoff_derot, "Yoff_derot/D" ); + iDataTree_reduced->Branch( "NImages", &NImages, "NImages/I" ); + iDataTree_reduced->Branch( "EmissionHeight", &EmissionHeight, "EmissionHeight/F" ); + iDataTree_reduced->Branch( "EmissionHeightChi2", &EmissionHeightChi2, "EmissionHeightChi2/F" ); + iDataTree_reduced->Branch( "SizeSecondMax", &SizeSecondMax, "SizeSecondMax/D" ); + iDataTree_reduced->Branch( "DispDiff", &DispDiff, "DispDiff/D" ); + iDataTree_reduced->Branch( "MCe0", &MCe0, "MCe0/D" ); - // add cut on number of telescope (per type) for - if( iVariable.find( "NImages_Ttype" ) != string::npos || iVariable.find( "EmissionHeightChi2" ) != string::npos ) - { - ostringstream iTemp; - if( iVariable.find( "NImages_Ttype" ) != string::npos ) - { - iTemp << "NTtype>0 && "; - } - iTemp << iVariable << " >=2"; - TCut ntCut( iTemp.str().c_str() ); - iCut = iCut && ntCut; - } + Long64_t n = 0; for( unsigned int i = 0; i < iTreeVector.size(); i++ ) { - h = 0; if( iTreeVector[i] ) { - // fill a histogram with the variable to be checked - sprintf( hname, "hXX_%d", i ); - h = new TH1D( hname, "", 100, -1.e5, 1.e5 ); - Long64_t iNEntriesBlock = 0; - if( iSplitBlock ) + iTreeVector[i]->SetBranchAddress( "Ze", &Ze ); + iTreeVector[i]->SetBranchAddress( "Az", &Az ); + iTreeVector[i]->SetBranchAddress( "WobbleN", &WobbleN ); + iTreeVector[i]->SetBranchAddress( "WobbleE", &WobbleE ); + iTreeVector[i]->SetBranchAddress( "MSCW", &MSCW ); + iTreeVector[i]->SetBranchAddress( "MSCL", &MSCL ); + iTreeVector[i]->SetBranchAddress( "ErecS", &ErecS ); + iTreeVector[i]->SetBranchAddress( "EChi2S", &EChi2S ); + iTreeVector[i]->SetBranchAddress( "Xcore", &Xcore ); + iTreeVector[i]->SetBranchAddress( "Ycore", &Ycore ); + iTreeVector[i]->SetBranchAddress( "Xoff_derot", &Xoff_derot ); + iTreeVector[i]->SetBranchAddress( "Yoff_derot", &Yoff_derot ); + iTreeVector[i]->SetBranchAddress( "NImages", &NImages ); + iTreeVector[i]->SetBranchAddress( "EmissionHeight", &EmissionHeight ); + iTreeVector[i]->SetBranchAddress( "EmissionHeightChi2", &EmissionHeightChi2 ); + iTreeVector[i]->SetBranchAddress( "SizeSecondMax", &SizeSecondMax ); + iTreeVector[i]->SetBranchAddress( "DispDiff", &DispDiff ); + if( iTreeVector[i]->GetBranchStatus( "MCe0" ) ) { - iNEntriesBlock = iTreeVector[i]->GetEntries() / 2; + iTreeVector[i]->SetBranchAddress( "MCe0", &MCe0 ); } - else + if( !iDataTree_reduced ) { - iNEntriesBlock = iTreeVector[i]->GetEntries(); + cout << "Error preparing reduced tree" << endl; + return 0; } - iTreeVector[i]->Project( h->GetName(), iVariable.c_str(), iCut, "", iNEntriesBlock ); - if( h ) + iTreeVector[i]->Draw( ">>elist", iCut, "entrylist" ); + TEntryList* elist = ( TEntryList* )gDirectory->Get( "elist" ); + if( elist && elist->GetN() > 0 ) { - if( h->GetRMS() > 1.e-5 ) + // select a random subsample + // require trainging and testing sample + // (add factor 10 to make sure that there are plenty + // of testing events) + double i_event_selected = ( double )iRun->fnTrain_Background; + if( iSignal ) + { + i_event_selected = ( double )iRun->fnTrain_Signal; + } + double i_fraction_of_events_to_keep = i_event_selected / ( double )elist->GetN(); + i_fraction_of_events_to_keep *= 10.; + if( iTreeVector.size() > 0. ) + { + i_fraction_of_events_to_keep /= ( double )iTreeVector.size(); + } + if( i_fraction_of_events_to_keep > 1. ) + { + i_fraction_of_events_to_keep = 1.; + } + cout << "\t keeping " << i_fraction_of_events_to_keep * 100. << "\% of events of "; + if( iSignal ) { - cout << "\t variable " << iVariable << " ok, RMS: " << h->GetRMS() << ", tree: " << i; - // (confusing) cout << ", nbins " << h->GetNbinsX() << ", xmin " << h->GetXaxis()->GetXmin() << ", xmax " << h->GetXaxis()->GetXmax(); - cout << ", entries " << h->GetEntries(); - cout << endl; - h->Delete(); - return -9999.; + cout << iRun->fSignalFileName[i]; + } + else + { + cout << iRun->fBackgroundFileName[i]; + } + cout << " (training events: " << i_event_selected; + cout << ", events after pre-cuts: " << elist->GetN() << " number of runs: " << iTreeVector.size() << ")"; + cout << endl; + for( Long64_t el = 0; el < elist->GetN(); el++ ) + { + if( gRandom->Uniform() > i_fraction_of_events_to_keep ) + { + continue; + } + Long64_t treeEntry = elist->GetEntry( el ); + iTreeVector[i]->GetEntry( treeEntry ); + iDataTree_reduced->Fill(); + n++; } } - } - if( i < iTreeVector.size() - 1 && h ) - { - h->Delete(); + // remove this tree + if( iSignal ) + { + iRun->fSignalTree[i]->Delete(); + iRun->fSignalTree[i] = 0; + } + else + { + iRun->fBackgroundTree[i]->Delete(); + iRun->fBackgroundTree[i] = 0; + } } } - // means: variable is in all trees constant - cout << "\t warning: constant variable " << iVariable << " in "; - if( iSignal ) + if( iSignal && iDataTree_reduced ) { - cout << " signal tree"; + cout << "\t Reduced signal tree entries: " << iDataTree_reduced->GetEntries() << endl; } - else + else if( iDataTree_reduced ) { - cout << " background tree"; + cout << "\t Reduced background tree entries: " << iDataTree_reduced->GetEntries() << endl; } - if( h ) + else { - cout << " (mean " << h->GetMean() << ", RMS " << h->GetRMS() << ", entries " << h->GetEntries() << ")"; + cout << "Error in reducing data trees (missing tree)" << endl; + return 0; } - cout << ", checked " << iTreeVector.size() << " trees"; - cout << endl; - double i_mean = -9999.; - if( h ) + // cleanup all remaining trees + for( unsigned int i = 0; i < iTreeVector.size(); i++ ) { - i_mean = h->GetMean(); - h->Delete(); + if( iSignal && iRun->fSignalTree[i] ) + { + iRun->fSignalTree[i]->Delete(); + iRun->fSignalTree[i] = 0; + } + else if( !iSignal && iRun->fBackgroundTree[i] ) + { + iRun->fBackgroundTree[i]->Delete(); + iRun->fBackgroundTree[i] = 0; + } } - - return i_mean; + return iDataTree_reduced; } /*! @@ -147,21 +232,21 @@ double checkIfVariableIsConstant( VTMVARunData* iRun, TCut iCut, string iVariabl */ bool trainGammaHadronSeparation( VTMVARunData* iRun, - unsigned int iEnergyBin, unsigned int iZenithBin ) + unsigned int iEnergyBin, unsigned int iZenithBin ) { return train( iRun, iEnergyBin, iZenithBin, true ); } bool trainReconstructionQuality( VTMVARunData* iRun, - unsigned int iEnergyBin, unsigned int iZenithBin ) + unsigned int iEnergyBin, unsigned int iZenithBin ) { return train( iRun, iEnergyBin, iZenithBin, false ); } bool train( VTMVARunData* iRun, - unsigned int iEnergyBin, unsigned int iZenithBin, - bool iTrainGammaHadronSeparation ) + unsigned int iEnergyBin, unsigned int iZenithBin, + bool iTrainGammaHadronSeparation ) { // sanity checks if( !iRun ) @@ -170,142 +255,122 @@ bool train( VTMVARunData* iRun, } if( iRun->fEnergyCutData.size() <= iEnergyBin || iRun->fOutputFile.size() <= iEnergyBin ) { - cout << "error in train: energy bin out of range " << iEnergyBin; + cout << "error during training: energy bin out of range " << iEnergyBin << endl; return false; } if( iRun->fZenithCutData.size() < iZenithBin || iRun->fOutputFile[0].size() < iZenithBin ) { - cout << "error in train: zenith bin out of range " << iZenithBin; + cout << "error during training: zenith bin out of range " << iZenithBin << endl; return false; } + // quality cuts before training + TCut iCutSignal = iRun->fQualityCuts + && iRun->fMCxyoffCut && + iRun->fEnergyCutData[iEnergyBin]->fEnergyCut + && iRun->fZenithCutData[iZenithBin]->fZenithCut; + + TCut iCutBck = iRun->fQualityCuts && iRun->fQualityCutsBkg + && iRun->fEnergyCutData[iEnergyBin]->fEnergyCut + && iRun->fZenithCutData[iZenithBin]->fZenithCut; + + if( !iRun->fMCxyoffCutSignalOnly ) + { + iCutBck = iCutBck && iRun->fMCxyoffCut; + } - TMVA::Tools::Instance(); - - // set output directory - gSystem->mkdir( iRun->fOutputDirectoryName.c_str() ); - TString iOutputDirectory( iRun->fOutputDirectoryName.c_str() ); - gSystem->ExpandPathName( iOutputDirectory ); - ( TMVA::gConfig().GetIONames() ).fWeightFileDir = iOutputDirectory; + // adding training variables + if( iRun->fTrainingVariable.size() != iRun->fTrainingVariableType.size() ) + { + cout << "train: error: training-variable vectors have different size" << endl; + return false; + } - ////////////////////////////////////////// - // defining training class - TMVA::Factory* factory = new TMVA::Factory( iRun->fOutputFile[iEnergyBin][iZenithBin]->GetTitle(), iRun->fOutputFile[iEnergyBin][iZenithBin], "V" ); - TMVA::DataLoader* dataloader = new TMVA::DataLoader( "dataset" ); - //////////////////////////// - // train gamma/hadron separation - if( iTrainGammaHadronSeparation ) + // prepare trees for training and testing with selected events only + // this step is necessary to minimise the memory impact for the BDT + // training + TTree* iSignalTree_reduced = 0; + TTree* iBackgroundTree_reduced = 0; + if( iRun->fRunOption == "WRITETRAININGEVENTS" ) { - // adding signal and background trees - for( unsigned int i = 0; i < iRun->fSignalTree.size(); i++ ) + iSignalTree_reduced = prepareSelectedEventsTree( iRun, + iCutSignal, true ); + iBackgroundTree_reduced = prepareSelectedEventsTree( iRun, + iCutBck, false ); + if( !iSignalTree_reduced || !iBackgroundTree_reduced ) { - dataloader->AddSignalTree( iRun->fSignalTree[i], iRun->fSignalWeight ); + cout << "Error: failed preparing traing / testing trees" << endl; + return false; } - for( unsigned int i = 0; i < iRun->fBackgroundTree.size(); i++ ) + iSignalTree_reduced->Write(); + iBackgroundTree_reduced->Write(); + if( iRun->getTLRunParameter() ) { - dataloader->AddBackgroundTree( iRun->fBackgroundTree[i], iRun->fBackgroundWeight ); + iRun->getTLRunParameter()->Write(); } + cout << "Writing reduced event lists for training: "; + cout << gDirectory->GetName() << endl; + return true; } - //////////////////////////// - // train reconstruction quality else { - for( unsigned int i = 0; i < iRun->fSignalTree.size(); i++ ) + cout << "Reading training / testing trees from "; + cout << iRun->fSelectedEventFileName << endl; + TFile* iF = new TFile( iRun->fSelectedEventFileName.c_str() ); + if( iF->IsZombie() ) { - dataloader->AddRegressionTree( iRun->fSignalTree[i], iRun->fSignalWeight ); + cout << "Error open file with pre-selected events: "; + cout << iRun->fSelectedEventFileName << endl; + return false; } - dataloader->AddRegressionTarget( iRun->fReconstructionQualityTarget.c_str(), iRun->fReconstructionQualityTargetName.c_str() ); + iSignalTree_reduced = ( TTree* )iF->Get( "data_signal" ); + iBackgroundTree_reduced = ( TTree* )iF->Get( "data_background" ); } - - // quality cuts before training - TCut iCutSignal = iRun->fQualityCuts - && iRun->fMCxyoffCut && - iRun->fEnergyCutData[iEnergyBin]->fEnergyCut - && iRun->fZenithCutData[iZenithBin]->fZenithCut; - - TCut iCutBck = iRun->fQualityCuts && iRun->fQualityCutsBkg - && iRun->fEnergyCutData[iEnergyBin]->fEnergyCut - && iRun->fZenithCutData[iZenithBin]->fZenithCut; - - if( !iRun->fMCxyoffCutSignalOnly ) + if( !iSignalTree_reduced || !iBackgroundTree_reduced ) { - iCutBck = iCutBck && iRun->fMCxyoffCut; + cout << "Error: failed preparing traing / testing trees" << endl; + return false; } - - // adding training variables - if( iRun->fTrainingVariable.size() != iRun->fTrainingVariableType.size() ) + if( iSignalTree_reduced->GetEntries() < 1000 || iBackgroundTree_reduced->GetEntries() < 1000 ) { - cout << "train: error: training-variable vectors have different size" << endl; + cout << "Error: less than 1000 events available for training: "; + cout << " signal (" << iSignalTree_reduced->GetEntries() << "), "; + cout << " background (" << iBackgroundTree_reduced->GetEntries() << ")" << endl; return false; } + iRun->updateTrainingEvents( "nTrain_Signal", ( unsigned int )iSignalTree_reduced->GetEntries() * 0.7 ); + iRun->updateTrainingEvents( "nTrain_Background", ( unsigned int )iBackgroundTree_reduced->GetEntries() * 0.7 ); + + TMVA::Tools::Instance(); + gSystem->mkdir( iRun->fOutputDirectoryName.c_str() ); + TString iOutputDirectory( iRun->fOutputDirectoryName.c_str() ); + gSystem->ExpandPathName( iOutputDirectory ); + ( TMVA::gConfig().GetIONames() ).fWeightFileDir = iOutputDirectory; - // check split mode - bool iSplitBlock = false; - if( iRun->fPrepareTrainingOptions.find( "SplitMode=Block" ) != string::npos ) + ////////////////////////////////////////// + // defining training class + TMVA::Factory* factory = new TMVA::Factory( iRun->fOutputFile[iEnergyBin][iZenithBin]->GetTitle(), + iRun->fOutputFile[iEnergyBin][iZenithBin], + "V:!DrawProgressBar" ); + TMVA::DataLoader* dataloader = new TMVA::DataLoader( "" ); + //////////////////////////// + // train gamma/hadron separation + if( iTrainGammaHadronSeparation ) { - cout << "train: use option SplitMode=Block" << endl; - iSplitBlock = true; + dataloader->AddSignalTree( iSignalTree_reduced, iRun->fSignalWeight ); + dataloader->AddBackgroundTree( iBackgroundTree_reduced, iRun->fBackgroundWeight ); + } + //////////////////////////// + // train reconstruction quality + else + { + dataloader->AddSignalTree( iSignalTree_reduced, iRun->fSignalWeight ); + dataloader->AddRegressionTarget( iRun->fReconstructionQualityTarget.c_str(), iRun->fReconstructionQualityTargetName.c_str() ); } // loop over all trainingvariables and add them to TMVA - // (test first if variable is constant, TMVA will stop when a variable - // is constant) for( unsigned int i = 0; i < iRun->fTrainingVariable.size(); i++ ) { - if( iRun->fTrainingVariable[i].find( "NImages_Ttype" ) != string::npos ) - { - for( int j = 0; j < iRun->fNTtype; j++ ) - { - ostringstream iTemp; - iTemp << iRun->fTrainingVariable[i] << "[" << j << "]"; - ostringstream iTempCut; - // require at least 2 image per telescope type - iTempCut << iTemp.str() << ">1"; - TCut iCutCC = iTempCut.str().c_str(); - - double iSignalMean = 1.; - double iBckMean = -1.; - if( iRun->fCheckValidityOfInputVariables ) - { - iSignalMean = checkIfVariableIsConstant( iRun, iCutSignal && iCutCC, iTemp.str(), true, iSplitBlock ); - iBckMean = checkIfVariableIsConstant( iRun, iCutBck && iCutCC, iTemp.str(), false, iSplitBlock ); - cout << "\t mean values " << iSignalMean << "\t" << iBckMean << endl; - } - if( ( TMath::Abs( iSignalMean - iBckMean ) > 1.e-6 - || TMath::Abs( iSignalMean + 9999. ) < 1.e-2 || TMath::Abs( iBckMean + 9999. ) < 1.e-2 ) - && iSignalMean != 0 && iBckMean != 0 ) - { - dataloader->AddVariable( iTemp.str().c_str(), iRun->fTrainingVariableType[i] ); - } - else - { - cout << "warning: removed constant variable " << iTemp.str() << " from training (added to spectators)" << endl; - dataloader->AddSpectator( iTemp.str().c_str() ); - } - } - } - else - { - // check if the training variable is constant - double iSignalMean = 1.; - double iBckMean = -1.; - if( iRun->fCheckValidityOfInputVariables ) - { - checkIfVariableIsConstant( iRun, iCutSignal, iRun->fTrainingVariable[i].c_str(), true, iSplitBlock ); - checkIfVariableIsConstant( iRun, iCutBck, iRun->fTrainingVariable[i].c_str(), false, iSplitBlock ); - cout << "\t mean values " << iSignalMean << "\t" << iBckMean << endl; - } - - if( TMath::Abs( iSignalMean - iBckMean ) > 1.e-6 - || TMath::Abs( iSignalMean + 9999. ) < 1.e-2 || TMath::Abs( iBckMean + 9999. ) < 1.e-2 ) - { - dataloader->AddVariable( iRun->fTrainingVariable[i].c_str(), iRun->fTrainingVariableType[i] ); - } - else - { - cout << "warning: removed constant variable " << iRun->fTrainingVariable[i] << " from training (added to spectators)" << endl; - dataloader->AddSpectator( iRun->fTrainingVariable[i].c_str() ); - } - } + dataloader->AddVariable( iRun->fTrainingVariable[i].c_str(), iRun->fTrainingVariableType[i] ); } // adding spectator variables for( unsigned int i = 0; i < iRun->fSpectatorVariable.size(); i++ ) @@ -318,52 +383,52 @@ bool train( VTMVARunData* iRun, // nTrain Signal=5000:nTrain Background=5000: nTest Signal=4000:nTest Background=5000 dataloader->PrepareTrainingAndTestTree( iCutSignal, - iCutBck, - iRun->fPrepareTrainingOptions ); - + iCutBck, + iRun->fPrepareTrainingOptions ); + ////////////////////////////////////////// // book all methods char htitle[6000]; for( unsigned int i = 0; i < iRun->fMVAMethod.size(); i++ ) { - TMVA::Types::EMVA i_tmva_type = TMVA::Types::kBDT; + TMVA::Types::EMVA i_tmva_type = TMVA::Types::kBDT; if( iRun->fMVAMethod[i] == "BDT" ) { if( iTrainGammaHadronSeparation ) { sprintf( htitle, "BDT_0" ); - i_tmva_type = TMVA::Types::kBDT; + i_tmva_type = TMVA::Types::kBDT; } else { sprintf( htitle, "BDT_RecQuality_0" ); } - } - else if( iRun->fMVAMethod[i] == "MLP" ) - { - i_tmva_type = TMVA::Types::kMLP; - } - + } + else if( iRun->fMVAMethod[i] == "MLP" ) + { + i_tmva_type = TMVA::Types::kMLP; + } + ////////////////////////// - if( iRun->fMVAMethod[i] != "BOXCUTS" ) + if( iRun->fMVAMethod[i] != "BOXCUTS" ) { if( iTrainGammaHadronSeparation ) { - sprintf( htitle, "%s_%u", iRun->fMVAMethod[i].c_str(), i ); + sprintf( htitle, "%s_%u", iRun->fMVAMethod[i].c_str(), i ); } else { - sprintf( htitle, "%s_RecQuality_%u", iRun->fMVAMethod[i].c_str(), i ); + sprintf( htitle, "%s_RecQuality_%u", iRun->fMVAMethod[i].c_str(), i ); } if( i < iRun->fMVAMethod_Options.size() ) { - cout << "Booking method " << htitle << endl; - factory->BookMethod( dataloader, i_tmva_type, htitle, iRun->fMVAMethod_Options[i].c_str() ); + cout << "Booking method " << htitle << endl; + factory->BookMethod( dataloader, i_tmva_type, htitle, iRun->fMVAMethod_Options[i].c_str() ); } else { - factory->BookMethod( dataloader, i_tmva_type, htitle ); + factory->BookMethod( dataloader, i_tmva_type, htitle ); } } ////////////////////////// @@ -372,7 +437,7 @@ bool train( VTMVARunData* iRun, else if( iRun->fMVAMethod[i] == "BOXCUTS" ) { stringstream i_opt; - i_opt << iRun->fMVAMethod_Options[i].c_str(); + i_opt << iRun->fMVAMethod_Options[i].c_str(); for( unsigned int i = 0; i < iRun->fTrainingVariable_CutRangeMin.size(); i++ ) { i_opt << ":CutRangeMin[" << i << "]=" << iRun->fTrainingVariable_CutRangeMin[i]; @@ -403,6 +468,7 @@ bool train( VTMVARunData* iRun, factory->EvaluateAllMethods(); + dataloader->Delete(); factory->Delete(); return true; @@ -427,13 +493,13 @@ int main( int argc, char* argv[] ) cout << endl; cout << "trainTMVAforGammaHadronSeparation " << VGlobalRunParameter::getEVNDISP_VERSION() << endl; cout << "----------------------------------------" << endl; - if( argc != 2 ) + if( argc != 2 && argc != 3 ) { cout << endl; - cout << "./trainTMVAforGammaHadronSeparation " << endl; + cout << "./trainTMVAforGammaHadronSeparation [WRITETRAININGEVENTS]" << endl; cout << endl; cout << " (an example for a configuration file can be found in " << endl; - cout << " $CTA_EVNDISP_AUX_DIR/ParameterFiles/TMVA.BDT.runparameter )" << endl; + cout << " $VERITAS_EVNDISP_AUX_DIR/ParameterFiles/TMVA.BDT.runparameter )" << endl; cout << endl; exit( EXIT_SUCCESS ); } @@ -453,6 +519,12 @@ int main( int argc, char* argv[] ) cout << ")" << endl; exit( EXIT_FAILURE ); } + if( argc == 3 ) + { + fData->fRunOption = "WRITETRAININGEVENTS"; + } + // randomize list of input files + cout << "randomizing input files" << endl; fData->print(); ////////////////////////////////////// @@ -465,10 +537,10 @@ int main( int argc, char* argv[] ) ////////////////////////////////////// // train MVA - // (one training per energy bin) - cout << "Number of energy bins: " << fData->fEnergyCutData.size(); - cout << ", number of zenith bins: " << fData->fZenithCutData.size(); - cout << endl; + // (one training per energy and zenith bin) + cout << "Number of energy bins: " << fData->fEnergyCutData.size(); + cout << ", number of zenith bins: " << fData->fZenithCutData.size(); + cout << endl; cout << "================================" << endl << endl; for( unsigned int i = 0; i < fData->fEnergyCutData.size(); i++ ) { @@ -477,15 +549,20 @@ int main( int argc, char* argv[] ) if( fData->fEnergyCutData[i]->fEnergyCut && fData->fZenithCutData[j]->fZenithCut ) { cout << "Training energy bin " << fData->fEnergyCutData[i]->fEnergyCut; - cout << " zenith bin " << fData->fZenithCutData[j]->fZenithCut << endl; + cout << " zenith bin " << fData->fZenithCutData[j]->fZenithCut << endl; cout << "===================================================================================" << endl; cout << endl; } - // training + /////////////////////////////////////////////// + // training if( fData->fTrainGammaHadronSeparation && !trainGammaHadronSeparation( fData, i, j ) ) { - cout << "Error during training...exiting" << endl; - exit( EXIT_FAILURE ); + cout << "Error during training...exiting" << endl; + exit( EXIT_FAILURE ); + } + if( fData->fRunOption == "WRITETRAININGEVENTS" ) + { + continue; } if( fData->fTrainReconstructionQuality ) { @@ -514,37 +591,37 @@ int main( int argc, char* argv[] ) iTempS2 << fData->fOutputFileName << ".root"; } - // prepare a short root file with the necessary values only - // write energy & zenith cuts, plus signal and background efficiencies + // prepare a short root file with the necessary values only + // write energy & zenith cuts, plus signal and background efficiencies TFile* root_file = fData->fOutputFile[i][j]; - if( !root_file ) - { - cout << "Error finding tvma root file " << endl; - continue; - } + if( !root_file ) + { + cout << "Error finding tvma root file " << endl; + continue; + } TFile* short_root_file = TFile::Open( iTempS.str().c_str(), "RECREATE" ); - if( !short_root_file->IsZombie() ) - { - VTMVARunDataEnergyCut* fDataEnergyCut = ( VTMVARunDataEnergyCut* )root_file->Get( "fDataEnergyCut" ); - VTMVARunDataZenithCut* fDataZenithCut = ( VTMVARunDataZenithCut* )root_file->Get( "fDataZenithCut" ); - TH1D* MVA_BDT_0_effS = ( TH1D* )root_file->Get( "Method_BDT/BDT_0/MVA_BDT_0_effS" ); - TH1D* MVA_BDT_0_effB = ( TH1D* )root_file->Get( "Method_BDT/BDT_0/MVA_BDT_0_effB" ); - fDataEnergyCut->Write(); - fDataZenithCut->Write(); - TDirectory* Method_BDT = short_root_file->mkdir( "Method_BDT" ); - Method_BDT->cd(); - TDirectory* BDT_0 = Method_BDT->mkdir( "BDT_0" ); - BDT_0->cd(); - MVA_BDT_0_effS->Write(); - MVA_BDT_0_effB->Write(); - short_root_file->GetList(); - short_root_file->Write(); - short_root_file->Close(); - } - else - { - cout << "Error: could not create file with energy cuts " << iTempS.str().c_str() << endl; - } + if( !short_root_file->IsZombie() ) + { + VTMVARunDataEnergyCut* fDataEnergyCut = ( VTMVARunDataEnergyCut* )root_file->Get( "fDataEnergyCut" ); + VTMVARunDataZenithCut* fDataZenithCut = ( VTMVARunDataZenithCut* )root_file->Get( "fDataZenithCut" ); + TH1D* MVA_BDT_0_effS = ( TH1D* )root_file->Get( "Method_BDT/BDT_0/MVA_BDT_0_effS" ); + TH1D* MVA_BDT_0_effB = ( TH1D* )root_file->Get( "Method_BDT/BDT_0/MVA_BDT_0_effB" ); + fDataEnergyCut->Write(); + fDataZenithCut->Write(); + TDirectory* Method_BDT = short_root_file->mkdir( "Method_BDT" ); + Method_BDT->cd(); + TDirectory* BDT_0 = Method_BDT->mkdir( "BDT_0" ); + BDT_0->cd(); + MVA_BDT_0_effS->Write(); + MVA_BDT_0_effB->Write(); + short_root_file->GetList(); + short_root_file->Write(); + short_root_file->Close(); + } + else + { + cout << "Error: could not create file with energy cuts " << iTempS.str().c_str() << endl; + } // copy complete TMVA output root-file to another directory string iOutputFileName( fData->fOutputDirectoryName + "/" + iTempS2.str() ); string iOutputFileNameCompleteSubDir( "complete_BDTroot" ); @@ -561,6 +638,6 @@ int main( int argc, char* argv[] ) rename( iTempS.str().c_str(), iFinalRootFileName.c_str() ); } } + fData->Delete(); return 0; } - diff --git a/src/trainTMVAforGammaHadronSeparation_TrainingFile.cpp b/src/trainTMVAforGammaHadronSeparation_TrainingFile.cpp deleted file mode 100644 index f27baf420..000000000 --- a/src/trainTMVAforGammaHadronSeparation_TrainingFile.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* \file trainTMVAforGammaHadronSeparation_TrainingFile.cpp - \brief make background training files for TMVA using MC and randomize theta2 - - Note: no wobble offsets are implemented yet - -*/ - -#include -#include -#include -#include -#include - -#include "TFile.h" -#include "TMath.h" -#include "TRandom3.h" -#include "TSystem.h" -#include "TTree.h" - -using namespace std; - -/* - - get list of file names (full paths) from parameter file - -*/ -vector< string > getListofFiles( string iFileName ) -{ - ifstream is; - is.open( iFileName.c_str(), ifstream::in ); - if( !is ) - { - cout << "error, no input file list found: " << iFileName << endl; - exit( -1 ); - - } - cout << "list of files from " << iFileName << endl; - cout << endl; - string is_line; - string temp; - vector< string > iFileList; - - while( getline( is, is_line ) ) - { - stringstream is_stream( is_line ); - is_stream >> temp; - if( temp != "*" ) - { - continue; - } - is_stream >> temp; - if( temp != "BACKGROUNDFILE" ) - { - continue; - } - is_stream >> temp; - iFileList.push_back( temp ); - } - is.close(); - - return iFileList; -} - - -/* - - main... - -*/ -int main( int argc, char* argv[] ) -{ - if( argc != 5 ) - { - cout << endl; - cout << "trainTMVAforGammaHadronSeparation_TrainingFile " << endl; - cout << endl; - cout << ""; - cout << "parameter file with list of background mscw file (same format as in trainTMVAforGammaHadronSeparation)" << endl; - cout << " seed for random generator (default: 0)" << endl; - cout << endl; - cout << "Note: no wobble offsets are implemented yet" << endl; - cout << "Note: you might want to have some additional cuts (e.g. distance to the camera center) hardwired" << endl; - cout << endl; - exit( 0 ); - } - - cout << endl; - cout << "trainTMVAforGammaHadronSeparation_TrainingFile" << endl; - cout << "====================================" << endl; - cout << endl; - - double fMaxTheta = TMath::Sqrt( atof( argv[3] ) ); - UInt_t fRandomSeed = ( UInt_t )( atoi( argv[4] ) ); - - cout << "replacing Xoff/Yoff by random value inside a circle of radius " << fMaxTheta << " deg" << endl; - cout << "replace MCxoff/MCyoff by 0,0 " << endl; - - // random generator - TRandom3* fRandom = new TRandom3( fRandomSeed ); - - // get list of files to change - vector< string > iFileList = getListofFiles( argv[1] ); - string i_outputDir = argv[2]; - - // loop over all input files - for( unsigned int f = 0; f < iFileList.size(); f++ ) - { - - // input data file - string iIfile = iFileList[f]; - - TFile* fInput = new TFile( iIfile.c_str() ); - if( fInput->IsZombie() ) - { - cout << "error reading input file " << iIfile << endl; - cout << "exit..." << endl; - exit( -1 ); - } - // input data tree - TTree* fInputData = ( TTree* )fInput->Get( "data" ); - if( !fInputData ) - { - cout << "error reading input tree from " << iIfile << endl; - exit( -1 ); - } - double fXoff = 0.; - double fYoff = 0.; - double fMCXoff = 0.; - double fMCYoff = 0.; - fInputData->SetBranchAddress( "Xoff", &fXoff ); - fInputData->SetBranchAddress( "Yoff", &fYoff ); - fInputData->SetBranchAddress( "MCxoff", &fMCXoff ); - fInputData->SetBranchAddress( "MCyoff", &fMCYoff ); - Int_t nentries = ( Int_t )fInputData->GetEntries(); - - // output data file - string iOfile = i_outputDir + "/" + gSystem->BaseName( iFileList[f].c_str() ); - if( iIfile == iOfile ) - { - cout << "error: input and output file is identical" << endl; - exit( -1 ); - } - TFile* fOutput = new TFile( iOfile.c_str(), "RECREATE" ); - if( fOutput->IsZombie() ) - { - cout << "error opening output file " << iOfile << endl; - exit( -1 ); - } - - // output data tree - TTree* fOutputData = fInputData->CloneTree( 0 ); - - double i_theta = 0.; - double i_r = 0.; - - // loop over all entries - cout << "Looping over " << nentries << " events in " << fInput->GetName() << endl; - for( Int_t i = 0; i < nentries; i++ ) - { - fInputData->GetEntry( i ); - - i_r = TMath::Sqrt( fRandom->Uniform( 1. ) ); - i_theta = fRandom->Uniform( TMath::TwoPi() ); - fXoff = fMaxTheta * i_r * TMath::Cos( i_theta ); - fYoff = fMaxTheta * i_r * TMath::Sin( i_theta ); - - fMCXoff = 0.; - fMCYoff = 0.; - - fOutputData->Fill(); - } - cout << "writing new tree to " << fOutput->GetName() << endl; - fOutputData->AutoSave(); - - delete fInput; - delete fOutput; - } // end of loop over all files -} diff --git a/src/writeParticleRateFilesForTMVA.cpp b/src/writeParticleRateFilesForTMVA.cpp index 0ed2a20d2..cafec7f38 100644 --- a/src/writeParticleRateFilesForTMVA.cpp +++ b/src/writeParticleRateFilesForTMVA.cpp @@ -1,6 +1,7 @@ /* writeParticleRateFilesForTMVA write files with particle number spectra for on (gamma) and off (protons+electrons) counts + (differential counting rates) files are needed e.g. for setting the optimal cut value for TMVA cuts @@ -12,27 +13,16 @@ */ -#include "VTMVARunData.h" -#include "VInstrumentResponseFunctionReader.h" -#include "VWPPhysSensitivityFile.h" #include #include #include -#include "TStyle.h" #include "TFile.h" #include "TTree.h" #include "TH1D.h" -#include "TCanvas.h" -#include "TGraph.h" -#include "TGraphErrors.h" #include "TH2D.h" -#include "TGraph2D.h" #include "TMath.h" -#include "TLegend.h" -#include "TMultiGraph.h" -#include "TGraph2D.h" #include "TGraph2DErrors.h" using namespace std; @@ -50,10 +40,8 @@ int main( int argc, char* argv[] ) { cout << endl; cout << "writeParticleRateFilesForTMVA "; - //cout << " [qsub options]" << endl; - //cout << argc << endl; cout << endl; - exit( 0 ); + exit( EXIT_FAILURE ); } cout << endl; @@ -64,64 +52,51 @@ int main( int argc, char* argv[] ) string iDataDir = argv[1]; string iOutFil = argv[2]; - Int_t runOn; - Double_t OffNorm, elevationOn, elevationOff, azimuthOn, azimuthOff; - Double_t tOn = 0.; - Double_t tObs, alphaNorm; - tObs = 0.; - alphaNorm = 0.; - /* Name and directory to the COMBINED anasum root file */ - char iInputFile[800]; - sprintf( iInputFile, "%s", iDataDir.c_str() ); - TFile* f1 = new TFile( iInputFile, "OPEN" ); + TFile* f1 = new TFile( iDataDir.c_str() , "OPEN" ); + if( f1->IsZombie() ) + { + cout << "Error reading file " << iDataDir << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } char reddataname[256], histnameOn[256], histnameOff[256]; TTree* RunSum = ( TTree* )f1->Get( "total_1/stereo/tRunSummary" ); + if( !RunSum ) + { + cout << "Error reading run summary tree" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + if( RunSum->GetEntries() == 0 ) + { + cout << "Error reading run summary tree - empty tree" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } - RunSum->SetBranchAddress( "runOn", &runOn ); + Int_t runOn = 0; + Double_t OffNorm = 0.; + Double_t elevationOff = 0.; + Double_t alphaNorm = 0.; RunSum->SetBranchAddress( "runOn", &runOn ); RunSum->SetBranchAddress( "OffNorm", &OffNorm ); - RunSum->SetBranchAddress( "elevationOn", &elevationOn ); RunSum->SetBranchAddress( "elevationOff", &elevationOff ); - RunSum->SetBranchAddress( "azimuthOn", &azimuthOn ); - RunSum->SetBranchAddress( "azimuthOff", &azimuthOff ); - RunSum->SetBranchAddress( "tOn", &tOn ); - - double iZenithperrun; - - double new_on; - double new_off; - double new_on_error, new_off_error; - - unsigned int iBin = 0; - - for( unsigned int i = 0; i < ( RunSum->GetEntries() - 1 ); i++ ) - { - RunSum->GetEntry( i ); - - sprintf( histnameOn, "run_%d/stereo/energyHistograms/herecCounts_on", runOn ); - sprintf( histnameOff, "run_%d/stereo/energyHistograms/herecCounts_off", runOn ); - TH1D* t2 = ( TH1D* )f1->Get( histnameOff ); - - //unsigned int nbins_t1 = t1->GetNbinsX(); - unsigned int nbins_t2 = t2->GetNbinsX(); - iBin = nbins_t2; - } - // ----------------------------------------------------------------- - // - // loop over the number of runs in the combined anasum root file - // - // check if the zenith angle is within a range of 5 degrees (zenith angle intervals are used for an easier optimization) - // - // ----------------------------------------------------------------- + // assume that all histograms for all runs have the same binning + RunSum->GetEntry( 0 ); + sprintf( histnameOn, "run_%d/stereo/energyHistograms/herecCounts_on", runOn ); + sprintf( histnameOff, "run_%d/stereo/energyHistograms/herecCounts_off", runOn ); + TH1D* t2 = ( TH1D* )f1->Get( histnameOff ); + unsigned int iBin = t2->GetNbinsX(); TGraph2DErrors* tRatePerEnergyON = new TGraph2DErrors(); + tRatePerEnergyON->SetMarkerStyle( 20 ); TGraph2DErrors* tRatePerEnergyOFF = new TGraph2DErrors(); + tRatePerEnergyOFF->SetMarkerStyle( 20 ); TGraph2DErrors* tRatePerEnergySignal = new TGraph2DErrors(); - - int l = 0; + tRatePerEnergySignal->SetMarkerStyle( 20 ); int m = 0; for( unsigned int i = 0; i < ( RunSum->GetEntries() - 1 ); i++ ) @@ -129,8 +104,7 @@ int main( int argc, char* argv[] ) RunSum->GetEntry( i ); alphaNorm = OffNorm; - //iZenithperrun = 90.0 - elevationOn; - iZenithperrun = 90.0 - elevationOff; + double iZenithperrun = 90.0 - elevationOff; sprintf( histnameOn, "run_%d/stereo/energyHistograms/herecCounts_on", runOn ); sprintf( histnameOff, "run_%d/stereo/energyHistograms/herecCounts_off", runOn ); TH1D* t1 = ( TH1D* )f1->Get( histnameOn ); @@ -139,93 +113,52 @@ int main( int argc, char* argv[] ) // get the observation time of each run sprintf( reddataname, "run_%d/stereo/pointingDataReduced", runOn ); TTree* tReddata = ( TTree* )f1->Get( reddataname ); - - tObs = tReddata->GetEntries(); + if( !tReddata ) + { + cout << "Error reading pointingDataReduced tree for run " << runOn << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + Double_t tObs = tReddata->GetEntries(); cout << "Run Number: " << runOn ; - cout << ", Elevation angle = " << 90 - iZenithperrun ; cout << ", Zenith angle = " << iZenithperrun ; cout << ", Time for Run = " << tObs << "s" << endl; // get the bin content of the ON and OFF events per second and scale the off-counts with the alpha factor for( unsigned int k = 0; k < iBin; k++ ) { - new_on = ( t1->GetBinContent( k ) ) * 1.0 / tObs; - new_on_error = ( t1->GetBinError( k ) ) * 1.0 / tObs; - new_off = ( t2->GetBinContent( k ) ) * alphaNorm / tObs; - new_off_error = ( t2->GetBinError( k ) ) * alphaNorm / tObs; + double n_on = ( t1->GetBinContent( k ) ) * 1.0 / tObs; + double n_on_error = ( t1->GetBinError( k ) ) * 1.0 / tObs; + double n_off = ( t2->GetBinContent( k ) ) * alphaNorm / tObs; + double n_off_error = ( t2->GetBinError( k ) ) * alphaNorm / tObs; /* ON rate (signal and background) */ - tRatePerEnergyON->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, new_on ); - tRatePerEnergyON->SetPointError( m, 0., 0., new_on_error ); - tRatePerEnergyON->SetMarkerStyle( 20 ); + tRatePerEnergyON->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, n_on ); + tRatePerEnergyON->SetPointError( m, 0., 0., n_on_error ); /* Signal rate (ON minus OFF) */ - tRatePerEnergySignal->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, TMath::Abs( new_on - new_off ) ); - tRatePerEnergySignal->SetPointError( m, 0., 0., ( TMath::Abs( new_on_error + new_off_error ) / 2.0 ) ); - tRatePerEnergySignal->SetMarkerStyle( 20 ); + tRatePerEnergySignal->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, TMath::Abs( n_on - n_off ) ); + tRatePerEnergySignal->SetPointError( m, 0., 0., ( TMath::Abs( n_on_error + n_off_error ) / 2.0 ) ); /* OFF rate */ - tRatePerEnergyOFF->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, new_off ); - tRatePerEnergyOFF->SetPointError( m, 0., 0., new_off_error ); - tRatePerEnergyOFF->SetMarkerStyle( 20 ); + tRatePerEnergyOFF->SetPoint( m, t1->GetBinCenter( k ), iZenithperrun, n_off ); + tRatePerEnergyOFF->SetPointError( m, 0., 0., n_off_error ); m++; } - l++; } - // ----------------------------------------------------------------- - // - // Plot the ON, OFF and Signal rates (ON minus OFF) for the specific zenith angle intervals - // - // ----------------------------------------------------------------- - gStyle->SetPalette( 1 ); - - /* ON rate = Signal plus background */ - TCanvas* c1 = new TCanvas( "c1", "1D_On_Counts", 0, 0, 700, 500 ); - c1->cd(); - c1->SetRightMargin( 0.15 ); - - tRatePerEnergyON->SetTitle( "signal+background rate (1/sec); Log_{10}E [TeV]; Zenith angle [deg]" ); - tRatePerEnergyON->Draw( "P" ); - c1->Update(); - - // OFF rate = Background rate - TCanvas* c2 = new TCanvas( "c2", "1D_Off_Counts", 750, 0, 700, 500 ); - c2->cd(); - c2->SetRightMargin( 0.15 ); - - tRatePerEnergyOFF->SetTitle( "background rate (1/sec); Log_{10}E [TeV]; Zenith angle [deg]" ); - tRatePerEnergyOFF->Draw( "P" ); - c2->Update(); - - TCanvas* c3 = new TCanvas( "c3", "1D_Signal_Counts", 750, 750, 700, 500 ); - c3->cd(); - c3->SetRightMargin( 0.15 ); - tRatePerEnergySignal->SetTitle( "signal rate (1/sec); Log_{10}E [TeV]; Zenith angle [deg] " ); - tRatePerEnergySignal->Draw( "P" ); - c3->Update(); - - ////////////////////////////////////////////////////////////////////////////////////////// - - /* write particle number file */ - - char iOutputFile[800]; - sprintf( iOutputFile, "%s", iOutFil.c_str() ); - TFile* SignalRateFile = new TFile( iOutputFile, "RECREATE" ); - - SignalRateFile->cd(); - SignalRateFile->Write(); + // write particle number file + TFile* SignalRateFile = new TFile( iOutFil.c_str() , "RECREATE" ); // write graphs of ON rate to file tRatePerEnergyON->Write( "gONRate" ); - // write graphs of OFF rate to file tRatePerEnergyOFF->Write( "gBGRate" ); - // write graphs of signal rate to file tRatePerEnergySignal->Write( "gSignalRate" ); + SignalRateFile->Close(); return 0; } diff --git a/src/writeParticleRateFilesFromEffectiveAreas.cpp b/src/writeParticleRateFilesFromEffectiveAreas.cpp deleted file mode 100644 index 8c4e07d2d..000000000 --- a/src/writeParticleRateFilesFromEffectiveAreas.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* writeParticleRateFilesFromEffectiveAreas - - write files with particle number spectra for on (gamma) and off (protons+electrons) counts - - files are needed e.g. for setting the optimal cut value for TMVA cuts - - Input: - * effective areas (gammas/protons/electrons/ec) - * cosmic ray spectra (read from files) - - Output: - * root file with signal and background rates - * [optional] angular resolution histograms - -*/ - -#include "VHistogramUtilities.h" -#include "VInstrumentResponseFunctionReader.h" -#include "VWPPhysSensitivityFile.h" - -#include -#include -#include - -using namespace std; - -/* - - calculate angular angular resolution vs containment radius vs energy -*/ -void writeAngResHistogram( char* iMC_Gamma = 0, string iParticleNumberFile = "particleNumbers.tmp.root" ) -{ - if( !iMC_Gamma ) - { - return; - } - - VInstrumentResponseFunctionReader iR; - iR.fillData( iMC_Gamma ); - for( unsigned int i = 0; i < iR.fIRF_TreeNames.size(); i++ ) - { - if( iR.fIRF_TreeNames[i] == "t_angular_resolution_095p" ) - { - TH2D* h = 0; - if( i < iR.fIRF_Data.size() && iR.fIRF_Data[i] ) - { - h = iR.fIRF_Data[i]->f2DHisto[VInstrumentResponseFunctionData::E_DIFF]; - } - TH2D* hRes = VHistogramUtilities::calculateContainmentDistance( h, "AngResCumulative" ); - if( hRes ) - { - TFile hh( iParticleNumberFile.c_str(), "update" ); - cout << "writing angular resolution histogram to " << hh.GetName() << endl; - hRes->Write(); - hh.Close(); - } - break; - } - } -} - - - - -void writeParticleNumberFile( char* iMC_Gamma = 0, char* iMC_Proton = 0, char* iMC_Electron = 0, - unsigned int iCrabSpec_ID = 5, string iParticleNumberFile = "particleNumbers.tmp.root", - string iObservatory = "CTA" ) -{ - string iESpecDataFile_CrabNebula = "$" + iObservatory + "_EVNDISP_AUX_DIR/AstroData/TeV_data/EnergySpectrum_literatureValues_CrabNebula.dat"; - string iESpecDataFile_CosmicRays = "$" + iObservatory + "_EVNDISP_AUX_DIR/AstroData/TeV_data/EnergySpectrum_literatureValues_CR.dat"; - - if( iMC_Gamma && iMC_Proton ) - { - // use sensitivity calculator for differential flux calculation - VSensitivityCalculator b; - b.setDebug( false ); // creates lots of output (if set to true) - // set Crab Nebula spectrum - b.setEnergySpectrumfromLiterature( iESpecDataFile_CrabNebula, iCrabSpec_ID ); - // set output result file name - b.setWriteParticleNumberFile( iParticleNumberFile ); - // CTA - int i_Azbin_gamma = 0; - double i_index_gamma = 2.5; - int i_noise_gamma = 250; - double i_woff_gamma = 0.; - - int i_Azbin_proton = 0; - double i_index_proton = 2.5; - int i_noise_proton = 250; - double i_woff_proton = 0.; - cout << "SETTING EFFECTIVE AREA SEARCH VALUES TO " << iObservatory << endl; - ////////////////////////////////////////////////////////////////////////// - - // gammas - b.setMonteCarloParameters( 1, iESpecDataFile_CrabNebula, iCrabSpec_ID, iMC_Gamma, 20., - i_Azbin_gamma, i_woff_gamma, i_noise_gamma, i_index_gamma, - -1.9 ); - // protons - b.setMonteCarloParameters( 14, iESpecDataFile_CosmicRays, 0, iMC_Proton, 20., - i_Azbin_proton, i_woff_proton, i_noise_proton, i_index_proton, - -1.9 ); - // electrons (spectral index?) - if( iMC_Electron ) - { - b.setMonteCarloParameters( 2, iESpecDataFile_CosmicRays, 8, iMC_Electron, 20., 0, 0.0, 250, 3.0, -1.9 ); - } - // calculate differential fluxes for 5 bins per decade (0.2) - b.calculateParticleNumberGraphs_MC( 0.2 ); - } -} - -/* - - write files with particle number spectra for on (gamma) and off (protons+electrons) counts - - files are needed e.g. for setting the optimal cut value for TMVA cuts - - (for all sub arrays) - -*/ -int main( int argc, char* argv[] ) -{ - if( argc != 5 && argc != 6 ) - { - cout << endl; - cout << "writeParticleRateFilesFromEffectiveAreas "; - cout << " [directory with angular resolution files]" << endl; - cout << argc << endl; - cout << endl; - exit( 0 ); - } - - cout << endl; - cout << "writeParticleRateFilesFromEffectiveAreas" << endl; - cout << "========================================" << endl; - cout << endl; - - string SubArray = argv[1]; - string iOnSource = argv[2]; - int iRecID = atoi( argv[3] ); - string iDataDir = argv[4]; - string iAngResDir = ""; - if( argc == 6 ) - { - iAngResDir = argv[5]; - } - - // hardwired total number of off source bins - int iOffSetCounter = -1; - if( iOnSource == "onSource" ) - { - iOffSetCounter = 0; - } - else if( iOnSource == "cone" ) - { - iOffSetCounter = 8; - } - else if( iOnSource == "offset_7_bin_Norm_Pointing" ) - { - iOffSetCounter = 7; - } - else if( iOnSource == "offset_9_bin_WARSAW" ) - { - iOffSetCounter = 9; - } - else - { - cout << iOnSource << " invalid off source descriptor; should be: onSource or cone" << endl; - exit( -1 ); - } - - // effective area file names - string iMC_Gamma_onSource = "gamma_onSource"; - string iMC_Gamma_cone = "gamma_cone"; - string iMC_Proton = "proton"; - string iMC_Proton_onSource = "proton_onSource"; - string iMC_Electron = "electron"; - string iMC_Electron_onSource = "electron_onSource"; - - if( iOnSource == "offset_9_bin_WARSAW" ) - { - iMC_Gamma_cone = "gamma_0-20_WARSAW"; - iMC_Proton = "proton_0-20_rER_WARSAW"; - iMC_Electron = ""; - iMC_Gamma_onSource = ""; - } - if( iOnSource == "offset_7_bin_Norm_Pointing" ) - { - iMC_Gamma_cone = "gamma_0-20_Norm_Pointing"; - iMC_Proton = "proton_0-20_rER_Norm_Pointing"; - iMC_Electron = ""; - iMC_Gamma_onSource = ""; - } - - - char iGamma[800]; - char iProton[800]; - char iElectron[800]; - char iParticleNumberFile[800]; - - cout << "STARTING SUBARRAY " << SubArray << endl; - - // on-axis rates - if( iMC_Gamma_onSource.size() > 0 ) - { - sprintf( iParticleNumberFile, "%s/ParticleNumbers.%s.00.root", iDataDir.c_str(), SubArray.c_str() ); - sprintf( iGamma, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Gamma_onSource.c_str(), SubArray.c_str(), iRecID, 0 ); - sprintf( iProton, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Proton_onSource.c_str(), SubArray.c_str(), iRecID, 0 ); - if( iMC_Electron_onSource.size() > 0 ) - { - sprintf( iElectron, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Electron_onSource.c_str(), SubArray.c_str(), iRecID, 0 ); - writeParticleNumberFile( iGamma, iProton, iElectron, 5, iParticleNumberFile ); - } - else - { - writeParticleNumberFile( iGamma, iProton, 0, 5, iParticleNumberFile ); - } - // angular resolution histogram - if( iAngResDir.size() > 0 ) - { - sprintf( iGamma, "%s/%s.%s_ID%d.eff-%d.root", iAngResDir.c_str(), iMC_Gamma_onSource.c_str(), SubArray.c_str(), iRecID, 0 ); - writeAngResHistogram( iGamma, iParticleNumberFile ); - } - } - - // off-axis rates - for( int j = 0; j < iOffSetCounter; j++ ) // use first bin on source particle file - { - - sprintf( iParticleNumberFile, "%s/ParticleNumbers.%s.%d.root", iDataDir.c_str(), SubArray.c_str(), j ); - sprintf( iGamma, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Gamma_cone.c_str(), SubArray.c_str(), iRecID, j ); - sprintf( iProton, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Proton.c_str(), SubArray.c_str(), iRecID, j ); - - if( iMC_Electron.size() > 0 ) - { - sprintf( iElectron, "%s/%s.%s_ID%d.eff-%d.root", iDataDir.c_str(), iMC_Electron.c_str(), SubArray.c_str(), iRecID, j ); - writeParticleNumberFile( iGamma, iProton, iElectron, 5, iParticleNumberFile ); - } - else - { - writeParticleNumberFile( iGamma, iProton, 0, 5, iParticleNumberFile ); - } - // angular resolution histogram - if( iAngResDir.size() > 0 ) - { - sprintf( iGamma, "%s/%s.%s_ID%d.eff-%d.root", iAngResDir.c_str(), iMC_Gamma_cone.c_str(), SubArray.c_str(), iRecID, j ); - writeAngResHistogram( iGamma, iParticleNumberFile ); - } - } -} - From 5de6eb658d71073ead8f941d2aaa43126972688c Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Tue, 18 Apr 2023 10:18:21 +0200 Subject: [PATCH 06/17] Add changes by GM --- inc/VCalibrator.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/inc/VCalibrator.h b/inc/VCalibrator.h index 05d86918a..015d2e4cc 100644 --- a/inc/VCalibrator.h +++ b/inc/VCalibrator.h @@ -4,17 +4,14 @@ #define VCALIBRATOR_H #include "VImageBaseAnalyzer.h" -<<<<<<< HEAD #include "VPedestalCalculator.h" #include "VIPRCalculator.h" #include "VDB_CalibrationInfo.h" #include -======= #include "VIPRCalculator.h" #include "VPedestalCalculator.h" #include "VDB_CalibrationInfo.h" #include "VSQLTextFileReader.h" ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 #include "TClonesArray.h" #include "TFile.h" @@ -112,15 +109,12 @@ class VCalibrator : public VImageBaseAnalyzer void readfromVOFFLINE_DB( int gain_or_toff, string& iFile, vector< unsigned int >& VchannelList, vector< double >& Vmean, vector< double >& Vrms ); void readGains( bool iLowGain = false ); bool readIPRGraph_from_DSTFile( string iDSTFile, unsigned int iSummationWindow, ULong64_t iTelType ); -<<<<<<< HEAD bool calculateIPRGraphs(); bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); TH1F* initializeIPRAveraged( unsigned int iSummationWindow, unsigned int iTelType ); TH1F* calculateIPRGraphAveraged( unsigned int iSummationWindow ); -======= bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 bool readLowGainMultiplier( ); bool readPeds( string iFile, bool, unsigned int ); bool readPeds_from_grisufile( bool, unsigned int ); @@ -133,11 +127,8 @@ class VCalibrator : public VImageBaseAnalyzer void setCalibrationFileNames(); void writeGains( bool iLowGain = false ); -<<<<<<< HEAD void writePeds( bool iLowGain, VPedestalCalculator* iP = 0, bool iWriteAsciiFile = true ); -======= void writePeds( bool iLowGain, VPedestalCalculator* iP = 0, bool iWriteAsciiFile = true, VIPRCalculator* fIPRCalculator = 0 ); ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 void writeTOffsets( bool iLowGain = false ); void writeAverageTZeros( bool iLowGain = false ); bool writeIPRgraphs( string iFile = "" ); @@ -151,13 +142,10 @@ class VCalibrator : public VImageBaseAnalyzer void calculatePedestals( bool iLowGain = false ); void calculateGainsAndTOffsets( bool iLowGain = false ); unsigned int getNumberOfEventsUsedInCalibration( int iTelID, int iType ); -<<<<<<< HEAD void initialize(VIPRCalculator *fIPRCalculator ); void terminate( VPedestalCalculator* ); -======= //void calculateIPRGraphs(VIPRCalculator *fIPRCalculator = 0, VPedestalCalculator *iP = 0); void initialize( VIPRCalculator* fIPRCalculator ); void terminate( VPedestalCalculator* iP, VIPRCalculator* fIPRCalculator ); ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 }; #endif From 49f7939fc41bd3628c5e3d8505158dd4f5d60db6 Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Tue, 18 Apr 2023 10:21:48 +0200 Subject: [PATCH 07/17] Add changes by GM --- inc/VPedestalCalculator.h | 6 ---- src/VCalibrator.cpp | 66 +++---------------------------------- src/VPedestalCalculator.cpp | 21 ------------ 3 files changed, 4 insertions(+), 89 deletions(-) diff --git a/inc/VPedestalCalculator.h b/inc/VPedestalCalculator.h index d3898b6a1..78aca8dc2 100644 --- a/inc/VPedestalCalculator.h +++ b/inc/VPedestalCalculator.h @@ -48,10 +48,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer vector< vector< vector< float > > > fpedcal_mean; vector< vector< vector< float > > > fpedcal_mean2; vector< vector< vector< TH1F* > > > fpedcal_histo; -<<<<<<< HEAD -======= std::vector > copy_fpedcal_histo; ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 vector< vector< float > > v_temp_pedEntries; vector< vector< float > > v_temp_ped; @@ -79,19 +76,16 @@ class VPedestalCalculator : public VImageBaseAnalyzer vector< vector< vector< vector< float > > > > v_ped_median; vector< vector< vector< vector< float > > > > v_pedvar68; -<<<<<<< HEAD VPedestalCalculator(); ~VPedestalCalculator() {} void doAnalysis( bool iLowGain = false ); -======= vector< vector< vector< TH1F* > > > fpedcal_histo_sw; VPedestalCalculator(); ~VPedestalCalculator() {} void doAnalysis( bool iLowGain = false , VIPRCalculator* fIPRCalculator = 0 ); ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 vector< TTree* > getPedestalTree() { return fTree; diff --git a/src/VCalibrator.cpp b/src/VCalibrator.cpp index 9323e03c2..bcd71df02 100644 --- a/src/VCalibrator.cpp +++ b/src/VCalibrator.cpp @@ -359,13 +359,9 @@ void VCalibrator::calculatePedestals( bool iLowGain ) this might be an ascii file and/or a root file */ -<<<<<<< HEAD //MK test void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile ) //void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile, VIPRCalculator *fIPRCalculator ) -======= -void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile, VIPRCalculator* fIPRCalculator ) ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 { if( getDebugFlag() ) { @@ -513,24 +509,6 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul } } } -<<<<<<< HEAD -======= - for( unsigned int ts = 0; ts < ( fIPRCalculator->getStorageHist() )[tel].size(); ts++ ) - { - for( unsigned int p = 0; p < getNChannels(); p++ ) - { - for( unsigned int sw = 0; sw < ( fIPRCalculator->getStorageHist() )[tel][ts][p].size(); sw++ ) - { - if( fIPRCalculator->getIPRPedestalHisto( tel, ts, p, sw ) ) - { - fIPRCalculator->getIPRPedestalHisto( tel, ts, p, sw )->SetName( Form( "hped_Tel%d_TS%d_Pix%d_SW%d", ( int )telType, ts, p, sw ) ); - fIPRCalculator->getIPRPedestalHisto( tel, ts, p, sw )->SetTitle( Form( "hped_Tel%d_TS%d_Pix%d_SW%d", ( int )telType, ts, p, sw ) ); - fIPRCalculator->getIPRPedestalHisto( tel, ts, p, sw )->Write(); - } - } - } - } ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 } iFileWritten[telType] = true; } @@ -574,9 +552,9 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul && getRunParameter()->fPedestalSingleRootFile ) { // write one IPR graph per telescope type and summation window - + cout << "Calculating IPR graphs " << endl; - + // keep track of telescope type map< ULong64_t, bool > iTelDone; for( unsigned int i = 0; i < getDetectorGeometry()->getTelType_list().size(); i++ ) @@ -586,9 +564,9 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul for( unsigned int i = 0; i < fNTel; i++ ) { setTelID( i ); - + ULong64_t iTelType = getTelType( i ); - + if( !iTelDone[iTelType] ) { if( iTelType >= hped_vec.size() ) @@ -1612,14 +1590,9 @@ void VCalibrator::writeTOffsets( bool iLowGain ) } } -<<<<<<< HEAD //MK test //void VCalibrator::terminate( VPedestalCalculator* iP, VIPRCalculator *fIPRCalculator ) void VCalibrator::terminate( VPedestalCalculator* iP ) -======= - -void VCalibrator::terminate( VPedestalCalculator* iP, VIPRCalculator* fIPRCalculator ) ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 { if( fRunPar->frunmode == 1 || fRunPar->frunmode == 6 ) { @@ -1670,13 +1643,6 @@ void VCalibrator::readCalibrationData() getGains( true ) = getGains( false ); } } -<<<<<<< HEAD -======= - else - { - - } ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 // read average tzeros if( getRunParameter()->frunmode != 2 && getRunParameter()->frunmode != 5 @@ -3128,13 +3094,8 @@ void VCalibrator::readTOffsets( bool iLowGain ) } -<<<<<<< HEAD //MK test void VCalibrator::initialize(VIPRCalculator *fIPRCalculator ) -======= - -void VCalibrator::initialize( VIPRCalculator* fIPRCalculator ) ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 { if( fDebug ) { @@ -3244,12 +3205,6 @@ void VCalibrator::initialize( VIPRCalculator* fIPRCalculator ) { readCalibrationData(); } -<<<<<<< HEAD -======= - else - { - } ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 } // PE mode: set gains to 1 else @@ -3270,13 +3225,9 @@ void VCalibrator::initialize( VIPRCalculator* fIPRCalculator ) // if needed: write IPR graphs to disk if( getRunParameter()->ifCreateIPRdatabase == true && getRunParameter()->ifReadIPRfromDatabase == false ) { -<<<<<<< HEAD //MK test //fIPRCalculator->writeIPRgraphs( hped_vec, ""); writeIPRgraphs(); -======= - fIPRCalculator->writeIPRgraphs( hped_vec, "" ); ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 } // initialize dead channel finder @@ -3292,15 +3243,10 @@ void VCalibrator::initialize( VIPRCalculator* fIPRCalculator ) && fRunPar->frunmode != 1 && fRunPar->frunmode != 6 ) { -<<<<<<< HEAD cout << "MK calculating IPR graphs"<< endl; //calculateIPRGraphs(); fIPRCalculator->calculateIPRGraphs(fPedFileNameC); //calculateIPRGraphs(); -======= - cout << "MK calculating IPR graphs" << endl; - fIPRCalculator->calculateIPRGraphs( fPedFileNameC ); ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 } } } @@ -4439,7 +4385,6 @@ bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) //////////////////////////////////////////////////////////////////////////// // read IPR graph from dst root file (for direct usage or creation of database ) -<<<<<<< HEAD if( getRunParameter()->ifReadIPRfromDSTFile == true ) { cout << "\t reading IPR graphs for NN image cleaning from DST file" << endl; @@ -4450,9 +4395,6 @@ bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) } } else if( getRunParameter()->ifReadIPRfromDatabase == true || getRunParameter()->ifCreateIPRdatabase == true ) -======= - if( getRunParameter()->ifReadIPRfromDatabase == true || getRunParameter()->ifCreateIPRdatabase == true ) ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 { cout << "\t reading IPR graphs for NN image cleaning" << endl; for( int i = 0; i < t->GetEntries(); i++ ) diff --git a/src/VPedestalCalculator.cpp b/src/VPedestalCalculator.cpp index 0bb831965..7a04e99e5 100644 --- a/src/VPedestalCalculator.cpp +++ b/src/VPedestalCalculator.cpp @@ -184,10 +184,6 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe fpedcal_mean.push_back( iped_cal2 ); fpedcal_mean2.push_back( iped_cal2 ); fpedcal_histo.push_back( iped_histo2 ); -<<<<<<< HEAD -======= - fpedcal_histo_sw.push_back( iped_histo2 ); ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 // define the time vector fTimeVec.push_back( 0 ); @@ -282,11 +278,7 @@ void VPedestalCalculator::fillTimeSlice( unsigned int telID ) } -<<<<<<< HEAD void VPedestalCalculator::doAnalysis( bool iLowGain ) -======= -void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator* fIPRCalculator ) ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 { double t = getEventTime(); // get right index for tel id @@ -313,20 +305,7 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator* fIPRCalcula else if( t - fTimeVec[telID] > fLengthofTimeSlice ) { time = t; -<<<<<<< HEAD fillTimeSlice( telID ); -======= - if( NTimeSlices[telID] == 0 and telID == 0 ) - { - fIPRCalculator->fillIPRPedestalHisto(); - } - - NTimeSlices[telID] += 1; - - fIPRCalculator->fillIPRPedestalHisto( telID, fpedcal_histo ); - fillTimeSlice( telID ); - ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 fTimeVec[telID] = t; } // if( t - fTimeVec[telID] > fLengthofTimeSlice ) /////////////////////////////////////////////////////// From d8316a71697969d3a98f4b45cf6d5b7de54fc074 Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Tue, 18 Apr 2023 10:22:47 +0200 Subject: [PATCH 08/17] remove some comments --- src/VEventLoop.cpp | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/src/VEventLoop.cpp b/src/VEventLoop.cpp index ea52e303b..cc495d58a 100644 --- a/src/VEventLoop.cpp +++ b/src/VEventLoop.cpp @@ -135,12 +135,6 @@ VEventLoop::VEventLoop( VEvndispRunParameter* irunparameter ) // reset cut strings and variables resetRunOptions(); -<<<<<<< HEAD -======= - - //add if statement: if ipr should be in time slices - fIPRTimeSlices = true; ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 } @@ -482,7 +476,6 @@ bool VEventLoop::initEventLoop( string iFileName ) // initialize analyzers (output files are created as well here) initializeAnalyzers(); -<<<<<<< HEAD if( fIPRCalculator ){ cout << "initializing IPR calculator" << endl; fIPRCalculator->initialize(); @@ -491,19 +484,6 @@ bool VEventLoop::initEventLoop( string iFileName ) if( fCalibrator ) { fCalibrator->initialize(fIPRCalculator ); -======= - - if( fIPRCalculator ) - { - cout << "initializing IPR calculator" << endl; - fIPRCalculator->initialize(); - } - - // create calibrators, analyzers, etc. at first event - if( fCalibrator ) - { - fCalibrator->initialize( fIPRCalculator ); ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 } // initialize pedestal calculator @@ -845,11 +825,7 @@ void VEventLoop::shutdown() } if( fCalibrator ) { -<<<<<<< HEAD fCalibrator->terminate( iP ); -======= - fCalibrator->terminate( iP , fIPRCalculator ); ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 } } // write data summary @@ -1042,24 +1018,6 @@ bool VEventLoop::nextEvent() else { cout << "!!! void VEventLoop::nextEvent(): no next event (end of file)" << endl; -<<<<<<< HEAD -======= - for( unsigned int tel = 0; tel < fIPRCalculator->getStorageHist().size(); tel++ ) - { - for( unsigned int ts = 0; ts < fIPRCalculator->getStorageHist()[tel].size(); ts++ ) - { - for( unsigned int p = 0; p < fIPRCalculator->getStorageHist()[tel][ts].size(); p++ ) - { - for( unsigned int sw = 0; sw < fIPRCalculator->getStorageHist()[tel][ts][p].size(); sw++ ) - { - fIPRCalculator->checkHistEmpty( tel, ts, p, sw ); - } - } - } - } - - ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 // if the display is run in the loop mode, goto event 0 and start again if( fRunPar->floopmode ) { @@ -1168,10 +1126,6 @@ int VEventLoop::analyzeEvent() cout << "\t now at event " << getEventNumber() << endl; cout << "----------------------------------------" << endl; } -<<<<<<< HEAD -======= - ->>>>>>> d875f786fff9a004b915438d724c168de7974e22 // analysis is running fAnalyzeMode = true; int i_cut = 0; From c748ebb20ae39ad6b9447edd96d0e99c6afdedf6 Mon Sep 17 00:00:00 2001 From: Maria Kherlakian <75071101+m-kherlakian@users.noreply.github.com> Date: Tue, 18 Apr 2023 10:34:26 +0200 Subject: [PATCH 09/17] Delete VIPRCalculator.h.bsk --- inc/VIPRCalculator.h.bsk | 62 ---------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 inc/VIPRCalculator.h.bsk diff --git a/inc/VIPRCalculator.h.bsk b/inc/VIPRCalculator.h.bsk deleted file mode 100644 index b2a59e4fc..000000000 --- a/inc/VIPRCalculator.h.bsk +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef VIPRCALCULATOR_H -#define VIPRCALCULATOR_H - -#include -#include -#include - -#include "TClonesArray.h" -#include "TFile.h" -#include "TH1F.h" -#include "TLeaf.h" -#include "TMath.h" -#include "TProfile.h" -#include "TSystem.h" -#include "TTree.h" - -#include -#include -#include -#include -#include - -using namespace std; - -class VIPRCalculator : public VImageBaseAnalyzer -{ - - private: - VEvndispData* fData; - vector< string > fPedFile; - bool fIPRTimeSlices; - bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs - bool fIPRInTimeSlices; - int fPedPerTelescopeTypeMinCnt; - TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); - TGraphErrors* updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow); - float convertRate(unsigned int i_tel); - float getTsearch(); - void definePedestalFile( std::vector fPedFileNameC ); - TFile* initializePedestalFile( int i_tel ); - TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); - bool calculateIPRGraphsTimeSlices( const int TimeSlice, int iSummationWindow, const int itel); - bool calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); - bool copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ); - TH1F* calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); - public: - void clearHistos(); - vector>>> fpedcal_histo_storage; - TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); - vector>>> getStorageHist(); - void fillIPRPedestalHisto(); - void fillIPRPedestalHisto(const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ); - bool calculateIPRGraphs( std::vector fPedFileNameC); - bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); - void checkHistEmpty(const int telID, const int ts, const int pixel, const int sw); - - VIPRCalculator(); - ~VIPRCalculator() {} - - void initialize(); -}; -#endif From cbe215eb68df257a24efc678e85dfebc490703cc Mon Sep 17 00:00:00 2001 From: Maria Kherlakian <75071101+m-kherlakian@users.noreply.github.com> Date: Tue, 18 Apr 2023 10:35:47 +0200 Subject: [PATCH 10/17] Update VIPRCalculator.h --- inc/VIPRCalculator.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/VIPRCalculator.h b/inc/VIPRCalculator.h index 732ce9b31..b367a5894 100644 --- a/inc/VIPRCalculator.h +++ b/inc/VIPRCalculator.h @@ -1,9 +1,9 @@ #ifndef VIPRCALCULATOR_H #define VIPRCALCULATOR_H -#include -#include -#include +#include "VImageBaseAnalyzer.h" +#include "VDB_CalibrationInfo.h" +#include "VSQLTextFileReader.h" #include "TClonesArray.h" #include "TFile.h" From f6c172643c80df318c1884c1821d62e82349b0f7 Mon Sep 17 00:00:00 2001 From: Maria Kherlakian <75071101+m-kherlakian@users.noreply.github.com> Date: Tue, 18 Apr 2023 10:36:19 +0200 Subject: [PATCH 11/17] Update VCalibrator.h --- inc/VCalibrator.h | 1 - 1 file changed, 1 deletion(-) diff --git a/inc/VCalibrator.h b/inc/VCalibrator.h index 015d2e4cc..6b5fbd95c 100644 --- a/inc/VCalibrator.h +++ b/inc/VCalibrator.h @@ -7,7 +7,6 @@ #include "VPedestalCalculator.h" #include "VIPRCalculator.h" #include "VDB_CalibrationInfo.h" -#include #include "VIPRCalculator.h" #include "VPedestalCalculator.h" #include "VDB_CalibrationInfo.h" From 7da500798795d16b895cb5b1474602932866a8ba Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Wed, 19 Apr 2023 23:43:35 +0200 Subject: [PATCH 12/17] backup progress --- inc/VCalibrationData.h | 3 +- inc/VCalibrator.h | 12 +- inc/VEventLoop.h | 3 + inc/VEvndispData.h | 8 + inc/VIPRCalculator.h | 73 +++ inc/VIPRCalculator.h.bsk | 62 ++ inc/VPedestalCalculator.h | 10 +- src/VCalibrationData.cpp | 19 + src/VCalibrator.cpp | 28 +- src/VEventLoop.cpp | 9 +- src/VIPRCalculator.cpp | 1085 +++++++++++++++++++++++++++++++++++ src/VIPRCalculator.cpp.bak | 830 +++++++++++++++++++++++++++ src/VPedestalCalculator.cpp | 1 + 13 files changed, 2133 insertions(+), 10 deletions(-) create mode 100644 inc/VIPRCalculator.h create mode 100644 inc/VIPRCalculator.h.bsk create mode 100644 src/VIPRCalculator.cpp create mode 100644 src/VIPRCalculator.cpp.bak diff --git a/inc/VCalibrationData.h b/inc/VCalibrationData.h index e7917d3a2..718b66b73 100644 --- a/inc/VCalibrationData.h +++ b/inc/VCalibrationData.h @@ -143,7 +143,7 @@ class VCalibrationData // IPR graphs map< unsigned int, TGraphErrors* > fGraphIPRGraph; // one IPR graph per summation window - + map< unsigned int, TGraphErrors* > fGraphTSIPRGraph; // one IPR graph per time slice VCalibrationData( unsigned int iTel, string iDir, string iPedfile, string iGainfile, string iTofffile, string iPedLowGainfile, string iGainLowGainFile = "", string iToffLowGainFile = "", string iLowGainMultFile = "", @@ -237,6 +237,7 @@ class VCalibrationData } } TGraphErrors* getIPRGraph( unsigned int iSumWindow, bool iMakeNewGraph = false ); + TGraphErrors* getIPRGraphTimeSlice( bool iMakeNewGraph = false, unsigned int TimeSlice = 0 ); TH1F* getLowGainMultiplierDistribution() { return getHistoDist( C_LOWGAIN, true ); diff --git a/inc/VCalibrator.h b/inc/VCalibrator.h index 0ed738ef2..015d2e4cc 100644 --- a/inc/VCalibrator.h +++ b/inc/VCalibrator.h @@ -5,6 +5,11 @@ #include "VImageBaseAnalyzer.h" #include "VPedestalCalculator.h" +#include "VIPRCalculator.h" +#include "VDB_CalibrationInfo.h" +#include +#include "VIPRCalculator.h" +#include "VPedestalCalculator.h" #include "VDB_CalibrationInfo.h" #include "VSQLTextFileReader.h" @@ -109,6 +114,7 @@ class VCalibrator : public VImageBaseAnalyzer bool copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); TH1F* initializeIPRAveraged( unsigned int iSummationWindow, unsigned int iTelType ); TH1F* calculateIPRGraphAveraged( unsigned int iSummationWindow ); + bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool readLowGainMultiplier( ); bool readPeds( string iFile, bool, unsigned int ); bool readPeds_from_grisufile( bool, unsigned int ); @@ -122,6 +128,7 @@ class VCalibrator : public VImageBaseAnalyzer void writeGains( bool iLowGain = false ); void writePeds( bool iLowGain, VPedestalCalculator* iP = 0, bool iWriteAsciiFile = true ); + void writePeds( bool iLowGain, VPedestalCalculator* iP = 0, bool iWriteAsciiFile = true, VIPRCalculator* fIPRCalculator = 0 ); void writeTOffsets( bool iLowGain = false ); void writeAverageTZeros( bool iLowGain = false ); bool writeIPRgraphs( string iFile = "" ); @@ -135,7 +142,10 @@ class VCalibrator : public VImageBaseAnalyzer void calculatePedestals( bool iLowGain = false ); void calculateGainsAndTOffsets( bool iLowGain = false ); unsigned int getNumberOfEventsUsedInCalibration( int iTelID, int iType ); - void initialize(); + void initialize(VIPRCalculator *fIPRCalculator ); void terminate( VPedestalCalculator* ); + //void calculateIPRGraphs(VIPRCalculator *fIPRCalculator = 0, VPedestalCalculator *iP = 0); + void initialize( VIPRCalculator* fIPRCalculator ); + void terminate( VPedestalCalculator* iP, VIPRCalculator* fIPRCalculator ); }; #endif diff --git a/inc/VEventLoop.h b/inc/VEventLoop.h index e8562e014..168cbdcdb 100644 --- a/inc/VEventLoop.h +++ b/inc/VEventLoop.h @@ -21,6 +21,7 @@ #include "VBFDataReader.h" #endif #include "VPedestalCalculator.h" +#include "VIPRCalculator.h" #include "VEvndispRunParameter.h" #include "VDeadPixelOrganizer.h" @@ -40,6 +41,7 @@ class VEventLoop : public VEvndispData enum E_runmode {R_ANA, R_PED, R_GTO, R_BCK, R_DST, R_GTOLOW, R_PEDLOW, R_TZERO, R_TZEROLOW }; VCalibrator* fCalibrator; //!< default calibration class + VIPRCalculator* fIPRCalculator; VPedestalCalculator* fPedestalCalculator; //!< default pedestal calculator VImageAnalyzer* fAnalyzer; //!< default analyzer class VArrayAnalyzer* fArrayAnalyzer; //!< default array analyzer @@ -55,6 +57,7 @@ class VEventLoop : public VEvndispData bool fAnalyzeMode; //!< used for gotoEvent (go through file without analyse events) bool bMCSetAtmosphericID; vector< bool > fBoolPrintSample; + bool fIPRTimeSlices; bool fCutTelescope; //!< cuts apply only to one telescope int fNCutNArrayTrigger; //!< show only events with more than fNCutNArrayTrigger triggered telescopes diff --git a/inc/VEvndispData.h b/inc/VEvndispData.h index be1574d03..31b841ea8 100644 --- a/inc/VEvndispData.h +++ b/inc/VEvndispData.h @@ -523,6 +523,14 @@ class VEvndispData { return fCalData[fTelID]->getIPRGraph( iSumWindow, iMakeNewGraph ); } + TGraphErrors* getIPRGraphTimeSlice( unsigned int TimeSlice = 0 ) + { + return fCalData[fTelID]->getIPRGraphTimeSlice( false, TimeSlice ); + } + TGraphErrors* getIPRGraphTimeSlice( bool iMakeNewGraph = false, unsigned int TimeSlice = 0 ) + { + return fCalData[fTelID]->getIPRGraphTimeSlice( iMakeNewGraph, TimeSlice ); + } float getL1Rate( unsigned int iChannel ) { if( fDB_PixelDataReader ) diff --git a/inc/VIPRCalculator.h b/inc/VIPRCalculator.h new file mode 100644 index 000000000..732ce9b31 --- /dev/null +++ b/inc/VIPRCalculator.h @@ -0,0 +1,73 @@ +#ifndef VIPRCALCULATOR_H +#define VIPRCALCULATOR_H + +#include +#include +#include + +#include "TClonesArray.h" +#include "TFile.h" +#include "TH1F.h" +#include "TLeaf.h" +#include "TMath.h" +#include "TProfile.h" +#include "TSystem.h" +#include "TTree.h" + +#include +#include +#include +#include +#include + +using namespace std; + +class VIPRCalculator : public VImageBaseAnalyzer +{ + + private: + VEvndispData* fData; + vector< string > fPedFileNameC; + bool fIPRTimeSlices; + bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs + bool fIPRInTimeSlices; + int fPedPerTelescopeTypeMinCnt; +<<<<<<< HEAD + TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + void definePedestalFile( std::vector fPedFileNameCalibrator ); + TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + bool copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); + TH1F* calculateIPRGraphAveraged( unsigned int iSummationWindow ); + public: + bool calculateIPRGraphs( std::vector fPedFileNameCalibrator ); + bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); + bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); + +======= + TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); + TGraphErrors* updateIPRGraph( TH1F* hIPR, unsigned int i_tel, int iSummationWindow ); + float convertRate( unsigned int i_tel ); + float getTsearch(); + void definePedestalFile( std::vector fPedFileNameC ); + TFile* initializePedestalFile( int i_tel ); + TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); + bool calculateIPRGraphsTimeSlices( const int TimeSlice, int iSummationWindow, const int itel ); + bool calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); + bool copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ); + TH1F* calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); + public: + + vector>>> fpedcal_histo_storage; + TH1F* getIPRPedestalHisto( const int telID, const int ts, const int pixel, const int sw ); + vector>>> getStorageHist(); + void fillIPRPedestalHisto(); + void fillIPRPedestalHisto( const int telID, const vector>>& fpedcal_histo ); + bool calculateIPRGraphs( std::vector fPedFileNameC ); + bool writeIPRgraphs( map>>& hped_vec, string iFile = "" ); + void checkHistEmpty( const int telID, const int ts, const int pixel, const int sw ); + VIPRCalculator(); + ~VIPRCalculator() {} + + void initialize(); +}; +#endif diff --git a/inc/VIPRCalculator.h.bsk b/inc/VIPRCalculator.h.bsk new file mode 100644 index 000000000..b2a59e4fc --- /dev/null +++ b/inc/VIPRCalculator.h.bsk @@ -0,0 +1,62 @@ +#ifndef VIPRCALCULATOR_H +#define VIPRCALCULATOR_H + +#include +#include +#include + +#include "TClonesArray.h" +#include "TFile.h" +#include "TH1F.h" +#include "TLeaf.h" +#include "TMath.h" +#include "TProfile.h" +#include "TSystem.h" +#include "TTree.h" + +#include +#include +#include +#include +#include + +using namespace std; + +class VIPRCalculator : public VImageBaseAnalyzer +{ + + private: + VEvndispData* fData; + vector< string > fPedFile; + bool fIPRTimeSlices; + bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs + bool fIPRInTimeSlices; + int fPedPerTelescopeTypeMinCnt; + TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + TGraphErrors* updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow); + float convertRate(unsigned int i_tel); + float getTsearch(); + void definePedestalFile( std::vector fPedFileNameC ); + TFile* initializePedestalFile( int i_tel ); + TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + bool calculateIPRGraphsTimeSlices( const int TimeSlice, int iSummationWindow, const int itel); + bool calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); + bool copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ); + TH1F* calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); + public: + void clearHistos(); + vector>>> fpedcal_histo_storage; + TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); + vector>>> getStorageHist(); + void fillIPRPedestalHisto(); + void fillIPRPedestalHisto(const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ); + bool calculateIPRGraphs( std::vector fPedFileNameC); + bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); + void checkHistEmpty(const int telID, const int ts, const int pixel, const int sw); + + VIPRCalculator(); + ~VIPRCalculator() {} + + void initialize(); +}; +#endif diff --git a/inc/VPedestalCalculator.h b/inc/VPedestalCalculator.h index 5bf71b24b..78aca8dc2 100644 --- a/inc/VPedestalCalculator.h +++ b/inc/VPedestalCalculator.h @@ -6,6 +6,7 @@ #include "VImageBaseAnalyzer.h" #include "VGlobalRunParameter.h" #include "VSkyCoordinatesUtilities.h" +#include "VIPRCalculator.h" #include "TDirectory.h" #include "TFile.h" @@ -47,6 +48,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer vector< vector< vector< float > > > fpedcal_mean; vector< vector< vector< float > > > fpedcal_mean2; vector< vector< vector< TH1F* > > > fpedcal_histo; + std::vector > copy_fpedcal_histo; vector< vector< float > > v_temp_pedEntries; vector< vector< float > > v_temp_ped; @@ -62,7 +64,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer void reset(); public: - + vector< int > NTimeSlices; vector< vector< int > > v_MJD; //! [telid][time slice] vector< vector< double > > v_time; //! [telid][time slice] //! [telid][time slice][npixel][summation window] @@ -78,6 +80,12 @@ class VPedestalCalculator : public VImageBaseAnalyzer ~VPedestalCalculator() {} void doAnalysis( bool iLowGain = false ); + vector< vector< vector< TH1F* > > > fpedcal_histo_sw; + + VPedestalCalculator(); + ~VPedestalCalculator() {} + + void doAnalysis( bool iLowGain = false , VIPRCalculator* fIPRCalculator = 0 ); vector< TTree* > getPedestalTree() { return fTree; diff --git a/src/VCalibrationData.cpp b/src/VCalibrationData.cpp index 5f7d7ee5c..1badb4c2c 100644 --- a/src/VCalibrationData.cpp +++ b/src/VCalibrationData.cpp @@ -1043,6 +1043,25 @@ TGraphErrors* VCalibrationData::getIPRGraph( unsigned int iSumWindow, bool iMake return 0; } +TGraphErrors* VCalibrationData::getIPRGraphTimeSlice( bool iMakeNewGraph, unsigned int TimeSlice ) +{ + + if( fGraphTSIPRGraph.find( TimeSlice ) != fGraphTSIPRGraph.end() && fGraphTSIPRGraph[TimeSlice] ) + { + return fGraphTSIPRGraph[TimeSlice]; + } + else if( iMakeNewGraph ) + { + fGraphTSIPRGraph[TimeSlice] = new TGraphErrors( 1 ); + fGraphTSIPRGraph[TimeSlice]->SetTitle( "" ); + char hname[200]; + sprintf( hname, "IRPFGraph_TelID%d_TimeSlice%d", fTelID, TimeSlice ); + fGraphTSIPRGraph[TimeSlice]->SetName( hname ); + return fGraphTSIPRGraph[TimeSlice]; + } + return 0; +} + void VCalibrationData::setIPRGraph( unsigned int iSumWindow, TGraphErrors* g ) { fGraphIPRGraph[iSumWindow] = g; diff --git a/src/VCalibrator.cpp b/src/VCalibrator.cpp index fcda4786a..bcd71df02 100644 --- a/src/VCalibrator.cpp +++ b/src/VCalibrator.cpp @@ -359,7 +359,9 @@ void VCalibrator::calculatePedestals( bool iLowGain ) this might be an ascii file and/or a root file */ +//MK test void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile ) +//void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalculator, bool iWriteAsciiFile, VIPRCalculator *fIPRCalculator ) { if( getDebugFlag() ) { @@ -1588,12 +1590,14 @@ void VCalibrator::writeTOffsets( bool iLowGain ) } } - +//MK test +//void VCalibrator::terminate( VPedestalCalculator* iP, VIPRCalculator *fIPRCalculator ) void VCalibrator::terminate( VPedestalCalculator* iP ) { if( fRunPar->frunmode == 1 || fRunPar->frunmode == 6 ) { writePeds( fRunPar->frunmode == 6, iP, !fRunPar->fPedestalSingleRootFile ); + //writePeds( fRunPar->frunmode == 6, iP, !fRunPar->fPedestalSingleRootFile, fIPRCalculator ); } else if( fRunPar->frunmode == 2 || fRunPar->frunmode == 5 ) { @@ -3090,8 +3094,8 @@ void VCalibrator::readTOffsets( bool iLowGain ) } - -void VCalibrator::initialize() +//MK test +void VCalibrator::initialize(VIPRCalculator *fIPRCalculator ) { if( fDebug ) { @@ -3221,6 +3225,8 @@ void VCalibrator::initialize() // if needed: write IPR graphs to disk if( getRunParameter()->ifCreateIPRdatabase == true && getRunParameter()->ifReadIPRfromDatabase == false ) { + //MK test + //fIPRCalculator->writeIPRgraphs( hped_vec, ""); writeIPRgraphs(); } @@ -3237,7 +3243,10 @@ void VCalibrator::initialize() && fRunPar->frunmode != 1 && fRunPar->frunmode != 6 ) { - calculateIPRGraphs(); + cout << "MK calculating IPR graphs"<< endl; + //calculateIPRGraphs(); + fIPRCalculator->calculateIPRGraphs(fPedFileNameC); + //calculateIPRGraphs(); } } } @@ -4376,7 +4385,16 @@ bool VCalibrator::readCalibrationDatafromDSTFiles( string iDSTfile ) //////////////////////////////////////////////////////////////////////////// // read IPR graph from dst root file (for direct usage or creation of database ) - if( getRunParameter()->ifReadIPRfromDatabase == true || getRunParameter()->ifCreateIPRdatabase == true ) + if( getRunParameter()->ifReadIPRfromDSTFile == true ) + { + cout << "\t reading IPR graphs for NN image cleaning from DST file" << endl; + for( int i = 0; i < t->GetEntries(); i++ ) + { + setTelID( i ); + readIPRGraph_from_DSTFile( iDSTfile, getSumWindow(), getTelType( i ) ); + } + } + else if( getRunParameter()->ifReadIPRfromDatabase == true || getRunParameter()->ifCreateIPRdatabase == true ) { cout << "\t reading IPR graphs for NN image cleaning" << endl; for( int i = 0; i < t->GetEntries(); i++ ) diff --git a/src/VEventLoop.cpp b/src/VEventLoop.cpp index 0931cb181..cc495d58a 100644 --- a/src/VEventLoop.cpp +++ b/src/VEventLoop.cpp @@ -101,6 +101,7 @@ VEventLoop::VEventLoop( VEvndispRunParameter* irunparameter ) fCalibrated.push_back( false ); } fCalibrator = new VCalibrator(); + fIPRCalculator = new VIPRCalculator(); // create data summarizer fDST = new VDST( ( fRunMode == R_DST ), ( fRunPar->fsourcetype == 1 || fRunPar->fsourcetype == 2 || fRunPar->fsourcetype == 6 ) ); @@ -475,11 +476,14 @@ bool VEventLoop::initEventLoop( string iFileName ) // initialize analyzers (output files are created as well here) initializeAnalyzers(); - + if( fIPRCalculator ){ + cout << "initializing IPR calculator" << endl; + fIPRCalculator->initialize(); + } // create calibrators, analyzers, etc. at first event if( fCalibrator ) { - fCalibrator->initialize(); + fCalibrator->initialize(fIPRCalculator ); } // initialize pedestal calculator @@ -1292,6 +1296,7 @@ int VEventLoop::analyzeEvent() // analysis case R_ANA: // analysis mode // ignore pedestal events (important for VBF only) + cout << getEventNumber() << endl; #ifndef NOVBF if( fReader->getATEventType() != VEventType::PED_TRIGGER ) #endif diff --git a/src/VIPRCalculator.cpp b/src/VIPRCalculator.cpp new file mode 100644 index 000000000..b28a1932f --- /dev/null +++ b/src/VIPRCalculator.cpp @@ -0,0 +1,1085 @@ +/*! \class IPRCalculator + * \brief calculation and save IPR GRAPH + * + * */ + +#include "VIPRCalculator.h" + +VIPRCalculator::VIPRCalculator() +{ + fIPRTimeSlices = true; + fIPRAverageTel = false; + fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements +} + +void VIPRCalculator::initialize() +{ + if( fDebug ) + { + cout << "VIPRCalculator::initialize()" << endl; + } + + // set the data readers + initializeDataReader(); + if( !initializeDataReader() ) + { + cout << "VIPRCalculator::initialize, error: cannot initialize data readers" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + +} + +void VIPRCalculator::definePedestalFile( std::vector fPedFileNameC ) +{ + fPedFile = fPedFileNameC; +} + + +TFile* VIPRCalculator::initializePedestalFile( int i_tel ) +{ + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return nullptr; + } + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << getTelType( getTeltoAna()[i_tel] ) << ": "; + cout << "reading IPR histograms for summation window " << getSumWindow(); + cout << " from "; + cout << iPedFileName << endl; + return iPedFile; + +} + +float VIPRCalculator::getTsearch() +{ + float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); + if( getSearchWindowLast() < getNSamples() ) + { + Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] + } + else + { + Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] + } + return Tsearch; +} + +float VIPRCalculator::convertRate( unsigned int i_tel ) +{ + // convert to Rate + float nsToSec = 1E-9; + float convToHz = 1.; + if( nsToSec > 0. && getTsearch() > 0. ) + { + convToHz /= ( nsToSec * getTsearch() ); + } + else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) + { + // simple peak sensing: sim_telarray uses the maximum bin only + // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file + // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as + // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns + // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. + convToHz /= ( nsToSec + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); + } + return convToHz; + +} + + +/* + HANDLING OF IPR FOR NO TIME SLICE CASE + +*/ + +TH1F* VIPRCalculator::initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + //get reference hpedPerTelescopeType for channel 1 + cout << "VIPRCalculator::initializeIPRHistogram initializing IPR graph for calculation of average of telescopes." << endl; + TH1F* hIPR = 0; + + TFile* iPedFile = ( TFile* )initializePedestalFile( i_tel ); + if( iPedFile == nullptr ) + { + return hIPR; + } + + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + //cout << "VIPRCalculator::initializeIPRHistogram Telescope type:" << iTelType << endl; + //cout << "reading IPR histograms for summation window " << iSummationWindow; + + stringstream Directory( stringstream::in | stringstream::out ); + Directory << "distributions_" << iTelType; + if( !iPedFile->Get( Directory.str().c_str() ) ) + { + return hIPR; + } + + // get charge distribution for first channel as reference fpedcal_histo_storagegram + stringstream hIPRname( stringstream::in | stringstream::out ); + hIPRname << "distributions_" << iTelType << "/hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << 1; + + //? + TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); + iPedFile->Close(); + + if( !href ) + { + cout << " Error: cannot find IPR histogram" << hIPRname.str().c_str(); + return hIPR; + } + //summary fpedcal_histo_storagegram + if( getRunParameter()->fIgnoreDSTGains ) + { + // work in dc + hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); + cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; + return hIPR; + } + else + { + // work in pe + hIPR = new TH1F( "", "", 1000, 0., 100. ); + return hIPR; + } +} + +TH1F* VIPRCalculator::FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, i_tel ); + // check suffix of ped file + TFile* iPedFile = ( TFile* )initializePedestalFile( i_tel ); + + stringstream i_Directory( stringstream::in | stringstream::out ); + i_Directory << "distributions_" << iTelType; + if( iPedFile->Get( i_Directory.str().c_str() ) ) + { + iPedFile->cd( i_Directory.str().c_str() ); + } + + float i_gainCorrect = 1.; + //hIPR->Reset(); + // //float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + iPedFile->Close(); + return hIPR; +} + +/* +IN CASE IPR IS GIVEN AS AVERAGE OF TELESCOPES, FOR TEL > 0 COPY IPR CALCULATED FOR TEL = 0. +*/ + +bool VIPRCalculator::copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[0] ); + TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[i_tel] ); + + if( !i_IPRGraph ) + { + cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << iTelType << endl; + return false; + } + if( !i_IPRGraph_Tel0 ) + { + cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; + return false; + } + + for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) + { + i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); + } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); + i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); + i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", iTelType, iSummationWindow ) ); + + return true; +} + +void VIPRCalculator::definePedestalFile( std::vector fPedFileNameCalibrator ) +{ + for( unsigned int i = 0; i < fPedFileNameCalibrator.size() ; i++) + { + fPedFileNameC.push_back(fPedFileNameCalibrator[i]); + } +} + +bool VIPRCalculator::calculateIPRGraphs(std::vector fPedFileNameCalibrator ) +{ + + definePedestalFile(fPedFileNameCalibrator); + for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) +======= + + TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow , 0 ); + int iTelType = getTelType( getTeltoAna()[i_tel] ); + + for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) + { + setTelID( getTeltoAna()[teltype] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + TFile* iPedFile = ( TFile* )initializePedestalFile( teltype ); + if( iPedFile == nullptr ) + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices error reading IPR graphs from pedestal file "; + TH1F* hNull = 0; + return hNull; + } + + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices Telescope type " << iTelType << ": "; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << iTelType; + if( iPedFile->Get( Directory.str().c_str() ) ) + { + iPedFile->cd( Directory.str().c_str() ); + } + else + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices no directory: " << Directory.str().c_str() << endl; + } + + /////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream HistName( stringstream::in | stringstream::out ); + HistName << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); + + + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream Pname( stringstream::in | stringstream::out ); + Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + if( i == 0 ) + { + cout << "gain : " << getGains()[i] << endl; + } + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + iPedFile->Close(); + + } + hIPR->Scale( 1. / getTeltoAna().size() ); + float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices normalization of average IPR fpedcal_histo_storagegram " << norm; + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices WARNING: there is NOT enough statistics "; + cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; + return hIPR; + } + else + { + cout << "VIPRCalculator::calculateIPRGraphsAveragedNoTimeSlices: there is enough statistics to average over telescopes. " << endl; + return hIPR; + } +} + +TGraphErrors* VIPRCalculator::updateIPRGraph( TH1F* hIPR, unsigned int i_tel, int iSummationWindow ) +{ + + TGraphErrors* i_IPRGraph = new TGraphErrors( 1 ); + i_IPRGraph->SetTitle( "" ); + + int z = 0; + float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convertRate( i_tel ) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate( i_tel ) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )getTelType( getTeltoAna()[i_tel] ), iSummationWindow ) ); + return i_IPRGraph; +} + +bool VIPRCalculator::calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ) +{ + TDirectory* iG_CurrentDirectory = gDirectory; + + // get an IPR graph + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + if( !i_IPRGraph ) + { + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices info: no IPR graph found for telescope type " << getTelType( getTeltoAna()[i_tel] ) << endl; + return false; + } + + ////////////////////////////////////////////////// + // average over all channels in one telescope + + TH1F* hIPR = ( TH1F* )FillIPRHistogram( iSummationWindow, i_tel ); + float norm = 0; + if( hIPR ) +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + { + setTelID( getTeltoAna()[i] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + if( fIPRAverageTel == false ) + { + calculateIPRGraphs( fPedFileNameC[getTeltoAna()[i]], getSumWindow(), getTelType( getTeltoAna()[i] ), i ); + } + else + { + copyIPRTelAveraged( getSumWindow(), getTeltoAna()[i], i ); + } + } +<<<<<<< HEAD +======= + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; + hIPR = calculateIPRGraphAveragedNoTimeSlices( iSummationWindow, i_tel ); + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; + return false; + } + i_IPRGraph = ( TGraphErrors* )updateIPRGraph( hIPR, i_tel, iSummationWindow ); + hIPR->Delete(); + iG_CurrentDirectory->cd(); +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + return true; +} + +/* + * calculate IPR graphs and write them to disk + * + * (this is done per telescope type) + * + */ + +<<<<<<< HEAD +bool VIPRCalculator::copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) +{ + + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[0] ); + TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[i_tel] ); + + if( !i_IPRGraph ) +======= + HANDLE IPR CALCULATION IF ASKED FOR IN TIME SLICES + +*/ + +void VIPRCalculator::checkHistEmpty( const int telID, const int ts, const int pixel, const int sw ) +{ + if( fpedcal_histo_storage[telID][ts][pixel][sw]->GetEntries() != 0 ) +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + { + cout << "VIPRCalculator::copyIPRTelAveraged: no IPR graph found for telescope type " << iTelType << endl; + return false; + } +<<<<<<< HEAD + if( !i_IPRGraph_Tel0 ) +======= +} + +vector>>> VIPRCalculator::getStorageHist() +{ + return fpedcal_histo_storage; +} + +void VIPRCalculator::fillIPRPedestalHisto() +{ + fpedcal_histo_storage.resize( getTeltoAna().size() ); +} + +void VIPRCalculator::fillIPRPedestalHisto( const int telID, const vector>>& fpedcal_histo ) +{ + fpedcal_histo_storage[telID].push_back( fpedcal_histo[telID] ); +} + + +TH1F* VIPRCalculator::getIPRPedestalHisto( const int telID, const int ts, const int pixel, const int sw ) +{ + + if( fpedcal_histo_storage.empty() ) + { + cout << "empty" << endl; + } + if( fpedcal_histo_storage[telID][ts][pixel][sw] ) +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + { + cout << "VIPRCalculator::copyIPRTelAveraged: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; + return false; + } + + for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) + { + i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); + } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); + i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); + i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); + + return true; + +} + +<<<<<<< HEAD +bool VIPRCalculator::calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) +======= +//needs sliding window fpedcal_histo_storagegram!! +bool VIPRCalculator::calculateIPRGraphsTimeSlices( const int TimeSlice, const int iSummationWindow, const int i_tel ) +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 +{ + TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, getTeltoAna()[i_tel] ); + TDirectory* iG_CurrentDirectory = gDirectory; +<<<<<<< HEAD + + // get an IPR graph + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + if( !i_IPRGraph ) +======= + TGraphErrors* i_IPRGraph = getIPRGraphTimeSlice( true, TimeSlice ); + + TFile* iPedFile = ( TFile* )initializePedestalFile( i_tel ); + if( iPedFile == nullptr ) +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + { + cout << "VIPRCalculator::calculateIPRGraphs info: no IPR graph found for telescope type " << iTelType << endl; + return false; + } +<<<<<<< HEAD + // check suffix of ped file + if( iPedFileName.find( ".root" ) == string::npos ) +======= + + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices for Telescope type " << iTelType << ": "; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << iTelType; + if( iPedFile->Get( Directory.str().c_str() ) ) +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + { + iPedFileName += ".root"; + } + // open pedestal files + TFile iPedFile( iPedFileName.c_str() ); + if( iPedFile.IsZombie() ) + { + cout << "VIPRCalculator::calculateIPRGraphs error reading IPR graphs from "; + cout << iPedFileName << endl; + return false; + } + // histograms with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << iTelType << ": "; + cout << "reading IPR histograms for summation window " << iSummationWindow; + cout << " from "; + cout << iPedFileName << endl; + +<<<<<<< HEAD + stringstream i_Directory( stringstream::in | stringstream::out ); + i_Directory << "distributions_" << iTelType; + if( iPedFile.Get( i_Directory.str().c_str() ) ) + { + iPedFile.cd( i_Directory.str().c_str() ); + } +======= + //Simplify: always do this in digital counts. No need to check for initialization. + TH1F* hIPR = new TH1F( "", "", 1000, 0., 100. ); + float i_gainCorrect = 1.; +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + + hIPR->Reset(); + + ////////////////////////////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { +<<<<<<< HEAD + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; +======= + + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hped_Tel" << iTelType << "_TS" << TimeSlice << "_Pix" << i << "_SW" << iSummationWindow; +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream i_Pname( stringstream::in | stringstream::out ); + i_Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( i_Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } + } +<<<<<<< HEAD + for( int j = 1; j <= h->GetNbinsX(); j++ ) +======= + for( unsigned int j = 1; j <= h->GetNbinsX(); j++ ) +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { +<<<<<<< HEAD + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); +======= + //hIPR->Fill( ( h[i_tel][TimeSlice][i][iSummationWindow]->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h[i_tel][TimeSlice][i][iSummationWindow]->GetBinContent( j ) ); + hIPR->Fill( ( h->GetBinCenter( 0 ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( 0 ) ); +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + } + } + } + } + } + } +<<<<<<< HEAD + + int z = 0; + float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "Telescope " << iTelType << ": "; + cout << "VIPRCalculator::calculateIPRGraphs WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphs(): fIPRAverageTel = " << fIPRAverageTel << endl; + hIPR = calculateIPRGraphAveraged( iSummationWindow ); + cout << "VIPRCalculator::calculateIPRGraphs norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphs ERROR: no counts in IPR histogram !" << endl; + return false; + } + // convert to Rate + float nsToSec = 1E-9; + float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); + if( getSearchWindowLast() < getNSamples() ) + { + Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] + } + else + { + Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] + } + float convToHz = 1.; + if( nsToSec > 0. && Tsearch > 0. ) + { + convToHz /= ( nsToSec * Tsearch ); + } + else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) + { + // simple peak sensing: sim_telarray uses the maximum bin only + // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file + // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as + // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns + // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. + convToHz /= ( nsToSec + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); + } +======= + int z = 0; + float norm = 0; + if( hIPR ) + { + norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "norm: " << norm << endl; + } + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "VIPRCalculator::calculateIPRGraphTimeSlices WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; + //hIPR = calculateIPRGraphAveragedNoTimeSlices( fPedFileNameC , iSummationWindow, i_tel ); + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; + return false; + } +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { +<<<<<<< HEAD + double val = convToHz * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convToHz * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; +======= + double val = convertRate( i_tel ) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate( i_tel ) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; +<<<<<<< HEAD + } + } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", Tsearch, + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); + hIPR->Delete(); + + iPedFile.Close(); + + iG_CurrentDirectory->cd(); + + return true; +} + +TH1F* VIPRCalculator::initializeIPRHistogram( unsigned int iSummationWindow, unsigned int iTelType ) +======= + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d_TS%d", iTelType, iSummationWindow, TimeSlice ) ); + hIPR->Delete(); + iPedFile->Close(); + iG_CurrentDirectory->cd(); + + return true; + +} + +/* + * calculate IPR graphs and write them to disk + * + * (loop over all telescopes) + * +*/ + +bool VIPRCalculator::calculateIPRGraphs( std::vector fPedFileNameC ) +{ + + definePedestalFile( fPedFileNameC ); + for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) + { + setTelID( getTeltoAna()[i] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + if( fIPRAverageTel == false ) + { + calculateIPRGraphsNoTimeSlices( getSumWindow(), i ); + } + else + { + copyIPRInitialized( getSumWindow(), i ); + } + + if( fIPRTimeSlices ) + { + for( unsigned int ts = 0 ; ts < getCalData()->getPedsTS_vector( false ).size() ; ts++ ) + { + cout << "MK ts: " << getCalData()->getPedsTS_vector( false ).size() << endl; + calculateIPRGraphsTimeSlices( ts, getSumWindow(), i ); + } + } + } + return true; +} + + +/* + * + * write IPR graphs to disk (one per telescope type) + * + */ +bool VIPRCalculator::writeIPRgraphs( map>>& hped_vec, string iFile ) +>>>>>>> d875f786fff9a004b915438d724c168de7974e22 +{ + //get reference hpedPerTelescopeType for channel 1 + cout << "VIPRCalculator::initializeIPRHistogram initializing IPR graph for calculation of average of telescopes." << endl; + TH1F* hIPR = 0; + + + int TelType = getTelType( iTelType ); + string PedFile_name = fPedFileNameC[iTelType]; + + // check suffix of ped file + if( PedFile_name.find( ".root" ) == string::npos ) + { + PedFile_name += ".root"; + } + // open pedestal files + TFile PedFile( PedFile_name.c_str() ); + + if( PedFile.IsZombie() ) + { + cout << "VIPRCalculator::calculateIPRGraphsStatistics: error reading IPR graphs from "; + cout << PedFile_name << endl; + return hIPR; + } + + // histograms with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << TelType << ": "; + cout << "reading IPR histograms for summation window " << iSummationWindow; + cout << " from "; + cout << PedFile_name << endl; + + stringstream Directory( stringstream::in | stringstream::out ); + Directory << "distributions_" << TelType; + if( !PedFile.Get( Directory.str().c_str() ) ) + { + return hIPR; + } + + // get charge distribution for first channel as reference histogram + stringstream hIPRname( stringstream::in | stringstream::out ); + hIPRname << "distributions_" << TelType << "/hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << 1; + + //? + TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); + PedFile.Close(); + + if( !href ) + { + cout << " Error: cannot find IPR histogram " << hIPRname.str().c_str(); + cout << " in file:" << PedFile_name << " ... exiting " << endl; + return hIPR; + } + + + //summary histogram + if( getRunParameter()->fIgnoreDSTGains ) + { + // work in dc + hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); + cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; + return hIPR; + } + else + { + // work in pe + hIPR = new TH1F( "", "", 1000, 0., 100. ); + return hIPR; + } +} + +TH1F* VIPRCalculator::calculateIPRGraphAveraged( unsigned int iSummationWindow ) +{ + + TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, getTeltoAna()[0] ); + + for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) + { + setTelID( getTeltoAna()[teltype] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + string PedFile_name = fPedFileNameC[getTeltoAna()[teltype]]; + int TelType = getTelType( getTeltoAna()[teltype] ); + + if( PedFile_name.find( ".root" ) == string::npos ) + { + PedFile_name += ".root"; + } + // open pedestal files + TFile PedFile( PedFile_name.c_str() ); + if( PedFile.IsZombie() ) + { + cout << "VIPRCalculator::calculateIPRGraphAveraged error reading IPR graphs from "; + cout << PedFile_name << endl; + TH1F* hNull = 0; + return hNull; + } + // histograms with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "VIPRCalculator::calculateIPRGraphAveraged Telescope type " << TelType << ": "; + cout << "reading IPR histograms for summation window " << iSummationWindow; + cout << " from "; + cout << PedFile_name << endl; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << TelType; + cout << Directory.str().c_str() << endl; + if( PedFile.Get( Directory.str().c_str() ) ) + { + PedFile.cd( Directory.str().c_str() ); + } + else + { + cout << "VIPRCalculator::calculateIPRGraphAveraged no directory: " << Directory.str().c_str() << endl; + } + + /////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream HistName( stringstream::in | stringstream::out ); + HistName << "hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); + + + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream Pname( stringstream::in | stringstream::out ); + Pname << "hped_" << TelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + PedFile.Close(); + + } + hIPR->Scale( 1. / getTeltoAna().size() ); + float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "VIPRCalculator::calculateIPRGraphAveraged normalization of average IPR histogram " << norm; + cout << ". Returning IPR histogram." << endl; + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + cout << "VIPRCalculator::calculateIPRGraphAveraged WARNING: there is NOT enough statistics "; + cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; + return hIPR; + } + else + { + cout << "VIPRCalculator::calculateIPRGraphsStatistics: there is enough statistics to average over telescopes. " << endl; + return hIPR; + } +} + diff --git a/src/VIPRCalculator.cpp.bak b/src/VIPRCalculator.cpp.bak new file mode 100644 index 000000000..4c233c0fa --- /dev/null +++ b/src/VIPRCalculator.cpp.bak @@ -0,0 +1,830 @@ +/*! \class IPRCalculator + * \brief calculation and save IPR GRAPH + * + * */ + +#include "VIPRCalculator.h" + +VIPRCalculator::VIPRCalculator() +{ + fIPRTimeSlices = true; + fIPRAverageTel = false; + fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements +} + +void VIPRCalculator::initialize() +{ + if( fDebug ) + { + cout << "VIPRCalculator::initialize()" << endl; + } + + // set the data readers + initializeDataReader(); + if( !initializeDataReader() ) + { + cout << "VIPRCalculator::initialize, error: cannot initialize data readers" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + + +} + +void VIPRCalculator::definePedestalFile( std::vector fPedFileNameC ) +{ + fPedFile = fPedFileNameC; +} + + +TFile* VIPRCalculator::initializePedestalFile( int i_tel ) +{ + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return nullptr; + } + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "Telescope type " << getTelType( getTeltoAna()[i_tel] ) << ": "; + cout << "reading IPR histograms for summation window " << getSumWindow(); + cout << " from "; + cout << iPedFileName << endl; + return iPedFile; + +} + +float VIPRCalculator::getTsearch() +{ + float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); + if( getSearchWindowLast() < getNSamples() ) + { + Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] + } + else + { + Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] + } + return Tsearch; +} + +float VIPRCalculator::convertRate( unsigned int i_tel) +{ + // convert to Rate + float nsToSec = 1E-9; + float convToHz = 1.; + if( nsToSec > 0. && getTsearch() > 0. ) + { + convToHz /= ( nsToSec * getTsearch() ); + } + else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 + && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) + { + // simple peak sensing: sim_telarray uses the maximum bin only + // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file + // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as + // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns + // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. + convToHz /= ( nsToSec + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice + * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); + } + return convToHz; + +} + + +/* + HANDLING OF IPR FOR NO TIME SLICE CASE + +*/ + +TH1F* VIPRCalculator::initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + //get reference hpedPerTelescopeType for channel 1 + cout << "VIPRCalculator::initializeIPRHistogram initializing IPR graph for calculation of average of telescopes." << endl; + TH1F* hIPR = 0; + + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return hIPR; + } + + stringstream Directory( stringstream::in | stringstream::out ); + Directory << "distributions_" << iTelType; + if( !iPedFile->Get( Directory.str().c_str() ) ) + { + return hIPR; + } + + // get charge distribution for first channel as reference fpedcal_histo_storagegram + stringstream hIPRname( stringstream::in | stringstream::out ); + hIPRname << "distributions_" << iTelType << "/hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << 1; + + //? + TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); + iPedFile->Close(); + + if( !href ) + { + cout << " Error: cannot find IPR histogram" << hIPRname.str().c_str(); + return hIPR; + } + //summary fpedcal_histo_storagegram + if( getRunParameter()->fIgnoreDSTGains ) + { + // work in dc + hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); + cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; + return hIPR; + } + else + { + // work in pe + hIPR = new TH1F( "", "", 1000, 0., 100. ); + return hIPR; + } +} + +TH1F* VIPRCalculator::FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, i_tel ); + // check suffix of ped file + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return hIPR; + } + + stringstream i_Directory( stringstream::in | stringstream::out ); + i_Directory << "distributions_" << iTelType; + if( iPedFile->Get( i_Directory.str().c_str() ) ) + { + iPedFile->cd( i_Directory.str().c_str() ); + } + + float i_gainCorrect = 1.; + //hIPR->Reset(); + // //float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + iPedFile->Close(); + return hIPR; +} + +/* +IN CASE IPR IS GIVEN AS AVERAGE OF TELESCOPES, FOR TEL > 0 COPY IPR CALCULATED FOR TEL = 0. +*/ + +bool VIPRCalculator::copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[0] ); + TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); + + setTelID( getTeltoAna()[i_tel] ); + + if( !i_IPRGraph ) + { + cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << iTelType << endl; + return false; + } + if( !i_IPRGraph_Tel0 ) + { + cout << "VIPRCalculator::copyIPRInitialized: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; + return false; + } + + for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) + { + i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); + } + + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); + i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); + i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", iTelType, iSummationWindow ) ); + + return true; + +} + +TH1F* VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ) +{ + + TH1F* hIPR = ( TH1F* )initializeIPRHistogram(iSummationWindow , 0); + int iTelType = getTelType( getTeltoAna()[i_tel] ); + + for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) + { + setTelID( getTeltoAna()[teltype] ); + + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + // TFile* iPedFile = (TFile*)initializePedestalFile( teltype ); + string iPedFileName = fPedFile[getTeltoAna()[i_tel]].c_str(); + if( iPedFileName.find( ".root" ) == string::npos ) + { + iPedFileName += ".root"; + } + // open pedestal files + TFile* iPedFile = new TFile( iPedFileName.c_str() ); + if( iPedFile->IsZombie() ) + { + cout << "VIPRCalculator::initializePedestalFile error reading IPR graphs from "; + cout << iPedFileName << endl; + return nullptr; + } + + if( iPedFile == nullptr ) + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices error reading IPR graphs from pedestal file "; + TH1F* hNull = 0; + return hNull; + } + + // fpedcal_histo_storagegrams with IPR distributions are either + // i) in a directory called distributions_TelType + // ii) in the current directory + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices Telescope type " << iTelType << ": "; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << iTelType; + if( iPedFile->Get( Directory.str().c_str() ) ) + { + iPedFile->cd( Directory.str().c_str() ); + } + else + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices no directory: " << Directory.str().c_str() << endl; + } + + /////////////////////////// + // average over all channels in one telescope + float i_gainCorrect = 1.; + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 + && i < getDead().size() && !getDead()[i] ) + { + stringstream HistName( stringstream::in | stringstream::out ); + HistName << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); + + + if( h ) + { + float ped = 0; + // default: pedestals are subtracted here + // (for combined channel analysis: charges are filled already pedestal subtracted) + // apply relative gain correction to integrated charges + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getPeds()[i]; + } + // special treatment for ASTRI telescopes + else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) + { + stringstream Pname( stringstream::in | stringstream::out ); + Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; + TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); + if( hP ) + { + ped = hP->GetMean(); + } + } + for( int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + if( i == 0){cout << "gain : " << getGains()[i] << endl;} + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + } + } + } + } + } + } + iPedFile->Close(); + + } + hIPR->Scale( 1. / getTeltoAna().size() ); + float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices normalization of average IPR fpedcal_histo_storagegram " << norm; + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + cout << "VIPRCalculator::calculateIPRGraphAveragedNoTimeSlices WARNING: there is NOT enough statistics "; + cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; + return hIPR; + } + else + { + cout << "VIPRCalculator::calculateIPRGraphsAveragedNoTimeSlices: there is enough statistics to average over telescopes. " << endl; + return hIPR; + } +} + +TGraphErrors* VIPRCalculator::updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow) +{ + + TGraphErrors* i_IPRGraph = new TGraphErrors( 1 ); + i_IPRGraph->SetTitle( "" ); + + int z = 0; + float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )getTelType( getTeltoAna()[i_tel] ), iSummationWindow ) ); + return i_IPRGraph; +} + +bool VIPRCalculator::calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ) +{ + TDirectory* iG_CurrentDirectory = gDirectory; + + // get an IPR graph + TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); + if( !i_IPRGraph ) + { + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices info: no IPR graph found for telescope type " << getTelType( getTeltoAna()[i_tel] ) << endl; + return false; + } + + ////////////////////////////////////////////////// + // average over all channels in one telescope + TH1F *hIPR = 0; +// TH1F *hIPR = (TH1F*)FillIPRHistogram( iSummationWindow, i_tel); + float norm = 0; + if (hIPR) + { + norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "norm: " << norm << endl; + } + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; + hIPR = calculateIPRGraphAveragedNoTimeSlices( iSummationWindow, i_tel ); + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; + return false; + } + //i_IPRGraph = (TGraphErrors*)updateIPRGraph(hIPR, i_tel, iSummationWindow); + + int z = 0; + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )getTelType( getTeltoAna()[i_tel] ), iSummationWindow ) ); + hIPR->Delete(); + iG_CurrentDirectory->cd(); + return true; +} + + +/* + + HANDLE IPR CALCULATION IF ASKED FOR IN TIME SLICES + +*/ + +void VIPRCalculator::checkHistEmpty(const int telID, const int ts, const int pixel, const int sw) +{ + if (fpedcal_histo_storage[telID][ts][pixel][sw]->GetEntries() != 0) + { + cout << "MK " << telID << " " << ts << " " << pixel << " " << sw << " " << fpedcal_histo_storage[telID][ts][pixel][sw]->GetEntries() << endl; + } +} + +vector>>> VIPRCalculator::getStorageHist() +{ + return fpedcal_histo_storage; +} + +void VIPRCalculator::fillIPRPedestalHisto(){ + fpedcal_histo_storage.resize(getTeltoAna().size()); +} + +void VIPRCalculator::fillIPRPedestalHisto(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ) +{ + fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); + if(false) + { + vector< vector< TH1F* > > v1; + for (int p = 0 ; p < getNChannels(); p++) + { + vector< TH1F* > v2; + for (int sw = 0 ; sw < 3; sw++) + { + if( fpedcal_histo[telID][p][sw] ) + { + v2.push_back( (TH1F*)fpedcal_histo[telID][p][sw]->Clone() ) ; + } + } + v1.push_back(v2); + v2.clear(); + } + fpedcal_histo_storage[telID].push_back(v1); + v1.clear(); + } +} + +void VIPRCalculator::clearHistos() +{ + fpedcal_histo_storage.clear(); + //vector>>>().swap(fpedcal_histo_storage); + +} + +TH1F* VIPRCalculator::getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw){ + + if (fpedcal_histo_storage.empty()){cout << "empty" << endl;} + if(fpedcal_histo_storage[telID][ts][pixel][sw]) + { + return fpedcal_histo_storage[telID][ts][pixel][sw]; + } + else + { + return nullptr; + } +} + +//needs sliding window fpedcal_histo_storagegram!! +bool VIPRCalculator::calculateIPRGraphsTimeSlices(const int TimeSlice, const int iSummationWindow, const int i_tel ) +{ + int iTelType = getTelType( getTeltoAna()[i_tel] ); + TDirectory* iG_CurrentDirectory = gDirectory; + TGraphErrors* i_IPRGraph = getIPRGraphTimeSlice( true, TimeSlice ); + + TFile* iPedFile = (TFile*)initializePedestalFile( i_tel ); + if(iPedFile == nullptr) + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices could not open pedestal file for telescope: " << iTelType; + return false; + } + + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices for Telescope type " << iTelType << ": "; + stringstream Directory( stringstream::in | stringstream::out ); + Directory.str( std::string() ); + Directory << "distributions_" << iTelType; + if( iPedFile->Get( Directory.str().c_str() ) ) + { + iPedFile->cd( Directory.str().c_str() ); + } + else + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices no directory: " << Directory.str().c_str() << endl; + } + /* + //Simplify: always do this in digital counts. No need to check for initialization. + TH1F *hIPR = new TH1F( "", "", 1000, 0., 100. ); + float i_gainCorrect = 1.; + + for( unsigned int i = 0; i < getNChannels(); i++ ) + { + if( getDetectorGeometry()->getAnaPixel()[i] > 0 && i < getDead().size() && !getDead()[i] ) + { + + stringstream i_Hname( stringstream::in | stringstream::out ); + i_Hname << "hped_Tel" << iTelType << "_TS" << TimeSlice << "_Pix" << i << "_SW" << iSummationWindow; + TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); + + if(h) + { + float ped = 0; + if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) + { + ped = getCalData()->getPedsTS_vector( false )[TimeSlice][i]; + } + for( unsigned int j = 1; j <= h->GetNbinsX(); j++ ) + { + if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) + { + i_gainCorrect = getGains()[i]; + if( getHIGHQE_gainfactor( i ) > 0. ) + { + i_gainCorrect *= getHIGHQE_gainfactor( i ); + } + if( i_gainCorrect > 0. ) + { + //hIPR->Fill( ( h[i_tel][TimeSlice][i][iSummationWindow]->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h[i_tel][TimeSlice][i][iSummationWindow]->GetBinContent( j ) ); + hIPR->Fill( ( h->GetBinCenter( 0 ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( 0 ) ); + } + } + } + } + } + } + int z = 0; + float norm = 0; + if (hIPR) + { + norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "norm: " << norm << endl; + } + if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts + { + fIPRAverageTel = true; + cout << "VIPRCalculator::calculateIPRGraphTimeSlices WARNING: too few statistics to measure IPR curves "; + cout << "(total counts available: " << norm << ", "; + cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; + cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; + cout << "VIPRCalculator::calculateIPRGraphNoTimeSlices fIPRAverageTel = " << fIPRAverageTel << endl; + //hIPR = calculateIPRGraphAveragedNoTimeSlices( fPedFileNameC , iSummationWindow, i_tel ); + cout << "VIPRCalculator::calculateIPRGraphsNoTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; + } + if( norm == 0 ) + { + cout << "VIPRCalculator::calculateIPRGraphsTimeSlices ERROR: no counts in IPR fpedcal_histo_storagegram !" << endl; + return false; + } + + for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) + { + if( hIPR->GetBinContent( i ) > 5 ) + { + double val = convertRate(i_tel) * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; + double valerr = convertRate(i_tel) * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; + double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); + double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); + + i_IPRGraph->SetPoint( z, charge_pe, val ); + i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); + z++; + } + } + i_IPRGraph->SetMinimum( 1 ); + i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", getTsearch(), + getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); + if( getRunParameter()->fIgnoreDSTGains ) + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); + } + else + { + i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); + } + i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); + i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d_TS%d", iTelType, iSummationWindow, TimeSlice ) ); + hIPR->Delete(); + iPedFile->Close(); + iG_CurrentDirectory->cd(); */ + iPedFile->Close(); + return true; + +} + +/* + * calculate IPR graphs and write them to disk + * + * (loop over all telescopes) + * +*/ + +bool VIPRCalculator::calculateIPRGraphs(std::vector fPedFileNameC) +{ + + definePedestalFile(fPedFileNameC); + for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) + { + setTelID( getTeltoAna()[i] ); + cout << "11111111111" << endl; + // first find dead channels + // (ignore low gains here) + findDeadChans( false ); + // calculate IPR graphs + if( fIPRAverageTel == false ) + { + calculateIPRGraphsNoTimeSlices( getSumWindow(), i ); + } + else + { + copyIPRInitialized( getSumWindow(), i ); + } + + /*if(false){ + for (unsigned int ts = 0 ; ts < getCalData()->getPedsTS_vector( false ).size() ; ts++ ) + { + cout << "MK ts: " << getCalData()->getPedsTS_vector( false ).size() << endl; + calculateIPRGraphsTimeSlices( ts, getSumWindow(), i); + } + }*/ + } + return true; +} + + +/* + * + * write IPR graphs to disk (one per telescope type) + * + */ +bool VIPRCalculator::writeIPRgraphs( map>> &hped_vec, string iFile ) +{ + TFile* fgraphs = 0; + if( iFile.size() == 0 ) + { + fgraphs = new TFile( getRunParameter()->fIPRdatabaseFile, "RECREATE" ); + } + else + { + fgraphs = new TFile( iFile.c_str(), "UPDATE" ); + } + if( fgraphs->IsZombie() ) + { + cout << "VIPRCalculator::writeIPRgraphs error opening IPR output file: " << endl; + cout << "\t" << fgraphs->GetName() << endl; + return false; + } + + // tree with conditions for these IRPs + TTree* header = new TTree( "IPRheader", "IPR parameters" ); + unsigned int sumwin = 0; // [FADC slices] + unsigned int Nsamples = 0; // [FADC slices] + float ROwin = 0.; // [ns] + float FADCslice = 0.; // [ns] + unsigned int SignalExtractor = 0; // [ Selected Extractor ] + header->Branch( "SignalExtractor", &SignalExtractor, "SignalExtractor/i" ); + header->Branch( "SummationWindow", &sumwin, "SummationWindow/i" ); + header->Branch( "Nsamples", &Nsamples, "Nsamples/i" ); + header->Branch( "FADCtimeSlice", &FADCslice, "FADCtimeSlice/F" ); + header->Branch( "ReadoutWindow", &ROwin, "ReadoutWindow/F" ); + + // one graph per telescope ID + map< ULong64_t, bool > iTelDone; + for( unsigned int i = 0; i < getDetectorGeometry()->getTelType_list().size(); i++ ) + { + iTelDone[getDetectorGeometry()->getTelType_list()[i]] = false; + } + + for( unsigned int i = 0; i < getNTel(); i++ ) + { + setTelID( i ); + if( iTelDone[getTelType( i )] ) + { + continue; + } + + if( hped_vec.find( getTelType( i ) ) == hped_vec.end() ) + { + continue; + } + + // loop over all summation windows + for( unsigned int j = 0; j < hped_vec[getTelType( i )].size(); j++ ) + { + // summation window + int i_sw = j + 1; + + TGraphErrors* g = getIPRGraph( i_sw, false ); + if( !g ) + { + continue; + } + SignalExtractor = getRunParameter()->fTraceIntegrationMethod.at( getTelID() ); + sumwin = i_sw; + Nsamples = getNSamples(); + FADCslice = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); //[ns] + ROwin = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * ( float )getNSamples(); // [ns] + + header->Fill(); + g->Write(); + } + + iTelDone[getTelType( i )] = true; + } + header->Write(); + fgraphs->Close(); + fgraphs->Delete(); + + return true; +} diff --git a/src/VPedestalCalculator.cpp b/src/VPedestalCalculator.cpp index 1bafb52a2..7a04e99e5 100644 --- a/src/VPedestalCalculator.cpp +++ b/src/VPedestalCalculator.cpp @@ -187,6 +187,7 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe // define the time vector fTimeVec.push_back( 0 ); + NTimeSlices.push_back( 0 ); } iDir->cd(); From 584da719a0bf4e60df29c404ed49c7cf265420f7 Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Fri, 21 Apr 2023 14:14:52 +0200 Subject: [PATCH 13/17] Change Makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 4c72ba360..2e9c90b1e 100644 --- a/Makefile +++ b/Makefile @@ -286,6 +286,7 @@ EVNOBJECTS = ./obj/VVirtualDataReader.o \ ./obj/VSpectralWeight.o ./obj/VSpectralWeight_Dict.o \ ./obj/VTableLookupRunParameter.o ./obj/VTableLookupRunParameter_Dict.o \ ./obj/VPedestalCalculator.o \ + ./obj/VIPRCalculator.o \ ./obj/VDeadChannelFinder.o \ ./obj/VSpecialChannel.o \ ./obj/VDeadTime.o \ From 6d9e676fb1d59e2d7e69ddc889a1f1da21a5578b Mon Sep 17 00:00:00 2001 From: GernotMaier Date: Tue, 25 Apr 2023 14:09:31 +0200 Subject: [PATCH 14/17] code formatting --- inc/VCalibrator.h | 2 +- inc/VEvndispData.h | 8 +- inc/VIPRCalculator.h | 18 ++-- inc/VIPRCalculator.h.bsk | 28 +++---- inc/VPedestalCalculator.h | 6 +- src/VCalibrator.cpp | 8 +- src/VEventLoop.cpp | 11 +-- src/VIPRCalculator.cpp | 159 +++++++++++++++++++----------------- src/VIPRCalculator.cpp.bak | 151 ++++++++++++++++++---------------- src/VPedestalCalculator.cpp | 15 ++-- 10 files changed, 212 insertions(+), 194 deletions(-) diff --git a/inc/VCalibrator.h b/inc/VCalibrator.h index 4f1effaa9..c38de1daa 100644 --- a/inc/VCalibrator.h +++ b/inc/VCalibrator.h @@ -136,7 +136,7 @@ class VCalibrator : public VImageBaseAnalyzer void calculatePedestals( bool iLowGain = false ); void calculateGainsAndTOffsets( bool iLowGain = false ); unsigned int getNumberOfEventsUsedInCalibration( int iTelID, int iType ); - void initialize(VIPRCalculator *fIPRCalculator ); + void initialize( VIPRCalculator* fIPRCalculator ); void terminate( VPedestalCalculator*, VIPRCalculator* ); }; #endif diff --git a/inc/VEvndispData.h b/inc/VEvndispData.h index 954e23942..31b841ea8 100644 --- a/inc/VEvndispData.h +++ b/inc/VEvndispData.h @@ -525,12 +525,12 @@ class VEvndispData } TGraphErrors* getIPRGraphTimeSlice( unsigned int TimeSlice = 0 ) { - return fCalData[fTelID]->getIPRGraphTimeSlice( false, TimeSlice ); + return fCalData[fTelID]->getIPRGraphTimeSlice( false, TimeSlice ); } TGraphErrors* getIPRGraphTimeSlice( bool iMakeNewGraph = false, unsigned int TimeSlice = 0 ) - { - return fCalData[fTelID]->getIPRGraphTimeSlice( iMakeNewGraph, TimeSlice ); - } + { + return fCalData[fTelID]->getIPRGraphTimeSlice( iMakeNewGraph, TimeSlice ); + } float getL1Rate( unsigned int iChannel ) { if( fDB_PixelDataReader ) diff --git a/inc/VIPRCalculator.h b/inc/VIPRCalculator.h index 39e8d3e16..a936b81e2 100644 --- a/inc/VIPRCalculator.h +++ b/inc/VIPRCalculator.h @@ -32,9 +32,9 @@ class VIPRCalculator : public VImageBaseAnalyzer bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs bool fIPRInTimeSlices; int fPedPerTelescopeTypeMinCnt; - TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); void definePedestalFile( std::vector fPedFileNameCalibrator ); - TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); + TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); bool copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); TH1F* calculateIPRGraphAveraged( unsigned int iSummationWindow ); public: @@ -42,16 +42,16 @@ class VIPRCalculator : public VImageBaseAnalyzer bool calculateIPRGraphs( std::vector fPedFileNameCalibrator ); bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool calculateIPRGraphsTimeSlices( string iPedFileName, int TS, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); - bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); - void fillIPRPedestalHisto(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ); + bool writeIPRgraphs( map>>& hped_vec, string iFile = "" ); + void fillIPRPedestalHisto( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ); void fillIPRPedestalHisto(); - TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); + TH1F* getIPRPedestalHisto( const int telID, const int ts, const int pixel, const int sw ); bool clearHistos(); vector>>> getStorageHist(); - + VIPRCalculator(); - ~VIPRCalculator() {} - + ~VIPRCalculator() {} + void initialize(); }; -#endif +#endif diff --git a/inc/VIPRCalculator.h.bsk b/inc/VIPRCalculator.h.bsk index b2a59e4fc..a543603fd 100644 --- a/inc/VIPRCalculator.h.bsk +++ b/inc/VIPRCalculator.h.bsk @@ -32,31 +32,31 @@ class VIPRCalculator : public VImageBaseAnalyzer bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs bool fIPRInTimeSlices; int fPedPerTelescopeTypeMinCnt; - TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); - TGraphErrors* updateIPRGraph(TH1F *hIPR, unsigned int i_tel, int iSummationWindow); - float convertRate(unsigned int i_tel); + TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); + TGraphErrors* updateIPRGraph( TH1F* hIPR, unsigned int i_tel, int iSummationWindow ); + float convertRate( unsigned int i_tel ); float getTsearch(); void definePedestalFile( std::vector fPedFileNameC ); TFile* initializePedestalFile( int i_tel ); - TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); - bool calculateIPRGraphsTimeSlices( const int TimeSlice, int iSummationWindow, const int itel); + TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); + bool calculateIPRGraphsTimeSlices( const int TimeSlice, int iSummationWindow, const int itel ); bool calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); bool copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ); TH1F* calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); public: void clearHistos(); vector>>> fpedcal_histo_storage; - TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); + TH1F* getIPRPedestalHisto( const int telID, const int ts, const int pixel, const int sw ); vector>>> getStorageHist(); void fillIPRPedestalHisto(); - void fillIPRPedestalHisto(const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ); - bool calculateIPRGraphs( std::vector fPedFileNameC); - bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); - void checkHistEmpty(const int telID, const int ts, const int pixel, const int sw); - + void fillIPRPedestalHisto( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ); + bool calculateIPRGraphs( std::vector fPedFileNameC ); + bool writeIPRgraphs( map>>& hped_vec, string iFile = "" ); + void checkHistEmpty( const int telID, const int ts, const int pixel, const int sw ); + VIPRCalculator(); - ~VIPRCalculator() {} - + ~VIPRCalculator() {} + void initialize(); }; -#endif +#endif diff --git a/inc/VPedestalCalculator.h b/inc/VPedestalCalculator.h index 3333c04f4..8bf853a17 100644 --- a/inc/VPedestalCalculator.h +++ b/inc/VPedestalCalculator.h @@ -63,7 +63,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer void reset(); public: - vector< int > NTimeSlices; + vector< int > NTimeSlices; vector< vector< int > > v_MJD; //! [telid][time slice] vector< vector< double > > v_time; //! [telid][time slice] //! [telid][time slice][npixel][summation window] @@ -78,7 +78,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer VPedestalCalculator(); ~VPedestalCalculator() {} - void doAnalysis( bool iLowGain = false, VIPRCalculator *fIPRCalculator = 0); + void doAnalysis( bool iLowGain = false, VIPRCalculator* fIPRCalculator = 0 ); vector< TTree* > getPedestalTree() { return fTree; @@ -86,6 +86,6 @@ class VPedestalCalculator : public VImageBaseAnalyzer bool initialize(); bool initialize( bool ibCalibrationRun, unsigned int iNPixel, double iLengthofTimeSlice, int iSumFirst, int iSumWindow, double iRunStartTime = -99., double iRunStoppTime = -99. ); - void terminate( bool iWrite = true, bool bDebug_IO = false, VIPRCalculator* fIPRCalculator = 0); + void terminate( bool iWrite = true, bool bDebug_IO = false, VIPRCalculator* fIPRCalculator = 0 ); }; #endif diff --git a/src/VCalibrator.cpp b/src/VCalibrator.cpp index a3e126205..9ae1ed276 100644 --- a/src/VCalibrator.cpp +++ b/src/VCalibrator.cpp @@ -480,7 +480,7 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul cout << "MKa" << endl; // fill and write pedestal tree fillPedestalTree( tel, iPedestalCalculator ); - cout << "MKb" << endl; + cout << "MKb" << endl; // write 1D histograms to directory calibration_TEL std::ostringstream iSname; iSname << "distributions_" << telType; @@ -3098,7 +3098,7 @@ void VCalibrator::readTOffsets( bool iLowGain ) } //MK test -void VCalibrator::initialize(VIPRCalculator *fIPRCalculator ) +void VCalibrator::initialize( VIPRCalculator* fIPRCalculator ) { if( fDebug ) { @@ -3246,9 +3246,9 @@ void VCalibrator::initialize(VIPRCalculator *fIPRCalculator ) && fRunPar->frunmode != 1 && fRunPar->frunmode != 6 ) { - cout << "MK calculating IPR graphs"<< endl; + cout << "MK calculating IPR graphs" << endl; //calculateIPRGraphs(); - fIPRCalculator->calculateIPRGraphs(fPedFileNameC); + fIPRCalculator->calculateIPRGraphs( fPedFileNameC ); //calculateIPRGraphs(); } } diff --git a/src/VEventLoop.cpp b/src/VEventLoop.cpp index c1226d9f7..d0bb40b25 100644 --- a/src/VEventLoop.cpp +++ b/src/VEventLoop.cpp @@ -476,14 +476,15 @@ bool VEventLoop::initEventLoop( string iFileName ) // initialize analyzers (output files are created as well here) initializeAnalyzers(); - if( fIPRCalculator ){ - cout << "initializing IPR calculator" << endl; - fIPRCalculator->initialize(); - } + if( fIPRCalculator ) + { + cout << "initializing IPR calculator" << endl; + fIPRCalculator->initialize(); + } // create calibrators, analyzers, etc. at first event if( fCalibrator ) { - fCalibrator->initialize(fIPRCalculator); + fCalibrator->initialize( fIPRCalculator ); } // initialize pedestal calculator diff --git a/src/VIPRCalculator.cpp b/src/VIPRCalculator.cpp index 505485c63..a2b459cc2 100644 --- a/src/VIPRCalculator.cpp +++ b/src/VIPRCalculator.cpp @@ -7,41 +7,41 @@ VIPRCalculator::VIPRCalculator() { - fIPRTimeSlices = true; - fIPRAverageTel = false; - fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements + fIPRTimeSlices = true; + fIPRAverageTel = false; + fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements } void VIPRCalculator::initialize() { - if( fDebug ) - { - cout << "VIPRCalculator::initialize()" << endl; - } - - // set the data readers - initializeDataReader(); - if( !initializeDataReader() ) - { - cout << "VIPRCalculator::initialize, error: cannot initialize data readers" << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } + if( fDebug ) + { + cout << "VIPRCalculator::initialize()" << endl; + } + + // set the data readers + initializeDataReader(); + if( !initializeDataReader() ) + { + cout << "VIPRCalculator::initialize, error: cannot initialize data readers" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } } void VIPRCalculator::definePedestalFile( std::vector fPedFileNameCalibrator ) { - for( unsigned int i = 0; i < fPedFileNameCalibrator.size() ; i++) + for( unsigned int i = 0; i < fPedFileNameCalibrator.size() ; i++ ) { - fPedFileNameC.push_back(fPedFileNameCalibrator[i]); + fPedFileNameC.push_back( fPedFileNameCalibrator[i] ); } } -bool VIPRCalculator::calculateIPRGraphs(std::vector fPedFileNameCalibrator ) +bool VIPRCalculator::calculateIPRGraphs( std::vector fPedFileNameCalibrator ) { - definePedestalFile(fPedFileNameCalibrator); + definePedestalFile( fPedFileNameCalibrator ); for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) { setTelID( getTeltoAna()[i] ); @@ -58,14 +58,14 @@ bool VIPRCalculator::calculateIPRGraphs(std::vector fPedFileNameCal { copyIPRTelAveraged( getSumWindow(), getTeltoAna()[i], i ); } - if(false) + if( false ) { cout << "MK ts: " << getCalData()->getPedsTS_vector( false ).size() << endl; - for (unsigned int ts = 0 ; ts < getCalData()->getPedsTS_vector( false ).size() ; ts++ ) - { - calculateIPRGraphsTimeSlices( fPedFileNameC[getTeltoAna()[i]], ts, getSumWindow(), getTelType( getTeltoAna()[i] ), i); - } - } + for( unsigned int ts = 0 ; ts < getCalData()->getPedsTS_vector( false ).size() ; ts++ ) + { + calculateIPRGraphsTimeSlices( fPedFileNameC[getTeltoAna()[i]], ts, getSumWindow(), getTelType( getTeltoAna()[i] ), i ); + } + } } return true; } @@ -491,27 +491,32 @@ TH1F* VIPRCalculator::calculateIPRGraphAveraged( unsigned int iSummationWindow ) * * TIME SLICES CASE: * - */ + */ bool VIPRCalculator::clearHistos() { - fpedcal_histo_storage.clear(); - if (fpedcal_histo_storage.empty() ){ + fpedcal_histo_storage.clear(); + if( fpedcal_histo_storage.empty() ) + { cout << "MK empty 1" << endl; return false; } - for (int telID = 0; telID < fpedcal_histo_storage.size(); telID++) { - for (int i = 0; i < fpedcal_histo_storage[telID].size(); i++) { - for (int j = 0; j < fpedcal_histo_storage[telID][i].size(); j++) { - for (int k = 0; k < fpedcal_histo_storage[telID][i][j].size(); k++) { - delete fpedcal_histo_storage[telID][i][j][k]; - } - fpedcal_histo_storage[telID][i][j].clear(); - } - fpedcal_histo_storage[telID][i].clear(); - } - fpedcal_histo_storage[telID].clear(); - } + for( int telID = 0; telID < fpedcal_histo_storage.size(); telID++ ) + { + for( int i = 0; i < fpedcal_histo_storage[telID].size(); i++ ) + { + for( int j = 0; j < fpedcal_histo_storage[telID][i].size(); j++ ) + { + for( int k = 0; k < fpedcal_histo_storage[telID][i][j].size(); k++ ) + { + delete fpedcal_histo_storage[telID][i][j][k]; + } + fpedcal_histo_storage[telID][i][j].clear(); + } + fpedcal_histo_storage[telID][i].clear(); + } + fpedcal_histo_storage[telID].clear(); + } return true; } @@ -520,49 +525,51 @@ vector>>> VIPRCalculator::getStorageHist() return fpedcal_histo_storage; } -TH1F* VIPRCalculator::getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw) +TH1F* VIPRCalculator::getIPRPedestalHisto( const int telID, const int ts, const int pixel, const int sw ) { - if (fpedcal_histo_storage.empty()){ + if( fpedcal_histo_storage.empty() ) + { cout << "*** MK empty" << endl; return nullptr; } - if(fpedcal_histo_storage[telID][ts][pixel][sw]) - { - return fpedcal_histo_storage[telID][ts][pixel][sw]; - } - else - { - return nullptr; - } + if( fpedcal_histo_storage[telID][ts][pixel][sw] ) + { + return fpedcal_histo_storage[telID][ts][pixel][sw]; + } + else + { + return nullptr; + } } -void VIPRCalculator::fillIPRPedestalHisto(){ - fpedcal_histo_storage.resize(getTeltoAna().size()); +void VIPRCalculator::fillIPRPedestalHisto() +{ + fpedcal_histo_storage.resize( getTeltoAna().size() ); } -void VIPRCalculator::fillIPRPedestalHisto(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ) -{ - //fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); - if(true) - { - vector< vector< TH1F* > > v1; - for (int p = 0 ; p < getNChannels(); p++) - { - vector< TH1F* > v2; - for (int sw = 0 ; sw < 3; sw++) - { - if( fpedcal_histo[telID][p][sw] ) - { - v2.push_back( (TH1F*)fpedcal_histo[telID][p][sw]->Clone() ) ; - } - } - v1.push_back(v2); - v2.clear(); - } - fpedcal_histo_storage[telID].push_back(v1); - v1.clear(); - } +void VIPRCalculator::fillIPRPedestalHisto( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ) +{ + //fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); + if( true ) + { + vector< vector< TH1F* > > v1; + for( int p = 0 ; p < getNChannels(); p++ ) + { + vector< TH1F* > v2; + for( int sw = 0 ; sw < 3; sw++ ) + { + if( fpedcal_histo[telID][p][sw] ) + { + v2.push_back( ( TH1F* )fpedcal_histo[telID][p][sw]->Clone() ) ; + } + } + v1.push_back( v2 ); + v2.clear(); + } + fpedcal_histo_storage[telID].push_back( v1 ); + v1.clear(); + } } bool VIPRCalculator::calculateIPRGraphsTimeSlices( string iPedFileName, int TS, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) @@ -571,7 +578,7 @@ bool VIPRCalculator::calculateIPRGraphsTimeSlices( string iPedFileName, int TS, TDirectory* iG_CurrentDirectory = gDirectory; // get an IPR graph - TGraphErrors* i_IPRGraph = getIPRGraphTimeSlice(true, TS ); + TGraphErrors* i_IPRGraph = getIPRGraphTimeSlice( true, TS ); if( !i_IPRGraph ) { cout << "VIPRCalculator::calculateIPRGraphsTimeSlices info: no IPR graph found for telescope type " << iTelType << endl; diff --git a/src/VIPRCalculator.cpp.bak b/src/VIPRCalculator.cpp.bak index 6c013fda1..4e1439a7b 100644 --- a/src/VIPRCalculator.cpp.bak +++ b/src/VIPRCalculator.cpp.bak @@ -7,42 +7,42 @@ VIPRCalculator::VIPRCalculator() { - fIPRTimeSlices = true; - fIPRAverageTel = false; - fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements + fIPRTimeSlices = true; + fIPRAverageTel = false; + fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements } void VIPRCalculator::initialize() { - if( fDebug ) - { - cout << "VIPRCalculator::initialize()" << endl; - } - - // set the data readers - initializeDataReader(); - if( !initializeDataReader() ) - { - cout << "VIPRCalculator::initialize, error: cannot initialize data readers" << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } - - + if( fDebug ) + { + cout << "VIPRCalculator::initialize()" << endl; + } + + // set the data readers + initializeDataReader(); + if( !initializeDataReader() ) + { + cout << "VIPRCalculator::initialize, error: cannot initialize data readers" << endl; + cout << "exiting..." << endl; + exit( EXIT_FAILURE ); + } + + } void VIPRCalculator::definePedestalFile( std::vector fPedFileNameCalibrator ) { - for( unsigned int i = 0; i < fPedFileNameCalibrator.size() ; i++) + for( unsigned int i = 0; i < fPedFileNameCalibrator.size() ; i++ ) { - fPedFileNameC.push_back(fPedFileNameCalibrator[i]); + fPedFileNameC.push_back( fPedFileNameCalibrator[i] ); } } -bool VIPRCalculator::calculateIPRGraphs(std::vector fPedFileNameCalibrator ) +bool VIPRCalculator::calculateIPRGraphs( std::vector fPedFileNameCalibrator ) { - definePedestalFile(fPedFileNameCalibrator); + definePedestalFile( fPedFileNameCalibrator ); for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) { setTelID( getTeltoAna()[i] ); @@ -484,24 +484,31 @@ TH1F* VIPRCalculator::calculateIPRGraphAveraged( unsigned int iSummationWindow ) * * TIME SLICES CASE: * - */ + */ void VIPRCalculator::clearHistos() { - fpedcal_histo_storage.clear(); - if (fpedcal_histo_storage.empty() ){ cout << "empty" << endl;} - for (int telID = 0; telID < fpedcal_histo_storage.size(); telID++) { - for (int i = 0; i < fpedcal_histo_storage[telID].size(); i++) { - for (int j = 0; j < fpedcal_histo_storage[telID][i].size(); j++) { - for (int k = 0; k < fpedcal_histo_storage[telID][i][j].size(); k++) { - delete fpedcal_histo_storage[telID][i][j][k]; - } - fpedcal_histo_storage[telID][i][j].clear(); - } - fpedcal_histo_storage[telID][i].clear(); - } - fpedcal_histo_storage[telID].clear(); - } + fpedcal_histo_storage.clear(); + if( fpedcal_histo_storage.empty() ) + { + cout << "empty" << endl; + } + for( int telID = 0; telID < fpedcal_histo_storage.size(); telID++ ) + { + for( int i = 0; i < fpedcal_histo_storage[telID].size(); i++ ) + { + for( int j = 0; j < fpedcal_histo_storage[telID][i].size(); j++ ) + { + for( int k = 0; k < fpedcal_histo_storage[telID][i][j].size(); k++ ) + { + delete fpedcal_histo_storage[telID][i][j][k]; + } + fpedcal_histo_storage[telID][i][j].clear(); + } + fpedcal_histo_storage[telID][i].clear(); + } + fpedcal_histo_storage[telID].clear(); + } } vector>>> VIPRCalculator::getStorageHist() @@ -509,49 +516,51 @@ vector>>> VIPRCalculator::getStorageHist() return fpedcal_histo_storage; } -TH1F* VIPRCalculator::getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw) +TH1F* VIPRCalculator::getIPRPedestalHisto( const int telID, const int ts, const int pixel, const int sw ) { - if (fpedcal_histo_storage.empty()){ + if( fpedcal_histo_storage.empty() ) + { cout << "empty" << endl; return nullptr; } - if(fpedcal_histo_storage[telID][ts][pixel][sw]) - { - return fpedcal_histo_storage[telID][ts][pixel][sw]; - } - else - { - return nullptr; - } + if( fpedcal_histo_storage[telID][ts][pixel][sw] ) + { + return fpedcal_histo_storage[telID][ts][pixel][sw]; + } + else + { + return nullptr; + } } -void VIPRCalculator::fillIPRPedestalHisto(){ - fpedcal_histo_storage.resize(getTeltoAna().size()); +void VIPRCalculator::fillIPRPedestalHisto() +{ + fpedcal_histo_storage.resize( getTeltoAna().size() ); } -void VIPRCalculator::fillIPRPedestalHisto(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ) -{ - //fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); - if(true) - { - vector< vector< TH1F* > > v1; - for (int p = 0 ; p < getNChannels(); p++) - { - vector< TH1F* > v2; - for (int sw = 0 ; sw < 3; sw++) - { - if( fpedcal_histo[telID][p][sw] ) - { - v2.push_back( (TH1F*)fpedcal_histo[telID][p][sw]->Clone() ) ; - } - } - v1.push_back(v2); - v2.clear(); - } - fpedcal_histo_storage[telID].push_back(v1); - v1.clear(); - } +void VIPRCalculator::fillIPRPedestalHisto( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ) +{ + //fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); + if( true ) + { + vector< vector< TH1F* > > v1; + for( int p = 0 ; p < getNChannels(); p++ ) + { + vector< TH1F* > v2; + for( int sw = 0 ; sw < 3; sw++ ) + { + if( fpedcal_histo[telID][p][sw] ) + { + v2.push_back( ( TH1F* )fpedcal_histo[telID][p][sw]->Clone() ) ; + } + } + v1.push_back( v2 ); + v2.clear(); + } + fpedcal_histo_storage[telID].push_back( v1 ); + v1.clear(); + } } diff --git a/src/VPedestalCalculator.cpp b/src/VPedestalCalculator.cpp index e537fd5a2..1d7e84047 100644 --- a/src/VPedestalCalculator.cpp +++ b/src/VPedestalCalculator.cpp @@ -278,7 +278,7 @@ void VPedestalCalculator::fillTimeSlice( unsigned int telID ) } -void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalculator ) +void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator* fIPRCalculator ) { double t = getEventTime(); // get right index for tel id @@ -305,13 +305,14 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula else if( t - fTimeVec[telID] > fLengthofTimeSlice ) { time = t; - - if (NTimeSlices[telID] == 0 and telID == 0){ + + if( NTimeSlices[telID] == 0 and telID == 0 ) + { fIPRCalculator->fillIPRPedestalHisto(); } - NTimeSlices[telID]+=1; - fIPRCalculator->fillIPRPedestalHisto(telID, NTimeSlices[telID], fpedcal_histo); - + NTimeSlices[telID] += 1; + fIPRCalculator->fillIPRPedestalHisto( telID, NTimeSlices[telID], fpedcal_histo ); + fillTimeSlice( telID ); fTimeVec[telID] = t; } // if( t - fTimeVec[telID] > fLengthofTimeSlice ) @@ -389,7 +390,7 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula } -void VPedestalCalculator::terminate( bool iWrite, bool iDebug_IO, VIPRCalculator* fIPRCalculator) +void VPedestalCalculator::terminate( bool iWrite, bool iDebug_IO, VIPRCalculator* fIPRCalculator ) { if( iWrite ) { From 4bed9df97cc6f23c623759723696181bed189562 Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Wed, 26 Apr 2023 10:10:16 +0200 Subject: [PATCH 15/17] Write IPR TS to .IPR.root file --- inc/VCalibrator.h | 2 +- inc/VEvndispData.h | 8 +- inc/VEvndispRunParameter.h | 2 +- inc/VIPRCalculator.h | 18 +- inc/VIPRCalculator.h.bsk | 62 ---- inc/VPedestalCalculator.h | 6 +- src/VCalibrator.cpp | 37 ++- src/VEventLoop.cpp | 8 - src/VIPRCalculator.cpp | 107 ++++++- src/VIPRCalculator.cpp.bak | 566 ------------------------------------ src/VImageCleaning.cpp | 13 + src/VPedestalCalculator.cpp | 16 +- 12 files changed, 167 insertions(+), 678 deletions(-) delete mode 100644 inc/VIPRCalculator.h.bsk delete mode 100644 src/VIPRCalculator.cpp.bak diff --git a/inc/VCalibrator.h b/inc/VCalibrator.h index c38de1daa..4f1effaa9 100644 --- a/inc/VCalibrator.h +++ b/inc/VCalibrator.h @@ -136,7 +136,7 @@ class VCalibrator : public VImageBaseAnalyzer void calculatePedestals( bool iLowGain = false ); void calculateGainsAndTOffsets( bool iLowGain = false ); unsigned int getNumberOfEventsUsedInCalibration( int iTelID, int iType ); - void initialize( VIPRCalculator* fIPRCalculator ); + void initialize(VIPRCalculator *fIPRCalculator ); void terminate( VPedestalCalculator*, VIPRCalculator* ); }; #endif diff --git a/inc/VEvndispData.h b/inc/VEvndispData.h index 31b841ea8..954e23942 100644 --- a/inc/VEvndispData.h +++ b/inc/VEvndispData.h @@ -525,12 +525,12 @@ class VEvndispData } TGraphErrors* getIPRGraphTimeSlice( unsigned int TimeSlice = 0 ) { - return fCalData[fTelID]->getIPRGraphTimeSlice( false, TimeSlice ); + return fCalData[fTelID]->getIPRGraphTimeSlice( false, TimeSlice ); } TGraphErrors* getIPRGraphTimeSlice( bool iMakeNewGraph = false, unsigned int TimeSlice = 0 ) - { - return fCalData[fTelID]->getIPRGraphTimeSlice( iMakeNewGraph, TimeSlice ); - } + { + return fCalData[fTelID]->getIPRGraphTimeSlice( iMakeNewGraph, TimeSlice ); + } float getL1Rate( unsigned int iChannel ) { if( fDB_PixelDataReader ) diff --git a/inc/VEvndispRunParameter.h b/inc/VEvndispRunParameter.h index 0bd48a1dd..07d28bbd8 100644 --- a/inc/VEvndispRunParameter.h +++ b/inc/VEvndispRunParameter.h @@ -333,6 +333,6 @@ class VEvndispRunParameter : public TNamed, public VGlobalRunParameter return ( fDBTextDirectory.size() > 0 ); } - ClassDef( VEvndispRunParameter, 2006 ); //(increase this number) + ClassDef( VEvndispRunParameter, 2007 ); //(increase this number) }; #endif diff --git a/inc/VIPRCalculator.h b/inc/VIPRCalculator.h index a936b81e2..39e8d3e16 100644 --- a/inc/VIPRCalculator.h +++ b/inc/VIPRCalculator.h @@ -32,9 +32,9 @@ class VIPRCalculator : public VImageBaseAnalyzer bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs bool fIPRInTimeSlices; int fPedPerTelescopeTypeMinCnt; - TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); + TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); void definePedestalFile( std::vector fPedFileNameCalibrator ); - TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); + TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel); bool copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); TH1F* calculateIPRGraphAveraged( unsigned int iSummationWindow ); public: @@ -42,16 +42,16 @@ class VIPRCalculator : public VImageBaseAnalyzer bool calculateIPRGraphs( std::vector fPedFileNameCalibrator ); bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool calculateIPRGraphsTimeSlices( string iPedFileName, int TS, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); - bool writeIPRgraphs( map>>& hped_vec, string iFile = "" ); - void fillIPRPedestalHisto( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ); + bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); + void fillIPRPedestalHisto(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ); void fillIPRPedestalHisto(); - TH1F* getIPRPedestalHisto( const int telID, const int ts, const int pixel, const int sw ); + TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); bool clearHistos(); vector>>> getStorageHist(); - + VIPRCalculator(); - ~VIPRCalculator() {} - + ~VIPRCalculator() {} + void initialize(); }; -#endif +#endif diff --git a/inc/VIPRCalculator.h.bsk b/inc/VIPRCalculator.h.bsk deleted file mode 100644 index a543603fd..000000000 --- a/inc/VIPRCalculator.h.bsk +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef VIPRCALCULATOR_H -#define VIPRCALCULATOR_H - -#include -#include -#include - -#include "TClonesArray.h" -#include "TFile.h" -#include "TH1F.h" -#include "TLeaf.h" -#include "TMath.h" -#include "TProfile.h" -#include "TSystem.h" -#include "TTree.h" - -#include -#include -#include -#include -#include - -using namespace std; - -class VIPRCalculator : public VImageBaseAnalyzer -{ - - private: - VEvndispData* fData; - vector< string > fPedFile; - bool fIPRTimeSlices; - bool fIPRAverageTel; // flag to make average of all telescopes IPR in case there is not enough statistics to produce IPR graphs - bool fIPRInTimeSlices; - int fPedPerTelescopeTypeMinCnt; - TH1F* FillIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); - TGraphErrors* updateIPRGraph( TH1F* hIPR, unsigned int i_tel, int iSummationWindow ); - float convertRate( unsigned int i_tel ); - float getTsearch(); - void definePedestalFile( std::vector fPedFileNameC ); - TFile* initializePedestalFile( int i_tel ); - TH1F* initializeIPRHistogram( unsigned int iSummationWindow, unsigned int i_tel ); - bool calculateIPRGraphsTimeSlices( const int TimeSlice, int iSummationWindow, const int itel ); - bool calculateIPRGraphsNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); - bool copyIPRInitialized( unsigned int iSummationWindow, unsigned int i_tel ); - TH1F* calculateIPRGraphAveragedNoTimeSlices( unsigned int iSummationWindow, unsigned int i_tel ); - public: - void clearHistos(); - vector>>> fpedcal_histo_storage; - TH1F* getIPRPedestalHisto( const int telID, const int ts, const int pixel, const int sw ); - vector>>> getStorageHist(); - void fillIPRPedestalHisto(); - void fillIPRPedestalHisto( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ); - bool calculateIPRGraphs( std::vector fPedFileNameC ); - bool writeIPRgraphs( map>>& hped_vec, string iFile = "" ); - void checkHistEmpty( const int telID, const int ts, const int pixel, const int sw ); - - VIPRCalculator(); - ~VIPRCalculator() {} - - void initialize(); -}; -#endif diff --git a/inc/VPedestalCalculator.h b/inc/VPedestalCalculator.h index 8bf853a17..3333c04f4 100644 --- a/inc/VPedestalCalculator.h +++ b/inc/VPedestalCalculator.h @@ -63,7 +63,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer void reset(); public: - vector< int > NTimeSlices; + vector< int > NTimeSlices; vector< vector< int > > v_MJD; //! [telid][time slice] vector< vector< double > > v_time; //! [telid][time slice] //! [telid][time slice][npixel][summation window] @@ -78,7 +78,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer VPedestalCalculator(); ~VPedestalCalculator() {} - void doAnalysis( bool iLowGain = false, VIPRCalculator* fIPRCalculator = 0 ); + void doAnalysis( bool iLowGain = false, VIPRCalculator *fIPRCalculator = 0); vector< TTree* > getPedestalTree() { return fTree; @@ -86,6 +86,6 @@ class VPedestalCalculator : public VImageBaseAnalyzer bool initialize(); bool initialize( bool ibCalibrationRun, unsigned int iNPixel, double iLengthofTimeSlice, int iSumFirst, int iSumWindow, double iRunStartTime = -99., double iRunStoppTime = -99. ); - void terminate( bool iWrite = true, bool bDebug_IO = false, VIPRCalculator* fIPRCalculator = 0 ); + void terminate( bool iWrite = true, bool bDebug_IO = false, VIPRCalculator* fIPRCalculator = 0); }; #endif diff --git a/src/VCalibrator.cpp b/src/VCalibrator.cpp index 9ae1ed276..7b9a88e1f 100644 --- a/src/VCalibrator.cpp +++ b/src/VCalibrator.cpp @@ -477,15 +477,15 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul cout << "...exiting" << endl; exit( EXIT_FAILURE ); } - cout << "MKa" << endl; + // fill and write pedestal tree fillPedestalTree( tel, iPedestalCalculator ); - cout << "MKb" << endl; + // write 1D histograms to directory calibration_TEL std::ostringstream iSname; iSname << "distributions_" << telType; TDirectory* i_dist = getPedestalRootFile( telType )->mkdir( iSname.str().c_str() ); - cout << "MKc" << endl; + if( i_dist->cd() ) { i_dist->cd(); @@ -499,7 +499,7 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul } } } - cout << "MKd" << endl; + for( unsigned int i = 0; i < hpedPerTelescopeType[telType].size(); i++ ) { for( unsigned int j = 0; j < hpedPerTelescopeType[telType][i].size(); j++ ) @@ -510,6 +510,20 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul } } } + //cout << "MK sum window: " << getSumWindow() << " " << getRunParameter()->fCalibrationSumWindow << endl; + for (unsigned int ts = 0; ts < (fIPRCalculator->getStorageHist())[tel].size(); ts++) + { + for (unsigned int p = 0; p < getNChannels(); p++) + { + int sw = getSumWindow() - 6; + if ( fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw) ) + { + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetName(Form( "hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 6 ) ); + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetTitle( Form("hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 6 ) ); + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->Write(); + } + } + } } iFileWritten[telType] = true; } @@ -589,7 +603,7 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul } } } - writeIPRgraphs( fPedSingleOutFile->GetName() ); + fIPRCalculator->writeIPRgraphs( hped_vec, fPedSingleOutFile->GetName() ); } } @@ -1593,14 +1607,13 @@ void VCalibrator::writeTOffsets( bool iLowGain ) } } -//MK test -//void VCalibrator::terminate( VPedestalCalculator* iP, VIPRCalculator *fIPRCalculator ) + void VCalibrator::terminate( VPedestalCalculator* iP, VIPRCalculator* fIPRCalculator ) { if( fRunPar->frunmode == 1 || fRunPar->frunmode == 6 ) { writePeds( fRunPar->frunmode == 6, iP, !fRunPar->fPedestalSingleRootFile, fIPRCalculator ); - //writePeds( fRunPar->frunmode == 6, iP, !fRunPar->fPedestalSingleRootFile, fIPRCalculator ); + } else if( fRunPar->frunmode == 2 || fRunPar->frunmode == 5 ) { @@ -3097,7 +3110,6 @@ void VCalibrator::readTOffsets( bool iLowGain ) } -//MK test void VCalibrator::initialize( VIPRCalculator* fIPRCalculator ) { if( fDebug ) @@ -3228,9 +3240,7 @@ void VCalibrator::initialize( VIPRCalculator* fIPRCalculator ) // if needed: write IPR graphs to disk if( getRunParameter()->ifCreateIPRdatabase == true && getRunParameter()->ifReadIPRfromDatabase == false ) { - //MK test - //fIPRCalculator->writeIPRgraphs( hped_vec, ""); - writeIPRgraphs(); + fIPRCalculator->writeIPRgraphs(hped_vec, ""); } // initialize dead channel finder @@ -3246,10 +3256,7 @@ void VCalibrator::initialize( VIPRCalculator* fIPRCalculator ) && fRunPar->frunmode != 1 && fRunPar->frunmode != 6 ) { - cout << "MK calculating IPR graphs" << endl; - //calculateIPRGraphs(); fIPRCalculator->calculateIPRGraphs( fPedFileNameC ); - //calculateIPRGraphs(); } } } diff --git a/src/VEventLoop.cpp b/src/VEventLoop.cpp index d0bb40b25..5e8b320d6 100644 --- a/src/VEventLoop.cpp +++ b/src/VEventLoop.cpp @@ -818,42 +818,34 @@ void VEventLoop::shutdown() else if( fRunPar->frunmode == R_PED || fRunPar->frunmode == R_GTO || fRunPar->frunmode == R_GTOLOW || fRunPar->frunmode == R_PEDLOW || fRunPar->frunmode == R_TZERO || fRunPar->frunmode == R_TZEROLOW ) { - //cout << "MKA " << fIPRCalculator->getIPRPedestalHisto(0, 0, 0, 0)->GetEntries() << endl; VPedestalCalculator* iP = 0; if( fRunPar->frunmode == R_PED && fRunPar->fPedestalsInTimeSlices && fPedestalCalculator ) { iP = fPedestalCalculator; fPedestalCalculator->terminate( false, false, fIPRCalculator ); } - //cout << "MKB " << fIPRCalculator->getIPRPedestalHisto(0, 0, 0, 0)->GetEntries() << endl; if( fCalibrator ) { fCalibrator->terminate( iP , fIPRCalculator ); } - //cout << "MKC " << fIPRCalculator->getIPRPedestalHisto(0, 0, 0, 0)->GetEntries() << endl; - cout << "MK here" << endl; } // write data summary else if( fDST && fRunPar->frunmode == R_DST ) { - cout << "MK here2" << endl; fDST->terminate(); } // delete readers if( fRunPar->fsourcetype != 0 && fGrIsuReader ) { - cout << "MK here3" << endl; delete fGrIsuReader; } if( fDebug ) { - cout << "MK here4" << endl; cout << "VEventLoop::shutdown() ... finished" << endl; } // final check of output file; just open and close it again if( fRunMode == R_ANA ) { - cout << "MK here5" << endl; if( fDebug ) { cout << "VEventLoop::shutdown: final check of output file" << endl; diff --git a/src/VIPRCalculator.cpp b/src/VIPRCalculator.cpp index a2b459cc2..a19ab1979 100644 --- a/src/VIPRCalculator.cpp +++ b/src/VIPRCalculator.cpp @@ -58,7 +58,7 @@ bool VIPRCalculator::calculateIPRGraphs( std::vector fPedFileNameCa { copyIPRTelAveraged( getSumWindow(), getTeltoAna()[i], i ); } - if( false ) + if( true ) { cout << "MK ts: " << getCalData()->getPedsTS_vector( false ).size() << endl; for( unsigned int ts = 0 ; ts < getCalData()->getPedsTS_vector( false ).size() ; ts++ ) @@ -740,3 +740,108 @@ bool VIPRCalculator::calculateIPRGraphsTimeSlices( string iPedFileName, int TS, return true; } + +/* + * + * write IPR graphs to disk (one per telescope type) + * + */ +bool VIPRCalculator::writeIPRgraphs( map>> &hped_vec, string iFile ) +{ + TFile* fgraphs = 0; + if( iFile.size() == 0 ) + { + fgraphs = new TFile( getRunParameter()->fIPRdatabaseFile, "RECREATE" ); + } + else + { + fgraphs = new TFile( iFile.c_str(), "UPDATE" ); + } + if( fgraphs->IsZombie() ) + { + cout << "VCalibrator::writeIPRgraphs error opening IPR output file: " << endl; + cout << "\t" << fgraphs->GetName() << endl; + return false; + } + + // tree with conditions for these IRPs + TTree* header = new TTree( "IPRheader", "IPR parameters" ); + unsigned int sumwin = 0; // [FADC slices] + unsigned int Nsamples = 0; // [FADC slices] + float ROwin = 0.; // [ns] + float FADCslice = 0.; // [ns] + unsigned int SignalExtractor = 0; // [ Selected Extractor ] + header->Branch( "SignalExtractor", &SignalExtractor, "SignalExtractor/i" ); + header->Branch( "SummationWindow", &sumwin, "SummationWindow/i" ); + header->Branch( "Nsamples", &Nsamples, "Nsamples/i" ); + header->Branch( "FADCtimeSlice", &FADCslice, "FADCtimeSlice/F" ); + header->Branch( "ReadoutWindow", &ROwin, "ReadoutWindow/F" ); + + // one graph per telescope ID + map< ULong64_t, bool > iTelDone; + for( unsigned int i = 0; i < getDetectorGeometry()->getTelType_list().size(); i++ ) + { + iTelDone[getDetectorGeometry()->getTelType_list()[i]] = false; + } + + for( unsigned int i = 0; i < getNTel(); i++ ) + { + setTelID( i ); + if( iTelDone[getTelType( i )] ) + { + continue; + } + + if( hped_vec.find( getTelType( i ) ) == hped_vec.end() ) + { + continue; + } + + // loop over all summation windows + for( unsigned int j = 0; j < hped_vec[getTelType( i )].size(); j++ ) + { + // summation window + int i_sw = j + 1; + + TGraphErrors* g = getIPRGraph( i_sw, false ); + if( !g ) + { + continue; + } + SignalExtractor = getRunParameter()->fTraceIntegrationMethod.at( getTelID() ); + sumwin = i_sw; + Nsamples = getNSamples(); + FADCslice = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); //[ns] + ROwin = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * ( float )getNSamples(); // [ns] + + header->Fill(); + g->Write(); + } + + //loop over all time slices + for (unsigned int ts = 0 ; ts < getCalData()->getPedsTS_vector( false ).size() ; ts++ ) + { + TGraphErrors* gTS = getIPRGraphTimeSlice(false, ts ); + if( !gTS ) + { + continue; + } + SignalExtractor = getRunParameter()->fTraceIntegrationMethod.at( getTelID() ); + sumwin = 1; + Nsamples = getNSamples(); + FADCslice = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); //[ns] + ROwin = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * ( float )getNSamples(); // [ns] + + header->Fill(); + gTS->Write(); + + } + + iTelDone[getTelType( i )] = true; + } + header->Write(); + fgraphs->Close(); + fgraphs->Delete(); + + return true; +} diff --git a/src/VIPRCalculator.cpp.bak b/src/VIPRCalculator.cpp.bak deleted file mode 100644 index 4e1439a7b..000000000 --- a/src/VIPRCalculator.cpp.bak +++ /dev/null @@ -1,566 +0,0 @@ -/*! \class IPRCalculator - * \brief calculation and save IPR GRAPH - * - * */ - -#include "VIPRCalculator.h" - -VIPRCalculator::VIPRCalculator() -{ - fIPRTimeSlices = true; - fIPRAverageTel = false; - fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements -} - -void VIPRCalculator::initialize() -{ - if( fDebug ) - { - cout << "VIPRCalculator::initialize()" << endl; - } - - // set the data readers - initializeDataReader(); - if( !initializeDataReader() ) - { - cout << "VIPRCalculator::initialize, error: cannot initialize data readers" << endl; - cout << "exiting..." << endl; - exit( EXIT_FAILURE ); - } - - -} - -void VIPRCalculator::definePedestalFile( std::vector fPedFileNameCalibrator ) -{ - for( unsigned int i = 0; i < fPedFileNameCalibrator.size() ; i++ ) - { - fPedFileNameC.push_back( fPedFileNameCalibrator[i] ); - } -} - -bool VIPRCalculator::calculateIPRGraphs( std::vector fPedFileNameCalibrator ) -{ - - definePedestalFile( fPedFileNameCalibrator ); - for( unsigned int i = 0; i < getTeltoAna().size(); i++ ) - { - setTelID( getTeltoAna()[i] ); - - // first find dead channels - // (ignore low gains here) - findDeadChans( false ); - // calculate IPR graphs - if( fIPRAverageTel == false ) - { - calculateIPRGraphs( fPedFileNameC[getTeltoAna()[i]], getSumWindow(), getTelType( getTeltoAna()[i] ), i ); - } - else - { - copyIPRTelAveraged( getSumWindow(), getTeltoAna()[i], i ); - } - } - return true; -} - -/* - * calculate IPR graphs and write them to disk - * - * (this is done per telescope type) - * - */ - -bool VIPRCalculator::copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) -{ - - TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); - - setTelID( getTeltoAna()[0] ); - TGraphErrors* i_IPRGraph_Tel0 = getIPRGraph( iSummationWindow, true ); - - setTelID( getTeltoAna()[i_tel] ); - - if( !i_IPRGraph ) - { - cout << "VIPRCalculator::copyIPRTelAveraged: no IPR graph found for telescope type " << iTelType << endl; - return false; - } - if( !i_IPRGraph_Tel0 ) - { - cout << "VIPRCalculator::copyIPRTelAveraged: no IPR graph found for telescope type " << getTeltoAna()[0] << endl; - return false; - } - - for( Int_t i = 0; i < i_IPRGraph_Tel0->GetN() ; i++ ) - { - i_IPRGraph->SetPoint( i, i_IPRGraph_Tel0->GetPointX( i ), i_IPRGraph_Tel0->GetPointY( i ) ); - } - - i_IPRGraph->SetMinimum( 1 ); - i_IPRGraph->SetTitle( i_IPRGraph_Tel0->GetTitle() ); - i_IPRGraph->GetXaxis()->SetTitle( i_IPRGraph_Tel0->GetXaxis()->GetTitle() ); - i_IPRGraph->GetYaxis()->SetTitle( i_IPRGraph_Tel0->GetYaxis()->GetTitle() ); - i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); - - return true; - -} - -bool VIPRCalculator::calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) -{ - TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, getTeltoAna()[i_tel] ); - TDirectory* iG_CurrentDirectory = gDirectory; - - // get an IPR graph - TGraphErrors* i_IPRGraph = getIPRGraph( iSummationWindow, true ); - if( !i_IPRGraph ) - { - cout << "VIPRCalculator::calculateIPRGraphs info: no IPR graph found for telescope type " << iTelType << endl; - return false; - } - // check suffix of ped file - if( iPedFileName.find( ".root" ) == string::npos ) - { - iPedFileName += ".root"; - } - // open pedestal files - TFile iPedFile( iPedFileName.c_str() ); - if( iPedFile.IsZombie() ) - { - cout << "VIPRCalculator::calculateIPRGraphs error reading IPR graphs from "; - cout << iPedFileName << endl; - return false; - } - // histograms with IPR distributions are either - // i) in a directory called distributions_TelType - // ii) in the current directory - cout << "Telescope type " << iTelType << ": "; - cout << "reading IPR histograms for summation window " << iSummationWindow; - cout << " from "; - cout << iPedFileName << endl; - - stringstream i_Directory( stringstream::in | stringstream::out ); - i_Directory << "distributions_" << iTelType; - if( iPedFile.Get( i_Directory.str().c_str() ) ) - { - iPedFile.cd( i_Directory.str().c_str() ); - } - - hIPR->Reset(); - - ////////////////////////////////////////////////// - // average over all channels in one telescope - float i_gainCorrect = 1.; - for( unsigned int i = 0; i < getNChannels(); i++ ) - { - if( getDetectorGeometry()->getAnaPixel()[i] > 0 - && i < getDead().size() && !getDead()[i] ) - { - stringstream i_Hname( stringstream::in | stringstream::out ); - i_Hname << "hpedPerTelescopeType_" << iTelType << "_" << iSummationWindow << "_" << i; - TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); - - if( h ) - { - float ped = 0; - // default: pedestals are subtracted here - // (for combined channel analysis: charges are filled already pedestal subtracted) - // apply relative gain correction to integrated charges - if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) - { - ped = getPeds()[i]; - } - // special treatment for ASTRI telescopes - else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) - { - stringstream i_Pname( stringstream::in | stringstream::out ); - i_Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; - TH1F* hP = ( TH1F* )gDirectory->Get( i_Pname.str().c_str() ); - if( hP ) - { - ped = hP->GetMean(); - } - } - for( int j = 1; j <= h->GetNbinsX(); j++ ) - { - if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) - { - i_gainCorrect = getGains()[i]; - if( getHIGHQE_gainfactor( i ) > 0. ) - { - i_gainCorrect *= getHIGHQE_gainfactor( i ); - } - if( i_gainCorrect > 0. ) - { - hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); - } - } - } - } - } - } - - int z = 0; - float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); - if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts - { - fIPRAverageTel = true; - cout << "Telescope " << iTelType << ": "; - cout << "VIPRCalculator::calculateIPRGraphs WARNING: too few statistics to measure IPR curves "; - cout << "(total counts available: " << norm << ", "; - cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; - cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; - cout << "VIPRCalculator::calculateIPRGraphs(): fIPRAverageTel = " << fIPRAverageTel << endl; - hIPR = calculateIPRGraphAveraged( iSummationWindow ); - cout << "VIPRCalculator::calculateIPRGraphs norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; - } - if( norm == 0 ) - { - cout << "VIPRCalculator::calculateIPRGraphs ERROR: no counts in IPR histogram !" << endl; - return false; - } - // convert to Rate - float nsToSec = 1E-9; - float Tsearch = getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ); - if( getSearchWindowLast() < getNSamples() ) - { - Tsearch *= ( getSearchWindowLast() - getSumFirst() ); // [ns] - } - else - { - Tsearch *= ( getNSamples() - getSumFirst() ); // [ns] - } - float convToHz = 1.; - if( nsToSec > 0. && Tsearch > 0. ) - { - convToHz /= ( nsToSec * Tsearch ); - } - else if( getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_ifExplicitSampleTimeSlice - && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice > 0 - && getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC > 0 ) - { - // simple peak sensing: sim_telarray uses the maximum bin only - // The values for sampleTimeSlice and nBinsADC are set in the cleaning parameter file - // For example, for the currect (Apr 17) ASTRI simulation, it is set in sim_telarray as - // fadc_mhz = 500 % MHz ==> sampleTimeSlice = 2 ns - // fadc_sum_bins = nBinsADC = 25 % Number of ADC time intervals actually summed up. - convToHz /= ( nsToSec - * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_sampleTimeSlice - * getRunParameter()->fImageCleaningParameters[i_tel]->fNNOpt_nBinsADC ); - } - - for( int i = 1; i <= hIPR->GetNbinsX(); i++ ) - { - if( hIPR->GetBinContent( i ) > 5 ) - { - double val = convToHz * hIPR->Integral( i, hIPR->GetNbinsX() ) / norm; - double valerr = convToHz * sqrt( hIPR->Integral( i, hIPR->GetNbinsX() ) ) / norm; - double charge_pe = hIPR->GetXaxis()->GetBinCenter( i ) * getTelescopeAverageFADCtoPhe(); - double charge_pe_bin_width = 0.5 * hIPR->GetXaxis()->GetBinWidth( i ) * getTelescopeAverageFADCtoPhe(); - - i_IPRGraph->SetPoint( z, charge_pe, val ); - i_IPRGraph->SetPointError( z, charge_pe_bin_width, valerr ); - z++; - } - } - - i_IPRGraph->SetMinimum( 1 ); - i_IPRGraph->SetTitle( Form( "Rate vs Threshold. W_{RO}=%2.1f ns, W_{int}=%2.1f ns", Tsearch, - getDetectorGeometry()->getLengthOfSampleTimeSlice( getTelID() ) * iSummationWindow ) ); - if( getRunParameter()->fIgnoreDSTGains ) - { - i_IPRGraph->GetXaxis()->SetTitle( "Threshold [FADC counts]" ); - } - else - { - i_IPRGraph->GetXaxis()->SetTitle( "Threshold [p.e.]" ); - } - i_IPRGraph->GetYaxis()->SetTitle( "Rate above Threshold [Hz]" ); - i_IPRGraph->SetName( Form( "IPRcharge_TelType%d_SW%d", ( int )iTelType, iSummationWindow ) ); - hIPR->Delete(); - - iPedFile.Close(); - - iG_CurrentDirectory->cd(); - - return true; -} - -TH1F* VIPRCalculator::initializeIPRHistogram( unsigned int iSummationWindow, unsigned int iTelType ) -{ - //get reference hpedPerTelescopeType for channel 1 - cout << "VIPRCalculator::initializeIPRHistogram initializing IPR graph for calculation of average of telescopes." << endl; - TH1F* hIPR = 0; - - - int TelType = getTelType( iTelType ); - string PedFile_name = fPedFileNameC[iTelType]; - - // check suffix of ped file - if( PedFile_name.find( ".root" ) == string::npos ) - { - PedFile_name += ".root"; - } - // open pedestal files - TFile PedFile( PedFile_name.c_str() ); - - if( PedFile.IsZombie() ) - { - cout << "VIPRCalculator::calculateIPRGraphsStatistics: error reading IPR graphs from "; - cout << PedFile_name << endl; - return hIPR; - } - - // histograms with IPR distributions are either - // i) in a directory called distributions_TelType - // ii) in the current directory - cout << "Telescope type " << TelType << ": "; - cout << "reading IPR histograms for summation window " << iSummationWindow; - cout << " from "; - cout << PedFile_name << endl; - - stringstream Directory( stringstream::in | stringstream::out ); - Directory << "distributions_" << TelType; - if( !PedFile.Get( Directory.str().c_str() ) ) - { - return hIPR; - } - - // get charge distribution for first channel as reference histogram - stringstream hIPRname( stringstream::in | stringstream::out ); - hIPRname << "distributions_" << TelType << "/hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << 1; - - //? - TH1F* href = ( TH1F* )gDirectory->Get( hIPRname.str().c_str() ); - PedFile.Close(); - - if( !href ) - { - cout << " Error: cannot find IPR histogram " << hIPRname.str().c_str(); - cout << " in file:" << PedFile_name << " ... exiting " << endl; - return hIPR; - } - - - //summary histogram - if( getRunParameter()->fIgnoreDSTGains ) - { - // work in dc - hIPR = new TH1F( "", "", int( 1.5 * href->GetNbinsX() + 0.5 ), href->GetXaxis()->GetXmin(), href->GetXaxis()->GetXmax() ); - cout << "Error: " << href->GetNbinsX() << " " << href->GetXaxis()->GetXmin() << " " << href->GetXaxis()->GetXmax() << endl; - return hIPR; - } - else - { - // work in pe - hIPR = new TH1F( "", "", 1000, 0., 100. ); - return hIPR; - } -} - -TH1F* VIPRCalculator::calculateIPRGraphAveraged( unsigned int iSummationWindow ) -{ - - TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, getTeltoAna()[0] ); - - for( unsigned int teltype = 0; teltype < getTeltoAna().size(); teltype++ ) - { - setTelID( getTeltoAna()[teltype] ); - - // first find dead channels - // (ignore low gains here) - findDeadChans( false ); - // calculate IPR graphs - string PedFile_name = fPedFileNameC[getTeltoAna()[teltype]]; - int TelType = getTelType( getTeltoAna()[teltype] ); - - if( PedFile_name.find( ".root" ) == string::npos ) - { - PedFile_name += ".root"; - } - // open pedestal files - TFile PedFile( PedFile_name.c_str() ); - if( PedFile.IsZombie() ) - { - cout << "VIPRCalculator::calculateIPRGraphAveraged error reading IPR graphs from "; - cout << PedFile_name << endl; - TH1F* hNull = 0; - return hNull; - } - // histograms with IPR distributions are either - // i) in a directory called distributions_TelType - // ii) in the current directory - cout << "VIPRCalculator::calculateIPRGraphAveraged Telescope type " << TelType << ": "; - cout << "reading IPR histograms for summation window " << iSummationWindow; - cout << " from "; - cout << PedFile_name << endl; - stringstream Directory( stringstream::in | stringstream::out ); - Directory.str( std::string() ); - Directory << "distributions_" << TelType; - cout << Directory.str().c_str() << endl; - if( PedFile.Get( Directory.str().c_str() ) ) - { - PedFile.cd( Directory.str().c_str() ); - } - else - { - cout << "VIPRCalculator::calculateIPRGraphAveraged no directory: " << Directory.str().c_str() << endl; - } - - /////////////////////////// - // average over all channels in one telescope - float i_gainCorrect = 1.; - for( unsigned int i = 0; i < getNChannels(); i++ ) - { - if( getDetectorGeometry()->getAnaPixel()[i] > 0 - && i < getDead().size() && !getDead()[i] ) - { - stringstream HistName( stringstream::in | stringstream::out ); - HistName << "hpedPerTelescopeType_" << TelType << "_" << iSummationWindow << "_" << i; - TH1F* h = ( TH1F* )gDirectory->Get( HistName.str().c_str() ); - - - if( h ) - { - float ped = 0; - // default: pedestals are subtracted here - // (for combined channel analysis: charges are filled already pedestal subtracted) - // apply relative gain correction to integrated charges - if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) - { - ped = getPeds()[i]; - } - // special treatment for ASTRI telescopes - else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) - { - stringstream Pname( stringstream::in | stringstream::out ); - Pname << "hped_" << TelType << "_" << iSummationWindow << "_" << i; - TH1F* hP = ( TH1F* )gDirectory->Get( Pname.str().c_str() ); - if( hP ) - { - ped = hP->GetMean(); - } - } - for( int j = 1; j <= h->GetNbinsX(); j++ ) - { - if( h->GetBinContent( j ) > 0. && getGains()[i] > 0 ) - { - i_gainCorrect = getGains()[i]; - if( getHIGHQE_gainfactor( i ) > 0. ) - { - i_gainCorrect *= getHIGHQE_gainfactor( i ); - } - if( i_gainCorrect > 0. ) - { - hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); - } - } - } - } - } - } - PedFile.Close(); - - } - hIPR->Scale( 1. / getTeltoAna().size() ); - float norm = getTeltoAna().size() * hIPR->Integral( 1, hIPR->GetNbinsX() ); - cout << "VIPRCalculator::calculateIPRGraphAveraged normalization of average IPR histogram " << norm; - cout << ". Returning IPR histogram." << endl; - if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts - { - cout << "VIPRCalculator::calculateIPRGraphAveraged WARNING: there is NOT enough statistics "; - cout << " ( < " << fPedPerTelescopeTypeMinCnt << ") even when averaging over all telescopes." << endl; - return hIPR; - } - else - { - cout << "VIPRCalculator::calculateIPRGraphsStatistics: there is enough statistics to average over telescopes. " << endl; - return hIPR; - } -} - - -/* - * - * TIME SLICES CASE: - * - */ - -void VIPRCalculator::clearHistos() -{ - fpedcal_histo_storage.clear(); - if( fpedcal_histo_storage.empty() ) - { - cout << "empty" << endl; - } - for( int telID = 0; telID < fpedcal_histo_storage.size(); telID++ ) - { - for( int i = 0; i < fpedcal_histo_storage[telID].size(); i++ ) - { - for( int j = 0; j < fpedcal_histo_storage[telID][i].size(); j++ ) - { - for( int k = 0; k < fpedcal_histo_storage[telID][i][j].size(); k++ ) - { - delete fpedcal_histo_storage[telID][i][j][k]; - } - fpedcal_histo_storage[telID][i][j].clear(); - } - fpedcal_histo_storage[telID][i].clear(); - } - fpedcal_histo_storage[telID].clear(); - } -} - -vector>>> VIPRCalculator::getStorageHist() -{ - return fpedcal_histo_storage; -} - -TH1F* VIPRCalculator::getIPRPedestalHisto( const int telID, const int ts, const int pixel, const int sw ) -{ - if( fpedcal_histo_storage.empty() ) - { - cout << "empty" << endl; - return nullptr; - } - if( fpedcal_histo_storage[telID][ts][pixel][sw] ) - { - return fpedcal_histo_storage[telID][ts][pixel][sw]; - } - else - { - return nullptr; - } -} - - -void VIPRCalculator::fillIPRPedestalHisto() -{ - fpedcal_histo_storage.resize( getTeltoAna().size() ); -} - -void VIPRCalculator::fillIPRPedestalHisto( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ) -{ - //fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); - if( true ) - { - vector< vector< TH1F* > > v1; - for( int p = 0 ; p < getNChannels(); p++ ) - { - vector< TH1F* > v2; - for( int sw = 0 ; sw < 3; sw++ ) - { - if( fpedcal_histo[telID][p][sw] ) - { - v2.push_back( ( TH1F* )fpedcal_histo[telID][p][sw]->Clone() ) ; - } - } - v1.push_back( v2 ); - v2.clear(); - } - fpedcal_histo_storage[telID].push_back( v1 ); - v1.clear(); - } -} - - diff --git a/src/VImageCleaning.cpp b/src/VImageCleaning.cpp index 27d52a18a..23bc72571 100644 --- a/src/VImageCleaning.cpp +++ b/src/VImageCleaning.cpp @@ -548,6 +548,19 @@ bool VImageCleaning::InitNNImgClnPerTelType( unsigned int teltype ) } // IPR graphs IPRgraph->Write(); + + for (unsigned int ts = 0 ; ts < 4 ; ts++ ) + { + TGraphErrors* gTS = fData->getIPRGraphTimeSlice(false, ts ); + if( !gTS ) + { + continue; + } + cout << "MK writing IPR" << endl; + gTS->Write(); + + } + if( fWriteGraphToFileRecreate ) { // probability curves (note that the x-axis is not charge!) diff --git a/src/VPedestalCalculator.cpp b/src/VPedestalCalculator.cpp index 1d7e84047..bfa296465 100644 --- a/src/VPedestalCalculator.cpp +++ b/src/VPedestalCalculator.cpp @@ -278,7 +278,7 @@ void VPedestalCalculator::fillTimeSlice( unsigned int telID ) } -void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator* fIPRCalculator ) +void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalculator ) { double t = getEventTime(); // get right index for tel id @@ -305,14 +305,14 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator* fIPRCalcula else if( t - fTimeVec[telID] > fLengthofTimeSlice ) { time = t; - - if( NTimeSlices[telID] == 0 and telID == 0 ) - { + + if (NTimeSlices[telID] == 0 and telID == 0){ fIPRCalculator->fillIPRPedestalHisto(); } - NTimeSlices[telID] += 1; - fIPRCalculator->fillIPRPedestalHisto( telID, NTimeSlices[telID], fpedcal_histo ); - + NTimeSlices[telID]+=1; + cout << "MK filling pedestal for IPR" << endl; + fIPRCalculator->fillIPRPedestalHisto(telID, NTimeSlices[telID], fpedcal_histo); + fillTimeSlice( telID ); fTimeVec[telID] = t; } // if( t - fTimeVec[telID] > fLengthofTimeSlice ) @@ -390,7 +390,7 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator* fIPRCalcula } -void VPedestalCalculator::terminate( bool iWrite, bool iDebug_IO, VIPRCalculator* fIPRCalculator ) +void VPedestalCalculator::terminate( bool iWrite, bool iDebug_IO, VIPRCalculator* fIPRCalculator) { if( iWrite ) { From 3ec7b906eb6ec13e88fbf937e9605335dd25d56a Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Thu, 27 Apr 2023 12:03:16 +0200 Subject: [PATCH 16/17] Updates after meeting --- inc/VIPRCalculator.h | 3 +-- src/VCalibrator.cpp | 7 ++++--- src/VIPRCalculator.cpp | 13 ++++--------- src/VPedestalCalculator.cpp | 7 ++----- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/inc/VIPRCalculator.h b/inc/VIPRCalculator.h index 39e8d3e16..74f6e8647 100644 --- a/inc/VIPRCalculator.h +++ b/inc/VIPRCalculator.h @@ -43,8 +43,7 @@ class VIPRCalculator : public VImageBaseAnalyzer bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool calculateIPRGraphsTimeSlices( string iPedFileName, int TS, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); - void fillIPRPedestalHisto(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ); - void fillIPRPedestalHisto(); + void initializeIPRStorageVector(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ); TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); bool clearHistos(); vector>>> getStorageHist(); diff --git a/src/VCalibrator.cpp b/src/VCalibrator.cpp index 7b9a88e1f..249bc05af 100644 --- a/src/VCalibrator.cpp +++ b/src/VCalibrator.cpp @@ -515,11 +515,12 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul { for (unsigned int p = 0; p < getNChannels(); p++) { - int sw = getSumWindow() - 6; + //MK: get the correct index (SW-1) for summation window SW. Same thing done in line 141 for hpedPerTelescopeType + int sw = getSumWindow() - 1; if ( fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw) ) { - fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetName(Form( "hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 6 ) ); - fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetTitle( Form("hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 6 ) ); + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetName(Form( "hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 1 ) ); + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetTitle( Form("hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 1 ) ); fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->Write(); } } diff --git a/src/VIPRCalculator.cpp b/src/VIPRCalculator.cpp index a19ab1979..12881974f 100644 --- a/src/VIPRCalculator.cpp +++ b/src/VIPRCalculator.cpp @@ -10,6 +10,7 @@ VIPRCalculator::VIPRCalculator() fIPRTimeSlices = true; fIPRAverageTel = false; fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements + fpedcal_histo_storage.resize( getTeltoAna().size() ); } void VIPRCalculator::initialize() @@ -542,13 +543,7 @@ TH1F* VIPRCalculator::getIPRPedestalHisto( const int telID, const int ts, const } } - -void VIPRCalculator::fillIPRPedestalHisto() -{ - fpedcal_histo_storage.resize( getTeltoAna().size() ); -} - -void VIPRCalculator::fillIPRPedestalHisto( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ) +void VIPRCalculator::initializeIPRStorageVector( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ) { //fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); if( true ) @@ -623,7 +618,7 @@ bool VIPRCalculator::calculateIPRGraphsTimeSlices( string iPedFileName, int TS, && i < getDead().size() && !getDead()[i] ) { stringstream i_Hname( stringstream::in | stringstream::out ); - i_Hname << "hpedTimeSlices_" << iTelType << "_" << iSummationWindow << "_" << i; + i_Hname << "hpedTimeSlices_Tel" << iTelType << "_TS" << TS << "_Pix" << i << "_SW" << iSummationWindow; TH1F* h = ( TH1F* )gDirectory->Get( i_Hname.str().c_str() ); if( h ) @@ -647,7 +642,7 @@ bool VIPRCalculator::calculateIPRGraphsTimeSlices( string iPedFileName, int TS, } if( i_gainCorrect > 0. ) { - hIPR->Fill( ( h->GetBinCenter( j ) - ped * iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); + hIPR->Fill( ( h->GetBinCenter( j ) - ped ) / i_gainCorrect, h->GetBinContent( j ) ); } } } diff --git a/src/VPedestalCalculator.cpp b/src/VPedestalCalculator.cpp index bfa296465..183c8e823 100644 --- a/src/VPedestalCalculator.cpp +++ b/src/VPedestalCalculator.cpp @@ -12,7 +12,7 @@ VPedestalCalculator::VPedestalCalculator() fDebug = getDebugFlag(); // default parameters (can be adjusted later in initialize()) - fLengthofTimeSlice = 180.; // in [s] + fLengthofTimeSlice = 2000.; // in [s] fSumWindow = 24; fNPixel = 500; fSumFirst = 0; @@ -306,12 +306,9 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula { time = t; - if (NTimeSlices[telID] == 0 and telID == 0){ - fIPRCalculator->fillIPRPedestalHisto(); - } NTimeSlices[telID]+=1; cout << "MK filling pedestal for IPR" << endl; - fIPRCalculator->fillIPRPedestalHisto(telID, NTimeSlices[telID], fpedcal_histo); + fIPRCalculator->initializeIPRStorageVector(telID, NTimeSlices[telID], fpedcal_histo); fillTimeSlice( telID ); fTimeVec[telID] = t; From 5c0d897cf617908a1abf7894b57e1a761783bae9 Mon Sep 17 00:00:00 2001 From: Maria Carolina Kherlakian Date: Thu, 4 May 2023 11:37:40 +0200 Subject: [PATCH 17/17] Fix segmentation fault --- inc/VIPRCalculator.h | 3 ++- inc/VPedestalCalculator.h | 1 + src/VCalibrator.cpp | 7 +++---- src/VIPRCalculator.cpp | 27 ++++++++++++--------------- src/VPedestalCalculator.cpp | 7 ++++++- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/inc/VIPRCalculator.h b/inc/VIPRCalculator.h index 74f6e8647..39e8d3e16 100644 --- a/inc/VIPRCalculator.h +++ b/inc/VIPRCalculator.h @@ -43,7 +43,8 @@ class VIPRCalculator : public VImageBaseAnalyzer bool calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool calculateIPRGraphsTimeSlices( string iPedFileName, int TS, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ); bool writeIPRgraphs( map>> &hped_vec, string iFile = "" ); - void initializeIPRStorageVector(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ); + void fillIPRPedestalHisto(const int telID, const int NTimeSlices,const vector>>& fpedcal_histo ); + void fillIPRPedestalHisto(); TH1F* getIPRPedestalHisto(const int telID, const int ts, const int pixel, const int sw); bool clearHistos(); vector>>> getStorageHist(); diff --git a/inc/VPedestalCalculator.h b/inc/VPedestalCalculator.h index 3333c04f4..a4c077578 100644 --- a/inc/VPedestalCalculator.h +++ b/inc/VPedestalCalculator.h @@ -48,6 +48,7 @@ class VPedestalCalculator : public VImageBaseAnalyzer vector< vector< vector< float > > > fpedcal_mean; vector< vector< vector< float > > > fpedcal_mean2; vector< vector< vector< TH1F* > > > fpedcal_histo; + vector< vector< vector< TH1F* > > > fpedcal_histo_slidingw; vector< vector< float > > v_temp_pedEntries; vector< vector< float > > v_temp_ped; diff --git a/src/VCalibrator.cpp b/src/VCalibrator.cpp index 249bc05af..7b9a88e1f 100644 --- a/src/VCalibrator.cpp +++ b/src/VCalibrator.cpp @@ -515,12 +515,11 @@ void VCalibrator::writePeds( bool iLowGain, VPedestalCalculator* iPedestalCalcul { for (unsigned int p = 0; p < getNChannels(); p++) { - //MK: get the correct index (SW-1) for summation window SW. Same thing done in line 141 for hpedPerTelescopeType - int sw = getSumWindow() - 1; + int sw = getSumWindow() - 6; if ( fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw) ) { - fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetName(Form( "hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 1 ) ); - fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetTitle( Form("hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 1 ) ); + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetName(Form( "hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 6 ) ); + fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->SetTitle( Form("hpedTimeSlices_Tel%d_TS%d_Pix%d_SW%d", (int)telType, ts, p, sw + 6 ) ); fIPRCalculator->getIPRPedestalHisto(tel, ts, p, sw)->Write(); } } diff --git a/src/VIPRCalculator.cpp b/src/VIPRCalculator.cpp index 12881974f..3ce56d6fa 100644 --- a/src/VIPRCalculator.cpp +++ b/src/VIPRCalculator.cpp @@ -9,7 +9,7 @@ VIPRCalculator::VIPRCalculator() { fIPRTimeSlices = true; fIPRAverageTel = false; - fPedPerTelescopeTypeMinCnt = 1.E5; // minimal counter for IPR measurements + fPedPerTelescopeTypeMinCnt = 1.e3; //1.E5; // minimal counter for IPR measurements fpedcal_histo_storage.resize( getTeltoAna().size() ); } @@ -59,6 +59,10 @@ bool VIPRCalculator::calculateIPRGraphs( std::vector fPedFileNameCa { copyIPRTelAveraged( getSumWindow(), getTeltoAna()[i], i ); } + + cout << "*******************************" << endl; + cout << "* Starting IPR in Time Slices *" << endl; + cout << "*******************************" << endl; if( true ) { cout << "MK ts: " << getCalData()->getPedsTS_vector( false ).size() << endl; @@ -116,6 +120,7 @@ bool VIPRCalculator::copyIPRTelAveraged( unsigned int iSummationWindow, ULong64_ bool VIPRCalculator::calculateIPRGraphs( string iPedFileName, unsigned int iSummationWindow, ULong64_t iTelType, unsigned int i_tel ) { + cout << "MK sum window: " << iSummationWindow << endl; TH1F* hIPR = ( TH1F* )initializeIPRHistogram( iSummationWindow, getTeltoAna()[i_tel] ); TDirectory* iG_CurrentDirectory = gDirectory; @@ -177,17 +182,7 @@ bool VIPRCalculator::calculateIPRGraphs( string iPedFileName, unsigned int iSumm if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) { ped = getPeds()[i]; - } - // special treatment for ASTRI telescopes - else if( getRunParameter()->fCombineChannelsForPedestalCalculation == 2 ) - { - stringstream i_Pname( stringstream::in | stringstream::out ); - i_Pname << "hped_" << iTelType << "_" << iSummationWindow << "_" << i; - TH1F* hP = ( TH1F* )gDirectory->Get( i_Pname.str().c_str() ); - if( hP ) - { - ped = hP->GetMean(); - } + if(i<5){ cout << "MK ped: " << ped << endl; } } for( int j = 1; j <= h->GetNbinsX(); j++ ) { @@ -543,7 +538,7 @@ TH1F* VIPRCalculator::getIPRPedestalHisto( const int telID, const int ts, const } } -void VIPRCalculator::initializeIPRStorageVector( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ) +void VIPRCalculator::fillIPRPedestalHisto( const int telID, const int NTimeSlices, const vector>>& fpedcal_histo ) { //fpedcal_histo_storage[telID].push_back(fpedcal_histo[telID]); if( true ) @@ -630,6 +625,7 @@ bool VIPRCalculator::calculateIPRGraphsTimeSlices( string iPedFileName, int TS, if( getRunParameter()->fCombineChannelsForPedestalCalculation == 0 ) { ped = getCalData()->getPedsTS_vector( false )[TS][i]; + if(i<5){ cout << "MK ped ts: " << ped << endl; } } for( int j = 1; j <= h->GetNbinsX(); j++ ) { @@ -642,7 +638,7 @@ bool VIPRCalculator::calculateIPRGraphsTimeSlices( string iPedFileName, int TS, } if( i_gainCorrect > 0. ) { - hIPR->Fill( ( h->GetBinCenter( j ) - ped ) / i_gainCorrect, h->GetBinContent( j ) ); + hIPR->Fill( ( h->GetBinCenter( j ) - ped*iSummationWindow ) / i_gainCorrect, h->GetBinContent( j ) ); } } } @@ -652,6 +648,7 @@ bool VIPRCalculator::calculateIPRGraphsTimeSlices( string iPedFileName, int TS, int z = 0; float norm = hIPR->Integral( 1, hIPR->GetNbinsX() ); + cout << "MK norm of IPR: " << norm << endl; if( norm < fPedPerTelescopeTypeMinCnt ) //statistical limit for number of counts { fIPRAverageTel = true; @@ -661,7 +658,7 @@ bool VIPRCalculator::calculateIPRGraphsTimeSlices( string iPedFileName, int TS, cout << "current limit " << fPedPerTelescopeTypeMinCnt << ")" << endl; cout << "IPR graphs will be provided as sum of " << getTeltoAna().size() << " telescopes statistics." << endl; cout << "VIPRCalculator::calculateIPRGraphsTimeSlices(): fIPRAverageTel = " << fIPRAverageTel << endl; - hIPR = calculateIPRGraphAveraged( iSummationWindow ); + //hIPR = calculateIPRGraphAveraged( iSummationWindow ); cout << "VIPRCalculator::calculateIPRGraphsTimeSlices norm IPR combined: " << hIPR->Integral( 1, hIPR->GetNbinsX() ) << endl; } if( norm == 0 ) diff --git a/src/VPedestalCalculator.cpp b/src/VPedestalCalculator.cpp index 183c8e823..4adc0411e 100644 --- a/src/VPedestalCalculator.cpp +++ b/src/VPedestalCalculator.cpp @@ -184,6 +184,7 @@ bool VPedestalCalculator::initialize( bool ibCalibrationRun, unsigned int iNPixe fpedcal_mean.push_back( iped_cal2 ); fpedcal_mean2.push_back( iped_cal2 ); fpedcal_histo.push_back( iped_histo2 ); + fpedcal_histo_slidingw.push_back( iped_histo2 ); // define the time vector fTimeVec.push_back( 0 ); @@ -253,6 +254,7 @@ void VPedestalCalculator::fillTimeSlice( unsigned int telID ) fpedcal_mean[telID][p][w] = 0.; fpedcal_mean2[telID][p][w] = 0.; fpedcal_histo[telID][p][w]->Reset(); + fpedcal_histo_slidingw[telID][p][w]->Reset(); } // deroate the pixel coordinates if( getTelID() < getPointing().size() && getPointing()[getTelID()] ) @@ -308,7 +310,7 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula NTimeSlices[telID]+=1; cout << "MK filling pedestal for IPR" << endl; - fIPRCalculator->initializeIPRStorageVector(telID, NTimeSlices[telID], fpedcal_histo); + fIPRCalculator->fillIPRPedestalHisto(telID, NTimeSlices[telID], fpedcal_histo_slidingw ); fillTimeSlice( telID ); fTimeVec[telID] = t; @@ -316,6 +318,7 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula /////////////////////////////////////////////////////// double i_tr_sum = 0.; + double i_tr_sum_slidingw = 0.; // calculate the sums (don't use calcsums because it overwrites getSums() ) // and fill the histograms for( unsigned int i = 0; i < getNChannels(); i++ ) @@ -351,6 +354,7 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula { // calculate trace sum i_tr_sum = fTraceHandler->getTraceSum( fSumFirst, fSumFirst + ( w + 1 ), true, 1 ); + i_tr_sum_slidingw = fTraceHandler->getTraceSum( fSumFirst, fSumFirst + ( w + 1 ), false, 2 ); if( i_tr_sum > 0. && i_tr_sum < 50.*( w + 1 ) ) { if( chanID < fpedcal_n[telID].size() && w < fpedcal_n[telID][chanID].size() ) @@ -359,6 +363,7 @@ void VPedestalCalculator::doAnalysis( bool iLowGain, VIPRCalculator *fIPRCalcula fpedcal_mean[telID][chanID][w] += i_tr_sum; fpedcal_mean2[telID][chanID][w] += i_tr_sum * i_tr_sum; fpedcal_histo[telID][chanID][w]->Fill( i_tr_sum ); + fpedcal_histo_slidingw[telID][chanID][w]->Fill( i_tr_sum_slidingw ); } else {