diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibEvtInfo.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibEvtInfo.h index 4f324b555bbb4a518a5d8ccde038fce01bdaae41..2f4b3812bc2bed633d047e33bf99971d3dca6b68 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibEvtInfo.h +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibEvtInfo.h @@ -14,6 +14,7 @@ #define ISCT_CalibEvtInfo_H //Gaudi includes +#include "GaudiKernel/IAlgTool.h" #include "GaudiKernel/IInterface.h" #include <vector> #include <string> @@ -23,7 +24,7 @@ * Interface to class to deal with run/event information for SCTCalib **/ -class ISCT_CalibEvtInfo: virtual public IInterface{ +class ISCT_CalibEvtInfo: virtual public IAlgTool{ public: /// no-op c/tor ISCT_CalibEvtInfo(){} @@ -60,7 +61,6 @@ class ISCT_CalibEvtInfo: virtual public IInterface{ }; - inline const InterfaceID & ISCT_CalibEvtInfo::interfaceID(){ static const InterfaceID IID("ISCT_CalibEvtInfo",1,0); return IID; diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibHistoSvc.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibHistoSvc.h deleted file mode 100644 index 80e891e5e1616eeec44c38c18d6482c73d09acd1..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibHistoSvc.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file ISCT_CalibHistoSvc.h - * Header file to interface class for histograms in the SCT_CalibAlgs package - * @author Shaun Roe -**/ - -#ifndef ISCT_CalibHistoSvc_h -#define ISCT_CalibHistoSvc_h - -//Gaudi includes -#include "GaudiKernel/IInterface.h" -#include "StoreGate/StoreGateSvc.h" -#include "GaudiKernel/ServiceHandle.h" -#include <vector> -#include <string> -#include <utility> -class TH1F; -class TH2F; -class TH1I; -class ITHistSvc; -class SCT_ID; - -class ISCT_CalibHistoSvc: virtual public IInterface{ - public: - ISCT_CalibHistoSvc(); - /// no-op destructor - virtual ~ISCT_CalibHistoSvc(){} - /// interfaceID re-implemented from IInterface - static const InterfaceID & interfaceID(); - /// book histograms - virtual bool book()=0; - /// read histograms - virtual bool read(const std::string & fileName)=0; - /// fill histograms from simulation - virtual bool fill(const bool fromData=false)=0; - /// fill histograms from data - virtual bool fillFromData()=0; - /// get number of events in a specific bin - virtual int getNumberOfEventsInBin(const int nbin); - /// get total number of entries in the number of events histo - int size(); - /// get bin content for bin in specific histogram - double getBinForHistogramIndex(const int bin, const int histogramIndex); - /// get the number of entries in a given histogram - int size(const int histogramIndex); - void binHistograms(const int nLbMerged); - /// set number of lumiblocks - static void setNumberOfLb(const int nLb); - /// get number of lumiblocks - static int numberOfLb(); - /// set number of lumiblocks - static void setLbToMerge(const int nLbMerge); - /// get number of lumiblocks - static int LbToMerge(); - protected: - std::vector<TH1F *> m_phistoVector; - std::vector<TH2F *> m_phistoVector2D; - TH1I * m_numberOfEventsHisto; - ITHistSvc * m_thistSvc; - //need to implement retrieval for these - //ServiceHandle<StoreGateSvc> m_detStore; - //ServiceHandle<StoreGateSvc> m_evtStore; - const SCT_ID* m_pSCTHelper; - static int m_nLb; - static int m_nLbMerge; - // - bool init(); - template<class S> - std::pair<std::string, bool> retrievedService(S & service){ - if (service.retrieve().isFailure() ) return std::make_pair(std::string("Unable to retrieve ")+service.name(), false); - return std::make_pair("",true); - } -}; - - -inline const InterfaceID & ISCT_CalibHistoSvc::interfaceID(){ - static const InterfaceID IID("ISCT_CalibHistoSvc",1,0); - return IID; -} - - - -#endif - diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibHistoTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibHistoTool.h new file mode 100644 index 0000000000000000000000000000000000000000..517e26c0bfec82b1febb23ef0f8d85ffe89b261e --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibHistoTool.h @@ -0,0 +1,86 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file ISCT_CalibHistoTool.h + * Header file to interface class for histograms in the SCT_CalibAlgs package + * @author Shaun Roe +**/ + +#ifndef ISCT_CalibHistoTool_h +#define ISCT_CalibHistoTool_h + +//Gaudi includes +#include "GaudiKernel/IInterface.h" +#include "GaudiKernel/IAlgTool.h" +#include "StoreGate/StoreGateSvc.h" +#include "GaudiKernel/ToolHandle.h" +#include <vector> +#include <string> +#include <utility> +class TH1F; +class TH2F; +class TH1I; +class ITHistSvc; +class SCT_ID; + +class ISCT_CalibHistoTool: virtual public IAlgTool { + public: + ISCT_CalibHistoTool(); + /// no-op destructor + virtual ~ISCT_CalibHistoTool() = default; + /// interfaceID re-implemented from IInterface + static const InterfaceID & interfaceID(); + /// book histograms + virtual bool book()=0; + /// read histograms + virtual bool read(const std::string & fileName)=0; + /// fill histograms from simulation + virtual bool fill(const bool fromData=false)=0; + /// fill histograms from data + virtual bool fillFromData()=0; + /// get number of events in a specific bin + virtual int getNumberOfEventsInBin(const int nbin); + /// get total number of entries in the number of events histo + int size(); + /// get bin content for bin in specific histogram + double getBinForHistogramIndex(const int bin, const int histogramIndex); + /// get the number of entries in a given histogram + int size(const int histogramIndex); + void binHistograms(const int nLbMerged); + /// set number of lumiblocks + static void setNumberOfLb(const int nLb); + /// get number of lumiblocks + static int numberOfLb(); + /// set number of lumiblocks + static void setLbToMerge(const int nLbMerge); + /// get number of lumiblocks + static int LbToMerge(); + protected: + std::vector<TH1F *> m_phistoVector; + std::vector<TH2F *> m_phistoVector2D; + TH1I * m_numberOfEventsHisto; + ITHistSvc * m_thistSvc; + //need to implement retrieval for these + //ServiceHandle<StoreGateSvc> m_detStore; + //ServiceHandle<StoreGateSvc> m_evtStore; + const SCT_ID* m_pSCTHelper; + static int m_nLb; + static int m_nLbMerge; + // + bool init(); + template<class T> + std::pair<std::string, bool> retrievedTool(T & tool) { + if (tool.retrieve().isFailure() ) return std::make_pair(std::string("Unable to retrieve ")+tool.name(), false); + return std::make_pair("",true); + } +}; + + +inline const InterfaceID & ISCT_CalibHistoTool::interfaceID() { + static const InterfaceID IID("ISCT_CalibHistoTool",1,0); + return IID; +} + +#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibModuleListSvc.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibModuleListSvc.h deleted file mode 100644 index d274eed12a5a6188d8bb3de2a59798ddec1b1a3f..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibModuleListSvc.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** -* @file SCT_CalibModuleListSvc.h -* Header file for the SCT_CalibModuleListSvc class -* @author Shaun Roe -**/ - -#ifndef ISCT_CalibModuleListSvc_h -#define ISCT_CalibModuleListSvc_h - -// STL and boost headers -#include <string> -#include <vector> -#include <set> -#include <map> -#include <utility> - -#include "GaudiKernel/IInterface.h" -#include "GaudiKernel/ServiceHandle.h" -#include "Identifier/Identifier.h" - -class ISCT_CalibModuleListSvc:virtual public IInterface{ -public: - //@name Service methods, reimplemented - //@{ - ISCT_CalibModuleListSvc(){/**nop**/}; - virtual ~ISCT_CalibModuleListSvc(){/**nop**/}; - virtual StatusCode initialize()=0; - virtual StatusCode finalize()=0; - static const InterfaceID & interfaceID(); - //@} - virtual StatusCode readModuleList( std::map< Identifier, std::set<Identifier> >& moduleList )=0; - -protected: - template<class S> - std::pair<std::string, bool> retrievedService(S & service){ - if (service.retrieve().isFailure() ) return std::make_pair(std::string("Unable to retrieve ")+service.name(), false); - return std::make_pair("",true); - } - }; - - inline const InterfaceID & ISCT_CalibModuleListSvc::interfaceID(){ - static const InterfaceID IID("ISCT_CalibModuleListSvc",1,0); - return IID; - } -#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibModuleListTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibModuleListTool.h new file mode 100644 index 0000000000000000000000000000000000000000..761348143382502d3fff990ddd39da50f9b36b90 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/ISCT_CalibModuleListTool.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** +* @file SCT_CalibModuleListTool.h +* Header file for the SCT_CalibModuleListTool class +* @author Shaun Roe +**/ + +#ifndef ISCT_CalibModuleListTool_h +#define ISCT_CalibModuleListTool_h + +// STL and boost headers +#include <string> +#include <vector> +#include <set> +#include <map> +#include <utility> + +#include "GaudiKernel/IInterface.h" +#include "GaudiKernel/IAlgTool.h" +#include "GaudiKernel/ToolHandle.h" +#include "Identifier/Identifier.h" + +class ISCT_CalibModuleListTool : virtual public IAlgTool { + public: + //@name Service methods, reimplemented + //@{ + ISCT_CalibModuleListTool() {/**nop**/}; + virtual ~ISCT_CalibModuleListTool() {/**nop**/}; + //virtual StatusCode initialize()=0; + //virtual StatusCode finalize()=0; + static const InterfaceID & interfaceID(); + //@} + virtual StatusCode readModuleList( std::map< Identifier, std::set<Identifier> >& moduleList )=0; + + protected: + template<class T> + std::pair<std::string, bool> retrievedTool(T & tool) { + if (tool.retrieve().isFailure() ) return std::make_pair(std::string("Unable to retrieve ")+tool.name(), false); + return std::make_pair("",true); + } +}; + +inline const InterfaceID & ISCT_CalibModuleListTool::interfaceID() { + static const InterfaceID IID("ISCT_CalibModuleListTool",1,0); + return IID; +} +#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalib.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalib.h index a5b34aafc8f5443509da20251f70224026efbccd..ad49c46cc508fd9e2ee4619e65fbd7929e41393b 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalib.h +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalib.h @@ -19,10 +19,10 @@ #define SCTCalib_H // Local -#include "SCT_CalibAlgs/ISCT_CalibHistoSvc.h" +#include "SCT_CalibAlgs/ISCT_CalibHistoTool.h" #include "SCT_CalibAlgs/ISCT_CalibEvtInfo.h" -#include "SCT_CalibAlgs/ISCT_CalibModuleListSvc.h" -#include "SCT_CalibAlgs/SCTCalibWriteSvc.h" //template parameter +#include "SCT_CalibAlgs/ISCT_CalibModuleListTool.h" +#include "SCT_CalibAlgs/SCTCalibWriteTool.h" //template parameter //Athena #include "AthenaBaseComps/AthAlgorithm.h" //baseclass @@ -85,317 +85,313 @@ class Identifier; class SCTCalib : public AthAlgorithm { - public: - SCTCalib( const std::string &name, ISvcLocator *pSvcLocator ) ; - ~SCTCalib(); - StatusCode initialize(); - StatusCode beginRun(); - StatusCode execute(); - StatusCode endRun(); - StatusCode finalize(); - - private: - ServiceHandle<StoreGateSvc> p_sgSvc; - ITHistSvc * m_thistSvc; - const SCT_ID* m_pSCTHelper; - SG::ReadCondHandleKey<InDetDD::SiDetectorElementCollection> m_SCTDetEleCollKey{this, "SCTDetEleCollKey", "SCT_DetectorElementCollection", "Key of SiDetectorElementCollection for SCT"}; - SG::ReadHandleKey<EventInfo> m_eventInfoKey; - - ServiceHandle<SCTCalibWriteSvc> m_pCalibWriteSvc; - ToolHandle<ISCT_ConfigurationConditionsTool> m_ConfigurationConditionsTool{this, "SCT_ConfigurationConditionsTool", "SCT_ConfigurationConditionsTool/InDetSCT_ConfigurationConditionsTool", "Tool to retrieve SCT Configuration"}; - ToolHandle<ISCT_ReadCalibDataTool> m_ReadCalibDataTool{this, "SCT_ReadCalibDataTool", "SCT_ReadCalibDataTool/InDetSCT_ReadCalibDataTool", "Tool to retrieve SCT calibration data"}; - ToolHandle<ISCT_DetectorLevelConditionsTool> m_MajorityConditionsTool{this, "SCT_MajorityConditionsTool", "SCT_MajorityConditionsTool", "Tool to retrieve the majority conditions of SCT"}; - ToolHandle<ISCT_CablingTool> m_CablingTool{this, "SCT_CablingTool", "SCT_CablingTool", "Tool to retrieve SCT Cabling"}; - - //shaun added - ServiceHandle<ISCT_CalibHistoSvc> m_calibHitmapSvc; - ServiceHandle<ISCT_CalibHistoSvc> m_calibBsErrSvc; - ServiceHandle<ISCT_CalibHistoSvc> m_calibLbSvc; - ServiceHandle<ISCT_CalibModuleListSvc> m_calibModuleListSvc; - ServiceHandle<ISCT_CalibEvtInfo> m_calibEvtInfoSvc; - - // Book histograms - - // Methods implemented - StatusCode prepareHV(); - StatusCode doHVPrintXML(const std::pair<int, int> & timeInterval, const std::pair<int, int> & lbRange, Identifier); - // - - bool notEnoughStatistics(const int required, const int obtained, const std::string & histogramName="HIST"); - // - void checkHVTrips(); - StatusCode getNoisyStrip(); - StatusCode getDeadStrip(); - StatusCode getNoiseOccupancy(); - StatusCode getRawOccupancy(); - StatusCode getEfficiency(); - StatusCode getBSErrors(); - StatusCode getLorentzAngle(); - - // To handle XML file for DB - StatusCode openXML4DB( std::ofstream&, const char*, const char*, IOVTime, IOVTime ) const; - StatusCode closeXML4DB( std::ofstream& ) const; - StatusCode addToXML4DB( std::ofstream&, const Identifier&, const char*, float, const char* ) const; - - // To handle XML file for Summary - StatusCode openXML4MonSummary( std::ofstream&, const char* ) const; - StatusCode openXML4DeadSummary( std::ofstream& file, const char* type, int n_Module=0, int n_Link=0, int n_Chip=0, int n_Strip=0 ) - const; - StatusCode wrapUpXML4Summary( std::ofstream&, const char*, std::ostringstream& ) const; - StatusCode addToSummaryStr( std::ostringstream&, const Identifier&, const char*, const char*, const char* ) const; - - // For retrieving informations of the run for MONP200 rerated things - // unsigned long long getDuration(std::string runStart, std::string runEnd); - unsigned long long getNevents(); - - // For ntuple sorting - typedef std::multimap<int, int> EvtIndex; - EvtIndex m_chain_index; - EvtIndex::const_iterator m_evt_iter; - - // For HV trips - std::vector< std::queue<int> > m_phvtripQueue; - std::queue<int> m_prevLBN; - std::vector<int> m_phvtripRunningTotalInt; - std::vector<int> m_phvtripProcessedEventsInt; - std::vector<int> m_phvtripHasItTripped; - std::vector<int> m_phvtripHasItTripped_prev; - std::vector< std::vector< std::pair<int, int> > > m_summarytrips; - std::vector< std::vector< std::pair<int, int> > > m_summarytripslb; - - Identifier m_moduleId; - Identifier m_waferId; - int m_tq[100]; - UnsignedIntegerProperty m_curr_time; - //bool newbin; - std::ofstream m_ofile, m_gofile; - - UnsignedIntegerProperty m_phvtripFirstTime; - UnsignedIntegerProperty m_phvtripPrevTime; - - // output files (for dead search & MONP200 related things ) - std::ofstream m_outDeadStrips; - std::ofstream m_outDeadChips; - std::ofstream m_outDeadSummary; - std::ofstream m_outNOSummary; - std::ofstream m_outROSummary; - std::ofstream m_outEffSummary; - std::ofstream m_outBSErrSummary; - std::ofstream m_outBSErrModule; - std::ofstream m_outLASummary; - - // Properties configurable from jobO - IntegerProperty m_runNumber; - - std::string m_runStartTime; // from runInfo.txt - std::string m_runEndTime; // from runInfo.txt - std::string m_LBMax; // from runInfo.txt - - BooleanProperty m_useDCS; - BooleanProperty m_useConfiguration; - BooleanProperty m_useCalibration; - BooleanProperty m_useMajority; - BooleanProperty m_useBSError; - - StringArrayProperty m_input_bs; // list of BS - StringArrayProperty m_input_hist; // list of HIST (assuming 1 file) - - BooleanProperty m_readBS; // True if BS is used - BooleanProperty m_histBefore2010; // True if HIST is from 2009 or earlier - - BooleanProperty m_doHitMaps; - IntegerProperty m_nLbsMerged; - BooleanProperty m_readHitMaps; - BooleanProperty m_doBSErrors; - BooleanProperty m_doNoisyStrip; - BooleanProperty m_doNoisyLB; - BooleanProperty m_doHV; - BooleanProperty m_doDeadStrip; - BooleanProperty m_doDeadChip; - BooleanProperty m_doNoiseOccupancy; - BooleanProperty m_doRawOccupancy; - BooleanProperty m_doEfficiency; - BooleanProperty m_doBSErrorDB; - BooleanProperty m_doLorentzAngle; - BooleanProperty m_writeToCool; - //reinstated 21 May, sroe - BooleanProperty m_noisyUpdate; - BooleanProperty m_noisyUploadTest; - FloatProperty m_noisyModuleAverageInDB; // Average number of modules with at least 1 noisy strip in COOL - IntegerProperty m_noisyStripLastRunInDB; // Number of noisy strips of the last run uploaded to COOL - FloatProperty m_noisyStripAverageInDB; // Number of noisy strips of the last run uploaded to COOL - IntegerProperty m_noisyModuleList; - FloatProperty m_noisyModuleDiff; - FloatProperty m_noisyStripDiff; - double m_numOfEventsProcessed; - int m_numOfLBsProcessed; - - UnsignedIntegerProperty m_noisyMinStat; - BooleanProperty m_noisyStripAll; - BooleanProperty m_noisyStripThrDef; - FloatProperty m_noisyStripThrOffline; - FloatProperty m_noisyStripThrOnline; - BooleanProperty m_noisyWaferFinder; - BooleanProperty m_noisyWaferWrite; - BooleanProperty m_noisyWaferAllStrips; - FloatProperty m_noisyWaferThrBarrel; - FloatProperty m_noisyWaferThrECA; - FloatProperty m_noisyWaferThrECC; - FloatProperty m_noisyWaferFraction; - FloatProperty m_noisyChipFraction; - - IntegerProperty m_maxtbins; - int m_maxq; - double m_absolutetriplimit; - double m_relativetriplimit; - BooleanProperty m_outputlowhits; - IntegerProperty m_lowHitCut; - - UnsignedIntegerProperty m_deadStripMinStat; - UnsignedIntegerProperty m_deadStripMinStatBusy; - UnsignedIntegerProperty m_deadChipMinStat; - UnsignedIntegerProperty m_deadStripSignificance; - UnsignedIntegerProperty m_deadChipSignificance; - FloatProperty m_busyThr4DeadFinding; - FloatProperty m_noisyThr4DeadFinding; - BooleanProperty m_deadChipUploadTest; - BooleanProperty m_deadStripUploadTest; - - - BooleanProperty m_noiseOccupancyTriggerAware; - UnsignedIntegerProperty m_noiseOccupancyMinStat; - UnsignedIntegerProperty m_rawOccupancyMinStat; - UnsignedIntegerProperty m_efficiencyMinStat; - UnsignedIntegerProperty m_BSErrorDBMinStat; - UnsignedIntegerProperty m_LorentzAngleMinStat; - - BooleanProperty m_LorentzAngleDebugMode; - - std::string m_tagID4NoisyStrips; - std::string m_tagID4DeadStrips; - std::string m_tagID4DeadChips; - std::string m_tagID4NoiseOccupancy; - std::string m_tagID4RawOccupancy; - std::string m_tagID4Efficiency; - std::string m_tagID4BSErrors; - std::string m_tagID4LorentzAngle; - - std::string m_badStripsAllFile; // Output XML for all noisy strips - std::string m_badStripsNewFile; // Output XML for newly found noisy strips (i.e. not in config/calib data) - std::string m_badStripsSummaryFile; // Output XML for summary info from noisy strip search - - std::string m_badModulesFile; // Output XML for HV trips - - std::string m_deadStripsFile; // Output XML for dead strips - std::string m_deadChipsFile; // Output XML for dead chips - std::string m_deadSummaryFile; // Output XML for summary of Dead Finding - - std::string m_noiseOccupancyFile; // Output XML for noise occupancy - std::string m_noiseOccupancySummaryFile; // Output XML for summary of noise occupancy - std::string m_rawOccupancySummaryFile; // Output XML for summary of raw occupancy - std::string m_efficiencySummaryFile; // Output XML for summary of efficiency - std::string m_efficiencyModuleFile; // Output XML for efficiency - std::string m_BSErrorSummaryFile; // Output XML for summary of BS Errors - std::string m_BSErrorModuleFile; // Output XML for summary of BS Errors - std::string m_LorentzAngleFile; // Output XML for noise occupancy - std::string m_LorentzAngleSummaryFile; // Output XML for summary of lorentz angle - - // Event info - const EventInfo* m_evt; - - // Event related - unsigned long long m_numberOfEvents; - unsigned long long m_numberOfEventsHist; // For number of events from HIST - unsigned long long m_eventCounter; - unsigned long long m_maxentry; - int m_timeStampBegin; - int m_timeStampEnd; - std::string m_utcBegin; - std::string m_utcEnd; - int m_LBBegin; - int m_LBEnd; - int m_LBRange; - IOVTime m_iovStart; - IOVTime m_iovStop; - - // Input - TFile* m_inputHist; // Monitoring histograms - bool m_readHIST; // True if HIST is used - - // Histograms - std::vector<TH1F *> m_phitmapHistoVector; - std::vector<TH1F *> m_pLBHistoVector; - std::vector<TH1F *> m_pBSErrorsHistoVector; - std::vector<TProfile2D *> m_pnoiseoccupancymapHistoVector; - std::vector<TProfile2D *> m_pnoiseoccupancymapHistoVectorECp; - std::vector<TProfile2D *> m_pnoiseoccupancymapHistoVectorECm; - std::vector<TProfile *> m_h_phiVsNstripsSideHistoVector; - - // SCT specific numbers - enum { nbins = 6*128, firstStrip = 0, lastStrip = nbins-1, - ntimeBins = 3, firstTimeBin = 0, lastTimeBin = 2, - n_hitBins = 50, first_hitBin = 0, last_hitBin = 50, - n_etaBins = 13, first_etaBin = -6, last_etaBin = 6, - n_phiBins = 56, first_phiBin = 0, last_phiBin = 55, - n_barrels = 4, first_barrel = 0, last_barrel = 3, - n_disks = 9, first_disk = 0, last_disk = 8, - n_etaBinsEC = 3, first_etaBinEC = 0, last_etaBinEC = 2, - n_phiBinsEC = 52, first_phiBinEC = 0, last_phiBinEC = 51 - }; - - // Additional info on SCT specific numbers - enum { n_chipPerSide = 6, n_chipPerModule = 12, n_stripPerChip = 128, n_etaInBarrel = 12, - n_phiBinsB0 = 32, n_phiBinsB1 = 40, n_phiBinsB2 = 48, n_phiBinsB3 = 56, - n_phiBinsECShort = 40, n_phiBinsECMiddle = 40, n_phiBinsECOuter = 52, n_elements=8176, - n_BSErrorType = 15, firstBSErrorType = 0, lastBSErrorType = 14 - }; - - int m_MAXHASH; - SCT_ID::const_id_iterator m_waferItrBegin; - SCT_ID::const_id_iterator m_waferItrEnd; - template<class S> - bool retrievedService(S & service) { - //msg(MSG::INFO)<<"Retrieving: "<<service.name()<<endmsg; - if (service.retrieve().isFailure() ) return msg(MSG::ERROR)<<"Unable to retrieve "<<service.name()<<endmsg, false; - return true; - } - std::string - xmlChannelNoiseOccDataString(const Identifier & waferId, const float occupancy, const SCT_SerialNumber & serial); - - std::string - xmlChannelEfficiencyDataString(const Identifier & waferId, const float efficiency, const SCT_SerialNumber & serial); - - std::pair<int, bool> - getNumNoisyStrips( const Identifier& waferId ) const; - - StatusCode - addStripsToList( Identifier& waferId, std::set<Identifier>& stripIdList, bool isNoisy, bool isNew ); - - StatusCode - writeModuleListToCool( const std::map< Identifier, std::set<Identifier> >& moduleListAll, + public: + SCTCalib( const std::string &name, ISvcLocator *pSvcLocator ) ; + ~SCTCalib(); + StatusCode initialize(); + StatusCode beginRun(); + StatusCode execute(); + StatusCode endRun(); + StatusCode finalize(); + + private: + ServiceHandle<StoreGateSvc> p_sgSvc; + ITHistSvc * m_thistSvc; + const SCT_ID* m_pSCTHelper; + SG::ReadCondHandleKey<InDetDD::SiDetectorElementCollection> m_SCTDetEleCollKey{this, "SCTDetEleCollKey", "SCT_DetectorElementCollection", "Key of SiDetectorElementCollection for SCT"}; + SG::ReadHandleKey<EventInfo> m_eventInfoKey; + + ToolHandle<SCTCalibWriteTool> m_pCalibWriteTool{this, "SCTCalibWriteTool", "SCTCalibWriteTool", "Tool to write out data from calibration loop"}; + ToolHandle<ISCT_ConfigurationConditionsTool> m_ConfigurationConditionsTool{this, "SCT_ConfigurationConditionsTool", "SCT_ConfigurationConditionsTool/InDetSCT_ConfigurationConditionsTool", "Tool to retrieve SCT Configuration"}; + ToolHandle<ISCT_ReadCalibDataTool> m_ReadCalibDataTool{this, "SCT_ReadCalibDataTool", "SCT_ReadCalibDataTool/InDetSCT_ReadCalibDataTool", "Tool to retrieve SCT calibration data"}; + ToolHandle<ISCT_DetectorLevelConditionsTool> m_MajorityConditionsTool{this, "SCT_MajorityConditionsTool", "SCT_MajorityConditionsTool", "Tool to retrieve the majority conditions of SCT"}; + ToolHandle<ISCT_CablingTool> m_CablingTool{this, "SCT_CablingTool", "SCT_CablingTool", "Tool to retrieve SCT Cabling"}; + ToolHandle<ISCT_CalibHistoTool> m_calibHitmapTool{this, "SCT_CalibHitMapTool", "SCT_CalibHitMapTool", "Tool for reading and writing HitMap histograms"}; + ToolHandle<ISCT_CalibHistoTool> m_calibLbTool{this, "SCT_CalibLbTool", "SCT_CalibLbTool", "Tool for reading and writing Lb dependent HitMap histograms"}; + ToolHandle<ISCT_CalibHistoTool> m_calibBsErrTool{this, "SCT_CalibBsErrTool", "SCT_CalibBsErrTool", "Tool for reading and writing BS error histograms"}; + ToolHandle<ISCT_CalibModuleListTool> m_calibModuleListTool{this, "SCT_CalibModuleListTool", "SCT_CalibModuleListTool", "Tool for handling list of modules"}; + ToolHandle<ISCT_CalibEvtInfo> m_calibEvtInfoTool{this, "SCT_CalibEvtInfo", "SCT_CalibEvtInfo", "Tool for handling event info"}; + + // Book histograms + + // Methods implemented + StatusCode prepareHV(); + StatusCode doHVPrintXML(const std::pair<int, int> & timeInterval, const std::pair<int, int> & lbRange, Identifier); + + bool notEnoughStatistics(const int required, const int obtained, const std::string & histogramName="HIST"); + + void checkHVTrips(); + StatusCode getNoisyStrip(); + StatusCode getDeadStrip(); + StatusCode getNoiseOccupancy(); + StatusCode getRawOccupancy(); + StatusCode getEfficiency(); + StatusCode getBSErrors(); + StatusCode getLorentzAngle(); + + // To handle XML file for DB + StatusCode openXML4DB( std::ofstream&, const char*, const char*, IOVTime, IOVTime ) const; + StatusCode closeXML4DB( std::ofstream& ) const; + StatusCode addToXML4DB( std::ofstream&, const Identifier&, const char*, float, const char* ) const; + + // To handle XML file for Summary + StatusCode openXML4MonSummary( std::ofstream&, const char* ) const; + StatusCode openXML4DeadSummary( std::ofstream& file, const char* type, int n_Module=0, int n_Link=0, int n_Chip=0, int n_Strip=0 ) + const; + StatusCode wrapUpXML4Summary( std::ofstream&, const char*, std::ostringstream& ) const; + StatusCode addToSummaryStr( std::ostringstream&, const Identifier&, const char*, const char*, const char* ) const; + + // For retrieving informations of the run for MONP200 rerated things + //unsigned long long getDuration(std::string runStart, std::string runEnd); + unsigned long long getNevents(); + + // For ntuple sorting + typedef std::multimap<int, int> EvtIndex; + EvtIndex m_chain_index; + EvtIndex::const_iterator m_evt_iter; + + // For HV trips + std::vector< std::queue<int> > m_phvtripQueue; + std::queue<int> m_prevLBN; + std::vector<int> m_phvtripRunningTotalInt; + std::vector<int> m_phvtripProcessedEventsInt; + std::vector<int> m_phvtripHasItTripped; + std::vector<int> m_phvtripHasItTripped_prev; + std::vector< std::vector< std::pair<int, int> > > m_summarytrips; + std::vector< std::vector< std::pair<int, int> > > m_summarytripslb; + + Identifier m_moduleId; + Identifier m_waferId; + int m_tq[100]; + UnsignedIntegerProperty m_curr_time; + //bool newbin; + std::ofstream m_ofile, m_gofile; + + UnsignedIntegerProperty m_phvtripFirstTime; + UnsignedIntegerProperty m_phvtripPrevTime; + + // output files (for dead search & MONP200 related things ) + std::ofstream m_outDeadStrips; + std::ofstream m_outDeadChips; + std::ofstream m_outDeadSummary; + std::ofstream m_outNOSummary; + std::ofstream m_outROSummary; + std::ofstream m_outEffSummary; + std::ofstream m_outBSErrSummary; + std::ofstream m_outBSErrModule; + std::ofstream m_outLASummary; + + // Properties configurable from jobO + IntegerProperty m_runNumber; + + std::string m_runStartTime; // from runInfo.txt + std::string m_runEndTime; // from runInfo.txt + std::string m_LBMax; // from runInfo.txt + + BooleanProperty m_useDCS; + BooleanProperty m_useConfiguration; + BooleanProperty m_useCalibration; + BooleanProperty m_useMajority; + BooleanProperty m_useBSError; + + StringArrayProperty m_input_bs; // list of BS + StringArrayProperty m_input_hist; // list of HIST (assuming 1 file) + + BooleanProperty m_readBS; // True if BS is used + BooleanProperty m_histBefore2010; // True if HIST is from 2009 or earlier + + BooleanProperty m_doHitMaps; + IntegerProperty m_nLbsMerged; + BooleanProperty m_readHitMaps; + BooleanProperty m_doBSErrors; + BooleanProperty m_doNoisyStrip; + BooleanProperty m_doNoisyLB; + BooleanProperty m_doHV; + BooleanProperty m_doDeadStrip; + BooleanProperty m_doDeadChip; + BooleanProperty m_doNoiseOccupancy; + BooleanProperty m_doRawOccupancy; + BooleanProperty m_doEfficiency; + BooleanProperty m_doBSErrorDB; + BooleanProperty m_doLorentzAngle; + BooleanProperty m_writeToCool; + + BooleanProperty m_noisyUpdate; + BooleanProperty m_noisyUploadTest; + FloatProperty m_noisyModuleAverageInDB; // Average number of modules with at least 1 noisy strip in COOL + IntegerProperty m_noisyStripLastRunInDB; // Number of noisy strips of the last run uploaded to COOL + FloatProperty m_noisyStripAverageInDB; // Number of noisy strips of the last run uploaded to COOL + IntegerProperty m_noisyModuleList; + FloatProperty m_noisyModuleDiff; + FloatProperty m_noisyStripDiff; + double m_numOfEventsProcessed; + int m_numOfLBsProcessed; + + UnsignedIntegerProperty m_noisyMinStat; + BooleanProperty m_noisyStripAll; + BooleanProperty m_noisyStripThrDef; + FloatProperty m_noisyStripThrOffline; + FloatProperty m_noisyStripThrOnline; + BooleanProperty m_noisyWaferFinder; + BooleanProperty m_noisyWaferWrite; + BooleanProperty m_noisyWaferAllStrips; + FloatProperty m_noisyWaferThrBarrel; + FloatProperty m_noisyWaferThrECA; + FloatProperty m_noisyWaferThrECC; + FloatProperty m_noisyWaferFraction; + FloatProperty m_noisyChipFraction; + + IntegerProperty m_maxtbins; + int m_maxq; + double m_absolutetriplimit; + double m_relativetriplimit; + BooleanProperty m_outputlowhits; + IntegerProperty m_lowHitCut; + + UnsignedIntegerProperty m_deadStripMinStat; + UnsignedIntegerProperty m_deadStripMinStatBusy; + UnsignedIntegerProperty m_deadChipMinStat; + UnsignedIntegerProperty m_deadStripSignificance; + UnsignedIntegerProperty m_deadChipSignificance; + FloatProperty m_busyThr4DeadFinding; + FloatProperty m_noisyThr4DeadFinding; + BooleanProperty m_deadChipUploadTest; + BooleanProperty m_deadStripUploadTest; + + + BooleanProperty m_noiseOccupancyTriggerAware; + UnsignedIntegerProperty m_noiseOccupancyMinStat; + UnsignedIntegerProperty m_rawOccupancyMinStat; + UnsignedIntegerProperty m_efficiencyMinStat; + UnsignedIntegerProperty m_BSErrorDBMinStat; + UnsignedIntegerProperty m_LorentzAngleMinStat; + + BooleanProperty m_LorentzAngleDebugMode; + + std::string m_tagID4NoisyStrips; + std::string m_tagID4DeadStrips; + std::string m_tagID4DeadChips; + std::string m_tagID4NoiseOccupancy; + std::string m_tagID4RawOccupancy; + std::string m_tagID4Efficiency; + std::string m_tagID4BSErrors; + std::string m_tagID4LorentzAngle; + + std::string m_badStripsAllFile; // Output XML for all noisy strips + std::string m_badStripsNewFile; // Output XML for newly found noisy strips (i.e. not in config/calib data) + std::string m_badStripsSummaryFile; // Output XML for summary info from noisy strip search + + std::string m_badModulesFile; // Output XML for HV trips + + std::string m_deadStripsFile; // Output XML for dead strips + std::string m_deadChipsFile; // Output XML for dead chips + std::string m_deadSummaryFile; // Output XML for summary of Dead Finding + + std::string m_noiseOccupancyFile; // Output XML for noise occupancy + std::string m_noiseOccupancySummaryFile; // Output XML for summary of noise occupancy + std::string m_rawOccupancySummaryFile; // Output XML for summary of raw occupancy + std::string m_efficiencySummaryFile; // Output XML for summary of efficiency + std::string m_efficiencyModuleFile; // Output XML for efficiency + std::string m_BSErrorSummaryFile; // Output XML for summary of BS Errors + std::string m_BSErrorModuleFile; // Output XML for summary of BS Errors + std::string m_LorentzAngleFile; // Output XML for noise occupancy + std::string m_LorentzAngleSummaryFile; // Output XML for summary of lorentz angle + + // Event info + const EventInfo* m_evt; + + // Event related + unsigned long long m_numberOfEvents; + unsigned long long m_numberOfEventsHist; // For number of events from HIST + unsigned long long m_eventCounter; + unsigned long long m_maxentry; + int m_timeStampBegin; + int m_timeStampEnd; + std::string m_utcBegin; + std::string m_utcEnd; + int m_LBBegin; + int m_LBEnd; + int m_LBRange; + IOVTime m_iovStart; + IOVTime m_iovStop; + + // Input + TFile* m_inputHist; // Monitoring histograms + bool m_readHIST; // True if HIST is used + + // Histograms + std::vector<TH1F *> m_phitmapHistoVector; + std::vector<TH1F *> m_pLBHistoVector; + std::vector<TH1F *> m_pBSErrorsHistoVector; + std::vector<TProfile2D *> m_pnoiseoccupancymapHistoVector; + std::vector<TProfile2D *> m_pnoiseoccupancymapHistoVectorECp; + std::vector<TProfile2D *> m_pnoiseoccupancymapHistoVectorECm; + std::vector<TProfile *> m_h_phiVsNstripsSideHistoVector; + + // SCT specific numbers + enum { nbins = 6*128, firstStrip = 0, lastStrip = nbins-1, + ntimeBins = 3, firstTimeBin = 0, lastTimeBin = 2, + n_hitBins = 50, first_hitBin = 0, last_hitBin = 50, + n_etaBins = 13, first_etaBin = -6, last_etaBin = 6, + n_phiBins = 56, first_phiBin = 0, last_phiBin = 55, + n_barrels = 4, first_barrel = 0, last_barrel = 3, + n_disks = 9, first_disk = 0, last_disk = 8, + n_etaBinsEC = 3, first_etaBinEC = 0, last_etaBinEC = 2, + n_phiBinsEC = 52, first_phiBinEC = 0, last_phiBinEC = 51 + }; + + // Additional info on SCT specific numbers + enum { n_chipPerSide = 6, n_chipPerModule = 12, n_stripPerChip = 128, n_etaInBarrel = 12, + n_phiBinsB0 = 32, n_phiBinsB1 = 40, n_phiBinsB2 = 48, n_phiBinsB3 = 56, + n_phiBinsECShort = 40, n_phiBinsECMiddle = 40, n_phiBinsECOuter = 52, n_elements=8176, + n_BSErrorType = 15, firstBSErrorType = 0, lastBSErrorType = 14 + }; + + int m_MAXHASH; + SCT_ID::const_id_iterator m_waferItrBegin; + SCT_ID::const_id_iterator m_waferItrEnd; + template<class S> + bool retrievedService(S & service) { + //msg(MSG::INFO)<<"Retrieving: "<<service.name()<<endmsg; + if (service.retrieve().isFailure() ) return msg(MSG::ERROR)<<"Unable to retrieve "<<service.name()<<endmsg, false; + return true; + } + std::string + xmlChannelNoiseOccDataString(const Identifier & waferId, const float occupancy, const SCT_SerialNumber & serial); + + std::string + xmlChannelEfficiencyDataString(const Identifier & waferId, const float efficiency, const SCT_SerialNumber & serial); + + std::pair<int, bool> + getNumNoisyStrips( const Identifier& waferId ) const; + + StatusCode + addStripsToList( Identifier& waferId, std::set<Identifier>& stripIdList, bool isNoisy, bool isNew ); + + StatusCode + writeModuleListToCool( const std::map< Identifier, std::set<Identifier> >& moduleListAll, + const std::map< Identifier, std::set<Identifier> >& moduleListNew, + const std::map< Identifier, std::set<Identifier> >& moduleListRef ) const; + std::string + getStripList( const std::set<Identifier>& stripIdList ) const; + + StatusCode + noisyStripsToXml( const std::map< Identifier, std::set<Identifier> >& moduleList, const std::string& badStripsFile ) const; + + StatusCode + noisyStripsToSummaryXml( const std::map< Identifier, std::set<Identifier> >& moduleListAll, const std::map< Identifier, std::set<Identifier> >& moduleListNew, - const std::map< Identifier, std::set<Identifier> >& moduleListRef ) const; - std::string - getStripList( const std::set<Identifier>& stripIdList ) const; - - StatusCode - noisyStripsToXml( const std::map< Identifier, std::set<Identifier> >& moduleList, const std::string& badStripsFile ) const; - - StatusCode - noisyStripsToSummaryXml( const std::map< Identifier, std::set<Identifier> >& moduleListAll, - const std::map< Identifier, std::set<Identifier> >& moduleListNew, - const std::map< Identifier, std::set<Identifier> >& moduleListRef, - const std::string& badStripsFile) const; - /* StatusCode */ - /* noisyStripsToSummaryXmlFake( const std::string& badStripsFile) const; */ - std::set<int> - getNoisyChips( const std::set<Identifier>& stripIdList ) const; - // - std::pair< std::string, float > - getNoisyLB( const Identifier& moduleId, int& chipId ) const; - - std::string - getLBList( const std::set<int>& LBList ) const; + const std::map< Identifier, std::set<Identifier> >& moduleListRef, + const std::string& badStripsFile) const; + + std::set<int> + getNoisyChips( const std::set<Identifier>& stripIdList ) const; + // + std::pair< std::string, float > + getNoisyLB( const Identifier& moduleId, int& chipId ) const; + + std::string + getLBList( const std::set<int>& LBList ) const; }; // end of class #endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteSvc.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteSvc.h deleted file mode 100644 index 75e97fc990b5f0c4d147eac9bbb4fd8e980fe0d8..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteSvc.h +++ /dev/null @@ -1,234 +0,0 @@ -/** -*- c++ -*- */ - -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/* -* @file SCTCalibWriteSvc.h -* -* @brief Header file for the SCTCalibWriteSvc class -* -* @author Jose E. Garcia -**/ - -#ifndef SCTCalibWriteSvc_H -#define SCTCalibWriteSvc_H - -//STL -#include <string> -#include <map> -#include <set> -#include <list> - -// Gaudi includes -#include "AthenaBaseComps/AthService.h" -#include "GaudiKernel/ServiceHandle.h" -#include "GaudiKernel/ToolHandle.h" -#include "GaudiKernel/StatusCode.h" -#include "GaudiKernel/ClassID.h" -#include "StoreGate/StoreGate.h" -#include "StoreGate/ReadHandleKey.h" -#include "CoralBase/AttributeListSpecification.h" -#include "AthenaPoolUtilities/AthenaAttributeList.h" - - -// Athena includes -#include "Identifier/Identifier.h" - -// local includes -#include "InDetConditionsSummaryService/InDetHierarchy.h" - -//forward declarations -class ISvcLocator; -class IdentifierHash; -class SCT_ID; -class EventInfo; -class IIOVRegistrationSvc; -class IAthenaOutputStreamTool; -class CondAttrListCollection; -class StoreGateSvc; - -/** -** Algorithm to test writing conditions data and reading them back. - **/ -class SCTCalibWriteSvc: public AthService { - friend class SvcFactory<SCTCalibWriteSvc>; - public: - // Constructor - SCTCalibWriteSvc(const std::string &name, ISvcLocator *pSvcLocator) ; - // Destructor - ~SCTCalibWriteSvc(); - - // overloading functions - virtual StatusCode initialize(); - virtual StatusCode finalize(); - static const InterfaceID& interfaceID() { - static const InterfaceID IID_SCTCalibWriteSvc("SCTCalibWriteSvc", 1, 0); - return IID_SCTCalibWriteSvc; - } - virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvIF); - - ///Manually get the data in the structure before proceding - virtual StatusCode fillData(); - - //I'm going to fill this from job options, so the callback version of fillData is not needed. - virtual StatusCode fillData(int& /*i */, std::list<std::string>& /*l*/) { //comment out unused parameters to prevent compiler warning - return StatusCode::FAILURE; - } - - std::string - addDefect(const std::string& defectlist,const int defectBeginChannel,const int defectEndChannel) const; - - std::string - addNumber(const std::string numStr,const unsigned long long number) const; - - std::string - createDefectString(const int defectBeginChannel,const int defectEndChannel) const; - - StatusCode - createCondObjects( const Identifier& wafer_id,const SCT_ID* m_sctId,const int samplesize,const std::string& defectType,const float threshold,const std::string& defectList ) const; - - StatusCode createListStrip( const Identifier& wafer_id, - const SCT_ID* m_sctId, - const int samplesize, - const std::string& defectType, - const float threshold, - const std::string& defectList ) const; - - StatusCode createListChip( const Identifier& wafer_id, - const SCT_ID* m_sctId, - const int samplesize, - const std::string& defectType, - const float threshold, - const std::string& defectList ) const; - - StatusCode createListEff( const Identifier& wafer_id, - const SCT_ID* m_sctId, - const int samplesize, - const float eff ) const; - - StatusCode createListNO( const Identifier& wafer_id, - const SCT_ID* m_sctId, - const int samplesize, - const float noise_occ ) const; - - StatusCode createListRawOccu( const Identifier& wafer_id, - const SCT_ID* m_sctId, - const int samplesize, - const float raw_occu ) const; - - StatusCode createListBSErr(const Identifier& wafer_id, - const SCT_ID* m_sctId, - const int samplesize, - const std::string & errorList, - const std::string & probList) const ; - - //StatusCode createListBSErr( const Identifier& wafer_id, - // const unsigned long long n_events, - // const std::string& BSErrorType, - // const std::string& Ratio ) const; - - // StatusCode createListLA(const Identifier& wafer_id,const SCT_ID* m_sctId,const int samplesize, const int module, const float lorentz, const float MCW ) const; - StatusCode createListLA(const Identifier& wafer_id,const SCT_ID* m_sctId,const int samplesize, const int module, const float lorentz, const float err_lorentz, const float chisq, const float fitParam_a, const float err_a, const float fitParam_b, const float err_b, const float fitParam_sigma, const float err_sigma, const float MCW, const float err_MCW ) const; -/* StatusCode createListLA( const Identifier& wafer_id, - const SCT_ID* m_sctId, - const int samplesize, - const float lorentz, - const float MCW ) const; -*/ - StatusCode wrapUpNoisyChannel(); - StatusCode wrapUpDeadStrips(); - StatusCode wrapUpDeadChips(); - StatusCode wrapUpEfficiency(); - StatusCode wrapUpNoiseOccupancy(); - StatusCode wrapUpRawOccupancy(); - StatusCode wrapUpBSErrors(); - StatusCode wrapUpLorentzAngle(); - -private: - StoreGateSvc* m_detStore; - SG::ReadHandleKey<EventInfo> m_eventInfoKey; - - StatusCode registerIOV(const CLID& clid); - int stringToInt(const std::string& s) const; - - StatusCode streamOutCondObjects(const std::string & foldername); - StatusCode streamOutCondObjectsWithErrMsg(const std::string & foldername); - - StatusCode registerCondObjects(const std::string & foldername,const std::string & tagname); - StatusCode recordAndStream(const CondAttrListCollection* pCollection,const std::string & foldername, bool & flag); - StatusCode registerCondObjectsWithErrMsg(const std::string& foldername,const std::string& tagname); - // - coral::AttributeListSpecification* createBasicDbSpec(const bool capsFormat) const; - void setBasicValues(coral::AttributeList & attrList, const Identifier& wafer_id, const int samplesize,const SCT_ID* m_sctId, const bool capsFormat) const; - // small helper function - unsigned int computeIstrip4moncond(const Identifier& elementId) const; - - const CondAttrListCollection* getAttrListCollectionByFolder(const std::string&) const; - - // would it make sense to change the strings to properties? - // that would be a fairly simple fix - static std::string s_separator; - static std::string s_defectFolderName; - static std::string s_deadStripFolderName; - static std::string s_deadChipFolderName; - static std::string s_effFolderName; - static std::string s_noFolderName; - static std::string s_RawOccuFolderName; - static std::string s_BSErrFolderName; - static std::string s_LAFolderName; - // cache for the Collections, access by foldername - mutable std::map<const std::string, const CondAttrListCollection*> m_attrListCollectionMap; - CondAttrListCollection* m_attrListColl; - CondAttrListCollection* m_attrListColl_deadStrip; - CondAttrListCollection* m_attrListColl_deadChip; - CondAttrListCollection* m_attrListColl_eff; - CondAttrListCollection* m_attrListColl_no; - CondAttrListCollection* m_attrListColl_RawOccu; - CondAttrListCollection* m_attrListColl_BSErr; - CondAttrListCollection* m_attrListColl_LA; - BooleanProperty m_writeCondObjs; - BooleanProperty m_regIOV; - BooleanProperty m_readWriteCool; - BooleanProperty m_twoStepWriteReg; - BooleanProperty m_manualiov; - /*IntegerProperty m_regTime;*/ - IntegerProperty m_version; - /*IntegerProperty m_nhits_noisychip;*/ - /*IntegerProperty m_nhits_noisywafer;*/ - /*IntegerProperty m_nhits_noisymodule;*/ - IntegerProperty m_beginRun; - IntegerProperty m_endRun; - StringProperty m_streamName; - std::string m_tagID4NoisyStrips; - std::string m_tagID4DeadStrips; - std::string m_tagID4DeadChips; - std::string m_tagID4Efficiency; - std::string m_tagID4NoiseOccupancy; - std::string m_tagID4RawOccupancy; - std::string m_tagID4BSErrors; - std::string m_tagID4LorentzAngle; - - - IIOVRegistrationSvc* m_regSvc; - //IAthenaOutputStreamTool* m_streamer; - ToolHandle<IAthenaOutputStreamTool> m_streamer; - - //StringArrayProperty m_badElements; unused list of bad detector elements (= module sides) - std::set<Identifier> m_badIds; - bool m_defectRecorded; - bool m_deadStripRecorded; - bool m_deadChipRecorded; - bool m_effRecorded; - bool m_noRecorded; - bool m_RawOccuRecorded; - bool m_BSErrRecorded; - bool m_LARecorded; - const SCT_ID* m_pHelper; - // FIXME: this caches only the last call of getList. - // creating a hash of _all_ calls may be faster, but wastes a lot of memory - mutable std::string m_currentDefectList; -}; - -#endif // SCTCalibWriteSvc.h diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteTool.h new file mode 100644 index 0000000000000000000000000000000000000000..437cfe410103386c62b5e9d6b5cbf94ea56dd14a --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCTCalibWriteTool.h @@ -0,0 +1,242 @@ +/** -*- c++ -*- */ + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* +* @file SCTCalibWriteTool.h +* +* @brief Header file for the SCTCalibWriteTool class +* +* @author Jose E. Garcia +**/ + +#ifndef SCTCalibWriteTool_H +#define SCTCalibWriteTool_H + +//STL +#include <string> +#include <map> +#include <set> +#include <list> + +// Gaudi includes +#include "GaudiKernel/IInterface.h" +#include "GaudiKernel/IAlgTool.h" +//#include "GaudiKernel/ServiceHandle.h" +#include "GaudiKernel/ToolHandle.h" +#include "GaudiKernel/StatusCode.h" +#include "GaudiKernel/ClassID.h" + +#include "StoreGate/StoreGate.h" +#include "StoreGate/ReadHandleKey.h" + +#include "CoralBase/AttributeListSpecification.h" + +#include "AthenaPoolUtilities/AthenaAttributeList.h" +#include "AthenaBaseComps/AthAlgTool.h" + +// Athena includes +#include "Identifier/Identifier.h" + +// local includes +#include "InDetConditionsSummaryService/InDetHierarchy.h" + +//forward declarations +class IdentifierHash; +class SCT_ID; +class EventInfo; +class IIOVRegistrationSvc; +class IAthenaOutputStreamTool; +class CondAttrListCollection; +class StoreGateSvc; + +/** +** Algorithm to test writing conditions data and reading them back. +**/ +class SCTCalibWriteTool : public AthAlgTool { + + public: + // Constructor + SCTCalibWriteTool(const std::string& type, const std::string& name, const IInterface* parent); + // Destructor + ~SCTCalibWriteTool() {}; + + // overloading functions + virtual StatusCode initialize(); + virtual StatusCode finalize(); + static const InterfaceID & interfaceID(); + virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvIF); + + ///Manually get the data in the structure before proceding + virtual StatusCode fillData(); + + //I'm going to fill this from job options, so the callback version of fillData is not needed. + virtual StatusCode fillData(int& /*i */, std::list<std::string>& /*l*/) { //comment out unused parameters to prevent compiler warning + return StatusCode::FAILURE; + } + + std::string + addDefect(const std::string& defectlist,const int defectBeginChannel,const int defectEndChannel) const; + + std::string + addNumber(const std::string numStr,const unsigned long long number) const; + + std::string + createDefectString(const int defectBeginChannel,const int defectEndChannel) const; + + StatusCode + createCondObjects( const Identifier& wafer_id,const SCT_ID* m_sctId,const int samplesize,const std::string& defectType,const float threshold,const std::string& defectList ) const; + + StatusCode createListStrip( const Identifier& wafer_id, + const SCT_ID* m_sctId, + const int samplesize, + const std::string& defectType, + const float threshold, + const std::string& defectList ) const; + + StatusCode createListChip( const Identifier& wafer_id, + const SCT_ID* m_sctId, + const int samplesize, + const std::string& defectType, + const float threshold, + const std::string& defectList ) const; + + StatusCode createListEff( const Identifier& wafer_id, + const SCT_ID* m_sctId, + const int samplesize, + const float eff ) const; + + StatusCode createListNO( const Identifier& wafer_id, + const SCT_ID* m_sctId, + const int samplesize, + const float noise_occ ) const; + + StatusCode createListRawOccu( const Identifier& wafer_id, + const SCT_ID* m_sctId, + const int samplesize, + const float raw_occu ) const; + + StatusCode createListBSErr(const Identifier& wafer_id, + const SCT_ID* m_sctId, + const int samplesize, + const std::string & errorList, + const std::string & probList) const ; + + StatusCode createListLA(const Identifier& wafer_id, + const SCT_ID* m_sctId, + const int samplesize, + const int module, + const float lorentz, + const float err_lorentz, + const float chisq, + const float fitParam_a, + const float err_a, + const float fitParam_b, + const float err_b, + const float fitParam_sigma, + const float err_sigma, + const float MCW, + const float err_MCW ) const; + + StatusCode wrapUpNoisyChannel(); + StatusCode wrapUpDeadStrips(); + StatusCode wrapUpDeadChips(); + StatusCode wrapUpEfficiency(); + StatusCode wrapUpNoiseOccupancy(); + StatusCode wrapUpRawOccupancy(); + StatusCode wrapUpBSErrors(); + StatusCode wrapUpLorentzAngle(); + + private: + StoreGateSvc* m_detStore; + SG::ReadHandleKey<EventInfo> m_eventInfoKey; + + StatusCode registerIOV(const CLID& clid); + int stringToInt(const std::string& s) const; + + StatusCode streamOutCondObjects(const std::string & foldername); + StatusCode streamOutCondObjectsWithErrMsg(const std::string & foldername); + + StatusCode registerCondObjects(const std::string & foldername,const std::string & tagname); + StatusCode recordAndStream(const CondAttrListCollection* pCollection,const std::string & foldername, bool & flag); + StatusCode registerCondObjectsWithErrMsg(const std::string& foldername,const std::string& tagname); + + coral::AttributeListSpecification* createBasicDbSpec(const bool capsFormat) const; + void setBasicValues(coral::AttributeList & attrList, const Identifier& wafer_id, const int samplesize,const SCT_ID* m_sctId, const bool capsFormat) const; + // small helper function + unsigned int computeIstrip4moncond(const Identifier& elementId) const; + + const CondAttrListCollection* getAttrListCollectionByFolder(const std::string&) const; + + // would it make sense to change the strings to properties? + // that would be a fairly simple fix + static std::string s_separator; + static std::string s_defectFolderName; + static std::string s_deadStripFolderName; + static std::string s_deadChipFolderName; + static std::string s_effFolderName; + static std::string s_noFolderName; + static std::string s_RawOccuFolderName; + static std::string s_BSErrFolderName; + static std::string s_LAFolderName; + + // cache for the Collections, access by foldername + mutable std::map<const std::string, const CondAttrListCollection*> m_attrListCollectionMap; + CondAttrListCollection* m_attrListColl; + CondAttrListCollection* m_attrListColl_deadStrip; + CondAttrListCollection* m_attrListColl_deadChip; + CondAttrListCollection* m_attrListColl_eff; + CondAttrListCollection* m_attrListColl_no; + CondAttrListCollection* m_attrListColl_RawOccu; + CondAttrListCollection* m_attrListColl_BSErr; + CondAttrListCollection* m_attrListColl_LA; + BooleanProperty m_writeCondObjs; + BooleanProperty m_regIOV; + BooleanProperty m_readWriteCool; + BooleanProperty m_twoStepWriteReg; + BooleanProperty m_manualiov; + /*IntegerProperty m_regTime;*/ + IntegerProperty m_version; + /*IntegerProperty m_nhits_noisychip;*/ + /*IntegerProperty m_nhits_noisywafer;*/ + /*IntegerProperty m_nhits_noisymodule;*/ + IntegerProperty m_beginRun; + IntegerProperty m_endRun; + StringProperty m_streamName; + std::string m_tagID4NoisyStrips; + std::string m_tagID4DeadStrips; + std::string m_tagID4DeadChips; + std::string m_tagID4Efficiency; + std::string m_tagID4NoiseOccupancy; + std::string m_tagID4RawOccupancy; + std::string m_tagID4BSErrors; + std::string m_tagID4LorentzAngle; + + IIOVRegistrationSvc* m_regSvc; + IAthenaOutputStreamTool* m_streamer; + //ToolHandle<IAthenaOutputStreamTool> m_streamer; + + //StringArrayProperty m_badElements; unused list of bad detector elements (= module sides) + std::set<Identifier> m_badIds; + bool m_defectRecorded; + bool m_deadStripRecorded; + bool m_deadChipRecorded; + bool m_effRecorded; + bool m_noRecorded; + bool m_RawOccuRecorded; + bool m_BSErrRecorded; + bool m_LARecorded; + const SCT_ID* m_pHelper; + // FIXME: this caches only the last call of getList. + // creating a hash of _all_ calls may be faster, but wastes a lot of memory + mutable std::string m_currentDefectList; +}; + +inline const InterfaceID & SCTCalibWriteTool::interfaceID() { + static const InterfaceID IID("SCTCalibWriteTool",1,0); + return IID; +} + +#endif // SCTCalibWriteTool.h diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCT_LorentzAngleFunc.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCT_LorentzAngleFunc.h index 748ab1caa5941c0f16f9577366f9687350a29495..6f71c74312ec83326c251f049ba22a5db0fefccf 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCT_LorentzAngleFunc.h +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/SCT_CalibAlgs/SCT_LorentzAngleFunc.h @@ -7,21 +7,19 @@ #include "TMath.h" Double_t -LA_func(Double_t *x, Double_t *par){ - const Int_t n = 1000; // number of integration step - const Double_t xmin = x[0] - 5.0*par[3]; - const Double_t xmax = x[0] + 5.0*par[3]; - const Double_t h = (xmax - xmin)/(n - 1); - const Double_t pi = 3.14159265; - Double_t sum = 0; - Double_t x_ = xmin; - Double_t LA_sum = 0; - for (Int_t i=1; i<n; i++) { - LA_sum= par[0]*TMath::Abs(TMath::Tan(x_*pi/180)-TMath::Tan(par[1]*pi/180))+par[2]; - sum += LA_sum * 0.017455/TMath::Sqrt(2*pi)/(par[3]*pi/180)*TMath::Exp(-(x[0]*pi/180 - x_*pi/180 )*(x[0]*pi/180 - x_*pi/180 )/(2*par[3]*pi/180*par[3]*pi/180))*h; - x_ += h; - } - return sum; +LA_func(Double_t *x, Double_t *par) { + const Int_t n = 1000; // number of integration step + const Double_t xmin = x[0] - 5.0*par[3]; + const Double_t xmax = x[0] + 5.0*par[3]; + const Double_t h = (xmax - xmin)/(n - 1); + const Double_t pi = 3.14159265; + Double_t sum = 0; + Double_t x_ = xmin; + Double_t LA_sum = 0; + for (Int_t i=1; i<n; i++) { + LA_sum= par[0]*TMath::Abs(TMath::Tan(x_*pi/180)-TMath::Tan(par[1]*pi/180))+par[2]; + sum += LA_sum * 0.017455/TMath::Sqrt(2*pi)/(par[3]*pi/180)*TMath::Exp(-(x[0]*pi/180 - x_*pi/180 )*(x[0]*pi/180 - x_*pi/180 )/(2*par[3]*pi/180*par[3]*pi/180))*h; + x_ += h; + } + return sum; } - - diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/IElementStreamer.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/IElementStreamer.cxx index a6463d789eab951aed7ba5043e136700bbe24425..f60cc25aa3078fb16e3cb716c1dc15b066a95cb3 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/IElementStreamer.cxx +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/IElementStreamer.cxx @@ -8,39 +8,38 @@ */ #include "IElementStreamer.h" +namespace SCT_CalibAlgs { + +unsigned int IElementStreamer::m_depth=0; +unsigned int IElementStreamer::m_nodeIndex=0; -namespace SCT_CalibAlgs{ - unsigned int IElementStreamer::m_depth=0; - unsigned int IElementStreamer::m_nodeIndex=0; IElementStreamer::IElementStreamer(const std::string & name, const std::map<std::string, std::string> & attributeMap, std::ostream & os): -m_name(name), m_os(os),m_nodeId(m_nodeIndex){ - std::map<std::string, std::string>::const_iterator i(attributeMap.begin()); - std::map<std::string, std::string>::const_iterator end(attributeMap.end()); - for(;i!=end;++i){ - m_attributeNames.push_back(i->first); - m_attributeValues.push_back(i->second); - } - ++m_depth; - ++m_nodeIndex; + m_name(name), m_os(os),m_nodeId(m_nodeIndex) { + std::map<std::string, std::string>::const_iterator i(attributeMap.begin()); + std::map<std::string, std::string>::const_iterator end(attributeMap.end()); + for(; i!=end; ++i) { + m_attributeNames.push_back(i->first); + m_attributeValues.push_back(i->second); + } + ++m_depth; + ++m_nodeIndex; } IElementStreamer::IElementStreamer(const std::string & name, const std::vector<std::string> & attributeNames, const std::vector<std::string> & attributeValues, std::ostream & os): -m_name(name), m_attributeNames(attributeNames), m_attributeValues(attributeValues),m_os(os),m_nodeId(m_nodeIndex){ - ++m_depth; - ++m_nodeIndex; + m_name(name), m_attributeNames(attributeNames), m_attributeValues(attributeValues),m_os(os),m_nodeId(m_nodeIndex) { + ++m_depth; + ++m_nodeIndex; } -IElementStreamer::IElementStreamer(const std::string & name, const std::string & attributeName, const std::string & attributeValue, std::ostream & os):m_name(name),m_os(os), m_nodeId(m_nodeIndex){ - m_attributeNames.push_back(attributeName); - m_attributeValues.push_back(attributeValue); - ++m_depth; - ++m_nodeIndex; -} -IElementStreamer::~IElementStreamer(){ - --m_depth; +IElementStreamer::IElementStreamer(const std::string & name, const std::string & attributeName, const std::string & attributeValue, std::ostream & os):m_name(name),m_os(os), m_nodeId(m_nodeIndex) { + m_attributeNames.push_back(attributeName); + m_attributeValues.push_back(attributeValue); + ++m_depth; + ++m_nodeIndex; } -} - - +IElementStreamer::~IElementStreamer() { + --m_depth; +} +} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/IElementStreamer.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/IElementStreamer.h index b00c7eb5c4d43b0099a89bf595e821de80da7524..5856d23a87d306b01e2581056d0a1b6c1e76ef4c 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/IElementStreamer.h +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/IElementStreamer.h @@ -12,28 +12,29 @@ #include <string> #include <map> #include <vector> -namespace SCT_CalibAlgs{ -class IElementStreamer{ -protected: - std::string m_name; - std::vector<std::string> m_attributeNames; - std::vector<std::string> m_attributeValues; - std::ostream & m_os; - static unsigned int m_depth; - static unsigned int m_nodeIndex; - unsigned int m_nodeId; - -public: - IElementStreamer(const std::string & name, const std::map<std::string, std::string> & attributeMap, std::ostream & os=std::cout); - IElementStreamer(const std::string & name, const std::string & attributeName, const std::string & attributeValue, std::ostream & os=std::cout); - IElementStreamer(const std::string & name, const std::vector<std::string> & attributeNames, const std::vector<std::string> & attributeValues, std::ostream & os=std::cout); - ~IElementStreamer(); - template<class T> - void value(const T & v){ - m_os<<v; - } +namespace SCT_CalibAlgs { + +class IElementStreamer { + + protected: + std::string m_name; + std::vector<std::string> m_attributeNames; + std::vector<std::string> m_attributeValues; + std::ostream & m_os; + static unsigned int m_depth; + static unsigned int m_nodeIndex; + unsigned int m_nodeId; + + public: + IElementStreamer(const std::string & name, const std::map<std::string, std::string> & attributeMap, std::ostream & os=std::cout); + IElementStreamer(const std::string & name, const std::string & attributeName, const std::string & attributeValue, std::ostream & os=std::cout); + IElementStreamer(const std::string & name, const std::vector<std::string> & attributeNames, const std::vector<std::string> & attributeValues, std::ostream & os=std::cout); + ~IElementStreamer(); + template<class T> + void value(const T & v) { + m_os<<v; + } }; + } #endif - - diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/ISCT_CalibHistoSvc.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/ISCT_CalibHistoSvc.cxx deleted file mode 100644 index 434be7c1f3fdae8a652d1058bd8cfe3f74948821..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/ISCT_CalibHistoSvc.cxx +++ /dev/null @@ -1,100 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - - -/** - * @file ISCT_CalibHistoSvc.cxx - * Implementation file to interface class for histograms in the SCT_CalibAlgs package - * @author Shaun Roe -**/ -#include "SCT_CalibAlgs/ISCT_CalibHistoSvc.h" -#include "TH1I.h" -#include "TH1F.h" -#include "TH2F.h" -#include "TMath.h" -#include <stdexcept> // out_of_range exception - -int ISCT_CalibHistoSvc::m_nLb=0; -int ISCT_CalibHistoSvc::m_nLbMerge=0; - -ISCT_CalibHistoSvc::ISCT_CalibHistoSvc():m_numberOfEventsHisto(0),m_thistSvc(0),m_pSCTHelper(0){ - //std::cout<<"Instantiation of ISCT_CalibHistoSvc"<<std::endl; - //nop -} - -int -ISCT_CalibHistoSvc::getNumberOfEventsInBin(const int nbin){ - if (m_numberOfEventsHisto) return m_numberOfEventsHisto->GetBinContent(nbin); - std::cout << "ERROR: a histogram pointer, m_numberOfEventsHisto, is zero" << std::endl; - return 0; -} - -int -ISCT_CalibHistoSvc::size(){ - return m_numberOfEventsHisto->GetEntries(); -} - - -int -ISCT_CalibHistoSvc::size(const int histogramIndex){ - TH1F* pHisto=0; - int result=0; - try{ - pHisto=m_phistoVector.at(histogramIndex); - result = pHisto->GetEntries(); - } catch (const std::out_of_range& outOfRange) { - //do nothing, result is zero if the vector<>.at() throws - } - return result; -} - -double -ISCT_CalibHistoSvc::getBinForHistogramIndex(const int bin, const int histogramIndex){ - TH1F* pHisto=0; - double result=0.0; - try{ - pHisto=m_phistoVector.at(histogramIndex); - result = pHisto->GetBinContent(bin); - } catch (const std::out_of_range& outOfRange) { - //do nothing, result is zero if the vector<>.at() throws - } - return result; -} - -void -//ISCT_CalibHistoSvc::binHistograms(const int eventsPerWindow){ -ISCT_CalibHistoSvc::binHistograms(const int nLbMerged){ - - int nLb = numberOfLb(); - int yAxisBins = TMath::Ceil(1.0*nLb/nLbMerged); - // int totalEventNumber = m_numberOfEventsHisto->GetEntries(); - - // int yAxisBins = TMath::Ceil(1.0*totalEventNumber/eventsPerWindow); - for (std::vector<TH2F *>::iterator it = m_phistoVector2D.begin() ; it != m_phistoVector2D.end(); ++it){ - (*it)->SetBins(768, -0.5, 768+0.5 ,yAxisBins,0.5,nLbMerged*yAxisBins+0.5); - } - // std::cout<<eventsPerWindow<<std::endl; - -} - -void -ISCT_CalibHistoSvc::setNumberOfLb(const int nLb){ - m_nLb=nLb; -} - -int -ISCT_CalibHistoSvc::numberOfLb(){ - return m_nLb; -} - -void -ISCT_CalibHistoSvc::setLbToMerge(const int nLbMerge){ - m_nLbMerge=nLbMerge; -} - -int -ISCT_CalibHistoSvc::LbToMerge(){ - return m_nLbMerge; -} - diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/ISCT_CalibHistoTool.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/ISCT_CalibHistoTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..20a73ad7c9bf06fee508e0fdb24b0ecedbd65ca1 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/ISCT_CalibHistoTool.cxx @@ -0,0 +1,100 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +/** + * @file ISCT_CalibHistoTool.cxx + * Implementation file to interface class for histograms in the SCT_CalibAlgs package + * @author Shaun Roe +**/ +#include "SCT_CalibAlgs/ISCT_CalibHistoTool.h" +#include "TH1I.h" +#include "TH1F.h" +#include "TH2F.h" +#include "TMath.h" +#include <stdexcept> // out_of_range exception + +int ISCT_CalibHistoTool::m_nLb=0; +int ISCT_CalibHistoTool::m_nLbMerge=0; + +ISCT_CalibHistoTool::ISCT_CalibHistoTool():m_numberOfEventsHisto(0),m_thistSvc(0),m_pSCTHelper(0) { + //std::cout<<"Instantiation of ISCT_CalibHistoTool"<<std::endl; + //nop +} + +int +ISCT_CalibHistoTool::getNumberOfEventsInBin(const int nbin) { + if (m_numberOfEventsHisto) return m_numberOfEventsHisto->GetBinContent(nbin); + std::cout << "ERROR: a histogram pointer, m_numberOfEventsHisto, is zero" << std::endl; + return 0; +} + +int +ISCT_CalibHistoTool::size() { + return m_numberOfEventsHisto->GetEntries(); +} + + +int +ISCT_CalibHistoTool::size(const int histogramIndex) { + TH1F* pHisto=0; + int result=0; + try { + pHisto=m_phistoVector.at(histogramIndex); + result = pHisto->GetEntries(); + } catch (const std::out_of_range& outOfRange) { + //do nothing, result is zero if the vector<>.at() throws + } + return result; +} + +double +ISCT_CalibHistoTool::getBinForHistogramIndex(const int bin, const int histogramIndex) { + TH1F* pHisto=0; + double result=0.0; + try { + pHisto=m_phistoVector.at(histogramIndex); + result = pHisto->GetBinContent(bin); + } catch (const std::out_of_range& outOfRange) { + //do nothing, result is zero if the vector<>.at() throws + } + return result; +} + +void +//ISCT_CalibHistoTool::binHistograms(const int eventsPerWindow){ +ISCT_CalibHistoTool::binHistograms(const int nLbMerged) { + + int nLb = numberOfLb(); + int yAxisBins = TMath::Ceil(1.0*nLb/nLbMerged); + // int totalEventNumber = m_numberOfEventsHisto->GetEntries(); + + // int yAxisBins = TMath::Ceil(1.0*totalEventNumber/eventsPerWindow); + for (std::vector<TH2F *>::iterator it = m_phistoVector2D.begin() ; it != m_phistoVector2D.end(); ++it) { + (*it)->SetBins(768, -0.5, 768+0.5,yAxisBins,0.5,nLbMerged*yAxisBins+0.5); + } + // std::cout<<eventsPerWindow<<std::endl; + +} + +void +ISCT_CalibHistoTool::setNumberOfLb(const int nLb) { + m_nLb=nLb; +} + +int +ISCT_CalibHistoTool::numberOfLb() { + return m_nLb; +} + +void +ISCT_CalibHistoTool::setLbToMerge(const int nLbMerge) { + m_nLbMerge=nLbMerge; +} + +int +ISCT_CalibHistoTool::LbToMerge() { + return m_nLbMerge; +} + diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalib.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalib.cxx index f8643b5bbafd719792eec27e2fe71f93b0e4eb5a..af1368e69fbc2e4644da1e1d5f1b8dd82365566c 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalib.cxx +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalib.cxx @@ -21,11 +21,11 @@ #include "SCT_CalibAlgs/SCTCalib.h" #include "SCT_CalibAlgs/SCT_LorentzAngleFunc.h" #include "SCT_CalibUtilities.h" -#include "SCT_CalibBsErrorSvc.h" -#include "SCT_CalibLbSvc.h" -#include "SCT_CalibModuleListSvc.h" +#include "SCT_CalibBsErrorTool.h" +#include "SCT_CalibLbTool.h" +#include "SCT_CalibModuleListTool.h" #include "SCT_CalibEventInfo.h" -#include "SCT_CalibHitmapSvc.h" +#include "SCT_CalibHitmapTool.h" #include "XmlHeader.h" #include "XmlStreamer.h" @@ -74,7 +74,7 @@ const std::string shortNames[] = { "EndCapC", "Barrel", "EndCapA" }; const std::string detectorPaths[] = { "SCTEC", "SCTB", "SCTEA" }; bool areConsecutiveIntervals(const std::pair<int, int> &i1, const std::pair<int, int> &i2, const int withinLimits) { - return i1.second <= (i2.first + withinLimits); + return i1.second <= (i2.first + withinLimits); } /** void @@ -86,69 +86,69 @@ const std::string xmlHeader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); const std::string linefeed("\n"); std::string associateStylesheet(const std::string &stylesheetName) { - return std::string("<?xml-stylesheet type=\"text/xsl\" href=\"")+stylesheetName+"\"?>"; + return std::string("<?xml-stylesheet type=\"text/xsl\" href=\"")+stylesheetName+"\"?>"; } template <class T> std::string xmlPartData(const Bec bec, const int layer, const int eta, const std::string & dataName, const T data) { - //agrohsje added spaces for proper output format - ostringstream os; - const std::string thisPart=shortNames[bec2Index(bec)]; - os<<" <parts>"<<endl - <<" "<<xmlValue("part",thisPart)<<endl - <<" "<<xmlValue("layer", layer)<<endl - <<" "; - std::string barrelEtaXml=xmlValue("eta", "all"); - std::string endcapEtaXml=xmlValue("eta",eta); - if(bec==BARREL) os<<barrelEtaXml; - else os<<endcapEtaXml; - os<<endl - <<" "<<xmlValue(dataName, data)<<endl - <<" </parts>"<<endl; - return os.str(); + //agrohsje added spaces for proper output format + ostringstream os; + const std::string thisPart=shortNames[bec2Index(bec)]; + os<<" <parts>"<<endl + <<" "<<xmlValue("part",thisPart)<<endl + <<" "<<xmlValue("layer", layer)<<endl + <<" "; + std::string barrelEtaXml=xmlValue("eta", "all"); + std::string endcapEtaXml=xmlValue("eta",eta); + if(bec==BARREL) os<<barrelEtaXml; + else os<<endcapEtaXml; + os<<endl + <<" "<<xmlValue(dataName, data)<<endl + <<" </parts>"<<endl; + return os.str(); } template <class T> std::string xmlModuleData(const Bec bec, const int layer, const int side, const int phi, const int eta, const std::string & dataName, const T data, const std::string & serial,const std::string & listOfErrors) { - //xmlModuleData(const Bec bec, const int layer, const int side, const int phi, const int eta, const std::string & dataName, const T data, const std::string & serial, const ostringstream listOfErrors){ - //agasconb added to generate BSErrors file for individual modules - ostringstream os; - os<<" <module>"<<endl - <<" "<<xmlValue("SN", serial)<<endl; - - if (bec==ENDCAP_C) - os<<" "<<xmlValue("barrel_endcap","-2")<<endl; - else if (bec==BARREL) - os<<" "<<xmlValue("barrel_endcap","0")<<endl; - else if (bec==ENDCAP_A) - os<<" "<<xmlValue("barrel_endcap","2")<<endl; - os<<" "<<xmlValue("layer", layer)<<endl - <<" "<<xmlValue("side", side)<<endl - <<" "<<xmlValue("eta", eta)<<endl - <<" "<<xmlValue("phi", phi)<<endl - <<" "<<xmlValue(dataName, data)<<endl; - os<<listOfErrors; - os<<" </module>"<<endl; - return os.str(); + //xmlModuleData(const Bec bec, const int layer, const int side, const int phi, const int eta, const std::string & dataName, const T data, const std::string & serial, const ostringstream listOfErrors){ + //agasconb added to generate BSErrors file for individual modules + ostringstream os; + os<<" <module>"<<endl + <<" "<<xmlValue("SN", serial)<<endl; + + if (bec==ENDCAP_C) + os<<" "<<xmlValue("barrel_endcap","-2")<<endl; + else if (bec==BARREL) + os<<" "<<xmlValue("barrel_endcap","0")<<endl; + else if (bec==ENDCAP_A) + os<<" "<<xmlValue("barrel_endcap","2")<<endl; + os<<" "<<xmlValue("layer", layer)<<endl + <<" "<<xmlValue("side", side)<<endl + <<" "<<xmlValue("eta", eta)<<endl + <<" "<<xmlValue("phi", phi)<<endl + <<" "<<xmlValue(dataName, data)<<endl; + os<<listOfErrors; + os<<" </module>"<<endl; + return os.str(); } std::string normalizeList( const std::string& strList ) { - std::string str = strList; - if ( !str.empty() ) { - //--- Remove 1st & last space - str = str.substr( 1, str.length()-2 ); - //--- Replace double space to single space - std::string strSingleSpace = " "; - std::string strDoubleSpace = " "; - std::string::size_type pos = 0; - while( pos =str.find( strDoubleSpace, pos), pos != std::string::npos ) { - str.erase( pos, strSingleSpace.length() ); - pos += strSingleSpace.length(); - } - } - return str; + std::string str = strList; + if ( !str.empty() ) { + //--- Remove 1st & last space + str = str.substr( 1, str.length()-2 ); + //--- Replace double space to single space + std::string strSingleSpace = " "; + std::string strDoubleSpace = " "; + std::string::size_type pos = 0; + while( pos =str.find( strDoubleSpace, pos), pos != std::string::npos ) { + str.erase( pos, strSingleSpace.length() ); + pos += strSingleSpace.length(); + } + } + return str; } } @@ -157,144 +157,143 @@ normalizeList( const std::string& strList ) { ////////////////////////////////////////////////////////////////////////////////////// SCTCalib::SCTCalib( const std::string& name, ISvcLocator* pSvcLocator ) : - AthAlgorithm( name, pSvcLocator ), - p_sgSvc ("StoreGateSvc",name), - m_thistSvc(0), - m_pSCTHelper(0), - m_eventInfoKey(std::string("ByteStreamEventInfo")), - m_pCalibWriteSvc ("SCTCalibWriteSvc",name), - m_calibHitmapSvc ("SCT_CalibHitmapSvc",name), - m_calibBsErrSvc ("SCT_CalibBsErrorSvc",name), - m_calibLbSvc ("SCT_CalibLbSvc",name), - m_calibModuleListSvc ("SCT_CalibModuleListSvc",name), - m_calibEvtInfoSvc ("SCT_CalibEventInfo",name), - m_numOfEventsProcessed(0), - - m_numOfLBsProcessed(0), - m_absolutetriplimit(0), - m_relativetriplimit(0), - m_numberOfEventsHist(0), - m_inputHist(0), - /* m_readHist(false), */ - m_MAXHASH(0) { - declareProperty( "RunNumber", m_runNumber ); - declareProperty( "RunStartTime", m_runStartTime ); - declareProperty( "RunEndTime", m_runEndTime ); - declareProperty( "LBMax", m_LBMax = "1000"); - declareProperty( "UseDCS", m_useDCS = false ); - declareProperty( "UseConfiguration", m_useConfiguration = true ); - declareProperty( "UseCalibration", m_useCalibration = true ); - declareProperty( "UseMajority", m_useMajority = true ); - declareProperty( "UseBSError", m_useBSError = false ); - declareProperty( "InputBS", m_input_bs ); - declareProperty( "InputHist", m_input_hist ); - declareProperty( "ReadBS", m_readBS = false ); - declareProperty( "HistBefore2010", m_histBefore2010 = false ); - declareProperty( "DoHitMaps", m_doHitMaps = true ); - declareProperty( "LbsPerWindow", m_nLbsMerged = 20 ); - // declareProperty( "EventsPerWindow", m_eventsPerWindow = 10000 ); - declareProperty( "ReadHitMaps", m_readHitMaps = false ); - declareProperty( "DoBSErrors", m_doBSErrors = false ); - declareProperty( "DoNoisyStrip", m_doNoisyStrip = true ); - declareProperty( "DoNoisyLB", m_doNoisyLB = true ); - declareProperty( "DoHV", m_doHV = false ); - declareProperty( "DoDeadStrip", m_doDeadStrip = false ); - declareProperty( "DoDeadChip", m_doDeadChip = false ); - declareProperty( "DoNoiseOccupancy", m_doNoiseOccupancy = false ); - declareProperty( "DoRawOccupancy", m_doRawOccupancy = false ); - declareProperty( "DoEfficiency", m_doEfficiency = false ); - declareProperty( "DoBSErrorDB", m_doBSErrorDB = false ); - declareProperty( "DoLorentzAngle", m_doLorentzAngle = false ); - declareProperty( "WriteToCool", m_writeToCool = true ); - //reinstated 21 May - declareProperty( "NoisyUpdate", m_noisyUpdate = true ); - declareProperty( "NoisyUploadTest", m_noisyUploadTest = true ); - declareProperty( "NoisyModuleAverageInDB", m_noisyModuleAverageInDB = -1. ); - declareProperty( "NoisyStripLastRunInDB", m_noisyStripLastRunInDB = -999 ); - declareProperty( "NoisyStripAverageInDB", m_noisyStripAverageInDB = -999. ); - declareProperty( "NoisyModuleList", m_noisyModuleList = 200 ); - declareProperty( "NoisyModuleDiff", m_noisyModuleDiff = 0.200 ); - declareProperty( "NoisyStripDiff", m_noisyStripDiff = 128. ); - - declareProperty( "NoisyMinStat", m_noisyMinStat = 50000 ); - declareProperty( "NoisyStripAll", m_noisyStripAll = true ); - declareProperty( "NoisyStripThrDef", m_noisyStripThrDef = true ); - declareProperty( "NoisyStripThrOffline", m_noisyStripThrOffline = 1.500E-2 ); - declareProperty( "NoisyStripThrOnline", m_noisyStripThrOnline = 1.500E-3 ); - declareProperty( "NoisyWaferFinder", m_noisyWaferFinder = true ); - declareProperty( "NoisyWaferWrite", m_noisyWaferWrite = true ); - declareProperty( "NoisyWaferAllStrips", m_noisyWaferAllStrips = true ); - declareProperty( "NoisyWaferThrBarrel", m_noisyWaferThrBarrel = 1.000E-4 ); - declareProperty( "NoisyWaferThrECA", m_noisyWaferThrECA = 1.000E-4 ); - declareProperty( "NoisyWaferThrECC", m_noisyWaferThrECC = 1.000E-4 ); - declareProperty( "NoisyWaferFraction", m_noisyWaferFraction = 0.500 ); - declareProperty( "NoisyChipFraction", m_noisyChipFraction = 0.500 ); - declareProperty( "HVBinWidth", m_maxtbins = 5 ); - declareProperty( "HVQlength", m_maxq = 100 ); - declareProperty( "HVAbsTripLimit", m_absolutetriplimit = 5. ); - declareProperty( "HVRelTripLimit", m_relativetriplimit = 4. ); - declareProperty( "OutputLowHits", m_outputlowhits = false ); - declareProperty( "LowHitsCut", m_lowHitCut = 100 ); - declareProperty( "DeadStripMinStat", m_deadStripMinStat = 200000 ); - declareProperty( "DeadStripMinStatBusy", m_deadStripMinStatBusy = 1600000 ); - declareProperty( "DeadChipMinStat", m_deadChipMinStat = 200000 ); - declareProperty( "DeadStripSignificance", m_deadStripSignificance = 10 ); - declareProperty( "DeadChipSignificance", m_deadChipSignificance = 10 ); - declareProperty( "BusyThr4DeadFinding", m_busyThr4DeadFinding = 1E-4 ); - declareProperty( "NoisyThr4DeadFinding", m_noisyThr4DeadFinding = 1.500E-3 ); - declareProperty( "DeadChipUploadTest", m_deadChipUploadTest = true ); - declareProperty( "DeadStripUploadTest", m_deadStripUploadTest = true ); - - declareProperty( "NoiseOccupancyTriggerAware",m_noiseOccupancyTriggerAware = true ); - declareProperty( "NoiseOccupancyMinStat", m_noiseOccupancyMinStat = 50000 ); - declareProperty( "RawOccupancyMinStat", m_rawOccupancyMinStat = 50000 ); - declareProperty( "EfficiencyMinStat", m_efficiencyMinStat = 50000 ); - declareProperty( "BSErrorDBMinStat", m_BSErrorDBMinStat = 50000 ); - declareProperty( "LorentzAngleMinStat", m_LorentzAngleMinStat = 50000 ); - - declareProperty( "LorentzAngleDebugMode", m_LorentzAngleDebugMode = true ); - - declareProperty( "TagID4NoisyStrips", m_tagID4NoisyStrips = "SctDerivedMonitoring-001-00" ); - declareProperty( "TagID4DeadStrips", m_tagID4DeadStrips = "SctDerivedDeadStrips-001-00" ); - declareProperty( "TagID4DeadChips", m_tagID4DeadChips = "SctDerivedDeadChips-001-00" ); - declareProperty( "TagID4NoiseOccupancy", m_tagID4NoiseOccupancy = "SctDerivedNoiseOccupancy-001-00" ); - declareProperty( "TagID4RawOccupancy", m_tagID4RawOccupancy = "SctDerivedRawOccupancy-001-00" ); - declareProperty( "TagID4Efficiency", m_tagID4Efficiency = "SctDerivedEfficiency-001-00" ); - declareProperty( "TagID4BSErrors", m_tagID4BSErrors = "SctDerivedBSErrors-000-00" ); - declareProperty( "TagID4LorentzAngle", m_tagID4LorentzAngle = "SctDerivedLorentzAngle-000-00" ); - - declareProperty( "BadStripsAllFile", m_badStripsAllFile = "BadStripsAllFile.xml" ); - declareProperty( "BadStripsNewFile", m_badStripsNewFile = "BadStripsNewFile.xml" ); - declareProperty( "BadStripsSummaryFile", m_badStripsSummaryFile = "BadStripsSummaryFile.xml" ); - declareProperty( "BadModulesFile", m_badModulesFile = "BadModulesFile.xml" ); - declareProperty( "DeadStripsFile", m_deadStripsFile = "DeadStripsFile.xml" ); - declareProperty( "DeadChipsFile", m_deadChipsFile = "DeadChipsFile.xml" ); - declareProperty( "DeadSummaryFile", m_deadSummaryFile = "DeadSummaryFile.xml" ); - - declareProperty( "NoiseOccupancyFile", m_noiseOccupancyFile = "NoiseOccupancyFile.xml" ); - declareProperty( "NoiseOccupancySummaryFile", m_noiseOccupancySummaryFile = "NoiseOccupancySummaryFile.xml" ); - declareProperty( "RawOccupancySummaryFile", m_rawOccupancySummaryFile = "RawOccupancySummaryFile.xml" ); - declareProperty( "EfficiencySummaryFile", m_efficiencySummaryFile = "EfficiencySummaryFile.xml" ); - declareProperty( "EfficiencyModuleFile", m_efficiencyModuleFile = "EfficiencyModuleSummary.xml" ); - declareProperty( "BSErrorSummaryFile", m_BSErrorSummaryFile = "BSErrorSummaryFile.xml" ); - declareProperty( "BSErrorModuleFile", m_BSErrorModuleFile = "BSErrorModuleSummary.xml" ); - declareProperty( "LorentzAngleFile", m_LorentzAngleFile = "LorentzAngleFile.xml" ); - declareProperty( "LorentzAngleSummaryFile", m_LorentzAngleSummaryFile = "LorentzAngleSummaryFile.xml" ); - - m_evt = 0; - m_numberOfEvents = 0; - m_eventCounter = 0; - m_maxentry = 0; - m_timeStampBegin = std::numeric_limits<int>::max(); - m_timeStampEnd = -999; - m_LBBegin = std::numeric_limits<int>::max(); - m_LBEnd = -999; - m_LBRange = -999; - - //--- for HV trip - m_phvtripFirstTime = 2000000000; - m_phvtripPrevTime = 0; - m_readHIST = m_doNoiseOccupancy || m_doRawOccupancy || m_doEfficiency || m_doBSErrorDB || m_doLorentzAngle; + AthAlgorithm( name, pSvcLocator ), + p_sgSvc ("StoreGateSvc",name), + m_thistSvc(0), + m_pSCTHelper(0), + m_eventInfoKey(std::string("ByteStreamEventInfo")), + //m_pCalibWriteTool ("SCTCalibWriteTool"), + //m_calibHitmapTool ("SCT_CalibHitmapTool"), + //m_calibBsErrTool ("SCT_CalibBsErrorTool"), + //m_calibLbTool ("SCT_CalibLbTool"), + //m_calibModuleListTool ("SCT_CalibModuleListTool"), + //m_calibEvtInfoTool ("SCT_CalibEventInfo"), + m_numOfEventsProcessed(0), + m_numOfLBsProcessed(0), + m_absolutetriplimit(0), + m_relativetriplimit(0), + m_numberOfEventsHist(0), + m_inputHist(0), + /* m_readHist(false), */ + m_MAXHASH(0) +{ + declareProperty( "RunNumber", m_runNumber ); + declareProperty( "RunStartTime", m_runStartTime ); + declareProperty( "RunEndTime", m_runEndTime ); + declareProperty( "LBMax", m_LBMax = "1000"); + declareProperty( "UseDCS", m_useDCS = false ); + declareProperty( "UseConfiguration", m_useConfiguration = true ); + declareProperty( "UseCalibration", m_useCalibration = true ); + declareProperty( "UseMajority", m_useMajority = true ); + declareProperty( "UseBSError", m_useBSError = false ); + declareProperty( "InputBS", m_input_bs ); + declareProperty( "InputHist", m_input_hist ); + declareProperty( "ReadBS", m_readBS = false ); + declareProperty( "HistBefore2010", m_histBefore2010 = false ); + declareProperty( "DoHitMaps", m_doHitMaps = true ); + declareProperty( "LbsPerWindow", m_nLbsMerged = 20 ); + declareProperty( "ReadHitMaps", m_readHitMaps = false ); + declareProperty( "DoBSErrors", m_doBSErrors = false ); + declareProperty( "DoNoisyStrip", m_doNoisyStrip = true ); + declareProperty( "DoNoisyLB", m_doNoisyLB = true ); + declareProperty( "DoHV", m_doHV = false ); + declareProperty( "DoDeadStrip", m_doDeadStrip = false ); + declareProperty( "DoDeadChip", m_doDeadChip = false ); + declareProperty( "DoNoiseOccupancy", m_doNoiseOccupancy = false ); + declareProperty( "DoRawOccupancy", m_doRawOccupancy = false ); + declareProperty( "DoEfficiency", m_doEfficiency = false ); + declareProperty( "DoBSErrorDB", m_doBSErrorDB = false ); + declareProperty( "DoLorentzAngle", m_doLorentzAngle = false ); + declareProperty( "WriteToCool", m_writeToCool = true ); + + declareProperty( "NoisyUpdate", m_noisyUpdate = true ); + declareProperty( "NoisyUploadTest", m_noisyUploadTest = true ); + declareProperty( "NoisyModuleAverageInDB", m_noisyModuleAverageInDB = -1. ); + declareProperty( "NoisyStripLastRunInDB", m_noisyStripLastRunInDB = -999 ); + declareProperty( "NoisyStripAverageInDB", m_noisyStripAverageInDB = -999. ); + declareProperty( "NoisyModuleList", m_noisyModuleList = 200 ); + declareProperty( "NoisyModuleDiff", m_noisyModuleDiff = 0.200 ); + declareProperty( "NoisyStripDiff", m_noisyStripDiff = 128. ); + + declareProperty( "NoisyMinStat", m_noisyMinStat = 50000 ); + declareProperty( "NoisyStripAll", m_noisyStripAll = true ); + declareProperty( "NoisyStripThrDef", m_noisyStripThrDef = true ); + declareProperty( "NoisyStripThrOffline", m_noisyStripThrOffline = 1.500E-2 ); + declareProperty( "NoisyStripThrOnline", m_noisyStripThrOnline = 1.500E-3 ); + declareProperty( "NoisyWaferFinder", m_noisyWaferFinder = true ); + declareProperty( "NoisyWaferWrite", m_noisyWaferWrite = true ); + declareProperty( "NoisyWaferAllStrips", m_noisyWaferAllStrips = true ); + declareProperty( "NoisyWaferThrBarrel", m_noisyWaferThrBarrel = 1.000E-4 ); + declareProperty( "NoisyWaferThrECA", m_noisyWaferThrECA = 1.000E-4 ); + declareProperty( "NoisyWaferThrECC", m_noisyWaferThrECC = 1.000E-4 ); + declareProperty( "NoisyWaferFraction", m_noisyWaferFraction = 0.500 ); + declareProperty( "NoisyChipFraction", m_noisyChipFraction = 0.500 ); + declareProperty( "HVBinWidth", m_maxtbins = 5 ); + declareProperty( "HVQlength", m_maxq = 100 ); + declareProperty( "HVAbsTripLimit", m_absolutetriplimit = 5. ); + declareProperty( "HVRelTripLimit", m_relativetriplimit = 4. ); + declareProperty( "OutputLowHits", m_outputlowhits = false ); + declareProperty( "LowHitsCut", m_lowHitCut = 100 ); + declareProperty( "DeadStripMinStat", m_deadStripMinStat = 200000 ); + declareProperty( "DeadStripMinStatBusy", m_deadStripMinStatBusy = 1600000 ); + declareProperty( "DeadChipMinStat", m_deadChipMinStat = 200000 ); + declareProperty( "DeadStripSignificance", m_deadStripSignificance = 10 ); + declareProperty( "DeadChipSignificance", m_deadChipSignificance = 10 ); + declareProperty( "BusyThr4DeadFinding", m_busyThr4DeadFinding = 1E-4 ); + declareProperty( "NoisyThr4DeadFinding", m_noisyThr4DeadFinding = 1.500E-3 ); + declareProperty( "DeadChipUploadTest", m_deadChipUploadTest = true ); + declareProperty( "DeadStripUploadTest", m_deadStripUploadTest = true ); + + declareProperty( "NoiseOccupancyTriggerAware",m_noiseOccupancyTriggerAware = true ); + declareProperty( "NoiseOccupancyMinStat", m_noiseOccupancyMinStat = 50000 ); + declareProperty( "RawOccupancyMinStat", m_rawOccupancyMinStat = 50000 ); + declareProperty( "EfficiencyMinStat", m_efficiencyMinStat = 50000 ); + declareProperty( "BSErrorDBMinStat", m_BSErrorDBMinStat = 50000 ); + declareProperty( "LorentzAngleMinStat", m_LorentzAngleMinStat = 50000 ); + + declareProperty( "LorentzAngleDebugMode", m_LorentzAngleDebugMode = true ); + + declareProperty( "TagID4NoisyStrips", m_tagID4NoisyStrips = "SctDerivedMonitoring-001-00" ); + declareProperty( "TagID4DeadStrips", m_tagID4DeadStrips = "SctDerivedDeadStrips-001-00" ); + declareProperty( "TagID4DeadChips", m_tagID4DeadChips = "SctDerivedDeadChips-001-00" ); + declareProperty( "TagID4NoiseOccupancy", m_tagID4NoiseOccupancy = "SctDerivedNoiseOccupancy-001-00" ); + declareProperty( "TagID4RawOccupancy", m_tagID4RawOccupancy = "SctDerivedRawOccupancy-001-00" ); + declareProperty( "TagID4Efficiency", m_tagID4Efficiency = "SctDerivedEfficiency-001-00" ); + declareProperty( "TagID4BSErrors", m_tagID4BSErrors = "SctDerivedBSErrors-000-00" ); + declareProperty( "TagID4LorentzAngle", m_tagID4LorentzAngle = "SctDerivedLorentzAngle-000-00" ); + + declareProperty( "BadStripsAllFile", m_badStripsAllFile = "BadStripsAllFile.xml" ); + declareProperty( "BadStripsNewFile", m_badStripsNewFile = "BadStripsNewFile.xml" ); + declareProperty( "BadStripsSummaryFile", m_badStripsSummaryFile = "BadStripsSummaryFile.xml" ); + declareProperty( "BadModulesFile", m_badModulesFile = "BadModulesFile.xml" ); + declareProperty( "DeadStripsFile", m_deadStripsFile = "DeadStripsFile.xml" ); + declareProperty( "DeadChipsFile", m_deadChipsFile = "DeadChipsFile.xml" ); + declareProperty( "DeadSummaryFile", m_deadSummaryFile = "DeadSummaryFile.xml" ); + + declareProperty( "NoiseOccupancyFile", m_noiseOccupancyFile = "NoiseOccupancyFile.xml" ); + declareProperty( "NoiseOccupancySummaryFile", m_noiseOccupancySummaryFile = "NoiseOccupancySummaryFile.xml" ); + declareProperty( "RawOccupancySummaryFile", m_rawOccupancySummaryFile = "RawOccupancySummaryFile.xml" ); + declareProperty( "EfficiencySummaryFile", m_efficiencySummaryFile = "EfficiencySummaryFile.xml" ); + declareProperty( "EfficiencyModuleFile", m_efficiencyModuleFile = "EfficiencyModuleSummary.xml" ); + declareProperty( "BSErrorSummaryFile", m_BSErrorSummaryFile = "BSErrorSummaryFile.xml" ); + declareProperty( "BSErrorModuleFile", m_BSErrorModuleFile = "BSErrorModuleSummary.xml" ); + declareProperty( "LorentzAngleFile", m_LorentzAngleFile = "LorentzAngleFile.xml" ); + declareProperty( "LorentzAngleSummaryFile", m_LorentzAngleSummaryFile = "LorentzAngleSummaryFile.xml" ); + + m_evt = 0; + m_numberOfEvents = 0; + m_eventCounter = 0; + m_maxentry = 0; + m_timeStampBegin = std::numeric_limits<int>::max(); + m_timeStampEnd = -999; + m_LBBegin = std::numeric_limits<int>::max(); + m_LBEnd = -999; + m_LBRange = -999; + + //--- for HV trip + m_phvtripFirstTime = 2000000000; + m_phvtripPrevTime = 0; + m_readHIST = m_doNoiseOccupancy || m_doRawOccupancy || m_doEfficiency || m_doBSErrorDB || m_doLorentzAngle; } @@ -303,164 +302,164 @@ SCTCalib::SCTCalib( const std::string& name, ISvcLocator* pSvcLocator ) : //////////////////////////////////////////////////////////////////////////////////// SCTCalib::~SCTCalib() { - //nop + //nop } //////////////////////////////////////////////////////////////////////////////////// // Initialization //////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::initialize() { - if ( service( "THistSvc", m_thistSvc ).isFailure() ) return msg( MSG::ERROR) << "Unable to retrieve pointer to THistSvc" << endmsg, StatusCode::FAILURE; - if ( detStore()->retrieve( m_pSCTHelper, "SCT_ID").isFailure()) return msg( MSG::ERROR) << "Unable to retrieve SCTHelper" << endmsg, StatusCode::FAILURE; - // - m_MAXHASH=m_pSCTHelper->wafer_hash_max(); - m_waferItrBegin = m_pSCTHelper->wafer_begin(); - m_waferItrEnd = m_pSCTHelper->wafer_end(); - // - if ( not retrievedService(m_pCalibWriteSvc)) return StatusCode::FAILURE; - if ( m_doHV) msg( MSG::FATAL ) << "Not yet properly implemented and tested!" << endmsg; - - ATH_CHECK(m_ConfigurationConditionsTool.retrieve( EnableTool {m_useConfiguration} ) ); - - if ( !m_useCalibration ) { - ATH_MSG_DEBUG( "ReadCalibDataTool was removed in initialization" ); - m_ReadCalibDataTool.disable(); - } else { + if ( service( "THistSvc", m_thistSvc ).isFailure() ) return msg( MSG::ERROR) << "Unable to retrieve pointer to THistSvc" << endmsg, StatusCode::FAILURE; + if ( detStore()->retrieve( m_pSCTHelper, "SCT_ID").isFailure()) return msg( MSG::ERROR) << "Unable to retrieve SCTHelper" << endmsg, StatusCode::FAILURE; + // + m_MAXHASH=m_pSCTHelper->wafer_hash_max(); + m_waferItrBegin = m_pSCTHelper->wafer_begin(); + m_waferItrEnd = m_pSCTHelper->wafer_end(); + // + if ( not retrievedService(m_pCalibWriteTool)) return StatusCode::FAILURE; + if ( m_doHV) msg( MSG::FATAL ) << "Not yet properly implemented and tested!" << endmsg; + + ATH_CHECK(m_ConfigurationConditionsTool.retrieve( EnableTool {m_useConfiguration} ) ); + + if ( !m_useCalibration ) { + ATH_MSG_DEBUG( "ReadCalibDataTool was removed in initialization" ); + m_ReadCalibDataTool.disable(); + } else { if (m_ReadCalibDataTool.retrieve().isFailure()) return StatusCode::FAILURE; - } + } - if ( !m_useMajority ) { - ATH_MSG_DEBUG( "MajorityConditionsTool was removed in initialization" ); - } else { + if ( !m_useMajority ) { + ATH_MSG_DEBUG( "MajorityConditionsTool was removed in initialization" ); + } else { if (m_MajorityConditionsTool.retrieve().isFailure()) return StatusCode::FAILURE; - } - - if ( not retrievedService(m_calibHitmapSvc)) return StatusCode::FAILURE; - - if ( not retrievedService(m_calibModuleListSvc)) return StatusCode::FAILURE; - - if ( not retrievedService(m_calibEvtInfoSvc)) return StatusCode::FAILURE; - - if ( !m_useBSError ) { - ATH_MSG_DEBUG( "ByteStreamErrorsSvc was removed in initialization" ); - } else { - if ( not retrievedService(m_calibBsErrSvc)) return StatusCode::FAILURE; - } - if ( not retrievedService(m_calibLbSvc) ) return StatusCode::FAILURE; - - ATH_CHECK(m_CablingTool.retrieve()); - - //--- LB range - try { - m_LBRange = std::stoi( m_LBMax ); - ISCT_CalibHistoSvc::setNumberOfLb(m_LBRange); - } catch (...) { - ATH_MSG_ERROR( "Couldn't cast m_LBMax=\""<< m_LBMax <<"\" to m_LBRange..."); - m_LBRange = 0; - } - - ISCT_CalibHistoSvc::setLbToMerge(m_nLbsMerged); - - - m_readHIST = m_doNoiseOccupancy || m_doRawOccupancy || m_doEfficiency || m_doBSErrorDB || m_doLorentzAngle; - - if ( m_readBS && m_readHIST ) { - ATH_MSG_ERROR( "Both BS and HIST are set to be read. Choose either of BS or HIST." ); - return StatusCode::FAILURE; - } - - //--- Open BS - if ( m_readBS ) { - ATH_MSG_INFO( "------------> Reading from ByteStream <-------------"); - m_calibEvtInfoSvc->setSource("BS"); - ATH_CHECK(m_eventInfoKey.initialize()); - } - - - //--- Open HIST - if ( m_readHIST ) { - ATH_MSG_INFO( "------------> Reading from HIST <-------------" ); - m_calibEvtInfoSvc->setSource("HIST"); - //--- List of HIST - std::string hist(""); - std::vector<std::string> histCollection = m_input_hist.value(); - ATH_MSG_INFO( "The input histogram name is : " << m_input_hist ); - if (not histCollection.empty()) { - hist=histCollection.back(); - if (histCollection.size() > 1) msg( MSG::WARNING ) << "The Histogram collection contains more than one histogram; using the last one."<< endmsg; - } else { - msg( MSG::ERROR ) << "The input histogram collection property is empty"<< endmsg; - return StatusCode::FAILURE; - } - - //in case of DeadStrip or DeadChip, change open from EOS to - //copy and open locally. Delete the file after processing - m_inputHist = TFile::Open( hist.c_str() ); - - ATH_MSG_INFO( "opening HIST file : " << hist.c_str() ); - cout<< "opening HIST file : " << hist.c_str()<<endl; - - if(m_inputHist) { - //--- Check run number - const std::string os=std::to_string((int)m_runNumber); - ATH_MSG_INFO( "Getting HIST directory : " << (int)m_runNumber ); - if ( not m_inputHist->GetDirectory( "/run_"+TString(os) ) ) return msg( MSG::ERROR ) << "RunNumber in HIST is inconsistent with jobO : " << os << endmsg, StatusCode::FAILURE ; - ATH_MSG_INFO( "Getting Number of events: " << m_calibEvtInfoSvc->counter() ); - //--- Read number of events : Get an entry of "tier0ESD" in "/GLOBAL/DQTDataFlow/events_lb" - std::string osHist= std::string( "/run_") + std::to_string((int)m_runNumber)+"/GLOBAL/DQTDataFlow/events_lb"; - TH1I* hist_events = (TH1I *) m_inputHist->Get( osHist.c_str() ); - m_numberOfEventsHist = hist_events->GetBinContent( 6 ); // Entry in "tier0ESD" - if ( hist_events->GetBinContent( 4 ) > m_numberOfEventsHist) m_numberOfEventsHist = hist_events->GetBinContent( 4 ); // Entry in "tier0" - //m_numberOfEventsHist = 13902; - } else { - ATH_MSG_WARNING( "can not open HIST : " << hist.c_str() ); - } - - - ATH_MSG_INFO( "Initialization of TimeStamp/LB, taken from runInfo.txt" ); - //--- Initialization of TimeStamp/LB, taken from runInfo.txt - m_calibEvtInfoSvc->setSource("HIST"); - m_calibEvtInfoSvc->setTimeStamp(m_runStartTime,m_runEndTime); - m_calibEvtInfoSvc->setRunNumber(m_runNumber); - } - - //--- Booking histograms for hitmaps - if ( m_doHitMaps ) m_calibHitmapSvc->book(); - //--- Reading histograms for hitmaps - if ( ( not m_doHitMaps && not m_doNoisyLB) && m_readHitMaps) { - m_calibEvtInfoSvc->setSource("HIST"); - m_calibHitmapSvc->read("./SCTHitMaps.root"); - m_numberOfEventsHist = m_calibHitmapSvc->size(); - m_calibEvtInfoSvc->setTimeStamp(m_runStartTime,m_runEndTime); - m_calibEvtInfoSvc->setRunNumber(m_runNumber); - m_calibLbSvc->read("./SCTLB.root"); - } - //--- Booking histograms for BSErrors - if ( m_doBSErrors ) m_calibBsErrSvc->book(); - //--- Hit-vs-LB for LBs in noisy links/chips - if ( m_doNoisyLB ) m_calibLbSvc->book(); - - //--- Check statistics for NoiseOccupancy - if ( m_doNoiseOccupancy and notEnoughStatistics(m_noiseOccupancyMinStat, m_numberOfEventsHist)) return StatusCode::FAILURE; - //--- Check statistics for RawOccupancy - if ( m_doRawOccupancy and notEnoughStatistics(m_rawOccupancyMinStat,m_numberOfEventsHist)) return StatusCode::FAILURE; - //--- Check statistics for Efficiency - if ( m_doEfficiency and notEnoughStatistics(m_efficiencyMinStat,m_numberOfEventsHist)) return StatusCode::FAILURE; - //--- Check statistics for BSError - if ( m_doBSErrorDB and notEnoughStatistics(m_BSErrorDBMinStat, m_numberOfEventsHist )) return StatusCode::FAILURE; - //--- Check statistics for LorentzAngle - if ( m_doLorentzAngle and notEnoughStatistics(m_LorentzAngleMinStat, m_numberOfEventsHist)) return StatusCode::FAILURE; - // - return StatusCode::SUCCESS; + } + + if ( not retrievedService(m_calibHitmapTool)) return StatusCode::FAILURE; + + if ( not retrievedService(m_calibModuleListTool)) return StatusCode::FAILURE; + + if ( not retrievedService(m_calibEvtInfoTool)) return StatusCode::FAILURE; + + if ( !m_useBSError ) { + ATH_MSG_DEBUG( "ByteStreamErrorsSvc was removed in initialization" ); + } else { + if ( not retrievedService(m_calibBsErrTool)) return StatusCode::FAILURE; + } + if ( not retrievedService(m_calibLbTool) ) return StatusCode::FAILURE; + + ATH_CHECK(m_CablingTool.retrieve()); + + //--- LB range + try { + m_LBRange = std::stoi( m_LBMax ); + ISCT_CalibHistoTool::setNumberOfLb(m_LBRange); + } catch (...) { + ATH_MSG_ERROR( "Couldn't cast m_LBMax=\""<< m_LBMax <<"\" to m_LBRange..."); + m_LBRange = 0; + } + + ISCT_CalibHistoTool::setLbToMerge(m_nLbsMerged); + + + m_readHIST = m_doNoiseOccupancy || m_doRawOccupancy || m_doEfficiency || m_doBSErrorDB || m_doLorentzAngle; + + if ( m_readBS && m_readHIST ) { + ATH_MSG_ERROR( "Both BS and HIST are set to be read. Choose either of BS or HIST." ); + return StatusCode::FAILURE; + } + + //--- Open BS + if ( m_readBS ) { + ATH_MSG_INFO( "------------> Reading from ByteStream <-------------"); + m_calibEvtInfoTool->setSource("BS"); + ATH_CHECK(m_eventInfoKey.initialize()); + } + + + //--- Open HIST + if ( m_readHIST ) { + ATH_MSG_INFO( "------------> Reading from HIST <-------------" ); + m_calibEvtInfoTool->setSource("HIST"); + //--- List of HIST + std::string hist(""); + std::vector<std::string> histCollection = m_input_hist.value(); + ATH_MSG_INFO( "The input histogram name is : " << m_input_hist ); + if (not histCollection.empty()) { + hist=histCollection.back(); + if (histCollection.size() > 1) msg( MSG::WARNING ) << "The Histogram collection contains more than one histogram; using the last one."<< endmsg; + } else { + msg( MSG::ERROR ) << "The input histogram collection property is empty"<< endmsg; + return StatusCode::FAILURE; + } + + //in case of DeadStrip or DeadChip, change open from EOS to + //copy and open locally. Delete the file after processing + m_inputHist = TFile::Open( hist.c_str() ); + + ATH_MSG_INFO( "opening HIST file : " << hist.c_str() ); + cout<< "opening HIST file : " << hist.c_str()<<endl; + + if(m_inputHist) { + //--- Check run number + const std::string os=std::to_string((int)m_runNumber); + ATH_MSG_INFO( "Getting HIST directory : " << (int)m_runNumber ); + if ( not m_inputHist->GetDirectory( "/run_"+TString(os) ) ) return msg( MSG::ERROR ) << "RunNumber in HIST is inconsistent with jobO : " << os << endmsg, StatusCode::FAILURE ; + ATH_MSG_INFO( "Getting Number of events: " << m_calibEvtInfoTool->counter() ); + //--- Read number of events : Get an entry of "tier0ESD" in "/GLOBAL/DQTDataFlow/events_lb" + std::string osHist= std::string( "/run_") + std::to_string((int)m_runNumber)+"/GLOBAL/DQTDataFlow/events_lb"; + TH1I* hist_events = (TH1I *) m_inputHist->Get( osHist.c_str() ); + m_numberOfEventsHist = hist_events->GetBinContent( 6 ); // Entry in "tier0ESD" + if ( hist_events->GetBinContent( 4 ) > m_numberOfEventsHist) m_numberOfEventsHist = hist_events->GetBinContent( 4 ); // Entry in "tier0" + //m_numberOfEventsHist = 13902; + } else { + ATH_MSG_WARNING( "can not open HIST : " << hist.c_str() ); + } + + + ATH_MSG_INFO( "Initialization of TimeStamp/LB, taken from runInfo.txt" ); + //--- Initialization of TimeStamp/LB, taken from runInfo.txt + m_calibEvtInfoTool->setSource("HIST"); + m_calibEvtInfoTool->setTimeStamp(m_runStartTime,m_runEndTime); + m_calibEvtInfoTool->setRunNumber(m_runNumber); + } + + //--- Booking histograms for hitmaps + if ( m_doHitMaps ) m_calibHitmapTool->book(); + //--- Reading histograms for hitmaps + if ( ( not m_doHitMaps && not m_doNoisyLB) && m_readHitMaps) { + m_calibEvtInfoTool->setSource("HIST"); + m_calibHitmapTool->read("./SCTHitMaps.root"); + m_numberOfEventsHist = m_calibHitmapTool->size(); + m_calibEvtInfoTool->setTimeStamp(m_runStartTime,m_runEndTime); + m_calibEvtInfoTool->setRunNumber(m_runNumber); + m_calibLbTool->read("./SCTLB.root"); + } + //--- Booking histograms for BSErrors + if ( m_doBSErrors ) m_calibBsErrTool->book(); + //--- Hit-vs-LB for LBs in noisy links/chips + if ( m_doNoisyLB ) m_calibLbTool->book(); + + //--- Check statistics for NoiseOccupancy + if ( m_doNoiseOccupancy and notEnoughStatistics(m_noiseOccupancyMinStat, m_numberOfEventsHist)) return StatusCode::FAILURE; + //--- Check statistics for RawOccupancy + if ( m_doRawOccupancy and notEnoughStatistics(m_rawOccupancyMinStat,m_numberOfEventsHist)) return StatusCode::FAILURE; + //--- Check statistics for Efficiency + if ( m_doEfficiency and notEnoughStatistics(m_efficiencyMinStat,m_numberOfEventsHist)) return StatusCode::FAILURE; + //--- Check statistics for BSError + if ( m_doBSErrorDB and notEnoughStatistics(m_BSErrorDBMinStat, m_numberOfEventsHist )) return StatusCode::FAILURE; + //--- Check statistics for LorentzAngle + if ( m_doLorentzAngle and notEnoughStatistics(m_LorentzAngleMinStat, m_numberOfEventsHist)) return StatusCode::FAILURE; + // + return StatusCode::SUCCESS; } bool SCTCalib::notEnoughStatistics(const int required, const int obtained, const std::string & histogramName) { - if (obtained<required) { - msg( MSG::ERROR ) << "Number of events in "<<histogramName<<": "<<obtained<<" is less than the required minimum number of events " <<required<< endmsg; - return true; - } - return false; + if (obtained<required) { + msg( MSG::ERROR ) << "Number of events in "<<histogramName<<": "<<obtained<<" is less than the required minimum number of events " <<required<< endmsg; + return true; + } + return false; } /////////////////////////////////////////////////////////////////////////////////// @@ -468,9 +467,9 @@ SCTCalib::notEnoughStatistics(const int required, const int obtained, const std: /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::beginRun() { - ATH_MSG_INFO ("----- in beginRun() -----" ); - //--- Check if calibration data is available or not - return StatusCode::SUCCESS; + ATH_MSG_INFO ("----- in beginRun() -----" ); + //--- Check if calibration data is available or not + return StatusCode::SUCCESS; } ////////////////////////////////////////////////////////////////////////////////// @@ -478,43 +477,43 @@ StatusCode SCTCalib::beginRun() { ////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::execute() { - if ( m_readBS ) { - SG::ReadHandle<EventInfo> evt(m_eventInfoKey); - if (not evt.isValid()) { - ATH_MSG_FATAL("Unable to get the EventInfo"); - return StatusCode::FAILURE; - } - const EventInfo* evt_ptr = &(*evt); - ATH_MSG_VERBOSE(SCT_CalibAlgs::eventInfoAsString(evt_ptr)); + if ( m_readBS ) { + SG::ReadHandle<EventInfo> evt(m_eventInfoKey); + if (not evt.isValid()) { + ATH_MSG_FATAL("Unable to get the EventInfo"); + return StatusCode::FAILURE; + } + const EventInfo* evt_ptr = &(*evt); + ATH_MSG_VERBOSE(SCT_CalibAlgs::eventInfoAsString(evt_ptr)); //--- TimeStamp/LB range analyzed const int timeStamp = evt->event_ID()->time_stamp(); const int lumiBlock = evt->event_ID()->lumi_block(); int timeStampBeginOld; int timeStampEndOld; - m_calibEvtInfoSvc->getTimeStamps(timeStampBeginOld, timeStampEndOld); - m_calibEvtInfoSvc->setTimeStamp(std::min(timeStamp, timeStampBeginOld), std::max(timeStamp, timeStampEndOld)); + m_calibEvtInfoTool->getTimeStamps(timeStampBeginOld, timeStampEndOld); + m_calibEvtInfoTool->setTimeStamp(std::min(timeStamp, timeStampBeginOld), std::max(timeStamp, timeStampEndOld)); int lbBeginOld; int lbEndOld; - m_calibEvtInfoSvc->getLumiBlock(lbBeginOld, lbEndOld); - m_calibEvtInfoSvc->setLumiBlock(std::min(lumiBlock, lbBeginOld), std::max(lumiBlock, lbEndOld)); - m_calibEvtInfoSvc->setLumiBlock(lumiBlock); - m_calibEvtInfoSvc->setTimeStamp(timeStamp); - } + m_calibEvtInfoTool->getLumiBlock(lbBeginOld, lbEndOld); + m_calibEvtInfoTool->setLumiBlock(std::min(lumiBlock, lbBeginOld), std::max(lumiBlock, lbEndOld)); + m_calibEvtInfoTool->setLumiBlock(lumiBlock); + m_calibEvtInfoTool->setTimeStamp(timeStamp); + } - const bool majorityIsGoodOrUnused=( m_useMajority and m_MajorityConditionsTool->isGood() ) or !m_useMajority; - //--- Fill histograms for (1) Number of events and (2) Hitmaps - if ( m_doHitMaps and majorityIsGoodOrUnused ) m_calibHitmapSvc->fill(m_readBS); + const bool majorityIsGoodOrUnused=( m_useMajority and m_MajorityConditionsTool->isGood() ) or !m_useMajority; + //--- Fill histograms for (1) Number of events and (2) Hitmaps + if ( m_doHitMaps and majorityIsGoodOrUnused ) m_calibHitmapTool->fill(m_readBS); - //--- Fill histograms for (1) Number of events and (2) Hits as a function of LB - if ( m_doNoisyLB and majorityIsGoodOrUnused ) m_calibLbSvc->fill(m_readBS); + //--- Fill histograms for (1) Number of events and (2) Hits as a function of LB + if ( m_doNoisyLB and majorityIsGoodOrUnused ) m_calibLbTool->fill(m_readBS); - //--- Fill histograms for (1) Number of events and (2) BSErrors - if ( m_doBSErrors ) m_calibBsErrSvc->fill(m_readBS); + //--- Fill histograms for (1) Number of events and (2) BSErrors + if ( m_doBSErrors ) m_calibBsErrTool->fill(m_readBS); - //--- Increment event counter : to be ready for the next event loop - m_calibEvtInfoSvc->incrementCounter(); + //--- Increment event counter : to be ready for the next event loop + m_calibEvtInfoTool->incrementCounter(); - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } /////////////////////////////////////////////////////////////////////////////////// @@ -522,87 +521,87 @@ StatusCode SCTCalib::execute() { /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::endRun() { - ATH_MSG_INFO( "----- in endRun() ----- " ); - //--- Number of events processed - m_numberOfEvents = (m_readHIST || (!m_doHitMaps && m_readHitMaps)) ? m_numberOfEventsHist : m_calibEvtInfoSvc->counter(); - m_calibEvtInfoSvc->getTimeStamps(m_utcBegin,m_utcEnd); - - - // if ( m_doNoisyLB ) m_calibLbSvc->binHistograms(m_nLbsMerged); - - //--- IOV range defined by RunNumber and LB - unsigned int beginRun = (int) m_runNumber; - unsigned int endRun = (int) m_runNumber; - unsigned int beginLB = IOVTime::MINEVENT; - unsigned int endLB = IOVTime::MAXEVENT; - m_iovStart.setRunEvent( (unsigned long) beginRun, (unsigned long) beginLB ); - m_iovStop.setRunEvent( (unsigned long) endRun, (unsigned long) endLB ); - - //--- Find noisy strips from hitmaps - const bool doNoisyStripAnalysis = ( ( !m_doHitMaps && m_readHitMaps ) || !m_readHitMaps ) && m_doNoisyStrip; - if ( doNoisyStripAnalysis and getNoisyStrip().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getNoisyStrip()" << endmsg, StatusCode::FAILURE; - - //--- Upload hv - if ( m_doHV ) { - m_gofile.open(m_badModulesFile.c_str(),std::ios::out); - if (not m_gofile and msgLvl(MSG::ERROR)) msg(MSG::ERROR)<<"Problem opening "<<m_badModulesFile<< endmsg; - // - XmlHeader myXml(m_gofile); - XmlStreamer root("modules", m_gofile); - SCT_ID::const_id_iterator waferItr = m_waferItrBegin; - const unsigned int onlyDummy(1); - pair<int, int> timeInterval(0,0); - pair<int, int> lbRange(0,0); - const int withinLimits(m_maxtbins); - // - for( ; waferItr not_eq m_waferItrEnd; ++waferItr ) { - const Identifier waferId=*waferItr ; - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - const vector< pair<int,int> > & tvec= m_summarytrips.at((int)waferHash); - const vector< pair<int,int> > & tlbn= m_summarytripslb.at((int)waferHash); - //tvec is a pair of times in general, although the very first one is a dummy - const unsigned int numberOfElements=tvec.size(); - if (numberOfElements > onlyDummy) { - //only care if something happened in this module - timeInterval=tvec.at(1); - lbRange=tlbn.at(1); - for (unsigned int itrip(2); itrip != numberOfElements; ++itrip) { //skip 0 since that is just the dummy pair. - if (areConsecutiveIntervals(tvec[itrip],timeInterval,withinLimits)) { - timeInterval.second = tvec.at(itrip).second; - lbRange.second = tlbn.at(itrip).second; - } else { - //not consecutive, so first print out the old one - doHVPrintXML(timeInterval,lbRange,waferId); - timeInterval = tvec.at(itrip); - lbRange = tlbn.at(itrip); - } - } // end loop over times - doHVPrintXML(timeInterval,lbRange,waferId ); - } - } // end loop over wafers - } - - //--- Find dead strips/chips from hitmaps - if ( (m_doDeadStrip or m_doDeadChip ) and getDeadStrip().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getDeadStrip()" << endmsg, StatusCode::FAILURE ; - - //--- Upload noise occupancy - if ( m_doNoiseOccupancy and getNoiseOccupancy().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getNoiseOccupancy()" << endmsg, StatusCode::FAILURE; - - //--- Upload raw occupancy - if ( m_doRawOccupancy and getRawOccupancy().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getRawOccupancy()" << endmsg, StatusCode::FAILURE; - - //--- Upload efficiency - if ( m_doEfficiency and getEfficiency().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getEfficiency()" << endmsg, StatusCode::FAILURE; - - //--- Upload ByteStream Errors - if ( m_doBSErrorDB and getBSErrors().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getBSErrors()" << endmsg, StatusCode::FAILURE; - - //--- Upload Lorentz Angle - if ( m_doLorentzAngle and getLorentzAngle().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getLorentzAngle()" << endmsg, StatusCode::FAILURE; - - //--- Close HIST - if ( m_readHIST ) m_inputHist->Close(); - return StatusCode::SUCCESS; + ATH_MSG_INFO( "----- in endRun() ----- " ); + //--- Number of events processed + m_numberOfEvents = (m_readHIST || (!m_doHitMaps && m_readHitMaps)) ? m_numberOfEventsHist : m_calibEvtInfoTool->counter(); + m_calibEvtInfoTool->getTimeStamps(m_utcBegin,m_utcEnd); + + + // if ( m_doNoisyLB ) m_calibLbTool->binHistograms(m_nLbsMerged); + + //--- IOV range defined by RunNumber and LB + unsigned int beginRun = (int) m_runNumber; + unsigned int endRun = (int) m_runNumber; + unsigned int beginLB = IOVTime::MINEVENT; + unsigned int endLB = IOVTime::MAXEVENT; + m_iovStart.setRunEvent( (unsigned long) beginRun, (unsigned long) beginLB ); + m_iovStop.setRunEvent( (unsigned long) endRun, (unsigned long) endLB ); + + //--- Find noisy strips from hitmaps + const bool doNoisyStripAnalysis = ( ( !m_doHitMaps && m_readHitMaps ) || !m_readHitMaps ) && m_doNoisyStrip; + if ( doNoisyStripAnalysis and getNoisyStrip().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getNoisyStrip()" << endmsg, StatusCode::FAILURE; + + //--- Upload hv + if ( m_doHV ) { + m_gofile.open(m_badModulesFile.c_str(),std::ios::out); + if (not m_gofile and msgLvl(MSG::ERROR)) msg(MSG::ERROR)<<"Problem opening "<<m_badModulesFile<< endmsg; + // + XmlHeader myXml(m_gofile); + XmlStreamer root("modules", m_gofile); + SCT_ID::const_id_iterator waferItr = m_waferItrBegin; + const unsigned int onlyDummy(1); + pair<int, int> timeInterval(0,0); + pair<int, int> lbRange(0,0); + const int withinLimits(m_maxtbins); + // + for( ; waferItr not_eq m_waferItrEnd; ++waferItr ) { + const Identifier waferId=*waferItr ; + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + const vector< pair<int,int> > & tvec= m_summarytrips.at((int)waferHash); + const vector< pair<int,int> > & tlbn= m_summarytripslb.at((int)waferHash); + //tvec is a pair of times in general, although the very first one is a dummy + const unsigned int numberOfElements=tvec.size(); + if (numberOfElements > onlyDummy) { + //only care if something happened in this module + timeInterval=tvec.at(1); + lbRange=tlbn.at(1); + for (unsigned int itrip(2); itrip != numberOfElements; ++itrip) { //skip 0 since that is just the dummy pair. + if (areConsecutiveIntervals(tvec[itrip],timeInterval,withinLimits)) { + timeInterval.second = tvec.at(itrip).second; + lbRange.second = tlbn.at(itrip).second; + } else { + //not consecutive, so first print out the old one + doHVPrintXML(timeInterval,lbRange,waferId); + timeInterval = tvec.at(itrip); + lbRange = tlbn.at(itrip); + } + } // end loop over times + doHVPrintXML(timeInterval,lbRange,waferId ); + } + } // end loop over wafers + } + + //--- Find dead strips/chips from hitmaps + if ( (m_doDeadStrip or m_doDeadChip ) and getDeadStrip().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getDeadStrip()" << endmsg, StatusCode::FAILURE ; + + //--- Upload noise occupancy + if ( m_doNoiseOccupancy and getNoiseOccupancy().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getNoiseOccupancy()" << endmsg, StatusCode::FAILURE; + + //--- Upload raw occupancy + if ( m_doRawOccupancy and getRawOccupancy().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getRawOccupancy()" << endmsg, StatusCode::FAILURE; + + //--- Upload efficiency + if ( m_doEfficiency and getEfficiency().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getEfficiency()" << endmsg, StatusCode::FAILURE; + + //--- Upload ByteStream Errors + if ( m_doBSErrorDB and getBSErrors().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getBSErrors()" << endmsg, StatusCode::FAILURE; + + //--- Upload Lorentz Angle + if ( m_doLorentzAngle and getLorentzAngle().isFailure() ) return msg( MSG::ERROR ) << "Failed to run getLorentzAngle()" << endmsg, StatusCode::FAILURE; + + //--- Close HIST + if ( m_readHIST ) m_inputHist->Close(); + return StatusCode::SUCCESS; } @@ -611,10 +610,10 @@ StatusCode SCTCalib::endRun() { /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::finalize() { - msg( MSG::INFO ) << "----- in finalize() ----- " << endmsg; + msg( MSG::INFO ) << "----- in finalize() ----- " << endmsg; - msg( MSG::INFO ) << "Thank-you for using SCT_CalibAlgs, version "<<PACKAGE_VERSION << endmsg; - return StatusCode::SUCCESS; + msg( MSG::INFO ) << "Thank-you for using SCT_CalibAlgs, version "<<PACKAGE_VERSION << endmsg; + return StatusCode::SUCCESS; } @@ -623,35 +622,35 @@ StatusCode SCTCalib::finalize() { /// Prints XML file for hv modules /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::doHVPrintXML(const std::pair<int, int> & timeInterval, const std::pair<int,int> & lbRange, Identifier waferId) { - const IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - const SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - - XmlStreamer mod("module", m_gofile); - { - XmlStreamer v("value","name","SN", m_gofile); - m_gofile<<sn.str(); - } - { - XmlStreamer v("value", "name", "BecLayerPhiEta", m_gofile); - m_gofile<< formatPosition(waferId, m_pSCTHelper,".",false); - } - { - XmlStreamer v("value","name", "StartTime", m_gofile); - m_gofile<<timeInterval.first; - } - { - XmlStreamer v("value","name","EndTime",m_gofile); - m_gofile<< timeInterval.second; - } - { - XmlStreamer v("value","name", "StartLBN", m_gofile); - m_gofile<<lbRange.first; - } - { - XmlStreamer v("value","name","EndLBN",m_gofile); - m_gofile<< lbRange.second; - } - return StatusCode::SUCCESS; + const IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + const SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + + XmlStreamer mod("module", m_gofile); + { + XmlStreamer v("value","name","SN", m_gofile); + m_gofile<<sn.str(); + } + { + XmlStreamer v("value", "name", "BecLayerPhiEta", m_gofile); + m_gofile<< formatPosition(waferId, m_pSCTHelper,".",false); + } + { + XmlStreamer v("value","name", "StartTime", m_gofile); + m_gofile<<timeInterval.first; + } + { + XmlStreamer v("value","name","EndTime",m_gofile); + m_gofile<< timeInterval.second; + } + { + XmlStreamer v("value","name", "StartLBN", m_gofile); + m_gofile<<lbRange.first; + } + { + XmlStreamer v("value","name","EndLBN",m_gofile); + m_gofile<< lbRange.second; + } + return StatusCode::SUCCESS; } /////////////////////////////////////////////////////////////////////////////////// @@ -659,111 +658,111 @@ StatusCode SCTCalib::doHVPrintXML(const std::pair<int, int> & timeInterval, cons /// Find noisy strips from hitmaps and write out into xml/db formats /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::getNoisyStrip() { - enum Categories {ALL, NEW, REF, N_CATEGORIES}; - //--- Check statistics - //msg( MSG::INFO ) << m_calibEvtInfoSvc->counter() << " " <<m_calibHitmapSvc->size() << endmsg; - //int numOfEventsProcessed=m_calibEvtInfoSvc->counter(); - m_numOfEventsProcessed=m_calibHitmapSvc->size(); - //sroe: This looks like a bug, so I change the code here - - // if ( noisyStripsToSummaryXmlFake( m_badStripsSummaryFile ).isFailure() ) { - // msg( MSG::ERROR ) << "Could not write XML file" << endmsg; - // return StatusCode::FAILURE; - // } - - // if (m_numOfEventsProcessed < (int) m_noisyMinStat ) { - // msg( MSG::ERROR ) << "in getNoisyStrip() : Number of events processed " << m_numOfEventsProcessed //original was just m_numberOfEvents - // << " is less than the required minimum number of events " << (int) m_noisyMinStat << endmsg; - // return StatusCode::FAILURE; - // } - - ATH_MSG_INFO( "----- in getNoisyStrip() ----- " ); - - //--- Number of LBs processed - m_numOfLBsProcessed = 0; - for ( int iLB = 0; iLB != m_LBRange; ++iLB ) { - if ( m_calibLbSvc and m_calibLbSvc->getNumberOfEventsInBin( iLB + 1 ) > 0 ) ++m_numOfLBsProcessed; - } - - //--- Choice of threshold - //three module lists: all, new, ref - typedef std::map< Identifier, std::set<Identifier> > ModuleList_t; - ModuleList_t moduleLists[N_CATEGORIES]; - //Reading data from COOL - // original code switched on this :if (m_noisyUpdate) - if (m_calibModuleListSvc->readModuleList(moduleLists[REF]).isFailure()) return msg( MSG::ERROR ) << "Could not read moduleList" << endmsg, StatusCode::FAILURE; - - //two bad strip lists: all, new - typedef std::set<Identifier> StripList_t; - StripList_t stripIdLists[2]; - - //--- Loop over wafers - SCT_ID::const_id_iterator waferItr = m_waferItrBegin; - SCT_ID::const_id_iterator waferItrE = m_waferItrEnd; - int numNoisyWafers(0); - for( ; waferItr not_eq waferItrE; ++waferItr ) { - //--- Identifier/SN - Identifier waferId = *waferItr; - Identifier moduleId = m_pSCTHelper->module_id( waferId ); - //--- Initialization in *module* - if ( m_pSCTHelper->side( waferId ) == 0 ) { - stripIdLists[ALL].clear(); - stripIdLists[NEW].clear(); - } - std::pair<int, bool> noisy=getNumNoisyStrips(waferId); - const int numNoisyStripsInWafer=noisy.first; - const bool isNoisyWafer=noisy.second; - if (numNoisyStripsInWafer!=0) { - if ( m_noisyWaferFinder && isNoisyWafer ) { //in noisy wafer - ++numNoisyWafers; - if (not m_noisyWaferWrite) break; - if (m_noisyWaferAllStrips) { //write out all strips - if ( addStripsToList( waferId, stripIdLists[ALL], false, false ).isFailure() or addStripsToList( waferId, stripIdLists[NEW], false, true ).isFailure() ) { - return msg( MSG::ERROR ) << "Could not add stripIds to the list" << endmsg, StatusCode::FAILURE; - } - break; - } else { - //only noisy strips in noisy wafer - if ( addStripsToList( waferId, stripIdLists[ALL], true, false ).isFailure() or addStripsToList( waferId, stripIdLists[NEW], true, true ).isFailure() ) { - return msg( MSG::ERROR ) << "Could not add stripIds to the list" << endmsg, StatusCode::FAILURE; - } - } - } else { // not in noisy wafer - if ( addStripsToList( waferId, stripIdLists[ALL], true, false ).isFailure() or addStripsToList( waferId, stripIdLists[NEW], true, true ).isFailure() ) { - return msg( MSG::ERROR ) << "Could not add stripIds to the list" << endmsg, StatusCode::FAILURE; - } + enum Categories {ALL, NEW, REF, N_CATEGORIES}; + //--- Check statistics + //msg( MSG::INFO ) << m_calibEvtInfoTool->counter() << " " <<m_calibHitmapTool->size() << endmsg; + //int numOfEventsProcessed=m_calibEvtInfoTool->counter(); + m_numOfEventsProcessed=m_calibHitmapTool->size(); + //sroe: This looks like a bug, so I change the code here + + // if ( noisyStripsToSummaryXmlFake( m_badStripsSummaryFile ).isFailure() ) { + // msg( MSG::ERROR ) << "Could not write XML file" << endmsg; + // return StatusCode::FAILURE; + // } + + // if (m_numOfEventsProcessed < (int) m_noisyMinStat ) { + // msg( MSG::ERROR ) << "in getNoisyStrip() : Number of events processed " << m_numOfEventsProcessed //original was just m_numberOfEvents + // << " is less than the required minimum number of events " << (int) m_noisyMinStat << endmsg; + // return StatusCode::FAILURE; + // } + + ATH_MSG_INFO( "----- in getNoisyStrip() ----- " ); + + //--- Number of LBs processed + m_numOfLBsProcessed = 0; + for ( int iLB = 0; iLB != m_LBRange; ++iLB ) { + if ( m_calibLbTool and m_calibLbTool->getNumberOfEventsInBin( iLB + 1 ) > 0 ) ++m_numOfLBsProcessed; + } + + //--- Choice of threshold + //three module lists: all, new, ref + typedef std::map< Identifier, std::set<Identifier> > ModuleList_t; + ModuleList_t moduleLists[N_CATEGORIES]; + //Reading data from COOL + // original code switched on this :if (m_noisyUpdate) + if (m_calibModuleListTool->readModuleList(moduleLists[REF]).isFailure()) return msg( MSG::ERROR ) << "Could not read moduleList" << endmsg, StatusCode::FAILURE; + + //two bad strip lists: all, new + typedef std::set<Identifier> StripList_t; + StripList_t stripIdLists[2]; + + //--- Loop over wafers + SCT_ID::const_id_iterator waferItr = m_waferItrBegin; + SCT_ID::const_id_iterator waferItrE = m_waferItrEnd; + int numNoisyWafers(0); + for( ; waferItr not_eq waferItrE; ++waferItr ) { + //--- Identifier/SN + Identifier waferId = *waferItr; + Identifier moduleId = m_pSCTHelper->module_id( waferId ); + //--- Initialization in *module* + if ( m_pSCTHelper->side( waferId ) == 0 ) { + stripIdLists[ALL].clear(); + stripIdLists[NEW].clear(); + } + std::pair<int, bool> noisy=getNumNoisyStrips(waferId); + const int numNoisyStripsInWafer=noisy.first; + const bool isNoisyWafer=noisy.second; + if (numNoisyStripsInWafer!=0) { + if ( m_noisyWaferFinder && isNoisyWafer ) { //in noisy wafer + ++numNoisyWafers; + if (not m_noisyWaferWrite) break; + if (m_noisyWaferAllStrips) { //write out all strips + if ( addStripsToList( waferId, stripIdLists[ALL], false, false ).isFailure() or addStripsToList( waferId, stripIdLists[NEW], false, true ).isFailure() ) { + return msg( MSG::ERROR ) << "Could not add stripIds to the list" << endmsg, StatusCode::FAILURE; + } + break; + } else { + //only noisy strips in noisy wafer + if ( addStripsToList( waferId, stripIdLists[ALL], true, false ).isFailure() or addStripsToList( waferId, stripIdLists[NEW], true, true ).isFailure() ) { + return msg( MSG::ERROR ) << "Could not add stripIds to the list" << endmsg, StatusCode::FAILURE; + } } - }//endif numnoisystrips!=0 - //--- Create objects for a module - if ( m_pSCTHelper->side( waferId ) == 1 ) { - if ( !stripIdLists[ALL].empty() ) moduleLists[ALL].insert( map< Identifier, std::set<Identifier> >::value_type( moduleId, stripIdLists[ALL] ) ); - if ( !stripIdLists[NEW].empty() ) moduleLists[NEW].insert( map< Identifier, std::set<Identifier> >::value_type( moduleId, stripIdLists[NEW] ) ); - } - }//end loop over wafers - - //--- Local sqlite files here - ATH_MSG_DEBUG( "------ Before writing into COOL ------" ); - if ( m_writeToCool ) { - if ( writeModuleListToCool( moduleLists[ALL], moduleLists[NEW], moduleLists[REF] ).isFailure() ) { - msg( MSG::ERROR ) << "Could not write NoisyStrips into COOL" << endmsg; - return StatusCode::FAILURE; - } - } - //--- XML outputs - if ( noisyStripsToXml( moduleLists[ALL], m_badStripsAllFile ).isFailure() ) { - msg( MSG::ERROR ) << "Could not write XML file" << endmsg; - return StatusCode::FAILURE; - } - if ( noisyStripsToXml( moduleLists[NEW], m_badStripsNewFile ).isFailure() ) { - msg( MSG::ERROR ) << "Could not write XML file" << endmsg; - return StatusCode::FAILURE; - } - if ( noisyStripsToSummaryXml( moduleLists[ALL], moduleLists[NEW], moduleLists[REF], m_badStripsSummaryFile ).isFailure() ) { - msg( MSG::ERROR ) << "Could not write XML file" << endmsg; - return StatusCode::FAILURE; - } - - return StatusCode::SUCCESS; + } else { // not in noisy wafer + if ( addStripsToList( waferId, stripIdLists[ALL], true, false ).isFailure() or addStripsToList( waferId, stripIdLists[NEW], true, true ).isFailure() ) { + return msg( MSG::ERROR ) << "Could not add stripIds to the list" << endmsg, StatusCode::FAILURE; + } + } + }//endif numnoisystrips!=0 + //--- Create objects for a module + if ( m_pSCTHelper->side( waferId ) == 1 ) { + if ( !stripIdLists[ALL].empty() ) moduleLists[ALL].insert( map< Identifier, std::set<Identifier> >::value_type( moduleId, stripIdLists[ALL] ) ); + if ( !stripIdLists[NEW].empty() ) moduleLists[NEW].insert( map< Identifier, std::set<Identifier> >::value_type( moduleId, stripIdLists[NEW] ) ); + } + }//end loop over wafers + + //--- Local sqlite files here + ATH_MSG_DEBUG( "------ Before writing into COOL ------" ); + if ( m_writeToCool ) { + if ( writeModuleListToCool( moduleLists[ALL], moduleLists[NEW], moduleLists[REF] ).isFailure() ) { + msg( MSG::ERROR ) << "Could not write NoisyStrips into COOL" << endmsg; + return StatusCode::FAILURE; + } + } + //--- XML outputs + if ( noisyStripsToXml( moduleLists[ALL], m_badStripsAllFile ).isFailure() ) { + msg( MSG::ERROR ) << "Could not write XML file" << endmsg; + return StatusCode::FAILURE; + } + if ( noisyStripsToXml( moduleLists[NEW], m_badStripsNewFile ).isFailure() ) { + msg( MSG::ERROR ) << "Could not write XML file" << endmsg; + return StatusCode::FAILURE; + } + if ( noisyStripsToSummaryXml( moduleLists[ALL], moduleLists[NEW], moduleLists[REF], m_badStripsSummaryFile ).isFailure() ) { + msg( MSG::ERROR ) << "Could not write XML file" << endmsg; + return StatusCode::FAILURE; + } + + return StatusCode::SUCCESS; } @@ -772,495 +771,495 @@ StatusCode SCTCalib::getNoisyStrip() { // SCTCalib :: getDeadStrip //==================================================================================================== StatusCode SCTCalib::getDeadStrip() { - //Function to identify and print out the dead strips. - ATH_MSG_INFO( "getDeadStrip() called" ); - - // Bad Mods - const std::set<Identifier>* badMods = m_ConfigurationConditionsTool->badModules(); - std::set<Identifier>::const_iterator ModItr(badMods->begin()); - std::set<Identifier>::const_iterator ModEnd(badMods->end()); - // Bad links - const std::map<IdentifierHash, std::pair<bool, bool> >* badLinks = m_ConfigurationConditionsTool->badLinks(); - std::map<IdentifierHash, std::pair<bool, bool> >::const_iterator linkItr(badLinks->begin()); - std::map<IdentifierHash, std::pair<bool, bool> >::const_iterator linkEnd(badLinks->end()); - // Bad chips - const std::map<Identifier, unsigned int>* badChips = m_ConfigurationConditionsTool->badChips(); - std::map<Identifier, unsigned int>::const_iterator chipItr(badChips->begin()); - std::map<Identifier, unsigned int>::const_iterator chipEnd(badChips->end()); - // Bad strips (w/o bad modules and chips) - std::set<Identifier> badStripsExclusive; - m_ConfigurationConditionsTool->badStrips(badStripsExclusive, true, true); - //std::set<Identifier>::const_iterator stripItr(badStripsExclusive.begin()); - std::set<Identifier>::const_iterator stripEnd(badStripsExclusive.end()); - //To get #(Enabled Modules) - int numEnabledModules_B[n_barrels]= {n_phiBinsB0*n_etaInBarrel,n_phiBinsB1*n_etaInBarrel,n_phiBinsB2*n_etaInBarrel,n_phiBinsB3*n_etaInBarrel}; - int numEnabledModules_EC[n_disks][n_etaBinsEC]= { {0}, {0} }; - for(int i=0; i<n_disks; i++) - for(int j=0; j<n_etaBinsEC; j++) - if(!((i==0&&j==2)||(i==6&&j==2)||(i==7&&j==2)||(i==8&&j==1)||(i==8&&j==2))) - numEnabledModules_EC[i][j] = j==0 ? n_phiBinsECOuter*2 : n_phiBinsECMiddle*2; - for(; ModItr!=ModEnd; ++ModItr) { - Identifier moduleId = *ModItr; - if(m_pSCTHelper->barrel_ec(moduleId)==BARREL) numEnabledModules_B[m_pSCTHelper->layer_disk(moduleId)]--; - else numEnabledModules_EC[m_pSCTHelper->layer_disk(moduleId)][m_pSCTHelper->eta_module(moduleId)]--; - } - //calculate meanOccupancy of layer etc... - double meanOccupancy_Barrel[n_barrels]= {0}; - double meanOccupancy_EC[n_disks][n_etaBinsEC]= { {0}, {0} }; - SCT_ID::const_id_iterator waferItr = m_waferItrBegin; - SCT_ID::const_id_iterator waferItrE = m_waferItrEnd; - for( ; waferItr != waferItrE; ++waferItr ) { - Identifier waferId = *waferItr; - // Identifier moduleId = m_pSCTHelper->module_id(waferId); - IdentifierHash waferHash = m_pSCTHelper->wafer_hash(waferId); - for(int j=0; j<n_stripPerChip*n_chipPerSide; j++) { - double n_hits = m_calibHitmapSvc->getBinForHistogramIndex( j+1 , (int) waferHash); - if(n_hits/m_numberOfEvents<m_noisyThr4DeadFinding) { - if(m_pSCTHelper->barrel_ec(waferId)==BARREL) { - meanOccupancy_Barrel[m_pSCTHelper->layer_disk(waferId)]+=m_calibHitmapSvc->getBinForHistogramIndex( j+1 , (int) waferHash); - } else { - meanOccupancy_EC[m_pSCTHelper->layer_disk(waferId)][m_pSCTHelper->eta_module(waferId)]+=m_calibHitmapSvc->getBinForHistogramIndex( j+1 , (int) waferHash); - } - } - } - } - - for(int i=0; i<n_barrels; i++) { - meanOccupancy_Barrel[i]/=(double)(m_numberOfEvents*nbins*2*numEnabledModules_B[i]); - if(msgLvl(MSG::INFO)) msg(MSG::INFO)<<"Barrel : layer="<<i<<", meanOccupancy="<<meanOccupancy_Barrel[i]<<", #enabledModule="<<numEnabledModules_B[i]<<endmsg; - } - - for(int i=0; i<n_disks; i++) { - for(int j=0; j<n_etaBinsEC; j++) { - if(numEnabledModules_EC[i][j]!=0) { - meanOccupancy_EC[i][j]/=(double)(m_numberOfEvents*nbins*2*numEnabledModules_EC[i][j]); - if(msgLvl(MSG::INFO)) msg(MSG::INFO)<<"EndCap : disk="<<i<<", eta="<<j<<", meanOccupancy="<<meanOccupancy_EC[i][j]<<", #enabledModule="<<numEnabledModules_EC[i][j]<<endmsg; + //Function to identify and print out the dead strips. + ATH_MSG_INFO( "getDeadStrip() called" ); + + // Bad Mods + const std::set<Identifier>* badMods = m_ConfigurationConditionsTool->badModules(); + std::set<Identifier>::const_iterator ModItr(badMods->begin()); + std::set<Identifier>::const_iterator ModEnd(badMods->end()); + // Bad links + const std::map<IdentifierHash, std::pair<bool, bool> >* badLinks = m_ConfigurationConditionsTool->badLinks(); + std::map<IdentifierHash, std::pair<bool, bool> >::const_iterator linkItr(badLinks->begin()); + std::map<IdentifierHash, std::pair<bool, bool> >::const_iterator linkEnd(badLinks->end()); + // Bad chips + const std::map<Identifier, unsigned int>* badChips = m_ConfigurationConditionsTool->badChips(); + std::map<Identifier, unsigned int>::const_iterator chipItr(badChips->begin()); + std::map<Identifier, unsigned int>::const_iterator chipEnd(badChips->end()); + // Bad strips (w/o bad modules and chips) + std::set<Identifier> badStripsExclusive; + m_ConfigurationConditionsTool->badStrips(badStripsExclusive, true, true); + //std::set<Identifier>::const_iterator stripItr(badStripsExclusive.begin()); + std::set<Identifier>::const_iterator stripEnd(badStripsExclusive.end()); + //To get #(Enabled Modules) + int numEnabledModules_B[n_barrels]= {n_phiBinsB0*n_etaInBarrel,n_phiBinsB1*n_etaInBarrel,n_phiBinsB2*n_etaInBarrel,n_phiBinsB3*n_etaInBarrel}; + int numEnabledModules_EC[n_disks][n_etaBinsEC]= { {0}, {0} }; + for(int i=0; i<n_disks; i++) + for(int j=0; j<n_etaBinsEC; j++) + if(!((i==0&&j==2)||(i==6&&j==2)||(i==7&&j==2)||(i==8&&j==1)||(i==8&&j==2))) + numEnabledModules_EC[i][j] = j==0 ? n_phiBinsECOuter*2 : n_phiBinsECMiddle*2; + for(; ModItr!=ModEnd; ++ModItr) { + Identifier moduleId = *ModItr; + if(m_pSCTHelper->barrel_ec(moduleId)==BARREL) numEnabledModules_B[m_pSCTHelper->layer_disk(moduleId)]--; + else numEnabledModules_EC[m_pSCTHelper->layer_disk(moduleId)][m_pSCTHelper->eta_module(moduleId)]--; + } + //calculate meanOccupancy of layer etc... + double meanOccupancy_Barrel[n_barrels]= {0}; + double meanOccupancy_EC[n_disks][n_etaBinsEC]= { {0}, {0} }; + SCT_ID::const_id_iterator waferItr = m_waferItrBegin; + SCT_ID::const_id_iterator waferItrE = m_waferItrEnd; + for( ; waferItr != waferItrE; ++waferItr ) { + Identifier waferId = *waferItr; + // Identifier moduleId = m_pSCTHelper->module_id(waferId); + IdentifierHash waferHash = m_pSCTHelper->wafer_hash(waferId); + for(int j=0; j<n_stripPerChip*n_chipPerSide; j++) { + double n_hits = m_calibHitmapTool->getBinForHistogramIndex( j+1, (int) waferHash); + if(n_hits/m_numberOfEvents<m_noisyThr4DeadFinding) { + if(m_pSCTHelper->barrel_ec(waferId)==BARREL) { + meanOccupancy_Barrel[m_pSCTHelper->layer_disk(waferId)]+=m_calibHitmapTool->getBinForHistogramIndex( j+1, (int) waferHash); + } else { + meanOccupancy_EC[m_pSCTHelper->layer_disk(waferId)][m_pSCTHelper->eta_module(waferId)]+=m_calibHitmapTool->getBinForHistogramIndex( j+1, (int) waferHash); } - } - } - bool busyStream = meanOccupancy_Barrel[3]>m_busyThr4DeadFinding ? true : false; - unsigned int minStat = busyStream ? (unsigned int)m_deadStripMinStatBusy : (unsigned int)m_deadStripMinStat; - if(m_doDeadStrip && m_numberOfEvents<minStat) { - if (msgLvl(MSG::WARNING)) - msg(MSG::WARNING)<<"required minimum statistics is "<<minStat/1E3<<"k events for DeadStrip search with this stream"<<endmsg; - m_doDeadStrip = false; - } - if(m_doDeadChip && m_numberOfEvents<m_deadChipMinStat) { - if (msgLvl(MSG::WARNING)) msg(MSG::WARNING)<<"required minimum statistics is "<<(unsigned int)m_deadChipMinStat<<" events for DeadChip search"<<endmsg; - m_doDeadChip = false; - } - if(m_doDeadStrip==false && m_doDeadChip==false) { - msg(MSG::ERROR) << "Number of events " << m_numberOfEvents<< " is less than the required minimum number of events... exit getDeadStrip()" << endmsg; - return StatusCode::FAILURE; - } - //create XML files - if(m_doDeadStrip) { - if(openXML4DB(m_outDeadStrips, "DeadStrip", m_tagID4DeadStrips.c_str(), m_iovStart, m_iovStop).isFailure()) { - msg(MSG::ERROR)<<"Problem opening "<<m_deadStripsFile<<endmsg; - return StatusCode::FAILURE; - } - } - if(m_doDeadChip) { - if(openXML4DB(m_outDeadChips, "DeadChip", m_tagID4DeadChips.c_str(), m_iovStart, m_iovStop).isFailure()) { - msg(MSG::ERROR)<<"Problem opening "<<m_deadChipsFile<<endmsg; - return StatusCode::FAILURE; - } - } - - // Get SCT_DetectorElementCollection - SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEle(m_SCTDetEleCollKey); - const InDetDD::SiDetectorElementCollection* elements(sctDetEle.retrieve()); - if (elements==nullptr) { + } + } + } + + for(int i=0; i<n_barrels; i++) { + meanOccupancy_Barrel[i]/=(double)(m_numberOfEvents*nbins*2*numEnabledModules_B[i]); + if(msgLvl(MSG::INFO)) msg(MSG::INFO)<<"Barrel : layer="<<i<<", meanOccupancy="<<meanOccupancy_Barrel[i]<<", #enabledModule="<<numEnabledModules_B[i]<<endmsg; + } + + for(int i=0; i<n_disks; i++) { + for(int j=0; j<n_etaBinsEC; j++) { + if(numEnabledModules_EC[i][j]!=0) { + meanOccupancy_EC[i][j]/=(double)(m_numberOfEvents*nbins*2*numEnabledModules_EC[i][j]); + if(msgLvl(MSG::INFO)) msg(MSG::INFO)<<"EndCap : disk="<<i<<", eta="<<j<<", meanOccupancy="<<meanOccupancy_EC[i][j]<<", #enabledModule="<<numEnabledModules_EC[i][j]<<endmsg; + } + } + } + bool busyStream = meanOccupancy_Barrel[3]>m_busyThr4DeadFinding ? true : false; + unsigned int minStat = busyStream ? (unsigned int)m_deadStripMinStatBusy : (unsigned int)m_deadStripMinStat; + if(m_doDeadStrip && m_numberOfEvents<minStat) { + if (msgLvl(MSG::WARNING)) + msg(MSG::WARNING)<<"required minimum statistics is "<<minStat/1E3<<"k events for DeadStrip search with this stream"<<endmsg; + m_doDeadStrip = false; + } + if(m_doDeadChip && m_numberOfEvents<m_deadChipMinStat) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING)<<"required minimum statistics is "<<(unsigned int)m_deadChipMinStat<<" events for DeadChip search"<<endmsg; + m_doDeadChip = false; + } + if(m_doDeadStrip==false && m_doDeadChip==false) { + msg(MSG::ERROR) << "Number of events " << m_numberOfEvents<< " is less than the required minimum number of events... exit getDeadStrip()" << endmsg; + return StatusCode::FAILURE; + } + //create XML files + if(m_doDeadStrip) { + if(openXML4DB(m_outDeadStrips, "DeadStrip", m_tagID4DeadStrips.c_str(), m_iovStart, m_iovStop).isFailure()) { + msg(MSG::ERROR)<<"Problem opening "<<m_deadStripsFile<<endmsg; + return StatusCode::FAILURE; + } + } + if(m_doDeadChip) { + if(openXML4DB(m_outDeadChips, "DeadChip", m_tagID4DeadChips.c_str(), m_iovStart, m_iovStop).isFailure()) { + msg(MSG::ERROR)<<"Problem opening "<<m_deadChipsFile<<endmsg; + return StatusCode::FAILURE; + } + } + + // Get SCT_DetectorElementCollection + SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEle(m_SCTDetEleCollKey); + const InDetDD::SiDetectorElementCollection* elements(sctDetEle.retrieve()); + if (elements==nullptr) { ATH_MSG_FATAL(m_SCTDetEleCollKey.fullKey() << " could not be retrieved"); return StatusCode::FAILURE; - } - - //Dead identification - bool hasDeadStrip=false; - bool hasDeadChip=false; - bool isNoHitLink=false; - bool isDead=false; - bool beforeIsDead=false; - int n_deadStrip=0; - int n_deadChip=0; - int n_deadLink=0; - int n_deadModule=0; - int n_checkedChip=0; - int beginDead=0; - int endDead=0; - std::string defectStrip; - std::string defectChip; - std::ostringstream summaryList; - defectStrip.erase(); - defectChip.erase(); - const double deadStripDefinition = ROOT::Math::gaussian_cdf_c(m_deadStripSignificance); - const double deadChipDefinition = ROOT::Math::gaussian_cdf_c(m_deadChipSignificance); - - - //--- Loop over wafers - waferItr = m_waferItrBegin; - for( ; waferItr != m_waferItrEnd; ++waferItr ) { - Identifier waferId = *waferItr; - Identifier moduleId = m_pSCTHelper->module_id(waferId); - IdentifierHash waferHash = m_pSCTHelper->wafer_hash(waferId); - - bool disabledChip[n_chipPerModule]= {false}; - unsigned int disabledChipFlag=0; - double numHitsInStrip[n_stripPerChip*n_chipPerSide]= {0}; - double numHitsInChip[n_chipPerSide]= {0}; - double totalHitsInWafer=0; - int n_noisyStrip=0; - int n_noHitsStrip=0; - int n_disabledStrip=0; - int n_disabledInChip[n_chipPerSide]= {0}; - - //initialize - int side = m_pSCTHelper->side(waferId); - if(side==0) { - isDead=false; - beforeIsDead=false; - beginDead=0; - endDead=0; - defectStrip.erase(); - defectChip.erase(); - } - - //check if module/link is disabled or not - bool disabled=false; - if(badMods->find(moduleId)!=badMods->end()) disabled=true; - linkItr=badLinks->find(waferHash); - if(linkItr!=linkEnd) { - std::pair<bool, bool> status = (*linkItr).second; - if((side==0 && status.first==true) || (side==1 && status.second==true)) disabled=true; - } - - //check BS Error - bool hasBSError=false; - if(m_calibBsErrSvc->size((int)waferHash)>0) hasBSError=true; - if(disabled || hasBSError) { //goto WRITE_DB; //<-- who ever put this in should be shot; http://xkcd.com/292/ - if(side==1) { - //write to DB & .xml. - if(defectChip==" 0-5 6-11 ") { - n_deadModule++; - } else if(defectChip==" 0-5 " || defectChip==" 6-11 ") { - n_deadLink++; - } - - if(!(defectStrip.empty()) || !(defectChip.empty())) { - if (addToSummaryStr(summaryList, waferId, "DEAD", defectStrip.c_str(), defectChip.c_str()).isFailure()) { - return msg( MSG::ERROR ) << "Could not add dead strips to the summary" << endmsg, StatusCode::FAILURE; - } - } - - if(!(defectStrip.empty())) { - if(m_writeToCool) { - if (m_pCalibWriteSvc->createListStrip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadStripSignificance,defectStrip).isFailure()) - return msg( MSG::ERROR ) << "Could not create list" << endmsg, StatusCode::FAILURE; - } - - if (addToXML4DB(m_outDeadStrips, waferId, "DEAD", m_deadStripSignificance, defectStrip.c_str()).isFailure()) - return msg( MSG::ERROR ) << "Could not add dead strips to the summary" << endmsg, StatusCode::FAILURE; - - hasDeadStrip=true; - } - - if(!(defectChip.empty())) { - if(m_writeToCool) { - if ( m_pCalibWriteSvc->createListChip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadChipSignificance,defectChip).isFailure()) - return msg( MSG::ERROR ) << "Could not create list" << endmsg, StatusCode::FAILURE; - } - - if (addToXML4DB(m_outDeadChips, waferId, "DEAD", m_deadChipSignificance, defectChip.c_str()).isFailure()) - return msg( MSG::ERROR ) << "Could not add dead chips to the summary" << endmsg, StatusCode::FAILURE; - - hasDeadChip=true; - - } + } + + //Dead identification + bool hasDeadStrip=false; + bool hasDeadChip=false; + bool isNoHitLink=false; + bool isDead=false; + bool beforeIsDead=false; + int n_deadStrip=0; + int n_deadChip=0; + int n_deadLink=0; + int n_deadModule=0; + int n_checkedChip=0; + int beginDead=0; + int endDead=0; + std::string defectStrip; + std::string defectChip; + std::ostringstream summaryList; + defectStrip.erase(); + defectChip.erase(); + const double deadStripDefinition = ROOT::Math::gaussian_cdf_c(m_deadStripSignificance); + const double deadChipDefinition = ROOT::Math::gaussian_cdf_c(m_deadChipSignificance); + + + //--- Loop over wafers + waferItr = m_waferItrBegin; + for( ; waferItr != m_waferItrEnd; ++waferItr ) { + Identifier waferId = *waferItr; + Identifier moduleId = m_pSCTHelper->module_id(waferId); + IdentifierHash waferHash = m_pSCTHelper->wafer_hash(waferId); + + bool disabledChip[n_chipPerModule]= {false}; + unsigned int disabledChipFlag=0; + double numHitsInStrip[n_stripPerChip*n_chipPerSide]= {0}; + double numHitsInChip[n_chipPerSide]= {0}; + double totalHitsInWafer=0; + int n_noisyStrip=0; + int n_noHitsStrip=0; + int n_disabledStrip=0; + int n_disabledInChip[n_chipPerSide]= {0}; + + //initialize + int side = m_pSCTHelper->side(waferId); + if(side==0) { + isDead=false; + beforeIsDead=false; + beginDead=0; + endDead=0; + defectStrip.erase(); + defectChip.erase(); + } + + //check if module/link is disabled or not + bool disabled=false; + if(badMods->find(moduleId)!=badMods->end()) disabled=true; + linkItr=badLinks->find(waferHash); + if(linkItr!=linkEnd) { + std::pair<bool, bool> status = (*linkItr).second; + if((side==0 && status.first==true) || (side==1 && status.second==true)) disabled=true; + } + + //check BS Error + bool hasBSError=false; + if(m_calibBsErrTool->size((int)waferHash)>0) hasBSError=true; + if(disabled || hasBSError) { //goto WRITE_DB; //<-- who ever put this in should be shot; http://xkcd.com/292/ + if(side==1) { + //write to DB & .xml. + if(defectChip==" 0-5 6-11 ") { + n_deadModule++; + } else if(defectChip==" 0-5 " || defectChip==" 6-11 ") { + n_deadLink++; } - continue; - } - //retrieving info of chip status - chipItr=badChips->find(moduleId); - if(chipItr!=chipEnd) disabledChipFlag = (*chipItr).second; - for (unsigned int i(0); i<n_chipPerModule; i++) - disabledChip[i] = ((disabledChipFlag & (1<<i)) != 0); - - //retrieving #hits in each strip - for(int j=0; j<n_stripPerChip*n_chipPerSide; j++) { - const InDetDD::SiDetectorElement* pElement = elements->getDetectorElement(waferHash); - bool swap=(pElement->swapPhiReadoutDirection()) ? true : false; - int chipNum=0; - if(side==0) chipNum = swap ? 5-j/n_stripPerChip : j/n_stripPerChip; - else chipNum = swap ? 11-j/n_stripPerChip : 6+j/n_stripPerChip; - int stripNum = swap ? 767-j : j; - Identifier stripId = m_pSCTHelper->strip_id(waferId,j); - - numHitsInStrip[stripNum] = m_calibHitmapSvc->getBinForHistogramIndex( j+1 , (int) waferHash); - bool misMatch=false; - double n_hitsInDisable=numHitsInStrip[stripNum]; - if(((disabledChipFlag & (1<<chipNum))!=0) || badStripsExclusive.find(stripId)!=stripEnd) { - if(numHitsInStrip[stripNum]!=0) misMatch = true; - numHitsInStrip[stripNum] = -99; - } - if(misMatch) { - if (msgLvl(MSG::WARNING)) { - msg(MSG::WARNING)<<"hits in disabled Strip : " - <<"n_hits="<<n_hitsInDisable<<", " - <<"bec="<<m_pSCTHelper->barrel_ec(stripId)<<", " - <<"layer="<<m_pSCTHelper->layer_disk(stripId)<<", " - <<"phi="<<m_pSCTHelper->phi_module(stripId)<<", " - <<"eta="<<m_pSCTHelper->eta_module(stripId)<<", " - <<"side="<<m_pSCTHelper->side(stripId)<<", " - <<"strip="<<m_pSCTHelper->strip(stripId)<<endmsg; - } + + if(!(defectStrip.empty()) || !(defectChip.empty())) { + if (addToSummaryStr(summaryList, waferId, "DEAD", defectStrip.c_str(), defectChip.c_str()).isFailure()) { + return msg( MSG::ERROR ) << "Could not add dead strips to the summary" << endmsg, StatusCode::FAILURE; + } } - if(numHitsInStrip[stripNum]==0) { - n_noHitsStrip++; - msg(MSG::DEBUG)<<"nohit strip : barrel_ec="<<m_pSCTHelper->barrel_ec(stripId) - <<", layer="<<m_pSCTHelper->layer_disk(stripId)<<", phi="<<m_pSCTHelper->phi_module(stripId) - <<", eta="<<m_pSCTHelper->eta_module(stripId)<<", side="<<m_pSCTHelper->side(stripId) - <<", strip=offline"<<m_pSCTHelper->strip(stripId)<<endmsg; - } else if(numHitsInStrip[stripNum]==-99) { - n_disabledStrip++; - n_disabledInChip[stripNum/n_stripPerChip]++; - msg(MSG::DEBUG)<<"disabled strip : barrel_ec="<<m_pSCTHelper->barrel_ec(stripId) - <<", layer="<<m_pSCTHelper->layer_disk(stripId)<<", phi="<<m_pSCTHelper->phi_module(stripId) - <<", eta="<<m_pSCTHelper->eta_module(stripId)<<", side="<<m_pSCTHelper->side(stripId) - <<", strip=offline"<<m_pSCTHelper->strip(stripId)<<endmsg; - } else if(numHitsInStrip[stripNum]/m_numberOfEvents>m_noisyThr4DeadFinding) { - n_noisyStrip++; - } else { - totalHitsInWafer+=numHitsInStrip[stripNum]; + if(!(defectStrip.empty())) { + if(m_writeToCool) { + if (m_pCalibWriteTool->createListStrip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadStripSignificance,defectStrip).isFailure()) + return msg( MSG::ERROR ) << "Could not create list" << endmsg, StatusCode::FAILURE; + } + + if (addToXML4DB(m_outDeadStrips, waferId, "DEAD", m_deadStripSignificance, defectStrip.c_str()).isFailure()) + return msg( MSG::ERROR ) << "Could not add dead strips to the summary" << endmsg, StatusCode::FAILURE; + + hasDeadStrip=true; } - }//end strip loop + if(!(defectChip.empty())) { + if(m_writeToCool) { + if ( m_pCalibWriteTool->createListChip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadChipSignificance,defectChip).isFailure()) + return msg( MSG::ERROR ) << "Could not create list" << endmsg, StatusCode::FAILURE; + } + + if (addToXML4DB(m_outDeadChips, waferId, "DEAD", m_deadChipSignificance, defectChip.c_str()).isFailure()) + return msg( MSG::ERROR ) << "Could not add dead chips to the summary" << endmsg, StatusCode::FAILURE; + + hasDeadChip=true; - if(n_disabledStrip==768) { - if(side==1) { - //write to DB & .xml. - if(defectChip==" 0-5 6-11 ") { - n_deadModule++; - } else if(defectChip==" 0-5 " || defectChip==" 6-11 ") { - n_deadLink++; - } - if(!(defectStrip.empty()) || !(defectChip.empty())) { - if (addToSummaryStr(summaryList, waferId, "DEAD", defectStrip.c_str(), defectChip.c_str()).isFailure()) - return msg( MSG::ERROR ) << "Could not add dead strips to the summary" << endmsg, StatusCode::FAILURE; - - } - - if(!(defectStrip.empty())) { - if(m_writeToCool) { - if (m_pCalibWriteSvc->createListStrip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadStripSignificance,defectStrip).isFailure()) - return msg( MSG::ERROR ) << "Could not create strip list" << endmsg, StatusCode::FAILURE; - } - - if (addToXML4DB(m_outDeadStrips, waferId, "DEAD", m_deadStripSignificance, defectStrip.c_str()).isFailure()) - return msg( MSG::ERROR ) << "Could not add xml strip list" << endmsg, StatusCode::FAILURE; - - hasDeadStrip=true; - - } - if(!(defectChip.empty())) { - if(m_writeToCool) { - if (m_pCalibWriteSvc->createListChip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadChipSignificance,defectChip).isFailure()) - return msg( MSG::ERROR ) << "Could not create strip list" << endmsg, StatusCode::FAILURE; - } - - if (addToXML4DB(m_outDeadChips, waferId, "DEAD", m_deadChipSignificance, defectChip.c_str()).isFailure()) - return msg( MSG::ERROR ) << "Could not add xml chip list" << endmsg, StatusCode::FAILURE; - - hasDeadChip=true; - - } } - continue; + } + continue; + } + //retrieving info of chip status + chipItr=badChips->find(moduleId); + if(chipItr!=chipEnd) disabledChipFlag = (*chipItr).second; + for (unsigned int i(0); i<n_chipPerModule; i++) + disabledChip[i] = ((disabledChipFlag & (1<<i)) != 0); + + //retrieving #hits in each strip + for(int j=0; j<n_stripPerChip*n_chipPerSide; j++) { + const InDetDD::SiDetectorElement* pElement = elements->getDetectorElement(waferHash); + bool swap=(pElement->swapPhiReadoutDirection()) ? true : false; + int chipNum=0; + if(side==0) chipNum = swap ? 5-j/n_stripPerChip : j/n_stripPerChip; + else chipNum = swap ? 11-j/n_stripPerChip : 6+j/n_stripPerChip; + int stripNum = swap ? 767-j : j; + Identifier stripId = m_pSCTHelper->strip_id(waferId,j); + + numHitsInStrip[stripNum] = m_calibHitmapTool->getBinForHistogramIndex( j+1, (int) waferHash); + bool misMatch=false; + double n_hitsInDisable=numHitsInStrip[stripNum]; + if(((disabledChipFlag & (1<<chipNum))!=0) || badStripsExclusive.find(stripId)!=stripEnd) { + if(numHitsInStrip[stripNum]!=0) misMatch = true; + numHitsInStrip[stripNum] = -99; + } + if(misMatch) { + if (msgLvl(MSG::WARNING)) { + msg(MSG::WARNING)<<"hits in disabled Strip : " + <<"n_hits="<<n_hitsInDisable<<", " + <<"bec="<<m_pSCTHelper->barrel_ec(stripId)<<", " + <<"layer="<<m_pSCTHelper->layer_disk(stripId)<<", " + <<"phi="<<m_pSCTHelper->phi_module(stripId)<<", " + <<"eta="<<m_pSCTHelper->eta_module(stripId)<<", " + <<"side="<<m_pSCTHelper->side(stripId)<<", " + <<"strip="<<m_pSCTHelper->strip(stripId)<<endmsg; + } + } + + if(numHitsInStrip[stripNum]==0) { + n_noHitsStrip++; + msg(MSG::DEBUG)<<"nohit strip : barrel_ec="<<m_pSCTHelper->barrel_ec(stripId) + <<", layer="<<m_pSCTHelper->layer_disk(stripId)<<", phi="<<m_pSCTHelper->phi_module(stripId) + <<", eta="<<m_pSCTHelper->eta_module(stripId)<<", side="<<m_pSCTHelper->side(stripId) + <<", strip=offline"<<m_pSCTHelper->strip(stripId)<<endmsg; + } else if(numHitsInStrip[stripNum]==-99) { + n_disabledStrip++; + n_disabledInChip[stripNum/n_stripPerChip]++; + msg(MSG::DEBUG)<<"disabled strip : barrel_ec="<<m_pSCTHelper->barrel_ec(stripId) + <<", layer="<<m_pSCTHelper->layer_disk(stripId)<<", phi="<<m_pSCTHelper->phi_module(stripId) + <<", eta="<<m_pSCTHelper->eta_module(stripId)<<", side="<<m_pSCTHelper->side(stripId) + <<", strip=offline"<<m_pSCTHelper->strip(stripId)<<endmsg; + } else if(numHitsInStrip[stripNum]/m_numberOfEvents>m_noisyThr4DeadFinding) { + n_noisyStrip++; + } else { + totalHitsInWafer+=numHitsInStrip[stripNum]; + } + + }//end strip loop + + if(n_disabledStrip==768) { + if(side==1) { + //write to DB & .xml. + if(defectChip==" 0-5 6-11 ") { + n_deadModule++; + } else if(defectChip==" 0-5 " || defectChip==" 6-11 ") { + n_deadLink++; + } + if(!(defectStrip.empty()) || !(defectChip.empty())) { + if (addToSummaryStr(summaryList, waferId, "DEAD", defectStrip.c_str(), defectChip.c_str()).isFailure()) + return msg( MSG::ERROR ) << "Could not add dead strips to the summary" << endmsg, StatusCode::FAILURE; - } - - isNoHitLink=false; - if(n_noHitsStrip+n_disabledStrip==768) { - n_checkedChip+=n_chipPerSide; - isNoHitLink=true; - - double meanOccu=0; - if(m_pSCTHelper->barrel_ec(waferId)==BARREL) meanOccu=meanOccupancy_Barrel[m_pSCTHelper->layer_disk(waferId)]; - else meanOccu=meanOccupancy_EC[m_pSCTHelper->layer_disk(waferId)][m_pSCTHelper->eta_module(waferId)]; - double sum_binomial = ROOT::Math::binomial_cdf(0, meanOccu, m_numberOfEvents*n_stripPerChip*n_chipPerSide); - - if(sum_binomial<deadChipDefinition) { - if (msgLvl(MSG::INFO)) msg(MSG::INFO)<<"DEADLINK : "<<moduleId<<", side="<<side<<endmsg; - n_deadChip+=n_chipPerSide; - - //For DeadStrip - if(m_doDeadStrip) { - if(side==0) beginDead=0, endDead=767; - else beginDead=768, endDead=1535; - defectStrip = m_pCalibWriteSvc->addDefect(defectStrip,beginDead,endDead); - } - - //For DeadChip - if(m_doDeadChip) { - if(side==0) beginDead=0, endDead=5; - else beginDead=6, endDead=11; - defectChip = m_pCalibWriteSvc->addDefect(defectChip,beginDead,endDead); - } - - if(side==1) { - //write to DB & .xml. - if(defectChip==" 0-5 6-11 ") { - n_deadModule++; - } else if(defectChip==" 0-5 " || defectChip==" 6-11 ") { - n_deadLink++; - } - - if(!(defectStrip.empty()) || !(defectChip.empty())) { - if (addToSummaryStr(summaryList, waferId, "DEAD", defectStrip.c_str(), defectChip.c_str()).isFailure()) - return msg( MSG::ERROR ) << "Could not add dead strips to the summary" << endmsg, StatusCode::FAILURE; - - - } - if(!(defectStrip.empty())) { - if(m_writeToCool) { - if (m_pCalibWriteSvc->createListStrip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadStripSignificance,defectStrip).isFailure()) - return msg( MSG::ERROR ) << "Could not create strip list" << endmsg, StatusCode::FAILURE; - } + } - if (addToXML4DB(m_outDeadStrips, waferId, "DEAD", m_deadStripSignificance, defectStrip.c_str()).isFailure()) - return msg( MSG::ERROR ) << "Could not add xml strip list" << endmsg, StatusCode::FAILURE; + if(!(defectStrip.empty())) { + if(m_writeToCool) { + if (m_pCalibWriteTool->createListStrip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadStripSignificance,defectStrip).isFailure()) + return msg( MSG::ERROR ) << "Could not create strip list" << endmsg, StatusCode::FAILURE; + } - hasDeadStrip=true; + if (addToXML4DB(m_outDeadStrips, waferId, "DEAD", m_deadStripSignificance, defectStrip.c_str()).isFailure()) + return msg( MSG::ERROR ) << "Could not add xml strip list" << endmsg, StatusCode::FAILURE; - } + hasDeadStrip=true; - if(!(defectChip.empty())) { - if(m_writeToCool) { - if ( m_pCalibWriteSvc->createListChip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadChipSignificance,defectChip).isFailure()) - return msg( MSG::ERROR ) << "Could not create chip list" << endmsg, StatusCode::FAILURE; - } + } + if(!(defectChip.empty())) { + if(m_writeToCool) { + if (m_pCalibWriteTool->createListChip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadChipSignificance,defectChip).isFailure()) + return msg( MSG::ERROR ) << "Could not create strip list" << endmsg, StatusCode::FAILURE; + } - if (addToXML4DB(m_outDeadChips, waferId, "DEAD", m_deadChipSignificance, defectChip.c_str()).isFailure()) - return msg( MSG::ERROR ) << "Could not add xml chip list" << endmsg, StatusCode::FAILURE; + if (addToXML4DB(m_outDeadChips, waferId, "DEAD", m_deadChipSignificance, defectChip.c_str()).isFailure()) + return msg( MSG::ERROR ) << "Could not add xml chip list" << endmsg, StatusCode::FAILURE; - hasDeadChip=true; + hasDeadChip=true; - } - } - continue; } - }//end DeadLink - - if(n_noHitsStrip>0) { - int n_deadStripInWafer=0; - int n_deadChipInWafer=0; - - double n_effectiveEvents=0; - if(busyStream) n_effectiveEvents = m_numberOfEvents*(n_stripPerChip*n_chipPerSide-n_disabledStrip-n_noisyStrip-n_noHitsStrip); - else n_effectiveEvents = m_numberOfEvents*(n_stripPerChip*n_chipPerSide-n_disabledStrip-n_noisyStrip); - - //First, check DeadChip - double meanOccupancy = totalHitsInWafer/n_effectiveEvents; - for(int j=0; j<n_stripPerChip*n_chipPerSide; j++) - if(numHitsInStrip[j]>0) numHitsInChip[j/n_stripPerChip] += numHitsInStrip[j]; - - for(int j=0; j<n_chipPerSide; j++) { - isDead=false; - int chipNum = side==0 ? j : j+6; - if(numHitsInChip[j]==0 && !disabledChip[chipNum]) { - if(!isNoHitLink) n_checkedChip++; - double sum_binomial = ROOT::Math::binomial_cdf(0, meanOccupancy, m_numberOfEvents*(n_stripPerChip-n_disabledInChip[j])); - if(sum_binomial<deadChipDefinition) { - if (msgLvl(MSG::INFO)) msg(MSG::INFO)<<"DEADCHIP : "<<moduleId<<", side="<<side - <<", chip(online)="<<(side==0 ? j : j+n_chipPerSide)<<endmsg; - isDead=true; - n_deadChip++; - n_deadChipInWafer++; - endDead = side==0 ? j : j+n_chipPerSide; - if(!beforeIsDead) beginDead = side==0 ? j : j+n_chipPerSide; - } - } - - if(m_doDeadChip) { - if((beforeIsDead && !isDead) || (j==5 && isDead)) defectChip = m_pCalibWriteSvc->addDefect(defectChip,beginDead,endDead); - } - beforeIsDead = isDead; - }//end chip loop - - //Second, check DeadStrip + } + continue; + + } + + isNoHitLink=false; + if(n_noHitsStrip+n_disabledStrip==768) { + n_checkedChip+=n_chipPerSide; + isNoHitLink=true; + + double meanOccu=0; + if(m_pSCTHelper->barrel_ec(waferId)==BARREL) meanOccu=meanOccupancy_Barrel[m_pSCTHelper->layer_disk(waferId)]; + else meanOccu=meanOccupancy_EC[m_pSCTHelper->layer_disk(waferId)][m_pSCTHelper->eta_module(waferId)]; + double sum_binomial = ROOT::Math::binomial_cdf(0, meanOccu, m_numberOfEvents*n_stripPerChip*n_chipPerSide); + + if(sum_binomial<deadChipDefinition) { + if (msgLvl(MSG::INFO)) msg(MSG::INFO)<<"DEADLINK : "<<moduleId<<", side="<<side<<endmsg; + n_deadChip+=n_chipPerSide; + + //For DeadStrip if(m_doDeadStrip) { - double meanOccExceptDeadChip=totalHitsInWafer/(n_effectiveEvents-n_stripPerChip*n_deadChipInWafer); - double numHitsInStripOnlineOrder[n_stripPerChip*n_chipPerSide]= {0}; - for(int j=0; j<n_stripPerChip*n_chipPerSide; j++) { - numHitsInStripOnlineOrder[j] = side==0 ? numHitsInStrip[j] : numHitsInStrip[n_stripPerChip*n_chipPerSide-j]; - isDead=false; - if(numHitsInStripOnlineOrder[j]==0) { - double sum_binomial = ROOT::Math::binomial_cdf(0, meanOccExceptDeadChip, m_numberOfEvents); - if(sum_binomial<deadStripDefinition) { - if (msgLvl(MSG::INFO)) msg(MSG::INFO)<<"DEADSTRIP : "<<moduleId<<", side="<<side<<", strip(offline)="<<j<<endmsg; - isDead=true; - n_deadStrip++; - n_deadStripInWafer++; - endDead = side==0 ? j : j+n_stripPerChip*n_chipPerSide; - if(!beforeIsDead) beginDead = side==0 ? j : j+n_stripPerChip*n_chipPerSide; - } - } + if(side==0) beginDead=0, endDead=767; + else beginDead=768, endDead=1535; + defectStrip = m_pCalibWriteTool->addDefect(defectStrip,beginDead,endDead); + } - if(m_doDeadStrip) { - if((beforeIsDead && !isDead) || (j==5 && isDead)) defectStrip = m_pCalibWriteSvc->addDefect(defectStrip,beginDead,endDead); - } - beforeIsDead = isDead; - } + //For DeadChip + if(m_doDeadChip) { + if(side==0) beginDead=0, endDead=5; + else beginDead=6, endDead=11; + defectChip = m_pCalibWriteTool->addDefect(defectChip,beginDead,endDead); } - } - //go to next wafer itr - }//Wafer Loop end + if(side==1) { + //write to DB & .xml. + if(defectChip==" 0-5 6-11 ") { + n_deadModule++; + } else if(defectChip==" 0-5 " || defectChip==" 6-11 ") { + n_deadLink++; + } + if(!(defectStrip.empty()) || !(defectChip.empty())) { + if (addToSummaryStr(summaryList, waferId, "DEAD", defectStrip.c_str(), defectChip.c_str()).isFailure()) + return msg( MSG::ERROR ) << "Could not add dead strips to the summary" << endmsg, StatusCode::FAILURE; - //Close Files - if(m_doDeadStrip) { - msg(MSG::INFO)<<"total #DeadStrip : "<<n_deadStrip<<endmsg; - if(closeXML4DB(m_outDeadStrips).isFailure()) { - msg(MSG::ERROR)<<"Problem closing "<<m_deadStripsFile<<endmsg; - return StatusCode::FAILURE; - } - } - if(m_doDeadChip) { - msg(MSG::INFO)<<"total #DeadChip : "<<n_deadChip<<", #noHitChip : "<<n_checkedChip<<endmsg; - if(closeXML4DB(m_outDeadChips).isFailure()) { - msg(MSG::ERROR)<<"Problem closing "<<m_deadChipsFile<<endmsg; - return StatusCode::FAILURE; - } - } - - //Making Summary File - if(openXML4DeadSummary(m_outDeadSummary, "DEAD", n_deadModule, n_deadLink, n_deadChip, n_deadStrip).isFailure()) { - msg(MSG::ERROR)<<"Problem opening "<<m_deadSummaryFile<<endmsg; - return StatusCode::FAILURE; - } - if(wrapUpXML4Summary(m_outDeadSummary, "DEAD", summaryList).isFailure()) { - msg(MSG::ERROR)<<"Problem closing "<<m_deadSummaryFile<<endmsg; - return StatusCode::FAILURE; - } - - if( m_writeToCool ) { - if(m_doDeadStrip && hasDeadStrip) { - if ( m_pCalibWriteSvc->wrapUpDeadStrips().isFailure() ) { - msg( MSG::ERROR ) << "Could not get DeadStrips Info" << endmsg; - return StatusCode::FAILURE; + + } + if(!(defectStrip.empty())) { + if(m_writeToCool) { + if (m_pCalibWriteTool->createListStrip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadStripSignificance,defectStrip).isFailure()) + return msg( MSG::ERROR ) << "Could not create strip list" << endmsg, StatusCode::FAILURE; + } + + if (addToXML4DB(m_outDeadStrips, waferId, "DEAD", m_deadStripSignificance, defectStrip.c_str()).isFailure()) + return msg( MSG::ERROR ) << "Could not add xml strip list" << endmsg, StatusCode::FAILURE; + + hasDeadStrip=true; + + } + + if(!(defectChip.empty())) { + if(m_writeToCool) { + if ( m_pCalibWriteTool->createListChip(moduleId,m_pSCTHelper,10000,"DEAD",m_deadChipSignificance,defectChip).isFailure()) + return msg( MSG::ERROR ) << "Could not create chip list" << endmsg, StatusCode::FAILURE; + } + + if (addToXML4DB(m_outDeadChips, waferId, "DEAD", m_deadChipSignificance, defectChip.c_str()).isFailure()) + return msg( MSG::ERROR ) << "Could not add xml chip list" << endmsg, StatusCode::FAILURE; + + hasDeadChip=true; + + } } - } - if(m_doDeadChip && hasDeadChip) { - if ( m_pCalibWriteSvc->wrapUpDeadChips().isFailure() ) { - msg( MSG::ERROR ) << "Could not get DeadChips Info" << endmsg; - return StatusCode::FAILURE; + continue; + } + }//end DeadLink + + if(n_noHitsStrip>0) { + int n_deadStripInWafer=0; + int n_deadChipInWafer=0; + + double n_effectiveEvents=0; + if(busyStream) n_effectiveEvents = m_numberOfEvents*(n_stripPerChip*n_chipPerSide-n_disabledStrip-n_noisyStrip-n_noHitsStrip); + else n_effectiveEvents = m_numberOfEvents*(n_stripPerChip*n_chipPerSide-n_disabledStrip-n_noisyStrip); + + //First, check DeadChip + double meanOccupancy = totalHitsInWafer/n_effectiveEvents; + for(int j=0; j<n_stripPerChip*n_chipPerSide; j++) + if(numHitsInStrip[j]>0) numHitsInChip[j/n_stripPerChip] += numHitsInStrip[j]; + + for(int j=0; j<n_chipPerSide; j++) { + isDead=false; + int chipNum = side==0 ? j : j+6; + if(numHitsInChip[j]==0 && !disabledChip[chipNum]) { + if(!isNoHitLink) n_checkedChip++; + double sum_binomial = ROOT::Math::binomial_cdf(0, meanOccupancy, m_numberOfEvents*(n_stripPerChip-n_disabledInChip[j])); + if(sum_binomial<deadChipDefinition) { + if (msgLvl(MSG::INFO)) msg(MSG::INFO)<<"DEADCHIP : "<<moduleId<<", side="<<side + <<", chip(online)="<<(side==0 ? j : j+n_chipPerSide)<<endmsg; + isDead=true; + n_deadChip++; + n_deadChipInWafer++; + endDead = side==0 ? j : j+n_chipPerSide; + if(!beforeIsDead) beginDead = side==0 ? j : j+n_chipPerSide; + } + } + + if(m_doDeadChip) { + if((beforeIsDead && !isDead) || (j==5 && isDead)) defectChip = m_pCalibWriteTool->addDefect(defectChip,beginDead,endDead); + } + beforeIsDead = isDead; + }//end chip loop + + //Second, check DeadStrip + if(m_doDeadStrip) { + double meanOccExceptDeadChip=totalHitsInWafer/(n_effectiveEvents-n_stripPerChip*n_deadChipInWafer); + double numHitsInStripOnlineOrder[n_stripPerChip*n_chipPerSide]= {0}; + for(int j=0; j<n_stripPerChip*n_chipPerSide; j++) { + numHitsInStripOnlineOrder[j] = side==0 ? numHitsInStrip[j] : numHitsInStrip[n_stripPerChip*n_chipPerSide-j]; + isDead=false; + if(numHitsInStripOnlineOrder[j]==0) { + double sum_binomial = ROOT::Math::binomial_cdf(0, meanOccExceptDeadChip, m_numberOfEvents); + if(sum_binomial<deadStripDefinition) { + if (msgLvl(MSG::INFO)) msg(MSG::INFO)<<"DEADSTRIP : "<<moduleId<<", side="<<side<<", strip(offline)="<<j<<endmsg; + isDead=true; + n_deadStrip++; + n_deadStripInWafer++; + endDead = side==0 ? j : j+n_stripPerChip*n_chipPerSide; + if(!beforeIsDead) beginDead = side==0 ? j : j+n_stripPerChip*n_chipPerSide; + } + } + + if(m_doDeadStrip) { + if((beforeIsDead && !isDead) || (j==5 && isDead)) defectStrip = m_pCalibWriteTool->addDefect(defectStrip,beginDead,endDead); + } + beforeIsDead = isDead; } - } - } + } + } + + //go to next wafer itr + }//Wafer Loop end + + + //Close Files + if(m_doDeadStrip) { + msg(MSG::INFO)<<"total #DeadStrip : "<<n_deadStrip<<endmsg; + if(closeXML4DB(m_outDeadStrips).isFailure()) { + msg(MSG::ERROR)<<"Problem closing "<<m_deadStripsFile<<endmsg; + return StatusCode::FAILURE; + } + } + if(m_doDeadChip) { + msg(MSG::INFO)<<"total #DeadChip : "<<n_deadChip<<", #noHitChip : "<<n_checkedChip<<endmsg; + if(closeXML4DB(m_outDeadChips).isFailure()) { + msg(MSG::ERROR)<<"Problem closing "<<m_deadChipsFile<<endmsg; + return StatusCode::FAILURE; + } + } + + //Making Summary File + if(openXML4DeadSummary(m_outDeadSummary, "DEAD", n_deadModule, n_deadLink, n_deadChip, n_deadStrip).isFailure()) { + msg(MSG::ERROR)<<"Problem opening "<<m_deadSummaryFile<<endmsg; + return StatusCode::FAILURE; + } + if(wrapUpXML4Summary(m_outDeadSummary, "DEAD", summaryList).isFailure()) { + msg(MSG::ERROR)<<"Problem closing "<<m_deadSummaryFile<<endmsg; + return StatusCode::FAILURE; + } + + if( m_writeToCool ) { + if(m_doDeadStrip && hasDeadStrip) { + if ( m_pCalibWriteTool->wrapUpDeadStrips().isFailure() ) { + msg( MSG::ERROR ) << "Could not get DeadStrips Info" << endmsg; + return StatusCode::FAILURE; + } + } + if(m_doDeadChip && hasDeadChip) { + if ( m_pCalibWriteTool->wrapUpDeadChips().isFailure() ) { + msg( MSG::ERROR ) << "Could not get DeadChips Info" << endmsg; + return StatusCode::FAILURE; + } + } + } - msg(MSG::INFO)<<"END HERE"<<endmsg; - return StatusCode::SUCCESS; + msg(MSG::INFO)<<"END HERE"<<endmsg; + return StatusCode::SUCCESS; } @@ -1271,214 +1270,214 @@ StatusCode SCTCalib::getDeadStrip() { StatusCode SCTCalib::getNoiseOccupancy() { - msg( MSG::INFO ) << "----- in getNoiseOccupancy() -----" << endmsg; - - //--- Initialization - int n_phiBinsBarrel[ n_barrels ] = { n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3 }; - int n_phiBinsEndcap[ n_disks ][ n_etaBinsEC ] = { { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, 0, 0 } - }; - - double meanNO_Barrel[ n_barrels ] = { 0 }; - double meanNO_ECA[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; - double meanNO_ECC[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; - - //--- RunNumber - std::ostringstream runnum; - runnum << (int) m_runNumber; - - //--- Directory in HIST - std::string stem; - - //--- EndcapC - stem = "/run_" + runnum.str() + "/SCT/SCTEC/Noise/"; - m_pnoiseoccupancymapHistoVectorECm.clear(); - for ( int iDisk = 0; iDisk < n_disks ; ++iDisk ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - ostringstream streamHist; - streamHist << "noiseoccupancymap"; - if ( m_noiseOccupancyTriggerAware ) streamHist << "trigger"; - streamHist << "ECm_" << iDisk << "_" << iSide; - std::string histName = stem + streamHist.str(); - TProfile2D* hist_tmp = (TProfile2D *) m_inputHist->Get( histName.c_str() ); - m_pnoiseoccupancymapHistoVectorECm.push_back( hist_tmp ); - } - } - //--- Barrel - stem = "/run_" + runnum.str() + "/SCT/SCTB/Noise/"; - m_pnoiseoccupancymapHistoVector.clear(); - for ( int iLayer = 0; iLayer < n_barrels ; ++iLayer ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - ostringstream streamHist; - streamHist << "noiseoccupancymap"; - if ( m_noiseOccupancyTriggerAware ) streamHist << "trigger"; - streamHist << "_" << iLayer << "_" << iSide; - std::string histName = stem + streamHist.str(); - TProfile2D* hist_tmp = (TProfile2D *) m_inputHist->Get( histName.c_str() ); - m_pnoiseoccupancymapHistoVector.push_back( hist_tmp ); - } - } - //--- EndcapA - stem = "/run_" + runnum.str() + "/SCT/SCTEA/Noise/"; - m_pnoiseoccupancymapHistoVectorECp.clear(); - for ( int iDisk = 0; iDisk < n_disks ; ++iDisk ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - ostringstream streamHist; - streamHist << "noiseoccupancymap"; - if ( m_noiseOccupancyTriggerAware ) streamHist << "trigger"; - streamHist << "ECp_" << iDisk << "_" << iSide; - std::string histName = stem + streamHist.str(); - TProfile2D* hist_tmp = (TProfile2D *) m_inputHist->Get( histName.c_str() ); - m_pnoiseoccupancymapHistoVectorECp.push_back( hist_tmp ); - } - } - - //--- XML file - const char* outputNoiseOccupancyFileName = m_noiseOccupancyFile.c_str(); - ofstream outFile( outputNoiseOccupancyFileName, std::ios::out ); - if ( !outFile.good() ) { - msg( MSG::ERROR ) << "Unable to open NoiseOccupancyFile : " << outputNoiseOccupancyFileName << endmsg; - return StatusCode::FAILURE; - } - - //--- Header for XML outputs - ostringstream osHeader; - osHeader << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"MONP200\" folder=\"SCT/Derived/NoiseOccupancy\" " - << "since=\"" << m_iovStart.re_time() << "\" " - << "until=\"" << m_iovStop.re_time() << "\" " - << "tag=\"" << m_tagID4NoiseOccupancy << "\" " - << "version=\"" << "multi\">"<< endl; - outFile << osHeader.str(); - - //--- EndcapC - for ( int iDisk = 0; iDisk < n_disks ; ++iDisk ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - for ( int iEta = 0; iEta < n_etaBinsEC; ++iEta ) { - for ( int iPhi = 0; iPhi < n_phiBinsEndcap[iDisk][iEta]; ++iPhi ) { - Identifier waferId = m_pSCTHelper->wafer_id( ENDCAP_C, iDisk, iPhi, iEta, iSide ); - float occupancy = m_pnoiseoccupancymapHistoVectorECm[ 2*iDisk + iSide ]->GetBinContent( iEta+1, iPhi+1 ); - occupancy /= float( ntimeBins ); - occupancy /= 1E5; - //--- For calculating average Noise Occupancy - meanNO_ECC[iDisk][iEta]+=occupancy; - //outFile << outFile << xmlChannelNoiseOccDataString(waferId, occupancy)<<endl; - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - outFile << xmlChannelNoiseOccDataString(waferId, occupancy, sn)<<endl; - //--- DB output - if ( m_writeToCool ) { - if ( m_pCalibWriteSvc->createListNO( waferId, m_pSCTHelper, 10000, occupancy ).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListNO" << endmsg; - return StatusCode::FAILURE; - } - } - } - } - } - } - //--- Barrel - for ( int iLayer = 0; iLayer < n_barrels; ++iLayer ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - for ( int iEta = 0; iEta < n_etaBins; ++iEta ) { - if ( iEta-6 == 0 ) continue; - for ( int iPhi = 0; iPhi < n_phiBinsBarrel[iLayer]; ++iPhi ) { - Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, iPhi, iEta-6, iSide ); - float occupancy = m_pnoiseoccupancymapHistoVector[ 2*iLayer + iSide ]->GetBinContent( iEta+1, iPhi+1 ); - occupancy /= float( ntimeBins ); - occupancy /= 1E5; - //--- For calculating average Noise Occupancy - meanNO_Barrel[iLayer]+=occupancy; - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - outFile << xmlChannelNoiseOccDataString(waferId, occupancy, sn)<<endl; - //--- DB output - if ( m_writeToCool ) { - if ( m_pCalibWriteSvc->createListNO( waferId, m_pSCTHelper, 10000, occupancy ).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListNO" << endmsg; - return StatusCode::FAILURE; - } - } - } - } - } - } - //--- EndcapA - for ( int iDisk = 0; iDisk < n_disks ; ++iDisk ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - for ( int iEta = 0; iEta < n_etaBinsEC; ++iEta ) { - for ( int iPhi = 0; iPhi < n_phiBinsEndcap[iDisk][iEta]; ++iPhi ) { - Identifier waferId = m_pSCTHelper->wafer_id( ENDCAP_A, iDisk, iPhi, iEta, iSide ); - float occupancy = m_pnoiseoccupancymapHistoVectorECp[ 2*iDisk + iSide ]->GetBinContent( iEta+1, iPhi+1 ); - occupancy /= float( ntimeBins ); - occupancy /= 1E5; - //--- For calculating average Noise Occupancy - meanNO_ECA[iDisk][iEta]+=occupancy; - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - outFile << xmlChannelNoiseOccDataString(waferId, occupancy, sn)<<endl; - //--- DB output - if ( m_writeToCool ) { - if ( m_pCalibWriteSvc->createListNO( waferId, m_pSCTHelper, 10000, occupancy ).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListNO" << endmsg; - return StatusCode::FAILURE; - } - } - } + msg( MSG::INFO ) << "----- in getNoiseOccupancy() -----" << endmsg; + + //--- Initialization + int n_phiBinsBarrel[ n_barrels ] = { n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3 }; + int n_phiBinsEndcap[ n_disks ][ n_etaBinsEC ] = { { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, 0, 0 } + }; + + double meanNO_Barrel[ n_barrels ] = { 0 }; + double meanNO_ECA[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; + double meanNO_ECC[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; + + //--- RunNumber + std::ostringstream runnum; + runnum << (int) m_runNumber; + + //--- Directory in HIST + std::string stem; + + //--- EndcapC + stem = "/run_" + runnum.str() + "/SCT/SCTEC/Noise/"; + m_pnoiseoccupancymapHistoVectorECm.clear(); + for ( int iDisk = 0; iDisk < n_disks ; ++iDisk ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + ostringstream streamHist; + streamHist << "noiseoccupancymap"; + if ( m_noiseOccupancyTriggerAware ) streamHist << "trigger"; + streamHist << "ECm_" << iDisk << "_" << iSide; + std::string histName = stem + streamHist.str(); + TProfile2D* hist_tmp = (TProfile2D *) m_inputHist->Get( histName.c_str() ); + m_pnoiseoccupancymapHistoVectorECm.push_back( hist_tmp ); + } + } + //--- Barrel + stem = "/run_" + runnum.str() + "/SCT/SCTB/Noise/"; + m_pnoiseoccupancymapHistoVector.clear(); + for ( int iLayer = 0; iLayer < n_barrels ; ++iLayer ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + ostringstream streamHist; + streamHist << "noiseoccupancymap"; + if ( m_noiseOccupancyTriggerAware ) streamHist << "trigger"; + streamHist << "_" << iLayer << "_" << iSide; + std::string histName = stem + streamHist.str(); + TProfile2D* hist_tmp = (TProfile2D *) m_inputHist->Get( histName.c_str() ); + m_pnoiseoccupancymapHistoVector.push_back( hist_tmp ); + } + } + //--- EndcapA + stem = "/run_" + runnum.str() + "/SCT/SCTEA/Noise/"; + m_pnoiseoccupancymapHistoVectorECp.clear(); + for ( int iDisk = 0; iDisk < n_disks ; ++iDisk ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + ostringstream streamHist; + streamHist << "noiseoccupancymap"; + if ( m_noiseOccupancyTriggerAware ) streamHist << "trigger"; + streamHist << "ECp_" << iDisk << "_" << iSide; + std::string histName = stem + streamHist.str(); + TProfile2D* hist_tmp = (TProfile2D *) m_inputHist->Get( histName.c_str() ); + m_pnoiseoccupancymapHistoVectorECp.push_back( hist_tmp ); + } + } + + //--- XML file + const char* outputNoiseOccupancyFileName = m_noiseOccupancyFile.c_str(); + ofstream outFile( outputNoiseOccupancyFileName, std::ios::out ); + if ( !outFile.good() ) { + msg( MSG::ERROR ) << "Unable to open NoiseOccupancyFile : " << outputNoiseOccupancyFileName << endmsg; + return StatusCode::FAILURE; + } + + //--- Header for XML outputs + ostringstream osHeader; + osHeader << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"MONP200\" folder=\"SCT/Derived/NoiseOccupancy\" " + << "since=\"" << m_iovStart.re_time() << "\" " + << "until=\"" << m_iovStop.re_time() << "\" " + << "tag=\"" << m_tagID4NoiseOccupancy << "\" " + << "version=\"" << "multi\">"<< endl; + outFile << osHeader.str(); + + //--- EndcapC + for ( int iDisk = 0; iDisk < n_disks ; ++iDisk ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + for ( int iEta = 0; iEta < n_etaBinsEC; ++iEta ) { + for ( int iPhi = 0; iPhi < n_phiBinsEndcap[iDisk][iEta]; ++iPhi ) { + Identifier waferId = m_pSCTHelper->wafer_id( ENDCAP_C, iDisk, iPhi, iEta, iSide ); + float occupancy = m_pnoiseoccupancymapHistoVectorECm[ 2*iDisk + iSide ]->GetBinContent( iEta+1, iPhi+1 ); + occupancy /= float( ntimeBins ); + occupancy /= 1E5; + //--- For calculating average Noise Occupancy + meanNO_ECC[iDisk][iEta]+=occupancy; + //outFile << outFile << xmlChannelNoiseOccDataString(waferId, occupancy)<<endl; + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + outFile << xmlChannelNoiseOccDataString(waferId, occupancy, sn)<<endl; + //--- DB output + if ( m_writeToCool ) { + if ( m_pCalibWriteTool->createListNO( waferId, m_pSCTHelper, 10000, occupancy ).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListNO" << endmsg; + return StatusCode::FAILURE; + } + } } - } - } - - //--- Tail of XML outputs - outFile << "</channels>" << endl; - - //--- Summary XML output - ostringstream summaryList; - for( int i = 0; i < n_disks; ++i ) { - for(int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - meanNO_ECC[i][j] /= (n_phiBinsEndcap[i][j]*2); - summaryList<<xmlPartData(ENDCAP_C, i, j, "meanNO",meanNO_ECC[i][j]); + } + } + } + //--- Barrel + for ( int iLayer = 0; iLayer < n_barrels; ++iLayer ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + for ( int iEta = 0; iEta < n_etaBins; ++iEta ) { + if ( iEta-6 == 0 ) continue; + for ( int iPhi = 0; iPhi < n_phiBinsBarrel[iLayer]; ++iPhi ) { + Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, iPhi, iEta-6, iSide ); + float occupancy = m_pnoiseoccupancymapHistoVector[ 2*iLayer + iSide ]->GetBinContent( iEta+1, iPhi+1 ); + occupancy /= float( ntimeBins ); + occupancy /= 1E5; + //--- For calculating average Noise Occupancy + meanNO_Barrel[iLayer]+=occupancy; + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + outFile << xmlChannelNoiseOccDataString(waferId, occupancy, sn)<<endl; + //--- DB output + if ( m_writeToCool ) { + if ( m_pCalibWriteTool->createListNO( waferId, m_pSCTHelper, 10000, occupancy ).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListNO" << endmsg; + return StatusCode::FAILURE; + } + } } - } - } - for( int i = 0; i < n_barrels; ++i ) { - meanNO_Barrel[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2); - summaryList<<xmlPartData(BARREL, i, 0, "meanNO",meanNO_Barrel[i] ); - } - for( int i = 0; i < n_disks; ++i ) { - for( int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - meanNO_ECA[i][j] /= (n_phiBinsEndcap[i][j]*2); - summaryList<<xmlPartData(ENDCAP_A, i, j, "meanNO",meanNO_ECA[i][j]); + } + } + } + //--- EndcapA + for ( int iDisk = 0; iDisk < n_disks ; ++iDisk ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + for ( int iEta = 0; iEta < n_etaBinsEC; ++iEta ) { + for ( int iPhi = 0; iPhi < n_phiBinsEndcap[iDisk][iEta]; ++iPhi ) { + Identifier waferId = m_pSCTHelper->wafer_id( ENDCAP_A, iDisk, iPhi, iEta, iSide ); + float occupancy = m_pnoiseoccupancymapHistoVectorECp[ 2*iDisk + iSide ]->GetBinContent( iEta+1, iPhi+1 ); + occupancy /= float( ntimeBins ); + occupancy /= 1E5; + //--- For calculating average Noise Occupancy + meanNO_ECA[iDisk][iEta]+=occupancy; + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + outFile << xmlChannelNoiseOccDataString(waferId, occupancy, sn)<<endl; + //--- DB output + if ( m_writeToCool ) { + if ( m_pCalibWriteTool->createListNO( waferId, m_pSCTHelper, 10000, occupancy ).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListNO" << endmsg; + return StatusCode::FAILURE; + } + } } - } - } - - if( openXML4MonSummary( m_outNOSummary, "NoiseOccupancy" ).isFailure() ) { - msg( MSG::ERROR )<< "Problem in opening NoiseOccupancy file" << endmsg; - return StatusCode::FAILURE; - } - if( wrapUpXML4Summary( m_outNOSummary, "NoiseOccupancy", summaryList ).isFailure() ) { - msg( MSG::ERROR )<< "Problem in closing NoiseOccupancy file" << endmsg; - return StatusCode::FAILURE; - } - - //--- DB output - if( m_writeToCool ) { - if ( m_pCalibWriteSvc->wrapUpNoiseOccupancy().isFailure() ) { - msg( MSG::ERROR ) << "Could not get NoiseOccupancy" << endmsg; - return StatusCode::FAILURE; - } - } + } + } + } + + //--- Tail of XML outputs + outFile << "</channels>" << endl; + + //--- Summary XML output + ostringstream summaryList; + for( int i = 0; i < n_disks; ++i ) { + for(int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + meanNO_ECC[i][j] /= (n_phiBinsEndcap[i][j]*2); + summaryList<<xmlPartData(ENDCAP_C, i, j, "meanNO",meanNO_ECC[i][j]); + } + } + } + for( int i = 0; i < n_barrels; ++i ) { + meanNO_Barrel[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2); + summaryList<<xmlPartData(BARREL, i, 0, "meanNO",meanNO_Barrel[i] ); + } + for( int i = 0; i < n_disks; ++i ) { + for( int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + meanNO_ECA[i][j] /= (n_phiBinsEndcap[i][j]*2); + summaryList<<xmlPartData(ENDCAP_A, i, j, "meanNO",meanNO_ECA[i][j]); + } + } + } + + if( openXML4MonSummary( m_outNOSummary, "NoiseOccupancy" ).isFailure() ) { + msg( MSG::ERROR )<< "Problem in opening NoiseOccupancy file" << endmsg; + return StatusCode::FAILURE; + } + if( wrapUpXML4Summary( m_outNOSummary, "NoiseOccupancy", summaryList ).isFailure() ) { + msg( MSG::ERROR )<< "Problem in closing NoiseOccupancy file" << endmsg; + return StatusCode::FAILURE; + } + + //--- DB output + if( m_writeToCool ) { + if ( m_pCalibWriteTool->wrapUpNoiseOccupancy().isFailure() ) { + msg( MSG::ERROR ) << "Could not get NoiseOccupancy" << endmsg; + return StatusCode::FAILURE; + } + } - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } @@ -1489,143 +1488,143 @@ StatusCode SCTCalib::getNoiseOccupancy() StatusCode SCTCalib::getRawOccupancy() { - msg( MSG::INFO ) << "----- in getRawOccupancy() -----" << endmsg; - - //--- Initialization - int n_phiBinsBarrel[ n_barrels ] = { n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3 }; - int n_phiBinsEndcap[ n_disks ][ n_etaBinsEC ] = { { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, 0, 0 } - }; - - double meanRO_Barrel[ n_barrels ] = { 0 }; - double meanRO_ECA[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; - double meanRO_ECC[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; - - //--- RunNumber - std::ostringstream runnum; - runnum << (int) m_runNumber; - - //--- Directory in HIST - std::vector< std::pair<std::string, int> > EC_stems; - EC_stems.clear(); - std::pair<std::string, int> stem_C("/run_" + runnum.str() + "/SCT/SCTEC/hits/", ENDCAP_C); - std::pair<std::string, int> stem_A("/run_" + runnum.str() + "/SCT/SCTEA/hits/", ENDCAP_A); - EC_stems.push_back(stem_C); - EC_stems.push_back(stem_A); - std::vector< std::pair<std::string, int> >::iterator stemItr=EC_stems.begin(); - - //--- Endcaps - for(stemItr=EC_stems.begin(); stemItr!=EC_stems.end(); stemItr++) { - for(int iDisk=0; iDisk<n_disks; ++iDisk) - for(int iSide=0; iSide<2; ++iSide) - for(int iEta=0; iEta<n_etaBinsEC; ++iEta) - for(int iPhi=0; iPhi<n_phiBinsEndcap[iDisk][iEta]; ++iPhi) { - Identifier waferId = m_pSCTHelper->wafer_id( (*stemItr).second, iDisk, iPhi, iEta, iSide ); - std::string detector_part; - detector_part.erase(); - if(m_histBefore2010) { - if( (*stemItr).second==ENDCAP_C ) detector_part = "ECm_hitsmap"; - else detector_part = "ECp_hitsmap"; - } else { - if( (*stemItr).second==ENDCAP_C ) detector_part = "hitsmapECm"; - else detector_part = "hitsmapECp"; - } - ostringstream streamHist; - streamHist << detector_part << "_" << iDisk << "_" << iSide; - std::string hitsmapname = stemItr->first + streamHist.str(); - TH2D* hist_tmp = (TH2D*) m_inputHist->Get( hitsmapname.c_str() ); - unsigned long long n_hits = (unsigned long long)hist_tmp->GetBinContent( iEta+1, iPhi+1 ); - float raw_occu = 0; - if(m_numberOfEvents!=0) { - raw_occu = float(n_hits)/(m_numberOfEvents*n_chipPerSide*n_stripPerChip); - //--- For calculating average Raw Occupancy - if (stemItr->second==ENDCAP_C ) meanRO_ECC[iDisk][iEta]+=(double)raw_occu; - else if( stemItr->second==ENDCAP_A ) meanRO_ECA[iDisk][iEta]+=(double)raw_occu; - } - //--- DB writing - if( m_writeToCool ) { - if( m_pCalibWriteSvc->createListRawOccu(waferId, m_pSCTHelper, m_numberOfEvents, raw_occu).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListRawOccu" << endmsg; - return StatusCode::FAILURE; - } - } - } - } - //--- Barrel - for(int iLayer=0; iLayer<n_barrels; ++iLayer) - for(int iSide=0; iSide<2; ++iSide) - for(int iEta=0; iEta<n_etaBins; ++iEta) { - if(iEta-6==0) continue; - for(int iPhi=0; iPhi<n_phiBinsBarrel[iLayer]; ++iPhi) { - Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, iPhi, iEta-6, iSide ); - ostringstream streamHist; - streamHist << iLayer << "_" << iSide; - std::string hitsmapname = "/run_" + runnum.str() + "/SCT/SCTB/hits/hitsmap_" + streamHist.str(); - TH2D* hist_tmp = (TH2D*) m_inputHist->Get( hitsmapname.c_str() ); - unsigned long long n_hits = (unsigned long long) hist_tmp->GetBinContent( iEta+1, iPhi+1 ); - float raw_occu = 0; - if(m_numberOfEvents!=0) { - raw_occu = float(n_hits)/(m_numberOfEvents*n_chipPerSide*n_stripPerChip); - //--- For calculating average Raw Occupancy - meanRO_Barrel[iLayer]+=(double)raw_occu; - } - //--- DB writing - if( m_writeToCool ) { - if( m_pCalibWriteSvc->createListRawOccu(waferId, m_pSCTHelper, m_numberOfEvents, raw_occu).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListRawOccu" << endmsg; - return StatusCode::FAILURE; - } - } - } - } - //--- Summary XML output - ostringstream summaryList; - for( int i = 0; i < n_disks; ++i ) { - for( int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - meanRO_ECC[i][j] /= (n_phiBinsEndcap[i][j]*2); - summaryList<<xmlPartData(ENDCAP_C, i, j, "meanRO",meanRO_ECC[i][j]); - } - } - } - for( int i = 0; i < n_barrels; ++i ) { - meanRO_Barrel[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2); - summaryList<<xmlPartData(BARREL, i, 0, "meanRO",meanRO_Barrel[i]); - } - for( int i = 0; i < n_disks; ++i ) { - for( int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - meanRO_ECA[i][j] /= (n_phiBinsEndcap[i][j]*2); - summaryList<<xmlPartData(ENDCAP_A, i, j, "meanRO",meanRO_ECA[i][j]); + msg( MSG::INFO ) << "----- in getRawOccupancy() -----" << endmsg; + + //--- Initialization + int n_phiBinsBarrel[ n_barrels ] = { n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3 }; + int n_phiBinsEndcap[ n_disks ][ n_etaBinsEC ] = { { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, 0, 0 } + }; + + double meanRO_Barrel[ n_barrels ] = { 0 }; + double meanRO_ECA[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; + double meanRO_ECC[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; + + //--- RunNumber + std::ostringstream runnum; + runnum << (int) m_runNumber; + + //--- Directory in HIST + std::vector< std::pair<std::string, int> > EC_stems; + EC_stems.clear(); + std::pair<std::string, int> stem_C("/run_" + runnum.str() + "/SCT/SCTEC/hits/", ENDCAP_C); + std::pair<std::string, int> stem_A("/run_" + runnum.str() + "/SCT/SCTEA/hits/", ENDCAP_A); + EC_stems.push_back(stem_C); + EC_stems.push_back(stem_A); + std::vector< std::pair<std::string, int> >::iterator stemItr=EC_stems.begin(); + + //--- Endcaps + for(stemItr=EC_stems.begin(); stemItr!=EC_stems.end(); stemItr++) { + for(int iDisk=0; iDisk<n_disks; ++iDisk) + for(int iSide=0; iSide<2; ++iSide) + for(int iEta=0; iEta<n_etaBinsEC; ++iEta) + for(int iPhi=0; iPhi<n_phiBinsEndcap[iDisk][iEta]; ++iPhi) { + Identifier waferId = m_pSCTHelper->wafer_id( (*stemItr).second, iDisk, iPhi, iEta, iSide ); + std::string detector_part; + detector_part.erase(); + if(m_histBefore2010) { + if( (*stemItr).second==ENDCAP_C ) detector_part = "ECm_hitsmap"; + else detector_part = "ECp_hitsmap"; + } else { + if( (*stemItr).second==ENDCAP_C ) detector_part = "hitsmapECm"; + else detector_part = "hitsmapECp"; + } + ostringstream streamHist; + streamHist << detector_part << "_" << iDisk << "_" << iSide; + std::string hitsmapname = stemItr->first + streamHist.str(); + TH2D* hist_tmp = (TH2D*) m_inputHist->Get( hitsmapname.c_str() ); + unsigned long long n_hits = (unsigned long long)hist_tmp->GetBinContent( iEta+1, iPhi+1 ); + float raw_occu = 0; + if(m_numberOfEvents!=0) { + raw_occu = float(n_hits)/(m_numberOfEvents*n_chipPerSide*n_stripPerChip); + //--- For calculating average Raw Occupancy + if (stemItr->second==ENDCAP_C ) meanRO_ECC[iDisk][iEta]+=(double)raw_occu; + else if( stemItr->second==ENDCAP_A ) meanRO_ECA[iDisk][iEta]+=(double)raw_occu; + } + //--- DB writing + if( m_writeToCool ) { + if( m_pCalibWriteTool->createListRawOccu(waferId, m_pSCTHelper, m_numberOfEvents, raw_occu).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListRawOccu" << endmsg; + return StatusCode::FAILURE; + } + } + } + } + //--- Barrel + for(int iLayer=0; iLayer<n_barrels; ++iLayer) + for(int iSide=0; iSide<2; ++iSide) + for(int iEta=0; iEta<n_etaBins; ++iEta) { + if(iEta-6==0) continue; + for(int iPhi=0; iPhi<n_phiBinsBarrel[iLayer]; ++iPhi) { + Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, iPhi, iEta-6, iSide ); + ostringstream streamHist; + streamHist << iLayer << "_" << iSide; + std::string hitsmapname = "/run_" + runnum.str() + "/SCT/SCTB/hits/hitsmap_" + streamHist.str(); + TH2D* hist_tmp = (TH2D*) m_inputHist->Get( hitsmapname.c_str() ); + unsigned long long n_hits = (unsigned long long) hist_tmp->GetBinContent( iEta+1, iPhi+1 ); + float raw_occu = 0; + if(m_numberOfEvents!=0) { + raw_occu = float(n_hits)/(m_numberOfEvents*n_chipPerSide*n_stripPerChip); + //--- For calculating average Raw Occupancy + meanRO_Barrel[iLayer]+=(double)raw_occu; + } + //--- DB writing + if( m_writeToCool ) { + if( m_pCalibWriteTool->createListRawOccu(waferId, m_pSCTHelper, m_numberOfEvents, raw_occu).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListRawOccu" << endmsg; + return StatusCode::FAILURE; + } + } } - } - } - - if( openXML4MonSummary( m_outROSummary, "RawOccupancy" ).isFailure() ) { - msg( MSG::ERROR ) << "Problem in opening RawOccupancy file" << endmsg; - return StatusCode::FAILURE; - } - if( wrapUpXML4Summary( m_outROSummary, "RawOccupancy", summaryList ).isFailure() ) { - msg( MSG::ERROR )<< "Problem in closing RawOccupancy file " << endmsg; - return StatusCode::FAILURE; - } - - //--- DB output - if( m_writeToCool ) { - if ( m_pCalibWriteSvc->wrapUpRawOccupancy().isFailure() ) { - msg( MSG::ERROR ) << "Could not get RawOccupancy" << endmsg; - return StatusCode::FAILURE; - } - } + } + //--- Summary XML output + ostringstream summaryList; + for( int i = 0; i < n_disks; ++i ) { + for( int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + meanRO_ECC[i][j] /= (n_phiBinsEndcap[i][j]*2); + summaryList<<xmlPartData(ENDCAP_C, i, j, "meanRO",meanRO_ECC[i][j]); + } + } + } + for( int i = 0; i < n_barrels; ++i ) { + meanRO_Barrel[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2); + summaryList<<xmlPartData(BARREL, i, 0, "meanRO",meanRO_Barrel[i]); + } + for( int i = 0; i < n_disks; ++i ) { + for( int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + meanRO_ECA[i][j] /= (n_phiBinsEndcap[i][j]*2); + summaryList<<xmlPartData(ENDCAP_A, i, j, "meanRO",meanRO_ECA[i][j]); + } + } + } + + if( openXML4MonSummary( m_outROSummary, "RawOccupancy" ).isFailure() ) { + msg( MSG::ERROR ) << "Problem in opening RawOccupancy file" << endmsg; + return StatusCode::FAILURE; + } + if( wrapUpXML4Summary( m_outROSummary, "RawOccupancy", summaryList ).isFailure() ) { + msg( MSG::ERROR )<< "Problem in closing RawOccupancy file " << endmsg; + return StatusCode::FAILURE; + } - return StatusCode::SUCCESS; + //--- DB output + if( m_writeToCool ) { + if ( m_pCalibWriteTool->wrapUpRawOccupancy().isFailure() ) { + msg( MSG::ERROR ) << "Could not get RawOccupancy" << endmsg; + return StatusCode::FAILURE; + } + } + + return StatusCode::SUCCESS; } @@ -1635,188 +1634,188 @@ StatusCode SCTCalib::getRawOccupancy() /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::getEfficiency() { - msg(MSG::INFO) << "----- in getEfficiency() -----" << endmsg; - - //--- Initialization - int n_phiBinsBarrel[ n_barrels ] = { n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3 }; - int n_phiBinsEndcap[ n_disks ][ n_etaBinsEC ] = { { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, 0, 0 } - }; - - double meanEff_Barrel[ n_barrels ] = { 0 }; - double meanEff_ECA[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; - double meanEff_ECC[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; - - //--- RunNumber - std::ostringstream runnum; - runnum << (int) m_runNumber; - - //--- Directory in HIST - std::vector< std::pair<std::string, int> > EC_stems; - EC_stems.clear(); - std::pair<std::string, int> stem_C("/run_" + runnum.str() + "/SCT/SCTEC/eff/", ENDCAP_C); - std::pair<std::string, int> stem_A("/run_" + runnum.str() + "/SCT/SCTEA/eff/", ENDCAP_A); - EC_stems.push_back(stem_C); - EC_stems.push_back(stem_A); - std::vector< std::pair<std::string, int> >::iterator stemItr=EC_stems.begin(); - - //--- XML file - // if( openXML4MonSummary( m_outEffSummary, "EfficiencyModule" ).isFailure() ) { - // msg( MSG::ERROR ) << "Problem in opening " << m_outEffSummary << endmsg; - // return StatusCode::FAILURE; - // } - - const char* outputEfficiencyFileName = m_efficiencyModuleFile.c_str(); - ofstream outFile( outputEfficiencyFileName, std::ios::out ); - if ( !outFile.good() ) { - msg( MSG::ERROR ) << "Unable to open EfficiencyFile : " << outputEfficiencyFileName << endmsg; - return StatusCode::FAILURE; - } - - std::string xslName="EfficiencyInfo.xsl"; - outFile << xmlHeader<< linefeed<< associateStylesheet(xslName) << linefeed<< "<run>"<< endl; - outFile << xmlValue("RunNumber", (int)m_runNumber ) << linefeed - << xmlValue("StartTime", m_utcBegin ) << linefeed - << xmlValue("EndTime", m_utcEnd ) << linefeed - << xmlValue("Duration", m_calibEvtInfoSvc->duration() ) << linefeed - << xmlValue("LB", m_LBRange ) << linefeed - << xmlValue("Events", m_numberOfEvents ) << linefeed - << " <modules>"<< endl; - - - // //--- Header for XML outputs - // ostringstream osHeader; - // osHeader << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"CONDBR2\" folder=\"SCT/Derived/Efficiency\" " - // << "since=\"" << m_iovStart.re_time() << "\" " - // << "until=\"" << m_iovStop.re_time() << "\" " - // << "tag=\"" << m_tagID4Efficiency << "\" " - // << "version=\"" << "multi\">"<< endl; - // outFile << osHeader.str(); - - //--- Endcaps - for(stemItr=EC_stems.begin(); stemItr!=EC_stems.end(); stemItr++) { - for(int iDisk=0; iDisk<n_disks; ++iDisk) - for(int iSide=0; iSide<2; ++iSide) - for(int iEta=0; iEta<n_etaBinsEC; ++iEta) - for(int iPhi=0; iPhi<n_phiBinsEndcap[iDisk][iEta]; ++iPhi) { - Identifier waferId = m_pSCTHelper->wafer_id( (*stemItr).second, iDisk, iPhi, iEta, iSide ); - std::string detector_part; - detector_part.erase(); - ostringstream streamProf; - if( (*stemItr).second==ENDCAP_C ) { - detector_part = "m_eff"; - streamProf << detector_part << "_" << iDisk << "_" << iSide; - } else { - detector_part = "p_eff"; - streamProf << detector_part << "_" << iDisk << "_" << iSide; - } - std::string effmapname = stemItr->first + streamProf.str(); - TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( effmapname.c_str() ); - int global_bin = prof_tmp->GetBin( iEta+1, iPhi+1 ); - float eff = (float)prof_tmp->GetBinContent( global_bin ); - unsigned long long eff_entry = (unsigned long long)prof_tmp->GetBinEntries( global_bin ); - //--- For calculating average Efficiency - if( stemItr->second==ENDCAP_C ) meanEff_ECC[iDisk][iEta]+=(double)eff; - else if( stemItr->second==ENDCAP_A ) meanEff_ECA[iDisk][iEta]+=(double)eff; - //--- For Efficiency _not_ averaged over modules - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - outFile << xmlChannelEfficiencyDataString(waferId, eff, sn)<<endl; - //--- DB writing - if( m_writeToCool ) { - if( m_pCalibWriteSvc->createListEff(waferId, m_pSCTHelper, eff_entry, eff).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListEff" << endmsg; - return StatusCode::FAILURE; - } - } - } - } - //--- Barrel - for(int iLayer=0; iLayer<n_barrels; ++iLayer) - for(int iSide=0; iSide<2; ++iSide) - for(int iEta=0; iEta<n_etaBins; ++iEta) { - if(iEta-6==0) continue; - for(int iPhi=0; iPhi<n_phiBinsBarrel[iLayer]; ++iPhi) { - Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, iPhi, iEta-6, iSide ); - ostringstream streamProf; - streamProf << iLayer << "_" << iSide; - std::string effmapname = "/run_" + runnum.str() + "/SCT/SCTB/eff/eff_" + streamProf.str(); - TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( effmapname.c_str() ); - int global_bin = prof_tmp->GetBin( iEta+1, iPhi+1 ); - float eff = (float)prof_tmp->GetBinContent( global_bin ); - unsigned long long eff_entry = (unsigned long long)prof_tmp->GetBinEntries( global_bin ); - //--- For calculating average Efficiency - meanEff_Barrel[iLayer]+=(double)eff; - //--- For Efficiency _not_ averaged over modules - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - outFile << xmlChannelEfficiencyDataString(waferId, eff, sn)<<endl; - //--- DB writing - if( m_writeToCool ) { - if( m_pCalibWriteSvc->createListEff(waferId, m_pSCTHelper, eff_entry, eff).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListEff" << endmsg; - return StatusCode::FAILURE; - } - } - } + msg(MSG::INFO) << "----- in getEfficiency() -----" << endmsg; + + //--- Initialization + int n_phiBinsBarrel[ n_barrels ] = { n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3 }; + int n_phiBinsEndcap[ n_disks ][ n_etaBinsEC ] = { { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, 0, 0 } + }; + + double meanEff_Barrel[ n_barrels ] = { 0 }; + double meanEff_ECA[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; + double meanEff_ECC[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; + + //--- RunNumber + std::ostringstream runnum; + runnum << (int) m_runNumber; + + //--- Directory in HIST + std::vector< std::pair<std::string, int> > EC_stems; + EC_stems.clear(); + std::pair<std::string, int> stem_C("/run_" + runnum.str() + "/SCT/SCTEC/eff/", ENDCAP_C); + std::pair<std::string, int> stem_A("/run_" + runnum.str() + "/SCT/SCTEA/eff/", ENDCAP_A); + EC_stems.push_back(stem_C); + EC_stems.push_back(stem_A); + std::vector< std::pair<std::string, int> >::iterator stemItr=EC_stems.begin(); + + //--- XML file + // if( openXML4MonSummary( m_outEffSummary, "EfficiencyModule" ).isFailure() ) { + // msg( MSG::ERROR ) << "Problem in opening " << m_outEffSummary << endmsg; + // return StatusCode::FAILURE; + // } + + const char* outputEfficiencyFileName = m_efficiencyModuleFile.c_str(); + ofstream outFile( outputEfficiencyFileName, std::ios::out ); + if ( !outFile.good() ) { + msg( MSG::ERROR ) << "Unable to open EfficiencyFile : " << outputEfficiencyFileName << endmsg; + return StatusCode::FAILURE; + } + + std::string xslName="EfficiencyInfo.xsl"; + outFile << xmlHeader<< linefeed<< associateStylesheet(xslName) << linefeed<< "<run>"<< endl; + outFile << xmlValue("RunNumber", (int)m_runNumber ) << linefeed + << xmlValue("StartTime", m_utcBegin ) << linefeed + << xmlValue("EndTime", m_utcEnd ) << linefeed + << xmlValue("Duration", m_calibEvtInfoTool->duration() ) << linefeed + << xmlValue("LB", m_LBRange ) << linefeed + << xmlValue("Events", m_numberOfEvents ) << linefeed + << " <modules>"<< endl; + + + // //--- Header for XML outputs + // ostringstream osHeader; + // osHeader << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"CONDBR2\" folder=\"SCT/Derived/Efficiency\" " + // << "since=\"" << m_iovStart.re_time() << "\" " + // << "until=\"" << m_iovStop.re_time() << "\" " + // << "tag=\"" << m_tagID4Efficiency << "\" " + // << "version=\"" << "multi\">"<< endl; + // outFile << osHeader.str(); + + //--- Endcaps + for(stemItr=EC_stems.begin(); stemItr!=EC_stems.end(); stemItr++) { + for(int iDisk=0; iDisk<n_disks; ++iDisk) + for(int iSide=0; iSide<2; ++iSide) + for(int iEta=0; iEta<n_etaBinsEC; ++iEta) + for(int iPhi=0; iPhi<n_phiBinsEndcap[iDisk][iEta]; ++iPhi) { + Identifier waferId = m_pSCTHelper->wafer_id( (*stemItr).second, iDisk, iPhi, iEta, iSide ); + std::string detector_part; + detector_part.erase(); + ostringstream streamProf; + if( (*stemItr).second==ENDCAP_C ) { + detector_part = "m_eff"; + streamProf << detector_part << "_" << iDisk << "_" << iSide; + } else { + detector_part = "p_eff"; + streamProf << detector_part << "_" << iDisk << "_" << iSide; + } + std::string effmapname = stemItr->first + streamProf.str(); + TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( effmapname.c_str() ); + int global_bin = prof_tmp->GetBin( iEta+1, iPhi+1 ); + float eff = (float)prof_tmp->GetBinContent( global_bin ); + unsigned long long eff_entry = (unsigned long long)prof_tmp->GetBinEntries( global_bin ); + //--- For calculating average Efficiency + if( stemItr->second==ENDCAP_C ) meanEff_ECC[iDisk][iEta]+=(double)eff; + else if( stemItr->second==ENDCAP_A ) meanEff_ECA[iDisk][iEta]+=(double)eff; + //--- For Efficiency _not_ averaged over modules + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + outFile << xmlChannelEfficiencyDataString(waferId, eff, sn)<<endl; + //--- DB writing + if( m_writeToCool ) { + if( m_pCalibWriteTool->createListEff(waferId, m_pSCTHelper, eff_entry, eff).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListEff" << endmsg; + return StatusCode::FAILURE; + } + } + } + } + //--- Barrel + for(int iLayer=0; iLayer<n_barrels; ++iLayer) + for(int iSide=0; iSide<2; ++iSide) + for(int iEta=0; iEta<n_etaBins; ++iEta) { + if(iEta-6==0) continue; + for(int iPhi=0; iPhi<n_phiBinsBarrel[iLayer]; ++iPhi) { + Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, iPhi, iEta-6, iSide ); + ostringstream streamProf; + streamProf << iLayer << "_" << iSide; + std::string effmapname = "/run_" + runnum.str() + "/SCT/SCTB/eff/eff_" + streamProf.str(); + TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( effmapname.c_str() ); + int global_bin = prof_tmp->GetBin( iEta+1, iPhi+1 ); + float eff = (float)prof_tmp->GetBinContent( global_bin ); + unsigned long long eff_entry = (unsigned long long)prof_tmp->GetBinEntries( global_bin ); + //--- For calculating average Efficiency + meanEff_Barrel[iLayer]+=(double)eff; + //--- For Efficiency _not_ averaged over modules + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + outFile << xmlChannelEfficiencyDataString(waferId, eff, sn)<<endl; + //--- DB writing + if( m_writeToCool ) { + if( m_pCalibWriteTool->createListEff(waferId, m_pSCTHelper, eff_entry, eff).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListEff" << endmsg; + return StatusCode::FAILURE; + } + } } + } + + //--- Tail of XML outputs + // outFile << "</channels>" << endl; + + outFile << " </modules>" << endl; + outFile << "</run>" << endl; + + + //--- Summary XML output + ostringstream summaryList; + for( int i = 0; i < n_disks; ++i ) { + for( int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + meanEff_ECC[i][j] /= (n_phiBinsEndcap[i][j]*2); + summaryList<<xmlPartData(ENDCAP_C, i, j, "meanEff",meanEff_ECC[i][j]); + } + } + } + for( int i = 0; i < n_barrels; ++i ) { + meanEff_Barrel[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2); + summaryList<<xmlPartData(BARREL, i, 0, "meanEff",meanEff_Barrel[i]); + } + for( int i = 0; i < n_disks; ++i ) { + for( int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + meanEff_ECA[i][j] /= (n_phiBinsEndcap[i][j]*2); + summaryList<<xmlPartData(ENDCAP_A, i, j, "meanEff",meanEff_ECA[i][j]); + } + } + } + + if( openXML4MonSummary( m_outEffSummary, "Efficiency" ).isFailure() ) { + msg( MSG::ERROR ) << "Problem in opening Efficiency file" << endmsg; + return StatusCode::FAILURE; + } - //--- Tail of XML outputs - // outFile << "</channels>" << endl; - - outFile << " </modules>" << endl; - outFile << "</run>" << endl; - + if( wrapUpXML4Summary( m_outEffSummary, "Efficiency", summaryList ).isFailure() ) { + msg( MSG::ERROR ) << "Problem in closing Efficiency file " <<endmsg; + return StatusCode::FAILURE; + } - //--- Summary XML output - ostringstream summaryList; - for( int i = 0; i < n_disks; ++i ) { - for( int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - meanEff_ECC[i][j] /= (n_phiBinsEndcap[i][j]*2); - summaryList<<xmlPartData(ENDCAP_C, i, j, "meanEff",meanEff_ECC[i][j]); - } - } - } - for( int i = 0; i < n_barrels; ++i ) { - meanEff_Barrel[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2); - summaryList<<xmlPartData(BARREL, i, 0, "meanEff",meanEff_Barrel[i]); - } - for( int i = 0; i < n_disks; ++i ) { - for( int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - meanEff_ECA[i][j] /= (n_phiBinsEndcap[i][j]*2); - summaryList<<xmlPartData(ENDCAP_A, i, j, "meanEff",meanEff_ECA[i][j]); - } - } - } - - if( openXML4MonSummary( m_outEffSummary, "Efficiency" ).isFailure() ) { - msg( MSG::ERROR ) << "Problem in opening Efficiency file" << endmsg; - return StatusCode::FAILURE; - } - - if( wrapUpXML4Summary( m_outEffSummary, "Efficiency", summaryList ).isFailure() ) { - msg( MSG::ERROR ) << "Problem in closing Efficiency file " <<endmsg; - return StatusCode::FAILURE; - } - - //--- DB output - if( m_writeToCool ) { - if ( m_pCalibWriteSvc->wrapUpEfficiency().isFailure() ) { - msg( MSG::ERROR ) << "Could not get Efficiency" << endmsg; - return StatusCode::FAILURE; - } - } + //--- DB output + if( m_writeToCool ) { + if ( m_pCalibWriteTool->wrapUpEfficiency().isFailure() ) { + msg( MSG::ERROR ) << "Could not get Efficiency" << endmsg; + return StatusCode::FAILURE; + } + } - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } @@ -1826,352 +1825,352 @@ StatusCode SCTCalib::getEfficiency() { /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::getBSErrors() { - msg( MSG::INFO ) << "----- in getBSErrors() -----" << endmsg; - - //--- Initialization - int n_phiBinsBarrel[ n_barrels ] = { n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3 }; - int n_phiBinsEndcap[ n_disks ][ n_etaBinsEC ] = { { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, - { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, - { n_phiBinsECOuter, 0, 0 } - }; - - unsigned long long nErrLink_Barrel[ n_barrels ] = { 0 }; - unsigned long long nErrLink_ECA[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; - unsigned long long nErrLink_ECC[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; - - - unsigned long long nErrLink_Barrel_module[ n_barrels ][ 2 ][ n_etaBins ][ n_phiBinsB3 ] = {{{{0}}}}; - unsigned long long nErrLink_ECA_module[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter] = {{{{0}}}}; - unsigned long long nErrLink_ECC_module[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter] = {{{{0}}}}; - - std::string nErrLink_Barrel_module_serial[ n_barrels ][ 2 ][ n_etaBins ][ n_phiBinsB3 ]; - std::string nErrLink_ECA_module_serial[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter]; - std::string nErrLink_ECC_module_serial[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter]; - - unsigned long long nErrs_Barrel_module[ n_barrels ][ 2 ][ n_etaBins ][ n_phiBinsB3 ][ 15 ] = {{{{{0}}}}}; - unsigned long long nErrs_ECA_module[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter][ 15 ] = {{{{{0}}}}}; - unsigned long long nErrs_ECC_module[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter][ 15 ] = {{{{{0}}}}}; - - - - //--- RunNumber - std::ostringstream runnum; - runnum << (int) m_runNumber; - //--- ErrorList - typedef std::map< int, std::string > IntStringMap; - IntStringMap ErrMap_C, ErrMap; - const int numberOfErrorTypes(12); - boost::array<std::string, numberOfErrorTypes> errorNames= {{ - "BSParse","TimeOut", "BCID","LVL1ID", "Preamble", "Formatter", - "ABCD","Raw", "MaskedLink", "RODClock", - "TruncROD", (m_histBefore2010?"ROBFragment":"ROBFrag" ) - } - }; - // - boost::array<std::string, numberOfErrorTypes> errorNames_C= {{ - "BSParse","TimeOut","BCID","LVL1ID", "Preamble", "Formatter", - "ABCD","Raw", (m_histBefore2010?"TmaskedLinks":"MaskedLink"), "RODClock", - "TruncROD", (m_histBefore2010?"ROBFragment":"ROBFrag" ) - } - }; - boost::array<int, numberOfErrorTypes> errorValues= {{0,1,2,3,4,5,9,10,11,12,13,14}}; - //should do compile time check to ensure the sizes are equal. - ErrMap_C.clear(); - for (int indx(0); indx!=numberOfErrorTypes; ++indx) { - ErrMap_C.insert(make_pair(errorValues[indx],errorNames_C[indx])); - } - ErrMap.clear(); - for (int indx(0); indx!=numberOfErrorTypes; ++indx) { - ErrMap.insert(make_pair(errorValues[indx],errorNames[indx])); - } - - //--- Directory in HIST - const int N_ENDCAPS(2); - boost::array<std::string, N_ENDCAPS> detectorStems= {{"/run_" + runnum.str() + "/SCT/SCTEC/errors/", "/run_" + runnum.str() + "/SCT/SCTEA/errors/"}}; //barrel stem unused here - boost::array<IntStringMap::iterator, N_ENDCAPS> detectorIterators= {{ErrMap_C.begin(), ErrMap.begin()}}; - boost::array<std::string, N_ENDCAPS> detectorParts= {{"ECm", "ECp"}}; - std::string defecttype(""); - std::string n_defect(""); - int n_errorLink = 0; - //--- Endcaps - for(int stemIndex=0; stemIndex!=N_ENDCAPS; ++stemIndex) { - // fix agrohsje const int thisBec=(2 * stemIndex) - 2; //map 0, 1 onto -2, 2 - const int thisBec=(4 * stemIndex) - 2; //map 0, 1 onto -2, 2 - const std::string detector_part=detectorParts[stemIndex]; - for(int iDisk=0; iDisk<n_disks; ++iDisk) { - for(int iSide=0; iSide<2; ++iSide) { - for(int iEta=0; iEta<n_etaBinsEC; ++iEta) { - for(int iPhi=0; iPhi<n_phiBinsEndcap[iDisk][iEta]; ++iPhi) { - defecttype.erase(); - n_defect.erase(); - ostringstream osErrorList; - ostringstream osProbList; - Identifier waferId = m_pSCTHelper->wafer_id( thisBec, iDisk, iPhi, iEta, iSide ); - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - - if( thisBec==ENDCAP_C ) - nErrLink_ECC_module_serial[iDisk][iSide][iEta][iPhi]=sn.str(); - else if( thisBec==ENDCAP_A ) - nErrLink_ECA_module_serial[iDisk][iSide][iEta][iPhi]=sn.str(); - - IntStringMap::iterator errItr=detectorIterators[stemIndex]; - for ( int iType = 0; iType < n_BSErrorType; ++iType ) { - float errorProb = 0.; - unsigned long long n_errors = 0; - if ( iType == errItr->first ) { - ostringstream streamHist; - //temporal fix: folder and histogram names should be Preamble - streamHist << errItr->second << "Errs" << "_" << iDisk << "_" << iSide; - // streamHist << "T" << errItr->second << "Errs" << detector_part << "_" << iDisk << "_" << iSide; - std::string folder = errItr->second+std::string("/"); - //histogram might or might not be inside a folder with the same name - std::string profname = detectorStems[stemIndex] + folder +streamHist.str(); - std::string profnameShort = detectorStems[stemIndex] + streamHist.str(); - - TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( profname.c_str() ); - if(prof_tmp ==NULL) { - prof_tmp = (TProfile2D*) m_inputHist->Get( profnameShort.c_str() ); - } - if(prof_tmp ==NULL) { - msg( MSG::ERROR ) << "Unable to get profile for BSErrorsDB : " << profname << endmsg; - return StatusCode::FAILURE; - } - - n_errors = (unsigned long long)prof_tmp->GetBinContent( iEta+1, iPhi+1 ); - // unsigned long long n_errors = (unsigned long long)prof_tmp->GetBinContent( iEta+1, iPhi+1 ); - if(n_errors!=0) { - defecttype = m_pCalibWriteSvc->addNumber( defecttype, errItr->first ); - n_defect = m_pCalibWriteSvc->addNumber( n_defect, n_errors ); - errorProb = (float) n_errors / (float) m_numberOfEvents; - nErrs_ECC_module[iDisk][iSide][iEta][iPhi][errItr->first] = n_errors; - if( thisBec==ENDCAP_C ) { - nErrLink_ECC_module[iDisk][iSide][iEta][iPhi]+=n_errors; - } - else if( thisBec==ENDCAP_A ) { - nErrLink_ECA_module[iDisk][iSide][iEta][iPhi]+=n_errors; - } - - }//end if(n_errors!=0) - ++errItr; - }//end if( iType == (*errItr).first ) - osErrorList << n_errors; - osProbList << errorProb; - if ( iType != n_BSErrorType-1 ) { - osErrorList << " "; - osProbList << " "; - } - }//end ErrorType Loop - //--- DB writing - if(!(defecttype.empty())) { - n_errorLink++; - if( thisBec==ENDCAP_C ) { - nErrLink_ECC[iDisk][iEta]++; - } - else if( thisBec==ENDCAP_A ) { - nErrLink_ECA[iDisk][iEta]++; - } - if( m_writeToCool ) { - if( m_pCalibWriteSvc->createListBSErr(waferId, m_pSCTHelper, m_numberOfEvents, osErrorList.str(),osProbList.str()).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListBSError" << endmsg; - return StatusCode::FAILURE; - } - } - } - }// end of for iPhi - }//implicit end of iEta - }//implicit end of iside - }//implicit end of iDisk - }//end of stemIndex loop - //--- Barrel - for(int iLayer=0; iLayer<n_barrels; ++iLayer) - for(int iSide=0; iSide<2; ++iSide) - for(int iEta=0; iEta<n_etaBins; ++iEta) { - if(iEta-6==0) continue; - for(int iPhi=0; iPhi<n_phiBinsBarrel[iLayer]; ++iPhi) { - defecttype.erase(); - n_defect.erase(); - ostringstream osErrorList;//agrohsje - ostringstream osProbList; - Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, iPhi, iEta-6, iSide ); - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - nErrLink_Barrel_module_serial[iLayer][iSide][iEta][iPhi] = sn.str(); - IntStringMap::iterator errItr=ErrMap.begin(); - for ( int iType = 0; iType < n_BSErrorType; ++iType ) { - float errorProb = 0.; - unsigned long long n_errors = 0; - if ( iType == errItr->first ) { - ostringstream streamHist; - streamHist << "T" << errItr->second << "Errs" << "_" << iLayer << "_" << iSide; - //histogram might or might not be inside a folder with the same name - std::string folder = errItr->second+std::string("/"); - std::string profname = "/run_" + runnum.str() + "/SCT/SCTB/errors/" + folder + streamHist.str(); - std::string profnameShort = "/run_" + runnum.str() + "/SCT/SCTB/errors/" + streamHist.str(); - - TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( profname.c_str() ); - if(prof_tmp ==NULL) { - prof_tmp = (TProfile2D*) m_inputHist->Get( profnameShort.c_str() ); - } - if(prof_tmp ==NULL) { - msg( MSG::ERROR ) << "Unable to get profile for BSErrorsDB : " << profname << endmsg; - return StatusCode::FAILURE; - } - n_errors = (unsigned long long)prof_tmp->GetBinContent( iEta+1, iPhi+1 ); - // unsigned long long n_errors = (unsigned long long)prof_tmp->GetBinContent( iEta+1, iPhi+1 ); - if(n_errors!=0) { - defecttype = m_pCalibWriteSvc->addNumber( defecttype, errItr->first ); - n_defect = m_pCalibWriteSvc->addNumber( n_defect, n_errors ); - errorProb = (float) n_errors / (float) m_numberOfEvents; - nErrs_Barrel_module[iLayer][iSide][iEta][iPhi][errItr->first] = n_errors; - nErrLink_Barrel_module[iLayer][iSide][iEta][iPhi]+=n_errors; - - }//end if(n_errors!=0) - ++errItr; - }//end if( iType == (*errItr).first ) - osErrorList << n_errors; - osProbList << errorProb; - if ( iType != n_BSErrorType-1 ) { - osErrorList << " "; - osProbList << " "; + msg( MSG::INFO ) << "----- in getBSErrors() -----" << endmsg; + + //--- Initialization + int n_phiBinsBarrel[ n_barrels ] = { n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3 }; + int n_phiBinsEndcap[ n_disks ][ n_etaBinsEC ] = { { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort }, + { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, n_phiBinsECMiddle, 0 }, + { n_phiBinsECOuter, 0, 0 } + }; + + unsigned long long nErrLink_Barrel[ n_barrels ] = { 0 }; + unsigned long long nErrLink_ECA[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; + unsigned long long nErrLink_ECC[ n_disks ][ n_etaBinsEC ] = { {0}, {0} }; + + + unsigned long long nErrLink_Barrel_module[ n_barrels ][ 2 ][ n_etaBins ][ n_phiBinsB3 ] = {{{{0}}}}; + unsigned long long nErrLink_ECA_module[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter] = {{{{0}}}}; + unsigned long long nErrLink_ECC_module[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter] = {{{{0}}}}; + + std::string nErrLink_Barrel_module_serial[ n_barrels ][ 2 ][ n_etaBins ][ n_phiBinsB3 ]; + std::string nErrLink_ECA_module_serial[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter]; + std::string nErrLink_ECC_module_serial[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter]; + + unsigned long long nErrs_Barrel_module[ n_barrels ][ 2 ][ n_etaBins ][ n_phiBinsB3 ][ 15 ] = {{{{{0}}}}}; + unsigned long long nErrs_ECA_module[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter][ 15 ] = {{{{{0}}}}}; + unsigned long long nErrs_ECC_module[ n_disks ][2][ n_etaBinsEC ][n_phiBinsECOuter][ 15 ] = {{{{{0}}}}}; + + + + //--- RunNumber + std::ostringstream runnum; + runnum << (int) m_runNumber; + //--- ErrorList + typedef std::map< int, std::string > IntStringMap; + IntStringMap ErrMap_C, ErrMap; + const int numberOfErrorTypes(12); + boost::array<std::string, numberOfErrorTypes> errorNames= {{ + "BSParse","TimeOut", "BCID","LVL1ID", "Preamble", "Formatter", + "ABCD","Raw", "MaskedLink", "RODClock", + "TruncROD", (m_histBefore2010?"ROBFragment":"ROBFrag" ) + } + }; + // + boost::array<std::string, numberOfErrorTypes> errorNames_C= {{ + "BSParse","TimeOut","BCID","LVL1ID", "Preamble", "Formatter", + "ABCD","Raw", (m_histBefore2010?"TmaskedLinks":"MaskedLink"), "RODClock", + "TruncROD", (m_histBefore2010?"ROBFragment":"ROBFrag" ) + } + }; + boost::array<int, numberOfErrorTypes> errorValues= {{0,1,2,3,4,5,9,10,11,12,13,14}}; + //should do compile time check to ensure the sizes are equal. + ErrMap_C.clear(); + for (int indx(0); indx!=numberOfErrorTypes; ++indx) { + ErrMap_C.insert(make_pair(errorValues[indx],errorNames_C[indx])); + } + ErrMap.clear(); + for (int indx(0); indx!=numberOfErrorTypes; ++indx) { + ErrMap.insert(make_pair(errorValues[indx],errorNames[indx])); + } + + //--- Directory in HIST + const int N_ENDCAPS(2); + boost::array<std::string, N_ENDCAPS> detectorStems= {{"/run_" + runnum.str() + "/SCT/SCTEC/errors/", "/run_" + runnum.str() + "/SCT/SCTEA/errors/"}}; //barrel stem unused here + boost::array<IntStringMap::iterator, N_ENDCAPS> detectorIterators= {{ErrMap_C.begin(), ErrMap.begin()}}; + boost::array<std::string, N_ENDCAPS> detectorParts= {{"ECm", "ECp"}}; + std::string defecttype(""); + std::string n_defect(""); + int n_errorLink = 0; + //--- Endcaps + for(int stemIndex=0; stemIndex!=N_ENDCAPS; ++stemIndex) { + // fix agrohsje const int thisBec=(2 * stemIndex) - 2; //map 0, 1 onto -2, 2 + const int thisBec=(4 * stemIndex) - 2; //map 0, 1 onto -2, 2 + const std::string detector_part=detectorParts[stemIndex]; + for(int iDisk=0; iDisk<n_disks; ++iDisk) { + for(int iSide=0; iSide<2; ++iSide) { + for(int iEta=0; iEta<n_etaBinsEC; ++iEta) { + for(int iPhi=0; iPhi<n_phiBinsEndcap[iDisk][iEta]; ++iPhi) { + defecttype.erase(); + n_defect.erase(); + ostringstream osErrorList; + ostringstream osProbList; + Identifier waferId = m_pSCTHelper->wafer_id( thisBec, iDisk, iPhi, iEta, iSide ); + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + + if( thisBec==ENDCAP_C ) + nErrLink_ECC_module_serial[iDisk][iSide][iEta][iPhi]=sn.str(); + else if( thisBec==ENDCAP_A ) + nErrLink_ECA_module_serial[iDisk][iSide][iEta][iPhi]=sn.str(); + + IntStringMap::iterator errItr=detectorIterators[stemIndex]; + for ( int iType = 0; iType < n_BSErrorType; ++iType ) { + float errorProb = 0.; + unsigned long long n_errors = 0; + if ( iType == errItr->first ) { + ostringstream streamHist; + //temporal fix: folder and histogram names should be Preamble + streamHist << errItr->second << "Errs" << "_" << iDisk << "_" << iSide; + // streamHist << "T" << errItr->second << "Errs" << detector_part << "_" << iDisk << "_" << iSide; + std::string folder = errItr->second+std::string("/"); + //histogram might or might not be inside a folder with the same name + std::string profname = detectorStems[stemIndex] + folder +streamHist.str(); + std::string profnameShort = detectorStems[stemIndex] + streamHist.str(); + + TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( profname.c_str() ); + if(prof_tmp ==NULL) { + prof_tmp = (TProfile2D*) m_inputHist->Get( profnameShort.c_str() ); } - } //end ErrorType Loop - //--- DB writing - if(!(defecttype.empty())) { - n_errorLink++; - nErrLink_Barrel[iLayer]++; - if( m_writeToCool ) { - if( m_pCalibWriteSvc->createListBSErr(waferId, m_pSCTHelper, m_numberOfEvents, osErrorList.str(), osProbList.str()).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListBSError" << endmsg; - return StatusCode::FAILURE; - }//end of if m_pCalib - }//end of if m_writeToCool - } //end of if defecttype empty - }//end of for iPhi - }//endof for iEta, implicit end of for iSide and iLayer - - msg( MSG::INFO ) << "#Links which send BSError : " << n_errorLink << endmsg; - - //--- Summary XML output - ostringstream summaryList; - for( int i = 0; i < n_disks; ++i ) { - for( int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - summaryList<<xmlPartData(ENDCAP_C, i, j, "nErrLink", nErrLink_ECC[i][j]); - } - } - } - for( int i = 0; i < n_barrels; ++i ) { - summaryList<<xmlPartData(BARREL, i, 0, "nErrLink", nErrLink_Barrel[i]); - } - - for( int i = 0; i < n_disks; ++i ) { - for( int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - summaryList<<xmlPartData(ENDCAP_A, i, j, "nErrLink", nErrLink_ECA[i][j]); - } - } - } - - if( openXML4MonSummary( m_outBSErrSummary, "BSErrors" ).isFailure() ) { - msg( MSG::ERROR ) << "Problem in opening BSErrors file" << endmsg; - return StatusCode::FAILURE; - } - if( wrapUpXML4Summary( m_outBSErrSummary, "BSErrors", summaryList ).isFailure() ) { - msg( MSG::ERROR ) << "Problem in closing BSErrors file" <<endmsg; - return StatusCode::FAILURE; - } - - //module XML output - //agascon 06.02.2015 - ostringstream moduleList; - std::string serial; - for( int i = 0; i < n_disks; ++i ) { - for( int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - for ( int k = 0; k < 2; k++) { - for ( int l = 0; l < n_phiBinsEndcap[i][j]; l++) { - serial = nErrLink_ECC_module_serial[i][k][j][l]; - - //fill ostringstream with number of error of each type for one particular module - ostringstream errList; - for ( int errCount = 0; errCount < numberOfErrorTypes; errCount++) { - int type = errorValues[errCount]; // - errList<<" "<<xmlValue(ErrMap[type] , nErrs_ECC_module[i][k][j][l][type])<<endl; + if(prof_tmp ==NULL) { + msg( MSG::ERROR ) << "Unable to get profile for BSErrorsDB : " << profname << endmsg; + return StatusCode::FAILURE; } - moduleList<<xmlModuleData(ENDCAP_C, i, k, j, l, "nErrors", nErrLink_ECC_module[i][k][j][l], serial, errList.str()); - // moduleList<<xmlModuleData(ENDCAP_C, i, k, j, l, "nErrLink", nErrLink_ECC_module[i][k][j][l], serial, errList); - - } - } + n_errors = (unsigned long long)prof_tmp->GetBinContent( iEta+1, iPhi+1 ); + // unsigned long long n_errors = (unsigned long long)prof_tmp->GetBinContent( iEta+1, iPhi+1 ); + if(n_errors!=0) { + defecttype = m_pCalibWriteTool->addNumber( defecttype, errItr->first ); + n_defect = m_pCalibWriteTool->addNumber( n_defect, n_errors ); + errorProb = (float) n_errors / (float) m_numberOfEvents; + nErrs_ECC_module[iDisk][iSide][iEta][iPhi][errItr->first] = n_errors; + if( thisBec==ENDCAP_C ) { + nErrLink_ECC_module[iDisk][iSide][iEta][iPhi]+=n_errors; + } + else if( thisBec==ENDCAP_A ) { + nErrLink_ECA_module[iDisk][iSide][iEta][iPhi]+=n_errors; + } + + }//end if(n_errors!=0) + ++errItr; + }//end if( iType == (*errItr).first ) + osErrorList << n_errors; + osProbList << errorProb; + if ( iType != n_BSErrorType-1 ) { + osErrorList << " "; + osProbList << " "; + } + }//end ErrorType Loop + //--- DB writing + if(!(defecttype.empty())) { + n_errorLink++; + if( thisBec==ENDCAP_C ) { + nErrLink_ECC[iDisk][iEta]++; + } + else if( thisBec==ENDCAP_A ) { + nErrLink_ECA[iDisk][iEta]++; + } + if( m_writeToCool ) { + if( m_pCalibWriteTool->createListBSErr(waferId, m_pSCTHelper, m_numberOfEvents, osErrorList.str(),osProbList.str()).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListBSError" << endmsg; + return StatusCode::FAILURE; + } + } + } + }// end of for iPhi + }//implicit end of iEta + }//implicit end of iside + }//implicit end of iDisk + }//end of stemIndex loop + //--- Barrel + for(int iLayer=0; iLayer<n_barrels; ++iLayer) + for(int iSide=0; iSide<2; ++iSide) + for(int iEta=0; iEta<n_etaBins; ++iEta) { + if(iEta-6==0) continue; + for(int iPhi=0; iPhi<n_phiBinsBarrel[iLayer]; ++iPhi) { + defecttype.erase(); + n_defect.erase(); + ostringstream osErrorList;//agrohsje + ostringstream osProbList; + Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, iPhi, iEta-6, iSide ); + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + nErrLink_Barrel_module_serial[iLayer][iSide][iEta][iPhi] = sn.str(); + IntStringMap::iterator errItr=ErrMap.begin(); + for ( int iType = 0; iType < n_BSErrorType; ++iType ) { + float errorProb = 0.; + unsigned long long n_errors = 0; + if ( iType == errItr->first ) { + ostringstream streamHist; + streamHist << "T" << errItr->second << "Errs" << "_" << iLayer << "_" << iSide; + //histogram might or might not be inside a folder with the same name + std::string folder = errItr->second+std::string("/"); + std::string profname = "/run_" + runnum.str() + "/SCT/SCTB/errors/" + folder + streamHist.str(); + std::string profnameShort = "/run_" + runnum.str() + "/SCT/SCTB/errors/" + streamHist.str(); + + TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( profname.c_str() ); + if(prof_tmp ==NULL) { + prof_tmp = (TProfile2D*) m_inputHist->Get( profnameShort.c_str() ); + } + if(prof_tmp ==NULL) { + msg( MSG::ERROR ) << "Unable to get profile for BSErrorsDB : " << profname << endmsg; + return StatusCode::FAILURE; + } + n_errors = (unsigned long long)prof_tmp->GetBinContent( iEta+1, iPhi+1 ); + // unsigned long long n_errors = (unsigned long long)prof_tmp->GetBinContent( iEta+1, iPhi+1 ); + if(n_errors!=0) { + defecttype = m_pCalibWriteTool->addNumber( defecttype, errItr->first ); + n_defect = m_pCalibWriteTool->addNumber( n_defect, n_errors ); + errorProb = (float) n_errors / (float) m_numberOfEvents; + nErrs_Barrel_module[iLayer][iSide][iEta][iPhi][errItr->first] = n_errors; + nErrLink_Barrel_module[iLayer][iSide][iEta][iPhi]+=n_errors; + + }//end if(n_errors!=0) + ++errItr; + }//end if( iType == (*errItr).first ) + osErrorList << n_errors; + osProbList << errorProb; + if ( iType != n_BSErrorType-1 ) { + osErrorList << " "; + osProbList << " "; + } + } //end ErrorType Loop + //--- DB writing + if(!(defecttype.empty())) { + n_errorLink++; + nErrLink_Barrel[iLayer]++; + if( m_writeToCool ) { + if( m_pCalibWriteTool->createListBSErr(waferId, m_pSCTHelper, m_numberOfEvents, osErrorList.str(), osProbList.str()).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListBSError" << endmsg; + return StatusCode::FAILURE; + }//end of if m_pCalib + }//end of if m_writeToCool + } //end of if defecttype empty + }//end of for iPhi + }//endof for iEta, implicit end of for iSide and iLayer + + msg( MSG::INFO ) << "#Links which send BSError : " << n_errorLink << endmsg; + + //--- Summary XML output + ostringstream summaryList; + for( int i = 0; i < n_disks; ++i ) { + for( int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + summaryList<<xmlPartData(ENDCAP_C, i, j, "nErrLink", nErrLink_ECC[i][j]); + } + } + } + for( int i = 0; i < n_barrels; ++i ) { + summaryList<<xmlPartData(BARREL, i, 0, "nErrLink", nErrLink_Barrel[i]); + } + + for( int i = 0; i < n_disks; ++i ) { + for( int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + summaryList<<xmlPartData(ENDCAP_A, i, j, "nErrLink", nErrLink_ECA[i][j]); + } + } + } + + if( openXML4MonSummary( m_outBSErrSummary, "BSErrors" ).isFailure() ) { + msg( MSG::ERROR ) << "Problem in opening BSErrors file" << endmsg; + return StatusCode::FAILURE; + } + if( wrapUpXML4Summary( m_outBSErrSummary, "BSErrors", summaryList ).isFailure() ) { + msg( MSG::ERROR ) << "Problem in closing BSErrors file" <<endmsg; + return StatusCode::FAILURE; + } + + //module XML output + //agascon 06.02.2015 + ostringstream moduleList; + std::string serial; + for( int i = 0; i < n_disks; ++i ) { + for( int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + for ( int k = 0; k < 2; k++) { + for ( int l = 0; l < n_phiBinsEndcap[i][j]; l++) { + serial = nErrLink_ECC_module_serial[i][k][j][l]; + + //fill ostringstream with number of error of each type for one particular module + ostringstream errList; + for ( int errCount = 0; errCount < numberOfErrorTypes; errCount++) { + int type = errorValues[errCount]; // + errList<<" "<<xmlValue(ErrMap[type], nErrs_ECC_module[i][k][j][l][type])<<endl; + } + + moduleList<<xmlModuleData(ENDCAP_C, i, k, j, l, "nErrors", nErrLink_ECC_module[i][k][j][l], serial, errList.str()); + // moduleList<<xmlModuleData(ENDCAP_C, i, k, j, l, "nErrLink", nErrLink_ECC_module[i][k][j][l], serial, errList); + + } } - } - } + } + } + } - for( int i = 0; i < n_barrels; i++ ) { - for ( int j = 0; j < 2; j++) { - for ( int k = 0; k < n_etaBins; k++) { - for ( int l = 0; l < n_phiBinsBarrel[i] ; l++) { - serial = nErrLink_Barrel_module_serial[i][j][k][l]; + for( int i = 0; i < n_barrels; i++ ) { + for ( int j = 0; j < 2; j++) { + for ( int k = 0; k < n_etaBins; k++) { + for ( int l = 0; l < n_phiBinsBarrel[i] ; l++) { + serial = nErrLink_Barrel_module_serial[i][j][k][l]; - ostringstream errList; - for ( int errCount = 0; errCount < numberOfErrorTypes; errCount++) { - int type = errorValues[errCount]; // - errList<<" "<<xmlValue(ErrMap[type] , nErrs_Barrel_module[i][j][k][l][type])<<endl; - } + ostringstream errList; + for ( int errCount = 0; errCount < numberOfErrorTypes; errCount++) { + int type = errorValues[errCount]; // + errList<<" "<<xmlValue(ErrMap[type], nErrs_Barrel_module[i][j][k][l][type])<<endl; + } - moduleList<<xmlModuleData(BARREL, i, j, k, l, "nErrors", nErrLink_Barrel_module[i][j][k][l], serial, errList.str()); - } + moduleList<<xmlModuleData(BARREL, i, j, k, l, "nErrors", nErrLink_Barrel_module[i][j][k][l], serial, errList.str()); } - } - } - - for( int i = 0; i < n_disks; ++i ) { - for( int j = 0; j < n_etaBinsEC; ++j ) { - if( n_phiBinsEndcap[i][j] != 0 ) { - for ( int k = 0; k < 2; k++) { - for ( int l = 0; l < n_phiBinsEndcap[i][j]; l++) { - serial = nErrLink_ECA_module_serial[i][k][j][l]; - - ostringstream errList; - for ( int errCount = 0; errCount < numberOfErrorTypes; errCount++) { - int type = errorValues[errCount]; // - errList<<" "<<xmlValue(ErrMap[type] , nErrs_ECA_module[i][k][j][l][type])<<endl; - } - - moduleList<<xmlModuleData(ENDCAP_A, i, k, j, l, "nErrors", nErrLink_ECA_module[i][k][j][l], serial, errList.str()); - } - } + } + } + } + + for( int i = 0; i < n_disks; ++i ) { + for( int j = 0; j < n_etaBinsEC; ++j ) { + if( n_phiBinsEndcap[i][j] != 0 ) { + for ( int k = 0; k < 2; k++) { + for ( int l = 0; l < n_phiBinsEndcap[i][j]; l++) { + serial = nErrLink_ECA_module_serial[i][k][j][l]; + + ostringstream errList; + for ( int errCount = 0; errCount < numberOfErrorTypes; errCount++) { + int type = errorValues[errCount]; // + errList<<" "<<xmlValue(ErrMap[type], nErrs_ECA_module[i][k][j][l][type])<<endl; + } + + moduleList<<xmlModuleData(ENDCAP_A, i, k, j, l, "nErrors", nErrLink_ECA_module[i][k][j][l], serial, errList.str()); + } } - } - } - - if( openXML4MonSummary( m_outBSErrModule, "BSErrorsModule" ).isFailure() ) { - msg( MSG::ERROR ) << "Problem in opening BSErrorsModule file" << endmsg; - return StatusCode::FAILURE; - } - if( wrapUpXML4Summary( m_outBSErrModule, "BSErrors", moduleList ).isFailure() ) { - msg( MSG::ERROR ) << "Problem in closing BSErrors file" <<endmsg; - return StatusCode::FAILURE; - } - - //--- DB output - if( m_writeToCool ) { - if ( m_pCalibWriteSvc->wrapUpBSErrors().isFailure() ) { - msg( MSG::ERROR ) << "Could not get ByteStream Errors" << endmsg; - return StatusCode::FAILURE; - } - } + } + } + } - return StatusCode::SUCCESS; + if( openXML4MonSummary( m_outBSErrModule, "BSErrorsModule" ).isFailure() ) { + msg( MSG::ERROR ) << "Problem in opening BSErrorsModule file" << endmsg; + return StatusCode::FAILURE; + } + if( wrapUpXML4Summary( m_outBSErrModule, "BSErrors", moduleList ).isFailure() ) { + msg( MSG::ERROR ) << "Problem in closing BSErrors file" <<endmsg; + return StatusCode::FAILURE; + } + + //--- DB output + if( m_writeToCool ) { + if ( m_pCalibWriteTool->wrapUpBSErrors().isFailure() ) { + msg( MSG::ERROR ) << "Could not get ByteStream Errors" << endmsg; + return StatusCode::FAILURE; + } + } + + return StatusCode::SUCCESS; } @@ -2181,324 +2180,324 @@ StatusCode SCTCalib::getBSErrors() { /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::getLorentzAngle() { - msg( MSG::INFO ) << "----- in getLorentzAngle() -----" << endmsg; - - //--- Initialization - - float A_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - float LA_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - float B_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - float Sigma_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - - float Err_A_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - float Err_LA_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - float Err_B_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - float Err_Sigma_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - - float MCW_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - float Err_MCW_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - float Chisq_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; - - string DBUploadFlag = "G"; // fit status flag - string module[2]= {"100","111"}; - int moduleint[2]= {100,111}; - - int FitFlag[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; // fit status flag - - TFile *fitFile; - - //--- RunNumber - std::ostringstream runnum; - runnum << (int) m_runNumber; - - //--- Directory in HIST - std::string stem; - - //--- Barrel - stem = "/run_" + runnum.str() + "/SCT/GENERAL/lorentz/"; - m_h_phiVsNstripsSideHistoVector.clear(); - for ( int iLayer = 0; iLayer < n_barrels ; ++iLayer ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - for ( int iModule = 0; iModule < 2; ++iModule ) { - ostringstream streamHist; - streamHist << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide; - std::string histName = stem + streamHist.str(); - cout<<histName<<endl; - TProfile* hist_tmp = (TProfile *) m_inputHist->Get( histName.c_str() ); - if(hist_tmp ==NULL) { - msg( MSG::ERROR ) << "Unable to get histogram for LorentzAngle : " << histName << endmsg; - return StatusCode::FAILURE; - } - m_h_phiVsNstripsSideHistoVector.push_back( hist_tmp ); + msg( MSG::INFO ) << "----- in getLorentzAngle() -----" << endmsg; + + //--- Initialization + + float A_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + float LA_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + float B_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + float Sigma_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + + float Err_A_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + float Err_LA_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + float Err_B_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + float Err_Sigma_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + + float MCW_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + float Err_MCW_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + float Chisq_BarrelSide[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; + + string DBUploadFlag = "G"; // fit status flag + string module[2]= {"100","111"}; + int moduleint[2]= {100,111}; + + int FitFlag[ n_barrels ][ 2 ][ 2 ] = { {{0},{0}}, {{0},{0}} }; // fit status flag + + TFile *fitFile; + + //--- RunNumber + std::ostringstream runnum; + runnum << (int) m_runNumber; + + //--- Directory in HIST + std::string stem; + + //--- Barrel + stem = "/run_" + runnum.str() + "/SCT/GENERAL/lorentz/"; + m_h_phiVsNstripsSideHistoVector.clear(); + for ( int iLayer = 0; iLayer < n_barrels ; ++iLayer ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + for ( int iModule = 0; iModule < 2; ++iModule ) { + ostringstream streamHist; + streamHist << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide; + std::string histName = stem + streamHist.str(); + cout<<histName<<endl; + TProfile* hist_tmp = (TProfile *) m_inputHist->Get( histName.c_str() ); + if(hist_tmp ==NULL) { + msg( MSG::ERROR ) << "Unable to get histogram for LorentzAngle : " << histName << endmsg; + return StatusCode::FAILURE; + } + m_h_phiVsNstripsSideHistoVector.push_back( hist_tmp ); + } + } + } + + //--- XML file + const char* outputLorentzAngleFileName = m_LorentzAngleFile.c_str(); + ofstream outFile( outputLorentzAngleFileName, std::ios::out ); + if ( !outFile.good() ) { + msg( MSG::ERROR ) << "Unable to open LorentzAngleFile : " << outputLorentzAngleFileName << endmsg; + return StatusCode::FAILURE; + } + + //--- Header for XML outputs + ostringstream osHeader; + osHeader << "<folder>"<< endl; + outFile << osHeader.str(); + + fitFile = new TFile("FittingDebugFile.root","RECREATE"); + + //--- Barrel + for ( int iLayer = 0; iLayer < n_barrels; ++iLayer ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + for ( int iModule = 0; iModule < 2; ++iModule ) { + if (iLayer==1 && iModule==0) continue; // Layer 1 doesn't contain 100 modules + msg( MSG::INFO ) << "LorentzAngle fit start : " << 4*iLayer + iSide +1 + iModule << " / 16" << endmsg; + Int_t fitResult; + Double_t par[4],err_par[4]; + TF1 *LAfit = new TF1("LAfit", LA_func, -9., 2.,4 ); + ostringstream streamFile; + streamFile << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide; + + LAfit->SetParLimits(3, 0.1, 50.); + LAfit->SetParNames("a","LA","b","sigma"); + LAfit->SetParameters(1.,-5.,1.13,2.); + fitResult = m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule ] -> Fit("LAfit", "E", "",-9.,2.); + LAfit->GetParameters(par); + err_par[0]=LAfit->GetParError(0); + err_par[1]=LAfit->GetParError(1); + err_par[2]=LAfit->GetParError(2); + err_par[3]=LAfit->GetParError(3); + + //DEBUG MODE + if ( m_LorentzAngleDebugMode ) { + ostringstream streamFileTmp; + streamFileTmp << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide << "_First_Fit"; + std::string dn = streamFile.str(); + std::string tmp_hn = streamFileTmp.str(); + const char* dir_name = dn.c_str(); + const char* histo_name = tmp_hn.c_str(); + fitFile->cd(); + fitFile->mkdir(dir_name); //Creating Directories + fitFile->cd(dir_name); + m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> SetName(histo_name); + m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Write(); + msg( MSG::INFO ) << "-------:Directory Name: " << dir_name << "--------" << endmsg; } - } - } - - //--- XML file - const char* outputLorentzAngleFileName = m_LorentzAngleFile.c_str(); - ofstream outFile( outputLorentzAngleFileName, std::ios::out ); - if ( !outFile.good() ) { - msg( MSG::ERROR ) << "Unable to open LorentzAngleFile : " << outputLorentzAngleFileName << endmsg; - return StatusCode::FAILURE; - } - - //--- Header for XML outputs - ostringstream osHeader; - osHeader << "<folder>"<< endl; - outFile << osHeader.str(); - - fitFile = new TFile("FittingDebugFile.root","RECREATE"); - - //--- Barrel - for ( int iLayer = 0; iLayer < n_barrels; ++iLayer ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - for ( int iModule = 0; iModule < 2; ++iModule ) { - if (iLayer==1 && iModule==0) continue; // Layer 1 doesn't contain 100 modules - msg( MSG::INFO ) << "LorentzAngle fit start : " << 4*iLayer + iSide +1 + iModule << " / 16" << endmsg; - Int_t fitResult; - Double_t par[4],err_par[4]; - TF1 *LAfit = new TF1("LAfit", LA_func, -9., 2.,4 ); - ostringstream streamFile; - streamFile << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide; - - LAfit->SetParLimits(3, 0.1, 50.); - LAfit->SetParNames("a","LA","b","sigma"); - LAfit->SetParameters(1.,-5.,1.13,2.); - fitResult = m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule ] -> Fit("LAfit", "E" , "" ,-9.,2.); - LAfit->GetParameters(par); - err_par[0]=LAfit->GetParError(0); - err_par[1]=LAfit->GetParError(1); - err_par[2]=LAfit->GetParError(2); - err_par[3]=LAfit->GetParError(3); - - //DEBUG MODE - if ( m_LorentzAngleDebugMode ) { - ostringstream streamFileTmp; - streamFileTmp << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide << "_First_Fit"; - std::string dn = streamFile.str(); - std::string tmp_hn = streamFileTmp.str(); - const char* dir_name = dn.c_str(); - const char* histo_name = tmp_hn.c_str(); - fitFile->cd(); - fitFile->mkdir(dir_name); //Creating Directories - fitFile->cd(dir_name); - m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> SetName(histo_name); - m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Write(); - msg( MSG::INFO ) << "-------:Directory Name: " << dir_name << "--------" << endmsg; - } - - - - if( fitResult != 0 ) { - msg( MSG::INFO ) << "Try to use parabola Fit to determine initial value!" << endmsg; - TF1 *parafit = new TF1("parafit", "[0]*(x-[1])*(x-[1])+[2]", -9., 2. ); - msg( MSG::INFO ) << "LorentzAngle 2nd para fit start : " << 4*iLayer + iSide +1 + iModule << " / 16" << endmsg; - parafit->SetParameters(par[0],par[1],LAfit->Eval(par[1],0,0,0)); - m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule ] -> Fit("parafit", "R" , "" ,-9.,2.); - msg( MSG::INFO ) << "LorentzAngle 2nd pre fit start : " << 4*iLayer + iSide +1 + iModule << " / 16" << endmsg; - par[1]=parafit->GetParameter(1); - LAfit->SetParameters(par[0],par[1],par[2],par[3]); - LAfit->SetParLimits(1,par[1],par[1]); - m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Fit("LAfit", "R" , "" ,-9.,2.); - LAfit->GetParameters(par); - LAfit->SetParLimits(1, -90., 90.); - LAfit->SetParameters(par[0],par[1],par[2],par[3]); - msg( MSG::INFO ) << "LorentzAngle 2nd main fit start : " << 4*iLayer + iSide +1 + iModule << " / 16" << endmsg; - fitResult = m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Fit("LAfit", "E" , "" ,-9.,2.); - LAfit->GetParameters(par); - if ( m_LorentzAngleDebugMode ) { - - ostringstream streamFileTmp; - streamFileTmp << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide << "Second_Fit"; - std::string tmp_hn = streamFileTmp.str(); - const char* histo_name = tmp_hn.c_str(); - m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> SetName(histo_name); - m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Write(); - - } - - } - - if( fitResult != 0 ) { - msg( MSG::INFO ) << "Try to fix one parameter sigma=2.0 to determine other initial value!" << endmsg; - msg( MSG::INFO ) << "LorentzAngle 3rd pre fit start : " << 4*iLayer + iSide +1+ iModule << " / 16" << endmsg; - LAfit->SetParameters(par[0],par[1],par[2],2.); - LAfit->SetParLimits(3,2.,2.); - m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Fit("LAfit", "R" , "" ,-9.,2.); - LAfit->GetParameters(par); - LAfit->SetParLimits(3, 0., 50.); - LAfit->SetParameters(par[0],par[1],par[2],par[3]); - msg( MSG::INFO ) << "LorentzAngle 3rd main fit start : " << 4*iLayer + iSide +1 +iModule<< " / 16" << endmsg; - fitResult = m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Fit("LAfit", "E" , "" ,-9.,2.); - LAfit->GetParameters(par); - if ( m_LorentzAngleDebugMode ) { - ostringstream streamFileTmp; - streamFileTmp << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide << "Third_Fit"; - std::string tmp_hn = streamFileTmp.str(); - const char* histo_name = tmp_hn.c_str(); - m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> SetName(histo_name); - m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Write(); - } - - } - - - if ( fitResult == 0 ) { - FitFlag[iLayer][iSide][iModule]= 1; - } else { - DBUploadFlag="R"; - FitFlag[iLayer][iSide][iModule]= 0; - msg( MSG::WARNING ) << "Fit Failed! Unable to get LorentzAngle" << endmsg; - } - double A = par[0]; - double LA = par[1]; // Lorentz Angle - double B = par[2]; - double sigma = par[3]; - double err_A = err_par[0]; - double err_LA = err_par[1]; // Lorentz Angle - double err_B = err_par[2]; - double err_sigma = err_par[3]; - float MCW = LAfit->Eval(LA,0,0,0); //Min-cluster-width - float err_MCW = LAfit->Eval(fabs(err_par[1]),0,0,0); //Min-cluster-width - // float lorentz = fabs(LA); - - A_BarrelSide[iLayer][iSide][iModule]= A; - LA_BarrelSide[iLayer][iSide][iModule]=LA; - B_BarrelSide[iLayer][iSide][iModule]=B; - Sigma_BarrelSide[iLayer][iSide][iModule]=sigma; - Err_A_BarrelSide[iLayer][iSide][iModule]= err_A; - Err_LA_BarrelSide[iLayer][iSide][iModule]=err_LA; - Err_B_BarrelSide[iLayer][iSide][iModule]=err_B; - Err_Sigma_BarrelSide[iLayer][iSide][iModule]=err_sigma; - MCW_BarrelSide[iLayer][iSide][iModule]=MCW; - Err_MCW_BarrelSide[iLayer][iSide][iModule]=err_MCW; - Chisq_BarrelSide[iLayer][iSide][iModule]=LAfit->GetChisquare(); + + if( fitResult != 0 ) { + msg( MSG::INFO ) << "Try to use parabola Fit to determine initial value!" << endmsg; + TF1 *parafit = new TF1("parafit", "[0]*(x-[1])*(x-[1])+[2]", -9., 2. ); + msg( MSG::INFO ) << "LorentzAngle 2nd para fit start : " << 4*iLayer + iSide +1 + iModule << " / 16" << endmsg; + parafit->SetParameters(par[0],par[1],LAfit->Eval(par[1],0,0,0)); + m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule ] -> Fit("parafit", "R", "",-9.,2.); + msg( MSG::INFO ) << "LorentzAngle 2nd pre fit start : " << 4*iLayer + iSide +1 + iModule << " / 16" << endmsg; + par[1]=parafit->GetParameter(1); + LAfit->SetParameters(par[0],par[1],par[2],par[3]); + LAfit->SetParLimits(1,par[1],par[1]); + m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Fit("LAfit", "R", "",-9.,2.); + LAfit->GetParameters(par); + LAfit->SetParLimits(1, -90., 90.); + LAfit->SetParameters(par[0],par[1],par[2],par[3]); + msg( MSG::INFO ) << "LorentzAngle 2nd main fit start : " << 4*iLayer + iSide +1 + iModule << " / 16" << endmsg; + fitResult = m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Fit("LAfit", "E", "",-9.,2.); + LAfit->GetParameters(par); + if ( m_LorentzAngleDebugMode ) { + + ostringstream streamFileTmp; + streamFileTmp << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide << "Second_Fit"; + std::string tmp_hn = streamFileTmp.str(); + const char* histo_name = tmp_hn.c_str(); + m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> SetName(histo_name); + m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Write(); + + } + } - } - - } - - - if ( m_LorentzAngleDebugMode ) { - fitFile->Close(); - } - - for ( int iLayer = 0; iLayer < n_barrels; ++iLayer ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - for ( int iModule = 0; iModule < 2; ++iModule ) { - Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, 0, 0, iSide ); - int ch = 0; - outFile << "<folderDefinition folder=\"SCT/Derived/LorentzAngleRun2_v2\" version=\"multi\">" << linefeed - << " <folderDescription>" << linefeed - << " <timeStamp>run-lumi</timeStamp>" << linefeed - << " <addrHeader>" << linefeed - << " <address_header service_type=\"71\" clid=\"1238547719\">" << linefeed - << " </addrHeader>" << linefeed - << " <typeName>CondAttrListCollection</typeName>" << linefeed - << " </folderDescription>" << linefeed - - << " <payloadDescription>" << linefeed - - - << " <payloadType name=\"moduleType\">" << moduleint[iModule] << "</payloadType>" << linefeed - << " <payloadType name=\"lorentzAngle\">" << LA_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed - << " <payloadType name=\"err_lorentzAngle\">" << Err_LA_BarrelSide[iLayer][iSide][iModule]<< "</payloadType>" << linefeed - << " <payloadType name=\"chisq\">" << Chisq_BarrelSide[iLayer][iSide][iModule]<< "</payloadType>" << linefeed - << " <payloadType name=\"fitParam_a\">" << A_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed - << " <payloadType name=\"err_a\">" << Err_A_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed - << " <payloadType name=\"fitParam_b\">" << B_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed - << " <payloadType name=\"err_b\">" << Err_B_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed - << " <payloadType name=\"fitParam_sigma\">" << Sigma_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed - << " <payloadType name=\"err_sigma\">" << Err_Sigma_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed - << " <payloadType name=\"minClusterWidth\">" << MCW_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed - << " <payloadType name=\"err_minClusterWidth\">" << Err_MCW_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed - - << " </payloadDescription>" <<linefeed - << " <channel id=\"" << ch << "\" name=\""<<iLayer<< "_"<<iSide<<" \" />" << linefeed - << "</folderDefinition>" << endl; - - ch++; - - //--- DB output - if ( m_writeToCool ) { - // if ( m_pCalibWriteSvc->createListLA( waferId, m_pSCTHelper, 10000, moduleint[iModule], LA_BarrelSide[iLayer][iSide][iModule],MCW_BarrelSide[iLayer][iSide][iModule] ).isFailure() ) { - if ( m_pCalibWriteSvc->createListLA( waferId, m_pSCTHelper, 10000, moduleint[iModule], LA_BarrelSide[iLayer][iSide][iModule], Err_LA_BarrelSide[iLayer][iSide][iModule], Chisq_BarrelSide[iLayer][iSide][iModule], A_BarrelSide[iLayer][iSide][iModule], Err_A_BarrelSide[iLayer][iSide][iModule], B_BarrelSide[iLayer][iSide][iModule], Err_B_BarrelSide[iLayer][iSide][iModule], Sigma_BarrelSide[iLayer][iSide][iModule], Err_Sigma_BarrelSide[iLayer][iSide][iModule], MCW_BarrelSide[iLayer][iSide][iModule], Err_MCW_BarrelSide[iLayer][iSide][iModule] ).isFailure() ) { - msg( MSG::ERROR ) << "Unable to run createListLA" << endmsg; - return StatusCode::FAILURE; - } - } + if( fitResult != 0 ) { + msg( MSG::INFO ) << "Try to fix one parameter sigma=2.0 to determine other initial value!" << endmsg; + msg( MSG::INFO ) << "LorentzAngle 3rd pre fit start : " << 4*iLayer + iSide +1+ iModule << " / 16" << endmsg; + LAfit->SetParameters(par[0],par[1],par[2],2.); + LAfit->SetParLimits(3,2.,2.); + m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Fit("LAfit", "R", "",-9.,2.); + LAfit->GetParameters(par); + LAfit->SetParLimits(3, 0., 50.); + LAfit->SetParameters(par[0],par[1],par[2],par[3]); + msg( MSG::INFO ) << "LorentzAngle 3rd main fit start : " << 4*iLayer + iSide +1 +iModule<< " / 16" << endmsg; + fitResult = m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Fit("LAfit", "E", "",-9.,2.); + LAfit->GetParameters(par); + if ( m_LorentzAngleDebugMode ) { + ostringstream streamFileTmp; + streamFileTmp << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide << "Third_Fit"; + std::string tmp_hn = streamFileTmp.str(); + const char* histo_name = tmp_hn.c_str(); + m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> SetName(histo_name); + m_h_phiVsNstripsSideHistoVector[ 4*iLayer + 2*iSide +iModule] -> Write(); + } } - } - } - - //--- Tail of XML outputs - outFile << "</folder>" << endl; - - //--- Summary XML output - ostringstream summaryList; - for( int i = 0; i < n_barrels; ++i ) { - for ( int iSide = 0; iSide < 2; ++iSide ) { - for ( int iModule = 0; iModule < 2; ++iModule ) { - const std::string thisPart=shortNames[bec2Index(BARREL)]; - summaryList<< " <parts>" << linefeed - << xmlValue("part",thisPart) << linefeed - << xmlValue("layer", i) << linefeed - << xmlValue("Side", iSide) << linefeed - << xmlValue("Module", module[iModule]) << linefeed - << xmlValue("lorentzAngle", LA_BarrelSide[i][iSide][iModule]) << linefeed - << xmlValue("minClusterWidth", MCW_BarrelSide[i][iSide][iModule]) << linefeed - << xmlValue("Fit", FitFlag[i][iSide][iModule]) << linefeed - <<" </parts>" << linefeed; + + + if ( fitResult == 0 ) { + FitFlag[iLayer][iSide][iModule]= 1; + } else { + DBUploadFlag="R"; + FitFlag[iLayer][iSide][iModule]= 0; + msg( MSG::WARNING ) << "Fit Failed! Unable to get LorentzAngle" << endmsg; } - } - } - - std::ofstream & file = m_outLASummary; - typedef std::pair<string, string> TwoStrings; - typedef std::map<std::string, TwoStrings > Names; - Names nameAssociation; - nameAssociation["LorentzAngle"]=TwoStrings(m_LorentzAngleSummaryFile, "LorentzAngleInfo.xsl"); - Names::iterator found=nameAssociation.find("LorentzAngle"); - if (found!=nameAssociation.end()) { - std::string filename=found->second.first; - std::string xslName=found->second.second; - file.open( filename.c_str(), std::ios::out ); - if( !file.good() ) return StatusCode::FAILURE; - file << xmlHeader<< linefeed<< associateStylesheet(xslName) << linefeed<< "<run>"<< endl; - } - else { - msg( MSG::ERROR ) << " argument \"type\" needs to be LorentzAngle." << endmsg; - return StatusCode::FAILURE; - } - - file << xmlValue("RunNumber", (int)m_runNumber) << linefeed - << xmlValue("StartTime", m_utcBegin) << linefeed - << xmlValue("EndTime", m_utcEnd) << linefeed - << xmlValue("Duration", m_calibEvtInfoSvc->duration() ) << linefeed - << xmlValue("LB", m_LBRange) << linefeed - << xmlValue("Events", m_numberOfEvents) << linefeed - << xmlValue("Flag", DBUploadFlag) << linefeed - << " <data>"<< endl; - - - if( wrapUpXML4Summary( m_outLASummary, "LorentzAngle", summaryList ).isFailure() ) { - msg( MSG::ERROR )<< "Problem in closing LorentzAngle file" << endmsg; - return StatusCode::FAILURE; - } - - //--- DB output - if( m_writeToCool ) { - if ( m_pCalibWriteSvc->wrapUpLorentzAngle().isFailure() ) { - msg( MSG::ERROR ) << "Could not get LorentzAngle" << endmsg; - return StatusCode::FAILURE; - } - } + double A = par[0]; + double LA = par[1]; // Lorentz Angle + double B = par[2]; + double sigma = par[3]; + double err_A = err_par[0]; + double err_LA = err_par[1]; // Lorentz Angle + double err_B = err_par[2]; + double err_sigma = err_par[3]; + float MCW = LAfit->Eval(LA,0,0,0); //Min-cluster-width + float err_MCW = LAfit->Eval(fabs(err_par[1]),0,0,0); //Min-cluster-width + // float lorentz = fabs(LA); + + A_BarrelSide[iLayer][iSide][iModule]= A; + LA_BarrelSide[iLayer][iSide][iModule]=LA; + B_BarrelSide[iLayer][iSide][iModule]=B; + Sigma_BarrelSide[iLayer][iSide][iModule]=sigma; + Err_A_BarrelSide[iLayer][iSide][iModule]= err_A; + Err_LA_BarrelSide[iLayer][iSide][iModule]=err_LA; + Err_B_BarrelSide[iLayer][iSide][iModule]=err_B; + Err_Sigma_BarrelSide[iLayer][iSide][iModule]=err_sigma; + MCW_BarrelSide[iLayer][iSide][iModule]=MCW; + Err_MCW_BarrelSide[iLayer][iSide][iModule]=err_MCW; + Chisq_BarrelSide[iLayer][iSide][iModule]=LAfit->GetChisquare(); + + + } + + } + + } + + + if ( m_LorentzAngleDebugMode ) { + fitFile->Close(); + } + + for ( int iLayer = 0; iLayer < n_barrels; ++iLayer ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + for ( int iModule = 0; iModule < 2; ++iModule ) { + Identifier waferId = m_pSCTHelper->wafer_id( BARREL, iLayer, 0, 0, iSide ); + int ch = 0; + outFile << "<folderDefinition folder=\"SCT/Derived/LorentzAngleRun2_v2\" version=\"multi\">" << linefeed + << " <folderDescription>" << linefeed + << " <timeStamp>run-lumi</timeStamp>" << linefeed + << " <addrHeader>" << linefeed + << " <address_header service_type=\"71\" clid=\"1238547719\">" << linefeed + << " </addrHeader>" << linefeed + << " <typeName>CondAttrListCollection</typeName>" << linefeed + << " </folderDescription>" << linefeed + + << " <payloadDescription>" << linefeed + + + << " <payloadType name=\"moduleType\">" << moduleint[iModule] << "</payloadType>" << linefeed + << " <payloadType name=\"lorentzAngle\">" << LA_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed + << " <payloadType name=\"err_lorentzAngle\">" << Err_LA_BarrelSide[iLayer][iSide][iModule]<< "</payloadType>" << linefeed + << " <payloadType name=\"chisq\">" << Chisq_BarrelSide[iLayer][iSide][iModule]<< "</payloadType>" << linefeed + << " <payloadType name=\"fitParam_a\">" << A_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed + << " <payloadType name=\"err_a\">" << Err_A_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed + << " <payloadType name=\"fitParam_b\">" << B_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed + << " <payloadType name=\"err_b\">" << Err_B_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed + << " <payloadType name=\"fitParam_sigma\">" << Sigma_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed + << " <payloadType name=\"err_sigma\">" << Err_Sigma_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed + << " <payloadType name=\"minClusterWidth\">" << MCW_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed + << " <payloadType name=\"err_minClusterWidth\">" << Err_MCW_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed + + << " </payloadDescription>" <<linefeed + << " <channel id=\"" << ch << "\" name=\""<<iLayer<< "_"<<iSide<<" \" />" << linefeed + << "</folderDefinition>" << endl; + + ch++; + + //--- DB output + if ( m_writeToCool ) { + // if ( m_pCalibWriteTool->createListLA( waferId, m_pSCTHelper, 10000, moduleint[iModule], LA_BarrelSide[iLayer][iSide][iModule],MCW_BarrelSide[iLayer][iSide][iModule] ).isFailure() ) { + if ( m_pCalibWriteTool->createListLA( waferId, m_pSCTHelper, 10000, moduleint[iModule], LA_BarrelSide[iLayer][iSide][iModule], Err_LA_BarrelSide[iLayer][iSide][iModule], Chisq_BarrelSide[iLayer][iSide][iModule], A_BarrelSide[iLayer][iSide][iModule], Err_A_BarrelSide[iLayer][iSide][iModule], B_BarrelSide[iLayer][iSide][iModule], Err_B_BarrelSide[iLayer][iSide][iModule], Sigma_BarrelSide[iLayer][iSide][iModule], Err_Sigma_BarrelSide[iLayer][iSide][iModule], MCW_BarrelSide[iLayer][iSide][iModule], Err_MCW_BarrelSide[iLayer][iSide][iModule] ).isFailure() ) { + msg( MSG::ERROR ) << "Unable to run createListLA" << endmsg; + return StatusCode::FAILURE; + } + } + + } + } + } + + //--- Tail of XML outputs + outFile << "</folder>" << endl; + + //--- Summary XML output + ostringstream summaryList; + for( int i = 0; i < n_barrels; ++i ) { + for ( int iSide = 0; iSide < 2; ++iSide ) { + for ( int iModule = 0; iModule < 2; ++iModule ) { + const std::string thisPart=shortNames[bec2Index(BARREL)]; + summaryList<< " <parts>" << linefeed + << xmlValue("part",thisPart) << linefeed + << xmlValue("layer", i) << linefeed + << xmlValue("Side", iSide) << linefeed + << xmlValue("Module", module[iModule]) << linefeed + << xmlValue("lorentzAngle", LA_BarrelSide[i][iSide][iModule]) << linefeed + << xmlValue("minClusterWidth", MCW_BarrelSide[i][iSide][iModule]) << linefeed + << xmlValue("Fit", FitFlag[i][iSide][iModule]) << linefeed + <<" </parts>" << linefeed; + } + } + } + + std::ofstream & file = m_outLASummary; + typedef std::pair<string, string> TwoStrings; + typedef std::map<std::string, TwoStrings > Names; + Names nameAssociation; + nameAssociation["LorentzAngle"]=TwoStrings(m_LorentzAngleSummaryFile, "LorentzAngleInfo.xsl"); + Names::iterator found=nameAssociation.find("LorentzAngle"); + if (found!=nameAssociation.end()) { + std::string filename=found->second.first; + std::string xslName=found->second.second; + file.open( filename.c_str(), std::ios::out ); + if( !file.good() ) return StatusCode::FAILURE; + file << xmlHeader<< linefeed<< associateStylesheet(xslName) << linefeed<< "<run>"<< endl; + } + else { + msg( MSG::ERROR ) << " argument \"type\" needs to be LorentzAngle." << endmsg; + return StatusCode::FAILURE; + } - return StatusCode::SUCCESS; + file << xmlValue("RunNumber", (int)m_runNumber) << linefeed + << xmlValue("StartTime", m_utcBegin) << linefeed + << xmlValue("EndTime", m_utcEnd) << linefeed + << xmlValue("Duration", m_calibEvtInfoTool->duration() ) << linefeed + << xmlValue("LB", m_LBRange) << linefeed + << xmlValue("Events", m_numberOfEvents) << linefeed + << xmlValue("Flag", DBUploadFlag) << linefeed + << " <data>"<< endl; + + + if( wrapUpXML4Summary( m_outLASummary, "LorentzAngle", summaryList ).isFailure() ) { + msg( MSG::ERROR )<< "Problem in closing LorentzAngle file" << endmsg; + return StatusCode::FAILURE; + } + + //--- DB output + if( m_writeToCool ) { + if ( m_pCalibWriteTool->wrapUpLorentzAngle().isFailure() ) { + msg( MSG::ERROR ) << "Could not get LorentzAngle" << endmsg; + return StatusCode::FAILURE; + } + } + + return StatusCode::SUCCESS; } @@ -2507,52 +2506,52 @@ StatusCode SCTCalib::getLorentzAngle() { /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::openXML4DB( std::ofstream& file, const char* type, const char* tag, IOVTime start, IOVTime end ) const { - if( !strcmp( type, "DeadStrip" ) ) { - file.open( m_deadStripsFile.c_str(), std::ios::out ); - if( !file.good() ) return StatusCode::FAILURE; - file << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"MONP200\" folder=\"SCT/Derived/DeadStrips\" "; - } else if ( !strcmp( type, "DeadChip" ) ) { - file.open( m_deadChipsFile.c_str(), std::ios::out ); - if( !file.good() ) return StatusCode::FAILURE; - file << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"MONP200\" folder=\"SCT/Derived/DeadChips\" "; - } else { - msg( MSG::ERROR ) << "in openXML4DB : argument \"type\" needs to be (DeadStrip, DeadChip)." << endmsg; - return StatusCode::FAILURE; - } - file << "since=\"" << start.re_time() << "\" " - << "until=\"" << end.re_time() << "\" " - << "tag=\"" << tag << "\" " - << "version=\"" << "multi\">" << linefeed; - return StatusCode::SUCCESS; + if( !strcmp( type, "DeadStrip" ) ) { + file.open( m_deadStripsFile.c_str(), std::ios::out ); + if( !file.good() ) return StatusCode::FAILURE; + file << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"MONP200\" folder=\"SCT/Derived/DeadStrips\" "; + } else if ( !strcmp( type, "DeadChip" ) ) { + file.open( m_deadChipsFile.c_str(), std::ios::out ); + if( !file.good() ) return StatusCode::FAILURE; + file << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"MONP200\" folder=\"SCT/Derived/DeadChips\" "; + } else { + msg( MSG::ERROR ) << "in openXML4DB : argument \"type\" needs to be (DeadStrip, DeadChip)." << endmsg; + return StatusCode::FAILURE; + } + file << "since=\"" << start.re_time() << "\" " + << "until=\"" << end.re_time() << "\" " + << "tag=\"" << tag << "\" " + << "version=\"" << "multi\">" << linefeed; + return StatusCode::SUCCESS; } StatusCode SCTCalib::closeXML4DB( std::ofstream& file ) const { - file << "</channels>" << endl; - if ( file.is_open() ) { - file.close(); - return StatusCode::SUCCESS; - } else { - return StatusCode::FAILURE; - } + file << "</channels>" << endl; + if ( file.is_open() ) { + file.close(); + return StatusCode::SUCCESS; + } else { + return StatusCode::FAILURE; + } } StatusCode SCTCalib::addToXML4DB( std::ofstream& file, const Identifier& waferId, const char* DefectType, float Threshold, const char* DefectList ) const { - std::string tmp = DefectList; - int length = tmp.length(); - std::string Defect4DB = tmp.substr( 1, length-2 ); // Removing first&end spaces in DefectList - - file << xmlOpenChannel( m_pSCTHelper->module_id( waferId ).get_identifier32().get_compact() , m_iovStart.re_time() , m_iovStop.re_time() ) << linefeed - << xmlValue("SampleSize","10000") << linefeed - << xmlValue("BarrelEndcap", m_pSCTHelper->barrel_ec( waferId ) )<< linefeed - << xmlValue("Layer", m_pSCTHelper->layer_disk( waferId ))<< linefeed - << xmlValue("Eta", m_pSCTHelper->eta_module( waferId )) << linefeed - << xmlValue("Phi", m_pSCTHelper->phi_module( waferId )) << linefeed - << xmlValue("DefectType", DefectType)<< linefeed - << xmlValue("Threshold", Threshold ) << linefeed - << xmlValue("DefectList",Defect4DB) << linefeed - << xmlCloseChannel() << endl; - - return StatusCode::SUCCESS; + std::string tmp = DefectList; + int length = tmp.length(); + std::string Defect4DB = tmp.substr( 1, length-2 ); // Removing first&end spaces in DefectList + + file << xmlOpenChannel( m_pSCTHelper->module_id( waferId ).get_identifier32().get_compact(), m_iovStart.re_time(), m_iovStop.re_time() ) << linefeed + << xmlValue("SampleSize","10000") << linefeed + << xmlValue("BarrelEndcap", m_pSCTHelper->barrel_ec( waferId ) )<< linefeed + << xmlValue("Layer", m_pSCTHelper->layer_disk( waferId ))<< linefeed + << xmlValue("Eta", m_pSCTHelper->eta_module( waferId )) << linefeed + << xmlValue("Phi", m_pSCTHelper->phi_module( waferId )) << linefeed + << xmlValue("DefectType", DefectType)<< linefeed + << xmlValue("Threshold", Threshold ) << linefeed + << xmlValue("DefectList",Defect4DB) << linefeed + << xmlCloseChannel() << endl; + + return StatusCode::SUCCESS; } @@ -2561,905 +2560,711 @@ StatusCode SCTCalib::addToXML4DB( std::ofstream& file, const Identifier& waferId /////////////////////////////////////////////////////////////////////////////////// StatusCode SCTCalib::openXML4DeadSummary( std::ofstream& file, const char* type, int n_Module, int n_Link, int n_Chip, int n_Strip ) const { - if ( !strcmp( type, "DEAD" ) ) { - file.open( m_deadSummaryFile.c_str(), std::ios::out ); - if( !file.good() ) return StatusCode::FAILURE; - file << xmlHeader<< linefeed<< associateStylesheet("DeadInfo.xsl") << linefeed - << "<run>"<< linefeed; - } else { - msg( MSG::ERROR ) << "in openXML4DeadSummary : argument \"type\" needs to be \"DEAD\"." << endmsg; - return StatusCode::FAILURE; - } - - //--- Upload flag - string strUploadFlag = "U"; - bool isNonZero( false ); - - if ( (m_doDeadChip && m_deadChipUploadTest) || (m_doDeadStrip && m_deadStripUploadTest) ) { - if ( n_Chip > 0 ) { - isNonZero = true; - strUploadFlag = "G"; - } else { - strUploadFlag = "R"; - } - } - - //--- Upload test result - ostringstream osNonZero; - osNonZero << "#chips or #strips is non-zero"; - ostringstream osFlagReason; - if ( !isNonZero ) osFlagReason << "FAILED in " << osNonZero.str(); - string strFlagEnable = ( m_deadChipUploadTest || m_deadStripUploadTest ) ? "ENABLED" : "DISABLED"; - ostringstream osCheckList; - osCheckList << osNonZero.str(); - - file <<xmlValue("RunNumber",(int) m_runNumber) << linefeed - <<xmlValue("StartTime", m_utcBegin) << linefeed - <<xmlValue("EndTime", m_utcEnd) << linefeed - <<xmlValue("Duration", m_calibEvtInfoSvc->duration()) << linefeed - <<xmlValue("LB", m_calibEvtInfoSvc->numLumiBlocks())<< linefeed - <<xmlValue("Events", m_numberOfEvents ) << linefeed - <<xmlValue("Modules", n_Module) << linefeed - <<xmlValue("Links", n_Link) << linefeed - <<xmlValue("Chips", n_Chip) << linefeed - <<xmlValue("Strips", n_Strip) << linefeed - <<xmlValue("Flag", strUploadFlag) << linefeed - <<xmlValue("FlagReason", osFlagReason.str()) << linefeed - <<xmlValue("FlagEnable", strFlagEnable) << linefeed - <<xmlValue("CheckList", osCheckList.str()) << linefeed - <<" <modules>" << endl; - - return StatusCode::SUCCESS; + if ( !strcmp( type, "DEAD" ) ) { + file.open( m_deadSummaryFile.c_str(), std::ios::out ); + if( !file.good() ) return StatusCode::FAILURE; + file << xmlHeader<< linefeed<< associateStylesheet("DeadInfo.xsl") << linefeed + << "<run>"<< linefeed; + } else { + msg( MSG::ERROR ) << "in openXML4DeadSummary : argument \"type\" needs to be \"DEAD\"." << endmsg; + return StatusCode::FAILURE; + } + + //--- Upload flag + string strUploadFlag = "U"; + bool isNonZero( false ); + + if ( (m_doDeadChip && m_deadChipUploadTest) || (m_doDeadStrip && m_deadStripUploadTest) ) { + if ( n_Chip > 0 ) { + isNonZero = true; + strUploadFlag = "G"; + } else { + strUploadFlag = "R"; + } + } + + //--- Upload test result + ostringstream osNonZero; + osNonZero << "#chips or #strips is non-zero"; + ostringstream osFlagReason; + if ( !isNonZero ) osFlagReason << "FAILED in " << osNonZero.str(); + string strFlagEnable = ( m_deadChipUploadTest || m_deadStripUploadTest ) ? "ENABLED" : "DISABLED"; + ostringstream osCheckList; + osCheckList << osNonZero.str(); + + file <<xmlValue("RunNumber",(int) m_runNumber) << linefeed + <<xmlValue("StartTime", m_utcBegin) << linefeed + <<xmlValue("EndTime", m_utcEnd) << linefeed + <<xmlValue("Duration", m_calibEvtInfoTool->duration()) << linefeed + <<xmlValue("LB", m_calibEvtInfoTool->numLumiBlocks())<< linefeed + <<xmlValue("Events", m_numberOfEvents ) << linefeed + <<xmlValue("Modules", n_Module) << linefeed + <<xmlValue("Links", n_Link) << linefeed + <<xmlValue("Chips", n_Chip) << linefeed + <<xmlValue("Strips", n_Strip) << linefeed + <<xmlValue("Flag", strUploadFlag) << linefeed + <<xmlValue("FlagReason", osFlagReason.str()) << linefeed + <<xmlValue("FlagEnable", strFlagEnable) << linefeed + <<xmlValue("CheckList", osCheckList.str()) << linefeed + <<" <modules>" << endl; + + return StatusCode::SUCCESS; } StatusCode SCTCalib::openXML4MonSummary( std::ofstream& file, const char* type ) const { - typedef std::pair<string, string> TwoStrings; - typedef std::map<std::string, TwoStrings > Names; - Names nameAssociation; - nameAssociation["NoiseOccupancy"]=TwoStrings(m_noiseOccupancySummaryFile, "NoiseOccupancyInfo.xsl"); - nameAssociation["RawOccupancy"]=TwoStrings(m_rawOccupancySummaryFile, "RawOccupancyInfo.xsl"); - nameAssociation["Efficiency"]=TwoStrings(m_efficiencySummaryFile, "EfficiencyInfo.xsl"); - nameAssociation["BSErrors"]=TwoStrings(m_BSErrorSummaryFile, "BSErrorInfo.xsl"); - nameAssociation["BSErrorsModule"]=TwoStrings(m_BSErrorModuleFile, "BSErrorInfo.xsl"); - // nameAssociation["LorentzAngle"]=TwoStrings(m_LorentzAngleSummaryFile, "LorentzAngleInfo.xsl"); - Names::iterator found=nameAssociation.find(type); - if (found!=nameAssociation.end()) { - std::string filename=found->second.first; - std::string xslName=found->second.second; - // - file.open( filename.c_str(), std::ios::out ); - if( !file.good() ) return StatusCode::FAILURE; - file << xmlHeader<< linefeed<< associateStylesheet(xslName) << linefeed<< "<run>"<< endl; - } else { - msg( MSG::ERROR ) << "in openXML4MonSummary : argument \"type\" needs to be ( NoiseOccupancy, RawOccupancy, Efficiency, BSErrors )." << endmsg; - return StatusCode::FAILURE; - } - file << xmlValue("RunNumber", (int)m_runNumber ) << linefeed - << xmlValue("StartTime", m_utcBegin ) << linefeed - << xmlValue("EndTime", m_utcEnd ) << linefeed - << xmlValue("Duration", m_calibEvtInfoSvc->duration() ) << linefeed - << xmlValue("LB", m_LBRange ) << linefeed - << xmlValue("Events", m_numberOfEvents ) << linefeed - << " <data>"<< endl; - return StatusCode::SUCCESS; + typedef std::pair<string, string> TwoStrings; + typedef std::map<std::string, TwoStrings > Names; + Names nameAssociation; + nameAssociation["NoiseOccupancy"]=TwoStrings(m_noiseOccupancySummaryFile, "NoiseOccupancyInfo.xsl"); + nameAssociation["RawOccupancy"]=TwoStrings(m_rawOccupancySummaryFile, "RawOccupancyInfo.xsl"); + nameAssociation["Efficiency"]=TwoStrings(m_efficiencySummaryFile, "EfficiencyInfo.xsl"); + nameAssociation["BSErrors"]=TwoStrings(m_BSErrorSummaryFile, "BSErrorInfo.xsl"); + nameAssociation["BSErrorsModule"]=TwoStrings(m_BSErrorModuleFile, "BSErrorInfo.xsl"); + // nameAssociation["LorentzAngle"]=TwoStrings(m_LorentzAngleSummaryFile, "LorentzAngleInfo.xsl"); + Names::iterator found=nameAssociation.find(type); + if (found!=nameAssociation.end()) { + std::string filename=found->second.first; + std::string xslName=found->second.second; + // + file.open( filename.c_str(), std::ios::out ); + if( !file.good() ) return StatusCode::FAILURE; + file << xmlHeader<< linefeed<< associateStylesheet(xslName) << linefeed<< "<run>"<< endl; + } else { + msg( MSG::ERROR ) << "in openXML4MonSummary : argument \"type\" needs to be ( NoiseOccupancy, RawOccupancy, Efficiency, BSErrors )." << endmsg; + return StatusCode::FAILURE; + } + file << xmlValue("RunNumber", (int)m_runNumber ) << linefeed + << xmlValue("StartTime", m_utcBegin ) << linefeed + << xmlValue("EndTime", m_utcEnd ) << linefeed + << xmlValue("Duration", m_calibEvtInfoTool->duration() ) << linefeed + << xmlValue("LB", m_LBRange ) << linefeed + << xmlValue("Events", m_numberOfEvents ) << linefeed + << " <data>"<< endl; + return StatusCode::SUCCESS; } StatusCode SCTCalib::wrapUpXML4Summary( std::ofstream& file, const char* type, std::ostringstream& list ) const { - file << list.str(); - if( !strcmp( type, "DEAD" ) ) { - file << " </modules>" << endl; - } else if ( !strcmp( type, "NoiseOccupancy" ) || !strcmp( type, "RawOccupancy" ) || !strcmp( type, "Efficiency" ) || !strcmp( type, "BSErrors" ) || !strcmp( type, "LorentzAngle" ) ) { - file << " </data>" << endl; - } - file << "</run>" << endl; - - if( file.is_open() ) { - file.close(); - return StatusCode::SUCCESS; - } else { - return StatusCode::FAILURE; - } + file << list.str(); + if( !strcmp( type, "DEAD" ) ) { + file << " </modules>" << endl; + } else if ( !strcmp( type, "NoiseOccupancy" ) || !strcmp( type, "RawOccupancy" ) || !strcmp( type, "Efficiency" ) || !strcmp( type, "BSErrors" ) || !strcmp( type, "LorentzAngle" ) ) { + file << " </data>" << endl; + } + file << "</run>" << endl; + + if( file.is_open() ) { + file.close(); + return StatusCode::SUCCESS; + } else { + return StatusCode::FAILURE; + } } StatusCode SCTCalib::addToSummaryStr( std::ostringstream& list, const Identifier& waferId, const char* type, const char* stripId, const char* chipId ) const { - //--- Remove first&end spaces in DefectList - const std::string tmpstrip(stripId); - const std::string tmpchip(chipId); - int len_strip = tmpstrip.length(); - int len_chip = tmpchip.length(); - std::string stripList(""); - std::string chipList(""); - if( len_strip > 0 ) stripList = tmpstrip.substr( 1, len_strip-2 ); - if( len_chip > 0 ) chipList = tmpchip.substr( 1, len_chip-2 ); - //--- Identifier/SN - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - cout<<"sn.str()"<<endl; - cout<<sn.str()<<endl; - //--- Preparing linkList - //std::string linkList=chipList2LinkList(chipList); - std::string linkList=chipList2LinkList(stripList); - cout<<linkList<<endl; - //--- Push to summary stream - XmlStreamer m("module", list); - { - XmlStreamer v("value", "name", "SN",list); - list<<sn.str(); - } - { - XmlStreamer v("value", "name", "BecLayerPhiEta", list); - list<<formatPosition(waferId, m_pSCTHelper,".",false); - } - { - XmlStreamer v("value", "name", "LinkID", list); - list<<linkList; - } - // {XmlStreamer v("value", "name", "ChipID", list); list<<chipList;} - { - XmlStreamer v("value", "name", "ChipID", list); - list<<stripList; - } - cout<<"after xmlstreamer"<<endl; - if ( !strcmp( type, "DEAD" ) ) { - - cout<<"before if streamer"<<endl; - XmlStreamer v("value", "name", "StripIDOnline", list); - cout<<"after if streamer"<<endl; - list << stripList; - cout<<"list"<<endl; - - } else { - - msg( MSG::ERROR ) << "in addToSummaryStr : argument \"type\" needs to be \"DEAD\"." << endmsg; - cout<<"return FAILURE"<<endl; - return StatusCode::FAILURE; - - } - - cout<<"return SUCCESS"<<endl; - return StatusCode::SUCCESS; + //--- Remove first&end spaces in DefectList + const std::string tmpstrip(stripId); + const std::string tmpchip(chipId); + int len_strip = tmpstrip.length(); + int len_chip = tmpchip.length(); + std::string stripList(""); + std::string chipList(""); + if( len_strip > 0 ) stripList = tmpstrip.substr( 1, len_strip-2 ); + if( len_chip > 0 ) chipList = tmpchip.substr( 1, len_chip-2 ); + //--- Identifier/SN + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + cout<<"sn.str()"<<endl; + cout<<sn.str()<<endl; + //--- Preparing linkList + //std::string linkList=chipList2LinkList(chipList); + std::string linkList=chipList2LinkList(stripList); + cout<<linkList<<endl; + //--- Push to summary stream + XmlStreamer m("module", list); + { + XmlStreamer v("value", "name", "SN",list); + list<<sn.str(); + } + { + XmlStreamer v("value", "name", "BecLayerPhiEta", list); + list<<formatPosition(waferId, m_pSCTHelper,".",false); + } + { + XmlStreamer v("value", "name", "LinkID", list); + list<<linkList; + } + // {XmlStreamer v("value", "name", "ChipID", list); list<<chipList;} + { + XmlStreamer v("value", "name", "ChipID", list); + list<<stripList; + } + cout<<"after xmlstreamer"<<endl; + if ( !strcmp( type, "DEAD" ) ) { + + cout<<"before if streamer"<<endl; + XmlStreamer v("value", "name", "StripIDOnline", list); + cout<<"after if streamer"<<endl; + list << stripList; + cout<<"list"<<endl; + + } else { + + msg( MSG::ERROR ) << "in addToSummaryStr : argument \"type\" needs to be \"DEAD\"." << endmsg; + cout<<"return FAILURE"<<endl; + return StatusCode::FAILURE; + + } + + cout<<"return SUCCESS"<<endl; + return StatusCode::SUCCESS; } std::string SCTCalib::xmlChannelNoiseOccDataString(const Identifier & waferId, const float occupancy, const SCT_SerialNumber & serial) { - //agrohsje added space and ostringstream for proper xml output - ostringstream os; - os<<xmlOpenChannel(waferId.get_identifier32().get_compact(), m_iovStart.re_time(), m_iovStop.re_time())<<endl - <<" "<<xmlValue("SN", serial.str())<<endl - <<" "<<xmlValue("SampleSize", "10000")<<endl - <<" "<<xmlValue("barrel_endcap", m_pSCTHelper->barrel_ec( waferId ) )<<endl - <<" "<<xmlValue("Layer", m_pSCTHelper->layer_disk( waferId ) )<< linefeed - <<" "<<xmlValue("Eta", m_pSCTHelper->eta_module( waferId ) )<<endl - <<" "<<xmlValue("Phi", m_pSCTHelper->phi_module( waferId ) )<<endl - <<" "<<xmlValue("NoiseOccupancy", occupancy)<<endl - <<" "<<xmlCloseChannel(); - return os.str(); + //agrohsje added space and ostringstream for proper xml output + ostringstream os; + os<<xmlOpenChannel(waferId.get_identifier32().get_compact(), m_iovStart.re_time(), m_iovStop.re_time())<<endl + <<" "<<xmlValue("SN", serial.str())<<endl + <<" "<<xmlValue("SampleSize", "10000")<<endl + <<" "<<xmlValue("barrel_endcap", m_pSCTHelper->barrel_ec( waferId ) )<<endl + <<" "<<xmlValue("Layer", m_pSCTHelper->layer_disk( waferId ) )<< linefeed + <<" "<<xmlValue("Eta", m_pSCTHelper->eta_module( waferId ) )<<endl + <<" "<<xmlValue("Phi", m_pSCTHelper->phi_module( waferId ) )<<endl + <<" "<<xmlValue("NoiseOccupancy", occupancy)<<endl + <<" "<<xmlCloseChannel(); + return os.str(); } //agasconb 02.02.2015: block for Efficiency output //requested by Naoki Ishijima std::string SCTCalib::xmlChannelEfficiencyDataString(const Identifier & waferId, const float efficiency, const SCT_SerialNumber & serial) { - ostringstream os; - os<<" <module>"<<endl - // os<<xmlOpenChannel(waferId.get_identifier32().get_compact(), m_iovStart.re_time(), m_iovStop.re_time())<<endl - <<" "<<xmlValue("SN", serial.str())<<endl - <<" "<<xmlValue("SampleSize", "10000")<<endl - <<" "<<xmlValue("barrel_endcap", m_pSCTHelper->barrel_ec( waferId ) )<<endl - <<" "<<xmlValue("Layer", m_pSCTHelper->layer_disk( waferId ) )<< linefeed - <<" "<<xmlValue("Eta", m_pSCTHelper->eta_module( waferId ) )<<endl - <<" "<<xmlValue("Phi", m_pSCTHelper->phi_module( waferId ) )<<endl - <<" "<<xmlValue("Efficiency", efficiency)<<endl - <<" </module>"; - // <<" "<<xmlCloseChannel(); - return os.str(); + ostringstream os; + os<<" <module>"<<endl + // os<<xmlOpenChannel(waferId.get_identifier32().get_compact(), m_iovStart.re_time(), m_iovStop.re_time())<<endl + <<" "<<xmlValue("SN", serial.str())<<endl + <<" "<<xmlValue("SampleSize", "10000")<<endl + <<" "<<xmlValue("barrel_endcap", m_pSCTHelper->barrel_ec( waferId ) )<<endl + <<" "<<xmlValue("Layer", m_pSCTHelper->layer_disk( waferId ) )<< linefeed + <<" "<<xmlValue("Eta", m_pSCTHelper->eta_module( waferId ) )<<endl + <<" "<<xmlValue("Phi", m_pSCTHelper->phi_module( waferId ) )<<endl + <<" "<<xmlValue("Efficiency", efficiency)<<endl + <<" </module>"; + // <<" "<<xmlCloseChannel(); + return os.str(); } std::pair< int, bool > SCTCalib::getNumNoisyStrips( const Identifier& waferId ) const { - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - //--- Check if there are noisy strips in the wafer - int numNoisyStripsInTheWafer = 0; - bool isNoisyWafer(false); - float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); - for ( int iStrip = 0; iStrip != nbins; ++iStrip ) { - if ( m_calibHitmapSvc->getBinForHistogramIndex( iStrip + 1 , (int) waferHash ) / m_numberOfEvents > noisyStripThr ) ++numNoisyStripsInTheWafer; - } - //--- Define/counts noisy wafers using wafer occupancy and number of noisy strips - double averageOccupancy = m_calibHitmapSvc->size((int) waferHash)/(double)nbins/(double)m_numberOfEvents; - const int subdetector(m_pSCTHelper->barrel_ec( waferId ) ); - isNoisyWafer = ( numNoisyStripsInTheWafer > m_noisyWaferFraction*nbins ) and - ( ( subdetector == ENDCAP_C && averageOccupancy > m_noisyWaferThrECC) or - ( subdetector == BARREL && averageOccupancy > m_noisyWaferThrBarrel) or - ( subdetector == ENDCAP_A && averageOccupancy > m_noisyWaferThrECA) ); - if (isNoisyWafer) { - msg( MSG::INFO ) << "Module: " << (int) waferHash << endmsg; - msg( MSG::INFO ) << "Hits, Nevts, Occ: " << m_calibHitmapSvc->size((int) waferHash) << ", " - << m_numberOfEvents << ", " - << averageOccupancy << endmsg; - } - return std::make_pair( numNoisyStripsInTheWafer, isNoisyWafer ); + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + //--- Check if there are noisy strips in the wafer + int numNoisyStripsInTheWafer = 0; + bool isNoisyWafer(false); + float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); + for ( int iStrip = 0; iStrip != nbins; ++iStrip ) { + if ( m_calibHitmapTool->getBinForHistogramIndex( iStrip + 1, (int) waferHash ) / m_numberOfEvents > noisyStripThr ) ++numNoisyStripsInTheWafer; + } + //--- Define/counts noisy wafers using wafer occupancy and number of noisy strips + double averageOccupancy = m_calibHitmapTool->size((int) waferHash)/(double)nbins/(double)m_numberOfEvents; + const int subdetector(m_pSCTHelper->barrel_ec( waferId ) ); + isNoisyWafer = ( numNoisyStripsInTheWafer > m_noisyWaferFraction*nbins ) and + ( ( subdetector == ENDCAP_C && averageOccupancy > m_noisyWaferThrECC) or + ( subdetector == BARREL && averageOccupancy > m_noisyWaferThrBarrel) or + ( subdetector == ENDCAP_A && averageOccupancy > m_noisyWaferThrECA) ); + if (isNoisyWafer) { + msg( MSG::INFO ) << "Module: " << (int) waferHash << endmsg; + msg( MSG::INFO ) << "Hits, Nevts, Occ: " << m_calibHitmapTool->size((int) waferHash) << ", " + << m_numberOfEvents << ", " + << averageOccupancy << endmsg; + } + return std::make_pair( numNoisyStripsInTheWafer, isNoisyWafer ); } StatusCode SCTCalib::addStripsToList( Identifier& waferId, std::set<Identifier>& stripIdList, bool isNoisy, bool isNew ) { - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); - for ( int iStrip = 0; iStrip != nbins; ++iStrip ) { - Identifier stripId = m_pSCTHelper->strip_id( waferId, iStrip ); - if ( !isNoisy ) { //--- Add all strips - stripIdList.insert( stripId ); - } else { - const float stripOccupancy = m_calibHitmapSvc->getBinForHistogramIndex( iStrip + 1 , (int) waferHash ) / m_numberOfEvents; - if ( stripOccupancy > noisyStripThr ) { - if ( !isNew ) { //--- All noisy strips - stripIdList.insert( stripId ); - } else { //--- New noisy strips : compared with configuration and calibration - const bool isGoodInConfiguration = m_useConfiguration ? m_ConfigurationConditionsTool->isGood( stripId, InDetConditions::SCT_STRIP ) : true; - const bool isGoodInCalibration = m_useCalibration ? m_ReadCalibDataTool->isGood( stripId, InDetConditions::SCT_STRIP ) : true; - if ( m_useConfiguration or m_useCalibration ) { - if ( isGoodInConfiguration && isGoodInCalibration ) { - stripIdList.insert( stripId ); - } - } - } + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); + for ( int iStrip = 0; iStrip != nbins; ++iStrip ) { + Identifier stripId = m_pSCTHelper->strip_id( waferId, iStrip ); + if ( !isNoisy ) { //--- Add all strips + stripIdList.insert( stripId ); + } else { + const float stripOccupancy = m_calibHitmapTool->getBinForHistogramIndex( iStrip + 1, (int) waferHash ) / m_numberOfEvents; + if ( stripOccupancy > noisyStripThr ) { + if ( !isNew ) { //--- All noisy strips + stripIdList.insert( stripId ); + } else { //--- New noisy strips : compared with configuration and calibration + const bool isGoodInConfiguration = m_useConfiguration ? m_ConfigurationConditionsTool->isGood( stripId, InDetConditions::SCT_STRIP ) : true; + const bool isGoodInCalibration = m_useCalibration ? m_ReadCalibDataTool->isGood( stripId, InDetConditions::SCT_STRIP ) : true; + if ( m_useConfiguration or m_useCalibration ) { + if ( isGoodInConfiguration && isGoodInCalibration ) { + stripIdList.insert( stripId ); + } + } } - } - } - return StatusCode::SUCCESS; + } + } + } + return StatusCode::SUCCESS; } StatusCode SCTCalib::writeModuleListToCool( const std::map< Identifier, std::set<Identifier> >& moduleListAll, const std::map< Identifier, std::set<Identifier> >& moduleListNew, const std::map< Identifier, std::set<Identifier> >& moduleListRef ) const { - //--- Write out strips - float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); - int nDefects = 0; - SCT_ID::const_id_iterator idItr = m_pSCTHelper->wafer_begin(); - SCT_ID::const_id_iterator idItrE = m_pSCTHelper->wafer_end(); - for( ; idItr != idItrE; ++idItr ) { - if ( m_pSCTHelper->side( *idItr ) == 0 ) { - Identifier moduleId = m_pSCTHelper->module_id( *idItr ); - map< Identifier, std::set<Identifier> >::const_iterator moduleAllItr = moduleListAll.find( moduleId ); - map< Identifier, std::set<Identifier> >::const_iterator moduleNewItr = moduleListNew.find( moduleId ); - map< Identifier, std::set<Identifier> >::const_iterator moduleRefItr = moduleListRef.find( moduleId ); - std::string defectStripsAll = moduleAllItr != moduleListAll.end() ? getStripList( (*moduleAllItr).second ) : ""; - std::string defectStripsNew = moduleNewItr != moduleListNew.end() ? getStripList( (*moduleNewItr).second ) : ""; - std::string defectStripsRef = moduleRefItr != moduleListRef.end() ? getStripList( (*moduleRefItr).second ) : ""; - if ( m_noisyUpdate ) { //--- UPD1/UPD4 - if ( defectStripsAll != defectStripsRef ) { - if(m_pCalibWriteSvc->createCondObjects( moduleId, m_pSCTHelper, 10000, "NOISY", noisyStripThr, defectStripsAll ).isFailure()) { - msg( MSG::ERROR ) << "Could not create defect strip entry in the CalibWriteSvc." << endmsg; - } - nDefects++; - } else msg( MSG::DEBUG ) << "Module "<< moduleId <<" is identical to the reference output" << endmsg; - } else { - if ( m_noisyStripAll ) { //--- ALL noisy strips - if ( !defectStripsAll.empty() ) m_pCalibWriteSvc->createCondObjects( moduleId, m_pSCTHelper, 10000, "NOISY", noisyStripThr, defectStripsAll ); - } else { //--- Only NEW noisy strips - if ( !defectStripsNew.empty() ) m_pCalibWriteSvc->createCondObjects( moduleId, m_pSCTHelper, 10000, "NOISY", noisyStripThr, defectStripsNew ); - } + //--- Write out strips + float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); + int nDefects = 0; + SCT_ID::const_id_iterator idItr = m_pSCTHelper->wafer_begin(); + SCT_ID::const_id_iterator idItrE = m_pSCTHelper->wafer_end(); + for( ; idItr != idItrE; ++idItr ) { + if ( m_pSCTHelper->side( *idItr ) == 0 ) { + Identifier moduleId = m_pSCTHelper->module_id( *idItr ); + map< Identifier, std::set<Identifier> >::const_iterator moduleAllItr = moduleListAll.find( moduleId ); + map< Identifier, std::set<Identifier> >::const_iterator moduleNewItr = moduleListNew.find( moduleId ); + map< Identifier, std::set<Identifier> >::const_iterator moduleRefItr = moduleListRef.find( moduleId ); + std::string defectStripsAll = moduleAllItr != moduleListAll.end() ? getStripList( (*moduleAllItr).second ) : ""; + std::string defectStripsNew = moduleNewItr != moduleListNew.end() ? getStripList( (*moduleNewItr).second ) : ""; + std::string defectStripsRef = moduleRefItr != moduleListRef.end() ? getStripList( (*moduleRefItr).second ) : ""; + if ( m_noisyUpdate ) { //--- UPD1/UPD4 + if ( defectStripsAll != defectStripsRef ) { + if(m_pCalibWriteTool->createCondObjects( moduleId, m_pSCTHelper, 10000, "NOISY", noisyStripThr, defectStripsAll ).isFailure()) { + msg( MSG::ERROR ) << "Could not create defect strip entry in the CalibWriteTool." << endmsg; + } + nDefects++; + } else msg( MSG::DEBUG ) << "Module "<< moduleId <<" is identical to the reference output" << endmsg; + } else { + if ( m_noisyStripAll ) { //--- ALL noisy strips + if ( !defectStripsAll.empty() ) m_pCalibWriteTool->createCondObjects( moduleId, m_pSCTHelper, 10000, "NOISY", noisyStripThr, defectStripsAll ); + } else { //--- Only NEW noisy strips + if ( !defectStripsNew.empty() ) m_pCalibWriteTool->createCondObjects( moduleId, m_pSCTHelper, 10000, "NOISY", noisyStripThr, defectStripsNew ); } - } - } - //msg( MSG::INFO ) << "Number of modules for which conditions were created: " << nDefects <<" !!!!"<< endmsg; - if ( moduleListAll.empty() || nDefects==0 ) { - msg( MSG::INFO ) << "Number of noisy strips was zero or the same list of noisy strips. No local DB was created." << endmsg; - } else { - if ( m_pCalibWriteSvc->wrapUpNoisyChannel().isFailure() ) { - msg( MSG::ERROR ) << "Could not get NoisyStrips info" << endmsg; - return StatusCode::FAILURE; - } - } - return StatusCode::SUCCESS; + } + } + } + //msg( MSG::INFO ) << "Number of modules for which conditions were created: " << nDefects <<" !!!!"<< endmsg; + if ( moduleListAll.empty() || nDefects==0 ) { + msg( MSG::INFO ) << "Number of noisy strips was zero or the same list of noisy strips. No local DB was created." << endmsg; + } else { + if ( m_pCalibWriteTool->wrapUpNoisyChannel().isFailure() ) { + msg( MSG::ERROR ) << "Could not get NoisyStrips info" << endmsg; + return StatusCode::FAILURE; + } + } + return StatusCode::SUCCESS; } std::string SCTCalib::getStripList( const std::set<Identifier>& stripIdList ) const { - std::string strList; - if ( !stripIdList.empty() ) { - int firstStrip = -1; - int groupSize = -1; - - std::set<Identifier>::const_iterator stripItrFirst = stripIdList.begin(); - std::set<Identifier>::const_iterator stripItrLast = --stripIdList.end(); - - std::set<Identifier>::const_iterator stripItr = stripIdList.begin(); - std::set<Identifier>::const_iterator stripItrE = stripIdList.end(); - for ( ; stripItr != stripItrE; ++stripItr ) { - Identifier stripId = *stripItr; - int stripNum = m_pSCTHelper->side( stripId )*nbins + m_pSCTHelper->strip( stripId ); - if ( stripItr == stripItrFirst ) { - firstStrip = stripNum; - groupSize = 1; + std::string strList; + if ( !stripIdList.empty() ) { + int firstStrip = -1; + int groupSize = -1; + + std::set<Identifier>::const_iterator stripItrFirst = stripIdList.begin(); + std::set<Identifier>::const_iterator stripItrLast = --stripIdList.end(); + + std::set<Identifier>::const_iterator stripItr = stripIdList.begin(); + std::set<Identifier>::const_iterator stripItrE = stripIdList.end(); + for ( ; stripItr != stripItrE; ++stripItr ) { + Identifier stripId = *stripItr; + int stripNum = m_pSCTHelper->side( stripId )*nbins + m_pSCTHelper->strip( stripId ); + if ( stripItr == stripItrFirst ) { + firstStrip = stripNum; + groupSize = 1; + } else { + if ( stripNum == firstStrip + groupSize ) { + ++groupSize; } else { - if ( stripNum == firstStrip + groupSize ) { - ++groupSize; - } else { - int stripBegin = firstStrip; - int stripEnd = firstStrip + groupSize -1; - strList = m_pCalibWriteSvc->addDefect( strList, stripBegin, stripEnd ); - firstStrip = stripNum; - groupSize = 1; - } - } - if ( stripItr == stripItrLast ) { - int stripBegin = firstStrip; - int stripEnd = stripNum; - strList = m_pCalibWriteSvc->addDefect( strList, stripBegin, stripEnd ); + int stripBegin = firstStrip; + int stripEnd = firstStrip + groupSize -1; + strList = m_pCalibWriteTool->addDefect( strList, stripBegin, stripEnd ); + firstStrip = stripNum; + groupSize = 1; } - } - } - return strList; + } + if ( stripItr == stripItrLast ) { + int stripBegin = firstStrip; + int stripEnd = stripNum; + strList = m_pCalibWriteTool->addDefect( strList, stripBegin, stripEnd ); + } + } + } + return strList; } StatusCode SCTCalib::noisyStripsToXml( const std::map< Identifier, std::set<Identifier> >& moduleList, const std::string& badStripsFile ) const { - //--- Open - const char* outputFileName = badStripsFile.c_str(); - ofstream outFile( outputFileName, std::ios::out ); - if ( !outFile.good() ) { - msg( MSG::ERROR ) << "Unable to open " << outputFileName << endmsg; - return( StatusCode::FAILURE ); - } - float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); - //--- Create module list - ostringstream osModuleList; - //--- Loop over wafers - SCT_ID::const_id_iterator waferItr = m_pSCTHelper->wafer_begin(); - SCT_ID::const_id_iterator waferItrE = m_pSCTHelper->wafer_end(); - for( ; waferItr != waferItrE; ++waferItr ) { - Identifier waferId = *waferItr; - Identifier moduleId = m_pSCTHelper->module_id( waferId ); - if ( m_pSCTHelper->side( waferId ) != 0 ) continue; - map< Identifier, std::set<Identifier> >::const_iterator moduleItr = moduleList.find( moduleId ); - if ( moduleItr != moduleList.end() ) { - std::string defectStrips = getStripList( (*moduleItr).second ); - osModuleList << " <channel id=\"" << m_pSCTHelper->module_id( waferId ).get_compact() << "\" " - << "since=\"" << m_iovStart.re_time() << "\" " - << "until=\"" << m_iovStop.re_time() << "\">" << linefeed - << " <value name=\"SampleSize\">" << "10000" << "</value>" << linefeed - << " <value name=\"BarrelEndcap\">" << m_pSCTHelper->barrel_ec( waferId ) << "</value>" << linefeed - << " <value name=\"Layer\">" << m_pSCTHelper->layer_disk( waferId )<< "</value>" << linefeed - << " <value name=\"Eta\">" << m_pSCTHelper->eta_module( waferId )<< "</value>" << linefeed - << " <value name=\"Phi\">" << m_pSCTHelper->phi_module( waferId )<< "</value>" << linefeed - << " <value name=\"DefectType\">" << "NOISY" << "</value>" << linefeed - << " <value name=\"Threshold\">" << noisyStripThr << "</value>" << linefeed - << " <value name=\"DefectList\">" << normalizeList( defectStrips ) << "</value>" << linefeed - << " </channel>" << endl; - } - } - //--- Write out the contents - outFile << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"CONDBR2\" folder=\"SCT/Derived/Monitoring\" " - << "since=\"" << m_iovStart.re_time() << "\" " - << "until=\"" << m_iovStop.re_time() << "\" " - << "tag=\"" << m_tagID4NoisyStrips << "\" " - << "version=\"" << "multi\">" << endl - << osModuleList.str() - << "</channels>" << endl; - - return StatusCode::SUCCESS; + //--- Open + const char* outputFileName = badStripsFile.c_str(); + ofstream outFile( outputFileName, std::ios::out ); + if ( !outFile.good() ) { + msg( MSG::ERROR ) << "Unable to open " << outputFileName << endmsg; + return( StatusCode::FAILURE ); + } + float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); + //--- Create module list + ostringstream osModuleList; + //--- Loop over wafers + SCT_ID::const_id_iterator waferItr = m_pSCTHelper->wafer_begin(); + SCT_ID::const_id_iterator waferItrE = m_pSCTHelper->wafer_end(); + for( ; waferItr != waferItrE; ++waferItr ) { + Identifier waferId = *waferItr; + Identifier moduleId = m_pSCTHelper->module_id( waferId ); + if ( m_pSCTHelper->side( waferId ) != 0 ) continue; + map< Identifier, std::set<Identifier> >::const_iterator moduleItr = moduleList.find( moduleId ); + if ( moduleItr != moduleList.end() ) { + std::string defectStrips = getStripList( (*moduleItr).second ); + osModuleList << " <channel id=\"" << m_pSCTHelper->module_id( waferId ).get_compact() << "\" " + << "since=\"" << m_iovStart.re_time() << "\" " + << "until=\"" << m_iovStop.re_time() << "\">" << linefeed + << " <value name=\"SampleSize\">" << "10000" << "</value>" << linefeed + << " <value name=\"BarrelEndcap\">" << m_pSCTHelper->barrel_ec( waferId ) << "</value>" << linefeed + << " <value name=\"Layer\">" << m_pSCTHelper->layer_disk( waferId )<< "</value>" << linefeed + << " <value name=\"Eta\">" << m_pSCTHelper->eta_module( waferId )<< "</value>" << linefeed + << " <value name=\"Phi\">" << m_pSCTHelper->phi_module( waferId )<< "</value>" << linefeed + << " <value name=\"DefectType\">" << "NOISY" << "</value>" << linefeed + << " <value name=\"Threshold\">" << noisyStripThr << "</value>" << linefeed + << " <value name=\"DefectList\">" << normalizeList( defectStrips ) << "</value>" << linefeed + << " </channel>" << endl; + } + } + //--- Write out the contents + outFile << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"CONDBR2\" folder=\"SCT/Derived/Monitoring\" " + << "since=\"" << m_iovStart.re_time() << "\" " + << "until=\"" << m_iovStop.re_time() << "\" " + << "tag=\"" << m_tagID4NoisyStrips << "\" " + << "version=\"" << "multi\">" << endl + << osModuleList.str() + << "</channels>" << endl; + + return StatusCode::SUCCESS; } -StatusCode SCTCalib::noisyStripsToSummaryXml( const std::map< Identifier, std::set<Identifier> >& moduleListAll, - const std::map< Identifier, std::set<Identifier> >& moduleListNew, - const std::map< Identifier, std::set<Identifier> >& moduleListRef, - const std::string& badStripsFile) const { - //--- Open - const char* outputFileName = badStripsFile.c_str(); - ofstream outFile( outputFileName, std::ios::out ); - if ( !outFile.good() ) { - msg( MSG::ERROR ) << "Unable to open " << outputFileName << endmsg; - return( StatusCode::FAILURE ); - } - - //--- Initialization - int numLinksAll( 0 ), numChipsAll( 0 ); - int numModulesAll( 0 ), numModulesNew( 0 ), numModulesRef( 0 ); - int numStripsAll( 0 ), numStripsNew( 0 ), numStripsRef( 0 ); - int numModulesDiff( 0 ); - - std::string defectLinks, defectChips; - std::string defectStripsAll, defectStripsNew, defectStripsRef; - ostringstream osModuleList, osChipList; - - //--- Create module list - SCT_ID::const_id_iterator waferItr = m_pSCTHelper->wafer_begin(); - SCT_ID::const_id_iterator waferItrE = m_pSCTHelper->wafer_end(); - for( ; waferItr != waferItrE; ++waferItr ) { - //--- Identifier - Identifier waferId = *waferItr; - Identifier moduleId = m_pSCTHelper->module_id( waferId ); - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - - //--- Initialization for a module - if ( m_pSCTHelper->side( waferId ) == 0 ) { - defectLinks.erase(); - defectChips.erase(); - defectStripsAll.erase(); - defectStripsNew.erase(); - defectStripsRef.erase(); - } - - //--- Noisy links - bool isNoisyWafer = getNumNoisyStrips( waferId ).second; // true if this wafer is noisy - if ( isNoisyWafer ) { - int link = m_pSCTHelper->side( waferId ); - defectLinks = m_pCalibWriteSvc->addDefect( defectLinks, link, link ); - ++numLinksAll; - } - - //--- Execute once in this module - if ( m_pSCTHelper->side( waferId ) == 1 ) { - //--- Noisy strips : All - map< Identifier, std::set<Identifier> >::const_iterator moduleAllItr = moduleListAll.find( moduleId ); - if ( moduleAllItr != moduleListAll.end() ) { - defectStripsAll = getStripList( (*moduleAllItr).second ); - ++numModulesAll; - numStripsAll += (*moduleAllItr).second.size(); - } - //--- Noisy strips : New - map< Identifier, std::set<Identifier> >::const_iterator moduleNewItr = moduleListNew.find( moduleId ); - if ( moduleNewItr != moduleListNew.end() ) { - defectStripsNew = getStripList( (*moduleNewItr).second ); - ++numModulesNew; - numStripsNew += (*moduleNewItr).second.size(); - } - //--- Noisy strips : Ref - map< Identifier, std::set<Identifier> >::const_iterator moduleRefItr = moduleListRef.find( moduleId ); - if ( moduleRefItr != moduleListRef.end() ) { - defectStripsRef = getStripList( moduleRefItr->second ); - ++numModulesRef; - numStripsRef += moduleRefItr->second.size(); - } - //--- Noisy chips : stripIdList -> chipIdList - if ( moduleAllItr != moduleListAll.end() ) { - std::set<int> chipIdList = getNoisyChips( moduleAllItr->second ); - if ( !chipIdList.empty() ) { - ++numChipsAll; // CS: I think we should count this!? - std::set<int>::iterator chipItr = chipIdList.begin(); - std::set<int>::iterator chipItrE = chipIdList.end(); - for ( ; chipItr != chipItrE; ++chipItr ) { - int chipId = *chipItr; - //--- To be written into module list - defectChips = m_pCalibWriteSvc->addDefect( defectChips, chipId, chipId ); - //--- LBs where this chip was noisy - std::pair< string, float > defectLB = getNoisyLB( moduleId, chipId ); - //--- Chip list written to XML - osChipList << " <chip>" << linefeed - << " <value name=\"SN\">" << sn.str() << "</value>" << linefeed - << " <value name=\"BecLayerPhiEta\">" << m_pSCTHelper->barrel_ec( waferId ) << "." - << m_pSCTHelper->layer_disk( waferId ) << "." - << m_pSCTHelper->phi_module( waferId ) << "." - << m_pSCTHelper->eta_module( waferId ) << "</value>" << linefeed - << " <value name=\"ChipID\">" << chipId << "</value>" << linefeed - << " <value name=\"LB\">" << normalizeList( defectLB.first ) << "</value>" << linefeed - << " <value name=\"LBFraction\">" << defectLB.second << "</value>" << linefeed - << " </chip>" << endl; - } - } - } - //--- Difference between All & Ref - if ( defectStripsAll != defectStripsRef ) ++numModulesDiff; - //--- Module list written to XML - if ( !defectStripsAll.empty() || ( m_noisyUpdate && defectStripsAll != defectStripsRef ) ) { - osModuleList << " <module>" << linefeed - << " <value name=\"SN\">" << sn.str() << "</value>" << linefeed - << " <value name=\"BecLayerPhiEta\">" << m_pSCTHelper->barrel_ec( waferId ) << "." - << m_pSCTHelper->layer_disk( waferId ) << "." - << m_pSCTHelper->phi_module( waferId ) << "." - << m_pSCTHelper->eta_module( waferId ) << "</value>" << linefeed - << " <value name=\"LinkID\">" << normalizeList( defectLinks ) << "</value>" << linefeed - << " <value name=\"ChipID\">" << normalizeList( defectChips ) << "</value>" << linefeed - << " <value name=\"StripOfflineAll\">" << normalizeList( defectStripsAll ) << "</value>" << linefeed - << " <value name=\"StripOfflineNew\">" << normalizeList( defectStripsNew ) << "</value>" << linefeed - << " <value name=\"StripOfflineRef\">" << normalizeList( defectStripsRef ) << "</value>" << linefeed - << " </module>" << endl; +StatusCode SCTCalib::noisyStripsToSummaryXml( const std::map< Identifier, std::set<Identifier> >& moduleListAll, + const std::map< Identifier, std::set<Identifier> >& moduleListNew, + const std::map< Identifier, std::set<Identifier> >& moduleListRef, + const std::string& badStripsFile) const { + //--- Open + const char* outputFileName = badStripsFile.c_str(); + ofstream outFile( outputFileName, std::ios::out ); + if ( !outFile.good() ) { + msg( MSG::ERROR ) << "Unable to open " << outputFileName << endmsg; + return( StatusCode::FAILURE ); + } + + //--- Initialization + int numLinksAll( 0 ), numChipsAll( 0 ); + int numModulesAll( 0 ), numModulesNew( 0 ), numModulesRef( 0 ); + int numStripsAll( 0 ), numStripsNew( 0 ), numStripsRef( 0 ); + int numModulesDiff( 0 ); + + std::string defectLinks, defectChips; + std::string defectStripsAll, defectStripsNew, defectStripsRef; + ostringstream osModuleList, osChipList; + + //--- Create module list + SCT_ID::const_id_iterator waferItr = m_pSCTHelper->wafer_begin(); + SCT_ID::const_id_iterator waferItrE = m_pSCTHelper->wafer_end(); + for( ; waferItr != waferItrE; ++waferItr ) { + //--- Identifier + Identifier waferId = *waferItr; + Identifier moduleId = m_pSCTHelper->module_id( waferId ); + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); + + //--- Initialization for a module + if ( m_pSCTHelper->side( waferId ) == 0 ) { + defectLinks.erase(); + defectChips.erase(); + defectStripsAll.erase(); + defectStripsNew.erase(); + defectStripsRef.erase(); + } + + //--- Noisy links + bool isNoisyWafer = getNumNoisyStrips( waferId ).second; // true if this wafer is noisy + if ( isNoisyWafer ) { + int link = m_pSCTHelper->side( waferId ); + defectLinks = m_pCalibWriteTool->addDefect( defectLinks, link, link ); + ++numLinksAll; + } + + //--- Execute once in this module + if ( m_pSCTHelper->side( waferId ) == 1 ) { + //--- Noisy strips : All + map< Identifier, std::set<Identifier> >::const_iterator moduleAllItr = moduleListAll.find( moduleId ); + if ( moduleAllItr != moduleListAll.end() ) { + defectStripsAll = getStripList( (*moduleAllItr).second ); + ++numModulesAll; + numStripsAll += (*moduleAllItr).second.size(); + } + //--- Noisy strips : New + map< Identifier, std::set<Identifier> >::const_iterator moduleNewItr = moduleListNew.find( moduleId ); + if ( moduleNewItr != moduleListNew.end() ) { + defectStripsNew = getStripList( (*moduleNewItr).second ); + ++numModulesNew; + numStripsNew += (*moduleNewItr).second.size(); + } + //--- Noisy strips : Ref + map< Identifier, std::set<Identifier> >::const_iterator moduleRefItr = moduleListRef.find( moduleId ); + if ( moduleRefItr != moduleListRef.end() ) { + defectStripsRef = getStripList( moduleRefItr->second ); + ++numModulesRef; + numStripsRef += moduleRefItr->second.size(); + } + + //--- Noisy chips : stripIdList -> chipIdList + if ( moduleAllItr != moduleListAll.end() ) { + std::set<int> chipIdList = getNoisyChips( moduleAllItr->second ); + if ( !chipIdList.empty() ) { + ++numChipsAll; // CS: I think we should count this!? + std::set<int>::iterator chipItr = chipIdList.begin(); + std::set<int>::iterator chipItrE = chipIdList.end(); + for ( ; chipItr != chipItrE; ++chipItr ) { + int chipId = *chipItr; + //--- To be written into module list + defectChips = m_pCalibWriteTool->addDefect( defectChips, chipId, chipId ); + //--- LBs where this chip was noisy + std::pair< string, float > defectLB = getNoisyLB( moduleId, chipId ); + //--- Chip list written to XML + osChipList << " <chip>" << linefeed + << " <value name=\"SN\">" << sn.str() << "</value>" << linefeed + << " <value name=\"BecLayerPhiEta\">" << m_pSCTHelper->barrel_ec( waferId ) << "." + << m_pSCTHelper->layer_disk( waferId ) << "." + << m_pSCTHelper->phi_module( waferId ) << "." + << m_pSCTHelper->eta_module( waferId ) << "</value>" << linefeed + << " <value name=\"ChipID\">" << chipId << "</value>" << linefeed + << " <value name=\"LB\">" << normalizeList( defectLB.first ) << "</value>" << linefeed + << " <value name=\"LBFraction\">" << defectLB.second << "</value>" << linefeed + << " </chip>" << endl; + } } - } - }//--- end loop : waferItr - - //--- Upload flag - string strUploadFlag = "U"; - - bool isRunsInCool( false ); - bool isNoisyMinStat( false ), isNoisyModuleList( false ), isNoisyModuleDiff( false ), isNoisyStripDiff( false ); - if ( m_noisyUploadTest ) { - isRunsInCool = m_noisyModuleAverageInDB != -1. && m_noisyStripLastRunInDB != -999; - if ( isRunsInCool ) { - isNoisyMinStat = m_numberOfEvents > m_noisyMinStat; - isNoisyModuleList = numModulesAll < m_noisyModuleList; - isNoisyModuleDiff = ( ( (float) numModulesAll - m_noisyModuleAverageInDB )/m_noisyModuleAverageInDB ) < m_noisyModuleDiff; - isNoisyStripDiff = ( numStripsAll - m_noisyStripAverageInDB ) < m_noisyStripDiff; - if ( !isNoisyMinStat || !isNoisyModuleList ) { - strUploadFlag = "R"; + } + //--- Difference between All & Ref + if ( defectStripsAll != defectStripsRef ) ++numModulesDiff; + //--- Module list written to XML + if ( !defectStripsAll.empty() || ( m_noisyUpdate && defectStripsAll != defectStripsRef ) ) { + osModuleList << " <module>" << linefeed + << " <value name=\"SN\">" << sn.str() << "</value>" << linefeed + << " <value name=\"BecLayerPhiEta\">" << m_pSCTHelper->barrel_ec( waferId ) << "." + << m_pSCTHelper->layer_disk( waferId ) << "." + << m_pSCTHelper->phi_module( waferId ) << "." + << m_pSCTHelper->eta_module( waferId ) << "</value>" << linefeed + << " <value name=\"LinkID\">" << normalizeList( defectLinks ) << "</value>" << linefeed + << " <value name=\"ChipID\">" << normalizeList( defectChips ) << "</value>" << linefeed + << " <value name=\"StripOfflineAll\">" << normalizeList( defectStripsAll ) << "</value>" << linefeed + << " <value name=\"StripOfflineNew\">" << normalizeList( defectStripsNew ) << "</value>" << linefeed + << " <value name=\"StripOfflineRef\">" << normalizeList( defectStripsRef ) << "</value>" << linefeed + << " </module>" << endl; + } + } + }//--- end loop : waferItr + + //--- Upload flag + string strUploadFlag = "U"; + + bool isRunsInCool( false ); + bool isNoisyMinStat( false ), isNoisyModuleList( false ), isNoisyModuleDiff( false ), isNoisyStripDiff( false ); + if ( m_noisyUploadTest ) { + isRunsInCool = m_noisyModuleAverageInDB != -1. && m_noisyStripLastRunInDB != -999; + if ( isRunsInCool ) { + isNoisyMinStat = m_numberOfEvents > m_noisyMinStat; + isNoisyModuleList = numModulesAll < m_noisyModuleList; + isNoisyModuleDiff = ( ( (float) numModulesAll - m_noisyModuleAverageInDB )/m_noisyModuleAverageInDB ) < m_noisyModuleDiff; + isNoisyStripDiff = ( numStripsAll - m_noisyStripAverageInDB ) < m_noisyStripDiff; + if ( !isNoisyMinStat || !isNoisyModuleList ) { + strUploadFlag = "R"; + } else { + if ( !isNoisyModuleDiff || !isNoisyStripDiff ) { + strUploadFlag = "Y"; } else { - if ( !isNoisyModuleDiff || !isNoisyStripDiff ) { - strUploadFlag = "Y"; - } else { - strUploadFlag = "G"; - } + strUploadFlag = "G"; } - } - } - - //--- Upload test result to XML - ostringstream osNoisyMinStat, osNoisyModuleList, osNoisyModuleDiff, osNoisyStripDiff; - osNoisyMinStat << "#events more than " << (int) m_noisyMinStat; - osNoisyModuleList << "#(modules w/ at least 1 noisy strip) less than " << (int) m_noisyModuleList; - osNoisyModuleDiff << "Increase of #(modules w/ at least 1 noisy strip) from average of recent runs less than " << m_noisyModuleDiff*100 << "%"; - osNoisyStripDiff << "Increase of #(noisy strips) from average of recent runs less than " << (int) m_noisyStripDiff; - - ostringstream osFlagReason; - if ( !isNoisyMinStat ) osFlagReason << "FAILED in " << osNoisyMinStat.str() << "; "; - if ( !isNoisyModuleList ) osFlagReason << "FAILED in " << osNoisyModuleList.str() << "; "; - if ( !isNoisyModuleDiff ) osFlagReason << "FAILED in " << osNoisyModuleDiff.str() << "; "; - if ( !isNoisyStripDiff ) osFlagReason << "FAILED in " << osNoisyStripDiff.str(); - - string strFlagEnable = m_noisyUploadTest ? "ENABLED" : "DISABLED"; - string strRunsInCool = isRunsInCool ? "AVAILABLE" : "UNAVAILABLE"; - - ostringstream osCheckList; - osCheckList << osNoisyMinStat.str() << "; " - << osNoisyModuleList.str() << "; " - << osNoisyModuleDiff.str() << "; " - << osNoisyStripDiff.str(); - - //--- Write out the contents to XML file - outFile << xmlHeader << linefeed - << associateStylesheet("BadStrips.xsl") << linefeed - << "<run>" << linefeed - << " <value name=\"RunNumber\">" << (int) m_runNumber << "</value>" << linefeed - << " <value name=\"StartTime\">" << m_utcBegin << "</value>" << linefeed - << " <value name=\"EndTime\">" << m_utcEnd << "</value>" << linefeed - << " <value name=\"Duration\">" << m_calibEvtInfoSvc->duration() << "</value>" << linefeed - << " <value name=\"LB\">" << m_numOfLBsProcessed << "</value>" << linefeed - << " <value name=\"Events\">" << m_numberOfEvents << "</value>" << linefeed - << " <value name=\"Modules\">" << numModulesAll << "</value>" << linefeed - << " <value name=\"Links\">" << numLinksAll << "</value>" << linefeed - << " <value name=\"Chips\">" << numChipsAll << "</value>" << linefeed - << " <value name=\"StripsOfflineAll\">" << numStripsAll << "</value>" << linefeed - << " <value name=\"StripsOfflineNew\">" << numStripsNew << "</value>" << linefeed - << " <value name=\"ModulesRef\">" << numModulesRef << "</value>" << linefeed - << " <value name=\"StripsOfflineRef\">" << numStripsRef << "</value>" << linefeed - << " <value name=\"ModulesDiff\">" << numModulesDiff << "</value>" << linefeed - << " <value name=\"Flag\">" << strUploadFlag << "</value>" << linefeed - << " <value name=\"FlagReason\">" << osFlagReason.str() << "</value>" << linefeed - << " <value name=\"FlagEnable\">" << strFlagEnable << "</value>" << linefeed - << " <value name=\"ReadCool\">" << strRunsInCool << "</value>" << linefeed - << " <value name=\"CheckList\">" << osCheckList.str() << "</value>" << linefeed - << " <chips>" << linefeed - << osChipList.str() - << " </chips>" << linefeed - << " <modules>" << linefeed - << osModuleList.str() - << " </modules>" << linefeed - << "</run>" << endl; - - return StatusCode::SUCCESS; + } + } + } + + //--- Upload test result to XML + ostringstream osNoisyMinStat, osNoisyModuleList, osNoisyModuleDiff, osNoisyStripDiff; + osNoisyMinStat << "#events more than " << (int) m_noisyMinStat; + osNoisyModuleList << "#(modules w/ at least 1 noisy strip) less than " << (int) m_noisyModuleList; + osNoisyModuleDiff << "Increase of #(modules w/ at least 1 noisy strip) from average of recent runs less than " << m_noisyModuleDiff*100 << "%"; + osNoisyStripDiff << "Increase of #(noisy strips) from average of recent runs less than " << (int) m_noisyStripDiff; + + ostringstream osFlagReason; + if ( !isNoisyMinStat ) osFlagReason << "FAILED in " << osNoisyMinStat.str() << "; "; + if ( !isNoisyModuleList ) osFlagReason << "FAILED in " << osNoisyModuleList.str() << "; "; + if ( !isNoisyModuleDiff ) osFlagReason << "FAILED in " << osNoisyModuleDiff.str() << "; "; + if ( !isNoisyStripDiff ) osFlagReason << "FAILED in " << osNoisyStripDiff.str(); + + string strFlagEnable = m_noisyUploadTest ? "ENABLED" : "DISABLED"; + string strRunsInCool = isRunsInCool ? "AVAILABLE" : "UNAVAILABLE"; + + ostringstream osCheckList; + osCheckList << osNoisyMinStat.str() << "; " + << osNoisyModuleList.str() << "; " + << osNoisyModuleDiff.str() << "; " + << osNoisyStripDiff.str(); + + //--- Write out the contents to XML file + outFile << xmlHeader << linefeed + << associateStylesheet("BadStrips.xsl") << linefeed + << "<run>" << linefeed + << " <value name=\"RunNumber\">" << (int) m_runNumber << "</value>" << linefeed + << " <value name=\"StartTime\">" << m_utcBegin << "</value>" << linefeed + << " <value name=\"EndTime\">" << m_utcEnd << "</value>" << linefeed + << " <value name=\"Duration\">" << m_calibEvtInfoTool->duration() << "</value>" << linefeed + << " <value name=\"LB\">" << m_numOfLBsProcessed << "</value>" << linefeed + << " <value name=\"Events\">" << m_numberOfEvents << "</value>" << linefeed + << " <value name=\"Modules\">" << numModulesAll << "</value>" << linefeed + << " <value name=\"Links\">" << numLinksAll << "</value>" << linefeed + << " <value name=\"Chips\">" << numChipsAll << "</value>" << linefeed + << " <value name=\"StripsOfflineAll\">" << numStripsAll << "</value>" << linefeed + << " <value name=\"StripsOfflineNew\">" << numStripsNew << "</value>" << linefeed + << " <value name=\"ModulesRef\">" << numModulesRef << "</value>" << linefeed + << " <value name=\"StripsOfflineRef\">" << numStripsRef << "</value>" << linefeed + << " <value name=\"ModulesDiff\">" << numModulesDiff << "</value>" << linefeed + << " <value name=\"Flag\">" << strUploadFlag << "</value>" << linefeed + << " <value name=\"FlagReason\">" << osFlagReason.str() << "</value>" << linefeed + << " <value name=\"FlagEnable\">" << strFlagEnable << "</value>" << linefeed + << " <value name=\"ReadCool\">" << strRunsInCool << "</value>" << linefeed + << " <value name=\"CheckList\">" << osCheckList.str() << "</value>" << linefeed + << " <chips>" << linefeed + << osChipList.str() + << " </chips>" << linefeed + << " <modules>" << linefeed + << osModuleList.str() + << " </modules>" << linefeed + << "</run>" << endl; + + return StatusCode::SUCCESS; } -// ////////////////// -// StatusCode SCTCalib::noisyStripsToSummaryXmlFake(const std::string& badStripsFile) const { -// //--- Open -// const char* outputFileName = badStripsFile.c_str(); -// ofstream outFile( outputFileName, std::ios::out ); -// if ( outFile == 0 ) { -// msg( MSG::ERROR ) << "Unable to open " << outputFileName << endmsg; -// return( StatusCode::FAILURE ); -// } - -// // //--- Initialization -// // int numLinksAll( 0 ), numChipsAll( 0 ); -// // int numModulesAll( 0 ), numModulesNew( 0 ), numModulesRef( 0 ); -// // int numStripsAll( 0 ), numStripsNew( 0 ), numStripsRef( 0 ); -// // int numModulesDiff( 0 ); - -// // std::string defectLinks, defectChips; -// // std::string defectStripsAll, defectStripsNew, defectStripsRef; -// // ostringstream osModuleList, osChipList; - -// // //--- Create module list -// // SCT_ID::const_id_iterator waferItr = m_pSCTHelper->wafer_begin(); -// // SCT_ID::const_id_iterator waferItrE = m_pSCTHelper->wafer_end(); -// // for( ; waferItr != waferItrE; ++waferItr ) { -// // //--- Identifier -// // Identifier waferId = *waferItr; -// // Identifier moduleId = m_pSCTHelper->module_id( waferId ); -// // IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); -// // SCT_SerialNumber sn = m_CablingTool->getSerialNumberFromHash( waferHash ); - -// // //--- Initialization for a module -// // if ( m_pSCTHelper->side( waferId ) == 0 ) { -// // defectLinks.erase(); -// // defectChips.erase(); -// // defectStripsAll.erase(); -// // defectStripsNew.erase(); -// // defectStripsRef.erase(); -// // } - -// // //--- Noisy links -// // bool isNoisyWafer = getNumNoisyStrips( waferId ).second; // true if this wafer is noisy -// // if ( isNoisyWafer ) { -// // int link = m_pSCTHelper->side( waferId ); -// // defectLinks = m_pCalibWriteSvc->addDefect( defectLinks, link, link ); -// // ++numLinksAll; -// // } - -// // //--- Execute once in this module -// // if ( m_pSCTHelper->side( waferId ) == 1 ) { -// // //--- Noisy strips : All -// // map< Identifier, std::set<Identifier> >::const_iterator moduleAllItr = moduleListAll.find( moduleId ); -// // if ( moduleAllItr != moduleListAll.end() ) { -// // defectStripsAll = getStripList( (*moduleAllItr).second ); -// // ++numModulesAll; -// // numStripsAll += (*moduleAllItr).second.size(); -// // } -// // //--- Noisy strips : New -// // map< Identifier, std::set<Identifier> >::const_iterator moduleNewItr = moduleListNew.find( moduleId ); -// // if ( moduleNewItr != moduleListNew.end() ) { -// // defectStripsNew = getStripList( (*moduleNewItr).second ); -// // ++numModulesNew; -// // numStripsNew += (*moduleNewItr).second.size(); -// // } -// // //--- Noisy strips : Ref -// // map< Identifier, std::set<Identifier> >::const_iterator moduleRefItr = moduleListRef.find( moduleId ); -// // if ( moduleRefItr != moduleListRef.end() ) { -// // defectStripsRef = getStripList( moduleRefItr->second ); -// // ++numModulesRef; -// // numStripsRef += moduleRefItr->second.size(); -// // } - -// // //--- Noisy chips : stripIdList -> chipIdList -// // if ( moduleAllItr != moduleListAll.end() ) { -// // std::set<int> chipIdList = getNoisyChips( moduleAllItr->second ); -// // if ( !chipIdList.empty() ) { -// // std::set<int>::iterator chipItr = chipIdList.begin(); -// // std::set<int>::iterator chipItrE = chipIdList.end(); -// // for ( ; chipItr != chipItrE; ++chipItr ) { -// // int chipId = *chipItr; -// // //--- To be written into module list -// // defectChips = m_pCalibWriteSvc->addDefect( defectChips, chipId, chipId ); -// // //--- LBs where this chip was noisy -// // std::pair< string, float > defectLB = getNoisyLB( moduleId, chipId ); -// // //--- Chip list written to XML -// // osChipList << " <chip>" << linefeed -// // << " <value name=\"SN\">" << sn.str() << "</value>" << linefeed -// // << " <value name=\"BecLayerPhiEta\">" << m_pSCTHelper->barrel_ec( waferId ) << "." -// // << m_pSCTHelper->layer_disk( waferId ) << "." -// // << m_pSCTHelper->phi_module( waferId ) << "." -// // << m_pSCTHelper->eta_module( waferId ) << "</value>" << linefeed -// // << " <value name=\"ChipID\">" << chipId << "</value>" << linefeed -// // << " <value name=\"LB\">" << normalizeList( defectLB.first ) << "</value>" << linefeed -// // << " <value name=\"LBFraction\">" << defectLB.second << "</value>" << linefeed -// // << " </chip>" << endl; -// // } -// // } -// // } -// // //--- Difference between All & Ref -// // if ( defectStripsAll != defectStripsRef ) ++numModulesDiff; -// // //--- Module list written to XML -// // if ( !defectStripsAll.empty() || ( m_noisyUpdate && defectStripsAll != defectStripsRef ) ) { -// // osModuleList << " <module>" << linefeed -// // << " <value name=\"SN\">" << sn.str() << "</value>" << linefeed -// // << " <value name=\"BecLayerPhiEta\">" << m_pSCTHelper->barrel_ec( waferId ) << "." -// // << m_pSCTHelper->layer_disk( waferId ) << "." -// // << m_pSCTHelper->phi_module( waferId ) << "." -// // << m_pSCTHelper->eta_module( waferId ) << "</value>" << linefeed -// // << " <value name=\"LinkID\">" << normalizeList( defectLinks ) << "</value>" << linefeed -// // << " <value name=\"ChipID\">" << normalizeList( defectChips ) << "</value>" << linefeed -// // << " <value name=\"StripOfflineAll\">" << normalizeList( defectStripsAll ) << "</value>" << linefeed -// // << " <value name=\"StripOfflineNew\">" << normalizeList( defectStripsNew ) << "</value>" << linefeed -// // << " <value name=\"StripOfflineRef\">" << normalizeList( defectStripsRef ) << "</value>" << linefeed -// // << " </module>" << endl; -// // } -// // } -// // }//--- end loop : waferItr - -// // //--- Upload flag -// // string strUploadFlag = "U"; - -// // bool isRunsInCool( false ); -// // bool isNoisyMinStat( false ), isNoisyModuleList( false ), isNoisyModuleDiff( false ), isNoisyStripDiff( false ); -// // if ( m_noisyUploadTest ) { -// // isRunsInCool = m_noisyModuleAverageInDB != -1. && m_noisyStripLastRunInDB != -999; -// // if ( isRunsInCool ) { -// // isNoisyMinStat = m_numberOfEvents > m_noisyMinStat; -// // isNoisyModuleList = numModulesAll < m_noisyModuleList; -// // isNoisyModuleDiff = fabs( ( (float) numModulesAll - m_noisyModuleAverageInDB )/m_noisyModuleAverageInDB ) < m_noisyModuleDiff; -// // isNoisyStripDiff = fabs( numStripsAll - m_noisyStripLastRunInDB ) < m_noisyStripDiff; -// // if ( !isNoisyMinStat || !isNoisyModuleList ) { -// // strUploadFlag = "R"; -// // } else { -// // if ( !isNoisyModuleDiff || !isNoisyStripDiff ) { -// // strUploadFlag = "Y"; -// // } else { -// // strUploadFlag = "G"; -// // } -// // } -// // } -// // } - -// bool isRunsInCool( false ); -// if ( m_noisyUploadTest ) -// isRunsInCool = m_noisyModuleAverageInDB != -1. && m_noisyStripLastRunInDB != -999; - -// //--- Upload test result to XML -// ostringstream osNoisyZeroEvents; -// osNoisyZeroEvents << "Noisy strips tried to run over empty hitmaps. Prevented and gracefully exited"; -// string strUploadFlag = "R"; -// ostringstream osFlagReason; -// osFlagReason << " "; -// // if ( !isNoisyMinStat ) osFlagReason << "FAILED in " << osNoisyMinStat.str() << "; "; -// // if ( !isNoisyModuleList ) osFlagReason << "FAILED in " << osNoisyModuleList.str() << "; "; -// // if ( !isNoisyModuleDiff ) osFlagReason << "FAILED in " << osNoisyModuleDiff.str() << "; "; -// // if ( !isNoisyStripDiff ) osFlagReason << "FAILED in " << osNoisyStripDiff.str(); - -// string strFlagEnable = m_noisyUploadTest ? "ENABLED" : "DISABLED"; -// string strRunsInCool = isRunsInCool ? "AVAILABLE" : "UNAVAILABLE"; - -// ostringstream osCheckList; -// osCheckList << osNoisyZeroEvents.str(); - -// //--- Write out the contents to XML file -// outFile << xmlHeader << linefeed -// << associateStylesheet("BadStrips.xsl") << linefeed -// << "<run>" << linefeed -// << " <value name=\"RunNumber\">" << (int) m_runNumber << "</value>" << linefeed -// << " <value name=\"StartTime\">" << m_utcBegin << "</value>" << linefeed -// << " <value name=\"EndTime\">" << m_utcEnd << "</value>" << linefeed -// << " <value name=\"Duration\">" << m_calibEvtInfoSvc->duration() << "</value>" << linefeed -// << " <value name=\"LB\">" << m_numOfLBsProcessed << "</value>" << linefeed -// << " <value name=\"Events\">" << m_numberOfEvents << "</value>" << linefeed -// << " <value name=\"Modules\">" << 0 << "</value>" << linefeed -// << " <value name=\"Links\">" << 0 << "</value>" << linefeed -// << " <value name=\"Chips\">" << 0 << "</value>" << linefeed -// << " <value name=\"StripsOfflineAll\">" << 0 << "</value>" << linefeed -// << " <value name=\"StripsOfflineNew\">" << 0 << "</value>" << linefeed -// << " <value name=\"ModulesRef\">" << 0 << "</value>" << linefeed -// << " <value name=\"StripsOfflineRef\">" << 0 << "</value>" << linefeed -// << " <value name=\"ModulesDiff\">" << 0 << "</value>" << linefeed -// << " <value name=\"Flag\">" << strUploadFlag << "</value>" << linefeed -// << " <value name=\"FlagReason\">" << osFlagReason.str() << "</value>" << linefeed -// << " <value name=\"FlagEnable\">" << strFlagEnable << "</value>" << linefeed -// << " <value name=\"ReadCool\">" << strRunsInCool << "</value>" << linefeed -// << " <value name=\"CheckList\">" << osCheckList.str() << "</value>" << linefeed -// << "</run>" << endl; - -// return StatusCode::SUCCESS; -// } - - std::set<int> SCTCalib::getNoisyChips( const std::set<Identifier>& stripIdList ) const { - std::set<int> chipIdList; - chipIdList.clear(); - - // Get SCT_DetectorElementCollection - SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEle(m_SCTDetEleCollKey); - const InDetDD::SiDetectorElementCollection* elements(sctDetEle.retrieve()); - if (elements==nullptr) { - ATH_MSG_FATAL(m_SCTDetEleCollKey.fullKey() << " could not be retrieved"); - return chipIdList; - } - - //--- Minimum number of noisy strips for a noisy chip - unsigned int noisyChipThr = m_noisyChipFraction*n_stripPerChip; - if ( stripIdList.size() > noisyChipThr ) { - unsigned int numStripsPerChip[ n_chipPerModule ] = { 0 }; - //--- Loop over stripIdList - std::set<Identifier>::const_iterator stripItr = stripIdList.begin(); - std::set<Identifier>::const_iterator stripItrE = stripIdList.end(); - for ( ; stripItr != stripItrE; ++stripItr ) { - Identifier stripId = *stripItr; - int stripOffline = m_pSCTHelper->strip( stripId ); - //--- Chip number : taken from SCT_ConfigurationConditionsSvc::getChip - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( m_pSCTHelper->wafer_id( stripId ) ); - const InDetDD::SiDetectorElement* pElement = elements->getDetectorElement( waferHash ); - if ( !pElement ) { - msg( MSG::FATAL ) << "Element pointer is NULL" << endmsg; - continue; - } - int stripOnline = ( pElement->swapPhiReadoutDirection() ) ? lastStrip - stripOffline : stripOffline; - int chipId = m_pSCTHelper->side( stripId ) == 0 ? stripOnline/n_stripPerChip : stripOnline/n_stripPerChip + n_chipPerSide; - //--- Count number of noisy strips per chips - ++numStripsPerChip[ chipId ]; - } - - //--- Insert noisy chips - for ( int iChip = 0; iChip != n_chipPerModule; ++iChip ) { - if ( numStripsPerChip[iChip] > noisyChipThr ) chipIdList.insert( iChip ); - } - } - return chipIdList; + std::set<int> chipIdList; + chipIdList.clear(); + + // Get SCT_DetectorElementCollection + SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEle(m_SCTDetEleCollKey); + const InDetDD::SiDetectorElementCollection* elements(sctDetEle.retrieve()); + if (elements==nullptr) { + ATH_MSG_FATAL(m_SCTDetEleCollKey.fullKey() << " could not be retrieved"); + return chipIdList; + } + + //--- Minimum number of noisy strips for a noisy chip + unsigned int noisyChipThr = m_noisyChipFraction*n_stripPerChip; + if ( stripIdList.size() > noisyChipThr ) { + unsigned int numStripsPerChip[ n_chipPerModule ] = { 0 }; + //--- Loop over stripIdList + std::set<Identifier>::const_iterator stripItr = stripIdList.begin(); + std::set<Identifier>::const_iterator stripItrE = stripIdList.end(); + for ( ; stripItr != stripItrE; ++stripItr ) { + Identifier stripId = *stripItr; + int stripOffline = m_pSCTHelper->strip( stripId ); + //--- Chip number : taken from SCT_ConfigurationConditionsSvc::getChip + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( m_pSCTHelper->wafer_id( stripId ) ); + const InDetDD::SiDetectorElement* pElement = elements->getDetectorElement( waferHash ); + if ( !pElement ) { + msg( MSG::FATAL ) << "Element pointer is NULL" << endmsg; + continue; + } + int stripOnline = ( pElement->swapPhiReadoutDirection() ) ? lastStrip - stripOffline : stripOffline; + int chipId = m_pSCTHelper->side( stripId ) == 0 ? stripOnline/n_stripPerChip : stripOnline/n_stripPerChip + n_chipPerSide; + //--- Count number of noisy strips per chips + ++numStripsPerChip[ chipId ]; + } + + //--- Insert noisy chips + for ( int iChip = 0; iChip != n_chipPerModule; ++iChip ) { + if ( numStripsPerChip[iChip] > noisyChipThr ) chipIdList.insert( iChip ); + } + } + return chipIdList; } std::pair< string, float > SCTCalib::getNoisyLB( const Identifier& moduleId, int& chipId ) const { - std::string defectLB(""); //return value if invalid - float defectLBFrac(0.0); //return value if invalid - float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); - - //--- Identifier - Identifier waferId = m_pSCTHelper->wafer_id( m_pSCTHelper->barrel_ec( moduleId ), - m_pSCTHelper->layer_disk( moduleId ), - m_pSCTHelper->phi_module( moduleId ), - m_pSCTHelper->eta_module( moduleId ), - chipId < n_chipPerSide ? 0 : 1 ); - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - //--- Histogram for this chip - int chipPositionInSide = m_pSCTHelper->side( waferId ) == 0 ? chipId : chipId - n_chipPerSide; - int histIndex = ((int)waferHash)*n_chipPerSide + chipPositionInSide; - - //--- Find LBs where this chip was noisy - double chipOccupancyThr = noisyStripThr*n_stripPerChip*m_noisyChipFraction; - std::set<int> LBList; - LBList.clear(); - if (!m_calibLbSvc) { - msg( MSG::ERROR ) << "NULL pointer m_calibLbSvc line "<<__LINE__ << endmsg; - return std::make_pair( defectLB, defectLBFrac ); - } - - for ( int iLB = 0; iLB != m_LBRange; ++iLB ) { - double numEventsInLB = m_calibLbSvc->getNumberOfEventsInBin( iLB + 1 ); - if ( numEventsInLB == 0 ) continue; - double chipOccupancy = m_calibLbSvc->getBinForHistogramIndex( iLB + 1, histIndex )/numEventsInLB; - if ( chipOccupancy > chipOccupancyThr ) LBList.insert( iLB ); - } - //--- Transform LBList to string and calculate a fraction of noisy LBs - if ( LBList.size() != 0 ) { - defectLB = getLBList( LBList ); - defectLBFrac = (float) LBList.size() / m_numOfLBsProcessed; - } - - return std::make_pair( defectLB, defectLBFrac ); + std::string defectLB(""); //return value if invalid + float defectLBFrac(0.0); //return value if invalid + float noisyStripThr = m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline); + + //--- Identifier + Identifier waferId = m_pSCTHelper->wafer_id( m_pSCTHelper->barrel_ec( moduleId ), + m_pSCTHelper->layer_disk( moduleId ), + m_pSCTHelper->phi_module( moduleId ), + m_pSCTHelper->eta_module( moduleId ), + chipId < n_chipPerSide ? 0 : 1 ); + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + //--- Histogram for this chip + int chipPositionInSide = m_pSCTHelper->side( waferId ) == 0 ? chipId : chipId - n_chipPerSide; + int histIndex = ((int)waferHash)*n_chipPerSide + chipPositionInSide; + + //--- Find LBs where this chip was noisy + double chipOccupancyThr = noisyStripThr*n_stripPerChip*m_noisyChipFraction; + std::set<int> LBList; + LBList.clear(); + if (!m_calibLbTool) { + msg( MSG::ERROR ) << "NULL pointer m_calibLbTool line "<<__LINE__ << endmsg; + return std::make_pair( defectLB, defectLBFrac ); + } + + for ( int iLB = 0; iLB != m_LBRange; ++iLB ) { + double numEventsInLB = m_calibLbTool->getNumberOfEventsInBin( iLB + 1 ); + if ( numEventsInLB == 0 ) continue; + double chipOccupancy = m_calibLbTool->getBinForHistogramIndex( iLB + 1, histIndex )/numEventsInLB; + if ( chipOccupancy > chipOccupancyThr ) LBList.insert( iLB ); + } + //--- Transform LBList to string and calculate a fraction of noisy LBs + if ( LBList.size() != 0 ) { + defectLB = getLBList( LBList ); + defectLBFrac = (float) LBList.size() / m_numOfLBsProcessed; + } + + return std::make_pair( defectLB, defectLBFrac ); } std::string SCTCalib::getLBList( const std::set<int>& LBList ) const { - std::string strList; - strList.erase(); - if ( !LBList.empty() ) { - int firstLB = -1; - int LBSize = -1; - - std::set<int>::const_iterator LBItrFirst = LBList.begin(); - std::set<int>::const_iterator LBItrLast = --LBList.end(); - - std::set<int>::const_iterator LBItr = LBList.begin(); - std::set<int>::const_iterator LBItrE = LBList.end(); - for ( ; LBItr != LBItrE; ++LBItr ) { - int iLB = *LBItr; - if ( LBItr == LBItrFirst ) { - firstLB = iLB; - LBSize = 1; + std::string strList; + strList.erase(); + if ( !LBList.empty() ) { + int firstLB = -1; + int LBSize = -1; + + std::set<int>::const_iterator LBItrFirst = LBList.begin(); + std::set<int>::const_iterator LBItrLast = --LBList.end(); + + std::set<int>::const_iterator LBItr = LBList.begin(); + std::set<int>::const_iterator LBItrE = LBList.end(); + for ( ; LBItr != LBItrE; ++LBItr ) { + int iLB = *LBItr; + if ( LBItr == LBItrFirst ) { + firstLB = iLB; + LBSize = 1; + } else { + if ( iLB == firstLB + LBSize ) { + ++LBSize; } else { - if ( iLB == firstLB + LBSize ) { - ++LBSize; - } else { - int LBBegin = firstLB; - int LBEnd = firstLB + LBSize -1; - strList = m_pCalibWriteSvc->addDefect( strList, LBBegin, LBEnd ); - firstLB = iLB; - LBSize = 1; - } - } - if ( LBItr == LBItrLast ) { - int LBBegin = firstLB; - int LBEnd = iLB; - strList = m_pCalibWriteSvc->addDefect( strList, LBBegin, LBEnd ); + int LBBegin = firstLB; + int LBEnd = firstLB + LBSize -1; + strList = m_pCalibWriteTool->addDefect( strList, LBBegin, LBEnd ); + firstLB = iLB; + LBSize = 1; } - } - } - return strList; + } + if ( LBItr == LBItrLast ) { + int LBBegin = firstLB; + int LBEnd = iLB; + strList = m_pCalibWriteTool->addDefect( strList, LBBegin, LBEnd ); + } + } + } + return strList; } - - - - diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteSvc.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteSvc.cxx deleted file mode 100644 index b8938c63a34981e345e6281b9c81ff12b04de5b2..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteSvc.cxx +++ /dev/null @@ -1,752 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file SCTCalibWriteSvc.cxx - * - * @brief Implementation file for uploading to DB on CAF - * - * @author Jose E. Garcia - **/ -#include "SCT_CalibAlgs/SCTCalibWriteSvc.h" - -// IOVDbTest includes -#include "RegistrationServices/IIOVRegistrationSvc.h" - -// Gaudi includes -#include "GaudiKernel/StatusCode.h" -//#include "GaudiKernel/IToolSvc.h" - -// Athena includes -#include "AthenaKernel/IAthenaOutputStreamTool.h" -#include "CoralBase/Attribute.h" - -#include "AthenaPoolUtilities/CondAttrListCollection.h" -#include "Identifier/IdentifierHash.h" -#include "InDetIdentifier/SCT_ID.h" - -// Event Info -#include "EventInfo/EventInfo.h" -#include "EventInfo/EventID.h" -#include "EventInfo/EventType.h" - -//path resolver to find the file -#include "PathResolver/PathResolver.h" - -#include <fstream> -#include <iterator> -#include <sstream> -#include <iostream> -#include <istream> -#include <boost/lexical_cast.hpp> - -using std::string; -///////////////////////////////////////////////////////////////////////////// -string SCTCalibWriteSvc::s_separator = string("-"); -string SCTCalibWriteSvc::s_defectFolderName = string("/SCT/Derived/Monitoring"); -string SCTCalibWriteSvc::s_deadStripFolderName = string("/SCT/Derived/DeadStrips"); -string SCTCalibWriteSvc::s_deadChipFolderName = string("/SCT/Derived/DeadChips"); -string SCTCalibWriteSvc::s_effFolderName = string("/SCT/Derived/Efficiency"); -string SCTCalibWriteSvc::s_noFolderName = string("/SCT/Derived/NoiseOccupancy"); -string SCTCalibWriteSvc::s_RawOccuFolderName = string("/SCT/Derived/RawOccupancy"); -string SCTCalibWriteSvc::s_BSErrFolderName = string("/SCT/Derived/BSErrorsRun2"); -string SCTCalibWriteSvc::s_LAFolderName = string("/SCT/Derived/LorentzAngleRun2_v2"); - -static bool becCapsFormat(true); -static bool becUnderscoreFormat(false); - -SCTCalibWriteSvc::SCTCalibWriteSvc(const std::string& name, ISvcLocator* pSvcLocator ) : - AthService(name, pSvcLocator), - m_detStore(0), - m_eventInfoKey(std::string("ByteStreamEventInfo")), - m_attrListColl(0), - m_attrListColl_deadStrip(0), - m_attrListColl_deadChip(0), - m_attrListColl_eff(0), - m_attrListColl_no(0), - m_attrListColl_RawOccu(0), - m_attrListColl_BSErr(0), - m_attrListColl_LA(0), - //boolean properties - m_writeCondObjs(true), - m_regIOV(true), - m_readWriteCool(true), - m_twoStepWriteReg(false), - m_manualiov(true), - // - /*m_regTime(0), never used */ - m_version(0), - m_beginRun(IOVTime::MINRUN), - m_endRun(IOVTime::MAXRUN), - m_streamName("CondStreamTest"), - - - m_regSvc(0), - //m_streamer(0), - m_streamer("AthenaOutputStreamTool", this), - m_badIds(), - - m_defectRecorded(false), - m_deadStripRecorded(false), - m_deadChipRecorded(false), - m_effRecorded(false), - m_noRecorded(false), - m_RawOccuRecorded(false), - m_BSErrRecorded(false), - m_LARecorded(false), - m_pHelper(0), - m_currentDefectList("") -{ - declareProperty("WriteCondObjs", m_writeCondObjs); - declareProperty("RegisterIOV", m_regIOV); - declareProperty("ReadWriteCool", m_readWriteCool); - declareProperty("TwoStepWriteReg", m_twoStepWriteReg); - declareProperty("ManualIOV", m_manualiov); - //declareProperty("RegTime", m_regTime); never used Register time in sec - - declareProperty("BeginRun", m_beginRun); - declareProperty("EndRun", m_endRun); - //string properties: - declareProperty("StreamName", m_streamName); - declareProperty("TagID4NoisyStrips", m_tagID4NoisyStrips); - declareProperty("TagID4DeadStrips", m_tagID4DeadStrips); - declareProperty("TagID4DeadChips", m_tagID4DeadChips); - declareProperty("TagID4Efficiency", m_tagID4Efficiency); - declareProperty("TagID4NoiseOccupancy", m_tagID4NoiseOccupancy); - declareProperty("TagID4RawOccupancy", m_tagID4RawOccupancy); - declareProperty("TagID4BSErrors", m_tagID4BSErrors); - declareProperty("TagID4LorentzAngle", m_tagID4LorentzAngle); - -} - -/////////////////////////////////////////////////////////////////////////////////////////// - -SCTCalibWriteSvc::~SCTCalibWriteSvc() -{ } - -/////////////////////////////////////////////////////////////////////////////////////////// - -StatusCode SCTCalibWriteSvc::initialize(){ - StatusCode sc = service("DetectorStore", m_detStore); - if ( !sc.isSuccess() || 0 == m_detStore) return msg(MSG:: ERROR) << "Could not find DetStore" << endmsg, StatusCode::FAILURE; - if (m_detStore->retrieve(m_pHelper,"SCT_ID").isFailure()) return msg(MSG:: ERROR) << "SCT mgr failed to retrieve" << endmsg, StatusCode::FAILURE; - - ATH_CHECK(m_eventInfoKey.initialize()); - - // ------------------------------------------------------------ - // The following is required for writing out something to COOL - - // CondAttrListCollection to store table temporarily - m_attrListColl = new CondAttrListCollection(true); - m_attrListColl_deadStrip = new CondAttrListCollection(true); - m_attrListColl_deadChip = new CondAttrListCollection(true); - m_attrListColl_eff = new CondAttrListCollection(true); - m_attrListColl_no = new CondAttrListCollection(true); - m_attrListColl_RawOccu = new CondAttrListCollection(true); - m_attrListColl_BSErr = new CondAttrListCollection(true); - m_attrListColl_LA = new CondAttrListCollection(true); - - // Get the IOVRegistrationSvc when needed - if (m_regIOV) { - if (service("IOVRegistrationSvc", m_regSvc).isFailure()) return msg(MSG:: ERROR)<< "Unable to find IOVRegistrationSvc "<< endmsg, StatusCode::FAILURE; - } - return StatusCode::SUCCESS; -} - -////////////////////////////////////////////////////////////////////////////////////////// -StatusCode SCTCalibWriteSvc::finalize(){ - if (!m_defectRecorded) delete m_attrListColl; - if (!m_deadStripRecorded) delete m_attrListColl_deadStrip; - if (!m_deadChipRecorded) delete m_attrListColl_deadChip; - if (!m_effRecorded) delete m_attrListColl_eff; - if (!m_noRecorded) delete m_attrListColl_no; - if (!m_RawOccuRecorded) delete m_attrListColl_RawOccu; - if (!m_BSErrRecorded) delete m_attrListColl_BSErr; - if (!m_LARecorded) delete m_attrListColl_LA; - return StatusCode::SUCCESS; -} - -////////////////////////////////////////////////////////////////////////////////////////// - -StatusCode SCTCalibWriteSvc::queryInterface(const InterfaceID& riid, void** ppvIF) -{ - if(SCTCalibWriteSvc::interfaceID().versionMatch(riid) ){ - *ppvIF = (SCTCalibWriteSvc*)this; - } else{ - return AthService::queryInterface(riid, ppvIF); - } - return StatusCode::SUCCESS; -} - -////////////////////////////////////////////////////////////////////////////////////////// - -unsigned int -SCTCalibWriteSvc::computeIstrip4moncond(const Identifier& elementId) const { - unsigned int iiside = m_pHelper->side(elementId); - unsigned int iistrip = m_pHelper->strip(elementId); - return 768*iiside + iistrip; -} - -StatusCode -SCTCalibWriteSvc::fillData(){ - // this is a dummy function - return StatusCode::SUCCESS; -} - - -////////////////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////////////////// -// Local stuff -////////////////////////////////////////////////////////////////////////////////////////// - -string -SCTCalibWriteSvc::addDefect(const string& defectlist,const int defectBeginChannel,const int defectEndChannel) const{ - // check size of defect list, - // if it is empty then use createDefectString to make first entry. - if (defectlist.empty()) return createDefectString(defectBeginChannel,defectEndChannel); - - // adding another Defect in DefectList - std::ostringstream defect; - defect << defectlist << " " << defectBeginChannel; - if (defectBeginChannel==defectEndChannel){ - defect << " "; - } else { - defect << "-" << defectEndChannel << " "; - } - return defect.str(); -} - -/////////////////////////////////////////////////////////////////////////////////////// -std::string -SCTCalibWriteSvc::createDefectString(const int defectBeginChannel,const int defectEndChannel) const{ - std::ostringstream defect; - defect << " " << defectBeginChannel; - if (defectBeginChannel!=defectEndChannel) { - defect << "-" << defectEndChannel; - } - defect << " "; - return defect.str(); -} - - -/////////////////////////////////////////////////////////////////////////////////////// - -std::string -SCTCalibWriteSvc::addNumber(const string numStr,const unsigned long long number) const{ - std::ostringstream num_string; - // if it is empty then use createDefectString to make first entry. - if (numStr.empty()){ - num_string << number; - }else{ // adding another number to numStr - num_string << numStr << " " << number; - } - return num_string.str(); -} - -///////////////////////////////////////////////////////////////////////////////////////////// -StatusCode SCTCalibWriteSvc::createCondObjects(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize, - const std::string & defectType,const float threshold,const std::string & defectList) const{ - if (!m_writeCondObjs) {return StatusCode::SUCCESS;} - coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becCapsFormat); - attrSpec->extend("DefectType","string"); - attrSpec->extend("Threshold","float"); - attrSpec->extend("DefectList","string"); - - if (!attrSpec->size()) { - msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; - return StatusCode::FAILURE; - } - - coral::AttributeList attrList0(*attrSpec); - setBasicValues(attrList0, wafer_id, samplesize,sctId,becCapsFormat); - attrList0["DefectType"].setValue(static_cast<std::string>(defectType)); - attrList0["Threshold"].setValue(static_cast<float>(threshold)); - attrList0["DefectList"].setValue(static_cast<std::string>(defectList)); - std::ostringstream attrStr2; - attrList0.toOutputStream( attrStr2 ); - m_attrListColl->add(wafer_id.get_identifier32().get_compact(), attrList0); - return StatusCode::SUCCESS; -} - -//////////////////////////////////////////////////////////////////////////////// - -StatusCode SCTCalibWriteSvc::createListStrip(const Identifier& wafer_id, - const SCT_ID* sctId, - const int samplesize, - const std::string & defectType, - const float threshold, - const std::string & defectList) const -{ - if (!m_writeCondObjs) {return StatusCode::SUCCESS;} - coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becCapsFormat); - attrSpec->extend("DefectType","string"); - attrSpec->extend("Threshold","float"); - attrSpec->extend("DefectList","string"); - - if (!attrSpec->size()) { - msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; - return StatusCode::FAILURE; - } - - coral::AttributeList attrList0(*attrSpec); - setBasicValues(attrList0, wafer_id, samplesize,sctId, becCapsFormat); - attrList0["DefectType"].setValue(static_cast<std::string>(defectType)); - attrList0["Threshold"].setValue(static_cast<float>(threshold)); - attrList0["DefectList"].setValue(static_cast<std::string>(defectList)); - - std::ostringstream attrStr2; - attrList0.toOutputStream( attrStr2 ); - m_attrListColl_deadStrip->add(wafer_id.get_identifier32().get_compact(), attrList0); - msg(MSG::INFO)<<"createListStrip: return StatusCode::SUCCESS"<<endmsg; - return StatusCode::SUCCESS; -} - -//////////////////////////////////////////////////////////////////////////////// - -StatusCode SCTCalibWriteSvc::createListChip(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const std::string & defectType,const float threshold,const std::string & defectList) const{ - if (!m_writeCondObjs) {return StatusCode::SUCCESS;} - coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becCapsFormat); - attrSpec->extend("DefectType","string"); - attrSpec->extend("Threshold","float"); - attrSpec->extend("DefectList","string"); - if (!attrSpec->size()) { - msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; - return StatusCode::FAILURE; - } - - // Add three attr lists - coral::AttributeList attrList0(*attrSpec); - setBasicValues(attrList0, wafer_id, samplesize,sctId, becCapsFormat); - attrList0["DefectType"].setValue(static_cast<std::string>(defectType)); - attrList0["Threshold"].setValue(static_cast<float>(threshold)); - attrList0["DefectList"].setValue(static_cast<std::string>(defectList)); - - std::ostringstream attrStr2; - attrList0.toOutputStream( attrStr2 ); - m_attrListColl_deadChip->add(wafer_id.get_identifier32().get_compact(), attrList0); - - return StatusCode::SUCCESS; -} - -//////////////////////////////////////////////////////////////////////////////// - -StatusCode SCTCalibWriteSvc::createListEff(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const float eff) const { - if(!m_writeCondObjs) {return StatusCode::SUCCESS;} - - coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becUnderscoreFormat); - attrSpec->extend("Efficiency", "float"); - if (!attrSpec->size()) { - msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; - return(StatusCode::FAILURE); - } - - coral::AttributeList attrList0(*attrSpec); - setBasicValues(attrList0, wafer_id, samplesize,sctId,becUnderscoreFormat); - attrList0["Efficiency"].setValue(static_cast<float>(eff)); - - std::ostringstream attrStr2; - attrList0.toOutputStream(attrStr2); - m_attrListColl_eff->add(wafer_id.get_identifier32().get_compact(), attrList0); - - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////// - -StatusCode SCTCalibWriteSvc::createListNO(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const float noise_occ) const { - if (!m_writeCondObjs) {return StatusCode::SUCCESS;} - coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becUnderscoreFormat); - attrSpec->extend("NoiseOccupancy", "float"); - if (!attrSpec->size()) { - msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; - return StatusCode::FAILURE; - } - // Add three attr lists - coral::AttributeList attrList0(*attrSpec); - setBasicValues(attrList0, wafer_id, samplesize,sctId,becUnderscoreFormat); - attrList0["NoiseOccupancy"].setValue(static_cast<float>(noise_occ)); - std::ostringstream attrStr2; - attrList0.toOutputStream(attrStr2); - m_attrListColl_no->add(wafer_id.get_identifier32().get_compact(), attrList0); - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////// - -StatusCode -SCTCalibWriteSvc::createListRawOccu(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const float raw_occu) const { - if (!m_writeCondObjs) {return StatusCode::SUCCESS;} - coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becUnderscoreFormat); - attrSpec->extend("RawOccupancy", "float"); - if (!attrSpec->size()) { - msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; - return StatusCode::FAILURE; - } - // Add three attr lists - coral::AttributeList attrList0(*attrSpec); - setBasicValues(attrList0, wafer_id, samplesize, sctId,becUnderscoreFormat); - attrList0["RawOccupancy"].setValue(static_cast<float>(raw_occu)); - std::ostringstream attrStr2; - attrList0.toOutputStream(attrStr2); - m_attrListColl_RawOccu->add(wafer_id.get_identifier32().get_compact(), attrList0); - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////// - -StatusCode -SCTCalibWriteSvc::createListBSErr(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const std::string & errorList,const std::string & probList) const { - if (!m_writeCondObjs) {return StatusCode::SUCCESS;} - - - int eta = sctId->eta_module(wafer_id); - int phi = sctId->phi_module(wafer_id); - int barrel_ec = sctId->barrel_ec(wafer_id); - int layer = sctId->layer_disk(wafer_id); - - coral::AttributeListSpecification* attrSpec = - new coral::AttributeListSpecification(); - attrSpec->extend("SampleSize", "int"); - attrSpec->extend("barrel_endcap", "int"); - attrSpec->extend("Layer", "int"); - attrSpec->extend("Eta", "int"); - attrSpec->extend("Phi", "int"); - attrSpec->extend("BSErrors", "string"); - attrSpec->extend("BadFraction", "string"); - - if (!attrSpec->size()) { - msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; - return StatusCode::FAILURE; - } - - // Add three attr lists - coral::AttributeList attrList0(*attrSpec); - attrList0["SampleSize"].setValue(static_cast<int>(samplesize)); - attrList0["barrel_endcap"].setValue(static_cast<int>(barrel_ec)); - attrList0["Layer"].setValue(static_cast<int>(layer)); - attrList0["Phi"].setValue(static_cast<int>(phi)); - attrList0["Eta"].setValue(static_cast<int>(eta)); - attrList0["BSErrors"].setValue(static_cast<std::string>(errorList)); - attrList0["BadFraction"].setValue(static_cast<std::string>(probList)); - - - std::ostringstream attrStr2; - attrList0.toOutputStream(attrStr2); - m_attrListColl_BSErr->add(wafer_id.get_identifier32().get_compact(), attrList0); - return StatusCode::SUCCESS; -} - - -StatusCode -SCTCalibWriteSvc::createListLA(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,int module, const float lorentz, const float err_lorentz, const float chisq, const float fitParam_a, const float err_a, const float fitParam_b, const float err_b, const float fitParam_sigma, const float err_sigma, const float MCW, const float err_MCW ) const { - if (!m_writeCondObjs) return StatusCode::SUCCESS; - int barrel_ec = sctId->barrel_ec(wafer_id); - int layer = sctId->layer_disk(wafer_id); - int side = sctId->side(wafer_id); - - coral::AttributeListSpecification* attrSpec =new coral::AttributeListSpecification(); - attrSpec->extend("SampleSize", "int"); - attrSpec->extend("barrel_endcap", "int"); - attrSpec->extend("Layer", "int"); - attrSpec->extend("Side", "int"); - attrSpec->extend("moduleType", "int"); - attrSpec->extend("lorentzAngle", "float"); - attrSpec->extend("err_lorentzAngle", "float"); - attrSpec->extend("chisq", "float"); - attrSpec->extend("fitParam_a", "float"); - attrSpec->extend("err_a", "float"); - attrSpec->extend("fitParam_b", "float"); - attrSpec->extend("err_b", "float"); - attrSpec->extend("fitParam_sigma", "float"); - attrSpec->extend("err_sigma", "float"); - attrSpec->extend("minClusterWidth", "float"); - attrSpec->extend("err_minClusterWidth", "float"); - - if (!attrSpec->size()) { - msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; - return StatusCode::FAILURE; - } - - // Add three attr lists - coral::AttributeList attrList0(*attrSpec); - attrList0["SampleSize"].setValue(static_cast<int>(samplesize)); - attrList0["barrel_endcap"].setValue(static_cast<int>(barrel_ec)); - attrList0["Layer"].setValue(static_cast<int>(layer)); - attrList0["Side"].setValue(static_cast<int>(side)); - attrList0["moduleType"].setValue(static_cast<int>(module)); - attrList0["lorentzAngle"].setValue(static_cast<float>(lorentz)); - attrList0["err_lorentzAngle"].setValue(static_cast<float>(err_lorentz)); - attrList0["chisq"].setValue(static_cast<float>(chisq)); - attrList0["fitParam_a"].setValue(static_cast<float>(fitParam_a)); - attrList0["err_a"].setValue(static_cast<float>(err_a)); - attrList0["fitParam_b"].setValue(static_cast<float>(fitParam_b)); - attrList0["err_b"].setValue(static_cast<float>(err_b)); - attrList0["fitParam_sigma"].setValue(static_cast<float>(fitParam_sigma)); - attrList0["err_sigma"].setValue(static_cast<float>(err_sigma)); - attrList0["minClusterWidth"].setValue(static_cast<float>(MCW)); - attrList0["err_minClusterWidth"].setValue(static_cast<float>(err_MCW)); - - std::ostringstream attrStr2; - attrList0.toOutputStream(attrStr2); - m_attrListColl_LA->add(wafer_id.get_identifier32().get_compact(), attrList0); - - return StatusCode::SUCCESS; -} - - -// StatusCode -// SCTCalibWriteSvc::createListLA(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,int /*module*/, const float lorentz, const float MCW ) const { -// if (!m_writeCondObjs) return StatusCode::SUCCESS; -// int barrel_ec = sctId->barrel_ec(wafer_id); -// int layer = sctId->layer_disk(wafer_id); -// int side = sctId->side(wafer_id); - -// coral::AttributeListSpecification* attrSpec =new coral::AttributeListSpecification(); -// attrSpec->extend("SampleSize", "int"); -// attrSpec->extend("barrel_endcap", "int"); -// attrSpec->extend("Layer", "int"); -// attrSpec->extend("Side", "int"); -// attrSpec->extend("LorentzAngle", "float"); -// attrSpec->extend("MinClusterWidth", "float"); - -// if (!attrSpec->size()) { -// msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; -// return StatusCode::FAILURE; -// } - -// // Add three attr lists -// coral::AttributeList attrList0(*attrSpec); -// attrList0["SampleSize"].setValue(static_cast<int>(samplesize)); -// attrList0["barrel_endcap"].setValue(static_cast<int>(barrel_ec)); -// attrList0["Layer"].setValue(static_cast<int>(layer)); -// attrList0["Side"].setValue(static_cast<int>(side)); -// attrList0["LorentzAngle"].setValue(static_cast<float>(lorentz)); -// attrList0["MinClusterWidth"].setValue(static_cast<float>(MCW)); - -// std::ostringstream attrStr2; -// attrList0.toOutputStream(attrStr2); -// m_attrListColl_LA->add(wafer_id.get_identifier32().get_compact(), attrList0); - -// return StatusCode::SUCCESS; -// } - -/////////////////////////////////////////////////////////////////////////////////// - -const CondAttrListCollection* -SCTCalibWriteSvc::getAttrListCollectionByFolder(const string& foldername) const { - // trying to find the pointer in the hashmap - // if it exists, return it, otherwise put it in. - const CondAttrListCollection* nullPtr(0); - const CondAttrListCollection* attrListCollection = nullPtr; - if (m_attrListCollectionMap.count(foldername) == 0) { - if ( m_detStore->retrieve(attrListCollection, foldername).isFailure()) return msg(MSG:: ERROR)<< "Could not retrieve " << foldername << endmsg, nullPtr; - m_attrListCollectionMap.insert(make_pair(foldername, attrListCollection)); - } else { - attrListCollection = m_attrListCollectionMap[foldername]; - } - return attrListCollection; -} - -// =========================================================================== - -int SCTCalibWriteSvc::stringToInt(const std::string& s) const { - return atoi(s.c_str()); -} - -// ====================================================================== -StatusCode SCTCalibWriteSvc::wrapUpNoisyChannel(){ - if (recordAndStream(m_attrListColl,s_defectFolderName,m_defectRecorded).isFailure()) return StatusCode::FAILURE; - if (registerCondObjectsWithErrMsg(s_defectFolderName, m_tagID4NoisyStrips).isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////////// -StatusCode SCTCalibWriteSvc::wrapUpDeadStrips(){ - if ( recordAndStream(m_attrListColl_deadStrip,s_deadStripFolderName,m_deadStripRecorded).isFailure()) return StatusCode::FAILURE; - if (registerCondObjectsWithErrMsg(s_deadStripFolderName, m_tagID4DeadStrips).isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////////// -StatusCode SCTCalibWriteSvc::wrapUpDeadChips(){ - if (recordAndStream(m_attrListColl_deadChip,s_deadChipFolderName,m_deadChipRecorded).isFailure()) return StatusCode::FAILURE; - if (registerCondObjectsWithErrMsg(s_deadChipFolderName, m_tagID4DeadChips).isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////////// -StatusCode SCTCalibWriteSvc::wrapUpEfficiency(){ - if (recordAndStream(m_attrListColl_eff, s_effFolderName,m_effRecorded).isFailure()) return StatusCode::FAILURE; - if (registerCondObjectsWithErrMsg(s_effFolderName, m_tagID4Efficiency).isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////////// -StatusCode SCTCalibWriteSvc::wrapUpNoiseOccupancy(){ - if (recordAndStream(m_attrListColl_no, s_noFolderName,m_noRecorded).isFailure()) return StatusCode::FAILURE; - if (registerCondObjectsWithErrMsg(s_noFolderName, m_tagID4NoiseOccupancy).isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////////// -StatusCode SCTCalibWriteSvc::wrapUpRawOccupancy(){ - if (recordAndStream(m_attrListColl_RawOccu, s_RawOccuFolderName,m_RawOccuRecorded).isFailure()) return StatusCode::FAILURE; - if( registerCondObjectsWithErrMsg(s_RawOccuFolderName, m_tagID4RawOccupancy).isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////////// -StatusCode SCTCalibWriteSvc::wrapUpBSErrors(){ - if (recordAndStream(m_attrListColl_BSErr, s_BSErrFolderName,m_BSErrRecorded).isFailure()) return StatusCode::FAILURE; - if (registerCondObjectsWithErrMsg(s_BSErrFolderName, m_tagID4BSErrors).isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////////// -StatusCode SCTCalibWriteSvc::wrapUpLorentzAngle(){ - if (recordAndStream(m_attrListColl_LA, s_LAFolderName,m_LARecorded).isFailure()) return StatusCode::FAILURE; - if( registerCondObjectsWithErrMsg(s_LAFolderName, m_tagID4LorentzAngle).isFailure()) return StatusCode::FAILURE; - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////////// - -StatusCode SCTCalibWriteSvc::streamOutCondObjects(const std::string& foldername) { - //if (m_streamer->connectOutput().isFailure()) { - if (m_streamer->connectOutput(m_streamName).isFailure()) { - msg(MSG:: ERROR) <<"Could not connect stream to output" <<endmsg; - return( StatusCode::FAILURE); - } - IAthenaOutputStreamTool::TypeKeyPairs typeKeys(1); - if (m_readWriteCool) { - IAthenaOutputStreamTool::TypeKeyPair - attrCollPair("CondAttrListCollection",foldername); - typeKeys[0] = attrCollPair; - } - - if (m_streamer->streamObjects(typeKeys).isFailure()) { - msg(MSG:: ERROR) << "Could not stream out AttributeLists" << endmsg; - return StatusCode::FAILURE; - } - - if (m_streamer->commitOutput().isFailure()) { - msg(MSG:: ERROR) << "Could not commit output stream" << endmsg; - return StatusCode::FAILURE; - } - return StatusCode::SUCCESS; -} -/////////////////////////////////////////////////////////////////////////////////////// - -StatusCode SCTCalibWriteSvc::streamOutCondObjectsWithErrMsg(const std::string& foldername) { - if (streamOutCondObjects(foldername).isFailure()){ - return msg(MSG:: ERROR) <<"Could create conditions object "<< foldername<< endmsg, StatusCode::FAILURE; - } - return StatusCode::SUCCESS; -} - -// ====================================================================== -StatusCode -SCTCalibWriteSvc::registerCondObjects(const std::string& foldername,const std::string& tagname) { - // Register the IOV DB with the conditions data written out - if (m_readWriteCool) { - // Can only write out AttrList's if this is NOT write and reg in two steps - if (!m_twoStepWriteReg) { - // Using COOL, write out attrlist and collection of attrlists - // attrlist collection - StatusCode sc; - unsigned int beginRun; - unsigned int endRun; - if ( !m_manualiov ) { - - SG::ReadHandle<EventInfo> evt(m_eventInfoKey); - if (not evt.isValid()) { - msg(MSG:: ERROR) << "Unable to get the EventInfo" << endmsg; - return StatusCode::FAILURE; - } - - beginRun = evt->event_ID()->run_number(); - endRun = beginRun; - - } else { - beginRun = m_beginRun; - if ( m_endRun != -1 ) endRun = m_endRun; - else endRun = IOVTime::MAXRUN; - } - - unsigned int beginLB = IOVTime::MINEVENT; - unsigned int endLB = IOVTime::MAXEVENT; - - //msg(MSG:: INFO) <<"beginRun = "<<beginRun<<" endRun = "<<endRun<<" tag = "<<tagname<<" m_manualiov = "<<m_manualiov << endmsg; - - if (not tagname.empty()) { - sc = m_regSvc->registerIOV("CondAttrListCollection",foldername,tagname,beginRun, endRun,beginLB, endLB); - } else { - sc = m_regSvc->registerIOV("CondAttrListCollection",foldername,"",beginRun, endRun,beginLB, endLB); - } - if (sc.isFailure()) { - msg(MSG:: ERROR) <<"Could not register in IOV DB for CondAttrListCollection" << endmsg; - return StatusCode::FAILURE; - } - } - } - return StatusCode::SUCCESS; -} - -StatusCode -SCTCalibWriteSvc::registerCondObjectsWithErrMsg(const std::string& foldername,const std::string& tagname) { - if (m_regIOV){ - if (registerCondObjects(foldername,tagname).isFailure()){ - msg(MSG:: ERROR) << "Could not register "<<foldername << endmsg; - return StatusCode::FAILURE; - } - } - return StatusCode::SUCCESS; -} - -StatusCode -SCTCalibWriteSvc::recordAndStream(const CondAttrListCollection* pCollection,const std::string & foldername, bool & flag){ - if (m_writeCondObjs) { - if (m_detStore->record(pCollection, foldername).isFailure()) { - msg(MSG:: ERROR) << "Could not record "<<foldername << endmsg; - return StatusCode::FAILURE; - } - flag=true; - if (streamOutCondObjectsWithErrMsg(s_defectFolderName).isFailure()) return StatusCode::FAILURE; - } - return StatusCode::SUCCESS; -} - -coral::AttributeListSpecification* -SCTCalibWriteSvc::createBasicDbSpec(const bool capsFormat) const{ - coral::AttributeListSpecification* attrSpec =new coral::AttributeListSpecification(); - const std::string becName=capsFormat?"BarrelEndcap":"barrel_endcap"; - attrSpec->extend("SampleSize", "int"); - attrSpec->extend(becName, "int"); - attrSpec->extend("Layer", "int"); - attrSpec->extend("Eta", "int"); - attrSpec->extend("Phi", "int"); - return attrSpec; -} - -void -SCTCalibWriteSvc::setBasicValues(coral::AttributeList & attrList, const Identifier& wafer_id, const int samplesize,const SCT_ID* sctId, const bool capsFormat) const{ - int eta = sctId->eta_module(wafer_id); - int phi = sctId->phi_module(wafer_id); - int barrel_ec = sctId->barrel_ec(wafer_id); - int layer = sctId->layer_disk(wafer_id); - // - const std::string becName=capsFormat?"BarrelEndcap":"barrel_endcap"; - attrList["SampleSize"].setValue(static_cast<int>(samplesize)); - attrList[becName].setValue(static_cast<int>(barrel_ec)); - attrList["Layer"].setValue(static_cast<int>(layer)); - attrList["Eta"].setValue(static_cast<int>(eta)); - attrList["Phi"].setValue(static_cast<int>(phi)); - - return; -} -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - - diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteTool.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..368ad7188a3a16e9dfca261e9b2792f03dd14fbb --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCTCalibWriteTool.cxx @@ -0,0 +1,758 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file SCTCalibWriteTool.cxx + * + * @brief Implementation file for uploading to DB on CAF + * + * @author Jose E. Garcia + **/ +#include "SCT_CalibAlgs/SCTCalibWriteTool.h" + +// IOVDbTest includes +#include "RegistrationServices/IIOVRegistrationSvc.h" + +// Gaudi includes +#include "GaudiKernel/StatusCode.h" +#include "GaudiKernel/IToolSvc.h" + +// Athena includes +#include "AthenaKernel/IAthenaOutputStreamTool.h" +#include "CoralBase/Attribute.h" + +#include "AthenaPoolUtilities/CondAttrListCollection.h" +#include "Identifier/IdentifierHash.h" +#include "InDetIdentifier/SCT_ID.h" + +// Event Info +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" +#include "EventInfo/EventType.h" + +//path resolver to find the file +#include "PathResolver/PathResolver.h" + +#include <fstream> +#include <iterator> +#include <sstream> +#include <iostream> +#include <istream> +#include <boost/lexical_cast.hpp> + +using std::string; +///////////////////////////////////////////////////////////////////////////// +string SCTCalibWriteTool::s_separator = string("-"); +string SCTCalibWriteTool::s_defectFolderName = string("/SCT/Derived/Monitoring"); +string SCTCalibWriteTool::s_deadStripFolderName = string("/SCT/Derived/DeadStrips"); +string SCTCalibWriteTool::s_deadChipFolderName = string("/SCT/Derived/DeadChips"); +string SCTCalibWriteTool::s_effFolderName = string("/SCT/Derived/Efficiency"); +string SCTCalibWriteTool::s_noFolderName = string("/SCT/Derived/NoiseOccupancy"); +string SCTCalibWriteTool::s_RawOccuFolderName = string("/SCT/Derived/RawOccupancy"); +string SCTCalibWriteTool::s_BSErrFolderName = string("/SCT/Derived/BSErrorsRun2"); +string SCTCalibWriteTool::s_LAFolderName = string("/SCT/Derived/LorentzAngleRun2_v2"); + +static bool becCapsFormat(true); +static bool becUnderscoreFormat(false); + +SCTCalibWriteTool::SCTCalibWriteTool(const std::string& type, const std::string& name, const IInterface* parent) : + AthAlgTool(type, name, parent), + m_detStore(0), + m_eventInfoKey(std::string("ByteStreamEventInfo")), + m_attrListColl(0), + m_attrListColl_deadStrip(0), + m_attrListColl_deadChip(0), + m_attrListColl_eff(0), + m_attrListColl_no(0), + m_attrListColl_RawOccu(0), + m_attrListColl_BSErr(0), + m_attrListColl_LA(0), + //boolean properties + m_writeCondObjs(true), + m_regIOV(true), + m_readWriteCool(true), + m_twoStepWriteReg(false), + m_manualiov(true), + + /*m_regTime(0), never used */ + m_version(0), + m_beginRun(IOVTime::MINRUN), + m_endRun(IOVTime::MAXRUN), + m_streamName("CondStreamTest"), + + m_regSvc(0), + m_streamer(0), + //m_streamer("AthenaOutputStreamTool"), + m_badIds(), + + m_defectRecorded(false), + m_deadStripRecorded(false), + m_deadChipRecorded(false), + m_effRecorded(false), + m_noRecorded(false), + m_RawOccuRecorded(false), + m_BSErrRecorded(false), + m_LARecorded(false), + m_pHelper(0), + m_currentDefectList("") +{ + declareProperty("WriteCondObjs", m_writeCondObjs); + declareProperty("RegisterIOV", m_regIOV); + declareProperty("ReadWriteCool", m_readWriteCool); + declareProperty("TwoStepWriteReg", m_twoStepWriteReg); + declareProperty("ManualIOV", m_manualiov); + //declareProperty("RegTime", m_regTime); never used Register time in sec + + declareProperty("BeginRun", m_beginRun); + declareProperty("EndRun", m_endRun); + //string properties: + declareProperty("StreamName", m_streamName); + declareProperty("TagID4NoisyStrips", m_tagID4NoisyStrips); + declareProperty("TagID4DeadStrips", m_tagID4DeadStrips); + declareProperty("TagID4DeadChips", m_tagID4DeadChips); + declareProperty("TagID4Efficiency", m_tagID4Efficiency); + declareProperty("TagID4NoiseOccupancy", m_tagID4NoiseOccupancy); + declareProperty("TagID4RawOccupancy", m_tagID4RawOccupancy); + declareProperty("TagID4BSErrors", m_tagID4BSErrors); + declareProperty("TagID4LorentzAngle", m_tagID4LorentzAngle); + +} + +/////////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::initialize() { + StatusCode sc = service("DetectorStore", m_detStore); + if ( !sc.isSuccess() || 0 == m_detStore) return msg(MSG:: ERROR) << "Could not find DetStore" << endmsg, StatusCode::FAILURE; + if (m_detStore->retrieve(m_pHelper,"SCT_ID").isFailure()) return msg(MSG:: ERROR) << "SCT mgr failed to retrieve" << endmsg, StatusCode::FAILURE; + + ATH_CHECK(m_eventInfoKey.initialize()); + + // ------------------------------------------------------------ + // The following is required for writing out something to COOL + + // CondAttrListCollection to store table temporarily + m_attrListColl = new CondAttrListCollection(true); + m_attrListColl_deadStrip = new CondAttrListCollection(true); + m_attrListColl_deadChip = new CondAttrListCollection(true); + m_attrListColl_eff = new CondAttrListCollection(true); + m_attrListColl_no = new CondAttrListCollection(true); + m_attrListColl_RawOccu = new CondAttrListCollection(true); + m_attrListColl_BSErr = new CondAttrListCollection(true); + m_attrListColl_LA = new CondAttrListCollection(true); + + // Get the IOVRegistrationSvc when needed + if (m_regIOV) { + if (service("IOVRegistrationSvc", m_regSvc).isFailure()) return msg(MSG:: ERROR)<< "Unable to find IOVRegistrationSvc "<< endmsg, StatusCode::FAILURE; + } + return StatusCode::SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::finalize() { + if (!m_defectRecorded) delete m_attrListColl; + if (!m_deadStripRecorded) delete m_attrListColl_deadStrip; + if (!m_deadChipRecorded) delete m_attrListColl_deadChip; + if (!m_effRecorded) delete m_attrListColl_eff; + if (!m_noRecorded) delete m_attrListColl_no; + if (!m_RawOccuRecorded) delete m_attrListColl_RawOccu; + if (!m_BSErrRecorded) delete m_attrListColl_BSErr; + if (!m_LARecorded) delete m_attrListColl_LA; + return StatusCode::SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::queryInterface(const InterfaceID& riid, void** ppvIF) +{ + if(SCTCalibWriteTool::interfaceID().versionMatch(riid) ) { + *ppvIF = (SCTCalibWriteTool*)this; + } else { + return AthAlgTool::queryInterface(riid, ppvIF); + } + return StatusCode::SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////////////////// + +unsigned int +SCTCalibWriteTool::computeIstrip4moncond(const Identifier& elementId) const { + unsigned int iiside = m_pHelper->side(elementId); + unsigned int iistrip = m_pHelper->strip(elementId); + return 768*iiside + iistrip; +} + +StatusCode +SCTCalibWriteTool::fillData() { + // this is a dummy function + return StatusCode::SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////////////////// +// Local stuff +////////////////////////////////////////////////////////////////////////////////////////// + +string +SCTCalibWriteTool::addDefect(const string& defectlist,const int defectBeginChannel,const int defectEndChannel) const { + // check size of defect list, + // if it is empty then use createDefectString to make first entry. + if (defectlist.empty()) return createDefectString(defectBeginChannel,defectEndChannel); + + // adding another Defect in DefectList + std::ostringstream defect; + defect << defectlist << " " << defectBeginChannel; + if (defectBeginChannel==defectEndChannel) { + defect << " "; + } else { + defect << "-" << defectEndChannel << " "; + } + return defect.str(); +} + +/////////////////////////////////////////////////////////////////////////////////////// + +std::string +SCTCalibWriteTool::createDefectString(const int defectBeginChannel,const int defectEndChannel) const { + std::ostringstream defect; + defect << " " << defectBeginChannel; + if (defectBeginChannel!=defectEndChannel) { + defect << "-" << defectEndChannel; + } + defect << " "; + return defect.str(); +} + + +/////////////////////////////////////////////////////////////////////////////////////// + +std::string +SCTCalibWriteTool::addNumber(const string numStr,const unsigned long long number) const { + std::ostringstream num_string; + // if it is empty then use createDefectString to make first entry. + if (numStr.empty()) { + num_string << number; + } else { // adding another number to numStr + num_string << numStr << " " << number; + } + return num_string.str(); +} + +///////////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::createCondObjects(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const std::string & defectType,const float threshold,const std::string & defectList) const { + if (!m_writeCondObjs) { + return StatusCode::SUCCESS; + } + coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becCapsFormat); + attrSpec->extend("DefectType","string"); + attrSpec->extend("Threshold","float"); + attrSpec->extend("DefectList","string"); + + if (!attrSpec->size()) { + msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; + return StatusCode::FAILURE; + } + + coral::AttributeList attrList0(*attrSpec); + setBasicValues(attrList0, wafer_id, samplesize,sctId,becCapsFormat); + attrList0["DefectType"].setValue(static_cast<std::string>(defectType)); + attrList0["Threshold"].setValue(static_cast<float>(threshold)); + attrList0["DefectList"].setValue(static_cast<std::string>(defectList)); + std::ostringstream attrStr2; + attrList0.toOutputStream( attrStr2 ); + m_attrListColl->add(wafer_id.get_identifier32().get_compact(), attrList0); + return StatusCode::SUCCESS; +} + +//////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::createListStrip(const Identifier& wafer_id, + const SCT_ID* sctId, + const int samplesize, + const std::string & defectType, + const float threshold, + const std::string & defectList) const +{ + if (!m_writeCondObjs) { + return StatusCode::SUCCESS; + } + coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becCapsFormat); + attrSpec->extend("DefectType","string"); + attrSpec->extend("Threshold","float"); + attrSpec->extend("DefectList","string"); + + if (!attrSpec->size()) { + msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; + return StatusCode::FAILURE; + } + + coral::AttributeList attrList0(*attrSpec); + setBasicValues(attrList0, wafer_id, samplesize,sctId, becCapsFormat); + attrList0["DefectType"].setValue(static_cast<std::string>(defectType)); + attrList0["Threshold"].setValue(static_cast<float>(threshold)); + attrList0["DefectList"].setValue(static_cast<std::string>(defectList)); + + std::ostringstream attrStr2; + attrList0.toOutputStream( attrStr2 ); + m_attrListColl_deadStrip->add(wafer_id.get_identifier32().get_compact(), attrList0); + msg(MSG::INFO)<<"createListStrip: return StatusCode::SUCCESS"<<endmsg; + return StatusCode::SUCCESS; +} + +//////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::createListChip(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const std::string & defectType,const float threshold,const std::string & defectList) const { + if (!m_writeCondObjs) { + return StatusCode::SUCCESS; + } + coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becCapsFormat); + attrSpec->extend("DefectType","string"); + attrSpec->extend("Threshold","float"); + attrSpec->extend("DefectList","string"); + if (!attrSpec->size()) { + msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; + return StatusCode::FAILURE; + } + + // Add three attr lists + coral::AttributeList attrList0(*attrSpec); + setBasicValues(attrList0, wafer_id, samplesize,sctId, becCapsFormat); + attrList0["DefectType"].setValue(static_cast<std::string>(defectType)); + attrList0["Threshold"].setValue(static_cast<float>(threshold)); + attrList0["DefectList"].setValue(static_cast<std::string>(defectList)); + + std::ostringstream attrStr2; + attrList0.toOutputStream( attrStr2 ); + m_attrListColl_deadChip->add(wafer_id.get_identifier32().get_compact(), attrList0); + + return StatusCode::SUCCESS; +} + +//////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::createListEff(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const float eff) const { + if(!m_writeCondObjs) { + return StatusCode::SUCCESS; + } + + coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becUnderscoreFormat); + attrSpec->extend("Efficiency", "float"); + if (!attrSpec->size()) { + msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; + return(StatusCode::FAILURE); + } + + coral::AttributeList attrList0(*attrSpec); + setBasicValues(attrList0, wafer_id, samplesize,sctId,becUnderscoreFormat); + attrList0["Efficiency"].setValue(static_cast<float>(eff)); + + std::ostringstream attrStr2; + attrList0.toOutputStream(attrStr2); + m_attrListColl_eff->add(wafer_id.get_identifier32().get_compact(), attrList0); + + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::createListNO(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const float noise_occ) const { + if (!m_writeCondObjs) { + return StatusCode::SUCCESS; + } + coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becUnderscoreFormat); + attrSpec->extend("NoiseOccupancy", "float"); + if (!attrSpec->size()) { + msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; + return StatusCode::FAILURE; + } + // Add three attr lists + coral::AttributeList attrList0(*attrSpec); + setBasicValues(attrList0, wafer_id, samplesize,sctId,becUnderscoreFormat); + attrList0["NoiseOccupancy"].setValue(static_cast<float>(noise_occ)); + std::ostringstream attrStr2; + attrList0.toOutputStream(attrStr2); + m_attrListColl_no->add(wafer_id.get_identifier32().get_compact(), attrList0); + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::createListRawOccu(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const float raw_occu) const { + if (!m_writeCondObjs) { + return StatusCode::SUCCESS; + } + coral::AttributeListSpecification* attrSpec =createBasicDbSpec(becUnderscoreFormat); + attrSpec->extend("RawOccupancy", "float"); + if (!attrSpec->size()) { + msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; + return StatusCode::FAILURE; + } + // Add three attr lists + coral::AttributeList attrList0(*attrSpec); + setBasicValues(attrList0, wafer_id, samplesize, sctId,becUnderscoreFormat); + attrList0["RawOccupancy"].setValue(static_cast<float>(raw_occu)); + std::ostringstream attrStr2; + attrList0.toOutputStream(attrStr2); + m_attrListColl_RawOccu->add(wafer_id.get_identifier32().get_compact(), attrList0); + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::createListBSErr(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,const std::string & errorList,const std::string & probList) const { + if (!m_writeCondObjs) { + return StatusCode::SUCCESS; + } + + int eta = sctId->eta_module(wafer_id); + int phi = sctId->phi_module(wafer_id); + int barrel_ec = sctId->barrel_ec(wafer_id); + int layer = sctId->layer_disk(wafer_id); + + coral::AttributeListSpecification* attrSpec = + new coral::AttributeListSpecification(); + attrSpec->extend("SampleSize", "int"); + attrSpec->extend("barrel_endcap", "int"); + attrSpec->extend("Layer", "int"); + attrSpec->extend("Eta", "int"); + attrSpec->extend("Phi", "int"); + attrSpec->extend("BSErrors", "string"); + attrSpec->extend("BadFraction", "string"); + + if (!attrSpec->size()) { + msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; + return StatusCode::FAILURE; + } + + // Add three attr lists + coral::AttributeList attrList0(*attrSpec); + attrList0["SampleSize"].setValue(static_cast<int>(samplesize)); + attrList0["barrel_endcap"].setValue(static_cast<int>(barrel_ec)); + attrList0["Layer"].setValue(static_cast<int>(layer)); + attrList0["Phi"].setValue(static_cast<int>(phi)); + attrList0["Eta"].setValue(static_cast<int>(eta)); + attrList0["BSErrors"].setValue(static_cast<std::string>(errorList)); + attrList0["BadFraction"].setValue(static_cast<std::string>(probList)); + + std::ostringstream attrStr2; + attrList0.toOutputStream(attrStr2); + m_attrListColl_BSErr->add(wafer_id.get_identifier32().get_compact(), attrList0); + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::createListLA(const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,int module, const float lorentz, const float err_lorentz, const float chisq, const float fitParam_a, const float err_a, const float fitParam_b, const float err_b, const float fitParam_sigma, const float err_sigma, const float MCW, const float err_MCW ) const { + if (!m_writeCondObjs) return StatusCode::SUCCESS; + int barrel_ec = sctId->barrel_ec(wafer_id); + int layer = sctId->layer_disk(wafer_id); + int side = sctId->side(wafer_id); + + coral::AttributeListSpecification* attrSpec =new coral::AttributeListSpecification(); + attrSpec->extend("SampleSize", "int"); + attrSpec->extend("barrel_endcap", "int"); + attrSpec->extend("Layer", "int"); + attrSpec->extend("Side", "int"); + attrSpec->extend("moduleType", "int"); + attrSpec->extend("lorentzAngle", "float"); + attrSpec->extend("err_lorentzAngle", "float"); + attrSpec->extend("chisq", "float"); + attrSpec->extend("fitParam_a", "float"); + attrSpec->extend("err_a", "float"); + attrSpec->extend("fitParam_b", "float"); + attrSpec->extend("err_b", "float"); + attrSpec->extend("fitParam_sigma", "float"); + attrSpec->extend("err_sigma", "float"); + attrSpec->extend("minClusterWidth", "float"); + attrSpec->extend("err_minClusterWidth", "float"); + + if (!attrSpec->size()) { + msg(MSG:: ERROR) << " Attribute list specification is empty" <<endmsg; + return StatusCode::FAILURE; + } + + // Add three attr lists + coral::AttributeList attrList0(*attrSpec); + attrList0["SampleSize"].setValue(static_cast<int>(samplesize)); + attrList0["barrel_endcap"].setValue(static_cast<int>(barrel_ec)); + attrList0["Layer"].setValue(static_cast<int>(layer)); + attrList0["Side"].setValue(static_cast<int>(side)); + attrList0["moduleType"].setValue(static_cast<int>(module)); + attrList0["lorentzAngle"].setValue(static_cast<float>(lorentz)); + attrList0["err_lorentzAngle"].setValue(static_cast<float>(err_lorentz)); + attrList0["chisq"].setValue(static_cast<float>(chisq)); + attrList0["fitParam_a"].setValue(static_cast<float>(fitParam_a)); + attrList0["err_a"].setValue(static_cast<float>(err_a)); + attrList0["fitParam_b"].setValue(static_cast<float>(fitParam_b)); + attrList0["err_b"].setValue(static_cast<float>(err_b)); + attrList0["fitParam_sigma"].setValue(static_cast<float>(fitParam_sigma)); + attrList0["err_sigma"].setValue(static_cast<float>(err_sigma)); + attrList0["minClusterWidth"].setValue(static_cast<float>(MCW)); + attrList0["err_minClusterWidth"].setValue(static_cast<float>(err_MCW)); + + std::ostringstream attrStr2; + attrList0.toOutputStream(attrStr2); + m_attrListColl_LA->add(wafer_id.get_identifier32().get_compact(), attrList0); + + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +const CondAttrListCollection* +SCTCalibWriteTool::getAttrListCollectionByFolder(const string& foldername) const { + // trying to find the pointer in the hashmap + // if it exists, return it, otherwise put it in. + const CondAttrListCollection* nullPtr(0); + const CondAttrListCollection* attrListCollection = nullPtr; + if (m_attrListCollectionMap.count(foldername) == 0) { + if ( m_detStore->retrieve(attrListCollection, foldername).isFailure()) return msg(MSG:: ERROR)<< "Could not retrieve " << foldername << endmsg, nullPtr; + m_attrListCollectionMap.insert(make_pair(foldername, attrListCollection)); + } else { + attrListCollection = m_attrListCollectionMap[foldername]; + } + return attrListCollection; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +int +SCTCalibWriteTool::stringToInt(const std::string& s) const { + return atoi(s.c_str()); +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::wrapUpNoisyChannel() { + if (recordAndStream(m_attrListColl,s_defectFolderName,m_defectRecorded).isFailure()) return StatusCode::FAILURE; + if (registerCondObjectsWithErrMsg(s_defectFolderName, m_tagID4NoisyStrips).isFailure()) return StatusCode::FAILURE; + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::wrapUpDeadStrips() { + if ( recordAndStream(m_attrListColl_deadStrip,s_deadStripFolderName,m_deadStripRecorded).isFailure()) return StatusCode::FAILURE; + if (registerCondObjectsWithErrMsg(s_deadStripFolderName, m_tagID4DeadStrips).isFailure()) return StatusCode::FAILURE; + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// +StatusCode + +SCTCalibWriteTool::wrapUpDeadChips() { + if (recordAndStream(m_attrListColl_deadChip,s_deadChipFolderName,m_deadChipRecorded).isFailure()) return StatusCode::FAILURE; + if (registerCondObjectsWithErrMsg(s_deadChipFolderName, m_tagID4DeadChips).isFailure()) return StatusCode::FAILURE; + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::wrapUpEfficiency() { + if (recordAndStream(m_attrListColl_eff, s_effFolderName,m_effRecorded).isFailure()) return StatusCode::FAILURE; + if (registerCondObjectsWithErrMsg(s_effFolderName, m_tagID4Efficiency).isFailure()) return StatusCode::FAILURE; + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::wrapUpNoiseOccupancy() { + if (recordAndStream(m_attrListColl_no, s_noFolderName,m_noRecorded).isFailure()) return StatusCode::FAILURE; + if (registerCondObjectsWithErrMsg(s_noFolderName, m_tagID4NoiseOccupancy).isFailure()) return StatusCode::FAILURE; + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::wrapUpRawOccupancy() { + if (recordAndStream(m_attrListColl_RawOccu, s_RawOccuFolderName,m_RawOccuRecorded).isFailure()) return StatusCode::FAILURE; + if( registerCondObjectsWithErrMsg(s_RawOccuFolderName, m_tagID4RawOccupancy).isFailure()) return StatusCode::FAILURE; + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::wrapUpBSErrors() { + if (recordAndStream(m_attrListColl_BSErr, s_BSErrFolderName,m_BSErrRecorded).isFailure()) return StatusCode::FAILURE; + if (registerCondObjectsWithErrMsg(s_BSErrFolderName, m_tagID4BSErrors).isFailure()) return StatusCode::FAILURE; + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::wrapUpLorentzAngle() { + if (recordAndStream(m_attrListColl_LA, s_LAFolderName,m_LARecorded).isFailure()) return StatusCode::FAILURE; + if( registerCondObjectsWithErrMsg(s_LAFolderName, m_tagID4LorentzAngle).isFailure()) return StatusCode::FAILURE; + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::streamOutCondObjects(const std::string& foldername) { + //if (m_streamer->connectOutput().isFailure()) { + if (m_streamer->connectOutput(m_streamName).isFailure()) { + msg(MSG:: ERROR) <<"Could not connect stream to output" <<endmsg; + return( StatusCode::FAILURE); + } + IAthenaOutputStreamTool::TypeKeyPairs typeKeys(1); + if (m_readWriteCool) { + IAthenaOutputStreamTool::TypeKeyPair + attrCollPair("CondAttrListCollection",foldername); + typeKeys[0] = attrCollPair; + } + + if (m_streamer->streamObjects(typeKeys).isFailure()) { + msg(MSG:: ERROR) << "Could not stream out AttributeLists" << endmsg; + return StatusCode::FAILURE; + } + + if (m_streamer->commitOutput().isFailure()) { + msg(MSG:: ERROR) << "Could not commit output stream" << endmsg; + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::streamOutCondObjectsWithErrMsg(const std::string& foldername) { + if (streamOutCondObjects(foldername).isFailure()) { + return msg(MSG:: ERROR) <<"Could create conditions object "<< foldername<< endmsg, StatusCode::FAILURE; + } + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::registerCondObjects(const std::string& foldername,const std::string& tagname) { + // Register the IOV DB with the conditions data written out + if (m_readWriteCool) { + // Can only write out AttrList's if this is NOT write and reg in two steps + if (!m_twoStepWriteReg) { + // Using COOL, write out attrlist and collection of attrlists + // attrlist collection + StatusCode sc; + unsigned int beginRun; + unsigned int endRun; + if ( !m_manualiov ) { + + SG::ReadHandle<EventInfo> evt(m_eventInfoKey); + if (not evt.isValid()) { + msg(MSG:: ERROR) << "Unable to get the EventInfo" << endmsg; + return StatusCode::FAILURE; + } + + beginRun = evt->event_ID()->run_number(); + endRun = beginRun; + + } else { + beginRun = m_beginRun; + if ( m_endRun != -1 ) endRun = m_endRun; + else endRun = IOVTime::MAXRUN; + } + + unsigned int beginLB = IOVTime::MINEVENT; + unsigned int endLB = IOVTime::MAXEVENT; + + //msg(MSG:: INFO) <<"beginRun = "<<beginRun<<" endRun = "<<endRun<<" tag = "<<tagname<<" m_manualiov = "<<m_manualiov << endmsg; + + if (not tagname.empty()) { + sc = m_regSvc->registerIOV("CondAttrListCollection",foldername,tagname,beginRun, endRun,beginLB, endLB); + } else { + sc = m_regSvc->registerIOV("CondAttrListCollection",foldername,"",beginRun, endRun,beginLB, endLB); + } + if (sc.isFailure()) { + msg(MSG:: ERROR) <<"Could not register in IOV DB for CondAttrListCollection" << endmsg; + return StatusCode::FAILURE; + } + } + } + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::registerCondObjectsWithErrMsg(const std::string& foldername,const std::string& tagname) { + if (m_regIOV) { + if (registerCondObjects(foldername,tagname).isFailure()) { + msg(MSG:: ERROR) << "Could not register "<<foldername << endmsg; + return StatusCode::FAILURE; + } + } + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +StatusCode +SCTCalibWriteTool::recordAndStream(const CondAttrListCollection* pCollection,const std::string & foldername, bool & flag) { + if (m_writeCondObjs) { + if (m_detStore->record(pCollection, foldername).isFailure()) { + msg(MSG:: ERROR) << "Could not record "<<foldername << endmsg; + return StatusCode::FAILURE; + } + flag=true; + if (streamOutCondObjectsWithErrMsg(s_defectFolderName).isFailure()) return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +coral::AttributeListSpecification* +SCTCalibWriteTool::createBasicDbSpec(const bool capsFormat) const { + coral::AttributeListSpecification* attrSpec =new coral::AttributeListSpecification(); + const std::string becName=capsFormat?"BarrelEndcap":"barrel_endcap"; + attrSpec->extend("SampleSize", "int"); + attrSpec->extend(becName, "int"); + attrSpec->extend("Layer", "int"); + attrSpec->extend("Eta", "int"); + attrSpec->extend("Phi", "int"); + return attrSpec; +} + +/////////////////////////////////////////////////////////////////////////////////////// + +void +SCTCalibWriteTool::setBasicValues(coral::AttributeList & attrList, const Identifier& wafer_id, const int samplesize,const SCT_ID* sctId, const bool capsFormat) const { + int eta = sctId->eta_module(wafer_id); + int phi = sctId->phi_module(wafer_id); + int barrel_ec = sctId->barrel_ec(wafer_id); + int layer = sctId->layer_disk(wafer_id); + // + const std::string becName=capsFormat?"BarrelEndcap":"barrel_endcap"; + attrList["SampleSize"].setValue(static_cast<int>(samplesize)); + attrList[becName].setValue(static_cast<int>(barrel_ec)); + attrList["Layer"].setValue(static_cast<int>(layer)); + attrList["Eta"].setValue(static_cast<int>(eta)); + attrList["Phi"].setValue(static_cast<int>(phi)); + + return; +} + +/////////////////////////////////////////////////////////////////////////////////////// diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorSvc.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorSvc.cxx deleted file mode 100644 index 67a4f9ab72c1994e43ea93286f0f7bee1f1fdd75..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorSvc.cxx +++ /dev/null @@ -1,175 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file SCT_CalibBsErrorSvc.cxx - * Implementation file for the SCT_CalibBsErrorSvc class - * @author Shaun Roe -**/ - -#include "SCT_CalibBsErrorSvc.h" -#include "SCT_CalibUtilities.h" -#include "SCT_CalibNumbers.h" -//Inner detector includes - -#include <set> - -#include "Identifier/Identifier.h" -#include "Identifier/IdentifierHash.h" -#include "GaudiKernel/ITHistSvc.h" - -#include "TH1I.h" - -// RAW data access -#include "InDetRawData/InDetRawDataCLASS_DEF.h" -#include "InDetRawData/SCT3_RawData.h" - -using namespace std; -using namespace SCT_CalibAlgs; - -const static string pathRoot("/BSErrors/"); -const static string detectorPaths[]={"SCTEC/", "SCTB/","SCTEA/"}; -const static string detectorNames[] = { "negativeEndcap", "barrel", "positiveEndcap" }; -const static int n_BSErrorType = 15; -const static int firstBSErrorType = 0; -const static int lastBSErrorType = 14; -static int MAXHASH(0); - - - -SCT_CalibBsErrorSvc::SCT_CalibBsErrorSvc(const std::string &name, ISvcLocator * svc): - AthService(name,svc), - m_detStore("DetectorStore", name), - m_evtStore("StoreGateSvc", name), - m_pSCTHelper(0), - m_scterr_bec(0), - m_scterr_layer(0), - m_scterr_eta(0), - m_scterr_phi(0), - m_scterr_side(0), - m_scterr_rodid(0), - m_scterr_channel(0), - m_scterr_type(0) -{ - -} - -StatusCode -SCT_CalibBsErrorSvc::initialize(){ - if ( service( "THistSvc", m_thistSvc ).isFailure() ) return msg( MSG::ERROR) << "Unable to retrieve pointer to THistSvc" << endmsg, StatusCode::FAILURE; - if ( m_detStore->retrieve( m_pSCTHelper, "SCT_ID").isFailure()) return msg( MSG::ERROR) << "Unable to retrieve SCTHelper" << endmsg, StatusCode::FAILURE; - if ( m_bytestreamErrorsTool.retrieve().isFailure()) return msg( MSG::ERROR) << "Unable to retrieve BS Error Tool" << endmsg, StatusCode::FAILURE; - // - MAXHASH=m_pSCTHelper->wafer_hash_max(); - m_waferItrBegin = m_pSCTHelper->wafer_begin(); - m_waferItrEnd = m_pSCTHelper->wafer_end(); - - return StatusCode::SUCCESS; -} - -StatusCode -SCT_CalibBsErrorSvc::finalize(){ - msg( MSG::INFO)<<"Finalize of SCT_CalibBsErrorSvc"<<endmsg; - - return StatusCode::SUCCESS; -} - -StatusCode -SCT_CalibBsErrorSvc::queryInterface(const InterfaceID & riid, void** ppvInterface ){ - if ( ISCT_CalibHistoSvc::interfaceID().versionMatch(riid) ) { - *ppvInterface = dynamic_cast<ISCT_CalibHistoSvc*>(this); - } else { - return AthService::queryInterface(riid, ppvInterface); - } - addRef(); - return StatusCode::SUCCESS; -} - -bool -SCT_CalibBsErrorSvc::book(){ - bool result(true); - m_phistoVector.clear(); - string histoName=pathRoot+"GENERAL/"; - //histogram for numbers of events - m_numberOfEventsHisto=new TH1I("events","Events",1,0.5,1.5); - if( m_thistSvc->regHist( histoName.c_str(), m_numberOfEventsHisto ).isFailure() ) { - msg( MSG::ERROR ) << "Error in booking BSErrors histogram" << endmsg; - } - //--- BSErrors for each wafer - SCT_ID::const_id_iterator waferItr = m_waferItrBegin; - SCT_ID::const_id_iterator waferItrE = m_waferItrEnd; - for( ; waferItr not_eq waferItrE; ++waferItr ) { - Identifier waferId = *waferItr; - const int bec( m_pSCTHelper->barrel_ec( waferId ) ); - const string formattedPosition( formatPosition(waferId, m_pSCTHelper)); - std::string histotitle = string( "SCT " ) + detectorNames[ bec2Index(bec) ] + string( " BSErrors : plane " ) + formattedPosition; - const std::string name=pathRoot+detectorPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition; - TH1F* hitmapHisto_tmp = new TH1F( TString( formattedPosition ), TString( histotitle ), n_BSErrorType, firstBSErrorType-0.5, lastBSErrorType+0.5 ); - if( m_thistSvc->regHist( name.c_str(), hitmapHisto_tmp ).isFailure() ) msg( MSG::ERROR ) << "Error in booking BSErrors histogram" << endmsg; - m_phistoVector.push_back( hitmapHisto_tmp ); - } - return result; -} - -bool -SCT_CalibBsErrorSvc::read(const std::string & fileName){ - msg( MSG::ERROR ) << "Reding BsError histograms from " << fileName.c_str() << " is not supported!" << endmsg; - return false; -} - -bool -SCT_CalibBsErrorSvc::fill(const bool fromData){ - if (fromData){ - return fillFromData(); - } - bool result(true); - //--- Number of event - m_numberOfEventsHisto->Fill( 1 ); - //--- Fill BSErrors - const int maxEntry = m_scterr_type->size(); - for( int i = 0; i != maxEntry; ++i ) { - int bec = (*m_scterr_bec)[i]; - int layer = (*m_scterr_layer)[i]; - int phi = (*m_scterr_phi)[i]; - int eta = (*m_scterr_eta)[i]; - int side = (*m_scterr_side)[i]; - int type = (*m_scterr_type)[i]; - Identifier waferId = m_pSCTHelper->wafer_id( bec, layer, phi, eta, side ); - fillBsErrorsForWafer(waferId, type); - } - return result; -} - -bool -SCT_CalibBsErrorSvc::fillFromData(){ - bool result(true); - //--- Number of event - m_numberOfEventsHisto->Fill( 1 ); - //--- Loop over BSErrors - for ( int type = 0; type < SCT_ByteStreamErrors::NUM_ERROR_TYPES; ++type ) { - const std::set<IdentifierHash>* errorSet = m_bytestreamErrorsTool->getErrorSet( type ); - if ( errorSet != 0 ) { - std::set<IdentifierHash>::const_iterator it = errorSet->begin(); - std::set<IdentifierHash>::const_iterator itE = errorSet->end(); - for ( ; it != itE; ++it ) { - Identifier waferId = m_pSCTHelper->wafer_id( *it ); - fillBsErrorsForWafer(waferId, type); - } - } - } - return result; -} - -void -SCT_CalibBsErrorSvc::fillBsErrorsForWafer(const Identifier & waferId, const int type){ - int iWaferHash = (int) m_pSCTHelper->wafer_hash( waferId ); - const string osWafer=formatPosition(waferId, m_pSCTHelper,"."); - //--- Protection for wrong waferID - if ( iWaferHash < 0 || iWaferHash >= MAXHASH ) { - msg( MSG::WARNING ) << "WaferHash " << iWaferHash << " is out of range : [ bec.layer.eta.phi.side, BSErrorType ] = [ " << osWafer << ", " << type << " ]" << endmsg; - } else { - if (msgLvl(MSG::DEBUG)) msg( MSG::DEBUG ) << "BSError : [ bec.layer.eta.phi.side, Type ] = [ " << osWafer<< ", " << type << " ]"<< endmsg; - m_phistoVector[ iWaferHash ]->Fill( type ); - } -} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorSvc.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorSvc.h deleted file mode 100644 index 7b9d8d77855937a1112922ceca637c899b809c64..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorSvc.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** -* @file SCT_CalibBsErrorSvc.h -* Header file for the SCT_CalibBsErrorSvc class -* @author Shaun Roe -**/ - -#ifndef SCT_CalibBsErrorSvc_h -#define SCT_CalibBsErrorSvc_h - - -//STL includes -#include <string> - -//Athena includes -#include "AthenaBaseComps/AthService.h" -#include "StoreGate/StoreGateSvc.h" -#include "GaudiKernel/ServiceHandle.h" -#include "InDetIdentifier/SCT_ID.h" - -#include "SCT_ConditionsTools/ISCT_ByteStreamErrorsTool.h" - - -//local includes -#include "SCT_CalibAlgs/ISCT_CalibHistoSvc.h" - -//fwd declarations -template <class TYPE> class SvcFactory; -class StatusCode; -class ISvcLocator; - - - -class SCT_CalibBsErrorSvc:virtual public ISCT_CalibHistoSvc, public AthService{ - friend class SvcFactory<SCT_CalibBsErrorSvc>; -public: - //@name Service methods, reimplemented - //@{ - SCT_CalibBsErrorSvc(const std::string &name, ISvcLocator * svc); - virtual ~SCT_CalibBsErrorSvc(){} - virtual StatusCode initialize(); - virtual StatusCode finalize(); - //interfaceID() implementation is in the baseclass - virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); - //@} - //@name ISCT_CalibHistoSvc methods, reimplemented - //@{ - virtual bool book(); - virtual bool read(const std::string & fileName); - virtual bool fill(const bool fromData=false); - virtual bool fillFromData(); - //@} -private: - ServiceHandle<StoreGateSvc> m_detStore; - ServiceHandle<StoreGateSvc> m_evtStore; - ToolHandle<ISCT_ByteStreamErrorsTool> m_bytestreamErrorsTool{this, "SCT_ByteStreamErrorsTool", "SCT_ByteStreamErrorsTool", "Tool to retrieve SCT ByteStream Errors"}; - const SCT_ID* m_pSCTHelper; - - - // SCT specific numbers - - SCT_ID::const_id_iterator m_waferItrBegin; - SCT_ID::const_id_iterator m_waferItrEnd; - typedef std::vector<int> VecInt; - VecInt *m_scterr_bec; - VecInt *m_scterr_layer; - VecInt *m_scterr_eta; - VecInt *m_scterr_phi; - VecInt *m_scterr_side; - VecInt *m_scterr_rodid; - VecInt *m_scterr_channel; - VecInt *m_scterr_type; - - - // - void - fillBsErrorsForWafer(const Identifier & waferId, const int type); - -}; -#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorTool.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e87add036bc866d29657334de2422b50d087f8ba --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorTool.cxx @@ -0,0 +1,172 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file SCT_CalibBsErrorTool.cxx + * Implementation file for the SCT_CalibBsErrorTool class + * @author Shaun Roe +**/ + +#include "SCT_CalibBsErrorTool.h" +#include "SCT_CalibUtilities.h" +#include "SCT_CalibNumbers.h" +//Inner detector includes + +#include <set> + +#include "Identifier/Identifier.h" +#include "Identifier/IdentifierHash.h" +#include "GaudiKernel/ITHistSvc.h" + +#include "TH1I.h" + +// RAW data access +#include "InDetRawData/InDetRawDataCLASS_DEF.h" +#include "InDetRawData/SCT3_RawData.h" + +using namespace std; +using namespace SCT_CalibAlgs; + +const static string pathRoot("/BSErrors/"); +const static string detectorPaths[]= {"SCTEC/", "SCTB/","SCTEA/"}; +const static string detectorNames[] = { "negativeEndcap", "barrel", "positiveEndcap" }; +const static int n_BSErrorType = 15; +const static int firstBSErrorType = 0; +const static int lastBSErrorType = 14; +static int MAXHASH(0); + +SCT_CalibBsErrorTool::SCT_CalibBsErrorTool(const std::string& type, const std::string& name, const IInterface* parent) : + base_class(type, name, parent), + m_detStore("DetectorStore", name), + m_evtStore("StoreGateSvc", name), + m_pSCTHelper(0), + m_scterr_bec(0), + m_scterr_layer(0), + m_scterr_eta(0), + m_scterr_phi(0), + m_scterr_side(0), + m_scterr_rodid(0), + m_scterr_channel(0), + m_scterr_type(0) +{ +} + +StatusCode +SCT_CalibBsErrorTool::initialize() { + if ( service( "THistSvc", m_thistSvc ).isFailure() ) return msg( MSG::ERROR) << "Unable to retrieve pointer to THistSvc" << endmsg, StatusCode::FAILURE; + if ( m_detStore->retrieve( m_pSCTHelper, "SCT_ID").isFailure()) return msg( MSG::ERROR) << "Unable to retrieve SCTHelper" << endmsg, StatusCode::FAILURE; + if ( m_bytestreamErrorsTool.retrieve().isFailure()) return msg( MSG::ERROR) << "Unable to retrieve BS Error Tool" << endmsg, StatusCode::FAILURE; + // + MAXHASH=m_pSCTHelper->wafer_hash_max(); + m_waferItrBegin = m_pSCTHelper->wafer_begin(); + m_waferItrEnd = m_pSCTHelper->wafer_end(); + + return StatusCode::SUCCESS; +} + +StatusCode +SCT_CalibBsErrorTool::finalize() { + msg( MSG::INFO)<<"Finalize of SCT_CalibBsErrorTool"<<endmsg; + + return StatusCode::SUCCESS; +} + +StatusCode +SCT_CalibBsErrorTool::queryInterface(const InterfaceID & riid, void** ppvInterface ) { + if ( ISCT_CalibHistoTool::interfaceID().versionMatch(riid) ) { + *ppvInterface = dynamic_cast<ISCT_CalibHistoTool*>(this); + } else { + return AthAlgTool::queryInterface(riid, ppvInterface); + } + addRef(); + return StatusCode::SUCCESS; +} + +bool +SCT_CalibBsErrorTool::book() { + bool result(true); + m_phistoVector.clear(); + string histoName=pathRoot+"GENERAL/"; + //histogram for numbers of events + m_numberOfEventsHisto=new TH1I("events","Events",1,0.5,1.5); + if( m_thistSvc->regHist( histoName.c_str(), m_numberOfEventsHisto ).isFailure() ) { + msg( MSG::ERROR ) << "Error in booking BSErrors histogram" << endmsg; + } + //--- BSErrors for each wafer + SCT_ID::const_id_iterator waferItr = m_waferItrBegin; + SCT_ID::const_id_iterator waferItrE = m_waferItrEnd; + for( ; waferItr not_eq waferItrE; ++waferItr ) { + Identifier waferId = *waferItr; + const int bec( m_pSCTHelper->barrel_ec( waferId ) ); + const string formattedPosition( formatPosition(waferId, m_pSCTHelper)); + std::string histotitle = string( "SCT " ) + detectorNames[ bec2Index(bec) ] + string( " BSErrors : plane " ) + formattedPosition; + const std::string name=pathRoot+detectorPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition; + TH1F* hitmapHisto_tmp = new TH1F( TString( formattedPosition ), TString( histotitle ), n_BSErrorType, firstBSErrorType-0.5, lastBSErrorType+0.5 ); + if( m_thistSvc->regHist( name.c_str(), hitmapHisto_tmp ).isFailure() ) msg( MSG::ERROR ) << "Error in booking BSErrors histogram" << endmsg; + m_phistoVector.push_back( hitmapHisto_tmp ); + } + return result; +} + +bool +SCT_CalibBsErrorTool::read(const std::string & fileName) { + msg( MSG::ERROR ) << "Reding BsError histograms from " << fileName.c_str() << " is not supported!" << endmsg; + return false; +} + +bool +SCT_CalibBsErrorTool::fill(const bool fromData) { + if (fromData) { + return fillFromData(); + } + bool result(true); + //--- Number of event + m_numberOfEventsHisto->Fill( 1 ); + //--- Fill BSErrors + const int maxEntry = m_scterr_type->size(); + for( int i = 0; i != maxEntry; ++i ) { + int bec = (*m_scterr_bec)[i]; + int layer = (*m_scterr_layer)[i]; + int phi = (*m_scterr_phi)[i]; + int eta = (*m_scterr_eta)[i]; + int side = (*m_scterr_side)[i]; + int type = (*m_scterr_type)[i]; + Identifier waferId = m_pSCTHelper->wafer_id( bec, layer, phi, eta, side ); + fillBsErrorsForWafer(waferId, type); + } + return result; +} + +bool +SCT_CalibBsErrorTool::fillFromData() { + bool result(true); + //--- Number of event + m_numberOfEventsHisto->Fill( 1 ); + //--- Loop over BSErrors + for ( int type = 0; type < SCT_ByteStreamErrors::NUM_ERROR_TYPES; ++type ) { + const std::set<IdentifierHash>* errorSet = m_bytestreamErrorsTool->getErrorSet( type ); + if ( errorSet != 0 ) { + std::set<IdentifierHash>::const_iterator it = errorSet->begin(); + std::set<IdentifierHash>::const_iterator itE = errorSet->end(); + for ( ; it != itE; ++it ) { + Identifier waferId = m_pSCTHelper->wafer_id( *it ); + fillBsErrorsForWafer(waferId, type); + } + } + } + return result; +} + +void +SCT_CalibBsErrorTool::fillBsErrorsForWafer(const Identifier & waferId, const int type) { + int iWaferHash = (int) m_pSCTHelper->wafer_hash( waferId ); + const string osWafer=formatPosition(waferId, m_pSCTHelper,"."); + //--- Protection for wrong waferID + if ( iWaferHash < 0 || iWaferHash >= MAXHASH ) { + msg( MSG::WARNING ) << "WaferHash " << iWaferHash << " is out of range : [ bec.layer.eta.phi.side, BSErrorType ] = [ " << osWafer << ", " << type << " ]" << endmsg; + } else { + if (msgLvl(MSG::DEBUG)) msg( MSG::DEBUG ) << "BSError : [ bec.layer.eta.phi.side, Type ] = [ " << osWafer<< ", " << type << " ]"<< endmsg; + m_phistoVector[ iWaferHash ]->Fill( type ); + } +} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorTool.h new file mode 100644 index 0000000000000000000000000000000000000000..7ee81e269a6b7a67ec095e67feabd4773f918058 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibBsErrorTool.h @@ -0,0 +1,78 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** +* @file SCT_CalibBsErrorTool.h +* Header file for the SCT_CalibBsErrorTool class +* @author Shaun Roe +**/ + +#ifndef SCT_CalibBsErrorTool_h +#define SCT_CalibBsErrorTool_h + + +//STL includes +#include <string> + +//Athena includes +#include "AthenaBaseComps/AthAlgTool.h" +#include "StoreGate/StoreGateSvc.h" +#include "GaudiKernel/ToolHandle.h" +#include "InDetIdentifier/SCT_ID.h" + +#include "SCT_ConditionsTools/ISCT_ByteStreamErrorsTool.h" + +//local includes +#include "SCT_CalibAlgs/ISCT_CalibHistoTool.h" + +//fwd declarations + +class StatusCode; +class ISvcLocator; + +class SCT_CalibBsErrorTool : public extends<AthAlgTool, ISCT_CalibHistoTool> +{ + + public: + //@name Tool methods, reimplemented + //@{ + SCT_CalibBsErrorTool(const std::string&, const std::string&, const IInterface*); + virtual ~SCT_CalibBsErrorTool() {}; + virtual StatusCode initialize(); + virtual StatusCode finalize(); + //interfaceID() implementation is in the baseclass + virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); + //@} + //@name ISCT_CalibHistoSvc methods, reimplemented + //@{ + virtual bool book(); + virtual bool read(const std::string & fileName); + virtual bool fill(const bool fromData=false); + virtual bool fillFromData(); + //@} + + private: + ServiceHandle<StoreGateSvc> m_detStore; + ServiceHandle<StoreGateSvc> m_evtStore; + ToolHandle<ISCT_ByteStreamErrorsTool> m_bytestreamErrorsTool{this, "SCT_ByteStreamErrorsTool", "SCT_ByteStreamErrorsTool", "Tool to retrieve SCT ByteStream Errors"}; + const SCT_ID* m_pSCTHelper; + + // SCT specific numbers + SCT_ID::const_id_iterator m_waferItrBegin; + SCT_ID::const_id_iterator m_waferItrEnd; + typedef std::vector<int> VecInt; + VecInt *m_scterr_bec; + VecInt *m_scterr_layer; + VecInt *m_scterr_eta; + VecInt *m_scterr_phi; + VecInt *m_scterr_side; + VecInt *m_scterr_rodid; + VecInt *m_scterr_channel; + VecInt *m_scterr_type; + + void + fillBsErrorsForWafer(const Identifier & waferId, const int type); + +}; +#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.cxx index d9fc765c22b1660772d64f7209f174bf1a5544cc..c6c714c423cde4d9d56faa07dbcca684cf5d87ef 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.cxx +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.cxx @@ -7,14 +7,15 @@ * Implementation file for the SCT_CalibEventInfo class * @author Shaun Roe **/ + #include <limits> -//STL, boost + #include "SCT_CalibEventInfo.h" #include "SCT_CalibUtilities.h" -#include "EventInfo/EventInfo.h" +#include "EventInfo/EventInfo.h" #include "EventInfo/EventID.h" -//coral/cool + #include "CoralBase/TimeStamp.h" namespace { @@ -23,7 +24,8 @@ const int INTMAX(std::numeric_limits<int>::max()); const long long oneBillion(1000000000LL); } -SCT_CalibEventInfo::SCT_CalibEventInfo(const std::string &name, ISvcLocator * svc):AthService(name,svc), +SCT_CalibEventInfo::SCT_CalibEventInfo(const std::string& type, const std::string& name, const IInterface* parent) : + base_class(type, name, parent), m_timeStampBegin(INTMAX), m_tsBeginString(""), m_tsEndString(""), @@ -59,7 +61,7 @@ SCT_CalibEventInfo::queryInterface(const InterfaceID & riid, void** ppvInterface if ( ISCT_CalibEvtInfo::interfaceID().versionMatch(riid) ) { *ppvInterface = dynamic_cast<ISCT_CalibEvtInfo*>(this); } else { - return AthService::queryInterface(riid, ppvInterface); + return AthAlgTool::queryInterface(riid, ppvInterface); } addRef(); return StatusCode::SUCCESS; @@ -106,18 +108,22 @@ SCT_CalibEventInfo::setLumiBlock(const int begin, const int end) { m_LBEnd=end; m_numLB=end-begin+1; } + void SCT_CalibEventInfo::setLumiBlock(const int lb) { m_lumiBlock=lb; } + void SCT_CalibEventInfo::setSource(const std::string source) { m_source=source; } + void SCT_CalibEventInfo::setRunNumber(const int rn) { - m_runNumber=rn; + m_runNumber=rn; } + void SCT_CalibEventInfo::setBunchCrossing(const int bc) { m_bunchCrossing=bc; diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.h index 56896443cc937f1b92e93759df51a9f6c64a3ed9..a80750b22dd0b39cfcb6e0e07839eca2645a624e 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.h +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibEventInfo.h @@ -10,8 +10,10 @@ #ifndef SCT_CalibEventInfo_h #define SCT_CalibEventInfo_h -#include "AthenaBaseComps/AthService.h" //baseclass -#include "GaudiKernel/ServiceHandle.h" //member +//#include "AthenaBaseComps/AthService.h" //baseclass +//#include "GaudiKernel/ServiceHandle.h" //member +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/ToolHandle.h" //member #include "SCT_CalibAlgs/ISCT_CalibEvtInfo.h" #include <string> @@ -20,12 +22,12 @@ class StatusCode; class ISvcLocator; class InterfaceID; -class SCT_CalibEventInfo: virtual public ISCT_CalibEvtInfo, public AthService { - friend class SvcFactory<SCT_CalibEventInfo>; +class SCT_CalibEventInfo: public extends<AthAlgTool, ISCT_CalibEvtInfo> +{ public: //@name Service methods, reimplemented //@{ - SCT_CalibEventInfo(const std::string &name, ISvcLocator * svc); + SCT_CalibEventInfo(const std::string&, const std::string&, const IInterface*); virtual ~SCT_CalibEventInfo() {} virtual StatusCode initialize(); virtual StatusCode finalize(); diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapSvc.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapSvc.cxx deleted file mode 100644 index aa5dff34b90fe717eac515c1995348fb31909b41..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapSvc.cxx +++ /dev/null @@ -1,208 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file SCT_CalibHitmapSvc.cxx - * Implementation file for the SCT_CalibHitmapSvc class - * @author Shaun Roe -**/ - -#include "SCT_CalibHitmapSvc.h" -#include "SCT_CalibUtilities.h" -#include "SCT_CalibNumbers.h" - - - -// RAW data access -#include "InDetRawData/InDetRawDataCLASS_DEF.h" -#include "InDetRawData/SCT3_RawData.h" -#include "StoreGate/ReadHandle.h" - -#include "Identifier/Identifier.h" -#include "Identifier/IdentifierHash.h" -#include "GaudiKernel/ITHistSvc.h" - -#include "TH1I.h" -#include "TH1F.h" -#include "TFile.h" -#include "TFileCollection.h" -#include "THashList.h" - -using namespace std; -using namespace SCT_CalibAlgs; -const static string pathRoot("/HitMaps/"); -const static string detectorNames[] = { "negativeEndcap", "barrel", "positiveEndcap" }; -const static string detectorPaths[]={"SCTEC/", "SCTB/","SCTEA/"}; - - - -SCT_CalibHitmapSvc::SCT_CalibHitmapSvc(const std::string &name, ISvcLocator * svc):AthService(name,svc), - m_detStore("DetectorStore", name), - m_evtStore("StoreGateSvc", name), - m_pSCTHelper(0), - m_sct_waferHash(0), - m_sct_firstStrip(0), - m_sct_rdoGroupSize(0), - m_rdoContainerKey(std::string("SCT_RDOs")) -{ -} - -StatusCode -SCT_CalibHitmapSvc::initialize(){ - if ( service( "THistSvc", m_thistSvc ).isFailure() ) return msg( MSG::ERROR) << "Unable to retrieve pointer to THistSvc" << endmsg, StatusCode::FAILURE; - if ( m_detStore->retrieve( m_pSCTHelper, "SCT_ID").isFailure()) return msg( MSG::ERROR) << "Unable to retrieve SCTHelper" << endmsg, StatusCode::FAILURE; - // - m_waferItrBegin = m_pSCTHelper->wafer_begin(); - m_waferItrEnd = m_pSCTHelper->wafer_end(); - // - - // Read Handle Key - ATH_CHECK(m_rdoContainerKey.initialize()); - - return StatusCode::SUCCESS; -} - -StatusCode -SCT_CalibHitmapSvc::finalize(){ - msg(MSG::VERBOSE) << "SCT_CalibHitmapSvc::finalize()"<<endmsg; - if (m_sct_waferHash) delete m_sct_waferHash; - if (m_sct_rdoGroupSize) delete m_sct_rdoGroupSize; - if (m_sct_firstStrip) delete m_sct_firstStrip; - return StatusCode::SUCCESS; -} - -StatusCode -SCT_CalibHitmapSvc::queryInterface(const InterfaceID & riid, void** ppvInterface ){ - if ( ISCT_CalibHistoSvc::interfaceID().versionMatch(riid) ) { - *ppvInterface = dynamic_cast<ISCT_CalibHistoSvc*>(this); - } else { - return AthService::queryInterface(riid, ppvInterface); - } - addRef(); - return StatusCode::SUCCESS; -} - -bool -SCT_CalibHitmapSvc::book(){ - bool result(true); - //pointers to the histos are deleted by m_thistSvc methods - m_phistoVector.clear(); - string histoName=pathRoot+"GENERAL/"; - //histogram for numbers of events - m_numberOfEventsHisto=new TH1I("events","Events",1,0.5,1.5); - if( m_thistSvc->regHist( histoName.c_str(), m_numberOfEventsHisto ).isFailure() ) { - msg( MSG::ERROR ) << "Error in booking EventNumber histogram" << endmsg; - } - //histograms for each wafer - SCT_ID::const_id_iterator waferItr = m_waferItrBegin; - std::string hitmapPaths[3]; - for (int i(0);i<3;++i){ - hitmapPaths[i]=pathRoot+detectorPaths[i]; - } - for( ; waferItr not_eq m_waferItrEnd; ++waferItr ) { - const Identifier & waferId = *waferItr; - const int bec( m_pSCTHelper->barrel_ec( waferId ) ); - const string formattedPosition=formatPosition(waferId, m_pSCTHelper); - std::string histotitle = string( "SCT " ) + detectorNames[ bec2Index(bec) ] + string( " Hitmap: plane " ) + formattedPosition; - std::string name=hitmapPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition; - TH1F* hitmapHisto_tmp = new TH1F( TString( formattedPosition ), TString( histotitle ), nbins, firstStrip-0.5, lastStrip+0.5 ); - - //cout<<name.c_str()<<endl; - if( m_thistSvc->regHist( name.c_str(), hitmapHisto_tmp ).isFailure()) { - msg( MSG::ERROR ) << "Error in booking Hitmap histogram" << endmsg; - } else { - m_phistoVector.push_back( hitmapHisto_tmp ); - } - - } - return result; -} - -bool -SCT_CalibHitmapSvc::read(const std::string & fileName){ - bool result(true); - //pointers to the histos are deleted by m_thistSvc methods - m_phistoVector.clear(); - TFile *fileHitmap = TFile::Open( fileName.c_str() ); - msg( MSG::INFO ) << "opening Hitmap file : " << fileName.c_str() << endmsg; - - if(fileHitmap==NULL) { - msg( MSG::ERROR ) << "can not open Hitmap file : " << fileName.c_str() << endmsg; - return result; - } - //histogram for numbers of events - m_numberOfEventsHisto = (TH1I*) fileHitmap->Get("GENERAL/events"); - if( m_numberOfEventsHisto==NULL ) { - msg( MSG::ERROR ) << "Error in reading EventNumber histogram" << endmsg; - } - //histograms for each wafer - SCT_ID::const_id_iterator waferItr = m_waferItrBegin; - for( ; waferItr not_eq m_waferItrEnd; ++waferItr ) { - const Identifier & waferId = *waferItr; - const string formattedPosition=formatPosition(waferId, m_pSCTHelper); - std::string name=detectorPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition; - TH1F* hitmapHisto_tmp = (TH1F*) fileHitmap->Get(name.c_str()); - if( hitmapHisto_tmp==NULL ) { - msg( MSG::ERROR ) << "Error in reading Hitmap histogram" << endmsg; - } else { - m_phistoVector.push_back( hitmapHisto_tmp ); - } - } - return result; -} - -bool -SCT_CalibHitmapSvc::fill(const bool fromData){ - //cout<<"fromData "<<fromData<<endl; - if (fromData){ - return fillFromData(); - } - bool result(true); - //--- Number of events - m_numberOfEventsHisto->Fill( 1 ); - // both ways hshould give the same results - // int eventNumber = m_numberOfEventsHisto->GetBinContent(1); - // int eventNumber = m_numberOfEventsHisto->GetEntries(); - - //--- Fill hitmap - const int MaxEntry = m_sct_waferHash->size(); - for( int i = 0; i != MaxEntry; ++i ) { - const int theFirstStrip = (*m_sct_firstStrip)[i]; - const int endStrip = (*m_sct_rdoGroupSize)[i] + theFirstStrip; - const int index = (*m_sct_waferHash)[i]; - TH1F * pThisHisto=m_phistoVector[ index ]; - for( int strip(theFirstStrip); strip !=endStrip; ++strip) { - pThisHisto->Fill( strip); - } - } - return result; -} - -bool -SCT_CalibHitmapSvc::fillFromData(){ - bool result(true); - m_numberOfEventsHisto->Fill( 1 ); - // unused int eventNumber = m_numberOfEventsHisto->GetEntries(); - SG::ReadHandle<SCT_RDO_Container> prdoContainer(m_rdoContainerKey); - if (not prdoContainer.isValid() ) msg(MSG::ERROR) <<"Failed to retrieve the SCT RDO container"<<endmsg; - SCT_RDO_Container::const_iterator itr=prdoContainer->begin(); - const SCT_RDO_Container::const_iterator end=prdoContainer->end(); - for (;itr !=end;++itr){ - const InDetRawDataCollection<SCT_RDORawData>* SCT_Collection(*itr); - if (not SCT_Collection) continue; - const Identifier waferId = SCT_Collection->identify(); - const IdentifierHash waferHash = m_pSCTHelper->wafer_hash(waferId); - TH1F * pThisHisto =m_phistoVector[(int)waferHash]; - DataVector<SCT_RDORawData>::const_iterator rdoItr = SCT_Collection->begin(); - const DataVector<SCT_RDORawData>::const_iterator rdoEnd = SCT_Collection->end(); - for(;rdoItr != rdoEnd;++rdoItr){ - int strip=m_pSCTHelper->strip((*rdoItr)->identify()); - const int endStrip=(*rdoItr)->getGroupSize() + strip; - for (;strip != endStrip;++strip){ - pThisHisto->Fill(strip); - } - } - } - return result; -} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapSvc.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapSvc.h deleted file mode 100644 index 4bfd945c7145c906bc4f9532b6901d19ae6fafc3..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapSvc.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file SCT_CalibHitmapSvc.h - * Header file for the SCT_CalibHitmapSvc class - * @author Shaun Roe -**/ - -#ifndef SCT_CalibHitmapSvc_h -#define SCT_CalibHitmapSvc_h - -//STL includes -#include <string> - -//Athena includes -#include "AthenaBaseComps/AthService.h" -#include "StoreGate/StoreGateSvc.h" -#include "GaudiKernel/ServiceHandle.h" -#include "StoreGate/ReadHandleKey.h" - -//Inner detector includes -#include "InDetIdentifier/SCT_ID.h" -#include "InDetRawData/SCT_RDO_Container.h" - -//local includes -#include "SCT_CalibAlgs/ISCT_CalibHistoSvc.h" - -//fwd declarations -template <class TYPE> class SvcFactory; -class StatusCode; -class ISvcLocator; - -class SCT_CalibHitmapSvc:virtual public ISCT_CalibHistoSvc, public AthService{ - friend class SvcFactory<SCT_CalibHitmapSvc>; - -public: - //@name Service methods, reimplemented - //@{ - SCT_CalibHitmapSvc(const std::string &name, ISvcLocator * svc); - virtual ~SCT_CalibHitmapSvc(){} - virtual StatusCode initialize(); - virtual StatusCode finalize(); - //interfaceID() implementation is in the baseclass - virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); - //@} - //@name ISCT_CalibHistoSvc methods, reimplemented - //@{ - virtual bool book(); - virtual bool read(const std::string & fileName); - virtual bool fill(const bool fromData=false); - virtual bool fillFromData(); - // virtual bool binHistograms(const int eventsPerWindow); - //@} -private: - ServiceHandle<StoreGateSvc> m_detStore; - ServiceHandle<StoreGateSvc> m_evtStore; - - const SCT_ID* m_pSCTHelper; - SCT_ID::const_id_iterator m_waferItrBegin; - SCT_ID::const_id_iterator m_waferItrEnd; - typedef std::vector<int> VecInt; - VecInt *m_sct_waferHash; - VecInt *m_sct_firstStrip; - VecInt *m_sct_rdoGroupSize; - - SG::ReadHandleKey<SCT_RDO_Container> m_rdoContainerKey; - -}; -#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapTool.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5b9d0c950f00d4ee7e2566f2498d6549b73ba1bd --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapTool.cxx @@ -0,0 +1,204 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file SCT_CalibHitmapSvc.cxx + * Implementation file for the SCT_CalibHitmapTool class + * @author Shaun Roe +**/ + +#include "SCT_CalibHitmapTool.h" +#include "SCT_CalibUtilities.h" +#include "SCT_CalibNumbers.h" + +// RAW data access +#include "InDetRawData/InDetRawDataCLASS_DEF.h" +#include "InDetRawData/SCT3_RawData.h" +#include "StoreGate/ReadHandle.h" + +#include "Identifier/Identifier.h" +#include "Identifier/IdentifierHash.h" +#include "GaudiKernel/ITHistSvc.h" + +#include "TH1I.h" +#include "TH1F.h" +#include "TFile.h" +#include "TFileCollection.h" +#include "THashList.h" + +using namespace std; +using namespace SCT_CalibAlgs; +const static string pathRoot("/HitMaps/"); +const static string detectorNames[] = { "negativeEndcap", "barrel", "positiveEndcap" }; +const static string detectorPaths[]= {"SCTEC/", "SCTB/","SCTEA/"}; + +SCT_CalibHitmapTool::SCT_CalibHitmapTool(const std::string& type, const std::string& name, const IInterface* parent) : + base_class(type, name, parent), + m_detStore("DetectorStore", name), + m_evtStore("StoreGateSvc", name), + m_pSCTHelper(0), + m_sct_waferHash(0), + m_sct_firstStrip(0), + m_sct_rdoGroupSize(0), + m_rdoContainerKey(std::string("SCT_RDOs")) +{ +} + +StatusCode +SCT_CalibHitmapTool::initialize() { + if ( m_detStore->retrieve( m_pSCTHelper, "SCT_ID").isFailure()) return msg( MSG::ERROR) << "Unable to retrieve SCTHelper" << endmsg, StatusCode::FAILURE; + // + m_waferItrBegin = m_pSCTHelper->wafer_begin(); + m_waferItrEnd = m_pSCTHelper->wafer_end(); + // + + // Read Handle Key + ATH_CHECK(m_rdoContainerKey.initialize()); + + return StatusCode::SUCCESS; +} + +StatusCode +SCT_CalibHitmapTool::finalize() { + msg(MSG::VERBOSE) << "SCT_CalibHitmapSvc::finalize()"<<endmsg; + if (m_sct_waferHash) delete m_sct_waferHash; + if (m_sct_rdoGroupSize) delete m_sct_rdoGroupSize; + if (m_sct_firstStrip) delete m_sct_firstStrip; + return StatusCode::SUCCESS; +} + +StatusCode +SCT_CalibHitmapTool::queryInterface(const InterfaceID & riid, void** ppvInterface ) { + if ( ISCT_CalibHistoTool::interfaceID().versionMatch(riid) ) { + *ppvInterface = dynamic_cast<ISCT_CalibHistoTool*>(this); + } else { + return AthAlgTool::queryInterface(riid, ppvInterface); + } + addRef(); + return StatusCode::SUCCESS; +} + +bool +SCT_CalibHitmapTool::book() { + bool result(true); + //pointers to the histos are deleted by m_thistSvc methods + m_phistoVector.clear(); + string histoName=pathRoot+"GENERAL/"; + //histogram for numbers of events + m_numberOfEventsHisto=new TH1I("events","Events",1,0.5,1.5); + if( m_thistSvc->regHist( histoName.c_str(), m_numberOfEventsHisto ).isFailure() ) { + msg( MSG::ERROR ) << "Error in booking EventNumber histogram" << endmsg; + } + //histograms for each wafer + SCT_ID::const_id_iterator waferItr = m_waferItrBegin; + std::string hitmapPaths[3]; + for (int i(0); i<3; ++i) { + hitmapPaths[i]=pathRoot+detectorPaths[i]; + } + for( ; waferItr not_eq m_waferItrEnd; ++waferItr ) { + const Identifier & waferId = *waferItr; + const int bec( m_pSCTHelper->barrel_ec( waferId ) ); + const string formattedPosition=formatPosition(waferId, m_pSCTHelper); + std::string histotitle = string( "SCT " ) + detectorNames[ bec2Index(bec) ] + string( " Hitmap: plane " ) + formattedPosition; + std::string name=hitmapPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition; + TH1F* hitmapHisto_tmp = new TH1F( TString( formattedPosition ), TString( histotitle ), nbins, firstStrip-0.5, lastStrip+0.5 ); + + //cout<<name.c_str()<<endl; + if( m_thistSvc->regHist( name.c_str(), hitmapHisto_tmp ).isFailure()) { + msg( MSG::ERROR ) << "Error in booking Hitmap histogram" << endmsg; + } else { + m_phistoVector.push_back( hitmapHisto_tmp ); + } + + } + return result; +} + +bool +SCT_CalibHitmapTool::read(const std::string & fileName) { + bool result(true); + //pointers to the histos are deleted by m_thistSvc methods + m_phistoVector.clear(); + TFile *fileHitmap = TFile::Open( fileName.c_str() ); + msg( MSG::INFO ) << "opening Hitmap file : " << fileName.c_str() << endmsg; + + if(fileHitmap==NULL) { + msg( MSG::ERROR ) << "can not open Hitmap file : " << fileName.c_str() << endmsg; + return result; + } + //histogram for numbers of events + m_numberOfEventsHisto = (TH1I*) fileHitmap->Get("GENERAL/events"); + if( m_numberOfEventsHisto==NULL ) { + msg( MSG::ERROR ) << "Error in reading EventNumber histogram" << endmsg; + } + //histograms for each wafer + SCT_ID::const_id_iterator waferItr = m_waferItrBegin; + for( ; waferItr not_eq m_waferItrEnd; ++waferItr ) { + const Identifier & waferId = *waferItr; + const string formattedPosition=formatPosition(waferId, m_pSCTHelper); + std::string name=detectorPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition; + TH1F* hitmapHisto_tmp = (TH1F*) fileHitmap->Get(name.c_str()); + if( hitmapHisto_tmp==NULL ) { + msg( MSG::ERROR ) << "Error in reading Hitmap histogram" << endmsg; + } else { + m_phistoVector.push_back( hitmapHisto_tmp ); + } + } + return result; +} + +bool +SCT_CalibHitmapTool::fill(const bool fromData) { + //cout<<"fromData "<<fromData<<endl; + if (fromData) { + return fillFromData(); + } + bool result(true); + //--- Number of events + m_numberOfEventsHisto->Fill( 1 ); + // both ways hshould give the same results + // int eventNumber = m_numberOfEventsHisto->GetBinContent(1); + // int eventNumber = m_numberOfEventsHisto->GetEntries(); + + //--- Fill hitmap + const int MaxEntry = m_sct_waferHash->size(); + for( int i = 0; i != MaxEntry; ++i ) { + const int theFirstStrip = (*m_sct_firstStrip)[i]; + const int endStrip = (*m_sct_rdoGroupSize)[i] + theFirstStrip; + const int index = (*m_sct_waferHash)[i]; + TH1F * pThisHisto=m_phistoVector[ index ]; + for( int strip(theFirstStrip); strip !=endStrip; ++strip) { + pThisHisto->Fill( strip); + } + } + return result; +} + +bool +SCT_CalibHitmapTool::fillFromData() { + bool result(true); + m_numberOfEventsHisto->Fill( 1 ); + // unused int eventNumber = m_numberOfEventsHisto->GetEntries(); + SG::ReadHandle<SCT_RDO_Container> prdoContainer(m_rdoContainerKey); + if (not prdoContainer.isValid() ) msg(MSG::ERROR) <<"Failed to retrieve the SCT RDO container"<<endmsg; + SCT_RDO_Container::const_iterator itr=prdoContainer->begin(); + const SCT_RDO_Container::const_iterator end=prdoContainer->end(); + for (; itr !=end; ++itr) { + const InDetRawDataCollection<SCT_RDORawData>* SCT_Collection(*itr); + if (not SCT_Collection) continue; + const Identifier waferId = SCT_Collection->identify(); + const IdentifierHash waferHash = m_pSCTHelper->wafer_hash(waferId); + TH1F * pThisHisto =m_phistoVector[(int)waferHash]; + DataVector<SCT_RDORawData>::const_iterator rdoItr = SCT_Collection->begin(); + const DataVector<SCT_RDORawData>::const_iterator rdoEnd = SCT_Collection->end(); + for(; rdoItr != rdoEnd; ++rdoItr) { + int strip=m_pSCTHelper->strip((*rdoItr)->identify()); + const int endStrip=(*rdoItr)->getGroupSize() + strip; + for (; strip != endStrip; ++strip) { + pThisHisto->Fill(strip); + } + } + } + return result; +} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapTool.h new file mode 100644 index 0000000000000000000000000000000000000000..594c6da54a5b92a5ab700c4488cd874fec2a3775 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHitmapTool.h @@ -0,0 +1,72 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file SCT_CalibHitmapTool.h + * Header file for the SCT_CalibHitmapTool class + * @author Shaun Roe +**/ + +#ifndef SCT_CalibHitmapTool_h +#define SCT_CalibHitmapTool_h + +//STL includes +#include <string> + +//Athena includes +#include "AthenaBaseComps/AthAlgTool.h" +#include "StoreGate/StoreGateSvc.h" +#include "GaudiKernel/ToolHandle.h" +#include "StoreGate/ReadHandleKey.h" + +//Inner detector includes +#include "InDetIdentifier/SCT_ID.h" +#include "InDetRawData/SCT_RDO_Container.h" + +//local includes +#include "SCT_CalibAlgs/ISCT_CalibHistoTool.h" + +//fwd declarations + +class StatusCode; + +//class SCT_CalibHitmapTool : virtual public ISCT_CalibHistoTool, public AthAlgTool +class SCT_CalibHitmapTool : public extends<AthAlgTool, ISCT_CalibHistoTool> + { + + public: + //@name Tool methods, reimplemented + //@{ + SCT_CalibHitmapTool(const std::string&, const std::string&, const IInterface*); + virtual ~SCT_CalibHitmapTool() {}; + virtual StatusCode initialize(); + virtual StatusCode finalize(); + //interfaceID() implementation is in the baseclass + virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); + //@} + //@name ISCT_CalibHistoTool methods, reimplemented + //@{ + virtual bool book(); + virtual bool read(const std::string & fileName); + virtual bool fill(const bool fromData=false); + virtual bool fillFromData(); + //virtual bool binHistograms(const int eventsPerWindow); + //@} + + private: + ServiceHandle<StoreGateSvc> m_detStore; + ServiceHandle<StoreGateSvc> m_evtStore; + + const SCT_ID* m_pSCTHelper; + SCT_ID::const_id_iterator m_waferItrBegin; + SCT_ID::const_id_iterator m_waferItrEnd; + typedef std::vector<int> VecInt; + VecInt *m_sct_waferHash; + VecInt *m_sct_firstStrip; + VecInt *m_sct_rdoGroupSize; + + SG::ReadHandleKey<SCT_RDO_Container> m_rdoContainerKey; + +}; +#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvSvc.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvSvc.cxx deleted file mode 100644 index a9e715b34f387c27d6943fe294fb7e68e34c9215..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvSvc.cxx +++ /dev/null @@ -1,252 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - - -/** -* @file SCT_CalibHvSvc.cxx -* Implementation file for the SCT_CalibHvSvc class -* @author Shaun Roe -**/ - -#include "SCT_CalibHvSvc.h" -#include "SCT_CalibUtilities.h" -#include "SCT_CalibNumbers.h" - - -#include "EventInfo/EventInfo.h" -#include "EventInfo/EventID.h" - -using namespace std; -using namespace SCT_CalibAlgs; - -//const static int n_chipsPerSide(6); -//const static int n_stripsPerChip(128); -const static string detectorNames[] = { "negativeEndcap", "barrel", "positiveEndcap" }; - - -const static string detectorPaths[]={"SCTEC/", "SCTB/","SCTEA/"}; -namespace{ - void - initQueue(std::queue<int> & q, const int numvals, const int setval){ - for (int i(0);i<numvals;++i) q.push(setval); - } - -} - - -SCT_CalibHvSvc::SCT_CalibHvSvc(const std::string &name, ISvcLocator * svc): - AthService(name,svc), - m_detStore("DetectorStore", name), - m_evtStore("StoreGateSvc", name), - m_pSCTHelper(0), - m_sct_waferHash(0), - m_sct_numHitsInWafer(0), - m_lumiBlock(0), - m_maxq(100), - m_phvtripPrevTime(0), - m_phvtripFirstTime(0), - m_absolutetriplimit(0), - m_relativetriplimit(0), - m_tq{0}, - m_evt(0), - m_outputLowHits(false),m_lowHitCut(100) -{ -} - - -StatusCode -SCT_CalibHvSvc::initialize(){ - ATH_CHECK(m_DCSConditionsTool.retrieve()); - - return StatusCode::SUCCESS; - -} - -StatusCode -SCT_CalibHvSvc::finalize(){ - return StatusCode::SUCCESS; -} - -StatusCode -SCT_CalibHvSvc::queryInterface(const InterfaceID & riid, void** ppvInterface ){ - if ( ISCT_CalibHistoSvc::interfaceID().versionMatch(riid) ) { - *ppvInterface = dynamic_cast<ISCT_CalibHistoSvc*>(this); - } else { - return AthService::queryInterface(riid, ppvInterface); - } - addRef(); - return StatusCode::SUCCESS; -} - - -bool -SCT_CalibHvSvc::book(){ - bool result(true); - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Book HVTrips" <<endmsg; - //now initialize the queues (fill 100 spots with 0): - queue<int> qtemp; - initQueue(qtemp, m_maxq,0); - // need to keep previous bins lbn 4 deep. - initQueue(m_prevLBN, 4, 0); - vector< pair <int,int> > dummy; - //first set num events processed to 0 - //int n_elements=8176; //info taken from SCTCalib.h: SCT specific number - m_phvtripProcessedEventsInt.insert(m_phvtripProcessedEventsInt.end(), n_elements, 1); - m_phvtripRunningTotalInt.insert(m_phvtripRunningTotalInt.end(), n_elements, 0); - m_phvtripHasItTripped.insert(m_phvtripHasItTripped.end(),n_elements, 0); - m_phvtripQueue.insert(m_phvtripQueue.end(), n_elements, qtemp); - m_summarytrips.insert(m_summarytrips.end(),n_elements, dummy); - m_summarytripslb.insert(m_summarytripslb.end(), n_elements, dummy); - m_phvtripHasItTripped_prev = m_phvtripHasItTripped; - return result; -} - -bool -SCT_CalibHvSvc::fill(const bool fromData){ - if (fromData){ - return fillFromData(); - } - bool result(true); - int lumi_block(0);//fix me!; - //int event_number; - const int wafersize = m_sct_waferHash->size(); - int time_stamp= m_evt->event_ID()->time_stamp(); - int curr_time = time_stamp; - int dtime = curr_time - m_phvtripPrevTime; - int totalHits = 0; - if (curr_time<m_phvtripPrevTime){ - msg(MSG::ERROR) << "Events not sorted properly (time is going backwards!) " << endmsg; - return false; - } - // for first event - if (m_phvtripFirstTime > curr_time){ m_phvtripFirstTime = curr_time; } - bool newbin = false; - // check if we have a new time bin, if we do pop off the back (oldest) part - // of the queue and enqueue 0 for every wafer - int maxtbins(5); - if (dtime > maxtbins) { - newbin = true; - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " new t bin " << dtime <<" since start "<< (curr_time-(m_phvtripFirstTime-1.01)) << endmsg; - m_phvtripHasItTripped_prev = m_phvtripHasItTripped; - for (int iwaf = 0; iwaf!=n_elements; ++iwaf){ - m_phvtripQueue[iwaf].pop(); - m_phvtripQueue[iwaf].push(0); - m_phvtripHasItTripped[iwaf]=0; - } - } - //if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "time stamp "<<time_stamp <<" event number "<< Event_number<<endmsg; - // Loop over all hits in the event - bool isgoodnow; - for( int itrk=0; itrk!=wafersize; ++itrk){ - int waferhash = (*m_sct_waferHash)[itrk]; - Identifier waferId = m_pSCTHelper->wafer_id(waferhash); - Identifier moduleId = m_pSCTHelper->module_id(waferId); - //step one is to make sure this one isn't already know to be messed up: - isgoodnow = m_DCSConditionsTool->isGood(moduleId,InDetConditions::SCT_MODULE); - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "checked is good "<< isgoodnow <<endmsg; - if (isgoodnow){ - int numhits = (*m_sct_numHitsInWafer)[itrk]; - totalHits += numhits; - /** - calculate the limit for an individual module, limit is m_relativetriplimit (default = 4) times the running average in that module. - limits are given in hits/second. need to convert numhits in bin to average (within bin) hits/sec. - **/ - double limit = m_relativetriplimit * (double)m_phvtripRunningTotalInt[waferhash] / ((double)curr_time-((double)m_phvtripFirstTime-0.01)); - - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "waferhash "<<waferhash<<" itrk "<<itrk <<" run tot "<< m_phvtripRunningTotalInt[waferhash] - <<" num hits "<<numhits<<" evnts processed "<< m_phvtripProcessedEventsInt[waferhash] <<" limit "<<limit - <<" abs limit, rel limit "<<m_absolutetriplimit<<","<< m_relativetriplimit<<" max bins "<<maxtbins - <<endmsg; - - if ( ((numhits + m_phvtripQueue[waferhash].back() )/ (double)maxtbins ) > m_absolutetriplimit - and ((numhits + m_phvtripQueue[waferhash].back() )/ (double)maxtbins ) > limit) { - //read back queue and see if the high hit rate is persistant for 3 previous bins (a bin is 5 seconds by default) - for (int iq = 0; iq<m_maxq; ++iq){ - m_tq[iq]=m_phvtripQueue[waferhash].front(); - m_phvtripQueue[waferhash].pop(); - } - if (m_tq[m_maxq-2]/(double)maxtbins > limit && m_tq[m_maxq-3]/(double)maxtbins > limit && m_tq[m_maxq-4]/(double)maxtbins > limit){ - // found a persistent trip/thing - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Found a potential trip in SCT wafer "<< waferhash<<endmsg; - //if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "TRIP: "<< waferhash<<" "<<time_stamp <<" "<< Event_number <<" "<< (numhits + m_tq[m_maxq-1] ) <<endmsg; - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "TRIP more info: limit = "<< limit <<" abslimit = "<< m_absolutetriplimit - <<" hits/secs now = "<< ((numhits + m_tq[m_maxq-1])/ maxtbins ) - <<" running total = "<< m_phvtripRunningTotalInt[waferhash] - <<" running average = "<< m_phvtripRunningTotalInt[waferhash] / (curr_time-(m_phvtripFirstTime-1.01)) << endmsg; - m_phvtripHasItTripped[waferhash] = (numhits + m_tq[m_maxq-1] ); - } // end trip found - - //put queue back the way we found it: - for (int iq = 0; iq < m_maxq; ++iq) { - m_phvtripQueue[waferhash].push(m_tq[iq]); - } - } // end potential trip id - //incriment event counter - m_phvtripProcessedEventsInt[waferhash] += 1; - //recalcuate running total: - m_phvtripRunningTotalInt[waferhash] += numhits; - m_phvtripQueue[waferhash].back() += numhits; -} //end is good check -else { - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Was a bad module already: "<< waferhash <<endmsg; -} -} //end loop over tracks - -// text output, summarizing the event -//if new bin summarzie the previous event. -if (newbin) { - SCT_ID::const_id_iterator waferItr = m_waferItrBegin; - SCT_ID::const_id_iterator waferItrE = m_waferItrEnd; - for( ; waferItr not_eq waferItrE; ++waferItr ) { - Identifier waferId = *waferItr; - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - if (m_phvtripHasItTripped_prev[waferHash]>0) { - pair<int,int> wp; - wp.first = (m_phvtripPrevTime - 3*maxtbins); - wp.second = (m_phvtripPrevTime + maxtbins); - m_summarytrips[waferHash].push_back(wp); - pair<int,int> lbn; - lbn.first = m_prevLBN.front(); - lbn.second = m_prevLBN.back(); - m_summarytripslb[waferHash].push_back(lbn); - } - } - m_phvtripPrevTime = curr_time; //reset prev and current time - m_prevLBN.pop(); - m_prevLBN.push(lumi_block); -} - -for (int iwaf(0); iwaf!=n_elements; ++iwaf){ - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "mod "<< iwaf <<" events with that waf " <<m_phvtripProcessedEventsInt[iwaf] << " numhits "<<m_phvtripRunningTotalInt[iwaf] <<endmsg; - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "did it trip "<<m_phvtripHasItTripped[iwaf] << endmsg; - if (m_phvtripHasItTripped[iwaf]) { - //if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "TRIP: "<< iwaf <<" "<<time_stamp <<" "<< Event_number <<" "<< m_phvtripQueue[iwaf].back() <<endmsg; - if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "TRIP more info: abslimit = "<< m_absolutetriplimit - <<" hits/secs now = "<< ( m_phvtripQueue[iwaf].back() / maxtbins ) - <<" running total = "<< m_phvtripRunningTotalInt[iwaf] - <<" running average = "<< m_phvtripRunningTotalInt[iwaf] / (curr_time-(m_phvtripFirstTime-1.01)) << endmsg; - } -} -if (m_outputLowHits && (totalHits < m_lowHitCut) ){ - //msg(MSG::WARNING) <<"Event: " << Event_number << " Total hits: " << totalHits << endmsg; -} -return result; -} - - -bool -SCT_CalibHvSvc::fillFromData(){ - bool result(true); - - - return result; -} - - - - - - - - diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvSvc.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvSvc.h deleted file mode 100644 index 95f45c775e4b44d85e7722efa8d619369425f16b..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvSvc.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file SCT_CalibHvSvc.h - * Header file for the SCT_CalibHvSvc class - * @author Shaun Roe -**/ - -#ifndef SCT_CalibHvSvc_h -#define SCT_CalibHvSvc_h - -//STL includes -#include <string> -#include <vector> -#include <queue> -#include <utility> //for 'pair' - -//Athena includes -#include "AthenaBaseComps/AthService.h" -#include "StoreGate/StoreGateSvc.h" -#include "GaudiKernel/ServiceHandle.h" - -//Inner detector includes -#include "InDetIdentifier/SCT_ID.h" - -//local includes -#include "SCT_CalibAlgs/ISCT_CalibHistoSvc.h" -#include "SCT_ConditionsTools/ISCT_DCSConditionsTool.h" //template parameter - -//fwd declarations -template <class TYPE> class SvcFactory; -class StatusCode; -class ISvcLocator; -class IdentifierHash; -class EventInfo; - -class SCT_CalibHvSvc:virtual public ISCT_CalibHistoSvc, public AthService{ - friend class SvcFactory<SCT_CalibHvSvc>; - -public: - //@name Service methods, reimplemented - //@{ - SCT_CalibHvSvc(const std::string &name, ISvcLocator * svc); - virtual ~SCT_CalibHvSvc(){} - virtual StatusCode initialize(); - virtual StatusCode finalize(); - //interfaceID() implementation is in the baseclass - virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); - //@} - //@name ISCT_CalibHistoSvc methods, reimplemented - //@{ - virtual bool book(); - virtual bool fill(const bool fromData=false); - virtual bool fillFromData(); - //@} -private: - enum { n_chipPerSide = 6, n_chipPerModule = 12, n_stripPerChip = 128, n_etaInBarrel = 12, - n_phiBinsB0 = 32, n_phiBinsB1 = 40, n_phiBinsB2 = 48, n_phiBinsB3 = 56, - n_phiBinsECShort = 40, n_phiBinsECMiddle = 40, n_phiBinsECOuter = 52, n_elements=8176, - n_BSErrorType = 15, firstBSErrorType = 0, lastBSErrorType = 14 }; - - ServiceHandle<StoreGateSvc> m_detStore; - ServiceHandle<StoreGateSvc> m_evtStore; - ToolHandle<ISCT_DCSConditionsTool> m_DCSConditionsTool{this, "SCT_DCSConditionsTool", "SCT_DCSConditionsTool", "Tool to retrieve SCT DCS information"}; - - const SCT_ID* m_pSCTHelper; - SCT_ID::const_id_iterator m_waferItrBegin; - SCT_ID::const_id_iterator m_waferItrEnd; - typedef std::vector<int> VecInt; - VecInt *m_sct_waferHash; - VecInt *m_sct_numHitsInWafer; - mutable int m_lumiBlock; - - //private use in this class - int m_maxq; - // For HV trips - std::vector< std::queue<int> > m_phvtripQueue; - std::queue<int> m_prevLBN; - VecInt m_phvtripRunningTotalInt; - VecInt m_phvtripProcessedEventsInt; - VecInt m_phvtripHasItTripped; - VecInt m_phvtripHasItTripped_prev; - // - int m_phvtripPrevTime; - int m_phvtripFirstTime; - double m_absolutetriplimit; - double m_relativetriplimit; - int m_tq[100]; - - std::vector< std::vector< std::pair<int, int> > > m_summarytrips; - std::vector< std::vector< std::pair<int, int> > > m_summarytripslb; - const EventInfo* m_evt; - bool m_outputLowHits; - int m_lowHitCut; - ///retrieve a service and report if it failed - template<class S> - bool retrievedService(S & service, const std::string & serviceName){ - if (service.retrieve().isFailure() ) return msg(MSG::ERROR)<<"Unable to retrieve "<<serviceName<<endmsg, false; - return true; - } - -}; -#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvTool.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..88e535743a61d1ed4000a0e4d8fe92c8d48d874e --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvTool.cxx @@ -0,0 +1,232 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** +* @file SCT_CalibHvTool.cxx +* Implementation file for the SCT_CalibHvTool class +* @author Shaun Roe +**/ + +#include "SCT_CalibHvTool.h" +#include "SCT_CalibUtilities.h" +#include "SCT_CalibNumbers.h" + +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +using namespace std; +using namespace SCT_CalibAlgs; + +const static string detectorNames[] = { "negativeEndcap", "barrel", "positiveEndcap" }; + +const static string detectorPaths[]= {"SCTEC/", "SCTB/","SCTEA/"}; +namespace { +void +initQueue(std::queue<int> & q, const int numvals, const int setval) { + for (int i(0); i<numvals; ++i) q.push(setval); +} +} + +SCT_CalibHvTool::SCT_CalibHvTool(const std::string& type, const std::string& name, const IInterface* parent) : + base_class(type, name, parent), + m_detStore("DetectorStore", name), + m_evtStore("StoreGateSvc", name), + m_pSCTHelper(0), + m_sct_waferHash(0), + m_sct_numHitsInWafer(0), + m_lumiBlock(0), + m_maxq(100), + m_phvtripPrevTime(0), + m_phvtripFirstTime(0), + m_absolutetriplimit(0), + m_relativetriplimit(0), + m_tq{0}, + m_evt(0), + m_outputLowHits(false),m_lowHitCut(100) +{ +} + +StatusCode +SCT_CalibHvTool::initialize() { + ATH_CHECK(m_DCSConditionsTool.retrieve()); + return StatusCode::SUCCESS; + +} + +StatusCode +SCT_CalibHvTool::finalize() { + return StatusCode::SUCCESS; +} + +StatusCode +SCT_CalibHvTool::queryInterface(const InterfaceID & riid, void** ppvInterface ) { + if ( ISCT_CalibHistoTool::interfaceID().versionMatch(riid) ) { + *ppvInterface = dynamic_cast<ISCT_CalibHistoTool*>(this); + } else { + return AthAlgTool::queryInterface(riid, ppvInterface); + } + addRef(); + return StatusCode::SUCCESS; +} + +bool +SCT_CalibHvTool::book() { + bool result(true); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Book HVTrips" <<endmsg; + //now initialize the queues (fill 100 spots with 0): + queue<int> qtemp; + initQueue(qtemp, m_maxq,0); + // need to keep previous bins lbn 4 deep. + initQueue(m_prevLBN, 4, 0); + vector< pair <int,int> > dummy; + //first set num events processed to 0 + m_phvtripProcessedEventsInt.insert(m_phvtripProcessedEventsInt.end(), n_elements, 1); + m_phvtripRunningTotalInt.insert(m_phvtripRunningTotalInt.end(), n_elements, 0); + m_phvtripHasItTripped.insert(m_phvtripHasItTripped.end(),n_elements, 0); + m_phvtripQueue.insert(m_phvtripQueue.end(), n_elements, qtemp); + m_summarytrips.insert(m_summarytrips.end(),n_elements, dummy); + m_summarytripslb.insert(m_summarytripslb.end(), n_elements, dummy); + m_phvtripHasItTripped_prev = m_phvtripHasItTripped; + return result; +} + +bool +SCT_CalibHvTool::fill(const bool fromData) { + if (fromData) { + return fillFromData(); + } + bool result(true); + int lumi_block(0); //fix me! + //int event_number; + const int wafersize = m_sct_waferHash->size(); + int time_stamp= m_evt->event_ID()->time_stamp(); + int curr_time = time_stamp; + int dtime = curr_time - m_phvtripPrevTime; + int totalHits = 0; + if (curr_time<m_phvtripPrevTime) { + msg(MSG::ERROR) << "Events not sorted properly (time is going backwards!) " << endmsg; + return false; + } + // for first event + if (m_phvtripFirstTime > curr_time) { + m_phvtripFirstTime = curr_time; + } + bool newbin = false; + // check if we have a new time bin, if we do pop off the back (oldest) part + // of the queue and enqueue 0 for every wafer + int maxtbins(5); + if (dtime > maxtbins) { + newbin = true; + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " new t bin " << dtime <<" since start "<< (curr_time-(m_phvtripFirstTime-1.01)) << endmsg; + m_phvtripHasItTripped_prev = m_phvtripHasItTripped; + for (int iwaf = 0; iwaf!=n_elements; ++iwaf) { + m_phvtripQueue[iwaf].pop(); + m_phvtripQueue[iwaf].push(0); + m_phvtripHasItTripped[iwaf]=0; + } + } + //if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "time stamp "<<time_stamp <<" event number "<< Event_number<<endmsg; + // Loop over all hits in the event + bool isgoodnow; + for( int itrk=0; itrk!=wafersize; ++itrk) { + int waferhash = (*m_sct_waferHash)[itrk]; + Identifier waferId = m_pSCTHelper->wafer_id(waferhash); + Identifier moduleId = m_pSCTHelper->module_id(waferId); + //step one is to make sure this one isn't already know to be messed up: + isgoodnow = m_DCSConditionsTool->isGood(moduleId,InDetConditions::SCT_MODULE); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "checked is good "<< isgoodnow <<endmsg; + if (isgoodnow) { + int numhits = (*m_sct_numHitsInWafer)[itrk]; + totalHits += numhits; + /** + calculate the limit for an individual module, limit is m_relativetriplimit (default = 4) times the running average in that module. + limits are given in hits/second. need to convert numhits in bin to average (within bin) hits/sec. + **/ + double limit = m_relativetriplimit * (double)m_phvtripRunningTotalInt[waferhash] / ((double)curr_time-((double)m_phvtripFirstTime-0.01)); + + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "waferhash "<<waferhash<<" itrk "<<itrk <<" run tot "<< m_phvtripRunningTotalInt[waferhash] + <<" num hits "<<numhits<<" evnts processed "<< m_phvtripProcessedEventsInt[waferhash] <<" limit "<<limit + <<" abs limit, rel limit "<<m_absolutetriplimit<<","<< m_relativetriplimit<<" max bins "<<maxtbins + <<endmsg; + + if ( ((numhits + m_phvtripQueue[waferhash].back() )/ (double)maxtbins ) > m_absolutetriplimit + and ((numhits + m_phvtripQueue[waferhash].back() )/ (double)maxtbins ) > limit) { + //read back queue and see if the high hit rate is persistant for 3 previous bins (a bin is 5 seconds by default) + for (int iq = 0; iq<m_maxq; ++iq) { + m_tq[iq]=m_phvtripQueue[waferhash].front(); + m_phvtripQueue[waferhash].pop(); + } + if (m_tq[m_maxq-2]/(double)maxtbins > limit && m_tq[m_maxq-3]/(double)maxtbins > limit && m_tq[m_maxq-4]/(double)maxtbins > limit) { + // found a persistent trip/thing + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Found a potential trip in SCT wafer "<< waferhash<<endmsg; + //if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "TRIP: "<< waferhash<<" "<<time_stamp <<" "<< Event_number <<" "<< (numhits + m_tq[m_maxq-1] ) <<endmsg; + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "TRIP more info: limit = "<< limit <<" abslimit = "<< m_absolutetriplimit + <<" hits/secs now = "<< ((numhits + m_tq[m_maxq-1])/ maxtbins ) + <<" running total = "<< m_phvtripRunningTotalInt[waferhash] + <<" running average = "<< m_phvtripRunningTotalInt[waferhash] / (curr_time-(m_phvtripFirstTime-1.01)) << endmsg; + m_phvtripHasItTripped[waferhash] = (numhits + m_tq[m_maxq-1] ); + } // end trip found + + //put queue back the way we found it: + for (int iq = 0; iq < m_maxq; ++iq) { + m_phvtripQueue[waferhash].push(m_tq[iq]); + } + } // end potential trip id + //incriment event counter + m_phvtripProcessedEventsInt[waferhash] += 1; + //recalcuate running total: + m_phvtripRunningTotalInt[waferhash] += numhits; + m_phvtripQueue[waferhash].back() += numhits; + } //end is good check + else { + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Was a bad module already: "<< waferhash <<endmsg; + } + } //end loop over tracks + + // text output, summarizing the event + //if new bin summarzie the previous event. + if (newbin) { + SCT_ID::const_id_iterator waferItr = m_waferItrBegin; + SCT_ID::const_id_iterator waferItrE = m_waferItrEnd; + for( ; waferItr not_eq waferItrE; ++waferItr ) { + Identifier waferId = *waferItr; + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + if (m_phvtripHasItTripped_prev[waferHash]>0) { + pair<int,int> wp; + wp.first = (m_phvtripPrevTime - 3*maxtbins); + wp.second = (m_phvtripPrevTime + maxtbins); + m_summarytrips[waferHash].push_back(wp); + pair<int,int> lbn; + lbn.first = m_prevLBN.front(); + lbn.second = m_prevLBN.back(); + m_summarytripslb[waferHash].push_back(lbn); + } + } + m_phvtripPrevTime = curr_time; //reset prev and current time + m_prevLBN.pop(); + m_prevLBN.push(lumi_block); + } + + for (int iwaf(0); iwaf!=n_elements; ++iwaf) { + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "mod "<< iwaf <<" events with that waf " <<m_phvtripProcessedEventsInt[iwaf] << " numhits "<<m_phvtripRunningTotalInt[iwaf] <<endmsg; + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "did it trip "<<m_phvtripHasItTripped[iwaf] << endmsg; + if (m_phvtripHasItTripped[iwaf]) { + //if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "TRIP: "<< iwaf <<" "<<time_stamp <<" "<< Event_number <<" "<< m_phvtripQueue[iwaf].back() <<endmsg; + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "TRIP more info: abslimit = "<< m_absolutetriplimit + <<" hits/secs now = "<< ( m_phvtripQueue[iwaf].back() / maxtbins ) + <<" running total = "<< m_phvtripRunningTotalInt[iwaf] + <<" running average = "<< m_phvtripRunningTotalInt[iwaf] / (curr_time-(m_phvtripFirstTime-1.01)) << endmsg; + } + } + if (m_outputLowHits && (totalHits < m_lowHitCut) ) { + //msg(MSG::WARNING) <<"Event: " << Event_number << " Total hits: " << totalHits << endmsg; + } + return result; +} + +bool +SCT_CalibHvTool::fillFromData() { + bool result(true); + return result; +} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvTool.h new file mode 100644 index 0000000000000000000000000000000000000000..7970874fd2e0dd8b3917e2b0540344a58e810200 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibHvTool.h @@ -0,0 +1,107 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file SCT_CalibHvTool.h + * Header file for the SCT_CalibHvTool class + * @author Shaun Roe +**/ + +#ifndef SCT_CalibHvTool_h +#define SCT_CalibHvTool_h + +//STL includes +#include <string> +#include <vector> +#include <queue> +#include <utility> //for 'pair' + +//Athena includes +#include "AthenaBaseComps/AthAlgTool.h" +#include "StoreGate/StoreGateSvc.h" +#include "GaudiKernel/ToolHandle.h" +#include "GaudiKernel/ServiceHandle.h" + +//Inner detector includes +#include "InDetIdentifier/SCT_ID.h" + +//local includes +#include "SCT_CalibAlgs/ISCT_CalibHistoTool.h" +#include "SCT_ConditionsTools/ISCT_DCSConditionsTool.h" //template parameter + +//fwd declarations +class StatusCode; +class ISvcLocator; +class IdentifierHash; +class EventInfo; + +class SCT_CalibHvTool : public extends<AthAlgTool, ISCT_CalibHistoTool> +{ + + public: + //@name Tool methods, reimplemented + //@{ + SCT_CalibHvTool(const std::string&, const std::string&, const IInterface*); + virtual ~SCT_CalibHvTool() {}; + virtual StatusCode initialize(); + virtual StatusCode finalize(); + //interfaceID() implementation is in the baseclass + virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); + //@} + //@name ISCT_CalibHistoTool methods, reimplemented + //@{ + virtual bool book(); + virtual bool fill(const bool fromData=false); + virtual bool fillFromData(); + //@} + + private: + enum { n_chipPerSide = 6, n_chipPerModule = 12, n_stripPerChip = 128, n_etaInBarrel = 12, + n_phiBinsB0 = 32, n_phiBinsB1 = 40, n_phiBinsB2 = 48, n_phiBinsB3 = 56, + n_phiBinsECShort = 40, n_phiBinsECMiddle = 40, n_phiBinsECOuter = 52, n_elements=8176, + n_BSErrorType = 15, firstBSErrorType = 0, lastBSErrorType = 14 + }; + + ServiceHandle<StoreGateSvc> m_detStore; + ServiceHandle<StoreGateSvc> m_evtStore; + ToolHandle<ISCT_DCSConditionsTool> m_DCSConditionsTool{this, "SCT_DCSConditionsTool", "SCT_DCSConditionsTool", "Tool to retrieve SCT DCS information"}; + + const SCT_ID* m_pSCTHelper; + SCT_ID::const_id_iterator m_waferItrBegin; + SCT_ID::const_id_iterator m_waferItrEnd; + typedef std::vector<int> VecInt; + VecInt *m_sct_waferHash; + VecInt *m_sct_numHitsInWafer; + mutable int m_lumiBlock; + + //private use in this class + int m_maxq; + // For HV trips + std::vector< std::queue<int> > m_phvtripQueue; + std::queue<int> m_prevLBN; + VecInt m_phvtripRunningTotalInt; + VecInt m_phvtripProcessedEventsInt; + VecInt m_phvtripHasItTripped; + VecInt m_phvtripHasItTripped_prev; + // + int m_phvtripPrevTime; + int m_phvtripFirstTime; + double m_absolutetriplimit; + double m_relativetriplimit; + int m_tq[100]; + + std::vector< std::vector< std::pair<int, int> > > m_summarytrips; + std::vector< std::vector< std::pair<int, int> > > m_summarytripslb; + const EventInfo* m_evt; + bool m_outputLowHits; + int m_lowHitCut; + ///retrieve a tool and report if it failed + template<class T> + bool retrievedTool(T & tool, const std::string & toolName) { + if (tool.retrieve().isFailure() ) return msg(MSG::ERROR)<<"Unable to retrieve "<<toolName<<endmsg, false; + return true; + } + +}; +#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbSvc.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbSvc.cxx deleted file mode 100644 index e549ccc45ad46ea154d3d75bf6eb6aa9a186620e..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbSvc.cxx +++ /dev/null @@ -1,301 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - - -/** - * @file SCT_CalibLbSvc.cxx - * Implementation file for the SCT_CalibLbSvc class - * @author Shaun Roe -**/ - -#include "SCT_CalibLbSvc.h" -#include "SCT_CalibUtilities.h" -#include "SCT_CalibNumbers.h" -#include "SCT_CalibEventInfo.h" - -//InnerDetector -#include "InDetReadoutGeometry/SiDetectorElement.h" -#include "InDetReadoutGeometry/SCT_DetectorManager.h" - -#include "InDetRawData/SCT3_RawData.h" -#include "InDetRawData/InDetRawDataCLASS_DEF.h" - -#include "StoreGate/ReadHandle.h" - -#include "Identifier/Identifier.h" -#include "Identifier/IdentifierHash.h" -#include "GaudiKernel/ITHistSvc.h" - -#include <boost/lexical_cast.hpp> - -#include "TH1I.h" -#include "TH1F.h" -#include "TH2F.h" -#include "TFile.h" -#include "TMath.h" - -using namespace std; -using namespace SCT_CalibAlgs; - -const static string pathRoot("/LB/"); -const static int n_chipsPerSide(6); -const static int n_stripsPerChip(128); -const static string detectorNames[] = { "negativeEndcap", "barrel", "positiveEndcap" }; -const static string detectorPaths[]={"SCTEC/", "SCTB/","SCTEA/"}; - - - -SCT_CalibLbSvc::SCT_CalibLbSvc(const std::string &name, ISvcLocator * svc):AthService(name,svc), -m_detStore("DetectorStore", name), -m_evtStore("StoreGateSvc", name), -m_evtInfo("SCT_CalibEventInfo",name), -m_pSCTHelper(0), -m_pManager(0), -m_sct_waferHash(0), -m_sct_firstStrip(0), -m_sct_rdoGroupSize(0), -m_lumiBlock(0), -m_LbRange(0), -m_LbsToMerge(0), -m_rdoContainerKey(std::string("SCT_RDOs")) { - //nop -} - -StatusCode -SCT_CalibLbSvc::initialize(){ - msg( MSG::INFO)<<"Initialize of "<<PACKAGE_VERSION<<endmsg; - if ( service( "THistSvc", m_thistSvc ).isFailure() ) return msg( MSG::ERROR) << "Unable to retrieve pointer to THistSvc" << endmsg, StatusCode::FAILURE; - if ( m_detStore->retrieve( m_pSCTHelper, "SCT_ID").isFailure()) return msg( MSG::ERROR) << "Unable to retrieve SCTHelper" << endmsg, StatusCode::FAILURE; - if ( m_detStore->retrieve( m_pManager, "SCT").isFailure() ) return msg( MSG::ERROR) << "Unable to retrieve SCTManager" << endmsg,StatusCode::FAILURE; - std::pair<std::string, bool> msgCode=retrievedService(m_evtInfo); - if (not msgCode.second) return msg( MSG::ERROR) <<msgCode.first<< endmsg,StatusCode::FAILURE; - // - m_waferItrBegin = m_pSCTHelper->wafer_begin(); - m_waferItrEnd = m_pSCTHelper->wafer_end(); - - m_LbRange=numberOfLb(); - - // Read Handle Key - ATH_CHECK( m_rdoContainerKey.initialize() ); - - return StatusCode::SUCCESS; - -} - - -StatusCode -SCT_CalibLbSvc::finalize(){ - msg( MSG::INFO)<<"Finalize of "<<PACKAGE_VERSION<<endmsg; - return StatusCode::SUCCESS; -} - -StatusCode -SCT_CalibLbSvc::queryInterface(const InterfaceID & riid, void** ppvInterface ){ - if ( ISCT_CalibHistoSvc::interfaceID().versionMatch(riid) ) { - *ppvInterface = dynamic_cast<ISCT_CalibHistoSvc*>(this); - } else { - return AthService::queryInterface(riid, ppvInterface); - } - addRef(); - return StatusCode::SUCCESS; -} - -bool -SCT_CalibLbSvc::book(){ - msg( MSG::INFO)<<"book() method of "<<PACKAGE_VERSION<<endmsg; - bool result(true); - //pointers to the histos are deleted by m_thistSvc methods - m_phistoVector.clear(); - m_phistoVector2D.clear(); - string histoName=pathRoot+"GENERAL/"; - m_LbRange=numberOfLb(); - m_numberOfEventsHisto=new TH1I("events","Events",m_LbRange,0.5,m_LbRange+0.5); - - m_LbsToMerge = LbToMerge(); - int yAxisBins = TMath::Ceil(1.0*m_LbRange/m_LbsToMerge); - - - if( m_thistSvc->regHist( histoName.c_str(), m_numberOfEventsHisto ).isFailure() ) { - msg( MSG::ERROR ) << "Error in booking EventNumber histogram" << endmsg; - } - //histograms for each wafer - SCT_ID::const_id_iterator waferItr = m_waferItrBegin; - //// - std::string hitmapPaths[3]; - for (int i(0);i<3;++i){ - hitmapPaths[i]=pathRoot+detectorPaths[i]; - } - //// - for(; waferItr !=m_waferItrEnd;++waferItr){ - const Identifier &waferId=*waferItr; - const int bec(m_pSCTHelper->barrel_ec(waferId)); - const string formattedPosition=formatPosition(waferId, m_pSCTHelper)+"_"; - //// - std::string histotitle = string( "SCT " ) + detectorNames[ bec2Index(bec) ] + string( " Hitmap: plane " ) + formattedPosition; - std::string formattedPosition2D = formattedPosition+"_2D"; - std::string name2D=hitmapPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition + "_2D"; - // TH2F* hitmapHistoLB_tmp2D = new TH2F( TString( formattedPosition2D ), TString( histotitle ), nbins, firstStrip-0.5, lastStrip+0.5 ,1,0,0); - TH2F* hitmapHistoLB_tmp2D = new TH2F( TString( formattedPosition2D ), TString( histotitle ), nbins, firstStrip-0.5, lastStrip+0.5 ,yAxisBins,0.5,m_LbsToMerge*yAxisBins+0.5); - // hitmapHistoLB_tmp2D->GetYaxis()->SetCanExtend(kTRUE); - // TH2F* hitmapHistoLB_tmp2D = new TH2F( TString( formattedPosition2D ), TString( histotitle ), nbins, firstStrip-0.5, lastStrip+0.5 ,m_LbRange,0.5,m_LbRange+0.5); - if(m_thistSvc->regHist( name2D.c_str(), hitmapHistoLB_tmp2D ).isFailure() ) { - msg( MSG::ERROR ) << "Error in booking 2D Hitmap histogram" << endmsg; - } else { - // m_phistoVector.push_back( hitmapHisto_tmp ); - m_phistoVector2D.push_back( hitmapHistoLB_tmp2D ); - } - //// - for (int iChip(0);iChip!=n_chipsPerSide;++iChip){ - int chipId= m_pSCTHelper->side(waferId)==0 ? iChip:iChip+n_chipsPerSide; - const string formattedChipPosition = formattedPosition + boost::lexical_cast<string>(chipId); - const string hname= pathRoot+detectorPaths[bec2Index(bec)]+"/"+formattedChipPosition; - const string histTitle = string("SCT")+detectorNames[bec2Index(bec)]+string(" LB: chip ")+formattedChipPosition; - TH1F* hist_tmp = new TH1F(TString(formattedChipPosition), TString(histTitle), m_LbRange, 0.5, m_LbRange+0.5); - if(m_thistSvc->regHist(hname.c_str(), hist_tmp).isFailure() ) msg(MSG::ERROR)<<"Error in booking LB histogram"<<endl; - m_phistoVector.push_back(hist_tmp); - } - } - return result; -} - -bool -SCT_CalibLbSvc::read(const std::string & fileName){ - msg( MSG::INFO)<<"read() method of "<<PACKAGE_VERSION<<endmsg; - bool result(true); - m_LbRange=numberOfLb(); - //pointers to the histos are deleted by m_thistSvc methods - m_phistoVector.clear(); - m_phistoVector2D.clear(); - TFile *fileLB = TFile::Open( fileName.c_str() ); - msg( MSG::INFO ) << "opening LB file : " << fileName.c_str() << endmsg; - - if(fileLB){ - m_numberOfEventsHisto= (TH1I*) fileLB->Get("GENERAL/events"); - } else { - msg( MSG::ERROR ) << "can not open LB file : " << fileName.c_str() << endmsg; - return result; - } - - if( m_numberOfEventsHisto==NULL ) { - msg( MSG::ERROR ) << "Error in reading EventNumber histogram" << endmsg; - } - //std::cout<<"new of m_numberOfEventsHisto, value = "<<m_numberOfEventsHisto<<std::endl; - //histograms for each wafer - SCT_ID::const_id_iterator waferItr = m_waferItrBegin; - for(; waferItr !=m_waferItrEnd;++waferItr){ - const Identifier &waferId=*waferItr; - const int bec(m_pSCTHelper->barrel_ec(waferId)); - const string formattedPosition=formatPosition(waferId, m_pSCTHelper)+"_"; - //// - std::string name2D=detectorPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition + "_2D"; - TH2F* hitmapHistoLB_tmp2D = (TH2F*) fileLB->Get(name2D.c_str()); - // hitmapHistoLB_tmp2D->GetYaxis()->SetCanExtend(kTRUE); - - if( hitmapHistoLB_tmp2D==NULL ) { - msg( MSG::ERROR ) << "Error in reading Hitmap histogram" << endmsg; - } else { - m_phistoVector2D.push_back( hitmapHistoLB_tmp2D ); - } - //// - for (int iChip(0);iChip!=n_chipsPerSide;++iChip){ - int chipId= m_pSCTHelper->side(waferId)==0 ? iChip : iChip+n_chipsPerSide; - const string hname= detectorPaths[bec2Index(bec)]+"/"+formattedPosition + boost::lexical_cast<string>(chipId); - TH1F* hist_tmp = (TH1F*) fileLB->Get(hname.c_str()); - if( hist_tmp==NULL ) { - msg( MSG::ERROR ) << "Error in reading LB histogram" << endmsg; - } else { - m_phistoVector.push_back(hist_tmp); - } - } - } - return result; -} - -bool -SCT_CalibLbSvc::fill(const bool fromData){ - if (fromData){ - return fillFromData(); - } - m_numberOfEventsHisto->Fill(m_lumiBlock); - bool result(true); - int maxEntry = m_sct_waferHash->size(); - for( int i = 0; i != maxEntry; ++i ) { - int theFirstStrip = (*m_sct_firstStrip)[i]; - // - int endStrip = (*m_sct_rdoGroupSize)[i] + theFirstStrip; - int index = (*m_sct_waferHash)[i]; - TH2F * pThisHisto2D=m_phistoVector2D[ index ]; - // pThisHisto2D->GetYaxis()->SetCanExtend(kTRUE); - - for( int strip(theFirstStrip); strip !=endStrip; ++strip) { - pThisHisto2D->Fill( strip, m_lumiBlock); - } - // - int rdoGroupSize = (*m_sct_rdoGroupSize)[i]; - IdentifierHash waferHash = (*m_sct_waferHash)[i]; - fillLbForWafer(waferHash, theFirstStrip, rdoGroupSize); - } - - return result; -} - -bool -SCT_CalibLbSvc::fillFromData(){ - if (not m_evtInfo) return msg( MSG::ERROR ) << "The evtInfo pointer is NULL" << endmsg, false; - m_lumiBlock=m_evtInfo->lumiBlock(); - m_numberOfEventsHisto->Fill(m_lumiBlock); - bool result(true); - //--- Retrieve the RDO container - typedef SCT_RDORawData SCTRawDataType; - SG::ReadHandle<SCT_RDO_Container> p_rdoContainer(m_rdoContainerKey); - if ( not p_rdoContainer.isValid() ) { - msg( MSG::ERROR ) << "Failed to retrieve SCT RDO container" << endmsg; - } - - SCT_RDO_Container::const_iterator itr = p_rdoContainer->begin(); - SCT_RDO_Container::const_iterator itrE = p_rdoContainer->end(); - for( ; itr != itrE; ++itr ) { - const InDetRawDataCollection<SCTRawDataType>* SCT_Collection( *itr ); - if ( !SCT_Collection ) continue;// select only SCT RDOs - Identifier waferId = SCT_Collection->identify(); - IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); - //// - TH2F * pThisHisto2D =m_phistoVector2D[(int)waferHash]; - //// - DataVector<SCTRawDataType>::const_iterator rdoItr = SCT_Collection->begin(); - DataVector<SCTRawDataType>::const_iterator rdoItrE = SCT_Collection->end(); - for( ; rdoItr != rdoItrE; ++rdoItr ) { - int theFirstStrip = m_pSCTHelper->strip((*rdoItr)->identify()); - //// - int strip=m_pSCTHelper->strip((*rdoItr)->identify()); - const int endStrip=(*rdoItr)->getGroupSize() + strip; - for (;strip != endStrip;++strip){ - pThisHisto2D->Fill( strip, m_lumiBlock); - } - //// - int rdoGroupSize = (*rdoItr)->getGroupSize(); - fillLbForWafer(waferHash, theFirstStrip, rdoGroupSize); - } - } - - return result; -} - -void -SCT_CalibLbSvc::fillLbForWafer(const IdentifierHash &waferHash, const int theFirstStrip, const int groupSize ){ - const InDetDD::SiDetectorElement* pElement = m_pManager->getDetectorElement( waferHash ); - - if ( pElement) { - int stripNumber = ( pElement->swapPhiReadoutDirection() ) ? lastStrip - theFirstStrip : theFirstStrip; - int index = ((int)waferHash)*n_chipsPerSide + stripNumber/n_stripsPerChip; - //--- Fill LB histograms - for( int j = 0; j != groupSize; ++j ) { - m_phistoVector[ index ]->Fill( m_lumiBlock ); - } - - } else { - msg( MSG::FATAL ) << "Element pointer is NULL" << endmsg; - } - -} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbSvc.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbSvc.h deleted file mode 100644 index ae62bde8cc7443c0b6a2c3bb4a918b22c7166f91..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbSvc.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file SCT_CalibLbSvc.h - * Header file for the SCT_CalibLbSvc class - * @author Shaun Roe -**/ - -#ifndef SCT_CalibLbSvc_h -#define SCT_CalibLbSvc_h - -//STL includes -#include <string> - -//Athena includes -#include "AthenaBaseComps/AthService.h" -#include "StoreGate/StoreGateSvc.h" -#include "StoreGate/ReadHandleKey.h" -#include "GaudiKernel/ServiceHandle.h" -#include "SCT_CalibAlgs/ISCT_CalibEvtInfo.h" -#include "InDetRawData/SCT_RDO_Container.h" - -//Inner detector includes -#include "InDetIdentifier/SCT_ID.h" - -//local includes -#include "SCT_CalibAlgs/ISCT_CalibHistoSvc.h" - -//fwd declarations -template <class TYPE> class SvcFactory; -namespace InDetDD{ - class SCT_DetectorManager; -} -class StatusCode; -class ISvcLocator; -class IdentifierHash; - -class SCT_CalibLbSvc: virtual public ISCT_CalibHistoSvc, public AthService{ - friend class SvcFactory<SCT_CalibLbSvc>; - -public: - //@name Service methods, reimplemented - //@{ - SCT_CalibLbSvc(const std::string &name, ISvcLocator * svc); - virtual ~SCT_CalibLbSvc(){} - virtual StatusCode initialize(); - virtual StatusCode finalize(); - //interfaceID() implementation is in the baseclass - virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); - //@} - //@name ISCT_CalibHistoSvc methods, reimplemented - //@{ - virtual bool book(); - virtual bool fill(const bool fromData=false); - virtual bool read(const std::string & fileName); - virtual bool fillFromData(); - //@} -private: - ServiceHandle<StoreGateSvc> m_detStore; - ServiceHandle<StoreGateSvc> m_evtStore; - ServiceHandle<ISCT_CalibEvtInfo> m_evtInfo; - - const SCT_ID* m_pSCTHelper; - const InDetDD::SCT_DetectorManager* m_pManager; - SCT_ID::const_id_iterator m_waferItrBegin; - SCT_ID::const_id_iterator m_waferItrEnd; - typedef std::vector<int> VecInt; - VecInt *m_sct_waferHash; - VecInt *m_sct_firstStrip; - VecInt *m_sct_rdoGroupSize; - - mutable int m_lumiBlock; - - //private use in this class - int m_LbRange; - int m_LbsToMerge; - - SG::ReadHandleKey<SCT_RDO_Container> m_rdoContainerKey; - - void - fillLbForWafer(const IdentifierHash &waferHash, const int theFirstStrip, const int groupSize ); - -}; -#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0ad0ddc382a9ddd9512b4adb0cc52368a76149b4 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.cxx @@ -0,0 +1,300 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +/** + * @file SCT_CalibLbTool.cxx + * Implementation file for the SCT_CalibLbTool class + * @author Shaun Roe +**/ + +#include "SCT_CalibLbTool.h" +#include "SCT_CalibUtilities.h" +#include "SCT_CalibNumbers.h" +#include "SCT_CalibEventInfo.h" + +//InnerDetector +#include "InDetReadoutGeometry/SiDetectorElement.h" +#include "InDetReadoutGeometry/SCT_DetectorManager.h" + +#include "InDetRawData/SCT3_RawData.h" +#include "InDetRawData/InDetRawDataCLASS_DEF.h" + +#include "StoreGate/ReadHandle.h" + +#include "Identifier/Identifier.h" +#include "Identifier/IdentifierHash.h" +#include "GaudiKernel/ITHistSvc.h" + +#include <boost/lexical_cast.hpp> + +#include "TH1I.h" +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TMath.h" + +using namespace std; +using namespace SCT_CalibAlgs; + +const static string pathRoot("/LB/"); +const static int n_chipsPerSide(6); +const static int n_stripsPerChip(128); +const static string detectorNames[] = { "negativeEndcap", "barrel", "positiveEndcap" }; +const static string detectorPaths[]= {"SCTEC/", "SCTB/","SCTEA/"}; + + +SCT_CalibLbTool::SCT_CalibLbTool(const std::string& type, const std::string& name, const IInterface* parent) : + base_class(type, name, parent), + m_detStore("DetectorStore", name), + m_evtStore("StoreGateSvc", name), + m_evtInfo("SCT_CalibEventInfo",name), + m_pSCTHelper(0), + m_pManager(0), + m_sct_waferHash(0), + m_sct_firstStrip(0), + m_sct_rdoGroupSize(0), + m_lumiBlock(0), + m_LbRange(0), + m_LbsToMerge(0), + m_rdoContainerKey(std::string("SCT_RDOs")) +{ + //nop +} + +StatusCode +SCT_CalibLbTool::initialize() { + msg( MSG::INFO)<<"Initialize of "<<PACKAGE_VERSION<<endmsg; + if ( service( "THistSvc", m_thistSvc ).isFailure() ) return msg( MSG::ERROR) << "Unable to retrieve pointer to THistSvc" << endmsg, StatusCode::FAILURE; + if ( m_detStore->retrieve( m_pSCTHelper, "SCT_ID").isFailure()) return msg( MSG::ERROR) << "Unable to retrieve SCTHelper" << endmsg, StatusCode::FAILURE; + if ( m_detStore->retrieve( m_pManager, "SCT").isFailure() ) return msg( MSG::ERROR) << "Unable to retrieve SCTManager" << endmsg,StatusCode::FAILURE; + std::pair<std::string, bool> msgCode=retrievedTool(m_evtInfo); + if (not msgCode.second) return msg( MSG::ERROR) <<msgCode.first<< endmsg,StatusCode::FAILURE; + // + m_waferItrBegin = m_pSCTHelper->wafer_begin(); + m_waferItrEnd = m_pSCTHelper->wafer_end(); + + m_LbRange=numberOfLb(); + + // Read Handle Key + ATH_CHECK( m_rdoContainerKey.initialize() ); + + return StatusCode::SUCCESS; +} + +StatusCode +SCT_CalibLbTool::finalize() { + msg( MSG::INFO)<<"Finalize of "<<PACKAGE_VERSION<<endmsg; + return StatusCode::SUCCESS; +} + +StatusCode +SCT_CalibLbTool::queryInterface(const InterfaceID & riid, void** ppvInterface ) { + if ( ISCT_CalibHistoTool::interfaceID().versionMatch(riid) ) { + *ppvInterface = dynamic_cast<ISCT_CalibHistoTool*>(this); + } else { + return AthAlgTool::queryInterface(riid, ppvInterface); + } + addRef(); + return StatusCode::SUCCESS; +} + +bool +SCT_CalibLbTool::book() { + msg( MSG::INFO)<<"book() method of "<<PACKAGE_VERSION<<endmsg; + bool result(true); + //pointers to the histos are deleted by m_thistSvc methods + m_phistoVector.clear(); + m_phistoVector2D.clear(); + string histoName=pathRoot+"GENERAL/"; + m_LbRange=numberOfLb(); + m_numberOfEventsHisto=new TH1I("events","Events",m_LbRange,0.5,m_LbRange+0.5); + + m_LbsToMerge = LbToMerge(); + int yAxisBins = TMath::Ceil(1.0*m_LbRange/m_LbsToMerge); + + + if( m_thistSvc->regHist( histoName.c_str(), m_numberOfEventsHisto ).isFailure() ) { + msg( MSG::ERROR ) << "Error in booking EventNumber histogram" << endmsg; + } + //histograms for each wafer + SCT_ID::const_id_iterator waferItr = m_waferItrBegin; + //// + std::string hitmapPaths[3]; + for (int i(0); i<3; ++i) { + hitmapPaths[i]=pathRoot+detectorPaths[i]; + } + //// + for(; waferItr !=m_waferItrEnd; ++waferItr) { + const Identifier &waferId=*waferItr; + const int bec(m_pSCTHelper->barrel_ec(waferId)); + const string formattedPosition=formatPosition(waferId, m_pSCTHelper)+"_"; + //// + std::string histotitle = string( "SCT " ) + detectorNames[ bec2Index(bec) ] + string( " Hitmap: plane " ) + formattedPosition; + std::string formattedPosition2D = formattedPosition+"_2D"; + std::string name2D=hitmapPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition + "_2D"; + // TH2F* hitmapHistoLB_tmp2D = new TH2F( TString( formattedPosition2D ), TString( histotitle ), nbins, firstStrip-0.5, lastStrip+0.5 ,1,0,0); + TH2F* hitmapHistoLB_tmp2D = new TH2F( TString( formattedPosition2D ), TString( histotitle ), nbins, firstStrip-0.5, lastStrip+0.5,yAxisBins,0.5,m_LbsToMerge*yAxisBins+0.5); + // hitmapHistoLB_tmp2D->GetYaxis()->SetCanExtend(kTRUE); + // TH2F* hitmapHistoLB_tmp2D = new TH2F( TString( formattedPosition2D ), TString( histotitle ), nbins, firstStrip-0.5, lastStrip+0.5 ,m_LbRange,0.5,m_LbRange+0.5); + if(m_thistSvc->regHist( name2D.c_str(), hitmapHistoLB_tmp2D ).isFailure() ) { + msg( MSG::ERROR ) << "Error in booking 2D Hitmap histogram" << endmsg; + } else { + // m_phistoVector.push_back( hitmapHisto_tmp ); + m_phistoVector2D.push_back( hitmapHistoLB_tmp2D ); + } + //// + for (int iChip(0); iChip!=n_chipsPerSide; ++iChip) { + int chipId= m_pSCTHelper->side(waferId)==0 ? iChip:iChip+n_chipsPerSide; + const string formattedChipPosition = formattedPosition + boost::lexical_cast<string>(chipId); + const string hname= pathRoot+detectorPaths[bec2Index(bec)]+"/"+formattedChipPosition; + const string histTitle = string("SCT")+detectorNames[bec2Index(bec)]+string(" LB: chip ")+formattedChipPosition; + TH1F* hist_tmp = new TH1F(TString(formattedChipPosition), TString(histTitle), m_LbRange, 0.5, m_LbRange+0.5); + if(m_thistSvc->regHist(hname.c_str(), hist_tmp).isFailure() ) msg(MSG::ERROR)<<"Error in booking LB histogram"<<endl; + m_phistoVector.push_back(hist_tmp); + } + } + return result; +} + +bool +SCT_CalibLbTool::read(const std::string & fileName) { + msg( MSG::INFO)<<"read() method of "<<PACKAGE_VERSION<<endmsg; + bool result(true); + m_LbRange=numberOfLb(); + //pointers to the histos are deleted by m_thistSvc methods + m_phistoVector.clear(); + m_phistoVector2D.clear(); + TFile *fileLB = TFile::Open( fileName.c_str() ); + msg( MSG::INFO ) << "opening LB file : " << fileName.c_str() << endmsg; + + if(fileLB) { + m_numberOfEventsHisto= (TH1I*) fileLB->Get("GENERAL/events"); + } else { + msg( MSG::ERROR ) << "can not open LB file : " << fileName.c_str() << endmsg; + return result; + } + + if( m_numberOfEventsHisto==NULL ) { + msg( MSG::ERROR ) << "Error in reading EventNumber histogram" << endmsg; + } + //std::cout<<"new of m_numberOfEventsHisto, value = "<<m_numberOfEventsHisto<<std::endl; + //histograms for each wafer + SCT_ID::const_id_iterator waferItr = m_waferItrBegin; + for(; waferItr !=m_waferItrEnd; ++waferItr) { + const Identifier &waferId=*waferItr; + const int bec(m_pSCTHelper->barrel_ec(waferId)); + const string formattedPosition=formatPosition(waferId, m_pSCTHelper)+"_"; + //// + std::string name2D=detectorPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition + "_2D"; + TH2F* hitmapHistoLB_tmp2D = (TH2F*) fileLB->Get(name2D.c_str()); + // hitmapHistoLB_tmp2D->GetYaxis()->SetCanExtend(kTRUE); + + if( hitmapHistoLB_tmp2D==NULL ) { + msg( MSG::ERROR ) << "Error in reading Hitmap histogram" << endmsg; + } else { + m_phistoVector2D.push_back( hitmapHistoLB_tmp2D ); + } + //// + for (int iChip(0); iChip!=n_chipsPerSide; ++iChip) { + int chipId= m_pSCTHelper->side(waferId)==0 ? iChip : iChip+n_chipsPerSide; + const string hname= detectorPaths[bec2Index(bec)]+"/"+formattedPosition + boost::lexical_cast<string>(chipId); + TH1F* hist_tmp = (TH1F*) fileLB->Get(hname.c_str()); + if( hist_tmp==NULL ) { + msg( MSG::ERROR ) << "Error in reading LB histogram" << endmsg; + } else { + m_phistoVector.push_back(hist_tmp); + } + } + } + return result; +} + +bool +SCT_CalibLbTool::fill(const bool fromData) { + if (fromData) { + return fillFromData(); + } + m_numberOfEventsHisto->Fill(m_lumiBlock); + bool result(true); + int maxEntry = m_sct_waferHash->size(); + for( int i = 0; i != maxEntry; ++i ) { + int theFirstStrip = (*m_sct_firstStrip)[i]; + // + int endStrip = (*m_sct_rdoGroupSize)[i] + theFirstStrip; + int index = (*m_sct_waferHash)[i]; + TH2F * pThisHisto2D=m_phistoVector2D[ index ]; + // pThisHisto2D->GetYaxis()->SetCanExtend(kTRUE); + + for( int strip(theFirstStrip); strip !=endStrip; ++strip) { + pThisHisto2D->Fill( strip, m_lumiBlock); + } + // + int rdoGroupSize = (*m_sct_rdoGroupSize)[i]; + IdentifierHash waferHash = (*m_sct_waferHash)[i]; + fillLbForWafer(waferHash, theFirstStrip, rdoGroupSize); + } + + return result; +} + +bool +SCT_CalibLbTool::fillFromData() { + if (not m_evtInfo) return msg( MSG::ERROR ) << "The evtInfo pointer is NULL" << endmsg, false; + m_lumiBlock=m_evtInfo->lumiBlock(); + m_numberOfEventsHisto->Fill(m_lumiBlock); + bool result(true); + //--- Retrieve the RDO container + typedef SCT_RDORawData SCTRawDataType; + SG::ReadHandle<SCT_RDO_Container> p_rdoContainer(m_rdoContainerKey); + if ( not p_rdoContainer.isValid() ) { + msg( MSG::ERROR ) << "Failed to retrieve SCT RDO container" << endmsg; + } + + SCT_RDO_Container::const_iterator itr = p_rdoContainer->begin(); + SCT_RDO_Container::const_iterator itrE = p_rdoContainer->end(); + for( ; itr != itrE; ++itr ) { + const InDetRawDataCollection<SCTRawDataType>* SCT_Collection( *itr ); + if ( !SCT_Collection ) continue;// select only SCT RDOs + Identifier waferId = SCT_Collection->identify(); + IdentifierHash waferHash = m_pSCTHelper->wafer_hash( waferId ); + //// + TH2F * pThisHisto2D =m_phistoVector2D[(int)waferHash]; + //// + DataVector<SCTRawDataType>::const_iterator rdoItr = SCT_Collection->begin(); + DataVector<SCTRawDataType>::const_iterator rdoItrE = SCT_Collection->end(); + for( ; rdoItr != rdoItrE; ++rdoItr ) { + int theFirstStrip = m_pSCTHelper->strip((*rdoItr)->identify()); + //// + int strip=m_pSCTHelper->strip((*rdoItr)->identify()); + const int endStrip=(*rdoItr)->getGroupSize() + strip; + for (; strip != endStrip; ++strip) { + pThisHisto2D->Fill( strip, m_lumiBlock); + } + //// + int rdoGroupSize = (*rdoItr)->getGroupSize(); + fillLbForWafer(waferHash, theFirstStrip, rdoGroupSize); + } + } + + return result; +} + +void +SCT_CalibLbTool::fillLbForWafer(const IdentifierHash &waferHash, const int theFirstStrip, const int groupSize ) { + const InDetDD::SiDetectorElement* pElement = m_pManager->getDetectorElement( waferHash ); + + if ( pElement) { + int stripNumber = ( pElement->swapPhiReadoutDirection() ) ? lastStrip - theFirstStrip : theFirstStrip; + int index = ((int)waferHash)*n_chipsPerSide + stripNumber/n_stripsPerChip; + //--- Fill LB histograms + for( int j = 0; j != groupSize; ++j ) { + m_phistoVector[ index ]->Fill( m_lumiBlock ); + } + + } else { + msg( MSG::FATAL ) << "Element pointer is NULL" << endmsg; + } + +} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.h new file mode 100644 index 0000000000000000000000000000000000000000..956d7a3b3d26bae20c6324a0b4503dcc3dfb3646 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibLbTool.h @@ -0,0 +1,87 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file SCT_CalibLbTool.h + * Header file for the SCT_CalibLbTool class + * @author Shaun Roe +**/ + +#ifndef SCT_CalibLbTool_h +#define SCT_CalibLbTool_h + +//STL includes +#include <string> + +//Athena includes +#include "AthenaBaseComps/AthAlgTool.h" +#include "StoreGate/StoreGateSvc.h" +#include "StoreGate/ReadHandleKey.h" +#include "GaudiKernel/ToolHandle.h" +#include "SCT_CalibAlgs/ISCT_CalibEvtInfo.h" +#include "InDetRawData/SCT_RDO_Container.h" + +//Inner detector includes +#include "InDetIdentifier/SCT_ID.h" + +//local includes +#include "SCT_CalibAlgs/ISCT_CalibHistoTool.h" + +//fwd declarations + +namespace InDetDD { +class SCT_DetectorManager; +} +class StatusCode; +class ISvcLocator; +class IdentifierHash; + +class SCT_CalibLbTool : public extends<AthAlgTool, ISCT_CalibHistoTool> +{ + + public: + //@name Tool methods, reimplemented + //@{ + SCT_CalibLbTool(const std::string&, const std::string&, const IInterface*); + virtual ~SCT_CalibLbTool() {}; + virtual StatusCode initialize(); + virtual StatusCode finalize(); + //interfaceID() implementation is in the baseclass + virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); + //@} + //@name ISCT_CalibHistoTool methods, reimplemented + //@{ + virtual bool book(); + virtual bool fill(const bool fromData=false); + virtual bool read(const std::string & fileName); + virtual bool fillFromData(); + //@} + + private: + ServiceHandle<StoreGateSvc> m_detStore; + ServiceHandle<StoreGateSvc> m_evtStore; + ServiceHandle<ISCT_CalibEvtInfo> m_evtInfo; + + const SCT_ID* m_pSCTHelper; + const InDetDD::SCT_DetectorManager* m_pManager; + SCT_ID::const_id_iterator m_waferItrBegin; + SCT_ID::const_id_iterator m_waferItrEnd; + typedef std::vector<int> VecInt; + VecInt *m_sct_waferHash; + VecInt *m_sct_firstStrip; + VecInt *m_sct_rdoGroupSize; + + mutable int m_lumiBlock; + + //private use in this class + int m_LbRange; + int m_LbsToMerge; + + SG::ReadHandleKey<SCT_RDO_Container> m_rdoContainerKey; + + void + fillLbForWafer(const IdentifierHash &waferHash, const int theFirstStrip, const int groupSize ); + +}; +#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListSvc.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListSvc.cxx deleted file mode 100644 index 78db75b9d06e12e2b0cb25556a8883e082ec3c7e..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListSvc.cxx +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -#include "SCT_CalibModuleListSvc.h" - -SCT_CalibModuleListSvc::SCT_CalibModuleListSvc(const std::string& name, ISvcLocator* pSvcLocator ) : - AthService(name, pSvcLocator), - m_pSCTHelper(0), - m_detStore("DetectorStore", name), - m_IOVDbSvc( "IOVDbSvc", name ){ - -} - -SCT_CalibModuleListSvc::~SCT_CalibModuleListSvc(){ - //nop -} - - -StatusCode SCT_CalibModuleListSvc::initialize(){ - if (msgLvl(MSG::DEBUG)) msg(MSG:: DEBUG) << "Initializing SCT_CalibModuleListSvc " << endmsg; - - StatusCode sc = m_detStore->retrieve( m_pSCTHelper, "SCT_ID" ); - if ( sc.isFailure() ) { - msg( MSG::ERROR ) << "Unable to retrieve SCTHelper" << endmsg; - return sc; - } - - sc = m_MonitorConditionsTool.retrieve(); - if ( sc.isFailure() ) { - msg( MSG::ERROR ) << "Unable to retrieve MonitorConditionsSvc" << endmsg; - return sc; - } - - sc = m_IOVDbSvc.retrieve(); - if ( sc.isFailure() ) { - msg( MSG::ERROR ) << "Unable to retrieve IOVDbSvc" << endmsg; - return sc; - } - - return StatusCode::SUCCESS; - -} - -StatusCode SCT_CalibModuleListSvc::finalize(){ - return StatusCode::SUCCESS; -} - -StatusCode -SCT_CalibModuleListSvc::queryInterface(const InterfaceID & riid, void** ppvInterface ){ - if ( ISCT_CalibModuleListSvc::interfaceID().versionMatch(riid) ) { - *ppvInterface = dynamic_cast<ISCT_CalibModuleListSvc*>(this); - } else { - return AthService::queryInterface(riid, ppvInterface); - } - addRef(); - return StatusCode::SUCCESS; -} - -StatusCode SCT_CalibModuleListSvc::readModuleList( std::map< Identifier, std::set<Identifier> >& moduleList ) { - //--- Read strips using SCT_MonitorConditionsSvc - SCT_ID::const_id_iterator waferIdItr = m_pSCTHelper->wafer_begin(); - SCT_ID::const_id_iterator waferIdItrE = m_pSCTHelper->wafer_end(); - for( ; waferIdItr != waferIdItrE; ++waferIdItr ) { - if ( m_pSCTHelper->side( *waferIdItr ) != 0 ) continue; - Identifier waferId = *waferIdItr; - Identifier moduleId = m_pSCTHelper->module_id( waferId ); - - std::set<Identifier> stripIdList; - m_MonitorConditionsTool->badStrips( moduleId, stripIdList ); - if ( !stripIdList.empty() ) moduleList.insert( std::map< Identifier, std::set<Identifier> >::value_type( moduleId, stripIdList ) ); - } - - //--- Drop the folder to avoid conflict with SCTCalibWriteSvc - if ( !( m_IOVDbSvc->dropObject( "/SCT/Derived/Monitoring", true ) ) ) msg( MSG::ERROR ) << "Unable to drop /SCT/Derived/Monitoring" << endmsg; - - return StatusCode::SUCCESS; -} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListSvc.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListSvc.h deleted file mode 100644 index 0ff8e6108c2a1436dc1e9f2c7951360b7a7cbca1..0000000000000000000000000000000000000000 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListSvc.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/** -* @file SCT_CalibModuleListSvc.h -* Header file for the SCT_CalibModuleListSvc class -* @author Shaun Roe -**/ - -#ifndef SCT_CalibModuleListSvc_h -#define SCT_CalibModuleListSvc_h - -// STL and boost headers -#include <string> -#include <vector> -#include <set> -#include <map> - -#include "GaudiKernel/IInterface.h" -#include "AthenaBaseComps/AthService.h" -#include "StoreGate/StoreGateSvc.h" -#include "AthenaKernel/IIOVDbSvc.h" - -#include "GaudiKernel/ServiceHandle.h" -#include "SCT_CalibAlgs/ISCT_CalibModuleListSvc.h" -#include "SCT_ConditionsTools/ISCT_MonitorConditionsTool.h" - -#include "Identifier/Identifier.h" -#include "InDetIdentifier/SCT_ID.h" - - -//fwd declarations -template <class TYPE> class SvcFactory; - - -class SCT_CalibModuleListSvc:virtual public ISCT_CalibModuleListSvc, public AthService{ - friend class SvcFactory<SCT_CalibModuleListSvc>; -public: - //@name Service methods, reimplemented - //@{ - SCT_CalibModuleListSvc(const std::string &name, ISvcLocator * svc); - virtual ~SCT_CalibModuleListSvc(); - virtual StatusCode initialize(); - virtual StatusCode finalize(); - virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); - //@} - virtual StatusCode readModuleList( std::map< Identifier, std::set<Identifier> >& moduleList ); - -private: - const SCT_ID* m_pSCTHelper; - ServiceHandle<StoreGateSvc> m_detStore; - ToolHandle<ISCT_MonitorConditionsTool> m_MonitorConditionsTool{this, "SCT_MonitorConditionsTool", "SCT_MonitorConditionsTool/InDetSCT_MonitorConditionsTool", "Tool to retrieve noisy strip information"}; - ServiceHandle<IIOVDbSvc> m_IOVDbSvc; - -}; -#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListTool.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..43a0b00fc0d8217eaf5c9b63ea5cbfbcbcfcda53 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListTool.cxx @@ -0,0 +1,72 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "SCT_CalibModuleListTool.h" + +SCT_CalibModuleListTool::SCT_CalibModuleListTool(const std::string& type, const std::string& name, const IInterface* parent) : + base_class(type, name, parent), + m_pSCTHelper(0), + m_detStore("DetectorStore", name), + m_IOVDbSvc( "IOVDbSvc", name ) +{ +} + +StatusCode SCT_CalibModuleListTool::initialize() { + if (msgLvl(MSG::DEBUG)) msg(MSG:: DEBUG) << "Initializing SCT_CalibModuleListTool " << endmsg; + + StatusCode sc = m_detStore->retrieve( m_pSCTHelper, "SCT_ID" ); + if ( sc.isFailure() ) { + msg( MSG::ERROR ) << "Unable to retrieve SCTHelper" << endmsg; + return sc; + } + + sc = m_MonitorConditionsTool.retrieve(); + if ( sc.isFailure() ) { + msg( MSG::ERROR ) << "Unable to retrieve MonitorConditionsSvc" << endmsg; + return sc; + } + + sc = m_IOVDbSvc.retrieve(); + if ( sc.isFailure() ) { + msg( MSG::ERROR ) << "Unable to retrieve IOVDbSvc" << endmsg; + return sc; + } + + return StatusCode::SUCCESS; +} + +StatusCode SCT_CalibModuleListTool::finalize() { + return StatusCode::SUCCESS; +} + +StatusCode +SCT_CalibModuleListTool::queryInterface(const InterfaceID & riid, void** ppvInterface ) { + if ( ISCT_CalibModuleListTool::interfaceID().versionMatch(riid) ) { + *ppvInterface = dynamic_cast<ISCT_CalibModuleListTool*>(this); + } else { + return AthAlgTool::queryInterface(riid, ppvInterface); + } + addRef(); + return StatusCode::SUCCESS; +} + +StatusCode SCT_CalibModuleListTool::readModuleList( std::map< Identifier, std::set<Identifier> >& moduleList ) { + //--- Read strips using SCT_MonitorConditionsSvc + SCT_ID::const_id_iterator waferIdItr = m_pSCTHelper->wafer_begin(); + SCT_ID::const_id_iterator waferIdItrE = m_pSCTHelper->wafer_end(); + for( ; waferIdItr != waferIdItrE; ++waferIdItr ) { + if ( m_pSCTHelper->side( *waferIdItr ) != 0 ) continue; + Identifier waferId = *waferIdItr; + Identifier moduleId = m_pSCTHelper->module_id( waferId ); + + std::set<Identifier> stripIdList; + m_MonitorConditionsTool->badStrips( moduleId, stripIdList ); + if ( !stripIdList.empty() ) moduleList.insert( std::map< Identifier, std::set<Identifier> >::value_type( moduleId, stripIdList ) ); + } + + //--- Drop the folder to avoid conflict with SCTCalibWriteSvc + if ( !( m_IOVDbSvc->dropObject( "/SCT/Derived/Monitoring", true ) ) ) msg( MSG::ERROR ) << "Unable to drop /SCT/Derived/Monitoring" << endmsg; + + return StatusCode::SUCCESS; +} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListTool.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListTool.h new file mode 100644 index 0000000000000000000000000000000000000000..ada9c098f82e27d7caf6c5d836e32902e356b05d --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibModuleListTool.h @@ -0,0 +1,58 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** +* @file SCT_CalibModuleListTool.h +* Header file for the SCT_CalibModuleListTool class +* @author Shaun Roe +**/ + +#ifndef SCT_CalibModuleListTool_h +#define SCT_CalibModuleListTool_h + +// STL and boost headers +#include <string> +#include <vector> +#include <set> +#include <map> + +#include "GaudiKernel/IInterface.h" +#include "AthenaBaseComps/AthAlgTool.h" +#include "StoreGate/StoreGateSvc.h" +#include "AthenaKernel/IIOVDbSvc.h" + +#include "GaudiKernel/ToolHandle.h" +#include "GaudiKernel/ServiceHandle.h" + +#include "SCT_CalibAlgs/ISCT_CalibModuleListTool.h" +#include "SCT_ConditionsTools/ISCT_MonitorConditionsTool.h" + +#include "Identifier/Identifier.h" +#include "InDetIdentifier/SCT_ID.h" + +//fwd declarations +class StatusCode; + +class SCT_CalibModuleListTool : public extends<AthAlgTool, ISCT_CalibModuleListTool> +{ + + public: + //@name Tool methods, reimplemented + //@{ + SCT_CalibModuleListTool(const std::string&, const std::string&, const IInterface*); + virtual ~SCT_CalibModuleListTool() {}; + virtual StatusCode initialize(); + virtual StatusCode finalize(); + virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface ); + //@} + virtual StatusCode readModuleList( std::map< Identifier, std::set<Identifier> >& moduleList ); + + private: + const SCT_ID* m_pSCTHelper; + ServiceHandle<StoreGateSvc> m_detStore; + ToolHandle<ISCT_MonitorConditionsTool> m_MonitorConditionsTool{this, "SCT_MonitorConditionsTool", "SCT_MonitorConditionsTool/InDetSCT_MonitorConditionsTool", "Tool to retrieve noisy strip information"}; + ServiceHandle<IIOVDbSvc> m_IOVDbSvc; + +}; +#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibNumbers.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibNumbers.h index 2f04d5a4408ac4d743c85fb17e4a850f66cd31ec..5a5dd67d19f76c35323a0f7171095916a96561b0 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibNumbers.h +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibNumbers.h @@ -4,17 +4,19 @@ #ifndef SCT_CalibNumbers_h #define SCT_CalibNumbers_h -namespace SCT_CalibAlgs{ +namespace SCT_CalibAlgs { + // SCT specific numbers - enum { nbins = 6*128, firstStrip = 0, lastStrip = nbins-1, - ntimeBins = 3, firstTimeBin = 0, lastTimeBin = 2, - n_hitBins = 50, first_hitBin = 0, last_hitBin = 50, - n_etaBins = 13, first_etaBin = -6, last_etaBin = 6, - n_phiBins = 56, first_phiBin = 0, last_phiBin = 55, - n_barrels = 4, first_barrel = 0, last_barrel = 3, - n_disks = 9, first_disk = 0, last_disk = 8, - n_etaBinsEC = 3, first_etaBinEC = 0, last_etaBinEC = 2, - n_phiBinsEC = 52, first_phiBinEC = 0, last_phiBinEC = 51 }; - } - -#endif \ No newline at end of file +enum { nbins = 6*128, firstStrip = 0, lastStrip = nbins-1, + ntimeBins = 3, firstTimeBin = 0, lastTimeBin = 2, + n_hitBins = 50, first_hitBin = 0, last_hitBin = 50, + n_etaBins = 13, first_etaBin = -6, last_etaBin = 6, + n_phiBins = 56, first_phiBin = 0, last_phiBin = 55, + n_barrels = 4, first_barrel = 0, last_barrel = 3, + n_disks = 9, first_disk = 0, last_disk = 8, + n_etaBinsEC = 3, first_etaBinEC = 0, last_etaBinEC = 2, + n_phiBinsEC = 52, first_phiBinEC = 0, last_phiBinEC = 51 + }; +} + +#endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibUtilities.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibUtilities.cxx index b1a17438a96d098e1c333b80ef64d44e0a6b9d47..291051f1bab04caddc8d20a737815ca4cb1e27c6 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibUtilities.cxx +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibUtilities.cxx @@ -8,70 +8,65 @@ * * @author Shaun Roe shaun.roe@cern.ch **/ - - - #include "SCT_CalibUtilities.h" - - //STL, boost - #include <boost/lexical_cast.hpp> - - //gaudi - #include "EventInfo/EventInfo.h" - #include "EventInfo/EventID.h" - #include "InDetIdentifier/SCT_ID.h" - #include "Identifier/Identifier.h" - - - namespace SCT_CalibAlgs{ - std::string - eventInfoAsString(const EventInfo * theEvent){ - using boost::lexical_cast; - using std::string; - const EventID* e=theEvent->event_ID(); - string result = string("[ Run, Event, Time, Lumi, Bunch ] = [ " )+ - lexical_cast<string>(e->run_number()) + ", " + - lexical_cast<string>(e->event_number()) + ", "+ - lexical_cast<string>(e->time_stamp()) + ", "+ - lexical_cast<string>(e->lumi_block()) + ", "+ - lexical_cast<string>(e->lumi_block()) + " ] "; - return result; - }//function end - - std::string - formatPosition(const Identifier & waferId, const SCT_ID* helper, const std::string & delimiter, const bool includeSide){ - using boost::lexical_cast; - using std::string; - string result=lexical_cast<string>(helper->barrel_ec(waferId))+delimiter; - result+=lexical_cast<string>(helper->layer_disk(waferId))+delimiter; - result+=lexical_cast<string>(helper->phi_module(waferId))+delimiter; - result+=lexical_cast<string>(helper->eta_module(waferId)); - if (includeSide) result+=( delimiter+lexical_cast<string>(helper->side(waferId)) ); - return result; - }//function end - - std::string - chipList2LinkList(const std::string & chipList){ - if ( chipList == "0-5 6-11" ) { - return "0 1"; - } else if ( chipList == "0-5" ) { - return "0"; - } else if ( chipList == "6-11" ) { - return "1"; - } else { - return ""; - } - } - - unsigned int - bec2Index( const int bec ) { - return (bec/2) + 1; - } - - - std::string - xmlCloseChannel(){ - return "</channel>"; + +#include "SCT_CalibUtilities.h" + +//STL, boost +#include <boost/lexical_cast.hpp> + +//gaudi +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" +#include "InDetIdentifier/SCT_ID.h" +#include "Identifier/Identifier.h" + +namespace SCT_CalibAlgs { +std::string +eventInfoAsString(const EventInfo * theEvent) { + using boost::lexical_cast; + using std::string; + const EventID* e=theEvent->event_ID(); + string result = string("[ Run, Event, Time, Lumi, Bunch ] = [ " )+ + lexical_cast<string>(e->run_number()) + ", " + + lexical_cast<string>(e->event_number()) + ", "+ + lexical_cast<string>(e->time_stamp()) + ", "+ + lexical_cast<string>(e->lumi_block()) + ", "+ + lexical_cast<string>(e->lumi_block()) + " ] "; + return result; +}//function end + +std::string +formatPosition(const Identifier & waferId, const SCT_ID* helper, const std::string & delimiter, const bool includeSide) { + using boost::lexical_cast; + using std::string; + string result=lexical_cast<string>(helper->barrel_ec(waferId))+delimiter; + result+=lexical_cast<string>(helper->layer_disk(waferId))+delimiter; + result+=lexical_cast<string>(helper->phi_module(waferId))+delimiter; + result+=lexical_cast<string>(helper->eta_module(waferId)); + if (includeSide) result+=( delimiter+lexical_cast<string>(helper->side(waferId)) ); + return result; +}//function end + +std::string +chipList2LinkList(const std::string & chipList) { + if ( chipList == "0-5 6-11" ) { + return "0 1"; + } else if ( chipList == "0-5" ) { + return "0"; + } else if ( chipList == "6-11" ) { + return "1"; + } else { + return ""; } - } //end of namespace - - +} + +unsigned int +bec2Index( const int bec ) { + return (bec/2) + 1; +} + +std::string +xmlCloseChannel() { + return "</channel>"; +} +} //end of namespace diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibUtilities.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibUtilities.h index 98ce37f00d346b5332dd2ab573d887d284c94ee3..6078988736a53787fcf569d827ffb4c562999abf 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibUtilities.h +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/SCT_CalibUtilities.h @@ -2,12 +2,12 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ - /** - * @file SCT_CalibUtilities.h - * header file for the SCTCalibUtilities - * - * @author Shaun Roe shaun.roe@cern.ch - **/ +/** + * @file SCT_CalibUtilities.h + * header file for the SCTCalibUtilities + * + * @author Shaun Roe shaun.roe@cern.ch + **/ #ifndef SCT_CalibAlgs_SCT_CalibUtilities_h #define SCT_CalibAlgs_SCT_CalibUtilities_h @@ -18,25 +18,31 @@ class Identifier; class SCT_ID; class EventInfo; -namespace SCT_CalibAlgs{ - std::string eventInfoAsString(const EventInfo * theEvent); - std::string formatPosition(const Identifier & waferId, const SCT_ID* helper, const std::string & delimiter="_", const bool includeSide=true); - std::string chipList2LinkList(const std::string & chipList); - unsigned int bec2Index( const int bec ); - template <class T> - std::string xmlValue(const std::string & name, const T value){ - std::ostringstream os; - os<<" <value name=\""<<name<<"\">"<<value<<"</value>"; - return os.str(); - } - template <class T> - std::string xmlOpenChannel(const long id, const T since, const T until){ - std::string opener=std::string(" <channel id=\"")+boost::lexical_cast<std::string>(id)+"\""; - std::string sinceAttr=std::string(" since=\"")+boost::lexical_cast<std::string>(since)+"\""; - std::string untilAttr=std::string(" until=\"")+boost::lexical_cast<std::string>(until)+"\""; - return opener+sinceAttr+untilAttr+">"; - } - std::string xmlCloseChannel(); + +namespace SCT_CalibAlgs { + +std::string eventInfoAsString(const EventInfo * theEvent); +std::string formatPosition(const Identifier & waferId, const SCT_ID* helper, const std::string & delimiter="_", const bool includeSide=true); +std::string chipList2LinkList(const std::string & chipList); +unsigned int bec2Index( const int bec ); + +template <class T> +std::string xmlValue(const std::string & name, const T value) { + std::ostringstream os; + os<<" <value name=\""<<name<<"\">"<<value<<"</value>"; + return os.str(); +} + +template <class T> +std::string xmlOpenChannel(const long id, const T since, const T until) { + std::string opener=std::string(" <channel id=\"")+boost::lexical_cast<std::string>(id)+"\""; + std::string sinceAttr=std::string(" since=\"")+boost::lexical_cast<std::string>(since)+"\""; + std::string untilAttr=std::string(" until=\"")+boost::lexical_cast<std::string>(until)+"\""; + return opener+sinceAttr+untilAttr+">"; +} + +std::string xmlCloseChannel(); + } //end of namespace #endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlHeader.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlHeader.cxx index 2d37847036f9526de5cfa9fd7d965be67ce293d2..893a8184927f252a25f927bdcf9b8d5c8f48c927 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlHeader.cxx +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlHeader.cxx @@ -2,24 +2,24 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ - /** - * @file XmlHeader.cxx - * implementation file for the XmlHeader class - * - * @author Shaun Roe shaun.roe@cern.ch - **/ - +/** + * @file XmlHeader.cxx + * implementation file for the XmlHeader class + * + * @author Shaun Roe shaun.roe@cern.ch + **/ + #include "XmlHeader.h" #include <ostream> - -namespace SCT_CalibAlgs{ - XmlHeader::XmlHeader(std::ostream & output): m_os(output){ - m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"; - } - - void - XmlHeader::addStylesheet(const std::string & stylesheetPath){ - m_os << std::string("<?xml-stylesheet type=\"text/xsl\" href=\"") + stylesheetPath + std::string("\"?>\n"); - } -} \ No newline at end of file +namespace SCT_CalibAlgs { +XmlHeader::XmlHeader(std::ostream & output): m_os(output) { + m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"; +} + +void +XmlHeader::addStylesheet(const std::string & stylesheetPath) { + m_os << std::string("<?xml-stylesheet type=\"text/xsl\" href=\"") + stylesheetPath + std::string("\"?>\n"); +} + +} diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlHeader.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlHeader.h index 1fd65cf869e0342bba135d99de7b551f9ebb90fd..8c11634bccc6b2adee691ba6b449e3cf039efacc 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlHeader.h +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlHeader.h @@ -14,16 +14,15 @@ #include <iosfwd> #include <string> -namespace SCT_CalibAlgs{ - class XmlHeader{ - public: - XmlHeader(std::ostream & output); - void addStylesheet(const std::string & stylesheetPath); +namespace SCT_CalibAlgs { +class XmlHeader { + public: + XmlHeader(std::ostream & output); + void addStylesheet(const std::string & stylesheetPath); - private: - std::ostream & m_os; - }; + private: + std::ostream & m_os; +}; } - #endif diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlStreamer.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlStreamer.cxx index 250b6c422ec1e6fe609e8e8d2aa7b71f73ca7ae8..89750e21c04984e3ef916f8de765cbbeb71ec381 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlStreamer.cxx +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlStreamer.cxx @@ -12,49 +12,51 @@ typedef std::map<std::string, std::string> Attributes_t; typedef std::vector<std::string> NameValue_t; static Attributes_t empty; -namespace SCT_CalibAlgs{ -XmlStreamer::XmlStreamer(const std::string & name, const Attributes_t & attributes, std::ostream & os):IElementStreamer(name,attributes, os){ - //if (m_nodeId==0) m_os<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; - m_os<<"\n<"<<m_name; - if (not attributes.empty()){ - Attributes_t::const_iterator i(attributes.begin()); - const Attributes_t::const_iterator end(attributes.end()); - for(;i!=end;++i){ - m_os<<" "<<i->first<<"=\""<<i->second<<"\""; - } - } - m_os<<">"; - m_os.flush(); + +namespace SCT_CalibAlgs { + +XmlStreamer::XmlStreamer(const std::string & name, const Attributes_t & attributes, std::ostream & os):IElementStreamer(name,attributes, os) { + //if (m_nodeId==0) m_os<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; + m_os<<"\n<"<<m_name; + if (not attributes.empty()) { + Attributes_t::const_iterator i(attributes.begin()); + const Attributes_t::const_iterator end(attributes.end()); + for(; i!=end; ++i) { + m_os<<" "<<i->first<<"=\""<<i->second<<"\""; + } + } + m_os<<">"; + m_os.flush(); } -XmlStreamer::XmlStreamer(const std::string & name, const NameValue_t & attributeNames, const NameValue_t & attributeValues, std::ostream & os):IElementStreamer(name,attributeNames,attributeValues, os){ - //if (m_nodeId==0) m_os<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; - m_os<<"\n<"<<m_name; - for(unsigned int i(0);i!=attributeNames.size();++i){ - m_os<<" "<<attributeNames[i]<<"=\""<<attributeValues[i]<<"\""; - } - m_os<<">"; - m_os.flush(); +XmlStreamer::XmlStreamer(const std::string & name, const NameValue_t & attributeNames, const NameValue_t & attributeValues, std::ostream & os):IElementStreamer(name,attributeNames,attributeValues, os) { + //if (m_nodeId==0) m_os<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; + m_os<<"\n<"<<m_name; + for(unsigned int i(0); i!=attributeNames.size(); ++i) { + m_os<<" "<<attributeNames[i]<<"=\""<<attributeValues[i]<<"\""; + } + m_os<<">"; + m_os.flush(); } XmlStreamer::XmlStreamer(const std::string & name, std::ostream & os) -:IElementStreamer(name,empty, os){ - m_os<<"\n<"<<m_name<<">"; - m_os.flush(); + :IElementStreamer(name,empty, os) { + m_os<<"\n<"<<m_name<<">"; + m_os.flush(); } -XmlStreamer::XmlStreamer(const std::string & name, const std::string & attributeName, const std::string & attributeValue, std::ostream & os):IElementStreamer(name,attributeName,attributeValue, os){ - m_os<<"\n<"<<m_name; - for(unsigned int i(0);i!=m_attributeNames.size();++i){ - m_os<<" "<<m_attributeNames[i]<<"=\""<<m_attributeValues[i]<<"\""; +XmlStreamer::XmlStreamer(const std::string & name, const std::string & attributeName, const std::string & attributeValue, std::ostream & os):IElementStreamer(name,attributeName,attributeValue, os) { + m_os<<"\n<"<<m_name; + for(unsigned int i(0); i!=m_attributeNames.size(); ++i) { + m_os<<" "<<m_attributeNames[i]<<"=\""<<m_attributeValues[i]<<"\""; } m_os<<">"; m_os.flush(); } - -XmlStreamer::~XmlStreamer(){ - m_os<<"</"<<m_name<<">"; - if (m_depth==1) m_os<<"\n"; +XmlStreamer::~XmlStreamer() { + m_os<<"</"<<m_name<<">"; + if (m_depth==1) m_os<<"\n"; } + } diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlStreamer.h b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlStreamer.h index efda412b4906813cb4c41e759d9c563d3e98e2fe..c3fb9b62e7a0c8657757f46b49a72da1deec0654 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlStreamer.h +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/XmlStreamer.h @@ -11,15 +11,17 @@ #include "IElementStreamer.h" -namespace SCT_CalibAlgs{ -class XmlStreamer:public IElementStreamer{ -public: - XmlStreamer(const std::string & name, const std::map<std::string, std::string> & attributes, std::ostream & os=std::cout); - XmlStreamer(const std::string & name, const std::string & attributeName, const std::string & attributeValue, std::ostream & os=std::cout); - - XmlStreamer(const std::string & name, const std::vector<std::string> & attributeNames, const std::vector<std::string> & attributeValues, std::ostream & os=std::cout); - XmlStreamer(const std::string & name, std::ostream & os=std::cout); - virtual ~XmlStreamer(); +namespace SCT_CalibAlgs { + +class XmlStreamer:public IElementStreamer { + + public: + XmlStreamer(const std::string & name, const std::map<std::string, std::string> & attributes, std::ostream & os=std::cout); + XmlStreamer(const std::string & name, const std::string & attributeName, const std::string & attributeValue, std::ostream & os=std::cout); + + XmlStreamer(const std::string & name, const std::vector<std::string> & attributeNames, const std::vector<std::string> & attributeValues, std::ostream & os=std::cout); + XmlStreamer(const std::string & name, std::ostream & os=std::cout); + virtual ~XmlStreamer(); }; } diff --git a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/components/SCT_CalibAlgs_entries.cxx b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/components/SCT_CalibAlgs_entries.cxx index 1c3f1c2008549e866e4fa2e6541daf5e35cf3cad..c631368c8a94b3b6555bed9739d49c6a02ac4fee 100644 --- a/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/components/SCT_CalibAlgs_entries.cxx +++ b/InnerDetector/InDetCalibAlgs/SCT_CalibAlgs/src/components/SCT_CalibAlgs_entries.cxx @@ -1,20 +1,7 @@ #include "SCT_CalibAlgs/SCTCalib.h" -#include "SCT_CalibAlgs/SCTCalibWriteSvc.h" -#include "../SCT_CalibHitmapSvc.h" -#include "../SCT_CalibLbSvc.h" -#include "../SCT_CalibBsErrorSvc.h" -#include "../SCT_CalibModuleListSvc.h" +//#include "SCT_CalibAlgs/SCTCalibWriteTool.h" #include "../SCT_CalibEventInfo.h" - - DECLARE_COMPONENT( SCTCalib ) -DECLARE_COMPONENT( SCT_CalibBsErrorSvc ) -DECLARE_COMPONENT( SCTCalibWriteSvc ) -DECLARE_COMPONENT( SCT_CalibHitmapSvc ) -DECLARE_COMPONENT( SCT_CalibLbSvc ) -DECLARE_COMPONENT( SCT_CalibModuleListSvc ) +//DECLARE_COMPONENT( SCTCalibWriteTool ) DECLARE_COMPONENT( SCT_CalibEventInfo ) - - -