diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/CoolMdt.h b/DataQuality/DataQualityUtils/DataQualityUtils/CoolMdt.h new file mode 100644 index 0000000000000000000000000000000000000000..741b4ee578c378f8d06db5bce21f269f048b63f5 --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/CoolMdt.h @@ -0,0 +1,146 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//************************************************* +// Class for the MDT interface with the COOL DB +// author Monica Verducci monica.verducci@cern.ch +//************************************************ + +#ifndef dqutilsCoolMdt_h +#define dqutilsCoolMdt_h + +// Protect CINT from some system definitions that cause problems +#ifndef __CINT__ + //COOL API include files (CoolKernel) + #include "CoolKernel/pointers.h" + #include "CoolKernel/ValidityKey.h" +#else + namespace cool { + class IDatabasePtr; + class IFolderPtr; + } +#endif + + +#include <iostream> +#include <string> +#include <cstdlib> + +#include <TObject.h> + +//CORAL API include files +#include "CoralBase/AttributeList.h" + +//COOL API include files (CoolApplication) +#include "CoolApplication/Application.h" +// --> limits.h is needed for CoolKernel/types.h +#include <limits.h> +#include "CoolKernel/types.h" +#include "CoolKernel/ChannelId.h" +#include "CoolKernel/RecordSpecification.h" +#include "CoolKernel/ChannelSelection.h" + + + +#include <sstream> +#include <fstream> +#include <string> +#include <TCanvas.h> +#include <TDirectory.h> +#include <TFile.h> +#include <TGraph.h> +#include <TGraphErrors.h> +#include <TH1.h> +#include <TH2.h> +#include <TIterator.h> +#include <TKey.h> +#include <TLegend.h> +#include <TProfile.h> +#include <TROOT.h> +#include <TStyle.h> +#include <TLatex.h> +#include <TMath.h> +#include <TTree.h> + + +namespace coral { + class AttributeList; +} + +namespace cool { + class RecordSpecification; + class ChannelSelection; +} + + +namespace dqutils { + +class CoolMdt : public cool::Application, public TObject { +private: + + +// Protect CINT from some system definitions that cause problems +// CINT does not need to know about these private variables +#ifndef __CINT__ + cool::ValidityKey since; + cool::ValidityKey until; + cool::IDatabasePtr coolDb; + cool::IFolderPtr coolFolder; + bool m_fist_folder; +#endif + +public: + + // Connects to the database. Throws a "DatabaseDoesNotExis" exception if database does not exist. + cool::IDatabasePtr coolDbInstance(std::string dbStr, bool readOnly); + + + // Browses the COOL folder. Throws a "FolderNotFound" exception if folder does not exist. + cool::IFolderPtr coolFolderInstance(std::string folderStr); + // Various methods to set and print the intervall of validity. + + void initialize(); + void coolDbFolder(std::string dbStr, std::string folderStr); + void setSince(cool::Int64 run, cool::Int64 lumi); + void setUntil(cool::Int64 run, cool::Int64 lumi); + void printIOV(); + void setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU); + void setIOV(cool::Int64 run); + + // Methods needed to come up to COOL framework. + cool::RecordSpecification createSpecDataDead(); + cool::RecordSpecification createSpecDataNoisy(); + coral::AttributeList createPayloadDataNoisy(std::string ChamberName, std::string NoisyMultilayer, std::string NoisyLayer, std::string NoisyMezz, std::string NoisyAsd, std::string NoisyTube, const cool::RecordSpecification& spec); + coral::AttributeList createPayloadDataDead(std::string ChamberName, std::string DeadMultilayer, std::string DeadLayer, std::string DeadMezz, std::string DeadAsd, std::string DeadTube, const cool::RecordSpecification& spec); + + // Constructors and Destructors. + void CoolOpen(std::string dbStr); + + //CoolMdt(); + virtual ~CoolMdt (); + + + void dump(cool::ChannelSelection selection); + std::string dumpField(cool::ChannelId channelId, std::string field); + int dumpCode(std::string channelName); + + void dumpall(); + + void insertNoisyFlag(cool::Int64 run, cool::ChannelId channelId,std::string ChamberName, std::string NoisyMultilayer, std::string NoisyLayer, std::string NoisyMezz, std::string NoisyAsd, std::string NoisyTube); + void insertNoisyFlag_withTag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string NoisyMultilayer, std::string NoisyLayer, std::string NoisyMezz, std::string NoisyAsd, std::string NoisyTube, std::string cool_tag); + + void insertDeadFlag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string DeadMultilayer, std::string DeadLayer, std::string DeadMezz, std::string DeadAsd, std::string DeadTube); + void insertDeadFlag_withTag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string DeadMultilayer, std::string DeadLayer, std::string DeadMezz, std::string DeadAsd, std::string DeadTube, std::string cool_tag); + + cool::IFolderPtr getCoolFolder(); + cool::IDatabasePtr getCoolDb(); + + + // Needed for the ROOT interface. + ClassDef( CoolMdt, 0 ) // A class for modifying DQ info in the COOL database +}; + +} + +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/CoolRpc.h b/DataQuality/DataQualityUtils/DataQualityUtils/CoolRpc.h new file mode 100644 index 0000000000000000000000000000000000000000..0479b79978b25ff134a490b0a5bb99018f2bc7fa --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/CoolRpc.h @@ -0,0 +1,145 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//************************************************* +// Class for the RPC interface with the COOL DB +// author Monica Verducci monica.verducci@cern.ch +//************************************************ + +#ifndef dqutilsCoolRpc_h +#define dqutilsCoolRpc_h + +// Protect CINT from some system definitions that cause problems +#ifndef __CINT__ + //COOL API include files (CoolKernel) + #include "CoolKernel/pointers.h" + #include "CoolKernel/ValidityKey.h" +#else + namespace cool { + class IDatabasePtr; + class IFolderPtr; + } +#endif + + +#include <iostream> +#include <string> +#include <cstdlib> + +#include <TObject.h> + +//CORAL API include files +#include "CoralBase/AttributeList.h" + +//COOL API include files (CoolApplication) +#include "CoolApplication/Application.h" +// --> limits.h is needed for CoolKernel/types.h +#include <limits.h> +#include "CoolKernel/types.h" +#include "CoolKernel/ChannelId.h" +#include "CoolKernel/RecordSpecification.h" +#include "CoolKernel/ChannelSelection.h" + + + +#include <sstream> +#include <fstream> +#include <string> +#include <TCanvas.h> +#include <TDirectory.h> +#include <TFile.h> +#include <TGraph.h> +#include <TGraphErrors.h> +#include <TH1.h> +#include <TH2.h> +#include <TIterator.h> +#include <TKey.h> +#include <TLegend.h> +#include <TProfile.h> +#include <TROOT.h> +#include <TStyle.h> +#include <TLatex.h> +#include <TMath.h> +#include <TTree.h> + + +namespace coral { + class AttributeList; +} + +namespace cool { + class RecordSpecification; + class ChannelSelection; +} + + +namespace dqutils { + +class CoolRpc : public cool::Application, public TObject { +private: + + +// Protect CINT from some system definitions that cause problems +// CINT does not need to know about these private variables +#ifndef __CINT__ + cool::ValidityKey since; + cool::ValidityKey until; + cool::IDatabasePtr coolDb; + cool::IFolderPtr coolFolder; +#endif + +public: + + // Connects to the database. Throws a "DatabaseDoesNotExis" exception if database does not exist. + cool::IDatabasePtr coolDbInstance(std::string dbStr, bool readOnly); + //cool::IDatabasePtr write(std::string stringa); + //cool::IDatabasePtr coolDbInstance(std::string dbStr); + + + // Browses the COOL folder. Throws a "FolderNotFound" exception if folder does not exist. + cool::IFolderPtr coolFolderInstance(std::string folderStr); + // Various methods to set and print the intervall of validity. + + void coolDbFolder(std::string dbStr, std::string folderStr); + void setSince(cool::Int64 run, cool::Int64 lumi); + void setUntil(cool::Int64 iovmax, cool::Int64 lumi); + void printIOV(); + void setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU); + void setIOV(cool::Int64 run); + + // Methods needed to come up to COOL framework. + cool::RecordSpecification createSpecData(); + coral::AttributeList createPayloadData(std::string recEta, std::string DetEta, std::string recPhi1, std::string recPhi2, std::string detPhi1, std::string detPhi2, const cool::RecordSpecification& spec); + + cool::RecordSpecification createSpecDataCondDB(); + coral::AttributeList createPayloadDataCondDB(std::string PanelRes, std::string StripStatus, const cool::RecordSpecification& spec); + + // Constructors and Destructors. + void CoolOpen(std::string dbStr); + + //CoolRpc(); + virtual ~CoolRpc (); + + + void dump(cool::ChannelSelection selection); + std::string dumpField(cool::ChannelId channelId, std::string field); + int dumpCode(std::string channelName); + + void dumpall(); + + void insert(cool::Int64 run, cool::ChannelId channelId,std::string recEta, std::string DetEta, std::string recPhi1, std::string recPhi2, std::string detPhi1, std::string detPhi2); + void insert_withTag(cool::Int64 run, cool::ChannelId channelId,std::string recEta, std::string DetEta, std::string recPhi1, std::string recPhi2, std::string detPhi1, std::string detPhi2, std::string cool_tag); + void insertCondDB_withTag(cool::Int64 run, cool::ChannelId channelId, std::string PanelRes,std::string StringStatus, std::string cool_tag); + + cool::IFolderPtr getCoolFolder(); + cool::IDatabasePtr getCoolDb(); + + + // Needed for the ROOT interface. + ClassDef( CoolRpc, 0 ) // A class for modifying DQ info in the COOL database +}; + +} + +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/CoolTgc.h b/DataQuality/DataQualityUtils/DataQualityUtils/CoolTgc.h new file mode 100644 index 0000000000000000000000000000000000000000..726eecc2f006274b2f2f5e4ad3997290e41f14c3 --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/CoolTgc.h @@ -0,0 +1,145 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//************************************************* +// Class for the TGC interface with the COOL DB +// copy of CoolMdt.cxx by Monica Verducci +// author Akimasa Ishikawa +//************************************************ + +#ifndef dqutilsCoolTgc_h +#define dqutilsCoolTgc_h + +// Protect CINT from some system definitions that cause problems +#ifndef __CINT__ + //COOL API include files (CoolKernel) + #include "CoolKernel/pointers.h" + #include "CoolKernel/ValidityKey.h" +#else + namespace cool { + class IDatabasePtr; + class IFolderPtr; + } +#endif + + +#include <iostream> +#include <string> +#include <cstdlib> + +#include <TObject.h> + +//CORAL API include files +#include "CoralBase/AttributeList.h" + +//COOL API include files (CoolApplication) +#include "CoolApplication/Application.h" +// --> limits.h is needed for CoolKernel/types.h +#include <limits.h> +#include "CoolKernel/types.h" +#include "CoolKernel/ChannelId.h" +#include "CoolKernel/RecordSpecification.h" +#include "CoolKernel/ChannelSelection.h" + + + +#include <sstream> +#include <fstream> +#include <string> +#include <TCanvas.h> +#include <TDirectory.h> +#include <TFile.h> +#include <TGraph.h> +#include <TGraphErrors.h> +#include <TH1.h> +#include <TH2.h> +#include <TIterator.h> +#include <TKey.h> +#include <TLegend.h> +#include <TProfile.h> +#include <TROOT.h> +#include <TStyle.h> +#include <TLatex.h> +#include <TMath.h> +#include <TTree.h> + + +namespace coral { + class AttributeList; +} + +namespace cool { + class RecordSpecification; + class ChannelSelection; +} + + +namespace dqutils { + +class CoolTgc : public cool::Application, public TObject { +private: + + +// Protect CINT from some system definitions that cause problems +// CINT does not need to know about these private variables +#ifndef __CINT__ + cool::ValidityKey since; + cool::ValidityKey until; + cool::IDatabasePtr coolDb; + cool::IFolderPtr coolFolder; +#endif + +public: + + // Connects to the database. Throws a "DatabaseDoesNotExis" exception if database does not exist. + cool::IDatabasePtr coolDbInstance(std::string dbStr, bool readOnly); + + + // Browses the COOL folder. Throws a "FolderNotFound" exception if folder does not exist. + cool::IFolderPtr coolFolderInstance(std::string folderStr); + // Various methods to set and print the intervall of validity. + + void coolDbFolder(std::string dbStr, std::string folderStr); + void setSince(cool::Int64 run, cool::Int64 lumi); + void setUntil(cool::Int64 run, cool::Int64 lumi); + void printIOV(); + void setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU); + void setIOV(cool::Int64 run); + + // Methods needed to come up to COOL framework. + cool::RecordSpecification createSpecDataDead(); + cool::RecordSpecification createSpecDataNoisy(); + coral::AttributeList createPayloadDataNoisy(std::string ChamberName, std::string NoisyMultilayer, std::string NoisyTube, const cool::RecordSpecification& spec); + coral::AttributeList createPayloadDataDead(std::string ChamberName, std::string DeadMultilayer, std::string DeadTube, const cool::RecordSpecification& spec); + + // Constructors and Destructors. + void CoolOpen(std::string dbStr); + + //CoolTgc(); + virtual ~CoolTgc (); + + + void dump(cool::ChannelSelection selection); + std::string dumpField(cool::ChannelId channelId, std::string field); + int dumpCode(std::string channelName); + + void dumpall(); + + void insertNoisyFlag(cool::Int64 run, cool::ChannelId channelId,std::string ChamberName, std::string NoisyMultilayer, std::string NoisyTube); + void insertNoisyFlag_withTag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string NoisyMultilayer, std::string NoisyTube, std::string cool_tag); + + void insertDeadFlag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string DeadMultilayer, std::string DeadTube); + void insertDeadFlag_withTag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string DeadMultilayer, std::string DeadTube, std::string cool_tag); + + cool::IFolderPtr getCoolFolder(); + cool::IDatabasePtr getCoolDb(); + + + // Needed for the ROOT interface. + ClassDef( CoolTgc, 0 ) // A class for modifying DQ info in the COOL database +}; + +} + +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/HanOutputFile.h b/DataQuality/DataQualityUtils/DataQualityUtils/HanOutputFile.h new file mode 100644 index 0000000000000000000000000000000000000000..d3bb9ea72931458d3fef5878f20344e6e5e2e4fc --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/HanOutputFile.h @@ -0,0 +1,113 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef dqutilsHanOutputFile_h +#define dqutilsHanOutputFile_h + +#include <iostream> +#include <map> +#include <string> + +#include <TObject.h> + + +class TCanvas; +class TDirectory; +class TFile; +class TH1; +class TH2; +class TStyle; +class TGraph; + +namespace dqutils { + +class HanOutputFile : public TObject { +public: + + HanOutputFile(); + + HanOutputFile( std::string fileName ); + + virtual ~HanOutputFile(); + + + typedef std::map< std::string, TDirectory* > DirMap_t; + typedef std::map< std::string, std::string > AssMap_t; + typedef std::map< std::string, AssMap_t* > DirToAssMap_t; + + static void getAllGroupDirs( DirMap_t& dirmap, TDirectory* dir, + std::string dirName ); + static void getAllAssessments( AssMap_t& dirmap, TDirectory* dir); + + + static std::string getStringName(std::string location); + static std::string getInfo(std::string location); + static std::string getIndentation( std::string pathName, + std::string leadingSpace = "" ); + + /** + * Clears all previous data and opens the file with the given name for + * analysis, returning a boolean indicating whether the file was opened + * successfully or not. + */ + + virtual bool setFile( std::string fileName ); + + virtual void printAllDQGroups(); + + virtual void printAllDQAssessments(); + virtual void printHistoAssessments(); + + virtual std::string stringListSystemPaths( std::string location ); + virtual std::string stringAllDQAssessments(); + virtual std::string stringHistoAssessments(); + virtual std::string stringAllHistograms(); + + virtual void streamAllDQAssessments( std::ostream& o, bool streamAll ); + virtual void streamHistoAssessments( std::ostream& o, bool streamAll ); + virtual void streamAllHistograms( std::ostream& o, bool streamAll ); + virtual int saveAllHistograms( std::string location, bool drawRefs, std::string run_min_LB ); + static bool containsDir(std::string dirname, std::string maindir); + + virtual bool saveHistogramToFile( std::string nameHis, std::string location, + TDirectory* groupDir, bool drawRefs,std::string run_min_LB, std::string pathName ); + virtual bool saveHistogramToFileSuperimposed( std::string nameHis, std::string location, + TDirectory* groupDir1, TDirectory* groupDir2, bool drawRefs,std::string run_min_LB, std::string pathName ); + + virtual bool drawH2(TCanvas* canv,TH2* hist,std::string &drawopt,std::string &display); + virtual bool drawH1(TCanvas* canv,TH1* hist,TH1* reference,std::string &drawopt,std::string &display,std::string &AlgoName); + virtual bool drawReference(TCanvas* canv,TH1* hRef,TH1 *h,std::string &drawopt,std::string &display,std::string& AlgoName); + // virtual bool drawGraph(TCanvas* canv,TGraph* g,std::string &drawopt,std::string &display); + virtual void attachFits(TH1* hist,std::string &drawopt,std::string &display); + virtual void setupCanvas(std::string &drawopt,std::string &display); + + virtual void displayExtra( TCanvas* c, std::string str ) ; + virtual void axisOption( std::string str, TH1* h ) ; + + virtual void formatTH1( TCanvas* c, TH1* h ) const; + virtual void formatTH2( TCanvas* c, TH2* h ) const; + virtual void formatTGraph( TCanvas* c, TGraph* g ) const; + + virtual double getNEntries( std::string location, std::string histname ); + virtual double getNEntries( const TObject* obj ); + + +protected: + + virtual void clearData(); + + + TFile* m_file; + DirMap_t m_indirMap; + DirToAssMap_t m_assessMap; + TStyle* m_style; + + + ClassDef( HanOutputFile, 0 ) // Provides functions to manipulate and analyze data-quality monitoring files + +}; + +} // namespace dqutils + +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/HistogramDataCOOL.h b/DataQuality/DataQualityUtils/DataQualityUtils/HistogramDataCOOL.h new file mode 100644 index 0000000000000000000000000000000000000000..edb66bf4b578d351cd57191bf007aa08208a176b --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/HistogramDataCOOL.h @@ -0,0 +1,137 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef dqutilsHistogramDataCOOL_h +#define dqutilsHistogramDataCOOL_h + +// Protect CINT from some system definitions that cause problems +#ifndef __CINT__ + //COOL API include files (CoolKernel) + #include "CoolKernel/pointers.h" + #include "CoolKernel/ValidityKey.h" +#else + namespace cool { + class IDatabasePtr; + class IFolderPtr; + } +#endif + + +#include <iostream> +#include <string> +#include <cstdlib> + +#include <TObject.h> + +//CORAL API include files +#include "CoralBase/AttributeList.h" + +//COOL API include files (CoolApplication) +#include "CoolApplication/Application.h" +// --> limits.h is needed for CoolKernel/types.h +#include <limits.h> +#include "CoolKernel/types.h" +#include "CoolKernel/ChannelId.h" +#include "CoolKernel/RecordSpecification.h" +#include "CoolKernel/ChannelSelection.h" + +#include <sstream> +#include <fstream> +#include <string> +#include <TCanvas.h> +#include <TDirectory.h> +#include <TFile.h> +#include <TGraph.h> +#include <TGraphErrors.h> +#include <TH1.h> +#include <TH2.h> +#include <TIterator.h> +#include <TKey.h> +#include <TLegend.h> +#include <TProfile.h> +#include <TROOT.h> +#include <TStyle.h> +#include <TLatex.h> +#include <TMath.h> +#include <TTree.h> + +namespace coral { + class AttributeList; +} + +namespace cool { + class RecordSpecification; + class ChannelSelection; +} + + +namespace dqutils { + +class HistogramDataCOOL : public cool::Application, public TObject { +private: + +// Protect CINT from some system definitions that cause problems +// CINT does not need to know about these private variables +#ifndef __CINT__ + cool::ValidityKey since; + cool::ValidityKey until; + cool::IDatabasePtr coolDb; + cool::IFolderPtr coolFolder; + cool::IFolderPtr coolFolderH; +#endif + +public: + // Connects to the database. Throws a "DatabaseDoesNotExis" exception if database does not exist. + cool::IDatabasePtr coolDbInstance(std::string dbStr, bool readOnly); + + // Browses the COOL folder. Throws a "FolderNotFound" exception if folder does not exist. + cool::IFolderPtr coolFolderInstance(std::string folderStr); + + // Various methods to set and print the intervall of validity. + void setSince(cool::Int64 run, cool::Int64 lumi); + void setUntil(cool::Int64 run, cool::Int64 lumi); + void printIOV(); + void setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU); + void setIOV(cool::Int64 run); + + // Methods needed to come up to COOL framework. + cool::RecordSpecification createSpec(); + coral::AttributeList createPayload(int colourCode, float dfrac, float thrust, const + cool::RecordSpecification& spec); + cool::RecordSpecification createSpecH(); + coral::AttributeList createPayloadH(int colourCode, std::string algo, int entries, float par1, float par2, float par3, float par4, float par5, const + cool::RecordSpecification& specH); + + // Constructors and Destructors. + HistogramDataCOOL(std::string dbStr, std::string folderStr, int runS, int lumiS, int runU, int lumiU); + HistogramDataCOOL(int runS, int lumiS, int runU, int lumiU); + HistogramDataCOOL(); + virtual ~HistogramDataCOOL (); + + // Methods of "interest". To insert a status flag you can use either ChannelId or ChannelName. + void dump(cool::ChannelSelection selection, std::string tag_name); + std::string dumpHisto(cool::ChannelId channelId, std::string field, std::string tag_name); + int dumpCode(std::string channelName, std::string tag_name); + void dumpall(std::string tag_name); + + void insertH(cool::ChannelId channelId, int code, std::string algo, int entries, float par1, float par2, float par3, float par4, float par5, std::string tag_name); + void insertH(std::string channelName, int code, std::string algo, int entries, float par1, float par2, float par3, float par4, float par5, std::string tag_name); + + virtual void ntupleDB( int HistoId, std::string nameHisto, std::string configuration, int Irun, int Frun ); + virtual void historyDB( int HistoId, std::string nameHisto, std::string tag_name ); + std::string defParName( std::string Algorithm, std::string nameHisto, int i); + virtual void formatGraph( TCanvas* c, TGraphErrors* gr ) const; + + // Some further getters. + cool::IFolderPtr getCoolFolderH(); + cool::IDatabasePtr getCoolDb(); + + + // Needed for the ROOT interface. + ClassDef( HistogramDataCOOL, 0 ) // A class for modifying DQ info in the COOL database +}; + +} + +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/MdtDeadNoisyUtils.h b/DataQuality/DataQualityUtils/DataQualityUtils/MdtDeadNoisyUtils.h new file mode 100644 index 0000000000000000000000000000000000000000..b89f62079e025460436000688092ed8581dd7ead --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/MdtDeadNoisyUtils.h @@ -0,0 +1,118 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef dqutilsMdtDeadNoisy_h +#define dqutilsMdtDeadNoisy_h + +#include <vector> +#include <string> +#include <sstream> +#include <iostream> +#include <fstream> +#include <stdio.h> + +#include <TString.h> +#include <TH1F.h> +#include <TCanvas.h> + +namespace dqutils_mdtdeadnoisy { + + struct TubeRange { + TubeRange(int a, int b) {x1 = a; x2 = b;} + bool InRange(int x) { if( (x >= x1) && (x <= x2) ) return true; return false; } + int x1; + int x2; + }; + + double sqr( double x ); + void displayList( std::vector<int> & v ); + void displayList( std::vector<int> & v, ofstream & outputfile ); + void getDeadList( TH1F* h, std::vector<int> & v ); + bool find( std::vector<int> & v, unsigned int x ); + void getSurelyDeadList( TH1F* h, std::vector<int> & v, std::vector<int> & betweenlist ); + void getNotBetweenList( std::vector<int> & v, std::vector<int> & surely_v, std::vector<int> & betweenlist ); + void getNotMasked( std::vector<int> & v, TH1F* h ); + void getNotInDeadML( std::vector<int> & v, std::vector<int> & deadML_v, const TString & hardware_name, int totalTubes); + void getNotInDeadLayer( std::vector<int> & v, std::vector<int> & deadLayer_v, const TString & hardware_name, int totalTubes); + void getNotInDeadMezz( std::vector<int> & v, std::vector<int> & deadMezz_v, const TString & hardware_name, int totalTubes); + void getAllBins( TH1F* h, std::vector<int> & v ); + void getAllBinsInRange( TH1F* h, std::vector<int> & v, int x1, int x2 ); + void getAllBinsInRangeBelowCutoff( TH1F* h, std::vector<int> & v, int crustCutoff, int x1, int x2 ); + void getAllUnmaskedBinsInRangeBelowCrustCutoff( TH1F* h, std::vector<int> & v, int crustCutoff, int x1, int x2 ); + void getBins( TH1F* h, std::vector<int> & indices, std::vector<int> & content ); + void removeZeros( std::vector<int> & v ); + void getAllTubes( TH1F* h, std::vector<int> & v ); + void getNonEmptyBins( TH1F* h, std::vector<int> & v ); + void getNonEmptyTubes( TH1F* h, std::vector<int> & v ); + template <class T> + double getMean( std::vector<T> & v ); + double getMean_WithCut( std::vector<int> & v, double cut ); + void getNoBetweens( TH1F* h, std::vector<int> & no_dead, std::vector<int> & no_betweens, std::vector<int> & betweenlist, float minBinContent ); + void getNoBetweens_middle( std::vector<int> no_betweens, std::vector<int> & no_betweens_middle ); + void getNoBetweens_lowmiddle( std::vector<int> no_betweens, std::vector<int> & no_betweens_lowmiddle ); + void getNoBetweens_middle_aggressive( std::vector<int> no_betweens, std::vector<int> & no_betweens_middle_aggressive ); + void getNoBetweens_middle_semiaggressive( std::vector<int> no_betweens, std::vector<int> & no_betweens_middle_aggressive ); + void getNoBetweens_lowmiddle_aggressive( std::vector<int> no_betweens, std::vector<int> & no_betweens_lowmiddle_aggressive ); + void getNoBetweens_highmiddle_aggressive( std::vector<int> no_betweens, std::vector<int> & no_betweens_lowmiddle_aggressive ); + double getStandardDevFromMean( std::vector<int> & v, double mean ); + double getStandardDevFromMean_neg( std::vector<int> & v, double mean ); + double getStandardDevFromMean_pos( std::vector<int> & v, double mean ); + void getNoisyList( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_middle_aggressive, double num_std_dev, std::vector<int> & noisylist); + void getNoisyList2( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_middle_aggressive, double num_pct, std::vector<int> & noisylist); + void getIneffList( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_std_dev, std::vector<int> & inefflist); + void getIneffList( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_std_dev_1, double num_std_dev_2, std::vector<int> & inefflist); + void getIneffList2( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_pct, std::vector<int> & inefflist); + void getIneffList2( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_pct_1, double num_pct_2, std::vector<int> & inefflist); + void getIneffList2( std::vector<int> & indices, TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_pct, std::vector<int> & inefflist); + bool validityCheckDead( std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_middle_aggressive ); + bool validityCheckNoise( std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_middle_aggressive /*, int max*/ ); //max parameter is not currently used + void getNonEmptyNonNoisyTubes( TH1F* h_tube_fornoise, TH1F* h_tube, std::vector<int> & non_dead_non_noisy); + void removeNonContiguous( std::vector<int> & betweenlist, unsigned int sz ); + void CatalogNoisyEff( TH1F* h_tube_bkd, TH1F* h_tube_fornoise, TH1F* num, TH1F* den, int nTriggers, TH1F* EffVSNoise_num, TH1F* EffVSNoise_den, TH1F* EffVSNoise_ADCCut_num, TH1F* EffVSNoise_ADCCut_den, TH1F* EffVSBkd_num, TH1F* EffVSBkd_den); + std::vector<int> GetNoisyTubes( TH1F* h_tube_fornoise, int nTriggers, float frequency);//Simply determine noisy tubes from freq. + std::vector<int> GetNoisyTubes( TH1F* h_tube_fornoise, TH1F* h_tube, TString chamber, int & validity); + std::vector<int> GetNoisyTubes_WithoutForNoise( TH1F* h_tube, int & validity, TString chamber ); + //std::vector<int> GetDeadTubes( TH1F* h_tube_fornoise, TH1F* h_tube, TString chamber); + std::vector<int> GetDeadTubes( TH1F* h_tube, int & validity, std::vector<int> & deadML_v, std::vector<int> & deadLayer_v, std::vector<int> & deadMezz_v ); + //std::vector<int> GetMaskedTubesForDead( TH1F* h_tube_fornoise, TH1F* h_tube, TString chamber); + std::vector<int> GetMaskedTubesForDead( TH1F* h_tube ); + //std::vector<int> GetMaskedTubesForNoisy( TH1F* h_tube_fornoise, TH1F* h_tube, TString chamber); + std::vector<int> GetMaskedTubesForNoisy( TH1F* h_tube_fornoise ); + double GetMeanFromHist( TH1F* h_tube ); + double GetStandardDevFromHist( TH1F* h_tube, double mean ); + int getLastTubeInLayer(int & firstTubeInLayer, const TString & hardware_name, int totalTubes); + std::vector<TubeRange> getLayerRanges(const TString & hardware_name, int totalTubes); + int getLastTubeInML(int & firstTubeInML, const TString & hardware_name, int totalTubes); + std::vector<TubeRange> getMLRanges(const TString & hardware_name, int totalTubes); + std::vector<TubeRange> getMezzRanges(const TString & hardware_name, int totalTubes, int & groupsPerLayer); + int Get_ML_of_Mezz(int &mezz, const TString & hardware_name, int totalTubes); + int Get_ML_of_Mezz_degenerate(int &mezz, const TString & hardware_name, int totalTubes); + std::vector<int> /*void*/ FindDeadMezz( TH1F* h_tube, const TString & hardware_name, std::vector<int> & deadML_v); + std::vector<int> /*void*/ FindDeadLayer( TH1F* h_tube, const TString & hardware_name, std::vector<int> & deadML_v); + std::vector<int> /*void*/ FindDeadML( TH1F* h_tube, const TString & hardware_name); + int GetNumML(const TString & hardware_name); + int GetNumLayersPerML(const TString & hardware_name); + int GetNumTubesPerMezz(const TString & hardware_name, int mezz);//For Getting total tube count + //global layer i.e. 5 instead of ML2 layer 2 + int GetNumTubesPerML(const TString & hardware_name, int layer, int TotalTubes);//For Getting total tube count + int GetNumTubesPerLayer(const TString & hardware_name, int ML, int TotalTubes);//For Getting total tube count + int Get_ML_of_Layer(int & layer, const TString & hardware_name); + int Get_ML_of_Tube(int & tubeID, const TString & hardware_name, int totalTubes); + int Get_Layer_of_Tube(int & tubeID, const TString & hardware_name, int totalTubes); + int Get_Mezz_of_Tube(int & tubeID, const TString & hardware_name/*, int totalTubes*/, std::vector<TubeRange> & tubeRanges, int groupsPerLayer); + int GetNumNonMaskedTubes( TH1F* h_tube ); + int GetNumMezz( TH1F* h_tube ); + bool AinB( int A, std::vector<int> & B ); + bool AinB( int A, const std::vector<int> * B ); + + //For dumping pdf + void FillPDF(std::string inFilename, TH1F* hDead, TH1F* hNoise, TCanvas* c, + const std::vector<int>* deadTubes, const std::vector<int>* deadASD, const std::vector<int>* deadMEZZ, const std::vector<int>* deadLayer, const std::vector<int>* deadML, + const std::vector<int>* noisyTubes, const std::vector<int>* noisyASD, const std::vector<int>* noisyMEZZ, const std::vector<int>* noisyLayer, const std::vector<int>* noisyML, + int deadTubesChamberValidity, int noisyTubesChamberValidity, + bool draw_Mezz_L_ML_guidlines, bool draw_mean, bool draw_masked_tubes, bool separate_dead_noisy_histos, bool draw_validity_message, bool draw_histo_if_nothing_to_report); + +} // end namespace + +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/MonitoringFile.h b/DataQuality/DataQualityUtils/DataQualityUtils/MonitoringFile.h new file mode 100644 index 0000000000000000000000000000000000000000..e5183d6f5c4338309dedaa61c5d67e6246dade89 --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/MonitoringFile.h @@ -0,0 +1,518 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef dqutilsMonitoringFile_h +#define dqutilsMonitoringFile_h + +#include <map> +#include <string> +#include <vector> +#include <set> + +#include <TObject.h> +#include <TFile.h> +#include <TH1.h> +#include <TString.h> +#include "RooRealVar.h" + +#ifndef __CINT__ +#include <boost/regex_fwd.hpp> +#else +// good enough for CINT +namespace boost { class regex; } +#endif + +class TDirectory; +class TFile; +class TGraph; +class TH1; +class TH1F; +class TH2F; +class TH1D; +class TH2D; +class TH1I; +class TH3F; +class TH2; +class TH3; +class TObjArray; +class TKey; +class TTree; +class TString; +class RooPlot; + + +namespace dqutils { + + typedef std::map<std::string, std::vector<int> > keycyclemap; + void populateKeyMapping(TDirectory*, keycyclemap&); + + class MonitoringFile : public TObject { + public: + + struct MetaData { + inline MetaData(std::string name_, std::string interval_, std::string chain_, std::string merge_) + : name(name_), interval(interval_), chain(chain_), merge(merge_) { } + std::string name; + std::string interval; + std::string chain; + std::string merge; + }; + + + class OutputMetadata { + public: + OutputMetadata(TTree* metadata); + virtual ~OutputMetadata(); + + virtual void fill(std::string name, + std::string interval, + std::string chain, + std::string merge); + + protected: + void copyString(char* to, const std::string& from); + void adjustAddresses(const char* branchName, void* ptr, const char* branchstr); + const int charArrSize; + TTree* m_metadata; + char* m_nameData; + char* m_intervalData; + char* m_chainData; + char* m_mergeData; + }; + + + MonitoringFile(); + + MonitoringFile(std::string fileName); + + virtual ~MonitoringFile(); + + typedef std::map< std::string, TDirectory* > DirMap_t; + + static void getAllDirs(DirMap_t& dirmap, TDirectory* dir, std::string dirName); + + static TDirectory* createDir(DirMap_t& dirmap, TDirectory* dir, std::string parent, std::string path); + + static TKey* getObjKey(TDirectory* dir, std::string path); + + // enum MergeMethod_t { TH1Add = 0, effAsPerCent, weightedAverage, weightedEff, mergeRebinned, weightedAverage2D, eventSample }; + + void mergeDirectory(TDirectory* outputDir, const std::vector<TFile*>& inputFiles, bool has_multiple_runs = false, std::map< TFile*, std::string >* prefixes = 0); + + static void fillMetaDataMap(std::map<std::string, dqutils::MonitoringFile::MetaData>& mdMap, TDirectory* dir); + + void mergeFiles(std::string outFileName, const std::vector<std::string>& files); + + void mergeFiles(std::string outFileName, std::string listFileName); + + static void merge_effAsPerCent(TH2& a, const TH2& b); + + static void merge_perBinEffPerCent(TH1& a, const TH1& b); + + static void merge_effAsPerCentAlt(TH1& a, const TH1& b); + + static void merge_weightedAverage(TH1& a, const TH1& b); + + static void merge_weightedAverage2D(TH2& a, const TH2& b); + + static void merge_weightedEff(TH1& a, const TH1& b); + + static void merge_Rebinned(TH1& a, TH1& b); + + static void merge_eventSample(TH2& a, const TH2& b); + + static void merge_RMS(TH1& a, const TH1& b); + + static void merge_RMSpercentDeviation(TH1& a, const TH1& b); + + static void merge_lowerLB(TH1& a, const TH1& b); + /** + * Methods for creating ID Alignment summary plots on merged files + */ + + static void fitMergedFile_IDPerfMonManager(std::string inFileName, bool isIncremental = false); + static void fitMergedFile_DiMuMonManager(std::string inFileName, bool isIncremental = false); + static void fitMergedFile_IDAlignMonManager(std::string inFileName, bool isIncremental = false); + static bool CheckHistogram(TFile* f, const char* HistoName); + static void fitMergedFile_IDAlignMonResiduals(TFile* f, std::string run_dir, std::string TriggerName); + static void fitMergedFile_IDAlignMonTrackSegments(TFile* file, std::string run_dir, std::string tracksName); + static void fitMergedFile_IDAlignMonGenericTracks(TFile* file, std::string run_dir, std::string tracksName); + static void fitMergedFile_IDPerfMonKshort(TFile* f, std::string run_dir, std::string TriggerName); + static void fitMergedFile_IDPerfMonJpsi(TFile* f, std::string run_dir, + std::string TriggerName); + static void fitMergedFile_IDPerfMonUpsilon(TFile* f, std::string run_dir, + std::string TriggerName); + static void fitMergedFile_IDPerfMonZee(TFile* f, std::string run_dir, std::string TriggerName); + static void fitMergedFile_IDPerfMonWenu(TFile* f, std::string run_dir, std::string TriggerName); + static void fitMergedFile_IDPerfMonZMM (TFile* f, std::string run_dir, std::string TriggerName); + static void fitJpsiHistograms(TH1F* hmass, TH1F* hwidth, TH1F* h1[], int n); + static void fitUpsilonHistograms(TH1F* hmass, TH1F* hwidth, TH1F* h1[], int n); + static void fitZmumuMassPlot(TH1F* hmass); + static std::pair<RooRealVar, RooRealVar> fitZmumuMass(TH1F* hmass); + static void fitZmumuHistograms(TH1F* hmass, TH1F* hwidth, std::vector<TH1F*> hvec); + static void processModule(TFile* f, std::string run_dir, TKey* key_module, std::string moduleName); + static void fitMergedFile_DiMuMonAll(TFile* f, std::string run_dir, std::string resonName, std::string triggerName); + static void fitHistos(TH2D* hin, std::vector<TH1D*> hout, int mode, std::string triggerName, std::string resonName, TH1D* m_chi2); + static void fillGaussianMeanOrWidth(TH2F* h2d, TH1F* h, float fitMin, float fitMax, int iopt); + static void fillMeanOrWidth(TH2F* h2d, TH1F* h, int iopt); + static void fillDetPaperMeanRMS(TH2F* h2d, TH1F* h, int iopt); + static void meanRMSProjections2D(TH2F* h2d, TH1F* h, int iopt); + static void meanRMSProjections3D(TH3F* h3d, TH2F* h, int iopt); + static void meanRMSProjections3D_DMRPlot(TH3F* h3d, TH1F* h, int iopt); + static void meanRMSProjections3D_XY(TH3F* h3d, TH1F* h, int iXY, int iopt); + static TH1F* combineHistos(const char* name, const char* title, TObjArray* plots, int gap); + static void setMinWindow(TH1* h1, float min, float max); + static float getMedian(TH1* h1); + static void ProcessAsymHistograms(TH1F* m_neg, TH1F* m_pos, TH1F* m_asym); + + // Muon CSC + static void CSCPostProcess(std::string inFilename, bool isIncremental = false); + static void CSCChamberEfficiency(TFile* f, TString& run_dir); + static void CSCClusterFit(TFile* f, TString& run_dir); + + // given bin- content and bin-error of numerator, denominator, compute efficiency (eff) + // and efficiency error (err) according to errtype = 0(binomial), =1(UPX) or Sumw2 + static void GetCscEffAndErr(float& num, float& num_err, float& den, float& den_err, float& eff, float& err, int errtype); + + // For MuonTrkPhysMonitoring + static void MuonTrkPhys(std::string inFileName, bool isIncremental = false); + static void MuonTrkPhys_Zmass(std::string inFileName); + static void MuonTrkPhys_Tracking(std::string inFileName); + static void MuonTrkPhys_DetectorSpecific(std::string inFileName); + static void MuonTrkPhys_BField(std::string inFileName); + static void MuonTrkPhys_Alignment(std::string inFileName); + static Double_t MuonTrkPhys_BWgaus(Double_t *x, Double_t *par); + static Double_t MuonTrkPhys_fitFunctionS(Double_t *x, Double_t *par); + + //For Muon MDT + static void MDTPostProcess(std::string inFilename, bool isIncremental = false, int txtFileOutputType = 0, bool useOfflineTubeID = false, bool makePDF = false, bool doAllPDF = true); + static void MDTChamReAlign(std::string inFilename, std::string title="MDT"); + static void MDTChamEff(std::string inFilename, bool isIncremental = false, std::string title="MDT", int txtFileOutputType = 0, bool useOfflineTubeID = false, bool makePDF = false, bool doAllPDF = true); + static void MDTChamOcc(std::string inFilename, std::string title="MDT"); + static void MDTTDCSum(std::string inFilename, std::string title="MDT"); + static void MDTLowStat(std::string inFilename, std::string title="MDT"); + static bool MDTCheckAlign(std::string inFilename, std::string title="MDT"); + static bool MDTCheck(std::string inFilename); + static void MDTTubeEff(const TString & dirName, const TH1F*, const TH1F*, TH1F*, float &countsML1, float &countsML2, float &entriesML1, float &entriesML2); + static void MDT2DHWName(TString, TString &, TString &, TString &, TString &, TString &); + static void MDTFitTDC(TH1F* h, double &t0, double &t0Err, double &tmax, double &tmaxErr); + static void MDTSetMetaData(TDirectory* targetDir, TH1* h1, TH1* h2=0, TH1* h3=0); + static void MDTSet2DRangeZ(TH2F* h); + static void MDTResetContents(TH2F* h); + static void MDTFinalizeWriteTH1FChar(TH1F* h); + static double fittzero(double *, double *); + static double fittmax(double *, double *); + static void GetTubeLength(double & tubeLength, TString dirName); + static TString returnString(int a); + static TString returnString(double a); + static TString ConvertTubeVectorToString(std::vector<int> & v, TH1F* h, TString chamber); + static TString ConvertLayerVectorToString(std::vector<int> & v, TString chamber); + static TString ConvertMezzVectorToString(std::vector<int> & v, TH1F* h, TString chamber); + static TString ConvertVectorToString(std::vector<int> & v); + static TString TubeID_to_ID_L_ML(int & tubeID, const TString & hardware_name, int totalTubes); + static TString Layer_to_L_ML(int & tubeID, const TString & hardware_name); + static TString Mezz_to_ML_mezz(int tubeID, const TString & hardware_name, int totalTubes); + static bool tdcSort(const TH1* h1, const TH1* h2); + class MDTPostProcessor : public TFile { //class to keep keep track of histograms we collect + public: + MDTPostProcessor(std::string inFilename, std::string name); + ~MDTPostProcessor(); //delete all objects accessed from the TFile whose SetDirectory(0) + + //function to automatically getObject, obj->SetDirectory(target), if target==0 save target for future deletion + //option to supply baseDir to get object from subdir of TFile rather than from TFile itself + //target if nothing is supplied thatn the object will be set to 0 (protects against f->Write() writing unintended copies of your histogram + template <class T> + void get(const char* namecycle, T* &ptr, TDirectory* baseDir=0, TDirectory* target=0); //use TDirectory->GetObject(const char* namecycle, void* &ptr); + void setDirectory(TH1* h, TDirectory* dir = 0); + void setDirectory(TH2* h, TDirectory* dir = 0); + void setMetaData(TDirectory* targetDir, TH1* h1, TH1* h2=0, TH1* h3=0); + void error();//call this function if you want the underlying TFile not to write i.e. recover error in program + private: + std::set<TObject*> m_garbage; + std::string m_name; + bool m_error; + }; + + static void RPCPostProcess(std::string inFilename, bool isIncremental = false); + static bool RPCCheckHistogram(TFile* f, const char* HistoName); + + //For TGC + static void TGCPostProcess(std::string inFilename, bool isIncremental = false); + static void TGCChannelOccupancy(std::string inFilename, std::vector< std::pair< std::string, float > >& p); + static void TGCChamberOccupancy(std::string inFilename, std::vector< std::pair< std::string, float > >& phigh, std::vector< std::pair< std::string, float > >& plow); + static void TGCChamberEfficiency(std::string inFilename, std::vector< std::pair< std::string, float > >& p); + static void TGCChamberTiming(std::string inFilename, std::vector< std::pair< std::string, float > >& pro, std::vector< std::pair< std::string, float > >& ptrg); + //static void TGCDQResultsToCool(); + static void TGCsubsectbin2stationeta(int subsect, int bin, int& station, int& eta); + static void TGCsubsect2sectorphi(int subsect, int& sector, int& phi4); + static void TGCRawHistogramDivision(std::string inFilename); + static void TGCLV1HistogramDivision(std::string inFilename); + static int nTGCWireStripMap(int ws, int etac, int phi48); + static int getTGCNumberOfWires(const int istationName, const int layer, const int istationEta, const int istationPhi); + static void TGCResetContents(TH1* h); + + //For MDTvsTGC + static void MDTvsTGCPostProcess(std::string inFilename, bool isIncremental = false); + static void MDTvsTGCEfficiency(std::string inFilename); + static void MDTvsTGCResetContents(TH1* h); + + class PostProcessorFileWrapper : public TFile { //class to keep keep track of histograms we collect + public: + PostProcessorFileWrapper(std::string inFilename, std::string name); + ~PostProcessorFileWrapper(); //delete all objects accessed from the TFile whose SetDirectory(0) + + //function to automatically getObject, obj->SetDirectory(target), if target==0 save target for future deletion + //option to supply baseDir to get object from subdir of TFile rather than from TFile itself + //target if nothing is supplied thatn the object will be set to 0 (protects against f->Write() writing unintended copies of your histogram + template <class T> + void get(const char* namecycle, T* &ptr, TDirectory* baseDir=0, TDirectory* target=0); //use TDirectory->GetObject(const char* namecycle, void* &ptr); + void setDirectory(TH1* h, TDirectory* dir = 0); + void setDirectory(TH2* h, TDirectory* dir = 0); + void setDirectory(TGraph* g, TDirectory* dir = 0); + void setMetaData(TDirectory* targetDir, TH1* h1, TH1* h2=0, TH1* h3=0); + void error();//call this function if you want the underlying TFile not to write i.e. recover error in program + private: + std::set<TObject*> m_garbage; + std::string m_name; + bool m_error; + }; + // + //static bool TGCCheckFile(std::string inFilename, std::string& run_dir); + static bool TGCCheckHistogram(TFile *f, TString& hname); + static void TGCSetMetaData(TDirectory* targetDir, TH1* h1, TH1* h2=0, TH1* h3=0); + + //For HLT Muon + static void HLTMuonPostProcess(std::string inFilename, bool isIncremental = false); + static void HLTMuonHistogramDivision(std::string inFilename, TString& run_dir); + static void HLTMuonTriggerOverlapMatrix(std::string inFilename, TString& run_dir); + static bool HLTMuonCheckHistogram(TFile* f, TString& hname); + static void HLTMuonHDiv(PostProcessorFileWrapper& mf, TString sdir, TString snum, TString sden, TString seff, TString seffg); + + //HLT Egamma + static void HLTEgammaPostProcess(const std::string &inFilename, bool isIncremental = false); + + static void HLTEgammaEfficiencyOff(TFile* f, TDirectory* trig_dir, TDirectory* off_dir, const TString &pathNum, + const TString &pathEff, const std::vector<TString> &varName); + static void HLTEgammaEfficiencyRel(TFile* f, TDirectory* trig_dir, const TString &pathPre, const TString &pathRej, + const std::vector<TString> &objStage, const std::vector<TString> &varName); + + //HLT tau + static void HLTTauPostProcess(std::string inFilename, bool isIncremental = false); + + static void HLTTauPostProcess(TFile* f, TDirectory* dir, + TString pathApp, TString pathAppEff, + std::vector<TString> lvlN, std::vector<TString> varN, + std::vector< std::pair< int, int > > ratioIndex, int nameStyle, + TString nameApp = ""); + + static std::string getPath (TDirectory* dir); + + // HLT MET + static void HLTMETPostProcess(std::string inFileName, bool isIncremental = false); + static void HLTMETAveragePhivsEtaMaps(TFile *f, TString& run_dir); + static size_t HLTMETGetDQLBNRange(TDirectory*& run_dir, std::vector<TString>& lbnDirs); + static int HLTMETGetStatusPerBin(TH1I *&hist, int ymin, int ymax, int rmin, int rmax); + static void HLTMETDQFlagSummary(TFile *f, TString& run_dir); + + // HLT Jet + static void HLTCaloPostProcess(std::string inFileName, bool isIncremental = false); + static void HLTCaloAveragePtPhiEtaMaps(TFile* f, TString& run_dir); + + // HLT Jet + static void HLTJetPostProcess(std::string inFileName, bool isIncremental = false); + static void HLTJetCalcEfficiencyAndRate(TFile* f, TString& run_dir); + + //JetTagging + static void BJetTaggingPostProcess(std::string inFileName, bool isIncremental = false); + static void BJetTaggingAdjustRanges(TFile * f); + static void BJetTaggingNormalise(TFile * f); + + // primary vertex monitoring + static void pv_PrimaryVertexMonitoring_calcResoAndEfficiency(std::string inFilename, bool isIncremental = false); + + // primary vertex multiplicity monitoring + static void VxMon_move(std::string inFilename, bool isIncremental=false); + + // L1Calo + static void L1CaloPostProcess(std::string inFileName, bool isIncremental = false); + static void L1CaloStabilityRMS(TFile* f, const TString& nameDir, const TString& nameTag); + static void L1CaloFillWithError(TFile* f, const TString& nameDir, const TString& nameData, + const TString& nameError); + static void L1CaloResetEfficiencies(TFile* f, const TString& effDir, + const TString& nameDen, const TString& nameEff, + int items, double threshold, int binSkip); + + // SCT + static void SCTPostProcess(std::string inFilename, bool isIncremental = false); + + // Other helper methods + // Compute Bin Errors a la Ullrich, Paterno, Xu (see source file for more details) + static int ComputeUPXBinErrors(TH1F *hnum, TH1F *hden, std::vector<float>& errors); + + /** + * Clears all previous data and opens the file with the given name for analysis, returning a + * boolean indicating whether the file was opened successfully or not. + */ + + virtual bool setFile(std::string fileName); + + + virtual void printDirectories() const; + + virtual void printStatistics() const; + + + /** + * Copy the indicated set of histograms to an output file + */ + + virtual bool copyHistograms(std::string outFileName, + std::string dirName = "all"); + + static std::string getHanResults( std::string hanResultsDir, std::string input, + std::string hcfg, std::string hcfg_min10, std::string hcfg_min30); + + virtual void printHanConfig() const; + + virtual std::string FindCommon(std::string name1, std::string name2) const; + protected: + + static std::string getIndentation(std::string pathName, std::string leadingSpace = ""); + + class HistogramOperation { + public: + virtual ~HistogramOperation() { } + virtual bool execute(TH1* hist) = 0; + virtual bool execute(TGraph* graph) = 0; + virtual bool executeMD(TH1* hist, const MetaData&) { return execute(hist); } + virtual bool executeMD(TGraph* graph, const MetaData&) { return execute(graph); } + }; + + class CopyHistogram : public HistogramOperation { + public: + CopyHistogram(TDirectory* target, std::string dirName); + virtual ~CopyHistogram(); + virtual bool execute(TH1* hist); + virtual bool execute(TGraph* graph); + virtual bool executeMD(TH1* hist, const MetaData& md); + virtual bool executeMD(TGraph* graph, const MetaData& md); + protected: + void copyString(char* to, const std::string& from); + TDirectory* m_target; + std::string m_dirName; + const int m_charArrSize; + TTree* m_metadata; + char* m_nameData; + char* m_intervalData; + char* m_chainData; + char* m_mergeData; + }; + + class GatherStatistics : public HistogramOperation { + public: + GatherStatistics(std::string dirName); + virtual bool execute(TH1* hist); + virtual bool execute(TGraph* graph); + + std::string m_dirName; + int m_nHist1D; + int m_nHist1DBins; + int m_nGraph; + int m_nGraphPoints; + int m_nHist2D; + int m_nHist2DBins; + }; + + class GatherNames : public HistogramOperation { + public: + GatherNames(); + virtual bool execute(TH1* hist); + virtual bool execute(TGraph* graph); + + std::vector<std::string> m_names; + }; + + + virtual void clearData(); + + + static bool dirHasHistogramsInMetadata(TDirectory* dir); + + static void loopOnHistograms(HistogramOperation& fcn, TDirectory* dir); + + static bool loopOnHistogramsInMetadata(HistogramOperation& fcn, TDirectory* dir); + + static bool setListFromFile(std::vector<std::string>& filelist, + const std::string& listFileName); + + TFile* m_file; + + /* Methods for merging luminosity block intervals + */ + private: + enum debugLevel_t { none = 0, DEBUG, VERBOSE }; + typedef std::map<TDirectory*, std::vector<TDirectory*> > map_dir_vdir; + + static TObject* mergeObjsMultiCycles(const std::string&, + const std::vector<int>&, + TDirectory*, std::string&, + TObject* = 0); + static int mergeObjs(TObject*, TObject*, std::string, debugLevel_t debugLevel = none); + static int mergeLB_createListOfHistos(TDirectory*, TDirectory*, std::vector<std::string>&, debugLevel_t&); + static int mergeLB_recursiveDirCopy(TDirectory*, TDirectory*, TDirectory*, std::vector<std::string>&, debugLevel_t&); + static int mergeLB_processLBinterval(std::vector<TDirectory*>&, TDirectory*, debugLevel_t&); + static void buildLBToIntervalMap(std::vector<TDirectory*>&, std::vector<TDirectory*>&, map_dir_vdir&, debugLevel_t&); + static int mergeLB_processLB(std::vector<TDirectory*>&, std::vector<TDirectory*>&, debugLevel_t&); + static int mergeLB_processRun(TDirectory*, debugLevel_t&); + + static Int_t getNumBins(const TH1& hist); + boost::regex *m_mergeMatchHistoRE; + boost::regex *m_mergeMatchDirRE; + std::string m_mergeMatchHistoREString; + std::string m_mergeMatchDirREString; + bool m_useRE; + static int m_debugLevel; + static int m_fileCompressionLevel; + public: + static int mergeLBintervals(std::string, std::string debugLevel = "none"); + static int getDebugLevel(); + static void setDebugLevel(int level); + static int getCompressionLevel(){return m_fileCompressionLevel;} + static void setCompressionLevel(int level){m_fileCompressionLevel=level;} + bool setHistogramRegEx(const std::string& re); + bool setDirectoryRegEx(const std::string& re); + + ClassDef(MonitoringFile, 0) // Provides functions to manipulate and analyze data-quality monitoring files + + }; + + std::string getInputDirectory(std::string outputDirName, TFile* input, bool has_multiple_runs, std::map< TFile*, std::string >* prefixes); + + std::string getOutputDirectory(std::string inputDirName, TFile* input, bool has_multiple_runs, std::map< TFile*, std::string >* prefixes); + + std::string getOutputDirectory(TKey* key, TFile* input, bool has_multiple_runs, std::map< TFile*, std::string >* prefixes); + + template <class T> + void MonitoringFile::PostProcessorFileWrapper::get(const char* namecycle, T* &ptr, TDirectory* baseDir, TDirectory* target){ + + if (baseDir) baseDir->GetObject(namecycle, ptr); // suggested root function + else this->GetObject(namecycle, ptr); //suggested root function + if(!ptr) return; + + if((T::Class())->InheritsFrom("TH1")){ + TH1 *obj = reinterpret_cast<TH1*> (ptr); + + obj->SetDirectory(target); + if(target == 0) m_garbage.insert(obj); + } + else{ + TObject *obj = reinterpret_cast<TObject*>(ptr); + + if(target == 0) m_garbage.insert(obj); + } + } +} // namespace dqutils + +// #include "DataQualityUtils/MonitoringFile_PPFileWrapper.cxx" +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/RootLinkDef.h b/DataQuality/DataQualityUtils/DataQualityUtils/RootLinkDef.h new file mode 100644 index 0000000000000000000000000000000000000000..49a4e496a0ab21b156862431d60574adbf8c4c6f --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/RootLinkDef.h @@ -0,0 +1,23 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ namespace dqutils ; + +#pragma link C++ class dqutils::HanOutputFile! ; +#pragma link C++ class dqutils::MonitoringFile! ; +#pragma link C++ class dqutils::StatusFlagCOOL! ; +#pragma link C++ class dqutils::StatusFlagCOOLBase! ; +#pragma link C++ class dqutils::StatusFlagCommentCOOL! ; +#pragma link C++ class dqutils::HistogramDataCOOL! ; +#pragma link C++ class dqutils::CoolRpc ; +#pragma link C++ class dqutils::CoolMdt ; +#pragma link C++ class dqutils::CoolTgc ; + +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/StatusFlagCOOL.h b/DataQuality/DataQualityUtils/DataQualityUtils/StatusFlagCOOL.h new file mode 100644 index 0000000000000000000000000000000000000000..dd26d8395920158ffae3b1324bbdd3470d54c97c --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/StatusFlagCOOL.h @@ -0,0 +1,67 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef dqutilsStatusFlagCOOL_h +#define dqutilsStatusFlagCOOL_h + +// Protect CINT from some system definitions that cause problems +#ifndef __CINT__ + //COOL API include files (CoolKernel) + #include "CoolKernel/pointers.h" + #include "CoolKernel/ValidityKey.h" +#else + namespace cool { + class IDatabasePtr; + class IFolderPtr; + } +#endif + + +#include <iostream> +#include <string> +#include <cstdlib> + +#include <TObject.h> + +//CORAL API include files +#include "CoralBase/AttributeList.h" + +//COOL API include files (CoolApplication) +#include "CoolApplication/Application.h" +// --> limits.h is needed for CoolKernel/types.h +#include <limits.h> +#include "CoolKernel/types.h" +#include "CoolKernel/ChannelId.h" +#include "CoolKernel/RecordSpecification.h" +#include "CoolKernel/ChannelSelection.h" + +#include "DataQualityUtils/StatusFlagCOOLBase.h" + +namespace dqutils { + +class StatusFlagCOOL : public StatusFlagCOOLBase { + +public: + // Methods needed to come up to COOL framework. + cool::RecordSpecification createSpec(); + coral::AttributeList createPayload(int colourCode, float dfrac, float thrust, const + cool::RecordSpecification& spec); + + // Constructors and Destructors. + StatusFlagCOOL(std::string dbStr, std::string folderStr, int runS, int lumiS, int runU, int lumiU); + StatusFlagCOOL(int runS, int lumiS, int runU, int lumiU); + StatusFlagCOOL(); + virtual ~StatusFlagCOOL () {}; + + // Methods of "interest". To insert a status flag you can use either ChannelId or ChannelName. + void insert(cool::ChannelId channelId, int code, float dfrac, float thrust, std::string tag_name); + void insert(std::string channelName, int code, float dfrac, float thrust, std::string tag_name); + + // Needed for the ROOT interface. + ClassDef( StatusFlagCOOL, 0 ) // A class for modifying DQ info in the COOL database +}; + +} + +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/StatusFlagCOOLBase.h b/DataQuality/DataQualityUtils/DataQualityUtils/StatusFlagCOOLBase.h new file mode 100644 index 0000000000000000000000000000000000000000..a57aab00f93e7478206e9592cc06dc04e8284edc --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/StatusFlagCOOLBase.h @@ -0,0 +1,110 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef dqutilsStatusFlagCOOLBase_h +#define dqutilsStatusFlagCOOLBase_h + +// Protect CINT from some system definitions that cause problems +#ifndef __CINT__ + //COOL API include files (CoolKernel) + #include "CoolKernel/pointers.h" + #include "CoolKernel/ValidityKey.h" +#else + namespace cool { + class IDatabasePtr; + class IFolderPtr; + } +#endif + + +#include <iostream> +#include <string> +#include <cstdlib> + +#include <TObject.h> + +//CORAL API include files +#include "CoralBase/AttributeList.h" + +//COOL API include files (CoolApplication) +#include "CoolApplication/Application.h" +// --> limits.h is needed for CoolKernel/types.h +#include <limits.h> +#include "CoolKernel/types.h" +#include "CoolKernel/ChannelId.h" +#include "CoolKernel/RecordSpecification.h" +#include "CoolKernel/ChannelSelection.h" + + +namespace coral { + class AttributeList; +} + +namespace cool { + class RecordSpecification; + class ChannelSelection; +} + + +namespace dqutils { + +class StatusFlagCOOLBase : public cool::Application, public TObject { +protected: + +// Protect CINT from some system definitions that cause problems +// CINT does not need to know about these private variables +#ifndef __CINT__ + cool::ValidityKey since; + cool::ValidityKey until; + cool::IDatabasePtr coolDb; + cool::IFolderPtr coolFolder; +#endif + + void insert_helper(cool::ChannelId channelId, + coral::AttributeList& payload, + std::string& tag_name); + void Initialize(std::string dbStr, std::string folderStr, + int runS, int lumiS, int runU, int lumiU); + +public: + // Connects to the database. Throws a "DatabaseDoesNotExist" exception if database does not exist. + cool::IDatabasePtr coolDbInstance(std::string dbStr, bool readOnly); + + // Browses the COOL folder. Throws a "FolderNotFound" exception if folder does not exist. + cool::IFolderPtr coolFolderInstance(std::string folderStr); + + // Various methods to set and print the intervall of validity. + void setSince(cool::Int64 run, cool::Int64 lumi); + void setUntil(cool::Int64 run, cool::Int64 lumi); + void printIOV(); + void setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU); + void setIOV(cool::Int64 run); + + // to flush after insertions! + void flush(); + + // Constructors and Destructors. + StatusFlagCOOLBase(std::string dbStr, std::string folderStr, int runS, int lumiS, int runU, int lumiU); + StatusFlagCOOLBase(int runS, int lumiS, int runU, int lumiU); + StatusFlagCOOLBase(); + virtual ~StatusFlagCOOLBase (); + + // Methods of "interest". To insert a status flag you can use either ChannelId or ChannelName. + void dump(cool::ChannelSelection selection, std::string tag_name); + std::string dumpField(cool::ChannelId channelId, std::string field, std::string tag_name); + int dumpCode(std::string channelName, std::string tag_name); + void dumpall(std::string tag_name); + + // Some further getters. + cool::IFolderPtr getCoolFolder(); + cool::IDatabasePtr getCoolDb(); + + + // Needed for the ROOT interface. + ClassDef( StatusFlagCOOLBase, 0 ) // A class for modifying DQ info in the COOL database +}; + +} + +#endif diff --git a/DataQuality/DataQualityUtils/DataQualityUtils/StatusFlagCommentCOOL.h b/DataQuality/DataQualityUtils/DataQualityUtils/StatusFlagCommentCOOL.h new file mode 100644 index 0000000000000000000000000000000000000000..8e3e73a22effdaaa647cc9c7d41386ce6b67c19a --- /dev/null +++ b/DataQuality/DataQualityUtils/DataQualityUtils/StatusFlagCommentCOOL.h @@ -0,0 +1,78 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef dqutilsStatusFlagCommentCOOL_h +#define dqutilsStatusFlagCommentCOOL_h + +// Protect CINT from some system definitions that cause problems +#ifndef __CINT__ + //COOL API include files (CoolKernel) + #include "CoolKernel/pointers.h" + #include "CoolKernel/ValidityKey.h" +#else + namespace cool { + class IDatabasePtr; + class IFolderPtr; + } +#endif + + +#include <iostream> +#include <string> +#include <cstdlib> + +#include <TObject.h> + +//CORAL API include files +#include "CoralBase/AttributeList.h" + +//COOL API include files (CoolApplication) +#include "CoolApplication/Application.h" +// --> limits.h is needed for CoolKernel/types.h +#include <limits.h> +#include "CoolKernel/types.h" +#include "CoolKernel/ChannelId.h" +#include "CoolKernel/RecordSpecification.h" +#include "CoolKernel/ChannelSelection.h" + +#include "DataQualityUtils/StatusFlagCOOLBase.h" + +namespace coral { + class AttributeList; +} + +namespace cool { + class RecordSpecification; + class ChannelSelection; +} + + +namespace dqutils { + +class StatusFlagCommentCOOL : public StatusFlagCOOLBase { + +public: + + // Methods needed to come up to COOL framework. + cool::RecordSpecification createSpec(); + coral::AttributeList createPayload(int colourCode, float dfrac, float thrust, std::string& comment, const + cool::RecordSpecification& spec); + + // Constructors and Destructors. + StatusFlagCommentCOOL(std::string dbStr, std::string folderStr, int runS, int lumiS, int runU, int lumiU); + StatusFlagCommentCOOL(int runS, int lumiS, int runU, int lumiU); + StatusFlagCommentCOOL(); + virtual ~StatusFlagCommentCOOL() {}; + + // Methods of "interest". To insert a status flag you can use either ChannelId or ChannelName. + void insert(cool::ChannelId channelId, int code, float dfrac, float thrust, std::string comment, std::string tag_name); + void insert(std::string channelName, int code, float dfrac, float thrust, std::string comment, std::string tag_name); + + // Needed for the ROOT interface. + ClassDef( StatusFlagCommentCOOL, 0 ) // A class for modifying DQ info in the COOL database +}; + +} + +#endif diff --git a/DataQuality/DataQualityUtils/cmt/requirements b/DataQuality/DataQualityUtils/cmt/requirements new file mode 100644 index 0000000000000000000000000000000000000000..394f8cf2f011206c45fe29a6161864562d4a6f43 --- /dev/null +++ b/DataQuality/DataQualityUtils/cmt/requirements @@ -0,0 +1,165 @@ +package DataQualityUtils + +author Rob McPherson <Robert.McPherson@cern.ch> +author Michael G. Wilson <Michael.G.Wilson@cern.ch> +author Peter Onyisi <ponyisi@cern.ch> + + +private + +apply_tag ROOTGraphicsLibs +apply_tag NEEDS_COOL_FACTORY +apply_tag ROOTRooFitLibs +apply_tag ROOTMathLibs + +#use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL +#use CoraCool CoraCool-* Database +use DataQualityInterfaces * DataQuality +#removing due to checkreq.py warnings +#use DataQualityConfigurations * DataQuality +#moved to public area due to checkreq.py warnings +#use AtlasBoost AtlasBoost-* External + +macro_append Boost_linkopts " $(Boost_linkopts_regex) " +#sami -uncomment to enable debug symbols +#macro cppdebugflags '$(cppdebugflags_s)' +#macro_remove componentshr_linkopts "-Wl,-s" +# sami end enable debug build + + +end_private + + +public + +use AtlasPolicy AtlasPolicy-* +#use AtlasPython AtlasPython-* External +use AtlasROOT AtlasROOT-* External +use AtlasCOOL AtlasCOOL-* External +use AtlasCORAL AtlasCORAL-* External +use AtlasBoost AtlasBoost-* External + + +############################################################################## +# library: DataQualityUtils +############################################################################## + +library DataQualityUtils $(lib_opts) "\ + ../src/HanOutputFile.cxx\ + ../src/MonitoringFile.cxx\ + ../src/MonitoringFile_CSCPostProcess.cxx\ + ../src/MonitoringFile_RPCPostProcess.cxx\ + ../src/MonitoringFile_MDTPostProcess.cxx\ + ../src/MonitoringFile_TGCPostProcess.cxx\ + ../src/MonitoringFile_MDTvsTGCPostProcess.cxx\ + ../src/MonitoringFile_PPFileWrapper.cxx\ + ../src/MonitoringFile_IDAlignPostProcess.cxx\ + ../src/MonitoringFile_IDPerfPostProcess.cxx\ + ../src/MonitoringFile_DiMuPostProcess.cxx\ + ../src/MonitoringFile_IDEnhancedPrimaryVertex.cxx\ + ../src/MonitoringFile_MoveVertexMonitoring.cxx\ + ../src/MonitoringFile_HLTMuonPostProcess.cxx\ + ../src/MonitoringFile_HLTEgammaPostProcess.cxx\ + ../src/MonitoringFile_HLTTauPostProcess.cxx\ + ../src/MonitoringFile_HLTMETPostProcess.cxx\ + ../src/MonitoringFile_HLTCaloPostProcess.cxx\ + ../src/MonitoringFile_HLTJetPostProcess.cxx\ + ../src/MonitoringFile_SCTPostProcess.cxx\ + ../src/MonitoringFile_MuonTrkPhys.cxx\ + ../src/MonitoringFile_MergeAlgs.cxx\ + ../src/StatusFlagCOOL.cxx\ + ../src/StatusFlagCOOLBase.cxx\ + ../src/StatusFlagCommentCOOL.cxx\ + ../src/HistogramDataCOOL.cxx\ + ../src/CoolRpc.cxx\ + ../src/CoolMdt.cxx\ + ../src/CoolTgc.cxx\ + ../src/MdtDeadNoisyUtils.cxx\ + ../src/MonitoringFile_CSCChamberEfficiency.cxx\ + ../src/MonitoringFile_CSCClusterFit.cxx\ + ../src/MonitoringFile_TgcHistogramDivision.cxx\ + ../src/MonitoringFile_HLTMuonHistogramDivision.cxx\ + ../src/MonitoringFile_HLTEgammaEfficiency.cxx\ + ../src/MonitoringFile_HLTMETAveragePhivsEtaMaps.cxx\ + ../src/MonitoringFile_HLTMETDQFlagSummary.cxx\ + ../src/MonitoringFile_HLTJetCalcEfficiencyAndRate.cxx\ + ../src/MonitoringFile_HLTCaloAveragePtPhiEtaMaps.cxx\ + ../src/MonitoringFile_BJetTaggingPostProcess.cxx\ + ../src/MonitoringFile_BJetTaggingAdjustRanges.cxx\ + ../src/MonitoringFile_BJetTaggingNormalise.cxx\ + ../src/MonitoringFile_L1CaloPostProcess.cxx\ + $(bin)DataQualityUtilsRootDict.cxx" + +apply_pattern installed_library + +macro_append DataQualityUtils_dependencies " dqutils_root_dictionary " + +macro_append dqutils_root_dictionary_dependencies " install_includes " + +action dqutils_root_dictionary "( $(ROOTSYS)/bin/rootcint -f $(bin)DataQualityUtilsRootDict.cxx -c -p $(includes)\ + ../DataQualityUtils/HanOutputFile.h\ + ../DataQualityUtils/MonitoringFile.h\ + ../DataQualityUtils/StatusFlagCOOL.h\ + ../DataQualityUtils/StatusFlagCOOLBase.h\ + ../DataQualityUtils/StatusFlagCommentCOOL.h\ + ../DataQualityUtils/HistogramDataCOOL.h\ + ../DataQualityUtils/CoolRpc.h\ + ../DataQualityUtils/CoolMdt.h\ + ../DataQualityUtils/CoolTgc.h\ + ../DataQualityUtils/MdtDeadNoisyUtils.h\ + ../DataQualityUtils/RootLinkDef.h )" + + +############################################################################# +# application: han-results-print +############################################################################# + +application han-results-print -no_prototypes "../src/han_results_print.cxx" + +macro han-results-print_dependencies "DataQualityUtils" +alias han-results-print han-results-print.exe + +#uncomment to build c++ postprocessing test application +#application PostProcessTest -no_prototypes "../share/PostProcessTest.cxx" +#macro PostProcessTest_dependencies "DataQualityUtils" +#application MergeFilesTest -no_prototypes "../share/MergeFilesTest.cxx" +#macro MergeFilesTest_dependencies "DataQualityUtils" +#application GetHanResultsTest -no_prototypes "../share/HanResultsTest.cxx" +#macro GetHanResultsTest_dependencies "DataQualityUtils" + + +############################################################################## +# python modules and scripts +############################################################################## + +## Python scripts are in the 'scripts' directory; only some are installed +apply_pattern declare_scripts files='-s=../scripts CreateDB.py CreateDB_Histo.py \ + DQHistogramMerge.py DQHistogramPrintStatistics.py \ + DQWebDisplay.py hancool_histo.py hancool.py handi.py historyDisplay.py \ + DQFileMove.py CreateMDTConfig_algos.sh CreateMDTConfig_chambers.sh \ + CreateMDTConfig_config.sh CreateMDTConfig_files.sh CreateMDTConfig_readme.sh \ + DQM_Tier0Wrapper_trf.py DQHistogramMergeRegExp.py dq_make_web_display.py \ + ScanHistFile.py physval_make_web_display.py\ + ' + +alias CreateDB_Histo CreateDB_Histo.py +alias DQHistogramMerge DQHistogramMerge.py +alias DQHistogramPrintStatistics DQHistogramPrintStatistics.py +alias DQWebDisplay DQWebDisplay.py +alias hancool_histo hancool_histo.py +alias hancool hancool.py +alias handi handi.py +alias historyDisplay historyDisplay.py +alias CreateMDTConfig_algos CreateMDTConfig_algos.sh +alias CreateMDTConfig_chambers CreateMDTConfig_chambers.sh +alias CreateMDTConfig_config CreateMDTConfig_config.sh +alias CreateMDTConfig_files CreateMDTConfig_files.sh +alias CreateMDTConfig_readme CreateMDTConfig_readme.sh + +## These plugins are for the QuerryDB.py script; uncomment if you install it (above) +#apply_pattern generic_declare_for_link kind=python_plugins \ +# files='-s=../python/plugins default.py' \ +# prefix=share/bin/plugins + +## Python modules are in the 'python' directory +apply_pattern declare_python_modules files='*.py' diff --git a/DataQuality/DataQualityUtils/python/DBInfo.py b/DataQuality/DataQualityUtils/python/DBInfo.py new file mode 100755 index 0000000000000000000000000000000000000000..36b76a485015b16477b6fddd705ded7e41fd37ee --- /dev/null +++ b/DataQuality/DataQualityUtils/python/DBInfo.py @@ -0,0 +1,34 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + + +# +---------------------------------------------+ +# | Vassilis D. Kazazakis - DBInfo.py v1.0 | +# | Returns COOL DB connection information | +# +---------------------------------------------+ + +# user & password information should be handled by each individual program + +def getReadServer(): + return "ATLAS_COOLPROD" + +def getWriteServer(): + #return "ATLAS_COOLWRITE" + return "" + +def getFolder(): + #return "/GLOBAL/DQM/HIST" + return "/GLOBAL/DETSTATUS/DQMFOFL" #/GLOBAL/DETSTATUS/DQMFOFLH" + +def getDbName(): + return "COMP200" +# return "STRMP200" + +def getSchema(): + #return "ATLAS_COOLOFL_GLOBAL" + return "MyCOOL.db" + +def getChannelDict(): + import DBInfo_Histo + ######################################### + + return DBInfo_Histo.getChannelDict() diff --git a/DataQuality/DataQualityUtils/python/DBInfo_Histo.py b/DataQuality/DataQualityUtils/python/DBInfo_Histo.py new file mode 100755 index 0000000000000000000000000000000000000000..7b86ae2b00436a99991683625331049c3668528f --- /dev/null +++ b/DataQuality/DataQualityUtils/python/DBInfo_Histo.py @@ -0,0 +1,241 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + + +# +---------------------------------------------+ +# | Vassilis D. Kazazakis - DBInfo.py v1.0 | +# | Returns COOL DB connection information | +# | Updated by M.D'Onofrio: new folder added | +# | for history plots | +# +---------------------------------------------+ + +# user & password information should be handled by each individual program + +def getReadServer(): + return "ATLAS_COOLPROD" + +def getWriteServer(): + #return "ATLAS_COOLWRITE" + return "" + +def getFolder(): + #return "/GLOBAL/DQM/HIST" + return "/GLOBAL/DETSTATUS/DQMFOFL" + +def getFolders(): + #return "/GLOBAL/DQM/HIST" + return ["/GLOBAL/DETSTATUS/DQMFOFL", "/GLOBAL/DETSTATUS/SHIFTOFL"] + +def getFolderH(): + #return "/GLOBAL/DQM/HIST" + return "/GLOBAL/DETSTATUS/DQMFOFLH" + +def getDbName(): +# return "OFLP200" + return "COMP200" +# return "STRMP200" + +def getSchema(): + #return "ATLAS_COOLOFL_GLOBAL" + return "MyCOOL_histo.db" + +def getChannelDict(): + from DetectorStatus.DetStatusLib import DetStatusNames + dsn = DetStatusNames() + channelDict = dsn.namedict.copy() +## channelDict = dict([]) + +## # the following channels are for the M4 # +## #channelDict["default"] = 0 +## #channelDict["default_dqmf"] = 1 + +## # DB Structure as in DBQuery (from DetStatusLib.py) + +## # Inner Detector +## channelDict["PIXB"] = 101 +## channelDict["PIX0"] = 102 #new: Pixel B-layer +## channelDict["PIXEA"] = 104 +## channelDict["PIXEC"] = 105 + +## channelDict["SCTB"] = 111 +## channelDict["SCTEA"] = 114 +## channelDict["SCTEC"] = 115 + +## channelDict["TRTB"] = 121 +## channelDict["TRTEA"] = 124 +## channelDict["TRTEC"] = 125 + +## # obsolete +## #channelDict["IDGB"] = 131 +## #channelDict["IDGEA"] = 134 +## #channelDict["IDGEC"] = 135 +## #channelDict["IDAB"] = 141 +## #channelDict["IDAEA"] = 144 +## #channelDict["IDAEC"] = 145 +## # new ID Alignement and Global +## channelDict["IDGL"] = 130 +## channelDict["IDAL"] = 140 +## channelDict["IDBS"] = 150 +## channelDict["IDPF"] = 160 +## channelDict["IDVX"] = 161 +## channelDict["IDBCM"] = 170 + +## # LAr +## channelDict["EMBA"] = 202 +## channelDict["EMBC"] = 203 +## channelDict["EMECA"] = 204 +## channelDict["EMECC"] = 205 +## channelDict["HECA"] = 214 +## channelDict["HECC"] = 215 +## channelDict["FCALA"] = 224 +## channelDict["FCALC"] = 225 + +## # TileCal +## channelDict["TIGB"] = 230 +## channelDict["TILBA"] = 232 +## channelDict["TILBC"] = 233 +## channelDict["TIEBA"] = 234 +## channelDict["TIEBC"] = 235 + +## # MBTS +## channelDict["MBTSA"] = 244 +## channelDict["MBTSC"] = 245 + +## # TileCal+LAr +## channelDict["CALBA"] = 251 +## channelDict["CALEA"] = 254 +## channelDict["CALEC"] = 255 + +## # Muon Detectors +## channelDict["MDTBA"] = 302 +## channelDict["MDTBC"] = 303 +## channelDict["MDTEA"] = 304 +## channelDict["MDTEC"] = 305 +## channelDict["RPCBA"] = 312 +## channelDict["RPCBC"] = 313 +## channelDict["TGCEA"] = 324 +## channelDict["TGCEC"] = 325 +## channelDict["CSCEA"] = 334 +## channelDict["CSCEC"] = 335 + +## # Lumi +## channelDict["LCD"] = 350 +## channelDict["LCDA"] = 353 +## channelDict["LCDC"] = 354 +## channelDict["ALFA"] = 360 +## channelDict["ZDC"] = 370 + +## # Trigger +## channelDict["L1CAL"] = 401 +## channelDict["L1MUB"] = 402 +## channelDict["L1MUE"] = 403 +## channelDict["L1CTP"] = 404 +## channelDict["TRCAL"] = 411 +## channelDict["HLTEF"] = 412 +## channelDict["TRBJT"] = 421 +## channelDict["TRBPH"] = 422 +## channelDict["TRCOS"] = 423 +## channelDict["TRELE"] = 424 +## channelDict["TRGAM"] = 425 +## channelDict["TRJET"] = 426 +## channelDict["TRMET"] = 427 +## channelDict["TRMBI"] = 428 +## channelDict["TRMUO"] = 429 +## channelDict["TRTAU"] = 430 +## channelDict["TRIDT"] = 431 + +## channelDict["LUMI"] = 450 +## channelDict["RUNCLT"] = 460 +## channelDict["RCOPS"] = 461 + +## channelDict["ATLGL"] = 480 +## channelDict["ATLSOL"] = 481 +## channelDict["ATLTOR"] = 482 + +## # Physics Objects +## channelDict["EIDB"] = 501 +## channelDict["EIDCR"] = 502 +## channelDict["EIDE"] = 503 +## channelDict["PIDB"] = 505 +## channelDict["PIDCR"] = 506 +## channelDict["PIDE"] = 507 +## channelDict["EIDF"] = 508 +## channelDict["EIDSOFT"] = 509 +## channelDict["MSTACO"] = 510 +## channelDict["MMUIDCB"] = 511 +## channelDict["MMUIDVX"] = 512 +## channelDict["MMUGIRL"] = 513 +## channelDict["MMUBOY"] = 514 +## channelDict["MMUIDSA"] = 515 +## channelDict["MMUTAG"] = 516 +## channelDict["MMTIMO"] = 517 +## channelDict["MCMUTAG"] = 518 +## channelDict["MCALLHR"] = 519 +## channelDict["JETB"] = 521 +## channelDict["JETEA"] = 524 +## channelDict["JETEC"] = 525 +## channelDict["JETFA"] = 526 +## channelDict["JETFC"] = 527 +## channelDict["MET"] = 530 +## channelDict["METCALO"] = 531 +## channelDict["METMUON"] = 532 +## channelDict["BTGLIFE"] = 541 +## channelDict["BTGSOFTE"] = 544 +## channelDict["BTGSOFTM"] = 545 +## channelDict["TAUB"] = 551 +## channelDict["TAUCR"] = 552 +## channelDict["TAUE"] = 553 + + ######################################### + + return channelDict + +def getChannelDictH(): + # This is all deprecated of course + print 'Why are you calling this function? This is very very deprecated ... - ponyisi, 17/6/10' + channelDict = dict([]) + + + channelDict["/InnerDetector/IDAlignment/ExtendedTracks_NoTriggerSelection/GenericTracks/Npixhits_per_track"]=10039 + channelDict["/InnerDetector/IDAlignment/ExtendedTracks_NoTriggerSelection/GenericTracks/Nscthits_per_track"]=10040 + channelDict["/InnerDetector/IDAlignment/ExtendedTracks_NoTriggerSelection/GenericTracks/Ntrthits_per_track"]=10041 + + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/HitEfficiencies/measurements_eff_vs_layer_barrel"]=10042 + + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Npixhits_per_track_barrel"]=10043 + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Npixhits_per_track_eca"]=10044 + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Npixhits_per_track_ecc"]=10045 + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Nscthits_per_track_barrel"]=10046 + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Nscthits_per_track_eca"]=10047 + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Nscthits_per_track_ecc"]=10048 + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Ntrthits_per_track_barrel"]=10049 + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Ntrthits_per_track_eca"]=10050 + channelDict["/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Ntrthits_per_track_ecc"]=10051 + + + channelDict["/InnerDetector/IDAlignment/PrimVtx/NoTriggerSelection/pvChiSqDof"]=10082 + channelDict["/InnerDetector/IDAlignment/PrimVtx/NoTriggerSelection/pvX"]=10083 + channelDict["/InnerDetector/IDAlignment/PrimVtx/NoTriggerSelection/pvY"]=10084 + channelDict["/InnerDetector/IDAlignment/PrimVtx/NoTriggerSelection/pvZ"]=10085 + + channelDict["/InnerDetector/IDAlignment_Perf/Jpsi-->mumu/NoTriggerSelection/Jpsi_invmass"]=100102 + channelDict["/InnerDetector/IDAlignment_Perf/Kshort-->pipi/NoTriggerSelection/ks_mass"]=100117 + + + channelDict["/InnerDetector/IDAlignment_Perf/Z-->ee/NoTriggerSelection/Zee_Eopasym_perevent"]=100198 + channelDict["/InnerDetector/IDAlignment_Perf/Z-->ee/NoTriggerSelection/Zee_Eop_incl"]=100199 + channelDict["/InnerDetector/IDAlignment_Perf/W-->enu/NoTriggerSelection/Wenu_Eop_incl"]=100200 + + + channelDict["/InnerDetector/IDAlignment_Perf/Z-->mumu/NoTriggerSelection/z-mass_trks"]=100215 + + + channelDict["/InnerDetector/Pixel/PixelExpert/Timing/m_Pixel_track_Lvl1A"]=100220 + channelDict["/InnerDetector/Pixel/PixelExpert/ToT/m_Pixel_track_cluster_ToT"]=100221 + channelDict["/InnerDetector/Pixel/PixelExpert/General/m_Pixel_track_clus_groupsize"]=100222 + + + + ######################################### + + return channelDict + diff --git a/DataQuality/DataQualityUtils/python/DQGetHistogramMod.py b/DataQuality/DataQualityUtils/python/DQGetHistogramMod.py new file mode 100644 index 0000000000000000000000000000000000000000..8028f8ceee4ff453c32b85565fa555d6dc34d4e3 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/DQGetHistogramMod.py @@ -0,0 +1,162 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + + +# +---------------------------------------------+ +# | Vassilis D. Kazazakis, GetHistogram.py v1.0 | +# | Extracts histograms from ROOT files | +# | Interface used by QuerryDB.py application | +# +---------------------------------------------+ + +import sys +import getopt +import os + +import ROOT +startDir = os.getcwd() +from ROOT import TFile, TBrowser, TKey ## This breaks up argument parsing and current directory +os.chdir(startDir) + +def getFullName(dir): + motherDir = dir.GetMotherDir() + if not motherDir: + return "" # it means that dir = TFile and we don't want the name of the file in the full name + else: + return getFullName(motherDir) + dir.GetName() + "/" + + +# getMetaDict(TDirectory dir) +def getMetadataDict(dir): + retDict = dict([]) + + metaKey = dir.FindKey("metadata") + if metaKey: + retDict[getFullName(dir)] = metaKey.ReadObj() + + iter = dir.GetListOfKeys().MakeIterator() + keyNext = iter.Next() + while keyNext: + if keyNext.GetClassName() == "TDirectory": + retDict.update(getMetadataDict(keyNext.ReadObj())); + keyNext = iter.Next() + + return retDict + +def createBrowser(): + browserWin = TBrowser() + wait = raw_input("Enter any 11-digit prime number to continue:") + +def GetObjectList(tFile, path): + + dirList = path.split("/") + ret = [tFile] + for dir in dirList: + if dir == '': + continue + key = ret[0].GetKey(dir) + if not key: + return [] + ret[0] = key.ReadObj() + + # if path ends with a '/' that means we must return a list of + # all histograms (class name begins with TH) in the last directory + if path.endswith('/'): + iter = ret[0].GetListOfKeys().MakeIterator() + ret = [] + keyNext = iter.Next() + while keyNext: + if keyNext.GetClassName()[:2] == "TH": + objNext = keyNext.ReadObj() + ret.append(objNext) + keyNext = iter.Next() + return ret + +def SetObjectDir(tFile, path, obj, clearDict = False, dirDict = dict([])): + if clearDict: + for key,elem in dict(dirDict).iteritems(): + del dirDict[key] + + if not obj: + return + + + dirList = path.split("/") + if not path.endswith('/'): + dirList.pop() + tmpf = tFile + partialPath = '' + + for dir in dirList: + if dir =='': + continue + partialPath += dir + '/' + try: + tmpf = dirDict[partialPath] + except KeyError: +# print "Creating directory '" + dir + "' for directory list:", dirList + tmpf = tmpf.mkdir(dir) + dirDict[partialPath] = tmpf + obj.SetDirectory(tmpf) + +# GetHistogram(string:ROOT_InputFileName, string:ROOT_OutputFileName, list:NameOfHistogramsToExtract) +def GetHistogram(inp, out, nameOptionList): + + # clear the new dir dictionary (necessary if GetHistogram is to be used more than once) + SetObjectDir("", "", None, True) # took me 30 mins to find this f***ing bug... + + changeCount = 0 + inpFile = TFile(inp) + + ################### check for shift/expert/etc flags and construct the approprate list of histograms to get #################### + nameList = [] + metaDict = getMetadataDict(inpFile) + for option in nameOptionList: + optionList = option.split(":") # optionList[0] = histogram name, optionList[1] = flag + if len(optionList) == 1: + if not optionList[0] in nameList: + nameList.append(optionList[0]) + else: # we have a flag + if (not optionList[0].endswith("/")) and (not optionList[0] == ""): # flags go only with directories (i.e. name ends with "/") + print >>sys.stderr, "Warning: Directory names should always end with \"/\" OR flag defined for histogram." + if optionList[0] == "": # we have to get all flagged histograms + for key in metaDict.keys(): + for event in metaDict[key]: + if event.LevelOfDetail == optionList[1]: + histName = key+event.Name + if not histName in nameList: + changeCount += 1 + nameList.append(histName) + if changeCount == 0: + print >>sys.stderr, "Warning: No histogram flagged", optionList[1], "found." + + else: # we have to get flagged histograms only from the specified directory + try: + for event in metaDict[optionList[0]]: + if event.LevelOfDetail == optionList[1]: + histName = optionList[0]+event.Name + if not histName in nameList: + changeCount += 1 + nameList.append(histName) + if changeCount == 0: + print >>sys.stderr, "Warning: No histogram flagged", optionList[1], "found in", optionList[0],"." + except KeyError: + print >>sys.stderr, "Warning:", optionList[0], "directory/metadata object does not exist." + ################################################################################################################################## + + outFile = TFile(out, "RECREATE") + changeCount = 0 + for path in nameList: + objList = GetObjectList(inpFile, path) + for obj in objList: + # print "Setting path for '" + obj.GetName() + "' to '" + path + "'" + changeCount = changeCount + 1 + SetObjectDir(outFile, path, obj) + outFile.Write() + outFile.Flush() + inpFile.Close() + outFile.Close() + if changeCount == 0: + os.remove(out) + return False + else: + return True + diff --git a/DataQuality/DataQualityUtils/python/DQHistogramMergeMod.py b/DataQuality/DataQualityUtils/python/DQHistogramMergeMod.py new file mode 100644 index 0000000000000000000000000000000000000000..d81d28c9b3f9631fd08dbc27db107fb604be2723 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/DQHistogramMergeMod.py @@ -0,0 +1,46 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + + +## ***************************************************************************** +MODVERSION = '$Id: DQHistogramMergeMod.py,v 1.8 2009-05-12 11:38:35 ponyisi Exp $' +## ***************************************************************************** + +import os +## Needed to correct ROOT behavior; see below +CWD = os.getcwd() + +import sys +import ROOT + +## MB: before starting, set ROOT to batch mode +from ROOT import gROOT +gROOT.SetBatch(True) + +## Importing gSystem may change the current directory to one of the +## command-line arguments; chdir to original directory to have +## predictable behavior +from ROOT import gSystem +os.chdir(CWD) + +## Import the ROOT library for reading han results +gSystem.Load('libDataQualityUtils') +from ROOT import dqutils +DoProcMon=False +if DoProcMon: + import DQProcMonitor + DQProcMonitor.startProcMonThread() + +def DQHistogramMerge( listFileName, outFileName, runPostProcessing, directoryRegularExpression=".*", histogramRegularExpression=".*", isIncremental=False, compressionLevel=1,debugLevel=0 ): + + mf = dqutils.MonitoringFile() + if directoryRegularExpression!=".*" or histogramRegularExpression!=".*": + mf.setDirectoryRegEx(directoryRegularExpression) + mf.setHistogramRegEx(histogramRegularExpression) + mf.setDebugLevel(debugLevel) + mf.setCompressionLevel(compressionLevel) + mf.mergeFiles( outFileName, listFileName ) + mf.mergeLBintervals( outFileName ) + + if runPostProcessing: + import DQPostProcessMod + DQPostProcessMod.DQPostProcess( outFileName, isIncremental ) diff --git a/DataQuality/DataQualityUtils/python/DQPostProcessMod.py b/DataQuality/DataQualityUtils/python/DQPostProcessMod.py new file mode 100644 index 0000000000000000000000000000000000000000..77ccdb50cb96dd0d7f446337b73b6a2d6c82ee52 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/DQPostProcessMod.py @@ -0,0 +1,182 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +import os, shutil, re + +from dqu_subprocess import apply as _local_apply + +def _dolsrwrapper(fname): + import ROOT + rf = ROOT.TFile.Open(fname, 'READ') + if not rf or not rf.IsOpen(): + print ' %s is empty or not accessible' % f + return False + + cleancache = ROOT.gROOT.MustClean(); ROOT.gROOT.SetMustClean(False) + _dolsr(rf) + rf.Close() + ROOT.gROOT.SetMustClean(cleancache) + +def _dolsr(dir): + import ROOT + + resultdir = dir.Get('Results'); statusobj = None + + if resultdir: + statusobj = resultdir.Get('Status') + + if statusobj: + l = statusobj.GetListOfKeys() + l[0].GetName() + + keys = dir.GetListOfKeys() + for key in keys: + name = key.GetName() + if ROOT.TClass.GetClass(key.GetClassName()).InheritsFrom('TDirectory'): + dirobj = key.ReadObj() + resultdir = dirobj.Get('Results'); statusobj = None + if resultdir: + statusobj = resultdir.Get('Status') + + # is a check? is a summary? or recurse? + if name[-1] == '_' and resultdir: + hist = dir.Get(name[:-1]) + subkeys = resultdir.GetListOfKeys() + for subkey in subkeys: + ressub = subkey.GetName() + if ressub not in ('Status', 'Reference', 'ResultObject') and ROOT.TClass.GetClass(subkey.GetClassName()).InheritsFrom('TDirectory'): + l = subkey.ReadObj().GetListOfKeys() + l[0].GetName() + + # status flag + l = statusobj.GetListOfKeys() + l[0].GetName() + else: + _dolsr(dirobj) + +def _ProtectPostProcessing( funcinfo, outFileName, isIncremental ): + import os + isProduction = 'DQPRODUCTION' in os.environ and bool(os.environ['DQPRODUCTION']) + func, mail_to = funcinfo + tmpfilename = outFileName + "-safe-" + str(os.getpid()) + shutil.copy2(outFileName, tmpfilename) + success = False + #try to get log file name and curr directory in order to find job info + logFiles="" + currDir=" pwd failed!" + try: + currDir=os.environ["PWD"] + logFilesList=[] + for files in os.listdir(currDir): + if re.match(r'^[0-9]*_.*.log$',files): + logFilesList.append("%s"%files) + logFiles='\r\n'.join(logFilesList) + except Exception, e: + pass + try: + _local_apply(func, (tmpfilename, isIncremental)) + _local_apply(_dolsrwrapper, (tmpfilename,)) + success = True + except Exception, e: + print 'WARNING!!!: POSTPROCESSING FAILED FOR', func.__name__ + print e + print 'Relevant results will not be in output' + if isProduction: + import smtplib + server = smtplib.SMTP('localhost') + mail_cc = ['ponyisi@hep.uchicago.edu', 'adrian.vogel@cern.ch'] + msg = ['From: atlasdqm@cern.ch', + 'To: %s' % ', '.join(mail_to), + 'Cc: %s' % ', '.join(mail_cc), + 'Reply-to: atlasdqm-no-reply@cern.ch', + 'Subject: WARNING: Postprocessing failure in production job', + '', + 'There has been a failure in Tier-0 postprocessing monitoring.', + '', + 'Function: %s' % func.__name__, + 'File: %s' % outFileName, + 'isIncremental? %s' % isIncremental, + 'Error:', + str(e), + 'Current directory (contains LSF job ID): %s' % currDir, + 'Log file name (contains ATLAS T0 job ID): %s' % logFiles + ] + print 'Emailing', ', '.join(mail_to) + server.sendmail('atlasdqm@cern.ch', mail_to + mail_cc, '\r\n'.join(msg)) + server.quit() + print + finally: + if success: + shutil.copy2(tmpfilename, outFileName) + os.unlink(tmpfilename) + +def DQPostProcess( outFileName, isIncremental=False ): + ## Import the ROOT library for reading han results + from ROOT import gSystem + gSystem.Load('libDataQualityUtils') + from ROOT import dqutils + + mf = dqutils.MonitoringFile() + + def rpc_create(dummy, dummy2): + from DataQualityUtils.createRpcFolders import (createRPCDQMFDB, + createRPCConditionDB) + createRPCDQMFDB() + createRPCConditionDB() + + def mdt_create(dummy, isIncremental): +# if False and not isIncremental: + if not isIncremental: + from DataQualityUtils.createMdtFolders import (createMDTConditionDBDead, + createMDTConditionDBNoisy) + createMDTConditionDBDead() + createMDTConditionDBNoisy() + + funclist = [ + (mf.fitMergedFile_IDPerfMonManager, + ['weina.ji@cern.ch', 'ana.ovcharova@cern.ch']), + (mf.fitMergedFile_DiMuMonManager, + ['ana.ovcharova@cern.ch']), + (mf.fitMergedFile_IDAlignMonManager, + ['John.Alison@cern.ch', 'anthony.morley@cern.ch']), + (mf.pv_PrimaryVertexMonitoring_calcResoAndEfficiency, + ['Andreas.Wildauer@cern.ch']), + (mf.VxMon_move, + ['federico.meloni@cern.ch']), + (mf.CSCPostProcess, + ['venkat.kaushik@cern.ch', 'jason.veatch@cern.ch']), + (rpc_create, + ['michele.bianco@le.infn.it', 'monica.verducci@cern.ch']), + (mf.RPCPostProcess, + ['michele.bianco@le.infn.it', 'monica.verducci@cern.ch']), + (mdt_create, + ['john.stakely.keller@cern.ch', 'monica.verducci@cern.ch']), + (mf.MDTPostProcess, + ['john.stakely.keller@cern.ch']), + (mf.TGCPostProcess, + ['lyuan@ihep.ac.cn', 'kingmgl@stu.kobe-u.ac.jp']), + (mf.MDTvsTGCPostProcess, + ['lyuan@ihep.ac.cn', 'kingmgl@stu.kobe-u.ac.jp']), + (mf.HLTMuonPostProcess, + ['lyuan@ihep.ac.cn', 'kingmgl@stu.kobe-u.ac.jp', 'yamazaki@phys.sci.kobe-u.ac.jp']), + (mf.HLTEgammaPostProcess, + ['yan.jie.schnellbach@cern.ch', 'alessandro.tricoli@cern.ch']), + (mf.HLTTauPostProcess, + ['Cristobal.Cuenca@cern.ch', 'Geng-Yuan.Jeng@cern.ch', 'Giovanna.Cottin@cern.ch']), + (mf.HLTMETPostProcess, + ['venkat.kaushik@cern.ch']), + (mf.HLTCaloPostProcess, + ['gareth.brown@cern.ch']), + (mf.HLTJetPostProcess, + ['venkat.kaushik@cern.ch']), + (mf.BJetTaggingPostProcess, + ['m.neumann@cern.ch']), + (mf.L1CaloPostProcess, + ['ivana.hristova@cern.ch', 'pjwf@hep.ph.bham.ac.uk']), + (mf.SCTPostProcess, + ['masaki.endo@cern.ch']), + (mf.MuonTrkPhys, + ['austin.basye@cern.ch', 'john.stakely.keller@cern.ch']) + ] + + for funcinfo in funclist: + _ProtectPostProcessing( funcinfo, outFileName, isIncremental ) diff --git a/DataQuality/DataQualityUtils/python/DQProcMonitor.py b/DataQuality/DataQualityUtils/python/DQProcMonitor.py new file mode 100644 index 0000000000000000000000000000000000000000..b5c7f87ddd0f17cb221464873efcbbf8a5da2f23 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/DQProcMonitor.py @@ -0,0 +1,48 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +##================================================== +PROCMONVERSION="$Id: DQProcMonitor.py 359096 2011-04-15 13:25:36Z kama $" +##================================================== +import os +#python 2.6 is buggy, it can't import modules in deamon threads one has to import them in to global +from resource import getrusage, RUSAGE_SELF, RUSAGE_CHILDREN +from pprint import pformat,pprint +from time import sleep, time + +def formatRusage(rusage): + fieldnames=["utime","stime","maxrss","shrmem","ushrmem","ushrstk","minflt", + "majflt","nswap","inblock","oublock","msgsnd","msgrcv", + "nsignals","nvcontsw","nivcontsw"] + return ", ".join(["=".join([n,"%s"%v] if type(v) is int else [n,"%f"%v]) for n,v in zip(fieldnames,rusage)]) +def DQProcMon(*args,**kwargs): +# from resource import getrusage, RUSAGE_SELF, RUSAGE_CHILDREN +# from pprint import pformat,pprint +# from time import sleep, time + pollPeriod = kwargs.pop("poll_period", 1.0) + if pollPeriod < 0.25: + pollPeriod=0.25 #min poll time + filename = kwargs.pop("file_name","DQResourceUtilization.txt") + print "Monitoring thread poll period=",pollPeriod,"seconds, output file name=\"%s\""%filename + with open(filename,'w') as resoutfile: + while True: + rusage = [] + crusage = [] + try: + ru=getrusage(RUSAGE_SELF) + cru=getrusage(RUSAGE_CHILDREN) + except: + pass + #self_info="[utime=%f, stime=%f, maxrss=%s, minflt=%s, majflt=%s, nvcsw=%s, nivcsw=%s]" % (ru.ru_utime, + #ru.ru_stime, ru.ru_maxrss, ru.ru_minflt, ru.ru_majflt, ru.ru_) + resoutfile.write(str(time())+" <self> "+formatRusage(ru)+" <children> "+formatRusage(cru)+"\n") + #pprint(rusage,resoutfile) + resoutfile.flush() + sleep(pollPeriod) +def startProcMonThread(pollPeriod=1,file_name="DQResourceUtilization.txt"): + from threading import Thread + ResMon=Thread(target=DQProcMon,args=[],kwargs={'poll_period':pollPeriod, + 'file_name':file_name}) + #ResMon.setDaemon(True) + ResMon.start() + print "========Starting DQProcMonThread==============" + diff --git a/DataQuality/DataQualityUtils/python/DQWebDisplayConfig.py b/DataQuality/DataQualityUtils/python/DQWebDisplayConfig.py new file mode 100644 index 0000000000000000000000000000000000000000..3275ac781ade847d1558ad79421851c0238f8d60 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/DQWebDisplayConfig.py @@ -0,0 +1,31 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +# -*- coding: utf-8 -*- + +class DQWebDisplayConfig: + config = "" + hcfg = "" + hcfg_min10 = "" + hcfg_min30 = "" + server = [] + histogramCache = "" + hanResultsDir = "" + htmlDir = "" + htmlWeb = "" + runlist = "" + indexFile = "" + lockFile = "" + dbConnection = "" + dqmfOfl = "" + shiftOfl = "" + dbTagName = "" + dbTagNameESn = "" + dbTagNameShiftOfl = "HEAD" + dbConnectionHisto = "" + dqmfOflHisto = "" + dbTagNameH = "" + auth = "" + webHandoffDir = "" + filemap = {} + doHandi = True + emailWarnings = False diff --git a/DataQuality/DataQualityUtils/python/DQWebDisplayMod.py b/DataQuality/DataQualityUtils/python/DQWebDisplayMod.py new file mode 100755 index 0000000000000000000000000000000000000000..5a4e11717938110f35564ed528e3360e2bf40a63 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/DQWebDisplayMod.py @@ -0,0 +1,810 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# -*- coding: utf-8 -*- + +## ***************************************************************************** +VERSION = '$Id: DQWebDisplay.py 529090 2012-12-05 22:32:03Z ponyisi $' +## ***************************************************************************** + +FROMEMAIL = 'atlasdqm@cern.ch' + +import os, shutil +import time +from time import sleep +from multiprocessing import Process, Queue, Manager +from DataQualityUtils.dqu_subprocess import apply as _local_apply + +## Needed to correct ROOT behavior; see below +CWD = os.getcwd() +os.chdir(CWD) + +## Get usable signal handlers +os.environ['TDAQ_ERS_NO_SIGNAL_HANDLERS'] = '1' + +import sys +import ROOT +## Importing gSystem may change the current directory to one of the +## command-line arguments; chdir to original directory to have +## predictable behavior +from ROOT import gSystem +os.chdir(CWD) + +from DataQualityUtils.handimod import handiWithComparisons +from DataQualityUtils.handimod import makeCSSFile +from DataQualityUtils.SingleAppInstance import SingleAppInstance +from DataQualityUtils.hancoolmod import hancool +from DataQualityUtils.DQHistogramMergeMod import DQHistogramMerge +import DataQualityUtils.HanMetadata + +gSystem.Load("libdqm_core"); +gSystem.Load("libDataQualityInterfaces"); +## libDataQualityUtils is loaded by handi + +# return code +LOCK_ERROR = 5 + +from ROOT import dqutils + +class LockAcquisitionException(Exception): + def __init__(self, msg): + super(LockAcquisitionException,self).__init__(msg) + +def DQWebDisplay( inputFilePath, runAccumulating, c ): + + print "" + print "SVN version:" + print VERSION + + # we use the multiprocessing module to isolate code that possibly + # has memory leaks, so they don't build up over time + + if type(c.server) == str: + if c.server == '': + c.server = [] + else: + c.server = [c.server] + + if c.server != [] or c.webHandoffDir != "" or c.lockFile == '': + print "" + print "Lockfile is disabled" + print "" + instance = None + else: + while True: + try: + instance = SingleAppInstance( c.htmlDir + "/" + c.lockFile, True ) + islocked = instance.acquire() + except SingleAppInstance.FileLockAcquisitionError, e: + print '=========================================================================' + print 'Cannot acquire lock on', c.htmlDir + print 'This usually means either' + print ' -> the directory does not exist,' + print ' -> you do not have the required permissions, or' + print ' -> the directory is out of space.' + print 'If you ran into this error while trying to test the web display, please' + print 'read the instructions at:' + print 'https://twiki.cern.ch/twiki/bin/view/Atlas/DQOperationalRecipes#Obtain_SVN_and_disk_write_permis' + print + print 'Explicit error:', e + print '=========================================================================' + sys.exit(1) + if islocked: + break + print "Another instance is running; waiting 60 seconds..." + sleep(60) + + ## Settings for compare button, hintbox (and browser menu in case you want it) + javaScript = "compare.js" # javascript for compare button + HjavaScript = "returnHistory.js" # javascript for history button + allDirsScript = "AllDirs.js" # javascript for browser menu and hintbox + + javaScriptLoc = c.htmlWeb + "/" + javaScript + HjavaScriptLoc = c.htmlWeb + "/" + HjavaScript + allDirsScriptLoc = c.htmlWeb #+ "/" + allDirsScript + runlistLoc = c.htmlWeb + "/" + c.runlist ## datafile catalog (run and streams), + + compare = True # Create the compare button + history = True # Create the history button + browserMenu = True # Use the menu interface + + if ( c.hanResultsDir.rfind("/")!=(len(c.hanResultsDir)-1) ): + c.hanResultsDir+="/" + + if ( c.htmlDir.rfind("/")!=(len(c.htmlDir)-1) ): + c.htmlDir+="/" + + inputFileName = inputFilePath + i = inputFilePath.rfind("/") + if( i != -1 ): + inputFileName = inputFilePath[i+1:] + + runid = 99999999 + shortStream = "NoStream" + amitag = None + procpass = int(sys.argv[3]) + + if c.config == "RTT": + shortStream = time.strftime("%A") + else: + fields = inputFileName.split(".") + if len(fields) >= 3: + runid = int(fields[1]) + shortStream = fields[2] + if len(fields) >= 6: + amitag = fields[5] + + if runAccumulating: + print "" + print "Searching for existing histogram cache to merge with input histograms..." + try: + inputFilePath = _local_apply(mergeAndCache, ( inputFilePath, runid, shortStream, c.histogramCache ) ) + except LockAcquisitionException: + sys.exit(LOCK_ERROR) + shortStream = "tmp_" + shortStream + elif c.histogramCache != "": + cacheFile, version = findCacheFile( inputFilePath, runid, shortStream, c.histogramCache ) + if cacheFile != "": + print "" + print "Removing cached histograms used during accumulation mode" + try: + while cacheFile != '': + fullCachePath = c.histogramCache + "/" + cacheFile + os.unlink( fullCachePath ) + cacheFile, version = findCacheFile( inputFilePath, runid, shortStream, c.histogramCache ) + except OSError: + pass + + stream = shortStream + if len(sys.argv) >= 5: + stream = `procpass` + "/" + shortStream + + outputHanResultsDir = c.hanResultsDir + stream + '/run_' + `runid` + outputHtmlDir = c.htmlDir + stream + "/" + + if c.server != [] or c.webHandoffDir != "": + print "Writing all output to \'./\'; will copy at the end to", + if c.webHandoffDir != "": + print "a handoff directory:", c.webHandoffDir + else: + print "the web server(s):", ', '.join(c.server) + print "" + outputHanResultsDir = "./han_results/" + stream + '/run_' + `runid` + outputHtmlDir = "./www/" + stream + "/" + + makeOutputDirectory( outputHanResultsDir ) + makeOutputDirectory( outputHtmlDir ) + + total=_local_apply(getHanResults, ( inputFilePath, outputHanResultsDir, inputFilePath, c.hcfg, c.hcfg_min10, c.hcfg_min30 )) + fileList=total.rsplit('\n') + if amitag is not None: + addAmiTags(fileList, amitag) + + number=len(fileList) + if (len(fileList[number-1])<1): # last line is empty + number-=1 + + # find run number to create index.html in run-dir + runfile=fileList[0].rsplit() + if (len(runfile) == 0): + print "ERROR: TFile has no \"run_*\" directories. The input monitoring file is not organized for production use," + print "probably because AthenaMonitoring is not configured properly. Exiting.\n" + sys.exit(1) + + xferFileList = [] + for allLines in fileList: + splitLine = allLines.rsplit() + if len(splitLine) >= 1: + xferFileList.append( splitLine[0] + "\n" ) + + ## Archive han results - 090422 : PUEO + if c.server != []: + failures = 0 + for server in c.server: + print "Transfering han files to server: ", server + success = transferFilesToServer( xferFileList, "./han_results/", c.hanResultsDir, server ) + if success: + print "Done." + print "" + else: + failures += 1 + print "FAILED!", + if c.emailWarnings: + email('The transfer of han files\n\n' + + ''.join(xferFileList) + + '\nto server ' + server + + ' failed. This may indicate that this server is down.\n' + 'Please investigate as soon as possible!', + 'WARNING! File transfer from Tier-0 failed', + FROMEMAIL, + 'hn-atlas-data-quality-operations@cern.ch' + ) + print "Email sent..." + else: + print "" + print "" + if failures == len(c.server): + print "SERIOUS PROBLEM: file transfers failed to ALL defined servers" + print "These are:", ', '.join(c.server) + print "Will die so as to alert Tier-0 shifter" + raise IOError('tarfile ssh transfer failed') + + + runNumber = runfile[1] + rN=runNumber.lstrip("run_") + if c.doHandi: + rundir=outputHtmlDir+runNumber+"/" + makeOutputDirectory( rundir ) + + ## local time + now = time.localtime() + lastUpdate = "Last Update: "+time.strftime('%Y-%m-%d %H:%M %Z', now) + + ## # make an index file with links to run and minutes files + g=open(outputHtmlDir+runNumber +'/index.html','w') + g.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + g.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + g.write('<head>\n') + g.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + g.write('<title>run ' +rN+ ' ' + stream + '</title>\n') + g.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n') + g.write('</head>\n') + g.write('<body>\n') + g.write('<font class="DQGroup">[<a href="#" onclick="history.go(-1);return false;">Back</a>]</font>\n') + g.write('<h1>Run '+rN+', ' + stream + '</h1>\n\n') + + makeCSSFile( rundir, "", "" ) + + if number >0: + min10List = [] + min30List = [] + for x in range(0,number): + sp=fileList[x].rsplit() + if (len(sp)==2): # the run file + print "Running handi on " + sp[0] + ":" + print 'handi("Run '+rN+ ', '+ stream + '",' + sp[0] + ','+rundir+'/run)' + _local_apply(handiWithComparisons, ( ('Run '+rN+', ' + stream), sp[0], (rundir+"/run"), runlistLoc, compare, browserMenu, allDirsScriptLoc) ) + print "" + else:# a minutes file + if sp[1].find("lowStat")!=-1: # low statistics interval + print "Running handi on " + sp[0] + ":" + print 'handi("Run '+rN+ ', '+sp[1]+', ' + stream + '",' + sp[0] + ','+rundir+sp[3]+')' + _local_apply(handiWithComparisons, ( ('Run '+rN+ ', '+sp[1]+', ' + stream), sp[0], (rundir+sp[3]), runlistLoc, compare, browserMenu, allDirsScriptLoc) ) + print "" + mN = sp[1].lstrip("lowStat_") + min10List.append( (sp[3], mN) ) + elif sp[1].find("medStat")!=-1: # medium statistics interval + print "Running handi on " + sp[0] + ":" + print 'handi("Run '+rN+ ', '+sp[1]+', ' + stream + '",' + sp[0] + ','+rundir+sp[3]+')' + _local_apply(handiWithComparisons, (('Run '+rN+ ', '+sp[1]+', ' + stream), sp[0], (rundir+sp[3]), runlistLoc, compare, browserMenu, allDirsScriptLoc)) + print "" + mN = sp[1].lstrip("medStat_") + min30List.append( (sp[3], mN) ) + + #min10List.sort(key=lambda x: int(x[1])) + #min30List.sort(key=lambda x: int(x[1])) + + g.write('<table>\n') + + if len(min10List) == 0 and len(min30List) == 0: + g.write('<tr>\n') + g.write(' <td width=120>\n') + g.write(' <a href="run/index.html">Entire Run</a>\n') + g.write(' </td>\n') + g.write('</tr>\n') + elif len(min10List) == 0 or len(min30List) == 0: + minList = [] + blockName = "" + if len(min10List) == 0: + minList = min30List + blockName = "medium stat interval" + else: + minList = min10List + blockName = "low stat interval" + g.write('<tr>\n') + g.write(' <td rowspan='+ str(len(minList)) +' valign="top" width=120>\n') + g.write(' <a href="run/index.html">Entire Run</a>\n') + g.write(' </td>\n') + margin = "" + minList.sort() + for page, nMin in minList: + g.write(margin) + g.write(' <td width=200>\n') + if nMin.find('merged_')!=-1: + g.write(' <a href="' + page + '/index.html">' + nMin + '</a>\n') + else: + g.write(' <a href="' + page + '/index.html">' + blockName + ' ' + nMin + '</a>\n') + g.write(' </td>\n') + margin = '</tr>\n<tr>\n' + g.write('</tr>\n') + else: + g.write('<tr>\n') + g.write(' <td rowspan='+ str(len(min10List)) +' valign="top" width=120>\n') + g.write(' <a href="run/index.html">Entire Run</a>\n') + g.write(' </td>\n') + margin = "" + count = 0 + min10List.sort() + for page10, nMin10 in min10List: + g.write(margin) + nMin30 = 0 + if count % 3 == 0: + iMin30 = (count / 3) + page30, nMin30 = min30List[iMin30] + g.write(' <td rowspan=3 valign="top" width=200>\n') + g.write(' <a href="' + page30 + '/index.html">medium stat interval ' + nMin30 + '</a>\n') + g.write(' </td>\n') + g.write(' <td width=200>\n') + g.write(' <a href="' + page10 + '/index.html">low stat interval ' + nMin10 + '</a>\n') + g.write(' </td>\n') + count = count + 1 + margin = '</tr>\n<tr>\n' + g.write('</tr>\n') + + g.write('</table>\n') + + + g.write('<br/>\n<font class=\"Note\">'+lastUpdate+'</font><br />\n') + g.write('</body>\n</html>') + g.close() + + if c.webHandoffDir != "": + print 'Transfering web files to handoff directory' + transferDirectoryToHandoffDir( rundir, './www/', c.webHandoffDir, c ) + elif c.server != []: + failures = 0 + for server in c.server: + print "Transfering web files to server: ", server + success = transferDirectoryToServer( rundir, "./www/", c.htmlDir, server ) + if success: + print "Done." + print "" + else: + failures += 1 + if c.emailWarnings: + email('The transfer of web files\n' + + c.htmlDir + + '\nto server' + server + + 'failed. This may indicate that this server is down.\n' + 'Please investigate as soon as possible!', + 'WARNING! File transfer from Tier-0 failed', + FROMEMAIL, + 'hn-atlas-data-quality-operations@cern.ch' + ) + print "FAILED!" + print "" + if failures == len(c.server): + print "SERIOUS PROBLEM: web files transfer failed to ALL defined servers" + print "These are:", ', '.join(c.server) + print "Will die so as to alert Tier-0 shifter" + raise IOError('Directory ssh transfer failed') + + + #markCompleteTransfer( rundir, './www/', c.htmlDir, c ) + + if c.webHandoffDir == '': + print "Generating index files..." + for server in c.server: + generateDQIndexFiles( server, c.htmlDir, c.config, c.indexFile, c.runlist, c.htmlWeb ) + + if not runAccumulating: + import commands + print "Getting COOL authentications" +# if c.auth: +# os.environ['CORAL_AUTH_PATH'] = c.auth +# else: +# home = os.environ.get('HOME') +# os.environ['CORAL_AUTH_PATH'] = home+"/private" + + # write monitor comparison results to cool + # MB : 29.05.2008 + if 'COOLUPLOADS' in os.environ: + uploadAllowed = (os.environ['COOLUPLOADS'] == '1') + else: + uploadAllowed = True + + if not uploadAllowed: + print 'hancool run and upload to DB switched off by request' + + if (uploadAllowed and len(c.dbConnection)>0) and (len(c.dqmfOfl)>0): + print "" + print "Now calling hancool ..." + #stream = os.path.basename(outputHanResultsDir) + if '_' in stream: stream = stream.split('_',1)[-1] + if amitag is not None and 'x' in amitag and stream.startswith('express'): # this is ESn processing + dbTagName = c.dbTagNameESn + isESn = True + else: + dbTagName = c.dbTagName + isESn = False + if '%' in dbTagName: + # this is a little fragile + uploadTag = dbTagName % { 'stream': stream, + 'amitag': amitag, + 'procpass': procpass } + doUpload = True + else: + uploadTag = dbTagName + doUpload = ('-%s-' % stream in uploadTag) + + if (doUpload): + print 'isESn?', isESn + _local_apply(hancool, (int(rN),outputHanResultsDir,c.dbConnection,c.dqmfOfl,uploadTag,c.shiftOfl,c.dbTagNameShiftOfl,isESn)) + + if runAccumulating: + os.unlink(inputFilePath) + + if instance != None: + instance.release() + return fileList + + +def makeOutputDirectory( dirname ): + if( not os.access(dirname,os.F_OK) ): + try: + os.umask(002) + os.makedirs(dirname) + except os.error: + print 'Cannot create directory "' + dirname + '"; exiting.' + sys.exit(-1) + + +def getHanResults(inputFilePath, *args): + of = dqutils.MonitoringFile(inputFilePath) + rv = of.getHanResults(*args) + return rv + +def mergeAndCache( inputFilePath, run, stream, cache ): + if cache == "": + print "Cannot use cache: No cache directory defined" + print "" + return inputFilePath + + MAX_LOCK_TRIES = 3 + + for i in xrange(MAX_LOCK_TRIES): + try: + lockfilename = os.path.join(cache, 'lock_%s_%s' % (run, stream)) + instance = SingleAppInstance( lockfilename, True ) + islocked = instance.acquire() + except SingleAppInstance.FileLockAcquisitionError, e: + print 'Unable to start to acquire cache directory lock! Bailing' + raise e + if islocked: + break + else: + print 'Unable to acquire cache directory lock; waiting 60 seconds; try', (i+1) + sleep(60) + + if not islocked: + raise LockAcquisitionException(' '.join(['Tried', `MAX_LOCK_TRIES`, 'times to acquire cache lock; exiting now'])) + + cacheFile, version = findCacheFile( inputFilePath, run, stream, cache ) + fullCachePath = "" + if cacheFile != "": + print "Found cached histograms: " + print " dir: ", cache + print " file: ", cacheFile + fullCachePath = cache + "/" + cacheFile + else: + print "Did not find cached histograms: " + print " dir: ", cache + + inputFileName = inputFilePath + i = inputFilePath.rfind("/") + if( i != -1 ): + inputFileName = inputFilePath[i+1:] + updatedFile = inputFileName + ".CACHE_" + str(version+1) + print "Creating updated cache: " + print " file: ", updatedFile + fullUpdatedFile = cache + "/" + updatedFile + print "" + + if fullCachePath != '': + print 'Copying previous cache to local directory ...', + shutil.copy(fullCachePath, cacheFile) + print 'done\n' + + mergeListName = "cache_merge.list" + f = open( mergeListName, 'w' ) + txtstr = "" + txtstr += "%s\n" % cacheFile + txtstr += "%s\n" % inputFilePath + f.write(txtstr) + f.close() + + print "Running DQHistogramMerge..." + DQHistogramMerge( mergeListName, updatedFile, False ) + print "Finished DQHistogramMerge." + print "" + + if fullCachePath != '': + print 'Deleting local copy of old cache ...', + os.unlink(cacheFile) + print 'done\n' + + print 'Copying new cache to cache directory ...', + shutil.copy(updatedFile, fullUpdatedFile) + print 'done\n' + + # make copy so we can process further without interference + # from other jobs + #localFullUpdatedFile = fullUpdatedFile + '-local' + #print 'Copying to new file', localFullUpdatedFile, '...', + #shutil.copy(updatedFile, localFullUpdatedFile) + #print 'done' + + os.unlink( mergeListName ) + if fullCachePath != "": + os.unlink( fullCachePath ) + + instance.release() + + print 'Now running histogram postprocessing ...' + from DataQualityUtils import DQPostProcessMod + DQPostProcessMod.DQPostProcess( updatedFile, isIncremental=True ) + + return updatedFile + +def verifyHasRunKey(inputFile, run): + f = ROOT.TFile(inputFile, 'READ') + if f.IsOpen(): + if f.Get('run_%s' % run): + f.Close() + return True + f.Close() + print 'WARNING: cache file %s appears to be corrupted' % inputFile + return False + +def findCacheFile( inputFilePath, run, stream, cache ): + fileDict = { } + for root, dirs, files in os.walk(cache): + removeDir = [] + for name in dirs: + removeDir.append(name) + for fileName in files: + if fileName.find(str(run)) == -1: + continue + if fileName.find(stream) == -1: + continue + vi = fileName.rfind(".CACHE_") + if vi != -1: + try: + v = int(fileName[vi+7:]) + fileDict[v] = fileName + except: + pass + for name in removeDir: + dirs.remove(name) + for v in reversed(sorted([key for key in fileDict.keys() if verifyHasRunKey(cache+'/'+fileDict[key], run)])): + return fileDict[v], v + + return "", 0 + + +def transferDirectoryToHandoffDir( dirName, localDir, targetDir, config ): + import time, ConfigParser, tarfile, shutil, glob + targetfname = `int(time.time())` + '-' + `os.getpid()` \ + + '-' + os.uname()[1] + '.tgz' + targetfile = os.path.join(targetDir, targetfname) + + print 'Creating tarball', targetfname, '...' + parser = ConfigParser.ConfigParser() + parser.set('DEFAULT', 'target', config.htmlDir) + parser.add_section('execute') + parser.set('execute', 'command', config.htmlDir + '/generateDQIndexFiles.py') + parser.set('execute', 'options', '"%s" "%s" "%s" "%s" "%s"' % (config.htmlDir, config.config, config.indexFile, config.runlist, config.htmlWeb)) + dnames = glob.glob('%s/*/*/*' % localDir) + if len(dnames) != 1: + print 'Unexpected glob result' + else: + parser.add_section('webdisplay') + parser.set('webdisplay', 'id', dnames[0][len(localDir):]) + manifest = open(localDir + '/MANIFEST', 'w') + parser.write(manifest); manifest.close() + + #loctf = tarfile.open(targetfname, 'w:gz') + ##loctf.debug=3 + #loctf.add(localDir + '/MANIFEST', 'MANIFEST') + #loctf.add(dirName, dirName.replace(localDir, '')) + #loctf.close() + print 'About to execute', + cmd = 'cd %s ; tar czf %s MANIFEST %s ; mv %s ..' % (localDir, targetfname, dirName.replace(localDir, ''), targetfname) + print cmd + rv = os.system(cmd) + if rv != 0: + raise IOError('Unable to create tarfile') + + print 'done' + + print 'Copying tarball to', targetDir, '...', + shutil.copy(targetfname, targetfile) + print 'done' + print 'Removing local tarball copy ...', + os.unlink(targetfname) + print 'done\n' + +def transferDirectoryToServer( dirName, localDir, targetDir, server ): + username = "atlasdqm" + if 'USER' in os.environ.keys(): + username = os.environ['USER'] + + dirName = dirName.replace(localDir,"") + + cmd = "" + cmd += "tar -czf - -C " + localDir + " " + dirName + cmd += " | " + cmd += "ssh -l " + username + " " + server + " -x \"umask 002; cd " + targetDir + " ; tar -xzf - \"" + + print cmd + rv = os.system( cmd ) + #if rv != 0: + # raise IOError('Directory ssh transfer failed') + return rv == 0 + +def markCompleteTransfer( dirName, localDir, targetDir, config ): + if config.webHandoffDir != '': + return + if config.server == '': + os.system('touch ' + os.path.join(dirName, 'complete')) + else: + dirName = dirName.replace(localDir, '') + username = "atlasdqm" + if 'USER' in os.environ.keys(): + username = os.environ['USER'] + cmd = "ssh -l " + username + " " + config.server + " -x \"umask 002; cd " + os.path.join(targetDir, dirName) + " ; touch complete\"" + + print cmd + rv = os.system( cmd ) + if rv != 0: + raise IOError('Directory complete transfer marking failed') + + +def transferFilesToServer( fileList, localDir, targetDir, server ): + username = "atlasdqm" + if 'USER' in os.environ.keys(): + username = os.environ['USER'] + tarFileListName = "./tarFileList.tmp" + t = open( tarFileListName, 'w' ) + for xferFile in fileList: + os.system( "chmod 664 " + xferFile ) + xferFile = xferFile.replace(localDir,"") + t.write(xferFile) + t.close() + + cmd = "" + cmd += ("tar -czf - -C %s -T %s" % (localDir, tarFileListName)) + cmd += " | " + cmd += "ssh -l " + username + " " + server + " -x \"umask 002; cd " + targetDir + " ; tar -xzf - \"" + + print cmd + rv = os.system( cmd ) + os.unlink(tarFileListName) + #if rv != 0: + # raise IOError('tarfile ssh transfer failed') + return rv == 0 + + +def retrieveFileFromServer( filePath, localDir, remoteDir, server ): + username = "atlasdqm" + if 'USER' in os.environ.keys(): + username = os.environ['USER'] + + filePath = filePath.replace(localDir,"") + + cmd = "" + cmd += "cd " + localDir + cmd += " ; " + cmd += "ssh -l " + username + " " + server + " -x \"cd " + remoteDir + " ; cat " + filePath + "\"" + cmd += " > " + filePath + + print cmd + rv = os.system( cmd ) + if rv != 0: + raise IOError('file retrieve failed') + +def generateDQIndexFiles( server, installPath, project, indexFile, runListFile, htmlAddress ): + username = "atlasdqm" + if 'USER' in os.environ.keys(): + username = os.environ['USER'] + + cmd = "" + + if server != "": + cmd += "ssh -l " + username + " " + server + " -x \"umask 002; " + cmd += installPath + "/generateDQIndexFiles.py " + installPath + " " + project + " " + indexFile + " " + cmd += runListFile + " " + htmlAddress + "\"" + else: + cmd += installPath + "/generateDQIndexFiles.py " + installPath + " " + project + " " + indexFile + " " + cmd += runListFile + " " + htmlAddress + + print cmd + return os.system( cmd ) == 0 + +def importConfiguration(modname): + from DataQualityConfigurations import getmodule + print 'getting configuration', modname + return getmodule(modname) + +def email(msg, subject, whofrom, addressees): + import smtplib + from email.mime.text import MIMEText + if type(addressees) == str: + addressees = [addressees] + email = MIMEText(msg) + email['Subject'] = subject + email['From'] = whofrom + email['To'] = ','.join(addressees) + serv = smtplib.SMTP() + serv.connect() + serv.sendmail(whofrom, addressees, email.as_string()) + serv.quit() + +def addAmiTags(fileList, amitag): + fileList = [x.split()[0] for x in fileList if x != ''] + print 'Appending AMI information to metadata; tag =', amitag + for f in fileList: + rf = ROOT.TFile.Open(f, 'UPDATE') + DataQualityUtils.HanMetadata.addMetadata(rf, 'AMI', {'AMI Tag': amitag}) + rf.Close() + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "" + print "Usage: ", cmd, "<data_file> <config> <processing_version> [run_accumulating [conditions_string]]" + print "" + print "This is a production utility; use TEST config for development and testing." + print "" + print "Processing version is an integer, starting from 1 (not 0)" + print "" + +if __name__ == "__main__": + if len(sys.argv) < 4 or len(sys.argv) > 7: + usage() + sys.exit(0) + + inputFile = sys.argv[1] # data file + runAccumulating = False + if len(sys.argv) in (6,7): + if sys.argv[4] == "True" or sys.argv[4] == "1": + runAccumulating = True + + if len(sys.argv) == 7: + ROOT.gSystem.Load('libDataQualityInterfaces') + ROOT.dqi.ConditionsSingleton.getInstance().setCondition(sys.argv[5]) + + configModule = "" + + if sys.argv[2] == "TEST": + configModule = "TestDisplay" + elif sys.argv[2] == "RTT": + configModule = "RTTDisplay" + elif sys.argv[2] == "TCT": + configModule = "TCTDisplay" + elif sys.argv[2] == "FDR1": + configModule = "fdr08_run1" + elif sys.argv[2] == "FDR2" or sys.argv[2] == "FDR2a" or sys.argv[2] == "FDR2b" or sys.argv[2] == "FDR2c": + configModule = "fdr08_run2" + elif sys.argv[2] == "Cosmics08": + configModule = "data08_cos" + elif sys.argv[2] == "SingleBeam08": + configModule = "data08_1beam" + else: + configModule = sys.argv[2] + + try: + cmod = importConfiguration(configModule) + except Exception, e: + print "Could not import configuration module \'" + configModule + "\'" + sys.exit(1) + + try: + config = cmod.dqconfig + except Exception, e: + print "Configuration object 'dqconfig' not defined in module \'" + configModule + "\'" + sys.exit(1) + + + DQWebDisplay( inputFile, runAccumulating, config ) + diff --git a/DataQuality/DataQualityUtils/python/HanMetadata.py b/DataQuality/DataQualityUtils/python/HanMetadata.py new file mode 100644 index 0000000000000000000000000000000000000000..f0f6115f8354d9f6b15b7bf1f3061b266a3a282f --- /dev/null +++ b/DataQuality/DataQualityUtils/python/HanMetadata.py @@ -0,0 +1,44 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +#import ROOT + +def getMetadataKeys(f): + mddir = f.Get('HanMetadata_') + if not mddir: + return [] + else: + return [x.GetName() for x in mddir.GetListOfKeys()] + +def getMetadata(f, key): + rv = {} + mddir = f.Get('HanMetadata_') + if not mddir: + return rv + else: + keydir = mddir.Get(key) + if not keydir: + return rv + else: + for subkey in keydir.GetListOfKeys(): + subkeydirlist = keydir.Get(subkey.GetName()).GetListOfKeys() + if len(subkeydirlist) < 1: + continue + rv[subkey.GetName()] = subkeydirlist[0].GetName() + return rv + +def addMetadata(f, key, mapping): + import ROOT + mddir = f.Get('HanMetadata_') + if not mddir: + mddir = f.mkdir('HanMetadata_') + keydir = mddir.Get(key) + if not keydir: + keydir = mddir.mkdir(key) + for subkey in mapping: + if keydir.Get(subkey): + keydir.rmdir(subkey) + subkeydir = keydir.mkdir(subkey) + val = mapping[subkey] + valstr = ROOT.TObjString(val) + subkeydir.WriteTObject(valstr, val) + f.Flush() diff --git a/DataQuality/DataQualityUtils/python/SingleAppInstance.py b/DataQuality/DataQualityUtils/python/SingleAppInstance.py new file mode 100644 index 0000000000000000000000000000000000000000..d8384b1f9a52fa7327e1523f841f9bb7686a6297 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/SingleAppInstance.py @@ -0,0 +1,129 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## This class is borrowed from flock.py, written by Jordan Callicoat and +## available from an online python cookbook (aspn.activestate.com) +## Updated to use lockf for actual network atomicity by Peter Onyisi +## Using system lock to ensure that lock released even in case of segfault + +import os +import socket +import time +import fcntl + +class SingleAppInstance(object): + '''Class to handle creating and removing lockfiles''' + + # custom exceptions + + class FileLockAcquisitionError(Exception): pass + class FileLockReleaseError(Exception): pass + + # convenience callables for formatting + addr = lambda self: '%d@%s' % (self.pid, self.host) + fddr = lambda self: '<%s %s>' % (self.path, self.addr()) + pddr = lambda self, lock: '<%s %s@%s>' %\ + (self.path, lock['pid'], lock['host']) + + def __init__(self, path, debug=None, blocking = False): + self.pid = os.getpid() + self.host = socket.gethostname() + self.path = path + self.debug = debug # set this to get status messages + self.locked = False + self.lockfile = None + self.blocking = blocking + + def acquire(self): + '''Acquire a lock, returning self if successful, False otherwise''' + if self.islocked(): + if self.debug: + lock = self._readlock() + print 'Previous lock detected: %s' % self.pddr(lock) + return False + try: + fd = os.open(self.path, os.O_RDWR | os.O_CREAT, 0777) + fh = os.fdopen(fd, 'r+') + self.lockfile = fh + fh.seek(0) + try: + fcntlflag = fcntl.LOCK_EX + if not self.blocking: + fcntlflag |= fcntl.LOCK_NB + fcntl.lockf(fh, fcntlflag) + self.locked = True + except IOError: + print 'Unable to acquire lock on %s: existing lock %s' % (self.path, fh.read()) + fh.close() + return False + fh.write(self.addr()) + fh.truncate() + fh.flush() + os.fsync(fh) + if self.debug: + modtime = os.stat(self.path) + outstring = 'Acquired lock: '+ self.fddr() + ' at time '+ time.ctime(modtime.st_mtime) + print outstring + except Exception, e: + if os.path.isfile(self.path): + try: + # my guess is this causes problems + #os.unlink(self.path) + pass + except: + pass + raise self.FileLockAcquisitionError( + 'Error acquiring lock: %s, reason %s' % (self.fddr(), e)) + return self + + def release(self): + '''Release lock, returning self''' + if self.ownlock(): + try: + fh = self.lockfile + fcntl.lockf(fh, fcntl.LOCK_UN) + self.locked = False + self.lockfile.close() + self.lockfile = None + if not self.blocking: + # some space for a small race here unfortunately + os.unlink(self.path) + if self.debug: + outstring = 'Released lock: ' + self.fddr() +' at time ' + time.ctime() + print outstring + except Exception, e: + print e + raise self.FileLockReleaseError( + 'Error releasing lock: %s, reason %s' % (self.fddr(), e)) + return self + + def _readlock(self): + '''Internal method to read lock info''' + try: + lock = {} + fh = open(self.path) + data = fh.read().rstrip().split('@') + fh.close() + lock['pid'], lock['host'] = data + return lock + except: + return {'pid': 8**10, 'host': ''} + + def islocked(self): + '''Check if we already have a lock''' + return self.locked + + def ownlock(self): + '''Check if we own the lock''' + return self.locked + + def __del__(self): + '''Magic method to clean up lock when program exits''' + self.release() + + def __enter__(self): + self.acquire() + return self + + def __exit__(self, typ, value, tb): + self.release() + return self diff --git a/DataQuality/DataQualityUtils/python/TestCases.py b/DataQuality/DataQualityUtils/python/TestCases.py new file mode 100644 index 0000000000000000000000000000000000000000..e74754273b1e6db536598176e447169eb71950bf --- /dev/null +++ b/DataQuality/DataQualityUtils/python/TestCases.py @@ -0,0 +1,68 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +import unittest +import sys, os, shutil + +TESTING_DIR = '/afs/cern.ch/user/a/atlasdqm/dqmdisk1/testing_references' + +class DQUTestCase(unittest.TestCase): + def setUp(self): + self.outfile = '' + + def test_01_Merging(self): + '''Test that histogram merging + postprocessing works''' + print + print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + print 'Running merge test ....' + print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + outdir = os.environ.get('TMPDIR', '.') + inlist = os.path.join(TESTING_DIR, 'test_merging') + self.outfile = os.path.join(outdir, 'data09_calophys.00128005.physics_CosmicMuons.root') + rv = os.system('cd %s ; DQHistogramMerge.py %s %s True' % (outdir, inlist, self.outfile)) + self.failUnless(rv==0, "DQHistogramMerge.py return code is nonzero") + + def test02_WebDisplay(self): + '''Test that a terminal web display job works''' + print + print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + print 'Running web display test ....' + print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + outdir = os.environ.get('TMPDIR', '.') + infile = os.path.join(TESTING_DIR, 'data09_calophys.00128005.physics_CosmicMuons.root') + rv = os.system('cd %s ; DQWebDisplay.py %s TestDisplay 123' % (outdir, infile)) + self.failUnless(rv==0, "DQWebDisplay.py return code is nonzero") + + def test_03_WebDisplay(self): + '''Test that a terminal web display job works in temporary accumulation mode''' + print + print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + print 'Running intermediate web display test ....' + print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + outdir = os.environ.get('TMPDIR', '.') + infile = os.path.join(TESTING_DIR, 'data09_calophys.00128005.physics_CosmicMuons.root') + from DataQualityConfigurations.TestDisplay import dqconfig + cachedir = dqconfig.histogramCache + if cachedir == '': + self.fail('Unable to test intermediate web displays; no histogramCache directory set') + if not os.access(cachedir, os.W_OK): + print "No write permissions for cache dir %s; skipping test" % cachedir + return + cachefilename = os.path.basename(infile).rsplit('.',1)[-2] + '.CACHE_1' + shutil.copy(infile, os.path.join(cachedir, cachefilename)) + + rv = os.system('cd %s ; DQWebDisplay.py %s TestDisplay 123 True' % (outdir, infile)) + self.failUnless(rv==0, "DQWebDisplay.py return code is nonzero") + + def tearDown(self): + try: + if self.outfile != '': + os.unlink(self.outfile) + except OSError: + pass + +def suite(): + suite = unittest.TestLoader().loadTestsFromTestCase(DQUTestCase) + return suite + +if __name__ == '__main__': + unittest.main() diff --git a/DataQuality/DataQualityUtils/python/__init__.py b/DataQuality/DataQualityUtils/python/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..531ab874fb028d3c9de1f65c38eed6b5c00c9aab --- /dev/null +++ b/DataQuality/DataQualityUtils/python/__init__.py @@ -0,0 +1,3 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +# Hook for the DataQualityUtils package diff --git a/DataQuality/DataQualityUtils/python/createMdtFolders.py b/DataQuality/DataQualityUtils/python/createMdtFolders.py new file mode 100644 index 0000000000000000000000000000000000000000..59c0d724c5a5d51ae5f5566047d720eaf85b538b --- /dev/null +++ b/DataQuality/DataQualityUtils/python/createMdtFolders.py @@ -0,0 +1,88 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +#************************************************* +#Author monica.verducci@cern.ch +#python script to create the MDT DQ folders in sqlite files and fill in it +#during the postprocessing algorithm +#************************************************ + + +def createMDTConditionDBDead(): + import sys, os + from PyCool import cool,coral + + # get database service and open database + dbSvc=cool.DatabaseSvcFactory.databaseService() + # database accessed via physical name + + dbstring='sqlite://;schema=MDTDQMFOFFLINE_DEAD.db;dbname=MDT_DQA' + + if os.access('MDTDQMFOFFLINE_DEAD.db', os.R_OK): + try: + os.unlink('MDTDQMFOFFLINE_DEAD.db') + #print 'Trying to Delete' + except Exception, e: + print 'Unable to remove existing db file, reason', e + try: + db=dbSvc.createDatabase(dbstring) + except Exception,e: + print 'Problem creating database',e + return + #print "Created database",dbstring + + spec2=cool.RecordSpecification() + spec2.extend("Chamber_Name",cool.StorageType.String255) + spec2.extend("Dead_multilayer",cool.StorageType.String255) + spec2.extend("Dead_layer",cool.StorageType.String255) + spec2.extend("Dead_mezz",cool.StorageType.String255) + spec2.extend("Dead_asd",cool.StorageType.String255) + spec2.extend("Dead_tube",cool.StorageType.String4k) + + + desc="<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\" /></addrHeader><typeName>CondAttrListCollection</typeName>" + + # create the folder - single version + # last argument is createParents - if true, automatically creates parent + # folders if needed + # note this will not work if the database already exists - delete mycool.db first + myfolder=db.createFolder("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_DEAD",spec2,desc,cool.FolderVersioning.MULTI_VERSION,True) + db.closeDatabase() + +def createMDTConditionDBNoisy(): + import sys, os + from PyCool import cool,coral + + # get database service and open database + dbSvc=cool.DatabaseSvcFactory.databaseService() + # database accessed via physical name + + dbstring='sqlite://;schema=MDTDQMFOFFLINE_NOISY.db;dbname=MDT_DQA' + + if os.access('MDTDQMFOFFLINE_NOISY.db', os.R_OK): + try: + os.unlink('MDTDQMFOFFLINE_NOISY.db') + except Exception, e: + print 'Unable to remove existing db file, reason', e + try: + db=dbSvc.createDatabase(dbstring) + except Exception,e: + print 'Problem creating database',e + return + #print "Created database",dbstring + + spec2=cool.RecordSpecification() + spec2.extend("Chamber_Name",cool.StorageType.String255) + spec2.extend("Noisy_multilayer",cool.StorageType.String255) + spec2.extend("Noisy_layer",cool.StorageType.String255) + spec2.extend("Noisy_mezz",cool.StorageType.String255) + spec2.extend("Noisy_asd",cool.StorageType.String255) + spec2.extend("Noisy_tube",cool.StorageType.String4k) + + desc="<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\" /></addrHeader><typeName>CondAttrListCollection</typeName>" + + # create the folder - single version + # last argument is createParents - if true, automatically creates parent + # folders if needed + # note this will not work if the database already exists - delete mycool.db first + myfolder=db.createFolder("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_NOISY",spec2,desc,cool.FolderVersioning.MULTI_VERSION,True) + db.closeDatabase() diff --git a/DataQuality/DataQualityUtils/python/createRpcFolders.py b/DataQuality/DataQualityUtils/python/createRpcFolders.py new file mode 100644 index 0000000000000000000000000000000000000000..3e1d29cc72050faea3f09561d4c6e1deb553218d --- /dev/null +++ b/DataQuality/DataQualityUtils/python/createRpcFolders.py @@ -0,0 +1,82 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +#************************************************* +# Python to create RPC SQLite Folder to be filled with RPC alibration results +# author Michele Bianco michele.bianco@le.infn.it, Gabriele Chiodini gabriele.chiodini@le.infn.it +#and Angelo Guida angelo.guida@le.infn.it +# 08/April/2009 +#************************************************ + + +def createRPCDQMFDB(): + import sys, os + from PyCool import cool,coral + + # get database service and open database + dbSvc=cool.DatabaseSvcFactory.databaseService() + # database accessed via physical name + dbstring='sqlite://;schema=RPCDQMFOFFLINE.db;dbname=RPC_DQA' + if os.access('RPCDQMFOFFLINE.db', os.R_OK): + try: + os.unlink('RPCDQMFOFFLINE.db') + except Exception, e: + print 'Unable to remove existing db file, reason', e + try: + db=dbSvc.createDatabase(dbstring) + except Exception,e: + print 'Problem creating database',e + return + print "Created database",dbstring + + spec2=cool.RecordSpecification() + spec2.extend("recEta",cool.StorageType.String4k) + spec2.extend("detEta",cool.StorageType.String4k) + spec2.extend("recPhi1",cool.StorageType.String4k) + spec2.extend("recPhi2",cool.StorageType.String4k) + spec2.extend("detPhi1",cool.StorageType.String4k) + spec2.extend("detPhi2",cool.StorageType.String4k) + + # folder meta-data - note for Athena this has a special meaning + desc="<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\" /></addrHeader><typeName>CondAttrListCollection</typeName>" + # create the folder - single version + # last argument is createParents - if true, automatically creates parent + # folders if needed + # note this will not work if the database already exists - delete mycool.db first + myfolder=db.createFolder('/OFFLINE/OFFLINE_DQMF',spec2,desc,cool.FolderVersioning.MULTI_VERSION,True) + db.closeDatabase() + + +def createRPCConditionDB(): + import sys, os + from PyCool import cool,coral + + # get database service and open database + dbSvc=cool.DatabaseSvcFactory.databaseService() + # database accessed via physical name + dbstring='sqlite://;schema=RPCConditionDB.db;dbname=RPC_DQA' + if os.access('RPCConditionDB.db', os.R_OK): + try: + os.unlink('RPCConditionDB.db') + except Exception, e: + print 'Unable to remove existing db file, reason', e + try: + db=dbSvc.createDatabase(dbstring) + except Exception,e: + print 'Problem creating database',e + return + print "Created database",dbstring + + spec2=cool.RecordSpecification() + spec2.extend("PanelRes",cool.StorageType.String255) + spec2.extend("StripStatus",cool.StorageType.String255) + + desc="<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\" /></addrHeader><typeName>CondAttrListCollection</typeName>" + + # create the folder - single version + # last argument is createParents - if true, automatically creates parent + # folders if needed + # note this will not work if the database already exists - delete mycool.db first + myfolder=db.createFolder('/OFFLINE/FINAL',spec2,desc,cool.FolderVersioning.MULTI_VERSION,True) + db.closeDatabase() + + diff --git a/DataQuality/DataQualityUtils/python/detmaskmod.py b/DataQuality/DataQualityUtils/python/detmaskmod.py new file mode 100644 index 0000000000000000000000000000000000000000..c9299fcf6b952134e2a3d377e3c511a4020c221d --- /dev/null +++ b/DataQuality/DataQualityUtils/python/detmaskmod.py @@ -0,0 +1,132 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +import eformat +import operator + +detmaskmap = { + 'FORWARD_ALPHA': 'ALFA', + 'FORWARD_BCM': 'IDBCM', + 'FORWARD_LUCID': 'LCD', + 'FORWARD_ZDC': 'ZDC', + 'LAR_EM_BARREL_A_SIDE': 'EMBA', + 'LAR_EM_BARREL_C_SIDE': 'EMBC', + 'LAR_EM_ENDCAP_A_SIDE': 'EMECA', + 'LAR_EM_ENDCAP_C_SIDE': 'EMECC', + 'LAR_FCAL_A_SIDE': 'FCALA', + 'LAR_FCAL_C_SIDE': 'FCALC', + 'LAR_HAD_ENDCAP_A_SIDE': 'HECA', + 'LAR_HAD_ENDCAP_C_SIDE': 'HECC', + 'MUON_CSC_ENDCAP_A_SIDE': 'CSCEA', + 'MUON_CSC_ENDCAP_C_SIDE': 'CSCEC', + 'MUON_MDT_BARREL_A_SIDE': 'MDTBA', + 'MUON_MDT_BARREL_C_SIDE': 'MDTBC', + 'MUON_MDT_ENDCAP_A_SIDE': 'MDTEA', + 'MUON_MDT_ENDCAP_C_SIDE': 'MDTEC', + 'MUON_RPC_BARREL_A_SIDE': 'RPCBA', + 'MUON_RPC_BARREL_C_SIDE': 'RPCBC', + 'MUON_TGC_ENDCAP_A_SIDE': 'TGCEA', + 'MUON_TGC_ENDCAP_C_SIDE': 'TGCEC', + 'PIXEL_BARREL': 'PIXB', + 'PIXEL_B_LAYER': 'PIX0', + 'PIXEL_DISK_SIDE': ('PIXEA', 'PIXEC'), + ('SCT_BARREL_A_SIDE', 'SCT_BARREL_C_SIDE'): 'SCTB', + 'SCT_ENDCAP_A_SIDE': 'SCTEA', + 'SCT_ENDCAP_C_SIDE': 'SCTEC', + 'TDAQ_CTP': 'L1CTP', + 'TILECAL_BARREL_A_SIDE': 'TILBA', + 'TILECAL_BARREL_C_SIDE': 'TILBC', + 'TILECAL_EXT_A_SIDE': 'TIEBA', + 'TILECAL_EXT_C_SIDE': 'TIEBC', + ('TRT_BARREL_A_SIDE', 'TRT_BARREL_C_SIDE'): 'TRTB', + 'TRT_ENDCAP_A_SIDE': 'TRTEA', + 'TRT_ENDCAP_C_SIDE': 'TRTEC', + ('TRT_BARREL_A_SIDE', 'TRT_BARREL_C_SIDE', 'TRT_ENDCAP_A_SIDE', 'TRT_ENDCAP_C_SIDE'): 'TRTTR', + } + +detmaskmap_defects = { + 'FORWARD_ALPHA': 'ALFA_DISABLED', + 'FORWARD_LUCID': 'LCD_DISABLED', + 'FORWARD_ZDC': 'ZDC_DISABLED', + 'LAR_EM_BARREL_A_SIDE': 'LAR_EMBA_DISABLED', + 'LAR_EM_BARREL_C_SIDE': 'LAR_EMBC_DISABLED', + 'LAR_EM_ENDCAP_A_SIDE': 'LAR_EMECA_DISABLED', + 'LAR_EM_ENDCAP_C_SIDE': 'LAR_EMECC_DISABLED', + 'LAR_FCAL_A_SIDE': 'LAR_FCALA_DISABLED', + 'LAR_FCAL_C_SIDE': 'LAR_FCALC_DISABLED', + 'LAR_HAD_ENDCAP_A_SIDE': 'LAR_HECA_DISABLED', + 'LAR_HAD_ENDCAP_C_SIDE': 'LAR_HECC_DISABLED', + 'MUON_CSC_ENDCAP_A_SIDE': 'MS_CSC_EA_DISABLED', + 'MUON_CSC_ENDCAP_C_SIDE': 'MS_CSC_EC_DISABLED', + 'MUON_MDT_BARREL_A_SIDE': 'MS_MDT_BA_DISABLED', + 'MUON_MDT_BARREL_C_SIDE': 'MS_MDT_BC_DISABLED', + 'MUON_MDT_ENDCAP_A_SIDE': 'MS_MDT_EA_DISABLED', + 'MUON_MDT_ENDCAP_C_SIDE': 'MS_MDT_EC_DISABLED', + 'MUON_RPC_BARREL_A_SIDE': 'MS_RPC_BA_DISABLED', + 'MUON_RPC_BARREL_C_SIDE': 'MS_RPC_BC_DISABLED', + 'MUON_TGC_ENDCAP_A_SIDE': 'MS_TGC_EA_DISABLED', + 'MUON_TGC_ENDCAP_C_SIDE': 'MS_TGC_EC_DISABLED', + 'PIXEL_BARREL': 'PIXEL_BARREL_DISABLED', + 'PIXEL_B_LAYER': 'PIXEL_LAYER0_DISABLED', + 'PIXEL_DISK_SIDE': 'PIXEL_ENDCAPS_DISABLED', + ('SCT_BARREL_A_SIDE', 'SCT_BARREL_C_SIDE', + 'SCT_ENDCAP_A_SIDE', 'SCT_ENDCAP_C_SIDE'): 'SCT_GLOBAL_DISABLED', + 'TILECAL_BARREL_A_SIDE': 'TILE_LBA_DISABLED', + 'TILECAL_BARREL_C_SIDE': 'TILE_LBC_DISABLED', + 'TILECAL_EXT_A_SIDE': 'TILE_EBA_DISABLED', + 'TILECAL_EXT_C_SIDE': 'TILE_EBC_DISABLED', + ('TRT_BARREL_A_SIDE', 'TRT_BARREL_C_SIDE', + 'TRT_ENDCAP_A_SIDE', 'TRT_ENDCAP_C_SIDE'): 'TRT_DISABLED', + } + +def getSubDetectorObj(sdstr): + return getattr(eformat.helper.SubDetector, sdstr) + +def decode(mask): + dm = eformat.helper.DetectorMask(mask) + rv = [] + for keys, value in detmaskmap.items(): + if type(keys) == str: + keys = [keys] + if reduce(operator.or_, + [dm.is_set(getSubDetectorObj(key)) for key in keys]): + flags = value + if type(flags) == str: + flags = [flags] + rv += list(flags) + + return sorted(rv) + +def decodeBlack(mask, defects=False): + dm = eformat.helper.DetectorMask(mask) + rv = [] + dmap = detmaskmap if not defects else detmaskmap_defects + for keys, value in sorted(dmap.items()): + if type(keys) == str: + keys = [keys] + if reduce(operator.and_, + [not dm.is_set(getSubDetectorObj(key)) for key in keys]): + flags = value + if type(flags) == str: + flags = [flags] + rv += list(flags) + + return sorted(rv) + +def getRunMask(run): + from PyCool import cool, coral + dbSvc = cool.DatabaseSvcFactory.databaseService() + # Necessary to work around COOL database lookup stupidity + db = dbSvc.openDatabase('oracle://ATLAS_COOLPROD;dbname=COMP200;schema=ATLAS_COOLONL_TDAQ', True) + iov = run << 32 + folder = db.getFolder('/TDAQ/RunCtrl/SOR_Params') + obj = folder.findObject(iov, 0) + mask = obj.payload()['DetectorMask'] + db.closeDatabase() + return mask + +def getNumLumiBlocks(run): + from DQUtils.db import fetch_iovs + lbs = fetch_iovs('LBLB', (run, 1), (run, 0xFFFFFFFF), database='oracle://ATLAS_COOLPROD;dbname=COMP200;schema=ATLAS_COOLONL_TRIGGER') + return len(lbs) + + diff --git a/DataQuality/DataQualityUtils/python/dqu_subprocess.py b/DataQuality/DataQualityUtils/python/dqu_subprocess.py new file mode 100644 index 0000000000000000000000000000000000000000..b6cc2ac367314b2031c816881982e6a15b5c6584 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/dqu_subprocess.py @@ -0,0 +1,45 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +def _local_apply_core(func, args, q): + import os + try: + q.put(func(*args)) + except BaseException, e: + q.put(e) + os._exit(1) + +def apply(func, args): + import random + from Queue import Empty + from multiprocessing import Process + from multiprocessing.managers import SyncManager + import tempfile + import os + if os.getcwd()[:4] != '/afs': + try: + m = SyncManager(address=tempfile.mktemp(prefix='dqu_subprocess-', + dir=os.getcwd())) + m.start() + except EOFError: + m = SyncManager() + m.start() + else: + m = SyncManager() + m.start() + q = m.Queue() + p = Process(target=_local_apply_core, args=(func, args, q)) + p.start() + p.join() + print 'Manager socket is', m.address + try: + rv = q.get(False) + except Empty: + raise RuntimeError('daughter died while trying to execute %s%s' % (func.func_name, args)) + if isinstance(rv, BaseException): + if isinstance(rv, SystemExit): + print 'SystemExit raised by daughter; ignoring' + return None + else: + raise rv + m.shutdown() + return rv diff --git a/DataQuality/DataQualityUtils/python/filemovemod.py b/DataQuality/DataQualityUtils/python/filemovemod.py new file mode 100644 index 0000000000000000000000000000000000000000..84f2797246ab38eda18ea8de78ddc4e800b58d11 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/filemovemod.py @@ -0,0 +1,14 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +def move_files(prefix, config): + import os, shutil + + filemap = config.filemap + if filemap == {}: + return + for src, dest in filemap.items(): + if os.access(src, os.R_OK): + try: + shutil.copy2(src, os.path.join(dest, prefix + '_' + os.path.basename(src))) + except IOError, e: + print e diff --git a/DataQuality/DataQualityUtils/python/hancool_histo_algdef.py b/DataQuality/DataQualityUtils/python/hancool_histo_algdef.py new file mode 100644 index 0000000000000000000000000000000000000000..e796331903a5d5e58d039ccb44ab6e99cb6b58f8 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/hancool_histo_algdef.py @@ -0,0 +1,266 @@ +#!/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +import string, os +import re +CWD = os.getcwd() +import sys +import pdb +import ROOT +from ROOT import gSystem +os.chdir(CWD) + +## Import the ROOT library for reading han results +gSystem.Load('libDataQualityUtils') +from ROOT import dqutils + +def ExtractMean( mean_rms ): + global mean + mean="" + h=mean_rms.split('Mean: ') + if (mean_rms.find('Error')>-1): + m=h[1].split('MeanError: ') + mean=m[0] + elif (mean_rms.find('Error')<0): + m=h[1].split('RMS: ') + if (m[0].find('NBins')>-1): + n=m[0].split('NBins: ') + mean=n[0] + else: + mean=m[0] + return mean + +def ExtractEMean( mean_rms ): + global EMean + EMean="" + h=mean_rms.split('Mean: ') + if (mean_rms.find('Error')>-1): + m=h[1].split('MeanError: ') + if (mean_rms.find('NBins')>-1): + n=m[1].split('NBins: ') + elif (mean_rms.find('NBins')<0): + n=m[1].split('RMS: ') + EMean=n[0] + return EMean + +def ExtractRMS( mean_rms ): + global RMS + RMS="" + h=mean_rms.split('Mean: ') + if (mean_rms.find('Error')>-1): + m=h[1].split('MeanError: ') + if (mean_rms.find('NBins')>-1): + n=m[1].split('NBins: ') + j = n[1].split('RMS: ') + jj = j[1].split('RMSError: ') + elif (mean_rms.find('NBins')<0): + n=m[1].split('RMS: ') + jj=n[1].split('RMSError: ') + RMS=jj[0] + elif (mean_rms.find('Error')<0): + m=h[1].split('RMS: ') + RMS=m[1] + return RMS + +def ExtractERMS( mean_rms ): + global ERMS + ERMS="" + h=mean_rms.split('Mean: ') + if (mean_rms.find('Error')>-1): + m=h[1].split('MeanError: ') + if (mean_rms.find('NBins')>-1): + n=m[1].split('NBins: ') + j = n[1].split('RMS: ') + jj = j[1].split('RMSError: ') + elif (mean_rms.find('NBins')<0): + n=m[1].split('RMS: ') + jj=n[1].split('RMSError: ') + ERMS=jj[1] + return ERMS + +def ExtractAverage( mean_rms ): + global Average + h=mean_rms.split('Average: ') + m=h[1].split('NBins: ') + Average=m[0] + return Average + +def ExtractNBins( mean_rms ): + global NBins + h=mean_rms.split('Average: ') + m=h[1].split('NBins: ') + NBins=m[1] + return NBins + +# CheckHisto_RMS +def ExtractXRMS( mean_rms ): + global xrms + h=mean_rms.split('XRMS: ') + m=h[1].split('YRMS: ') + xrms=m[0] + return xrms + +def ExtractYRMS( mean_rms ): + global yrms + h=mean_rms.split('XRMS: ') + m=h[1].split('YRMS: ') + yrms=m[1] + return yrms + +# CheckHisto_Mean +def ExtractXMean( mean_rms ): + global xmean + if (mean_rms.find('XMean: ')>-1): + h=mean_rms.split('XMean: ') + m=h[1].split('YMean: ') + else: + h=mean_rms + m=h.split('YMean: ') + xmean=m[0] + return xmean + +def ExtractYMean( mean_rms ): + global ymean + if (mean_rms.find('XMean: ')>-1): + h=mean_rms.split('XMean: ') + m=h[1].split('YMean: ') + else: + h=mean_rms + m=h.split('YMean: ') + ymean=m[1] + return ymean + +# Sidebands_Absolute, Sidebands_Relative +def ExtractSideBands( mean_rms ): + global sideb + h=mean_rms.split('SideBands: ') + m=h[1].split('TotalIntegral: ') + sideb=m[0] + return sideb + +def ExtractTotInt( mean_rms ): + global totint + h=mean_rms.split('SideBands: ') + m=h[1].split('TotalIntegral: ') + totint=m[1] + return totint + +# simple_pol1_fit +def ExtractPol0( mean_rms ): + global pol0 + h=mean_rms.split('pol1[0]: ') + m=h[1].split('pol1[1]: ') + pol0=m[0] + return pol0 + +def ExtractPol1( mean_rms ): + global pol1 + h=mean_rms.split('pol1[0]: ') + m=h[1].split('pol1[1]: ') + pol1=m[1] + return pol1 + +# simple_gaus_fit +def ExtractConstG( mean_rms ): + global constant + h=mean_rms.split('Constant: ') + m=h[1].split('Mean: ') + constant=m[0] + return constant + +def ExtractMeanG( mean_rms ): + global meang + h=mean_rms.split('Constant: ') + m=h[1].split('Mean: ') + n = m[1].split('Sigma: ') + meang=n[0] + return meang + +def ExtractRMSG( mean_rms ): + global rmsg + h=mean_rms.split('Constant: ') + m=h[1].split('Mean: ') + n = m[1].split('Sigma: ') + rmsg=n[1] + return rmsg + +# binContentComp, Bins_LessThan_Threshold, Bins_LessThanEqual_Threshold, Bins_GreaterThan_Threshold, Bins_GreaterThanEqual_Threshold +def ExtractOnlyNBins( histo_nameonly, mean_rms ): + global contbins + global bin_inf1 + global bin_inf2 + global bin_inf3 + global bin_inf4 + h=mean_rms.split('NBins: ') + if (len(h)>1): + if (h[1].find('RMS')>-1): + n=h[1].split('RMS: ') + contbins=n[0] + elif (h[1].find(histo_nameonly.strip())>-1): + reading = h[1].split(histo_nameonly.strip()) + contbins = reading[0] + for i in range(1,len(reading)): + if (reading[i].find('(0.0000')>-1): + bin_inf1 = reading[i].split(':')[1] + break + else: + bin_inf1 = '-0.0001' + for i in range(1,len(reading)): + if (reading[i].find('(1.0000')>-1): + bin_inf2 = reading[i].split(':')[1] + break + else: + bin_inf2 = '-0.0001' + for i in range(1,len(reading)): + if (reading[i].find('(2.0000')>-1): + bin_inf3 = reading[i].split(':')[1] + break + else: + bin_inf3 = '-0.0001' + for i in range(1,len(reading)): + if (reading[i].find('(3.0000')>-1): + bin_inf4 = reading[i].split(':')[1] + break + else: + bin_inf4 = '-0.0001' + else: + contbins=h[1] + bin_inf1 = '0' + bin_inf2 = '0' + bin_inf3 = '0' + bin_inf4 = '0' + + if (len(h)==1): + if not h[0]: + contbins=0 + bin_inf1 = '0' + bin_inf2 = '0' + bin_inf3 = '0' + bin_inf4 = '0' + else: + contbins=h[0] + bin_inf1 = '0' + bin_inf2 = '0' + bin_inf3 = '0' + bin_inf4 = '0' + + return (contbins, bin_inf1, bin_inf2, bin_inf3, bin_inf4) + +def ExtractAlgo( file, rootFolder ): + rootFolder =file+":"+rootFolder + of = dqutils.HanOutputFile( file ) + algo = of.getAlgorithm(rootFolder) + return algo + +def ExtractNEntries( file, rootFolder , histo_string): + nentries='0' + rootFolder =file+":"+rootFolder + of = dqutils.HanOutputFile( file ) + nentries = of.getNEntries(rootFolder, histo_string) + return nentries + + + + + diff --git a/DataQuality/DataQualityUtils/python/hancool_histo_foldermap.py b/DataQuality/DataQualityUtils/python/hancool_histo_foldermap.py new file mode 100644 index 0000000000000000000000000000000000000000..82dee6d8b8aaff8081dd644336530e8468a0c49a --- /dev/null +++ b/DataQuality/DataQualityUtils/python/hancool_histo_foldermap.py @@ -0,0 +1,538 @@ +#!/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +import string, os + + +folderMapHisto = { +# add w.r.t. config before + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks/Npixhits_per_track":"/InnerDetector/IDAlignment/ExtendedTracks_NoTriggerSelection/GenericTracks/Npixhits_per_track", +# + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks/Nscthits_per_track":"/InnerDetector/IDAlignment/ExtendedTracks_NoTriggerSelection/GenericTracks/Nscthits_per_track", + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks/Ntrthits_per_track":"/InnerDetector/IDAlignment/ExtendedTracks_NoTriggerSelection/GenericTracks/Ntrthits_per_track", + +# was PrimVtx, now is BeamSpot +## "/InnerDetector/IDAlignment/BeamSpot/NoTriggerSelection/pvChiSqDof":"/InnerDetector/IDAlignment/PrimVtx/NoTriggerSelection/pvChiSqDof", +## "/InnerDetector/IDAlignment/BeamSpot/NoTriggerSelection/pvX":"/InnerDetector/IDAlignment/PrimVtx/NoTriggerSelection/pvX", +## "/InnerDetector/IDAlignment/BeamSpot/NoTriggerSelection/pvY":"/InnerDetector/IDAlignment/PrimVtx/NoTriggerSelection/pvY", +## "/InnerDetector/IDAlignment/BeamSpot/NoTriggerSelection/pvZ":"/InnerDetector/IDAlignment/PrimVtx/NoTriggerSelection/pvZ", + +## "/InnerDetector/IDAlignment_Perf/Jpsi-->mumu/NoTriggerSelection/Jpsi_invmass":"/InnerDetector/IDAlignment_Perf/Jpsi-->mumu/NoTriggerSelection/Jpsi_invmass", + +## "/InnerDetector/IDAlignment_Perf/Kshort-->pipi/NoTriggerSelection/ks_mass":"/InnerDetector/IDAlignment_Perf/Kshort-->pipi/NoTriggerSelection/ks_mass", +## "/InnerDetector/IDAlignment_Perf/Z-->mumu/NoTriggerSelection/z-mass_trks":"/InnerDetector/IDAlignment_Perf/Z-->mumu/NoTriggerSelection/z-mass_trks", +## "/InnerDetector/IDAlignment_Perf/Z-->ee/NoTriggerSelection/Zee_Eopasym_perevent":"/InnerDetector/IDAlignment_Perf/Z-->ee/NoTriggerSelection/Zee_Eopasym_perevent", +# 2 are missing +## "/InnerDetector/IDAlignment_Perf/Z-->ee/NoTriggerSelection/Zee_Eop_incl":"/InnerDetector/IDAlignment_Perf/Z-->ee/NoTriggerSelection/Zee_Eop_incl", +## "/InnerDetector/IDAlignment_Perf/W-->enu/NoTriggerSelection/Wenu_Eop_incl":"/InnerDetector/IDAlignment_Perf/W-->enu/NoTriggerSelection/Wenu_Eop_incl", + +# added as test for Tobias (1) + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/HitEfficiencies/measurements_eff_vs_layer_barrel":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/HitEfficiencies/measurements_eff_vs_layer_barrel", +# added as test for Tobias (9) + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Npixhits_per_track_barrel":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Npixhits_per_track_barrel", + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Npixhits_per_track_eca":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Npixhits_per_track_eca", + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Npixhits_per_track_ecc":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Npixhits_per_track_ecc", + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Nscthits_per_track_barrel":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Nscthits_per_track_barrel", + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Nscthits_per_track_eca":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Nscthits_per_track_eca", + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Nscthits_per_track_ecc":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Nscthits_per_track_ecc", + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Ntrthits_per_track_barrel":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Ntrthits_per_track_barrel", + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Ntrthits_per_track_eca":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Ntrthits_per_track_eca", + "/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Ntrthits_per_track_ecc":"/InnerDetector/IDAlignment/Tracks_NoTriggerSelection/GenericTracks_Detail/Ntrthits_per_track_ecc", +# added as test for Beate (3) + "/InnerDetector/Pixel/PixelExpert/Timing/m_Pixel_track_Lvl1A":"/InnerDetector/Pixel/PixelExpert/Timing/m_Pixel_track_Lvl1A", + "/InnerDetector/Pixel/PixelExpert/ToT/m_Pixel_track_cluster_ToT":"/InnerDetector/Pixel/PixelExpert/ToT/m_Pixel_track_cluster_ToT", + "/InnerDetector/Pixel/PixelExpert/General/m_Pixel_track_clus_groupsize":"/InnerDetector/Pixel/PixelExpert/General/m_Pixel_track_clus_groupsize" + + } + +folderMapHistoP10 = { + +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM1_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM1_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM1_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM1_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM1_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM1_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM2_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM2_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM2_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM2_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM2_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM2_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM3_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM3_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM3_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM3_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM3_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EM3_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC1C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC2C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMEC3C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPA_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPA_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPA_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPA_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPA_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPA_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPC_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPC_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPC_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPC_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPC_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_EMECPC_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL1C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL2C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_FCAL3C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC1C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC2C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC3C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4A_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4A_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4A_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4A_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4A_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4A_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4C_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4C_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4C_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4C_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4C_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_HEC4C_noth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_PSR_hiEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_PSR_hiEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_PSR_medEth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_PSR_medEth", +## "/LAr/CaloCellVec/CellAvEnvsEtaPhi_PSR_noth":"/LAr/CaloCellVec/CellAvEnvsEtaPhi_PSR_noth", +## "/LAr/CaloCellVec/CellEnergy_EM1":"/LAr/CaloCellVec/CellEnergy_EM1", +## "/LAr/CaloCellVec/CellEnergy_EM2":"/LAr/CaloCellVec/CellEnergy_EM2", +## "/LAr/CaloCellVec/CellEnergy_EM3":"/LAr/CaloCellVec/CellEnergy_EM3", +## "/LAr/CaloCellVec/CellEnergy_EMEC1A":"/LAr/CaloCellVec/CellEnergy_EMEC1A", +## "/LAr/CaloCellVec/CellEnergy_EMEC1C":"/LAr/CaloCellVec/CellEnergy_EMEC1C", +## "/LAr/CaloCellVec/CellEnergy_EMEC2A":"/LAr/CaloCellVec/CellEnergy_EMEC2A", +## "/LAr/CaloCellVec/CellEnergy_EMEC2C":"/LAr/CaloCellVec/CellEnergy_EMEC2C", +## "/LAr/CaloCellVec/CellEnergy_EMEC3A":"/LAr/CaloCellVec/CellEnergy_EMEC3A", +## "/LAr/CaloCellVec/CellEnergy_EMEC3C":"/LAr/CaloCellVec/CellEnergy_EMEC3C", +## "/LAr/CaloCellVec/CellEnergy_EMECPA":"/LAr/CaloCellVec/CellEnergy_EMECPA", +## "/LAr/CaloCellVec/CellEnergy_EMECPC":"/LAr/CaloCellVec/CellEnergy_EMECPC", +## "/LAr/CaloCellVec/CellEnergy_FCAL1A":"/LAr/CaloCellVec/CellEnergy_FCAL1A", +## "/LAr/CaloCellVec/CellEnergy_FCAL1C":"/LAr/CaloCellVec/CellEnergy_FCAL1C", +## "/LAr/CaloCellVec/CellEnergy_FCAL2A":"/LAr/CaloCellVec/CellEnergy_FCAL2A", +## "/LAr/CaloCellVec/CellEnergy_FCAL2C":"/LAr/CaloCellVec/CellEnergy_FCAL2C", +## "/LAr/CaloCellVec/CellEnergy_FCAL3A":"/LAr/CaloCellVec/CellEnergy_FCAL3A", +## "/LAr/CaloCellVec/CellEnergy_FCAL3C":"/LAr/CaloCellVec/CellEnergy_FCAL3C", +## "/LAr/CaloCellVec/CellEnergy_HEC1A":"/LAr/CaloCellVec/CellEnergy_HEC1A", +## "/LAr/CaloCellVec/CellEnergy_HEC1C":"/LAr/CaloCellVec/CellEnergy_HEC1C", +## "/LAr/CaloCellVec/CellEnergy_HEC2A":"/LAr/CaloCellVec/CellEnergy_HEC2A", +## "/LAr/CaloCellVec/CellEnergy_HEC2C":"/LAr/CaloCellVec/CellEnergy_HEC2C", +## "/LAr/CaloCellVec/CellEnergy_HEC3A":"/LAr/CaloCellVec/CellEnergy_HEC3A", +## "/LAr/CaloCellVec/CellEnergy_HEC3C":"/LAr/CaloCellVec/CellEnergy_HEC3C", +## "/LAr/CaloCellVec/CellEnergy_HEC4A":"/LAr/CaloCellVec/CellEnergy_HEC4A", +## "/LAr/CaloCellVec/CellEnergy_HEC4C":"/LAr/CaloCellVec/CellEnergy_HEC4C", +## "/LAr/CaloCellVec/CellEnergy_PSR":"/LAr/CaloCellVec/CellEnergy_PSR", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EM1_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EM1_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EM1_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EM1_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EM1_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EM1_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EM2_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EM2_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EM2_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EM2_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EM3_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EM3_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EM3_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EM3_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EM3_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EM3_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1A_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1A_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1C_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC1C_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC2A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC2A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC2A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC2A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC2C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC2C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC2C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC2C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3A_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3A_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3C_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMEC3C_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPA_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPA_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPA_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPA_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPA_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPA_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPC_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPC_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPC_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPC_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPC_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_EMECPC_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1A_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1A_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1C_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL1C_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL2A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL2A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL2A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL2A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL2C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL2C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL2C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL2C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3A_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3A_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3C_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_FCAL3C_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1A_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1A_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1C_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC1C_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC2A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC2A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC2A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC2A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC2C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC2C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC2C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC2C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3A_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3A_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3C_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC3C_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4A_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4A_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4A_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4A_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4A_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4A_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4C_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4C_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4C_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4C_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4C_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_HEC4C_noth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_PSR_hiEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_PSR_hiEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_PSR_medEth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_PSR_medEth", +## "/LAr/CaloCellVec/CellNoisevsEtaPhi_PSR_noth":"/LAr/CaloCellVec/CellNoisevsEtaPhi_PSR_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EM1_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EM1_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EM1_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EM1_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EM1_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EM1_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EM2_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EM2_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EM2_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EM2_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EM3_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EM3_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EM3_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EM3_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EM3_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EM3_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1A_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1A_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1C_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1C_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC1C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC2A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC2A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC2A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC2A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC2C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC2C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC2C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC2C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3A_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3A_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3C_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3C_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMEC3C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPA_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPA_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPA_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPA_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPA_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPA_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPC_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPC_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPC_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPC_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPC_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_EMECPC_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1A_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1A_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1C_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1C_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL1C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL2A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL2A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL2A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL2A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL2C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL2C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL2C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL2C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3A_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3A_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3C_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3C_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_FCAL3C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1A_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1A_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1C_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1C_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC1C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC2A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC2A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC2A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC2A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC2C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC2C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC2C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC2C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3A_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3A_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3C_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3C_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC3C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4A_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4A_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4A_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4A_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4A_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4C_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4C_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4C_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4C_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_HEC4C_noth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_PSR_hiEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_PSR_hiEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_PSR_medEth":"/LAr/CaloCellVec/CellRatevsEtaPhi_PSR_medEth", +## "/LAr/CaloCellVec/CellRatevsEtaPhi_PSR_noth":"/LAr/CaloCellVec/CellRatevsEtaPhi_PSR_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EM1_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EM1_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EM1_medEth":"/LAr/CaloCellVec/CellRatevsEta_EM1_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EM1_noth":"/LAr/CaloCellVec/CellRatevsEta_EM1_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EM2_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EM2_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EM2_medEth":"/LAr/CaloCellVec/CellRatevsEta_EM2_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EM2_noth":"/LAr/CaloCellVec/CellRatevsEta_EM2_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EM3_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EM3_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EM3_medEth":"/LAr/CaloCellVec/CellRatevsEta_EM3_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EM3_noth":"/LAr/CaloCellVec/CellRatevsEta_EM3_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC1A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC1A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC1A_medEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC1A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC1A_noth":"/LAr/CaloCellVec/CellRatevsEta_EMEC1A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC1C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC1C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC1C_medEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC1C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC1C_noth":"/LAr/CaloCellVec/CellRatevsEta_EMEC1C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC2A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC2A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC2A_medEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC2A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC2A_noth":"/LAr/CaloCellVec/CellRatevsEta_EMEC2A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC2C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC2C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC2C_medEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC2C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC2C_noth":"/LAr/CaloCellVec/CellRatevsEta_EMEC2C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC3A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC3A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC3A_medEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC3A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC3A_noth":"/LAr/CaloCellVec/CellRatevsEta_EMEC3A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC3C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC3C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC3C_medEth":"/LAr/CaloCellVec/CellRatevsEta_EMEC3C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMEC3C_noth":"/LAr/CaloCellVec/CellRatevsEta_EMEC3C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EMECPA_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EMECPA_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMECPA_medEth":"/LAr/CaloCellVec/CellRatevsEta_EMECPA_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMECPA_noth":"/LAr/CaloCellVec/CellRatevsEta_EMECPA_noth", +## "/LAr/CaloCellVec/CellRatevsEta_EMECPC_hiEth":"/LAr/CaloCellVec/CellRatevsEta_EMECPC_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMECPC_medEth":"/LAr/CaloCellVec/CellRatevsEta_EMECPC_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_EMECPC_noth":"/LAr/CaloCellVec/CellRatevsEta_EMECPC_noth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL1A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL1A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL1A_medEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL1A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL1A_noth":"/LAr/CaloCellVec/CellRatevsEta_FCAL1A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL1C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL1C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL1C_medEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL1C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL1C_noth":"/LAr/CaloCellVec/CellRatevsEta_FCAL1C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL2A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL2A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL2A_medEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL2A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL2A_noth":"/LAr/CaloCellVec/CellRatevsEta_FCAL2A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL2C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL2C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL2C_medEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL2C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL2C_noth":"/LAr/CaloCellVec/CellRatevsEta_FCAL2C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL3A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL3A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL3A_medEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL3A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL3A_noth":"/LAr/CaloCellVec/CellRatevsEta_FCAL3A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL3C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL3C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL3C_medEth":"/LAr/CaloCellVec/CellRatevsEta_FCAL3C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_FCAL3C_noth":"/LAr/CaloCellVec/CellRatevsEta_FCAL3C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC1A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_HEC1A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC1A_medEth":"/LAr/CaloCellVec/CellRatevsEta_HEC1A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC1A_noth":"/LAr/CaloCellVec/CellRatevsEta_HEC1A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC1C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_HEC1C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC1C_medEth":"/LAr/CaloCellVec/CellRatevsEta_HEC1C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC1C_noth":"/LAr/CaloCellVec/CellRatevsEta_HEC1C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC2A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_HEC2A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC2A_medEth":"/LAr/CaloCellVec/CellRatevsEta_HEC2A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC2A_noth":"/LAr/CaloCellVec/CellRatevsEta_HEC2A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC2C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_HEC2C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC2C_medEth":"/LAr/CaloCellVec/CellRatevsEta_HEC2C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC2C_noth":"/LAr/CaloCellVec/CellRatevsEta_HEC2C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC3A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_HEC3A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC3A_medEth":"/LAr/CaloCellVec/CellRatevsEta_HEC3A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC3A_noth":"/LAr/CaloCellVec/CellRatevsEta_HEC3A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC3C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_HEC3C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC3C_medEth":"/LAr/CaloCellVec/CellRatevsEta_HEC3C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC3C_noth":"/LAr/CaloCellVec/CellRatevsEta_HEC3C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC4A_hiEth":"/LAr/CaloCellVec/CellRatevsEta_HEC4A_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC4A_medEth":"/LAr/CaloCellVec/CellRatevsEta_HEC4A_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC4A_noth":"/LAr/CaloCellVec/CellRatevsEta_HEC4A_noth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC4C_hiEth":"/LAr/CaloCellVec/CellRatevsEta_HEC4C_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC4C_medEth":"/LAr/CaloCellVec/CellRatevsEta_HEC4C_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_HEC4C_noth":"/LAr/CaloCellVec/CellRatevsEta_HEC4C_noth", +## "/LAr/CaloCellVec/CellRatevsEta_PSR_hiEth":"/LAr/CaloCellVec/CellRatevsEta_PSR_hiEth", +## "/LAr/CaloCellVec/CellRatevsEta_PSR_medEth":"/LAr/CaloCellVec/CellRatevsEta_PSR_medEth", +## "/LAr/CaloCellVec/CellRatevsEta_PSR_noth":"/LAr/CaloCellVec/CellRatevsEta_PSR_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EM1_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EM1_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EM1_medEth":"/LAr/CaloCellVec/CellRatevsPhi_EM1_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EM1_noth":"/LAr/CaloCellVec/CellRatevsPhi_EM1_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EM2_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EM2_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EM2_noth":"/LAr/CaloCellVec/CellRatevsPhi_EM2_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EM3_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EM3_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EM3_medEth":"/LAr/CaloCellVec/CellRatevsPhi_EM3_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EM3_noth":"/LAr/CaloCellVec/CellRatevsPhi_EM3_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC1A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC1A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC1A_medEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC1A_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC1A_noth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC1A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC1C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC1C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC1C_medEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC1C_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC1C_noth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC1C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC2A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC2A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC2A_noth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC2A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC2C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC2C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC2C_noth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC2C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC3A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC3A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC3A_medEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC3A_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC3A_noth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC3A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC3C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC3C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC3C_medEth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC3C_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMEC3C_noth":"/LAr/CaloCellVec/CellRatevsPhi_EMEC3C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMECPA_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EMECPA_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMECPA_medEth":"/LAr/CaloCellVec/CellRatevsPhi_EMECPA_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMECPA_noth":"/LAr/CaloCellVec/CellRatevsPhi_EMECPA_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMECPC_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_EMECPC_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMECPC_medEth":"/LAr/CaloCellVec/CellRatevsPhi_EMECPC_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_EMECPC_noth":"/LAr/CaloCellVec/CellRatevsPhi_EMECPC_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL1A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL1A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL1A_medEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL1A_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL1A_noth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL1A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL1C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL1C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL1C_medEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL1C_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL1C_noth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL1C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL2A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL2A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL2A_noth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL2A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL2C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL2C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL2C_noth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL2C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL3A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL3A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL3A_medEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL3A_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL3A_noth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL3A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL3C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL3C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL3C_medEth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL3C_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_FCAL3C_noth":"/LAr/CaloCellVec/CellRatevsPhi_FCAL3C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC1A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC1A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC1A_medEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC1A_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC1A_noth":"/LAr/CaloCellVec/CellRatevsPhi_HEC1A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC1C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC1C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC1C_medEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC1C_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC1C_noth":"/LAr/CaloCellVec/CellRatevsPhi_HEC1C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC2A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC2A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC2A_noth":"/LAr/CaloCellVec/CellRatevsPhi_HEC2A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC2C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC2C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC2C_noth":"/LAr/CaloCellVec/CellRatevsPhi_HEC2C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC3A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC3A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC3A_medEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC3A_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC3A_noth":"/LAr/CaloCellVec/CellRatevsPhi_HEC3A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC3C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC3C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC3C_medEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC3C_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC3C_noth":"/LAr/CaloCellVec/CellRatevsPhi_HEC3C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC4A_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC4A_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC4A_medEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC4A_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC4A_noth":"/LAr/CaloCellVec/CellRatevsPhi_HEC4A_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC4C_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC4C_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC4C_medEth":"/LAr/CaloCellVec/CellRatevsPhi_HEC4C_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_HEC4C_noth":"/LAr/CaloCellVec/CellRatevsPhi_HEC4C_noth", +## "/LAr/CaloCellVec/CellRatevsPhi_PSR_hiEth":"/LAr/CaloCellVec/CellRatevsPhi_PSR_hiEth", +## "/LAr/CaloCellVec/CellRatevsPhi_PSR_medEth":"/LAr/CaloCellVec/CellRatevsPhi_PSR_medEth", +## "/LAr/CaloCellVec/CellRatevsPhi_PSR_noth":"/LAr/CaloCellVec/CellRatevsPhi_PSR_noth", +## "/LAr/EMB/CellNoisevsEtaPhi_EM2_noth":"/LAr/EMB/CellNoisevsEtaPhi_EM2_noth", +## "/LAr/EMB/CellRatevsEtaPhi_EM2_medEth":"/LAr/EMB/CellRatevsEtaPhi_EM2_medEth", +## "/LAr/EMB/CellRatevsPhi_EM2_medEth":"/LAr/EMB/CellRatevsPhi_EM2_medEth", +## "/LAr/EMECA/CellNoisevsEtaPhi_EMEC2A_noth":"/LAr/EMECA/CellNoisevsEtaPhi_EMEC2A_noth", +## "/LAr/EMECA/CellRatevsEtaPhi_EMEC2A_medEth":"/LAr/EMECA/CellRatevsEtaPhi_EMEC2A_medEth", +## "/LAr/EMECA/CellRatevsPhi_EMEC2A_medEth":"/LAr/EMECA/CellRatevsPhi_EMEC2A_medEth", +## "/LAr/EMECC/CellNoisevsEtaPhi_EMEC2C_noth":"/LAr/EMECC/CellNoisevsEtaPhi_EMEC2C_noth", +## "/LAr/EMECC/CellRatevsEtaPhi_EMEC2C_medEth":"/LAr/EMECC/CellRatevsEtaPhi_EMEC2C_medEth", +## "/LAr/EMECC/CellRatevsPhi_EMEC2C_medEth":"/LAr/EMECC/CellRatevsPhi_EMEC2C_medEth", +## "/LAr/FCALA/CellNoisevsEtaPhi_FCAL2A_noth":"/LAr/FCALA/CellNoisevsEtaPhi_FCAL2A_noth", +## "/LAr/FCALA/CellRatevsEtaPhi_FCAL2A_medEth":"/LAr/FCALA/CellRatevsEtaPhi_FCAL2A_medEth", +## "/LAr/FCALA/CellRatevsPhi_FCAL2A_medEth":"/LAr/FCALA/CellRatevsPhi_FCAL2A_medEth", +## "/LAr/FCALC/CellNoisevsEtaPhi_FCAL2C_noth":"/LAr/FCALC/CellNoisevsEtaPhi_FCAL2C_noth", +## "/LAr/FCALC/CellRatevsEtaPhi_FCAL2C_medEth":"/LAr/FCALC/CellRatevsEtaPhi_FCAL2C_medEth", +## "/LAr/FCALC/CellRatevsPhi_FCAL2C_medEth":"/LAr/FCALC/CellRatevsPhi_FCAL2C_medEth", +## "/LAr/HECA/CellNoisevsEtaPhi_HEC2A_noth":"/LAr/HECA/CellNoisevsEtaPhi_HEC2A_noth", +## "/LAr/HECA/CellRatevsEtaPhi_HEC2A_medEth":"/LAr/HECA/CellRatevsEtaPhi_HEC2A_medEth", +## "/LAr/HECA/CellRatevsPhi_HEC2A_medEth":"/LAr/HECA/CellRatevsPhi_HEC2A_medEth", +## "/LAr/HECC/CellNoisevsEtaPhi_HEC2C_noth":"/LAr/HECC/CellNoisevsEtaPhi_HEC2C_noth", +## "/LAr/HECC/CellRatevsEtaPhi_HEC2C_medEth":"/LAr/HECC/CellRatevsEtaPhi_HEC2C_medEth", +## "/LAr/HECC/CellRatevsPhi_HEC2C_medEth":"/LAr/HECC/CellRatevsPhi_HEC2C_medEth" + + + } + +folderMapHistoP30 = { + +## "/LAr/Cluster/CalTopoCluster/Max500_etaphi_avget":"/LAr/Cluster/CalTopoCluster/Max500_etaphi_avget", +## "/LAr/Cluster/CalTopoCluster/MaxEnergy_etaphi_avgenergy":"/LAr/Cluster/CalTopoCluster/MaxEnergy_etaphi_avgenergy", +## "/LAr/Cluster/CalTopoCluster/NCells":"/LAr/Cluster/CalTopoCluster/NCells", +## "/LAr/Cluster/CalTopoCluster/NClus":"/LAr/Cluster/CalTopoCluster/NClus", +## "/LAr/Cluster/CalTopoCluster/NClus_botvstop":"/LAr/Cluster/CalTopoCluster/NClus_botvstop", +## "/LAr/Cluster/CalTopoCluster/energy_clus_barrel":"/LAr/Cluster/CalTopoCluster/energy_clus_barrel", +## "/LAr/Cluster/CalTopoCluster/energy_clus_endcap":"/LAr/Cluster/CalTopoCluster/energy_clus_endcap", +## "/LAr/Cluster/CalTopoCluster/energy_clus_hecfcal":"/LAr/Cluster/CalTopoCluster/energy_clus_hecfcal", +## "/LAr/Cluster/CalTopoCluster/et_clus_barrel":"/LAr/Cluster/CalTopoCluster/et_clus_barrel", +## "/LAr/Cluster/CalTopoCluster/et_clus_endcap":"/LAr/Cluster/CalTopoCluster/et_clus_endcap", +## "/LAr/Cluster/CalTopoCluster/et_clus_hecfcal":"/LAr/Cluster/CalTopoCluster/et_clus_hecfcal", +## "/LAr/Cluster/CalTopoCluster/eta_avgenergy":"/LAr/Cluster/CalTopoCluster/eta_avgenergy", +## "/LAr/Cluster/CalTopoCluster/etaphi_avgenergy_hotrat":"/LAr/Cluster/CalTopoCluster/etaphi_avgenergy_hotrat", +## "/LAr/Cluster/CalTopoCluster/etaphi_avgnegenergy":"/LAr/Cluster/CalTopoCluster/etaphi_avgnegenergy", +## "/LAr/Cluster/CalTopoCluster/etaphi_hotrat":"/LAr/Cluster/CalTopoCluster/etaphi_hotrat", +## "/LAr/Cluster/CalTopoCluster/etaphi_ncellinclus":"/LAr/Cluster/CalTopoCluster/etaphi_ncellinclus", +## "/LAr/Cluster/CalTopoCluster/etaphi_thresh_avgenergy_0":"/LAr/Cluster/CalTopoCluster/etaphi_thresh_avgenergy_0", +## "/LAr/Cluster/CalTopoCluster/etaphi_thresh_avgenergy_1":"/LAr/Cluster/CalTopoCluster/etaphi_thresh_avgenergy_1", +## "/LAr/Cluster/CalTopoCluster/etaphi_thresh_avgenergy_2":"/LAr/Cluster/CalTopoCluster/etaphi_thresh_avgenergy_2", +## "/LAr/Cluster/CalTopoCluster/m_EtavsPhi0":"/LAr/Cluster/CalTopoCluster/m_EtavsPhi0", +## "/LAr/Cluster/CalTopoCluster/m_EtavsPhi1":"/LAr/Cluster/CalTopoCluster/m_EtavsPhi1", +## "/LAr/Cluster/CalTopoCluster/m_EtavsPhi2":"/LAr/Cluster/CalTopoCluster/m_EtavsPhi2", +## "/LAr/Cluster/CalTopoCluster/m_clus_eta0":"/LAr/Cluster/CalTopoCluster/m_clus_eta0", +## "/LAr/Cluster/CalTopoCluster/m_clus_eta1":"/LAr/Cluster/CalTopoCluster/m_clus_eta1", +## "/LAr/Cluster/CalTopoCluster/m_clus_eta2":"/LAr/Cluster/CalTopoCluster/m_clus_eta2", +## "/LAr/Cluster/CalTopoCluster/m_clus_phi0":"/LAr/Cluster/CalTopoCluster/m_clus_phi0", +## "/LAr/Cluster/CalTopoCluster/m_clus_phi1":"/LAr/Cluster/CalTopoCluster/m_clus_phi1", +## "/LAr/Cluster/CalTopoCluster/m_clus_phi2":"/LAr/Cluster/CalTopoCluster/m_clus_phi2", +## "/LAr/Cluster/CalTopoCluster/m_clus_time":"/LAr/Cluster/CalTopoCluster/m_clus_time", +## "/LAr/Cluster/CalTopoCluster/m_clus_timevsenergy":"/LAr/Cluster/CalTopoCluster/m_clus_timevsenergy", +## "/LAr/Cluster/CalTopoCluster/phi_avgenergy":"/LAr/Cluster/CalTopoCluster/phi_avgenergy", +## "/LAr/Cluster/CalTopoCluster/ratioE_leadcell_clus":"/LAr/Cluster/CalTopoCluster/ratioE_leadcell_clus", +## "/LAr/Cluster/EMTopoCluster/Max500_etaphi_avget":"/LAr/Cluster/EMTopoCluster/Max500_etaphi_avget", +## "/LAr/Cluster/EMTopoCluster/MaxEnergy_etaphi_avgenergy":"/LAr/Cluster/EMTopoCluster/MaxEnergy_etaphi_avgenergy", +## "/LAr/Cluster/EMTopoCluster/NCells":"/LAr/Cluster/EMTopoCluster/NCells", +## "/LAr/Cluster/EMTopoCluster/NClus":"/LAr/Cluster/EMTopoCluster/NClus", +## "/LAr/Cluster/EMTopoCluster/NClus_botvstop":"/LAr/Cluster/EMTopoCluster/NClus_botvstop", +## "/LAr/Cluster/EMTopoCluster/energy_clus_barrel":"/LAr/Cluster/EMTopoCluster/energy_clus_barrel", +## "/LAr/Cluster/EMTopoCluster/energy_clus_endcap":"/LAr/Cluster/EMTopoCluster/energy_clus_endcap", +## "/LAr/Cluster/EMTopoCluster/energy_clus_hecfcal":"/LAr/Cluster/EMTopoCluster/energy_clus_hecfcal", +## "/LAr/Cluster/EMTopoCluster/et_clus_barrel":"/LAr/Cluster/EMTopoCluster/et_clus_barrel", +## "/LAr/Cluster/EMTopoCluster/et_clus_endcap":"/LAr/Cluster/EMTopoCluster/et_clus_endcap", +## "/LAr/Cluster/EMTopoCluster/et_clus_hecfcal":"/LAr/Cluster/EMTopoCluster/et_clus_hecfcal", +## "/LAr/Cluster/EMTopoCluster/eta_avgenergy":"/LAr/Cluster/EMTopoCluster/eta_avgenergy", +## "/LAr/Cluster/EMTopoCluster/etaphi_avgenergy_hotrat":"/LAr/Cluster/EMTopoCluster/etaphi_avgenergy_hotrat", +## "/LAr/Cluster/EMTopoCluster/etaphi_avgnegenergy":"/LAr/Cluster/EMTopoCluster/etaphi_avgnegenergy", +## "/LAr/Cluster/EMTopoCluster/etaphi_hotrat":"/LAr/Cluster/EMTopoCluster/etaphi_hotrat", +## "/LAr/Cluster/EMTopoCluster/etaphi_ncellinclus":"/LAr/Cluster/EMTopoCluster/etaphi_ncellinclus", +## "/LAr/Cluster/EMTopoCluster/etaphi_thresh_avgenergy_1":"/LAr/Cluster/EMTopoCluster/etaphi_thresh_avgenergy_1", +## "/LAr/Cluster/EMTopoCluster/etaphi_thresh_avgenergy_2":"/LAr/Cluster/EMTopoCluster/etaphi_thresh_avgenergy_2", +## "/LAr/Cluster/EMTopoCluster/m_EtavsPhi1":"/LAr/Cluster/EMTopoCluster/m_EtavsPhi1", +## "/LAr/Cluster/EMTopoCluster/m_EtavsPhi2":"/LAr/Cluster/EMTopoCluster/m_EtavsPhi2", +## "/LAr/Cluster/EMTopoCluster/m_clus_eta0":"/LAr/Cluster/EMTopoCluster/m_clus_eta0", +## "/LAr/Cluster/EMTopoCluster/m_clus_eta1":"/LAr/Cluster/EMTopoCluster/m_clus_eta1", +## "/LAr/Cluster/EMTopoCluster/m_clus_eta2":"/LAr/Cluster/EMTopoCluster/m_clus_eta2", +## "/LAr/Cluster/EMTopoCluster/m_clus_phi1":"/LAr/Cluster/EMTopoCluster/m_clus_phi1", +## "/LAr/Cluster/EMTopoCluster/m_clus_phi2":"/LAr/Cluster/EMTopoCluster/m_clus_phi2", +## "/LAr/Cluster/EMTopoCluster/m_clus_time":"/LAr/Cluster/EMTopoCluster/m_clus_time", +## "/LAr/Cluster/EMTopoCluster/m_clus_timevsenergy":"/LAr/Cluster/EMTopoCluster/m_clus_timevsenergy", +## "/LAr/Cluster/EMTopoCluster/phi_avgenergy":"/LAr/Cluster/EMTopoCluster/phi_avgenergy", +## "/LAr/Cluster/EMTopoCluster/ratioE_leadcell_clus":"/LAr/Cluster/EMTopoCluster/ratioE_leadcell_clus", +## "/LAr/EMB/m_clus_phi0":"/LAr/EMB/m_clus_phi0", +## "/LAr/EMECA/etaphi_thresh_avgenergy_0":"/LAr/EMECA/etaphi_thresh_avgenergy_0", +## "/LAr/EMECC/m_EtavsPhi0":"/LAr/EMECC/m_EtavsPhi0" + + } diff --git a/DataQuality/DataQualityUtils/python/hancool_histo_mod.py b/DataQuality/DataQualityUtils/python/hancool_histo_mod.py new file mode 100644 index 0000000000000000000000000000000000000000..e6b67a2df0b4d566e4466d3dad21911f4ddb18c2 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/hancool_histo_mod.py @@ -0,0 +1,283 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + + +import string, os +import re +## Needed to correct ROOT behavior; see below +CWD = os.getcwd() + +import sys +import pdb + +import ROOT +## Importing gSystem may change the current directory to one of the +## command-line arguments; chdir to original directory to have +## predictable behavior +from ROOT import gSystem +os.chdir(CWD) + +## Import the ROOT library for reading han results +gSystem.Load('libDataQualityUtils') +from ROOT import dqutils +from DataQualityUtils.hancool_histo_algdef import * + +## LumiBlock length (in minutes) +LBlength = 1.0 + +## Mapping han<->COOL +from DataQualityUtils.hancool_histo_foldermap import * + +## Mapping Status<->Code +codeMap = { + "Undefined":0, + "Red":1, + "Yellow":2, + "Green":3 + } + +## Mapping different interval types +intervalType = { + 0 : "_minutes30_", + 1 : "_minutes10_", + 2 : "ERROR" + } + +## Generates LB from filename +def getLimits( name ): + global low_limit + global hi_limit + if (name.find('minutes10_')>-1): + t=name.split('minutes10_') + digit = float( ((t[len(t)-1]).split('_'))[0]) + low_limit = int((digit-1.0)*10.0/LBlength+1)-1 + hi_limit = int(digit*10.0/LBlength) + elif (name.find('minutes30_')>-1): + t=name.split('minutes30_') + digit = float( ((t[len(t)-1]).split('_'))[0]) + low_limit = int((digit-1.0)*30.0/LBlength+1)-1 + hi_limit = int(digit*30.0/LBlength) + else: + low_limit = 0 + hi_limit = 4294967295 + return {"since":low_limit, "until":hi_limit} + + +## Looks up the result in the HanOutputFile +def stringGetResult( file, rootFolder ): + rootFolder =file+":"+rootFolder + of = dqutils.HanOutputFile( file ) + result = of.getStringName(rootFolder) + return result + +def stringGetInfo( file, rootFolder ): + rootFolder =file+":"+rootFolder + of = dqutils.HanOutputFile( file ) + info = of.getInfo(rootFolder) + if (len(info)>0): + return info + else: + return 'null result' + +def ListHistoAssessments( xml, channel ): + the_result_histo = "Undefined" + g=open(xml,'r') + while 1: + line = g.readline() + if not line: + break + if line.find('run') > -1: + gg = line.split(':')[1] + ww = gg.split(' ') + res = ''.join(ww) + if res.find(channel)>-1: + the_result_histo = res + g.close() + return the_result_histo + +def AllHistograms( file ): + of = dqutils.HanOutputFile( file ) + resultstrH = of.stringAllHistograms() + return resultstrH + +def AllDQAssessments( file ): + of = dqutils.HanOutputFile( file ) + resultstr = of.stringAllDQAssessments() + return resultstr + +def MakeHistoAssessmentsFile( file ): + of = dqutils.HanOutputFile( file ) + resultstr = of.stringHistoAssessments() + g=open('Allhisto.list','w') + g.write(resultstr) + g.close() + +def NameHisto_Splitting( channel ): + t = channel.split('/') + N = int(len(t)-1) + histo_name = channel.split('/')[N] + return histo_name + +def NamePath_Splitting( channel ): + t = channel.split('/') + N = int(len(t)-1) + list_name = channel.split('/')[0:N] + path_name = '/'.join(list_name) + return path_name + +##------------------------------------------------------------- +# hancool_histo() +##------------------------------------------------------------- + +def hancool_histo( inputFilePath="", input_run=-1, dbConnectionHisto="",dqmfOflHisto="", dbTagName=""): + + if (input_run==-1): input_run = 52280 + + if (len(inputFilePath)<1): + inputFilePath = "/afs/cern.ch/user/a/atlasdqm/dqmdisk1/han_results/tier0/FDR2b/1/physics_Express/" + if ( inputFilePath.rfind("/")!=(len(inputFilePath)-1) ): + inputFilePath+="/" + if (len(dbConnectionHisto)<1): dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio/DQMF_08112008/14.2.10/WorkArea/python/MyCOOL_histo_FDR2c.db;dbname=OFLP200" + + if (len(dqmfOflHisto)<1): dqmfOflHisto = "/GLOBAL/DETSTATUS/DQMFOFLH" + if (len(dbTagName)<1): dbTagName = "DetStatusDQMFOFLH-FDR2-02" + + ## pdb.set_trace() + modH = dqutils.HistogramDataCOOL(dbConnectionHisto,dqmfOflHisto,0,0,0,0) + path=inputFilePath + run=int(input_run) + filename="run_"+str(run)+"_han.root" + + # filling OFLH DB for histos (global run) + for pair in folderMapHisto.iteritems(): + i = 0 + number = 0 + print pair[0], pair[1] + # print "--------------------------------------" + histo_string = NameHisto_Splitting( pair[0] ) + path_string = NamePath_Splitting( pair[0] ) + # print "--------------------------------------" + while ((os.path.isfile(path+filename)) and (i<2)): + while os.path.isfile(path+filename): + if (getLimits(filename)["until"]==4294967295): + modH.setIOV(run, getLimits(filename)["since"], + run, getLimits(filename)["until"]) + MakeHistoAssessmentsFile( path+filename ) + xml = 'Allhisto.list' + the_result_histo = ListHistoAssessments( xml, pair[0] ) + print the_result_histo + + if (the_result_histo=="Undefined"): + + print " This histogram DOES NOT have a corresponding channel in the DB! " + print " Info cannot be inserted " + + else: + histo_nameonly = the_result_histo.split('/')[int(len(the_result_histo.split('/')))-1] + print histo_nameonly + resultH=stringGetResult(path+filename, pair[0]+"_/Results/Status") + print resultH + algo=stringGetResult(path+filename, pair[0]+"_/Config/name") + print algo + entries = ExtractNEntries(path+filename,path_string,histo_string) + print entries + mean_rms= stringGetInfo(path+filename, pair[0]+"_/Results") + print mean_rms + + par1 = '0' + par2 = '0' + par3 = '0' + par4 = '0' + par5 = '0' + + if (algo.find('Bins_Diff_FromAvg')>-1 and mean_rms.find('null')<0): + par1 = ExtractAverage(mean_rms) + par2 = ExtractNBins(mean_rms) + elif (algo.find('GatherData')>-1 and mean_rms.find('null')<0): + if (mean_rms.find('Error')>-1): #new GatherData + par1 = ExtractMean(mean_rms) + par2 = ExtractEMean(mean_rms) + par3 = ExtractRMS(mean_rms) + par4 = ExtractERMS(mean_rms) + else: #old GatherData + par1 = ExtractMean(mean_rms) + par2 = ExtractRMS(mean_rms) + elif (algo.find('Simple_pol1_Fit')>-1 and mean_rms.find('null')<0): + par1 = ExtractPol0(mean_rms) + par2 = ExtractPol1(mean_rms) + elif (algo.find('Simple_gaus_Fit')>-1 and mean_rms.find('null')<0): + par1 = ExtractMeanG(mean_rms) + par2 = ExtractRMSG(mean_rms) + par3 = ExtractConstG(mean_rms) + elif (algo.find('SideBand')>-1 and mean_rms.find('null')<0): + par1 = ExtractSideBands(mean_rms) + par2 = ExtractTotInt(mean_rms) + elif (algo.find('CheckHisto_Mean')>-1 and mean_rms.find('null')<0): + par1 = ExtractXMean(mean_rms) + par2 = ExtractYMean(mean_rms) + elif (algo.find('CheckHisto_RMS')>-1 and mean_rms.find('null')<0): + par1 = ExtractXRMS(mean_rms) + par2 = ExtractYRMS(mean_rms) + elif (algo.find('Bin')>-1) and mean_rms.find('null')<0 and ((algo.find('Threshold')>-1) or (algo.find('ContentComp')>-1)): + output = ExtractOnlyNBins(histo_nameonly, mean_rms) + par1 = output[0] + if (len(output)>1): + par2 = output[1] + par3 = output[2] + par4 = output[3] + par5 = output[4] + else: + par2 = '0' + else: + par1 = '0' + par2 = '0' +# combined algorithms: + # CheckHisto_Mean&GatherData + if (algo.find('CheckHisto_Mean')>-1 and algo.find('GatherData')>-1 and mean_rms.find('null')<0): + comb_mean_rms = mean_rms.split('XMean: ') + if (comb_mean_rms[0].find('Error')>-1): #new GatherData + par1 = ExtractMean(comb_mean_rms[0]) + par2 = ExtractEMean(comb_mean_rms[0]) + par3 = ExtractRMS(comb_mean_rms[0]) + par4 = ExtractERMS(comb_mean_rms[0]) + par5 = ExtractXMean(comb_mean_rms[1]) + else: #old GatherData + par1 = ExtractMean(comb_mean_rms[0]) + par2 = ExtractRMS(comb_mean_rms[0]) + par3 = ExtractXMean(comb_mean_rms[1]) + par4 = ExtractYMean(comb_mean_rms[1]) + # BinContentComp&GatherData + if (algo.find('BinContentComp')>-1 and algo.find('GatherData')>-1 and mean_rms.find('null')<0): + if (mean_rms.find('Error')>-1): #new GatherData + par1 = ExtractMean(mean_rms) + par2 = ExtractEMean(mean_rms) + par3 = ExtractOnlyNBins(histo_nameonly, mean_rms) + par4 = ExtractRMS(mean_rms) + par5 = ExtractERMS(mean_rms) + else: #old GatherData + par1 = ExtractMean(mean_rms) + par2 = ExtractRMS(mean_rms) + par3 = ExtractOnlyNBins(histo_nameonly, mean_rms) + + codeH = codeMap[resultH] + + try: + test1 = float(par1) + test2 = float(par2) + test3 = float(par3) + test4 = float(par4) + test5 = float(par5) + modH.insertH(pair[1], codeH, str(algo), int(entries), float(par1), float(par2), float(par3), float(par4), float(par5), dbTagName ) + print "----------- global: Insertion successfull! --------------------" + print dbTagName + except: + modH.insertH(pair[1], codeH, str(algo), int(entries), 0, 0, 0, 0, 0, dbTagName) + print 'Could not upload parameters in DB, they are not numbers! Check the algorithm!' + + number = number+1 + filename="run_"+str(run)+intervalType[i]+str(number)+"_han.root" + number = 1 + i = i+1 + filename="run_"+str(run)+intervalType[i]+str(number)+"_han.root" + filename="run_"+str(run)+"_han.root" + print "--------------------------------------" + diff --git a/DataQuality/DataQualityUtils/python/hancoolmod.py b/DataQuality/DataQualityUtils/python/hancoolmod.py new file mode 100644 index 0000000000000000000000000000000000000000..b82895d7a42f7faafdc5161c1ffc073b03bb4f8b --- /dev/null +++ b/DataQuality/DataQualityUtils/python/hancoolmod.py @@ -0,0 +1,490 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + + +import os +## Needed to correct ROOT behavior; see below +CWD = os.getcwd() + +import sys +import pdb +import glob + +import ROOT +## Importing gSystem may change the current directory to one of the +## command-line arguments; chdir to original directory to have +## predictable behavior +from ROOT import gSystem +os.chdir(CWD) + +## Import the ROOT library for reading han results +gSystem.Load('libDataQualityUtils') +from ROOT import dqutils + + +## LumiBlock length (in minutes) +LBlength = 1.0 + + +## Mapping han<->COOL +folderMap = { + # ATLAS global + #"/Global/DQShift": "ATLGL", + #lar + "/LAr/EMBC":"EMBC", + "/LAr/EMBA":"EMBA", + "/LAr/EMECA":"EMECA", + "/LAr/EMECC":"EMECC", + "/LAr/FCALA":"FCALA", + "/LAr/FCALC":"FCALC", + "/LAr/HECA" :"HECA", + "/LAr/HECC" :"HECC", + # Tile + "/TileCal/Cell/AnyPhysTrig/LBA": "TILBA", + "/TileCal/Cell/AnyPhysTrig/LBC": "TILBC", + "/TileCal/Cell/AnyPhysTrig/EBA": "TIEBA", + "/TileCal/Cell/AnyPhysTrig/EBC": "TIEBC", + "/InnerDetector/IDAlignment/BeamSpot/NoTriggerSelection" : "IDBS", + "/InnerDetector/IDAlignment/CombinedInDetTracks_NoTriggerSelection" : "IDAL", + "/InnerDetector/IDAlignment_Perf" : "IDPF", + "/InnerDetector/Global" : "IDGL", + # CaloGlobal + "/CaloMonitoring/CaloMonShift/CaloMonBAR" : "CALBA", + "/CaloMonitoring/CaloMonShift/CaloMonECA" : "CALEA", + "/CaloMonitoring/CaloMonShift/CaloMonECC" : "CALEC", + # pixels + "/InnerDetector/Pixel/DQMF/BLayer" :"PIX0", + "/InnerDetector/Pixel/DQMF/Barrel" :"PIXB", + "/InnerDetector/Pixel/DQMF/ECA" :"PIXEA", + "/InnerDetector/Pixel/DQMF/ECC" :"PIXEC", + # sct + "/InnerDetector/SCT/SCTB" :"SCTB", + "/InnerDetector/SCT/SCTEA" :"SCTEA", + "/InnerDetector/SCT/SCTEC" :"SCTEC", + # trt + "/InnerDetector/TRT/TRTB" :"TRTB", + "/InnerDetector/TRT/TRTEA" :"TRTEA", + "/InnerDetector/TRT/TRTEC" :"TRTEC", + # rpc + "/MuonDetectors/RPC/RPCBA" :"RPCBA", + "/MuonDetectors/RPC/RPCBC" :"RPCBC", + # mdt + "/MuonDetectors/MDT/MDTBA" :"MDTBA", + "/MuonDetectors/MDT/MDTBC" :"MDTBC", + "/MuonDetectors/MDT/MDTEA" :"MDTEA", + "/MuonDetectors/MDT/MDTEC" :"MDTEC", + # tgc + "/MuonDetectors/TGC/TGCEA" :"TGCEA", + "/MuonDetectors/TGC/TGCEC" :"TGCEC", + # csc + "/MuonDetectors/CSC/CSCEA/Cluster" :"CSCEA", + "/MuonDetectors/CSC/CSCEC/Cluster" :"CSCEC", + # l1 + "/CentralTrigger/ErrorSummary": "L1CTP", + "/L1Calo" : "L1CAL", + # HLT + "/HLT/TRCAL" : "TRCAL", + "/HLT/TRBJT" : "TRBJT", + "/HLT/TRBPH" : "TRBPH", + "/HLT/TRELE" : "TRELE", + "/HLT/TRGAM" : "TRGAM", + "/HLT/TRJET" : "TRJET", + "/HLT/TRMET" : "TRMET", + "/HLT/TRMBI" : "TRMBI", + "/HLT/TRMUO" : "TRMUO", + "/HLT/TRTAU" : "TRTAU", + "/HLT/TRIDT" : "TRIDT", + # egamma + "/egamma/EIDB" : "EIDB", + "/egamma/EIDC" : "EIDCR", + "/egamma/EIDE" : "EIDE", + "/egamma/PHOB" : "PIDB", + "/egamma/PHOC" : "PIDCR", + "/egamma/PHOE" : "PIDE", + # tau + "/Tau/TAUB" : "TAUB", + } + +## Mapping Status<->Code +codeMap = { + "Disabled": -1, + "Undefined":0, + "Red":1, + "Yellow":2, + "Green":3 + } + +## Mapping different interval types +intervalType = { + 0 : "_minutes30_", + 1 : "_minutes10_", + 2 : "_medStat_", + 3 : "_lowStat_", + 4 : "ERROR" + } + +## Generates LB from filename +def getLimits( name ): + try: + import re, detmaskmod + runNumber = re.match('run_(\d+)_.*han.root', name).group(1) + max_hi_limit = detmaskmod.getNumLumiBlocks(int(runNumber))+1 + if (name.find('minutes10_')>-1): + t=name.split('minutes10_') + digit = float( ((t[len(t)-1]).split('_'))[0]) + low_limit = int((digit-1.0)*10.0/LBlength+1)-1 + hi_limit = int(digit*10.0/LBlength) + elif (name.find('minutes30_')>-1): + t=name.split('minutes30_') + digit = float( ((t[len(t)-1]).split('_'))[0]) + low_limit = int((digit-1.0)*30.0/LBlength+1)-1 + hi_limit = int(digit*30.0/LBlength) + elif 'lowStat_' in name: + t=name.split('lowStat_LB')[-1] + t=t.split('_han.root')[0] + digits = t.split('-') + low_limit = int(digits[0]) + hi_limit = min(int(digits[1])+1, max_hi_limit) + elif 'medStat_' in name: + t=name.split('medStat_LB')[-1] + t=t.split('_han.root')[0] + digits = t.split('-') + low_limit = int(digits[0]) + hi_limit = min(int(digits[1])+1, max_hi_limit) + else: + low_limit = 1 + hi_limit = max_hi_limit + except Exception, e: + print 'Could not determine limits because:', e + low_limit = 1 + hi_limit = 4294967295 + + return (low_limit, hi_limit) + +## Looks up the result in the HanOutputFile +def stringGetResult( file, rootFolder ): + rootFolder =file+":"+rootFolder + of = dqutils.HanOutputFile( file ) +# result = of.getStatus(rootFolder) #until DataQualityUtils-02-02-00 + result = of.getStringName(rootFolder) + return result + +#/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/FDR2/NoStream/run_3070_han.root + +##path="/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/physics_HLT_Cosmic_AllTeIDSelected/" +#path="/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/FDR2/NoStream/" + +##------------------------------------------------------------- + +def hancool(runNumber=3070, + filePath="/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/FDR2/NoStream/", + dbConnection="sqlite://;schema=MyCOOL.db;dbname=COMP200",dqmfOfl="/GLOBAL/DETSTATUS/DQMFOFL", + db_tag="HEAD", shiftOfl="", shiftOfl_db_tag="HEAD", isESn=True): + + runlimitscache = {} + + print '====> Running hancool_defects' + hancool_defects(runNumber, filePath, dbConnection, 'HEAD', isESn) + print '<==== Done with hancool_defects' + + if ( filePath.rfind("/")!=(len(filePath)-1) ): + filePath+="/" + + def nocomment_insert(mod, flag, code, comment): + mod.insert(flag, code, 0, 0, db_tag) + + def comment_insert(mod, flag, code, comment): + mod.insert(flag, code, 0, 0, comment, db_tag) + + def codelogic(since, until, flag, code, comment=None): + if comment is None: + inserter = nocomment_insert + else: + inserter = comment_insert + mod.setIOV(runNumber, since, runNumber, until) + wasModified = True + oldcode=mod.dumpCode(flag, db_tag) + if (oldcode == -1): + # this situation shouldn't happen + inserter(mod, flag, code, comment) + elif (code==3 and oldcode in (sys.maxint, 0)): + inserter(mod, flag, code, comment) + elif (code==2 and (oldcode in (sys.maxint, 0, 3))): + inserter(mod, flag, code, comment) + elif (code==0 and oldcode==sys.maxint): + inserter(mod, flag, code, comment) + elif ((code==1 or code==-1) and code != oldcode): + inserter(mod, flag, code, comment) + else: + wasModified = False + if wasModified: + print '%d-%d, %s --> %s' % (since, until, flag, code) + else: + print 'Not changed for %s' % flag + + def filelogic(globname, filename, pair): + result=stringGetResult(globname, pair[0]+"/Results/Status") + code = codeMap[result] + if filename not in runlimitscache: + runlimitscache[filename] = getLimits(filename) + since, until = runlimitscache[filename] + print filename + ':', + codelogic(since, until, pair[1], code) + #print filename + ": " + pair[1]+" --> "+result+" ("+str(code)+")" + + ## pdb.set_trace() + mod = dqutils.StatusFlagCOOL(dbConnection,dqmfOfl,0,0,0,0) + filename="run_"+str(runNumber)+"_han.root" + runNumber = int(runNumber) + for pair in folderMap.iteritems(): + i = 0 + number = 0 + while ((os.path.isfile(filePath+filename)) and (i<2)): + while os.path.isfile(filePath+filename): + ##print "--------------------------------------" + filelogic(filePath+filename, filename, pair) + ##print "in database: "+str(mod.dumpCode(pair[1])) + number = number+1 + filename="run_"+str(runNumber)+intervalType[i]+str(number)+"_han.root" + number = 1 + i = i+1 + filename="run_"+str(runNumber)+intervalType[i]+str(number)+"_han.root" + for i in [2,3]: + for globname in glob.glob(os.path.join(filePath, 'run_%d%s*_han.root' % (runNumber, intervalType[i]))): + filename = os.path.basename(globname) + ##print "--------------------------------------" + filelogic(globname, filename, pair) + ##print "in database: "+str(mod.dumpCode(pair[1])) + filename="run_"+str(runNumber)+"_han.root" + ##print "--------------------------------------" + + import detmaskmod + blacks = detmaskmod.decodeBlack(detmaskmod.getRunMask(runNumber)) + for flag in blacks: + print 'Detector mask:', + codelogic(1, 4294967295, flag, -1) + + if shiftOfl != '': + print 'Exporting black flags to SHIFTOFL' + db_tag = shiftOfl_db_tag + mod = dqutils.StatusFlagCommentCOOL(dbConnection,shiftOfl,0,0,0,0) + for flag in blacks: + print 'Detector mask:', + codelogic(1, 4294967295, flag, -1, 'Automatically filled by hancool') + +def detmask_defects(runNumber, ddb): + import detmaskmod + blacks = detmaskmod.decodeBlack(detmaskmod.getRunMask(runNumber), + defects=True) + nlbs = detmaskmod.getNumLumiBlocks(runNumber) + for defect in blacks: + ddb.insert(defect, since=(runNumber << 32 | 1), + until=(runNumber << 32 | (nlbs+1)), + comment='Automatically added by hancool', + added_by='sys:hancool') + +import collections +defect_val = collections.namedtuple('defect_val', + 'defect, comment, recoverable') +defect_iov = collections.namedtuple('defect_iov', + 'defect, comment, recoverable, since, until') + +def ctp_defects(d, i, runNumber): + mapping = { 1: 'TRIG_L1_CTP_CTP_ROD_bcid', + 2: 'TRIG_L1_CTP_bcid', + 3: 'TRIG_L1_CTP_CTP_MuCTPI_bcid', + 4: 'TRIG_L1_CTP_candnumber', + 5: 'TRIG_L1_CTP_multpt', + 6: 'TRIG_L1_CTP_roiNum', + 7: 'TRIG_L1_CTP_roiCand', + 8: 'TRIG_L1_CTP_bcidrange', + 9: 'TRIG_L1_CTP_lumiblockrange', + 10: 'TRIG_L1_CTP_lumiblocktime', + 11: 'TRIG_L1_CTP_nanosectime', + 12: 'TRIG_L1_CTP_TAPnoTBP', + 13: 'TRIG_L1_CTP_TAVnoTAP', + 14: 'TRIG_L1_CTP_CTPsim', + 15: 'TRIG_L1_CTP_incompletefragment', + #TODO: add missing-orbit bin here, eventually (i.e. 15: 'TRIG_L1_CTP_missingorbit') + } + + rv = [] + when = d.Get('CentralTrigger/ErrorSummary/errorSummaryPerLumiBlock') + if not when: + return None + bad_lbs = {} + overflow_bad_lbs = {} + for key in mapping: + bad_lbs[key] = [] + + # loop over error bin numbers defined in dict above + for errorBin in mapping: + bad_lbs[errorBin] = [bin for bin in xrange(1, when.GetNbinsX()+1) if when.GetBinContent(bin, errorBin) > 0] # fix this line, slicing in Y? is that it? + overflow_bad_lbs[errorBin] = (when.GetBinContent(when.GetNbinsX()+1, errorBin) > 0) + + message = 'Automatically set' + + for defect in mapping: + for lb in bad_lbs[defect]: + rv.append(defect_iov(mapping[defect], message, False, lb, lb+1)) + if overflow_bad_lbs[defect]: + message += '; defect occurred past end of monitoring histogram, marking end of run as bad' + import detmaskmod # ugly: could happen for more than one defect - should be cheap though + nlbs = detmaskmod.getNumLumiBlocks(runNumber) + rv.append(defect_iov(defect, message, False, when.GetNbinsX(), nlbs+1)) + print "The following defects were extracted: " # TODO: remove this line? + print rv # TODO: remove this line? + return rv + +def sct_conf_defects(d, i, runNumber): + mapping = { 1: 'SCT_MOD_OUT_GT40', + 4: 'SCT_MOD_ERR_GT40', + 6: 'SCT_MOD_NOISE_GT40', + } + + rv = [] + histogram = d.Get('InnerDetector/SCT/SCTAll/ModuleStatus/SCTConf') + if not histogram: return None + for bin in mapping: + if histogram.GetBinContent(bin) > 40: + rv.append(defect_val(mapping[bin], '%.1d modules affected' % histogram.GetBinContent(bin), False)) + return rv + +def iovs_merge(l): + l.sort(key=lambda x: x.since) + rl = [] + i = 0 + previous = None; until = -1 + while i < len(l): + if not previous: + previous = l[i] + until = previous.until + else: + if l[i].since != until or previous.comment != l[i].comment: + # we have no more to merge for this range + rl.append(previous._replace(until=until)) + previous = l[i]; until = previous.until + else: + until = l[i].until + i += 1 + if previous: + rl.append(previous._replace(until=until)) + return rl + +def sct_readout_defects(d, i, runNumber): + def sct_readout_defects_core(d, prefix, l, comment): + import re + for k in d.GetListOfKeys(): + keyname = k.GetName() + m = re.search(prefix + '\((\d+)', keyname) + if m: + l.append(int(m.group(1))+1) + + def lb_comment(lb, l): + # l is a tuple name, list + rvl = [] + for name, l2 in l: + if lb in l2: + rvl.append(name) + return ' '.join(rvl) + + robfragment = d.Get('InnerDetector/SCT/SCTAll/ModuleStatus/SCTROBFragmentConf_/Results') + robwarnings = []; roberrors = [] + if not robfragment: return None + for prefix, l in (('WarningBin', robwarnings), + ('ErrorBin', roberrors)): + sct_readout_defects_core(robfragment, prefix, l, 'ROBFragment') + + maskedlink = d.Get('InnerDetector/SCT/SCTAll/ModuleStatus/SCTMaskedLinkConf_/Results') + linkwarnings = []; linkerrors = [] + if not maskedlink: return None + for prefix, l in (('WarningBin', linkwarnings), + ('ErrorBin', linkerrors)): + sct_readout_defects_core(maskedlink, prefix, l, 'MaskedLink') + allwarnings = set(robwarnings + roberrors + linkwarnings + linkerrors) + namelisttuple = (('ROBFragment', robwarnings), + ('MaskedLink', linkwarnings), + ('ROBFragment', roberrors), + ('MaskedLink', linkerrors)) + allwarnings_defects = [defect_iov('SCT_ROD_OUT_1', lb_comment(lb, namelisttuple), False, lb, lb+1) for lb in allwarnings] + allwarnings_defects = iovs_merge(allwarnings_defects) + + allerrors = set(roberrors + linkerrors) + namelisttuple = (('ROBFragment', roberrors), + ('MaskedLink', linkerrors)) + allerrors_defects = [defect_iov('SCT_GLOBAL_UNKNOWN', lb_comment(lb, namelisttuple), False, lb, lb+1) for lb in allerrors] + allerrors_defects = iovs_merge(allerrors_defects) + + #if allwarnings_defects: print allwarnings_defects + #if allerrors_defects: print allerrors_defects + + return allwarnings_defects + allerrors_defects + +def dqmf_node_defect(node, defect, badstatuses=['Red']): + badstatuses = set(badstatuses) + def dqmf_node_defect_core(d, i, runNumber): + filenode = d.Get(node + '_/Results/Status') + if not filenode: return None + status = set(x.GetName() for x in filenode.GetListOfKeys()) + if len(badstatuses & status) > 0: + assert len(status) == 1, 'Status must be length one or the file is corrupt' + return [defect_val(defect, node + ' DQMF color ' + status.pop(), False)] + else: + return [] + return dqmf_node_defect_core + +def hancool_defects(runNumber, filePath="./", dbConnection="", db_tag='HEAD', isESn=True): + analyzers = [ctp_defects] + if isESn: + analyzers += [dqmf_node_defect('InnerDetector/SCT/SCTAll/Hits/SctTotalEff', 'SCT_EFF_LT99', ['Yellow', 'Red']), + dqmf_node_defect('InnerDetector/SCT/SCTAll/Hits/SctTotalEff', 'SCT_GLOBAL_UNKNOWN', ['Red']), + dqmf_node_defect('InnerDetector/SCT/SCTAll/ModuleStatus/SCTConf', 'SCT_GLOBAL_UNKNOWN', ['Red']), + sct_conf_defects, + sct_readout_defects, + ] + + if ( len(filePath) == 0 or filePath[-1] != '/'): + filePath+="/" + if (len(dbConnection)<1): dbConnection = "/afs/cern.ch/user/a/atlasdqm/dqmdisk1/cherrypy-devel/defectstest.db/COMP200" + + import ROOT + # Conflict logic: shorter intervals override longer ones + defects_by_function = {} + + # empty list for missing high stat, reserved for future use + + fnames = ([ [filePath+"run_"+str(runNumber)+"_han.root"], [] ] + + [glob.glob(os.path.join(filePath, 'run_%s%s*_han.root' % (runNumber, intervalType[i]))) for i in [2, 3]]) + for i, itype in enumerate(fnames): + ldefects_by_function = {} + for globname in itype: + filename = os.path.basename(globname) + ##print "--------------------------------------" + since, until = getLimits(filename) + default_iov = defect_iov(*([0]*5)) + default_iov = default_iov._replace(since=since, until=until) + #print filename + ':', since, until + fobj = ROOT.TFile.Open(globname) + ldefects = None + for func in analyzers: + rv = func(fobj, i, runNumber) + if rv is not None: + rvt = [default_iov._replace(**(i._asdict())) for i in rv] + if func not in ldefects_by_function: + ldefects_by_function[func] = rvt + else: + ldefects_by_function[func] += rvt + defects_by_function.update(ldefects_by_function) + defects = sum(defects_by_function.values(), []) + + from DQDefects import DefectsDB + ddb = DefectsDB(dbConnection, read_only=False) + if isESn: + detmask_defects(runNumber, ddb) + with ddb.storage_buffer: + for defect in defects: + print defect + ddb.insert(defect.defect, since=(runNumber << 32 | defect.since), + until=(runNumber << 32 | defect.until), + comment=defect.comment, + recoverable=defect.recoverable, + added_by='sys:hancool') diff --git a/DataQuality/DataQualityUtils/python/handimod.py b/DataQuality/DataQualityUtils/python/handimod.py new file mode 100644 index 0000000000000000000000000000000000000000..c9c3c7a808deab07016e6e7dc13a3843230650fb --- /dev/null +++ b/DataQuality/DataQualityUtils/python/handimod.py @@ -0,0 +1,700 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## ***************************************************************************** +MODVERSION = '$Id: handimod.py,v 1.5 2009-03-16 19:48:32 boelaert Exp $' +## ***************************************************************************** + +import os +## Needed to correct ROOT behavior; see below +CWD = os.getcwd() + +import sys +import time +import ROOT +## Importing gSystem may change the current directory to one of the +## command-line arguments; chdir to original directory to have +## predictable behavior +from ROOT import gSystem +os.chdir(CWD) + +## Import the ROOT library for reading han results +gSystem.Load('libDataQualityUtils') +from ROOT import dqutils + +## LumiBlock length (in minutes) +LBlength = 1.0 + +def handiWithComparisons( name, resultsFile, htmlDir, runlistLoc, compare, browserMenu, allDirsScriptDir ): + ## compare: True if you want a "compare" button on every 1histo page, False by default + ## javaScriptLoc = url of the javascript for the "compare" button + ## HjavaScriptLoc = url of the javascript for the "history" button + ## runlistLoc = url where to find runlist.xml (runlist catalog) + ## browserMenu = True if you want a browser menu instead of the + ## allDirsScript = url of javascript to create browser menu + + if ( htmlDir.rfind("/")!=(len(htmlDir)-1) ): # htmlDir needs "/" at the end + htmlDir+="/" + + dirsstring = stringListSystemPaths( resultsFile, htmlDir ) + + dirs = dirsstring.rsplit() + for subHtmlDir in dirs: + if( not os.access(subHtmlDir,os.F_OK) ): + try: + os.makedirs(subHtmlDir) + except os.error: + print 'Cannot create directory "' + subHtmlDir + '"; exiting.' + sys.exit(-1) + + total = stringAllDQAssessments( resultsFile ) + + LB_range = '' + if (name.find('minutes10_')>-1): + t=name.split('10_') + digit = ((t[len(t)-1]).split(','))[0] + digit = float(digit) + low_limit = int((digit-1.0)*10.0/LBlength+1) + hi_limit = int(digit*10.0/LBlength) + LB_range = ', LB '+str(low_limit)+' - ' + str(hi_limit) + elif (name.find('minutes30_')>-1): + t=name.split('30_') + digit = float( ((t[len(t)-1]).split(','))[0]) + low_limit = int((digit-1.0)*30.0/LBlength+1) + hi_limit = int(digit*30.0/LBlength) + LB_range = ', LB '+str(low_limit)+' - ' + str(hi_limit) + + nSaved = saveAllHistograms( resultsFile, htmlDir, True, (name+LB_range) ) + if nSaved == 0: + print "There are no histograms in this file; writing a dummy index file" + if( not os.access(htmlDir,os.F_OK) ): + try: + os.makedirs(htmlDir) + except os.error: + print 'Cannot create directory "' + htmlDir + '"; exiting.' + sys.exit(-1) + dummyIndex = htmlDir + "/index.html" + d = open(dummyIndex,'w') + d.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + d.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + d.write('<head>\n') + d.write('<title>Error</title>\n') + d.write('</head>\n') + d.write('<body>\n') + d.write('<h1>Error:</h1>\n') + d.write('No histograms found for display. Check the <tt>han</tt> configuration\n') + d.write('to make sure it is consistent with the <tt>han</tt> input file.\n') + d.write('</body>\n') + d.write('</html>\n') + d.close() + return + + s=total.rsplit('\n') + # number = number of lines in total + number=len(s) + if (len(s[number-1])<1): # last line is empty + number-=1 + + if (browserMenu): + makeAllDirsXml( htmlDir, name, s, number, resultsFile) + list, namelist = makeAllDirsBrowserFile( htmlDir, name, s, number, resultsFile,allDirsScriptDir ) + else: + list, namelist = makeAllDirsFile( htmlDir, name, s, number, resultsFile ) + + for x in range(0,len(list)): + makeSubDirFile( htmlDir, name, s, number, namelist[x], list[x], runlistLoc, compare, allDirsScriptDir ) + makeColorFile( htmlDir, name, s, number, namelist[x], list[x], 'Red', runlistLoc, compare, allDirsScriptDir) + makeColorFile( htmlDir, name, s, number, namelist[x], list[x], 'Yellow', runlistLoc, compare, allDirsScriptDir) + makeColorFile( htmlDir, name, s, number, namelist[x], list[x], 'Green', runlistLoc, compare, allDirsScriptDir ) + makeCSSFile( htmlDir,"", namelist[x] ) + + makeCSSFile( htmlDir,"", "." ) + + +def makeAllDirsXml( htmlDir, name, s, number, resultsFile ): + g=open(htmlDir+'AllDirs.xml','w') + g.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n') + # initial number of white spaces, will change to positive value once we go over the lines + spaces=-1 + num_lists=0 + sub=""; + for x in range(0,number): + sp=s[x].rsplit() + if sp[3]=='dir': # a directory + namedir=sp[0] + shortNameDir = namedir + namediri = namedir.rfind("/") + if( namediri != -1 ): + shortNameDir = namedir[namediri+1:] + if namedir=='<top_level>': + shortNameDir='Overall Status' + spaces_new=s[x].find(sp[0][0]) + if ( (x<number-1) and (s[x+1].rsplit())[3]=='ass' ): + histo ="yes" + else: + histo = "no" + if spaces_new > spaces: # current dir is subdir of previous dir -> new item in new list + if (spaces !=-1): + sub +="sub" + g.write('<dir tag=\"'+sub+'dir\" id=\"' +shortNameDir + '\" status=\"'+sp[1]+'\" histo = \"' + histo + '\">\n') + num_lists+=1 + elif spaces_new==spaces: # current en previous dir in same motherdir -> new item + g.write('</dir>\n<dir tag=\"'+sub+'dir\" id=\"' +shortNameDir + '\" status=\"'+sp[1] +'\" histo = \"' + histo + '\">\n') + else: # close list and open new one + diff = spaces - spaces_new + while diff > 0: + g.write('</dir>\n') + diff -= 2 + num_lists-=1 + sub=sub[3:len(sub)] + g.write('</dir>\n') + g.write('<dir tag=\"'+sub+'dir\" id=\"' +shortNameDir + '\" status=\"'+sp[1] +'\" histo = \"' + histo + '\">\n') + if ( histo=='yes' ): # check that dir contains histos + if namedir=='<top_level>': + namedir = '.' + g.write('<a href="'+namedir +'/toplevel.html">'+shortNameDir+ '</a>\n') + else: + g.write('<a href="'+namedir +'/index.html" >'+shortNameDir+ '</a>\n') + # g.write('<'+sp[1]+'></'+sp[1]+'>\n') + spaces=spaces_new + for x in range(0,num_lists): + g.write('</dir>\n') + sub=sub[3:len(sub)] + g.close() + +def makeAllDirsFile( htmlDir, name, s, number, resultsFile ): + g=open(htmlDir+'index.html','w') + g.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + g.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + g.write('<head>\n') + g.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + g.write('<title>'+ name+ '</title>\n') + g.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n') + g.write('<link rel="stylesheet" href="https://atlasdqm.web.cern.ch/atlasdqm/css/mktree.css"/>\n') + g.write('<script type="text/javascript" src="https://atlasdqm.web.cern.ch/atlasdqm/js/mktree.js"></script>\n') + g.write('</head>\n') +# g.write('<body onload="CollapsibleLists.apply()">') + g.write('<body>') + g.write('<font class="DQGroup">[<a href="#" onclick="history.go(-1);return false;">Back</a>]</font>') +# g.write('<font class="DQGroup">[<a href="../index.html">Back</a>]</font>\n') + g.write('<h1>' + name + ': Monitoring and Automatic Checks</h1>\n') + + # initial number of white spaces, will change to positive value once we go over the lines + spaces=-1 + # list = list with directories (the line number) that contain histos + list=[] + # namelist = list with corresponding direcotory names + namelist=[] + + num_lists=0 + + g.write('<table>\n') + g.write('<tr><td>Click to expand</td></tr>\n') + g.write('<tr valign="top">\n<td width="500"><font class="DQGroup">\n') + for x in range(0,number): + sp=s[x].rsplit() + if sp[3]=='dir': # a directory + namedir=sp[0] + shortNameDir = namedir + namediri = namedir.rfind("/") + if( namediri != -1 ): + shortNameDir = namedir[namediri+1:] + if namedir=='<top_level>': + shortNameDir='Overall Status' + spaces_new=s[x].find(sp[0][0]) + if spaces_new > spaces: # current dir is subdir of previous dir -> new item in new list +# g.write('<ul%s>\n<li>' % (' class="collapsibleList"' if namedir=='<top_level>' else '')) + g.write('<ul%s>\n<li>' % (' class="mktree"' if namedir=='<top_level>' else '')) + num_lists+=1 + elif spaces_new==spaces: # current en previous dir in same motherdir -> new item + g.write('</li>\n<li>') + else: # close list and open new one + g.write('</li>') + diff = spaces - spaces_new + while diff > 0: + g.write('</ul></li>\n') + diff -= 2 + num_lists-=1 + g.write('<li>') +# if namedir!='<top_level>': +# g.write('<img src="http://atlasdqm.web.cern.ch/atlasdqm/img/pixel.png" width="0" height="13" alt="" />') + if ( (x<number-1) and (s[x+1].rsplit())[3]=='ass' ): # check that dir contains histos + if namedir=='<top_level>': + namedir = '.' + g.write('<a href="'+namedir +'/toplevel.html">'+shortNameDir+ ':</a>') + else: + g.write('<a href="'+namedir +'/index.html" >'+shortNameDir+ ':</a>') + g.write(' <font class="'+ sp[1]+'">'+ sp[1] + '</font>\n') + list.append(x) + namelist.append(namedir) + else: + g.write(shortNameDir+ ':') + g.write(' <font class="'+ sp[1]+'">'+ sp[1] + '</font>\n') + spaces=spaces_new + if num_lists>0: + g.write('</li>') + for x in range(0,num_lists-1): + g.write('</ul></li>\n') + if num_lists>0: + g.write('</ul>\n') + #g.write('</font></td>\n<td><font class="Info">From file:</font><br/><font class="Note">' + resultsFile + '</font></td>\n</tr>\n</table>') + g.write('</font></td>\n</tr>\n</table>') + g.write('</body>\n</html>\n') + g.close() + return list, namelist + + +def makeAllDirsBrowserFile( htmlDir, name, s, number, resultsFile,AllDirsScriptDir ): + g=open(htmlDir+'index.html','w') + g.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + g.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + g.write('<head>\n') + g.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + g.write('<title>'+ name+ '</title>\n') + g.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n') + g.write('<link rel="stylesheet" href="'+AllDirsScriptDir+'/mktree/mktree.css" type="text/css" />') + g.write('<script type="text/javascript" src="'+AllDirsScriptDir+'/AllDirs.js"><!-- dont contract--></script>\n') + g.write('<script type="text/javascript" src="'+AllDirsScriptDir+'/mktree/mktree.js"><!-- dont contract--></script>\n') + g.write('</head>\n') + g.write('<body onLoad=\"loadXMLDoc(\'AllDirs.xml\');\">') + g.write('<font class="DQGroup">[<a href="#" onclick="history.go(-1);return false;">Back</a>]</font>') + g.write('<h1>' + name + ': Monitoring and Automatic Checks</h1>\n') + #g.write('<p><font class="Info">From file:</font><br/><font class="Note">' + resultsFile + '</font></p>\n') + g.write('<div id=\"Select_subdir\">\n</div>\n') + #g.write('<table>\n<tr>\n') + #g.write('<td valign="top">        <input type="button" onclick="displaySubdirs();" value="... or display directories at current level" />\n') + #g.write('</td>\n</tr>\n</table>\n + #g.write('<br />\n') + g.write('<div id=\"Display_dir\">\n</div>\n') + g.write('</body>\n</html>\n') + g.close() + + # list = list with directories (the line number) that contain histos + list=[] + # namelist = list with corresponding direcotory names + namelist=[] + + num_lists=0 + + for x in range(0,number): + sp=s[x].rsplit() + if sp[3]=='dir': # a directory + namedir=sp[0] + if ( (x<number-1) and (s[x+1].rsplit())[3]=='ass' ): # check that dir contains histos + if namedir=='<top_level>': + namedir = '.' + list.append(x) + namelist.append(namedir) + g.close() + return list, namelist + +def makeSubDirFile( htmlDir, name, s, number, subname, assessIndex, runlistLoc,compare, AllDirsScriptDir): + + if( subname == '.' ): + h=open(htmlDir+'/'+subname+'/toplevel.html','w') + subnameTitle = 'Top Level' + else: + h=open(htmlDir+'/'+subname+'/index.html','w') + subnameTitle = subname + h.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + h.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + h.write('<head>\n') + h.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + h.write('<title>'+ name + ' ' + subnameTitle + '</title>\n') + h.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n') + h.write('<script type="text/javascript" src="'+AllDirsScriptDir+'/AllDirs.js"><!-- dont contract--></script>\n') + h.write('</head>\n') + h.write('<body>\n') + h.write('<font class="DQGroup">[<a href="#" onclick="history.go(-1);return false;">Back</a>]</font>') +# h.write('<font class="DQGroup">[<a href="') +# for x in range(subname.count("/")): +# h.write('../') +# h.write('../index.html">Back</a>]</font>\n') + h.write('<center>') + h.write('<table>\n<tr valign="top">\n<td width="250"></td>\n') + h.write('<td width="300" align="center"><h2>'+name+' '+subnameTitle+'</h2>\n') + h.write('<a href="Red.html">[Only Red]</a>\n') + h.write('<a href="Yellow.html">[Only Yellow]</a>\n') + h.write('<a href="Green.html">[Only Green]</a></td>\n') + h.write('<td width="250">\n<font class="Note">Click on images for details and full size.</font>\n') + h.write('</td>\n</tr>\n</table>\n') + h.write('<table cellpadding="4" cellspacing="20">\n') + y=assessIndex+1 + sp=s[y].rsplit() + col=0 + while(sp[3]=='ass' and y<number): + sp=s[y].rsplit() + titleStream = s[y].rsplit(" title ") + title = titleStream[1] + col+=1 + if col==1: + h.write('<tr>\n<td class="' + sp[1] + '" align="center"><a href="'+sp[0]+'.html" class="hintanchor" onmouseover="showhint(\'' +title+'\', this, event, \'400px\')"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + elif col==3: + h.write('<td class="' + sp[1] + '" align="center"><a href="'+sp[0]+'.html" class="hintanchor" onmouseover="showhint(\'' +title+'\', this, event, \'500px\')"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n</tr>\n') + col=0 + else: + h.write('<td class="' + sp[1] + '" align="center"><a href="'+sp[0]+'.html" class="hintanchor" onmouseover="showhint(\'' +title+'\', this, event, \'400px\')"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + temp = s[y].rsplit(" title ") + sp = temp[0].split() + makeOneHistFile( htmlDir, name, subname, sp, runlistLoc,compare ) + y=y+1 + if y< number: + sp=s[y].rsplit() + if not (col==3): + h.write('</tr>\n') + h.write('</table>\n</center>\n</body>\n</html>\n') + h.close() + + +def makeColorFile( htmlDir, name, s, number, subname, assessIndex , color, runlistLoc,compare,AllDirsScriptDir): + + if( subname == '.' ): + h=open(htmlDir+'/'+subname+'/'+color+'.html','w') + subnameTitle = 'Top Level' + else: + h=open(htmlDir+'/'+subname+'/'+color+'.html','w') + subnameTitle = subname + h.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + h.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + h.write('<head>\n') + h.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + h.write('<title>'+ name + ' ' + subnameTitle + ' ' + color + '</title>\n') + h.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n') + h.write('<script type="text/javascript" src="'+AllDirsScriptDir+'/AllDirs.js"><!-- dont contract--></script>\n') + h.write('</head>\n') + h.write('<body>\n') + h.write('<font class="DQGroup">[<a href="#" onclick="history.go(-1);return false;">Back</a>]</font>') + h.write('<center>') + h.write('<table>\n<tr valign="top">\n<td width="250"></td>\n') + h.write('<td width="300"><h2>'+name+' '+subnameTitle+': ' + color + ' only</h2>\n') + h.write('<a href="Red.html">[Only Red]</a>\n') + h.write('<a href="Yellow.html">[Only Yellow]</a>\n') + h.write('<a href="Green.html">[Only Green]</a></td>\n') + h.write('<td width="250">\n<font class="Note">Click on images for details and full size.</font>\n') + h.write('</td>\n</tr>\n</table>\n') + h.write('<table cellpadding="4" cellspacing="20">\n') + y=assessIndex+1 + sp=s[y].rsplit() + col=0 + count=0 + while(sp[3]=='ass' and y<number): + titleStream = s[y].rsplit(" title ") + title = titleStream[1] + sp=s[y].rsplit() + if sp[1]==color: + count = count +1 + col+=1 + if col==1: + h.write('<tr>\n<td class="' + sp[1] + '"><a href="'+sp[0]+'.html" class="hintanchor" onmouseover="showhint(\''+title+'\', this, event, \'400px\')"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + elif col==3: + h.write('<td class="' + sp[1] + '"><a href="'+sp[0]+'.html" class="hintanchor" onmouseover="showhint(\''+title+'\', this, event, \'500px\')"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n</tr>\n') + col=0 + else: + h.write('<td class="' + sp[1] + '"><a href="'+sp[0]+'.html" class="hintanchor" onmouseover="showhint(\'' +title+'\', this, event, \'400px\')"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + temp = s[y].rsplit(" title ") + sp = temp[0] + makeOneHistFile( htmlDir, name, subname, sp, runlistLoc,compare) + y=y+1 + if y< number: + sp=s[y].rsplit() + if not (col==3): + h.write('</tr>\n') + h.write('</table>\n') + if count==0: + h.write('<h3> No '+color+' histograms </h3>\n') + h.write('</center>\n</body>\n</html>\n') + h.close() + + +def writeLimitDiagram( k, limitName, lowColor, hiColor, loVal, hiVal ): + k.write('<tr><td> </td></tr>\n') + k.write('<tr><td colspan="2">\n') + k.write('<table>\n') + k.write('<caption>'+limitName+'</caption>\n') + k.write('<tr>\n') + k.write('<td width="340" align="center" colspan="4">\n') + k.write('<font color="'+lowColor+'">XXXXXXX</font><b>I</b>\n') + k.write('<font color="#ffd700">XXXXXXX</font><b>I</b>\n') + k.write('<font color="'+hiColor+'">XXXXXXX</font></td>\n') + k.write('</tr><tr>\n') + k.write('<td width="92"></td>\n') + k.write('<td width="78" align="center">'+ loVal +'</td>\n') + k.write('<td width="78" align="center">'+ hiVal +'</td>\n') + k.write('<td width="92"></td>\n') + k.write('</tr>\n</table>\n') + + +def makeOneHistFile( htmlDir, name, subname, sp, runlistLoc, compare ): + import re + runmatch = re.compile('^Run ([0-9]+), ([0-9]+)/(.+)$') + subrunmatch = re.compile('^Run ([0-9]+), (.+)_(.*), ([0-9]+)/(.+)$') + rm = runmatch.match(name); srm = subrunmatch.match(name) + if rm != None: + run, proc_ver, stream = rm.groups() + period_type = 'run'; period = '1' + elif srm != None: + run, period_type, period, proc_ver, stream = srm.groups() + else: + run, period_type, period, proc_ver, stream = [None]*5 + + k=open(htmlDir+'/'+subname+'/'+sp[0]+'.html','w') + k.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + k.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + k.write('<head>\n') + k.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + k.write('<title>'+name+ ' ' + subname+ ' ' + sp[0]+'</title>\n') + k.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n') +## k.write('<script type=\"text/javascript\" src=\"'+javaScriptLoc +'\"><!-- dont contract-->\n</script>\n') + k.write('</head>\n') + k.write('<body>\n') + k.write('<center>\n') + k.write('<table>\n<tr valign="top">\n') + k.write('<td width="250"><font class="DQGroup">[<a href="#" onclick="history.go(-1);return false;">Back</a>]</font></td>\n') + k.write('<td width="500"><h2>'+name + ' ' + subname+'/'+sp[0]+'</h2></td>\n') + k.write('<td width="250"></td>\n</tr>\n') + for x in range(4,len(sp)-1): + if ('inputname' in sp[x]): + inputname = sp[x+1] + k.write('<tr><td width="250"></td><td width="500">Location in ROOT file: ' + inputname + '</td>\n</tr>\n') + k.write('</table>\n') + k.write('<table cellpadding="10">\n<tr>\n') + k.write('<td>\n<table width="400">\n') + k.write('<tr><td colspan="2"><font class="Heading">Assessment Details:</font></td></tr>\n') + k.write('<tr><td> </td></tr>\n') + k.write('<tr><td align="right"><font class="DatumName">Name:</font></td>') + k.write('<td>' +sp[0] +'</td></tr>\n' ) + k.write('<tr><td align="right"><font class="DatumName">Status:</font></td>') + k.write('<td><font class="'+ sp[1] +'">'+ sp[1] + '</font></td></tr>\n') + k.write('<tr><td align="right"><font class="DatumName">Algorithm:</font></td>') + k.write('<td>'+sp[2]+'</td></tr>\n') + algorithm = sp[2] + extra=len(sp)-4 + cc=4 + cG=-1 + cR=-1 + currentHeading = '' + namecache = [] + while(extra>0): + if 'Green' in sp[cc]: + currentHeading = 'limits' + spi=sp[cc].find("Green") + limitName=sp[cc][:spi] + Green=float(sp[cc+1]) + cG=cc+1 + cc+=2 + extra-=2 + if (cG>0 and cR>0): + if(Green>Red): + writeLimitDiagram( k, limitName, "Red", "Green", sp[cR], sp[cG] ) + else: + writeLimitDiagram( k, limitName, "Green", "Red", sp[cG], sp[cR] ) + cG=-1 + cR=-1 + elif 'Red' in sp[cc]: + currentHeading = 'limits' + spi = sp[cc].find("Red") + limitName=sp[cc][:spi] + Red=float(sp[cc+1]) + cR=cc+1 + cc+=2 + extra-=2 + if (cG>0 and cR>0): + if(Green>Red): + writeLimitDiagram( k, limitName, "Red", "Green", sp[cR], sp[cG] ) + else: + writeLimitDiagram( k, limitName, "Green", "Red", sp[cG], sp[cR] ) + cG=-1 + cR=-1 + elif sp[cc]=="Results": + currentHeading = 'results' + k.write('<tr><td> </td></tr>\n') + k.write('<tr><td colspan="2"><font class="Heading">Results:</font></td></tr>\n') + k.write('<tr><td> </td></tr>\n') + cc+=2 + extra-=2 + elif sp[cc]=="Config": + currentHeading = 'config' + k.write('<tr><td> </td></tr>\n') + k.write('<tr><td colspan="2"><font class="Heading">Configuration Parameters:</font></td></tr>\n') + k.write('<tr><td> </td></tr>\n') + cc+=2 + extra-=2 + elif sp[cc]=="entries:": + currentHeading = 'nentries' + k.write('<tr><td align="right"><font class="DatumName">Num. of Entries:</font> </td>') + k.write('<td>'+sp[cc+1]+'</td></tr>\n') + cc+=2 + extra-=2 + elif sp[cc]=="Underflow:": + k.write('<tr><td align="right"><font class="DatumName">Underflow:</font> </td>') + k.write('<td>'+sp[cc+1]+'</td></tr>\n') + cc+=2 + extra-=2 + elif sp[cc]=="Overflow:": + k.write('<tr><td align="right"><font class="DatumName">Overflow:</font> </td>') + k.write('<td>'+sp[cc+1]+'</td></tr>\n') + cc+=2 + extra-=2 + elif cc<len(sp)-1 and 'inputname' not in sp[cc]: + if currentHeading == 'results': + namecache.append(sp[cc]) + if ':' not in sp[cc]: + cc+=1 + extra-=1 + continue + else: + name = ' '.join(namecache) + namecache = [] + import urllib + resultname = name.rsplit(':', 1)[0] + resultval = sp[cc+1] + if algorithm == 'RepeatAlgorithm' and resultname.endswith('|Status'): + resultval = {'1': 'Red', '2': 'Yellow', '3': 'Green'}[resultval] + if compare and run != None: + if period_type == 'run': + queryurl = 'http://atlasdqm.cern.ch:8080/dqmfquery/query?histogram=%s&result=%s&error=&stream=%s&period_type=%s&source=tier0&proc_ver=%s&low_run=%s&high_run=&low_y=&high_y=&outputtype=png' % (urllib.quote_plus(subname+'/'+sp[0]), urllib.quote_plus(resultname), stream.strip(), period_type, proc_ver, int(run)-1000) + k.write('<tr><td align="right"><b><a href="%s">%s</a>:</b></td>' % (queryurl, resultname)) + k.write('<td>'+resultval+'</td></tr>\n') + else: + queryurl1 = 'http://atlasdqm.cern.ch:8080/dqmfquery/query?histogram=%s&result=%s&error=&stream=%s&period_type=%s&source=tier0&proc_ver=%s&low_run=%s&high_run=&low_y=&high_y=&outputtype=png' % (urllib.quote_plus(subname+'/'+sp[0]), urllib.quote_plus(resultname), stream.strip(), period_type, proc_ver, int(run)-1000) + queryurl2 = 'http://atlasdqm.cern.ch:8080/dqmfquery/query?histogram=%s&result=%s&error=&stream=%s&period_type=%s&source=tier0&proc_ver=%s&low_run=%s&high_run=%s&low_y=&high_y=&outputtype=png' % (urllib.quote_plus(subname+'/'+sp[0]), urllib.quote_plus(resultname), stream.strip(), period_type, proc_ver, run, run) + k.write('<tr><td align="right"><b><a href="%s">%s</a>:</b></td>' % (queryurl1, resultname)) + k.write('<td>'+resultval+' (<a href="%s">History for this run</a>)</td></tr>\n' % queryurl2) + else: + k.write('<tr><td align="right"><b> %s: </b></td>' % (resultname,)) + k.write('<td>'+resultval+'</td></tr>\n') + else: + k.write('<tr><td align="right"><b>'+sp[cc]+' </b></td>') + k.write('<td>'+sp[cc+1]+'</td></tr>\n') + cc+=2 + extra-=2 + else: + cc+=2 + extra-=2 + k.write('</table>\n</td>\n') + if subname == '.': + k.write('<td><a href="toplevel.html"><img src="'+ sp[0] +'.png" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + else: + k.write('<td><a href="index.html"><img src="'+ sp[0] +'.png" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + k.write('</tr></table>\n') + k.write('</center>\n') + now = time.localtime() + #lastUpdate = "Last Update: "+str(now[0])+"-"+str(now[1])+"-"+str(now[2])+" "+str(now[3])+":"+str(now[4])+" UTC" + lastUpdate = "Last Update: "+time.strftime('%Y-%m-%d %H:%M %Z', now) + k.write('</br><font class=\"Note\">'+lastUpdate+'</font><br />\n') +## if(compare): +## t = htmlDir.split("/"); +## pref = "run"; +## stream = "no stream"; +## run = "no run"; +## for x in range(0,len(t)): +## if (t[x].find("run_")!=-1): +## run = t[x] +## if(x>1): +## stream = t[x-1] +## if(t[x].find("minutes10_")!=-1): +## pref =t[x] +## if(t[x].find("minutes30_")!=-1): +## pref =t[x] +## k.write('<div id=\"compareButton\">\n<br/>\n<hr/>\n') +## hisname=pref+"/"+subname+ '/' + sp[0] +## k.write('<input type=\"button\" onclick=\"compare(\''+ runlistLoc +'\',\''+hisname +'\');\" value=\"compare\" />') +## k.write('<br/>\n<hr/>\n</div>\n') +## k.write('<table>\n<tr>\n<td>\n<div id=\"streamSelect\"><!-- insert menu for Streams here-->\n</div>\n</td>') +## k.write('<td><div id=\"runSelect\"><!-- insert menu for Runs here-->\n</div>\n</td>\n</tr>\n</table>\n') +## k.write('<div id=\"secondHisto\"><!-- insert menu for Runs here-->\n</div>\n') + +## ## history button (Monica D'Onofrio, 08/21/2008) +## histname='/'+subname+ '/' + sp[0] +## # need to do a bit of tricks to point to the webpage +## # will be improved in the future (another input variable to handi.py?) +## if (htmlDir.find('./www/')>-1): +## g = htmlDir.split('./www/') +## htmlWeb='http://atlasdqm.cern.ch/tier0/FDR2c/'+g[1] +## else: +## htmlWeb='http://atlasdqm.web.cern.ch/atlasdqm/test/4/physics_Express/run' + +## try: +## history_dir = htmlWeb.split('/run')[0]+"/history_plot" +## except: +## history_dir = "http://atlasdqm.web.cern.ch/atlasdqm/test/4/physics_Express/history_plot" + +## sep = histname.split('/') +## riu = '-'.join(sep) +## if (riu.find('-->')>-1): +## hh = riu.split('-->') +## gg = '-'.join(hh) +## riu = gg + +## hisname = history_dir+'/h'+str(riu)+'.gif' +## k.write('<script type=\"text/javascript\" src=\"'+HjavaScriptLoc +'\"><!-- dont contract-->\n</script>\n') +## k.write('<input type=\"button\" onclick=\"returnHistory(\''+hisname +'\');\" value=\"History\" />') +## k.write('<br/>\n<hr/>\n</div>\n') + + k.write('</body>\n</html>\n') + k.close() + + +def makeRootFile( htmlDir, name, subname ): + k=open(htmlDir+'index.html','w') + k.write('<html>\n<frameset rows="200,*">\n') + k.write('<frame src="'+name+'AllDirs.html">\n') + if subname != "": + if subname != '.': + k.write('<frame src="'+subname+'/index.html" name="showframe"> \n') + else: + k.write('<frame src="'+subname+'/toplevel.html" name="showframe"> \n') + k.write('</frameset>\n</html> \n') + k.close() + + +def makeCSSFile( htmlDir, name, subname ): + css=open(htmlDir+'/'+subname+'/'+name+'AutomChecks.css','w') + css.write('BODY\n{\n background: #E6E6FA;\n color: #000000;\n font-family: helvetica,sans-serif;\n}\n') + css.write('H1\n{\n font-family: helvetica,sans-serif;\n font-size: x-large;\n text-align: left;\n}\n') + css.write('H2\n{\n font-family: helvetica,sans-serif;\n font-size: large;\n text-align: center;\n}\n') + css.write('H3\n{\n font-family: helvetica,sans-serif;\n font-size: medium;\n text-align: left;\n}\n') + css.write('A IMG\n{\n border: none;\n}\n') + css.write('FONT.Info\n{\n color: black;\n font-style: italic;\n}\n') + css.write('FONT.Heading\n{\n color: black;\n font-weight: bold;\n font-size: large;\n}\n') + css.write('FONT.DatumName\n{\n color: black;\n font-weight: bold;\n}\n') + css.write('FONT.Note\n{\n color: black;\n font-size: small;\n}\n') + css.write('FONT.DQGroup\n{\n font-size: small;\n}\n') + css.write('FONT.Red\n{\n color: red;\n font-weight: bold;\n}\n') + css.write('FONT.Yellow\n{\n color: #ffd700;\n font-weight: bold;\n}\n') + css.write('FONT.Green\n{\n color: green;\n font-weight: bold;\n}\n') + css.write('FONT.Disabled\n{\n color: black;\n font-weight: bold;\n}\n') + css.write('FONT.Undefined\n{\n color: gray;\n}\n') + css.write('FONT.NoCheck\n{\n color: black;\n font-weight: bold;\n}\n') + css.write('TD.Red\n{\n background-color: red;\n}\n') + css.write('TD.Yellow\n{\n background-color: #ffd700;\n}\n') + css.write('TD.Green\n{\n background-color: green;\n}\n') + css.write('TD.Disabled\n{\n background-color: black;\n}\n') + css.write('TD.Undef\n{\n background-color: gray;\n}\n') + css.write('TD.NoCheck\n{\n background-color: #E6E6FA;\n}\n') + css.write('.hintanchor\n{\n font-weight: bold; \n color: navy; \n }\n') + css.write('#hintbox{\n position:absolute; \n top: 0; \n background-color: lightyellow; \n width: 150px; \n padding: 3px; \n border:1px solid black; \n') + css.write('font:normal 15px Verdana;\n line-height:18px; \n z-index:100; \n border-right: 3px solid black; \n border-bottom: 3px solid black; \n visibility: hidden;\n }') + css.close() + + +def stringListSystemPaths( resultsFile, location ): + of = dqutils.HanOutputFile( resultsFile ) + dirsstring = of.stringListSystemPaths( location ) + of.setFile('') + return dirsstring + + +def stringAllDQAssessments( resultsFile ): + of = dqutils.HanOutputFile( resultsFile ) + total = of.stringAllDQAssessments() + of.setFile('') + return total + + +def saveAllHistograms( resultsFile, location, drawRefs, run_min_LB ): + of = dqutils.HanOutputFile( resultsFile ) + nSaved = of.saveAllHistograms( location, drawRefs, run_min_LB ) + of.setFile('') + return nSaved + + diff --git a/DataQuality/DataQualityUtils/python/hanwriter.py b/DataQuality/DataQualityUtils/python/hanwriter.py new file mode 100755 index 0000000000000000000000000000000000000000..e64ccb3d910cea5ad74fe7fe553c048077ef1488 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/hanwriter.py @@ -0,0 +1,690 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## @package DQHanConfMaker.hanwriter +# Module containing the tools to write a DQConfiguration in han format. +# @author: andrea.dotti@pi.infn.it +# @author: ponyisi@hep.uchicago.edu +# 15 August 2008 +# @note: The content of this module is inspired by the xml.dom.minidom module +""" +This module contains tools to write a DQConfiguration in han format +""" +import DQHanConfMaker +from DQConfMakerBase.Helpers import BaseException, toList +from DQConfMakerBase.DQElements import DQParameter, DQBase + +## Writing exception +# Han exception +class HanWritingError(BaseException): + """ + This exception is thrown when an error writing the han configuration is encountered + """ + def __init__(self,reason): + BaseException.__init__(self, "Cannot create the han file ("+str(reason)+")" ) + +## Generic exception +# Han exception +class HanCannotCreateConf(BaseException): + """ + This exception is thrown when an error creating the han configuration is encountered + """ + def __init__(self,reason): + BaseException.__init__(self, "Cannot create configuration ("+str(reason)+")" ) + +## Han writer base class +# Each valid element that can be written in a han file must inherit from this class +class Node(DQHanConfMaker.Node): + """ + This is the base class for each element that can be written in a valid han configuration file. + Attributes: + - subnodes : a list of Node instances + - attributes : a list of attributes associated with the node + - acceptChild : a list of Node types that can be accepted as sub nodes + - nodeType : the type of the node + - name : the name of the node + """ + ## Default constructor + # @param name: the name of the element @type name: string + def __init__(self,name=''): + """ + Create a han node + """ + self.subnodes=None + self.attributes=None + self.acceptChild= [ Node.ALGORITHM , Node.DIR , Node.DOCUMENT , Node.HIST , Node.OUTPUT , + Node.REFERENCE , Node.THRESHOLD , Node.LIMIT, Node.COMPALG ] + self.nodeType=Node.UNKNOWN + self.name=name + + ## Creates a valid han block + # @param encoding: a valid encoding identifier. @see: module codecs + # @return: the han string + def tohan(self,encoding=None): + """ + convert the object in a valid han script block + """ + return self.toprettyhan("","",encoding) + + ## Creates a valid han block + # @param indent: used as indentation @type indent: string + # @param newl: used as new line character @type newl: string + # @param encoding: a valid encoding identifier @see: module codecs + # @return: the string representing the han configuration + def toprettyhan(self,indent="\t",newl="\n",encoding=None): + """ + convert the object in a formatted han string + """ + writer=DQHanConfMaker._get_StringIO() + if encoding is not None: + import codecs + writer = codecs.lookup(encoding)[3](writer) + self.writehan(writer, "", indent, newl) + return writer.getvalue() + + + ## Writes a han block + # @param writer: the writer helper @type writer: an object supporting the write method + # @param indent: used as indentation @type indent: string + # @param addindent: used as additional indentation for each sub node @type addindent: string + # @param newl: used as newline at the end of the element @type newl: string + def writehan(self,writer,indent="",addindent="",newl=""): + """ + Converts the object in a han string and writes it in the writer object + """ + writer.write(indent+DQHanConfMaker._get_NodeType(self.nodeType)+" "+self.name) + if self.nodeType != Node.DOCUMENT: #if it is a document do not need to add { } + writer.write(" { %s" % (newl) ) + if self.attributes: + for key,attribute in self.attributes.iteritems(): + writer.write("%s %s = %s%s" % ( indent,key,attribute,newl) ) + if self.subnodes: + for node in self.subnodes: + node.writehan(writer,indent+addindent,addindent,newl) + if self.nodeType != Node.DOCUMENT: + writer.write("%s}%s"%(indent,newl)) + + ## Adds a sub node + # @param child: the node to add @type child: a Node object instance + # @raise HanCannotCreaqteConf: in case of errors + def appendChild(self,child): + """ + Add a sub node to this node + """ + try: + if child.nodeType not in self.acceptChild: + msg = " Node: "+DQHanConfMaker._get_NodeType(self.nodeType) + msg += " Cannot have a child of type:",child.nodeType + raise HanCannotCreateConf( msg ) + except: + raise HanCannotCreateConf( "Object:"+str(child)+" is not a valid Node") + if not self.subnodes: + self.subnodes = [] + self.subnodes += [ child ] + + ## Adds an attribute to the node + # @param key: the attribute identifier @type key: a string + # @param attribute: the value for the attribute @type attribute: a string + def setAttribute(self,key,attribute): + """ + The attribute identified by key is added to this node + """ + if not self.attributes: + self.attributes = {} + self.attributes[key]=attribute + ## Removes an attribute + # @param key: the attribute key @type key: a string + # @return: True on success + def removeAttribute(self,key): + """ + Removes attribute identified by key + """ + if self.attributes and self.attributes.has_key(key): + del self.attributes[key] + return True + return False + ## Gets the attribute identified by key + # @param key: an attribute identifier @type key: string + # @return: the corresponding attribute or None if not found + def getAttribute(self,key): + """ + Gets the attribute identified by the key, None if not found + """ + if self.attributes and self.attributes.has_key(key): + return self.attributes[key] + return None + ## Gets a sub-node by name and type + # @param name: the sub-node name + # @param nodetype: the sub-node type + # @return: the found Node or None if not found + def getSubNode(self,name,nodetype): + """ + Returns the sub-node identified by name and nodetype + """ + if self.subnodes: + for sn in self.subnodes: + if sn.nodeType == nodetype and sn.name == name: + return sn + return None + + def __str__(self): + return "HanNode: "+self.name+" ("+DQHanConfMaker._get_NodeType(self.nodeType)+") Attributes:"+str(self.attributes)+" SubNodes: "+str(self.subnodes) + + +## HanHistogram class +# This class represents the configuration for a histogram +class HanHistogram(Node): + """ + A han histogram element is a Node with attributes: + - the histogram name + - the algorithm to be used + - the output where to store the dq result + """ + ## Default constructor + # @param histogram: the histogram name @type histogram: a string + # @param algorithm: the algorithm element name @type algorithm: a string + # @param output: the output key @type output: a string + # @param annotations: annotations for the DQRegion @type : a dict + # @param attributes: attributes for the DQRegion @type : a dict + # @note: the histogram name is the histogram name without the directory structure. Thus a HanHistogram is usually nested in a directory tree (@see: HanDir) + def __init__(self,histogram , algorithm , annotations = {}, output=DQHanConfMaker._default_output, attributes = {}): + """ + Creates a han histogram configuration element + """ + Node.__init__(self, histogram) + self.acceptChild = [] + self.nodeType = Node.HIST + self.setAttribute('algorithm', algorithm) + self.setAttribute('output', output) + if 'Weight' in attributes: + self.setAttribute('weight', attributes['Weight'][1]) + for annotation in annotations: + self.setAttribute(annotation, annotations[annotation]) + + ## Gets the output attribute + # @return: the output attribute string + def getOutput(self): + """ + Retrieves the output attribute + """ + return self.getAttribute('output') + + ## Gets the algorithm attribute + # @return: the algorithm attribute string + def getAlgorithm(self): + """ + Retrieves the algorithm attribute + """ + return self.getAttribute('algorithm') + +## Class algorithm +# This class implements the han representation of a DQAlgorithm element +class HanAlgorithm(Node): + """ + The han representation of a DQAlgorithm + """ + ## Default constructor + # @param name: the identifier for the han algorithm @type name: a string + # @param algoname: the dqm_algorithm name @type algoname: a string + # @param libname: the library containing the algorithm @type libname: a string + # @param reference: the reference object, can be None + # @param thresholds: the thresholds objects, can be None + # @param parameters: additional parameters, can be empty. @type parameters: a list + def __init__(self,name , algoname , libname = 'libdqm_algorithms.so',reference=None,thresholds=None, + parameters = {}): + """ + Creates a han algorithm configuration element + """ + Node.__init__(self, name) + self.acceptChild = [ Node.THRESHOLD, Node.REFERENCE ] + self.nodeType = Node.ALGORITHM + self.setAttribute('name', algoname) + if libname: + self.setAttribute('libname', libname) + if reference: + self.setAttribute('reference', reference) + if thresholds: + self.setAttribute('thresholds',thresholds) + for parameter in parameters: + self.setAttribute(parameter, parameters[parameter]) + +## Class for composite algorithm +# This class implements the han representation of a DQCompositeAlgorithm +class HanCompositeAlgorithm(Node): + """ + The han representation of a CompositeAlgorithm + """ + ## Default constructor + # @param name: the identifier for the han algorithm @type name: a string + # @param algoname: the dqm_algorithm name @type algoname: a string + # @param libname: the library containing the algorithm @type libname: a string + def __init__(self,name , subalgnames=[], libnames=[]): + """ + Creates a han composite algorithm configuration element + """ + Node.__init__(self, name) + self.acceptChild = [ ] + self.nodeType = Node.COMPALG + self.setAttribute('subalgs', ','.join(subalgnames)) + self.setAttribute('libnames', ','.join(libnames)) + +## Class for reference +# This class implements the han representation of a DQReference +class HanReference(Node): + """ + The han representation of a DQReference + """ + ## Default constructor + # @param name: the identifier for the han reference @type name: a string + # @param histogramname: the histogram name @type histogramname: a string + # @param file: the filename for the reference histogram @type file: a string + def __init__(self,name,histogramname,file): + """ + Creates a han reference configuration element + """ + Node.__init__(self,name) + self.setAttribute('name',histogramname) + self.setAttribute('file', file) + self.nodeType = Node.REFERENCE + self.acceptChild = [] + +## Class for limit +# This class implements the han representation of a DQLimit +class HanLimit(Node): + """ + The han representation of a limit for a HanThreshold + """ + ## Default constructor + # @param name: the name of the limit @type name: a string + # @param warning: the value for the warning level + # @param error: the value for the error level + def __init__(self,name,warning,error): + """ + Creates a han limit object + """ + Node.__init__(self, name) + self.nodeType = Node.LIMIT + self.acceptChild=[] + self.setAttribute('warning',warning) + self.setAttribute('error', error) + +## Class for threshold +# This class implements the han representation of a DQThreshold +class HanThreshold(Node): + """ + The han representation of a DQThreshold + """ + ## Default constructor + # @param name: the threshold identifier @type name: a string + def __init__(self,name): + """ + Creates a han threshold configuration element + """ + Node.__init__(self, name) + self.acceptChild = [Node.LIMIT] + self.nodeType = Node.THRESHOLD + def addLimit(self,name,warning,error): + """ + Adds a limit to the threshold + @param name: the limits name + @param warning: the limit value for the warning level + @param error: the limit value for the error level + """ + if self.getSubNode(name, Node.LIMIT): + raise HanCannotCreateConf("The limit: "+name+" already exists for threshold: "+self.name) + limit=HanLimit(name,warning,error) + self.appendChild(limit) + +## Class for han directory +# This class implements the han directory +class HanDir(Node): + """ + Class representing a dir element + A han dir element is a Node with sub nodes of type HanDir or HanHisto + """ + ## Default constructor + # @param namne: the name of the directory @type name: a string + def __init__(self,name): + """ + Creates a han directory element + """ + Node.__init__(self, name) + self.acceptChild = [ Node.DIR , Node.HIST ] + self.nodeType = Node.DIR + + ## Adds a sub directory + # @param name: the name of the subdirectory @type name: a string + # @return: the created HanDir object + def addSubDir(self,name): + """ + Adds a subdirectory called name to the current directory and returns the newly created sub directory + """ + subdir = HanDir( name ) + self.appendChild( subdir ) + return subdir + ## Adds a histogram to the current directory + # @param histogram: the name of the histogram @type histogram: a string + # @param algorithm: the algorithm name to be used for this check @type algorithm: a string + # @param annotations: annotations for the DQRegion @type : a dict + # @param attributes: attributes for the DQRegion @type : a dict + # @param output: the output path for the result @type output: a string + # @return: the created HanHistogram object + def addHistogram(self,histogram,algorithm,annotations={},output=DQHanConfMaker._default_output,attributes={}): + """ + Adds to the directory a histogram specifying the histogram name, the algorithm and the output path. + """ + histo = HanHistogram(histogram , algorithm, annotations, output, attributes) + self.appendChild(histo) + return histo + ## Gets a sub-directory name + # @param name: the subdirectory name @type name: a string + def getSubDir(self,name): + """ + returns the sub-directory called name + """ + return self.getSubNode(name, Node.DIR) + +## Class for han output +# This class implements the han output +class HanOutput(Node): + """ + Class representing a output element + A han output element is a Node with sub nodes of type output and with the optional attribute algorithm + attribute: + - father: the HanOutput that contains this HanOutput + """ + ## Default constructor + # @param name: the output name @type name: a string + # @param algorithm: the optional algorithm name for this summary @type algorithm: summary + # @param father: the HanOutput containing this node + # @param annotations: annotations for the DQRegion @type : a dict + # @param attributes: attributes for the DQRegion @type : a dict + def __init__(self,name,algorithm=None,father=None,annotations={},attributes={}): + """ + Creates an output han element + """ + Node.__init__(self, name) + self.acceptChild = [ Node.OUTPUT ] + self.nodeType = Node.OUTPUT + if algorithm: + self.setAttribute('algorithm', algorithm) + self.father = father + if 'Weight' in attributes: + self.setAttribute('weight', attributes['Weight'][1]) + for annotation in annotations: + self.setAttribute(annotation, annotations[annotation]) + + ## Gets the algorithm + # @return: the associated algorithm name + def getAlgorithm(self): + """ + Gets the algorithm attribute + """ + if self.attributes.has_key('algorithm'): + return self.getAttribute('algorithm') + ## Adds a sub-output + # @param name: the sub output name @type name: a string + # @param algorithm: the algorithm for the sub output @type : a string + # @param annotations: annotations for the DQRegion @type : a dict + # @param attributes: attributes for the DQRegion @type : a dict + # @return: the created HanOutput object + def addOutput(self,name,algorithm,annotations,attributes): + """ + Adds a sub output element with name and algorithm + """ + subnode = HanOutput(name,algorithm,self,annotations,attributes) + self.appendChild(subnode) + return subnode + ## Creates the complete output string + # @param append: string to be appended to the name @type append: a string + # @param delimter: the delimiting characters for the string concatenation @type delimiter: a string + # @return: the complete path output string + def getOutputPath(self,append=None,delimiter="/"): + """ + Creates the complete path of this output directory + """ + name = self.name + if append: + name = name + append + if self.father: + name = self.father.getOutputPath( delimiter+name, delimiter ) + return name + +## Class document +# This class represents the han document. +# This class is a set of nodes +class Document(HanDir,HanOutput): + """ + Class representing a han document + """ + ## Default constructor + # @param top_level_algorithm: the algorithm name for the top level output + def __init__(self , top_level_algorithm='WorstCaseSummary'): + """ + Creates an empty han document with a top level output + """ + HanDir.__init__(self, '') + HanOutput.__init__(self, '') + self.nodeType = Node.DOCUMENT + self.acceptChild = [ Node.ALGORITHM , Node.DIR , Node.HIST , Node.OUTPUT , Node.REFERENCE , Node.THRESHOLD, + Node.COMPALG ] + self.root_output_level = HanOutput('top_level',top_level_algorithm) + self.appendChild(self.root_output_level) + ## Adds an output subdirectory + # @param name: the sub output name @type name: a string + # @param algorithm: the algorithm for the sub output @type : a string + # @param annotations: annotations for the DQRegion @type : a dict + # @param attributes: attributes for the DQRegion @type : a dict + # @return: the created HanOutput object + def addOutput(self,name,algorithm,annotations={},attributes={}): + """ + Adds a sub output element with name and algorithm + """ + #forward to root region + return HanOutput.addOutput(self.root_output_level, name, algorithm, annotations,attributes) + ## Gets the algorithm object + # @param name: the name of the algorithm + # @return: the algorithm associated to name + def getAlgorithm(self,name): + """ + retrieves the algorithm han object associated with name + """ + return self.getSubNode(name, Node.ALGORITHM) + ## Gets the reference object + # @param name: the reference name + # @return: the HanReference object + def getReference(self,name): + """ + retrieves the han reference associated with name + """ + return self.getSubNode(name, Node.REFERENCE) + + +## Add a DQParameter object to the HanDocument +# @param handocument: the document containing the configuration @type handocument: a HanDocument object +# @param dqparameter: the DQParameter object @type dqparameter: a DQParameter object +# @param output: the output element for the result +# @note: This function is used internally and should not be used by users of this module +def _hanAddDQParameter(handocument,dqparameter,output=DQHanConfMaker._default_output): + """ + Add a DQParameter object to a HanDocument, Doing this it creates the tree of + dir and output. + """ + try: + if dqparameter.type != "DQParameter": #This is not valid + raise HanCannotCreateConf("Object: "+str(dqmparameter)+" type does not match 'DQParameter'") + #gets the directory structure of the histogram and add it, if needed to the document + histoname = dqparameter.getInput().split('/') + theDir = handocument + for directory in histoname[0:len(histoname)-1]: # add directories to han document if needed + subdir=theDir.getSubDir(directory) + if subdir is None: + subdir=theDir.addSubDir(directory) + theDir = subdir + #prepare to build the han algorithm element + algo = dqparameter.getAlgorithm() + if algo is None: + raise Exception('DQParameter without DQAlgorithm') + dqalgoname ,dqalgolibrary = algo.id,algo.getLibraryName() + #Build the han reference, if any, associated to this DQParameter + dqrefname , dqreference , refs = "", dqparameter.getReference() ,[] + if dqreference != [None]: #References are defined + refs = '[%s]' % (','.join(_.id for _ in dqreference)) + for iref in dqreference: + ref=iref.id + #search if reference is already in the han document + if handocument.getReference( ref ) is None: + #it's not found, let's create it + refcompletename = iref.getReference() + filename = refcompletename.rpartition(':')[0] + refhistoname = refcompletename.rpartition(':')[2].lstrip('/') + hanref = HanReference( ref,histogramname=refhistoname,file=filename) + handocument.appendChild(hanref) + dqrefname = '_'+ref + #build the han thresholds + #here it's quite tricky: we have to get two sets of DQThresholds and combine them in a single + #han thresholds element + warnings = toList(dqparameter.getWarnings()) + errors = toList(dqparameter.getErrors()) + thresholds, hanthreshold, thresholdsname= '',None , '' + if ( warnings != [None]) and ( errors != [None] ): + # Found errors and warnings limits + thresholds=dqparameter.id.replace('_', '__').replace('/', '_')+'_thr' + hanthreshold=HanThreshold(thresholds) + thresholdsname=thresholds + thresholds='_'+thresholds + def getCorrespondingRed( warningname ): + for e in errors: + if e.getAttribute('Name')[1] == warningname: + return e + return None + for warning in warnings: + warningname = warning.getAttribute('Name')[1] + error = getCorrespondingRed(warningname) + if error is None: + raise HanCannotCreateConf('Cannot find corresponding error for warning names: '+warning.id) + hanthreshold.addLimit(warningname,warning.getAttribute('Value')[1],error.getAttribute('Value')[1]) + #print DQHanConfMaker._get_NodeType(hanthreshold.nodeType),hanthreshold.name + handocument.appendChild(hanthreshold) + + #build the parameter id string and key, value pairs + parameterstr = '_'.join([x.id for x in toList(dqparameter.getAlgorithmParameters()) if x != None]) + parameters = {} + for x in toList(dqparameter.getAlgorithmParameters()): + if x == None: + continue + parameters[x.getName()[1]] = x.getValue()[1][0] + #create a unique string identifying this han algorithm element so far + hanalgoname = ("%s_%s%s%s%s" % ( dqalgolibrary , dqalgoname ,dqrefname,thresholds.replace('/','_'),parameterstr) ) + #Finally add the histogram han element + theDir.addHistogram(histogram=histoname[len(histoname)-1],algorithm=hanalgoname, + annotations=dqparameter.getAllAnnotations(),output=output,attributes=dqparameter.getAllAttributes()) + #search the han algorithm in the document + if handocument.getAlgorithm( hanalgoname ) is None: + # This algorithm has never been added before in the document + node=HanAlgorithm( name = hanalgoname , algoname=dqalgoname , libname=dqalgolibrary, + reference=refs,thresholds=thresholdsname, parameters=parameters) + handocument.appendChild( node ) + # check for possible composite algorithms + compalg = algo.getCompositeAlgorithm() + if compalg != None: + node = HanCompositeAlgorithm( name=compalg.id, subalgnames = compalg.getSubAlgNames(), + libnames = compalg.getLibNames() ) + handocument.appendChild( node ) + except Exception,msg: + raise HanCannotCreateConf("Object: "+str(dqparameter)+" is not a valid DQParameter. Reason: "+str(msg)) + +## Finds the root han objects of the input collection +# @param input: the list of objects @type input: a list of DQBase objects +# @raise HanCannotCreateConf: in case of errors +# @return: the list of roots +# @note: This function is used internally and should not be used by users of this module +def _findRoots(input=[],objecttype="DQRegion"): + """ + This helper return the list of objects that are the roots in the tree represented by input. + """ + result = [] + for o in input: + try: + if o.type == objecttype: + if len(o.isReferencedBy) == 0: + result += [ o ] + except: + raise HanCannotCreateConf( "object %s is not a valid DQBase object" % o) + return result + +## Gets all DQBase objects that corresponds to the input han objects +# @param rootlist: a list of han object trees +# @return: the list of all DQBaseObjects associated to each node of the input tree +# @note: This function is used internally and should not be used by users of this module +def _findAllDQBaseObjects(rootlist): + """ + This returns all DQBase objects reachable from the rootlist as a set. + """ + import operator + def recurse(dqbase): + if dqbase == None: + return set() + if isinstance(dqbase, list): + return reduce(operator.ior, [recurse(x) for x in dqbase]) + if not isinstance(dqbase, DQBase): + raise ValueError('%s is not a valid DQBase object; this should never happen' % dqbase) + retset = set([dqbase]) + for rel in dqbase.getAllRelatedObjects(): + retset |= recurse(rel) + return retset + + topset = set() + for dqbase in toList(rootlist): + topset |= recurse(dqbase) + return list(topset) + +## Writes the han configuration to a file +# @param roots: the list of all roots of han trees +def writeHanConfiguration( filename = 'dq.han.config' , roots = []): + """ + Writes the configuration to a han file. + The configuration has to be passed as a list of roots in han configuration. + """ + configList = _findAllDQBaseObjects(roots) + # First remove the configuration elements that cannot be saved as han + for element in configList: + try: + if not DQHanConfMaker._isAceptedHanElement(element): + print "==========WARNING===========" + print "Object: "+str(element)+" does not have a valid han representation, cannot save" + print "The object is referenced by:",element.isReferencedBy + print "You may need to manually edit the configuration" + print "============================" + configList.remove(element) + except Exception,msg: + print element.isReferencedBy + raise HanCannotCreateConf("Not valid object:" +str(element)) + #Let's create the han document + doc = Document() + #Find all root regions + rootregions = _findRoots(configList) + + # Navigate through DQRegions tree and add it to the han document + def _addchild( hanfather, dqregion ,handocument): + outputalgo = dqregion.getAlgorithm() + if handocument.getAlgorithm(outputalgo.id) is None: + #Add to the document the summary maker algorithm + #summary makers do not have thresholds or parameters + #@todo: in the future extend this to make in enough general to support parameter + handocument.appendChild( HanAlgorithm( outputalgo.id , outputalgo.id, outputalgo.getLibraryName()) )#, reference, thresholds) + output = hanfather.addOutput( dqregion.id , outputalgo.id, annotations=dqregion.getAllAnnotations(), attributes=dqregion.getAllAttributes() ) + #recursively add subregions + for subregion in dqregion.getSubRegions(): + if subregion != None: + _addchild( output, subregion,doc) + #Add each DQParameter to the han document with the helper + for parameter in dqregion.getDQParameters(): + if parameter != None: + _hanAddDQParameter( handocument , parameter , output = output.getOutputPath()) + + for region in rootregions: + _addchild( doc , region , doc) + + fileout = open(filename, 'w') + print >> fileout, doc.toprettyhan(" ") + diff --git a/DataQuality/DataQualityUtils/python/historyDisplayMod.py b/DataQuality/DataQualityUtils/python/historyDisplayMod.py new file mode 100644 index 0000000000000000000000000000000000000000..26683f3b9946a608a65c843aab5f80c2716c4bd4 --- /dev/null +++ b/DataQuality/DataQualityUtils/python/historyDisplayMod.py @@ -0,0 +1,141 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + + +import string, os +import re, commands +## Needed to correct ROOT behavior; see below +CWD = os.getcwd() + +import sys +import pdb + +import ROOT +## Importing gSystem may change the current directory to one of the +## command-line arguments; chdir to original directory to have +## predictable behavior + +from ROOT import gSystem, gROOT +os.chdir(CWD) + +## Import the ROOT library for reading han results +gSystem.Load('libDataQualityUtils') +from ROOT import dqutils + +from PyCool import cool, coral +##sys.path.append('../DataQuality/DataQualityUtils/python') +from DataQualityUtils.DBInfo_Histo import * + +connectString = "sqlite://" + getWriteServer() +connectString += ";schema=" + getSchema() +connectString += ";dbname=" + getDbName() + +folderName = getFolderH() +metadata = getChannelDictH() + +def runlist( xml ): + +#initial and final run + global runsince, rununtil +# time stamps + global timesince, timeuntil + timesince = 0 + timeuntil=(2 << 31)-1 + + g=open(xml,'r') + f=open('runxml','w') + mydict={} + while 1: + line = g.readline() + if not line: + break + if line.find('<html>') > -1: + gg = line.split('/run_')[1] + nn = gg.split('</html>')[0] + try: + n = int(nn) + mydict[nn]=n + except: + n = 0 +# find last run on the list + rununtil = 0 + for elem in mydict.keys(): + if (int(elem)>rununtil): + rununtil=int(elem) +# find first run on the list + runsince = 9999999 + for elem in mydict.keys(): + if (int(elem)<runsince): + runsince=int(elem) + + for elem in mydict.keys(): + f.write(elem+"\n") + f.close() + g.close() + return runsince, timesince, rununtil, timeuntil + +import resource +def cpu_time(): + return resource.getrusage(resource.RUSAGE_SELF)[0] + +def historyDisplay( xml, htmlDirectory, dbConnectionHisto="", dqmfOflHisto="", dbTagName="", configuration=""): + + if (len(dbConnectionHisto)<1): + dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio/DQMF_08112008/14.2.10/WorkArea/python/MyCOOL_histo_FDR2c.db;dbname=OFLP200" + if (len(dqmfOflHisto)<1): dqmfOflHisto = "/GLOBAL/DETSTATUS/DQMFOFLH" + if (len(dbTagName)<1): dbTagName = "DetStatusDQMFOFLH-FDR2-02" + + runlist( xml ) + f=open('runxml','r') + histodir=htmlDirectory+"history_plot" + if( not os.access(histodir,os.F_OK) ): + try: + os.makedirs(histodir) + except os.error: + print 'Cannot create directory "' + histodir + '"; exiting.' + sys.exit(-1) + print histodir + + g=open(histodir+'/index.html','w') + g.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + g.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + g.write('<head>\n') + g.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + g.write('<font=+1> <font COLOR="green"><b> History plots </font></b></font> \n') + g.write('</head>') + g.write('<body>') + g.write('<ul>\n') + +# dump all info from COOL to a root file + comm = 'AtlCoolCopy.exe "%s" dqmfoflh_%s.root -root -folder %s -tag %s -rls %i %i -rlu %i %i ' % (dbConnectionHisto,configuration,dqmfOflHisto,dbTagName, runsince,timesince, rununtil+1,timeuntil) + print comm + commands.getstatusoutput(comm) + + of = dqutils.HistogramDataCOOL( dbConnectionHisto,dqmfOflHisto,0,0,0,0 ) + for key in metadata: + channel = metadata[key] + root_file = 'dqmfoflh_'+configuration+'.root' + if(os.access(root_file,os.F_OK) ): + of.ntupleDB(channel,key,configuration, runsince, rununtil) + else: + print ' I did not find the root file, accessing DB one by one' + of.historyDB(channel,key,dbTagName) + + sep = key.split('/') + riu = '-'.join(sep) + if (riu.find('-->')>-1): + hh = riu.split('-->') + gg = '-'.join(hh) + riu = gg + + movetoweb = 'mv c1.gif '+histodir+'/h'+str(riu)+'.gif' + makeroot = 'mv c1.root '+histodir+'/h'+str(riu)+'.root' + + commands.getstatusoutput(movetoweb) + commands.getstatusoutput(makeroot) + + g.write("<li> <a href="+"\"" +"h"+str(riu)+".gif"+"\""+ "> "+ str(key) + "</a> \n </li>") + + g.write('</ul>\n') + g.write('</body>\n</html>') + g.close() + diff --git a/DataQuality/DataQualityUtils/python/plugins/default.py b/DataQuality/DataQualityUtils/python/plugins/default.py new file mode 100644 index 0000000000000000000000000000000000000000..39ed612ab15952c7aafde6feb7acbc92277b39ba --- /dev/null +++ b/DataQuality/DataQualityUtils/python/plugins/default.py @@ -0,0 +1,115 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +# ------------------------------------------ +# | Vassilis D. Kazazakis, default.py v1.1 | +# | Plugin for the QuerryDB.py application | +# ------------------------------------------ + +import sys +import getopt +import os + +from PyCool import cool, coral + +import DBInfo + +userName = "ATLAS_COOL_READER" +password = "COOLRED4PRO" + +connectString = "oracle://" + DBInfo.getWriteServer() +connectString += ";schema=" + DBInfo.getSchema() +connectString += ";user=" + userName +connectString += ";dbname=" + DBInfo.getDbName() +connectString += ";password=" + password + +folderName = DBInfo.getFolder() + +# print connectString + +### PUBLIC INTERFACE OF PLUGIN ### + +PluginName = "DefaultPlugin" + +def usage(): + print PluginName, "options:" + print """ + --about print this help + -s/--start Starting run:lumiBlock + -e/--end Ending run:lumiBlock (defaults to the next lumiBlock) + -c/--channel Name of channel + """ + +def QuerryDB(argDict): + startTime = argDict["runStart"][0] << 32 + startTime += argDict["runStart"][1] + + if argDict["runEnd"] == None: + endTime = startTime + 1 # just till the next lumiBlock + else: + endTime = argDict["runEnd"][0] << 32 + endTime += argDict["runEnd"][1] + + if startTime >= endTime: + print >>sys.stderr, "Starting timestamp must be LESS than ending timestamp." + sys.exit(-1) + + #print argDict + + dbSvc = cool.DatabaseSvcFactory.databaseService() + try: + db = dbSvc.openDatabase(connectString) + except: + print >>sys.stderr, "Error opening database. Connection string:",connectString + sys.exit(-1) + folder = db.getFolder(folderName) + + try: + channelNum = DBInfo.getChannelDict()[argDict["channelName"]] + except KeyError: + print >>sys.stderr, "Invalid channel name:", argDict["channelName"] + sys.exit(-1) + + objIter = folder.browseObjects(startTime, endTime, cool.ChannelSelection(channelNum)) + + resultList = [] + while(objIter.hasNext()): + resultList.append(objIter.next().payload()["filename"]) + + return resultList + +def ParseArguments(arg): + argDict = dict([]) + argDict["runStart"] = (0, 0) + argDict["runEnd"] = None + argDict["channelName"] = "default" + + try: + optList, unparsed = getopt.getopt(arg, "s:e:c:", ["start=", "end=", "channel=", "about"]) + except getopt.GetoptError: + usage() + sys.exit(-1) + + for opt, arg in optList: + if opt in ("-s", "--start"): + startList = arg.split(":") + if len(startList) == 1: + startList.append("0") + for i in range(2): + if startList[i] == "": + startList[i] = "0" + argDict["runStart"] = ( int(startList[0]), int(startList[1]) ) + elif opt in ("-e", "--end"): + endList = arg.split(":") + if len(endList) == 1: + endList.append("0") + for i in range(2): + if endList[i] == "": + endList[i] = "0" + argDict["runEnd"] = ( int(endList[0]), int(endList[1]) ) + elif opt in ("-c", "--channel"): + argDict["channelName"] = arg + elif opt in ("--about"): + usage() + sys.exit(0) + + return argDict diff --git a/DataQuality/DataQualityUtils/python/plugins/pluginSkeleton.py b/DataQuality/DataQualityUtils/python/plugins/pluginSkeleton.py new file mode 100644 index 0000000000000000000000000000000000000000..8b98b72787ac86058830fa8627df3a1058dee72b --- /dev/null +++ b/DataQuality/DataQualityUtils/python/plugins/pluginSkeleton.py @@ -0,0 +1,28 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +# +-----------------------------------------------------+ +# | Vassilis D. Kazazakis, pluginSkeleton.py v1.0 | +# | Sample plugin file for the QuerryDB.py application | +# +-----------------------------------------------------+ + +### PUBLIC INTERFACE OF PLUGIN ### + +PluginName = "TestPlugin" + +def usage(): + print PluginName, "options:" + print """ + (none) + """ + +def QuerryDB(argDict): #{start=<int>, iov=<int>} + + print PluginName, ": QuerryDB(",argDict,")" + return [] # return empty list so that ExtractData does not do anything + +def ParseArguments(arg): + argDict = dict([]) + + print PluginName, ": ParseArguments(",arg,")" + + return argDict diff --git a/DataQuality/DataQualityUtils/scripts/BrowseDB.py b/DataQuality/DataQualityUtils/scripts/BrowseDB.py new file mode 100755 index 0000000000000000000000000000000000000000..3ef767525e7d6980e6236bbdd1ef011b6a73f899 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/BrowseDB.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# +-----------------------------------------------------+ +# | Vassilis D. Kazazakis - BrowseDB.py v1.0 | +# | Browses the COOL database and prints all elements | +# | For testing purposes only | +# +-----------------------------------------------------+ + +import sys + +from PyCool import cool, coral + +import DataQualityUtils.DBInfo as DBInfo + +# user & password information should be handled by each individual program +# if you have authentication file, this works + +home = os.environ.get('HOME') +os.environ['CORAL_AUTH_PATH'] = home+"/private" + +#userName = "ATLAS_COOL_READER" +#password = "*******" no need for a pwd here + +connectString = "oracle://" + DBInfo.getWriteServer() +connectString += ";schema=" + DBInfo.getSchema() +#connectString += ";user=" + userName +connectString += ";dbname=" + DBInfo.getDbName() +#connectString += ";password=" + password + +folderName = DBInfo.getFolder() + +dbSvc = cool.DatabaseSvcFactory.databaseService() + +try: + db = dbSvc.openDatabase( connectString ) +except: + print >>sys.stderr, "Database does not exist" + sys.exit(-1) + +folder = db.getFolder( folderName) +metadata = DBInfo.getChannelDict() +for key in metadata: + channel = metadata[key] + objIter = folder.browseObjects(0, cool.ValidityKeyMax, cool.ChannelSelection(channel)) + + print "Folder:", folderName + print "Channel:", channel, "Stream:", key + + while(objIter.hasNext()): + objPayload = objIter.next().payload() + print " ", objPayload["filename"], "GUID:", objPayload["guid"] + + print diff --git a/DataQuality/DataQualityUtils/scripts/CreateDB.py b/DataQuality/DataQualityUtils/scripts/CreateDB.py new file mode 100755 index 0000000000000000000000000000000000000000..588f6e1176976a1a01a748e993068fd712a9fd90 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/CreateDB.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# +-----------------------------------------------------+ +# | Vassilis D. Kazazakis, CreateDB.py v1.0 | +# | Creates the appropriate folder structure in COOL db | +# +-----------------------------------------------------+ + +import sys, os +import DataQualityUtils.DBInfo_Histo as DBInfo + +from PyCool import cool, coral + +# user & password information should be handled by each individual program +# if you have authentication file, this works + +home = os.environ.get('HOME') +os.environ['CORAL_AUTH_PATH'] = home+"/private" + +#userName = "ATLAS_COOLOFL_GLOBAL" +#password = "*********" # no need for a pwd + +dropExistingDB = False + +connectString = "sqlite://" + DBInfo.getWriteServer() +connectString += ";schema=" + DBInfo.getSchema() +#connectString += ";user=" + userName +connectString += ";dbname=" + DBInfo.getDbName() +#connectString += ";password=" + password + +if len(sys.argv) > 1 and sys.argv[1] == "createdb": + dbSvc = cool.DatabaseSvcFactory.databaseService() + db = dbSvc.createDatabase( connectString ) + +if len(sys.argv) > 1 and sys.argv[1] == "drop": + dropExistingDB = True + +folderNames = DBInfo.getFolders() + +dbSvc = cool.DatabaseSvcFactory.databaseService() +print connectString +db = dbSvc.openDatabase( connectString, False) + +for folderName in folderNames: + folderList = folderName.split("/")[1:] + folder = "" + for name in folderList[:-1]: + folder = folder + "/" + name + if db.existsFolderSet(folder): + print "Folderset", folder, "already exists." + continue + print "Creating folderset", folder, + db.createFolderSet(folder) + print "... Done" + + if dropExistingDB: + if db.existsFolder(folderName): + print "Droping", folderName, + folder = db.dropNode(folderName) + print "... Done" + if db.existsFolder(folderName): + folder = db.getFolder(folderName) + else: + spec = cool.RecordSpecification() + #spec.extend("filename", cool.StorageType.String255) + #spec.extend("guid", cool.StorageType.Int32) + spec.extend("Code", cool.StorageType.Int32) + spec.extend("deadFrac", cool.StorageType.Float) + spec.extend("Thrust",cool.StorageType.Float) + # heaven forgive me ... + if 'SHIFT' in folderName: + spec.extend("Comment",cool.StorageType.String255) + print "Creating folder", folderName, + folder = db.createFolder(folderName, spec, "", cool.FolderVersioning.MULTI_VERSION, False) + print "... Done" + + print "Creating channels." + channelDict = DBInfo.getChannelDict() + for channelName in channelDict.keys(): + try: + folder.createChannel(channelDict[channelName], channelName) + print "Created channel:", channelName + except: + print "Channel", channelName, "already exists." diff --git a/DataQuality/DataQualityUtils/scripts/CreateDB_Histo.py b/DataQuality/DataQualityUtils/scripts/CreateDB_Histo.py new file mode 100755 index 0000000000000000000000000000000000000000..11a6ea58826db03af337e08e7d57d26a502d13a3 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/CreateDB_Histo.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# +-----------------------------------------------------+ +# | Vassilis D. Kazazakis, CreateDB.py v1.0 | +# | Creates the appropriate folder structure in COOL db | +# | Update by M.D'Onofrio to include new folder | +# | for history plots | +# +-----------------------------------------------------+ + +import sys, os +from DataQualityUtils.DBInfo_Histo import * + +from PyCool import cool, coral + +# user & password information should be handled by each individual program +# if you have authentication file, this works + +home = os.environ.get('HOME') +os.environ['CORAL_AUTH_PATH'] = home+"/private" + +#userName = "ATLAS_COOLOFL_GLOBAL" +#password = "*******" #no need for a pwd + +dropExistingDB = False + +connectString = "sqlite://" + getWriteServer() +connectString += ";schema=" + getSchema() +#connectString += ";user=" + userName +connectString += ";dbname=" + getDbName() +#connectString += ";password=" + password + +if len(sys.argv) > 1 and sys.argv[1] == "createdb": + dbSvc = cool.DatabaseSvcFactory.databaseService() + db = dbSvc.createDatabase( connectString ) + +if len(sys.argv) > 1 and sys.argv[1] == "drop": + dropExistingDB = True + +folderName = getFolder() +folderNameH = getFolderH() + +dbSvc = cool.DatabaseSvcFactory.databaseService() +print connectString +db = dbSvc.openDatabase( connectString, False) + +# DQMF folder + +folderList = folderName.split("/")[1:] +folder = "" +for name in folderList[:-1]: + folder = folder + "/" + name + if db.existsFolderSet(folder): + print "Folderset", folder, "already exists." + continue + print "Creating folderset", folder, + db.createFolderSet(folder) + print "... Done" + +if dropExistingDB: + if db.existsFolder(folderName): + print "Droping", folderName, + folder = db.dropNode(folderName) + print "... Done" +if db.existsFolder(folderName): + folder = db.getFolder(folderName) +else: + spec = cool.RecordSpecification() + #spec.extend("filename", cool.StorageType.String255) + #spec.extend("guid", cool.StorageType.Int32) + spec.extend("Code", cool.StorageType.Int32) + spec.extend("deadFrac", cool.StorageType.Float) + spec.extend("Thrust",cool.StorageType.Float) + print "Creating folder", folderName, + folder = db.createFolder(folderName, spec, "", cool.FolderVersioning.MULTI_VERSION, False) + print "... Done" + +print "Creating channels." +channelDict = getChannelDict() +for channelName in channelDict.keys(): + try: + folder.createChannel(channelDict[channelName], channelName) + print "Created channel:", channelName + except: + print "Channel", channelName, "already exists." + +db.closeDatabase() + +# create defects +from DQDefects import DefectsDB +ddb = DefectsDB(connectString, create=True, read_only=False) +chandb = DefectsDB('COOLOFL_GLOBAL/COMP200') +for chan in chandb.defect_names: + ddb.create_defect(chan, chandb.get_channel_descriptions([chan])) diff --git a/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_algos.sh b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_algos.sh new file mode 100755 index 0000000000000000000000000000000000000000..489e235a4b1d9182e9fc096cf1360b170e19ad3b --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_algos.sh @@ -0,0 +1,170 @@ +#!/bin/bash --norc +# +# Author Paolo Bagnaia <paolo.bagnaia@cern.ch> +# and Elena Solfaroli Camillocci <elena.solfaroli.camillocci@cern.ch> +# [Manual in CreateMDTConfig_readme.sh] +# +# choose the weights and algos for CreateMDTConfig_config - PB 100319 v 3.1.2 +# +# ./CreateMDTConfig_algos.sh -c chamber_list_input +# [ output NOT changeable -o g_output_temp.txt] +# +usag="./CreateMDTConfig_algos.sh -c chamber_list_input" +usag=$usag" [not anymore : -u user_algos_input -o g_output_temp.txt]" +vers=3.1.2 +debug=1 +echo -en "\n\n `date +'%d-%b-%y %T'` - CreateMDTConfig_algos - vers $vers\n\n" >&2 +# +if [ $# != 2 ] ; then + echo -en "called with $# args\n$usag\n\n" >&2 + exit +fi +cinfile="./doesnot/exist" +uinfile="temp.user_algos.txt" +outfile="g_output_temp.txt" +while getopts "hc:u:" opt ; do + case "$opt" in + c) cinfile=$OPTARG ;; +# o) outfile=$OPTARG ;; +# u) uinfile=$OPTARG ;; + h | * ) echo -en "$usag\n\n" >&2 ; exit ;; + esac +done +echo -en "c-input file : $cinfile - " >&2 +echo -en "u-input file : $uinfile - " >&2 +echo -en "output file : $outfile \n" >&2 +# +if [ ! -f $cinfile ] ; then + echo -en "file $cinfile not present - exit\n" >&2 + exit +fi +if [ -f $uinfile ] ; then + echo -en "file $uinfile already present - exit\n" >&2 + exit +fi +if ( [ $outfile != "/dev/stdout" ] && [ -f $outfile ] ) ; then + echo -en "file $outfile already present - exit\n" >&2 + exit +fi +# +`dirname $BASH_SOURCE`/CreateMDTConfig_files.sh "user_algos.txt" >> $uinfile +# +exec 7> $outfile +echo -e "# created by $USER with v $vers on "`date +"%d-%b-%y %T"` >&7 +echo -en "#\n#\n" >&7 +################ +declare -ar detect_name=("-" BA BC EA EC) +declare -ar detect_nam1=("-" "Barrel_A" "Barrel_C" "Endcap_A" "Endcap_C") +function get_file_chambers() { + grep -e '^use_ ' $cinfile | cut -f 2 -d ' ' ;} +function get_chamber() { + tag1="Sector0$i_sector" + if (( $i_sector >= 10 )) ; then tag1="Sector$i_sector" ; fi + tag="${detect_nam1[$i_detect]}/$tag1" + echo $tag >&2 + get_file_chambers | grep -e "$tag" | cut -f 5-5 -d '/' ;} +function put_values() { + let item++ + lvl1[$item]=$f1 ; lvl2[$item]=$f2 ; lvl3[$item]=$f3 + lvl4[$item]=$f4 ; lvl5[$item]=$f5 ; algo[$item]=$fa ; wei[$item]=$fw ;} +# +f1="NULL" ; f2="NULL" ; f3="NULL" ; f4="NULL" ; f5="NULL" +fa="doesnotexist" +fw=-1.0 +let item=0 +################################################################################ +f1="top_level" ; put_values +f1="ALLMDTs" ; put_values +for (( i_detect=1; i_detect<=4 ; i_detect++ )) ; do # detector + if [ $debug -gt 0 ] ; then + echo -en "=== ${detect_nam1[$i_detect]}\n" >&2 + fi + f1="${detect_nam1[$i_detect]}" + f2="NULL" ; f3="NULL" ; f4="NULL" ; f5="NULL" ; put_values + f2="MDT" ; put_values + f3="AllSectors" ; put_values + for (( i_sector=1; i_sector<=16 ; i_sector++ )) ; do # sector + dir_sector='Sector0'$i_sector + if (( $i_sector >= 10 )) ; then dir_sector='Sector'$i_sector ; fi + if [ $debug -gt 0 ] ; then + echo -en "\t\t=== $dir_sector\n" >&2 + fi + f3="$dir_sector" ; f4="NULL" ; f5="NULL" ; put_values + f4="AllChambers" ; f5="NULL" ; put_values + for cham in `get_chamber` ; do # chamber + if [ $debug -gt 1 ] ; then + echo -en "\t\t\t\t cham $cham\n" >&2 + fi + f4="$cham" + f5="NULL" ; put_values + f5="Chamber" ; put_values + f5="Occupancy" ; put_values + f5="DeadStatus" ; put_values + f5="Efficiency" ; put_values + done + done + f2="MDTvsRPC" ; if [ $i_detect -gt 2 ] ; then f2="MDTvsTGC" ; fi + f3="NULL" ; f4="NULL" ; f5="NULL" ; put_values + for (( i_sector=1; i_sector<=16 ; i_sector++ )) ; do # sector + dir_sector='Sector0'$i_sector + if (( $i_sector >= 10 )) ; then dir_sector='Sector'$i_sector ; fi + if [ $debug -gt 0 ] ; then + echo -en "\t\t=== $dir_sector\n" >&2 + fi + f3="$dir_sector" ; put_values + done +done +################################################################################ +let nitem=item +echo -en "\n\n\n=== end - $nitem items - user_changes \"`wc -l $uinfile`\" :\n\n" >&2 +exec 6< $uinfile +eof=0 +for (( loop=1; loop<=1000000 ; loop++ )) ; do + if [ $eof != 0 ] ; then break ; fi + read -u 6 iden fa left + eof=$? + if [[ $iden == "" || ${iden:0:1} == "#" ]] ; then continue ; fi + fw=`echo "$left" | cut -f 1-1 -d '#' | sed -r s/' +'/''/g` + if [ $debug -gt 3 ] ; then echo -en "[$loop] $iden\n" >&2 ; fi + if [[ `echo "$iden" | cut -f 6- -d '/'` == "" ]] ; then # not enough fields + echo -en "\n\nline $loop : \"$iden\" : not enough fields specified - exit\n" >&2 + exit + fi + f1=`echo "$iden" | cut -f 2-2 -d '/'` + f2=`echo "$iden" | cut -f 3-3 -d '/'` + f3=`echo "$iden" | cut -f 4-4 -d '/'` + f4=`echo "$iden" | cut -f 5-5 -d '/'` + f5=`echo "$iden" | cut -f 6-6 -d '/'` + if [ $debug -gt 0 ] ; then + echo -en "[$loop]\t/$f1/$f2/$f3/$f4/$f5/\t$fa\t$fw" >&2 + if [ $debug -gt 1 ] ; then echo -en "\n" >&2 ; fi + fi + let nmod=0 + for (( item=1; item<=nitem ; item++ )) ; do + if [[ $f1 != '*' && $f1 != ${lvl1[$item]} ]] ; then continue ; fi + if [[ $f2 != '*' && $f2 != ${lvl2[$item]} ]] ; then continue ; fi + if [[ $f3 != '*' && $f3 != ${lvl3[$item]} ]] ; then continue ; fi + if [[ $f4 != '*' && $f4 != ${lvl4[$item]} ]] ; then continue ; fi + if [[ $f5 != '*' && $f5 != ${lvl5[$item]} ]] ; then continue ; fi + let nmod++ + if [ $debug -gt 1 ] ; then + echo -en "\t[$nmod]\t/${lvl1[$item]}/${lvl2[$item]}/" >&2 + echo -en "${lvl3[$item]}/${lvl4[$item]}/${lvl5[$item]}/\n" >&2 + fi + if [[ $fa != '=' ]] ; then algo[$item]="$fa" ; fi + if [[ $fw != '=' ]] ; then wei[$item]="$fw" ; fi + done + if [ $debug -gt 0 ] ; then echo -en "\t$nmod changes\n" >&2 ; fi +done +exec 6<&- +################################################################################ +for (( item=1; item<=nitem ; item++ )) ; do + echo -en "/${lvl1[$item]}/${lvl2[$item]}/${lvl3[$item]}/" >&7 + echo -en "${lvl4[$item]}/${lvl5[$item]}/" >&7 + echo -en " ${algo[$item]} ${wei[$item]}\n" >&7 +done +echo -en "#\n# end - `date +'%d-%b-%y %T'`\n" >&7 +exec 7>&- +echo -en "\nend - `date +'%d-%b-%y %T'`\n" >&2 +rm -f $uinfile +exit diff --git a/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_chambers.sh b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_chambers.sh new file mode 100755 index 0000000000000000000000000000000000000000..18618d23d269635daaf2544c7e2976d2fd280eb0 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_chambers.sh @@ -0,0 +1,96 @@ +#!/bin/bash --norc +# +# Author Paolo Bagnaia <paolo.bagnaia@cern.ch> +# and Elena Solfaroli Camillocci <elena.solfaroli.camillocci@cern.ch> +# [Manual in CreateMDTConfig_readme.sh] +# +# choose the chambers for CreateMDTConfig_config - PB 100319 v 3.1.2 +# +# ./CreateMDTConfig_chambers.sh -i inputfile -o outputfile +# +vers=3.1.2 +echo -en "\n\n `date +'%d-%b-%y %T'` - CreateMDTConfig_" > /dev/stderr +echo -en "chambers.sh - vers $vers\n\n" > /dev/stderr +# +if [ $# != 4 ] ; then + echo -en "./CreateMDTConfig_chambers.sh -i inputfile -o outputfile\n\n" + exit +fi +infile="./doesnot/exist" +outfile="/dev/stdout" +while getopts "hi:o:" opt ; do + case "$opt" in + i) infile=$OPTARG ;; + o) outfile=$OPTARG ;; + h | * ) echo -en "./CreateMDTConfig_chambers.sh -i inputfile"; + echo -en " -o outputfile\n\n" ; exit ;; + esac +done +echo -en "input file : $infile - output file : $outfile \n" > /dev/stderr +# +if [ "$ROOTSYS" = "" ] ; then + echo -en "run root login - exit\n" > /dev/stderr + exit +fi +if [ ! -f $infile ] ; then + echo -en "file $infile not present - exit\n" > /dev/stderr + exit +fi +if ( [ $outfile != "/dev/stdout" ] && [ -f $outfile ] ) ; then + echo -en "file $outfile already present - exit\n" > /dev/stderr + exit +fi +# +echo -e "# created by $USER with v $vers on "`date +"%d-%b-%y %T"` > $outfile +ln -s $infile ./input.temp.root +# +cat << E_O_F >> temp.scandir.C +{ +// scandir.C - V 2 PB 090611 +// root -b -n -l -q scandir.C > some_file.txt +// cat this_file | grep -e '^use_ ' | cut -f 2 -d ' ' | cut -f 5 -d '/' +// + int ncha=0; + TString s0="/MDT", s1, s2, s3, scur; + TKey *key1, *key2, *key3; + TDirectory *curdir; + TFile f("./input.temp.root"); + curdir=f.GetDirectory(s0,false,""); + TIter next1 (curdir.GetListOfKeys()); +// + while ((key1=(TKey*)next1())) { + s1=key1->GetName(); +// cout << " ===== key1 : '" << s1 << "'" << endl; + if ((s1.BeginsWith("Barrel")) || (s1.BeginsWith("Endcap"))) { + scur=s0 + "/" + s1; +// cout << " ===== Barrel '" << scur << "'" << endl; + curdir=f.GetDirectory(scur,false,""); + TIter next2 (curdir.GetListOfKeys()); + while ((key2=(TKey*)next2())) { + s2=key2->GetName(); +// cout << "\t ===== key2 : '" << s2 << "'" << endl; + if (s2.BeginsWith("Sector")) { + scur=s0 + "/" + s1 + "/" + s2; +// cout << "\t ===== Sector '" << scur << "'" << endl; + curdir=f.GetDirectory(scur,false,""); + TIter next3 (curdir.GetListOfKeys()); + while ((key3=(TKey*)next3())) { + s3=key3->GetName(); +// cout << "\t\t ===== key3 : '" << s3 << "'" << endl; + if ( s3 != "OVERVIEW") { + cout << "use_ " << scur << "/" << s3 << endl; + ncha++; + } + } + } + } + } + } +//cout << " end - chambers : " << ncha << ". ==============" << endl; +} +E_O_F +root -b -n -l -q ./temp.scandir.C >> $outfile +# +rm -f ./input.temp.root +rm -f ./temp.scandir.C +exit diff --git a/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_config.sh b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_config.sh new file mode 100755 index 0000000000000000000000000000000000000000..f3466ec96a1024c7b26b17b56281370eb0c15300 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_config.sh @@ -0,0 +1,312 @@ +#!/bin/bash --norc +# +# Author Paolo Bagnaia <paolo.bagnaia@cern.ch> +# and Elena Solfaroli Camillocci <elena.solfaroli.camillocci@cern.ch> +# [Manual in CreateMDTConfig_readme.sh] +# +# create a "config" file for DQMF - PB + ESC 100319 v 3.1.2 +# +# ./CreateMDTConfig_config.sh -i inputfile -o outputfile +# [-r refrootfile] [-d "BA BC EA EC"] [-s 1-16] [-h] +# +vers=3.1.2 +echo -en "\n\n `date +'%d-%b-%y %T'` - preconfig - vers $vers\n\n" >&2 +if [ $# -lt 1 ] ; then + echo -en "\nfor help, type \"./CreateMDTConfig_config.sh -h\"\n\n" + exit +fi +cinfile="./doesnot/exist" +outfile="/dev/stdout" +rootfile="./ref_file.root" +myfiles=`dirname $BASH_SOURCE`/CreateMDTConfig_files.sh +# +# defaults "BA" and sect 1-16, or use the "-d " and "-s " args +# +declare -ar detect_name=("-" BA BC EA EC) +declare -ar detect_nam1=("-" "Barrel_A" "Barrel_C" "Endcap_A" "Endcap_C") +declare -a detect_flag=( 0 0 0 0 0) +arg_detect=" BA " +arg_sector="1-16" +while getopts "i:o:d:r:s:h" opt ; do + case "$opt" in + i) cinfile=$OPTARG ;; + o) outfile=$OPTARG ;; + d) arg_detect=`echo "$OPTARG" | tr "[:lower:]" "[:upper:]" | sed -r s/' +'/' '/g` ;; + r) rootfile=`readlink -f $OPTARG` ;; + s) arg_sector=$OPTARG ;; + h) echo -en "./CreateMDTConfig_config.sh -i inputfile [-o outputfile] " >&2 ; + echo -en "[-r refrootfile] [-b A-C] [-d \"BA BC EA EC\"] [-h]\n\n" >&2 ; + exit ;; + *) echo -en "\nfor help, type \"./CreateMDTConfig_config.sh -h\"\n\n" ; exit ;; + esac +done + + +# +for (( i=1 ; i<=5 ; i++ )) ; do + temp=`echo "$arg_detect" | cut -d " " -f $i-$i` + if [ "$temp" != "" ] ; then + for (( j=1 ; j<=4 ; j++ )) ; do + if [ $temp == ${detect_name[$j]} ] ; then + detect_flag[$j]=1 + echo -en "$i $temp $j\n" >&2 + fi + done + fi +done +let sector_start=`echo "$arg_sector" | cut -f 1-1 -d "-"` +let sector_end=`echo "$arg_sector" | cut -f 2-2 -d "-"` +echo -en "input file : $cinfile \n" >&2 +echo -en "output file : $outfile \n" >&2 +echo -en "ref. file : $rootfile \n" >&2 +echo -en "detector : " >&2 +for (( j=1 ; j<=4 ; j++ )) ; do + if [ ${detect_flag[$j]} == 1 ] ; then + echo -en "${detect_name[$j]} " >&2 + fi +done +echo -en "\nsectors : $arg_sector \t($sector_start-$sector_end)\n" >&2 +# +if [ ! -f $cinfile ] ; then + echo -en "\nfile $cinfile not present - exit\n\n" >&2 + exit +fi +if ( [ $outfile != "/dev/stdout" ] && [ -f $outfile ] ) ; then + echo -en "\nfile $outfile already present - exit\n\n" >&2 + exit +fi +if [ ! -f $rootfile ] ; then + echo -en "\nfile $rootfile not present - exit\n\n" >&2 + exit +fi +# +function get_file_chambers() { + grep -e '^use_ ' $cinfile | cut -f 2 -d ' ' ;} +function get_detect_number() { + get_file_chambers | grep -c "${detect_nam1[$i_detect]}" ;} +function get_sector_number() { + tag1="Sector0$i_sector" + if (( $i_sector >= 10 )) ; then tag1="Sector$i_sector" ; fi + tag="${detect_nam1[$i_detect]}/$tag1" + get_file_chambers | grep -c "$tag";} +function get_chamber() { + tag1="Sector0$i_sector" + if (( $i_sector >= 10 )) ; then tag1="Sector$i_sector" ; fi + tag="${detect_nam1[$i_detect]}/$tag1" + echo $tag >&2 + get_file_chambers | grep -e "$tag" | cut -f 5-5 -d '/' ;} +# +# loops +# +exec 7> $outfile +echo -en "#######################" >&7 +echo -e " created by $USER with v $vers on "`date +"%d-%b-%y %T"` >&7 +echo -e "# Histogram Assessments" >&7 +echo -e "#######################\n\n" >&7 +echo -e "### One algorithm per histo" >&7 +# +# GLOBAL +# +echo -e "dir GLOBAL {" >&7 +echo -e " output = ALLMDTs" >&7 +echo -e " hist phi_vs_eta {" >&7 +echo -e " algorithm = GatherData" >&7 +echo -e " display = LogZ" >&7 +echo -e " }" >&7 +echo -e " hist Global_HitsPerML_Barrel {" >&7 +echo -e " algorithm = MDTOverview_Global" >&7 +echo -e " display = LogZ" >&7 +echo -e " reference = BasicRef" >&7 +echo -e " }" >&7 +echo -e " hist Global_HitsPerML_Endcap {" >&7 +echo -e " algorithm = MDTOverview_Global" >&7 +echo -e " display = LogZ" >&7 +echo -e " reference = BasicRef" >&7 +echo -e " }" >&7 +echo -e "} ### End of GLOBAL" >&7 +# +# MDT +# +echo -e "dir MDT {" >&7 +echo -e "\nloop on MDT : \n" >&2 +let loop=0 +for (( i_detect=1; i_detect<=4 ; i_detect++ )) ; do # detector +# echo -en "detector $i_detect ${detect_name[$i_detect]} ${detect_flag[$i_detect]}\n" >&2 + if [ ${detect_flag[$i_detect]} == 0 ] ; then continue ; fi + dir_detect=${detect_nam1[$i_detect]} + let n_dete=`get_detect_number` + echo -e "\t\t\t\t\t$dir_detect\t\t: $n_dete chambers" >&2 + if [[ $n_dete = 0 ]] ; then continue ; fi + echo -e " dir $dir_detect {" >&7 + echo -e " output = ${dir_detect}"'/'"MDT/AllSectors" >&7 + $myfiles "a_detect.config" | sed -r s/___dete/$dir_detect/ >&7 # <-- a + for (( i_sector=$sector_start; i_sector<=$sector_end ; i_sector++ )) ; do # sector + dir_sector='Sector0'$i_sector + if (( $i_sector >= 10 )) ; then dir_sector='Sector'$i_sector ; fi + let n_sect=`get_sector_number` + echo -e "\t\t\t\t\t$dir_detect $dir_sector \t: $n_sect chambers" >&2 + if [[ $n_sect = 0 ]] ; then continue ; fi + echo -e " dir $dir_sector {" >&7 + echo -e " output = ${dir_detect}"'/'"MDT/${dir_sector}"'/'"AllChambers" >&7 + vectype="" + for cham in `get_chamber` ; do # chamber + dir_name='MDT/'"${dir_detect}"'/'"${dir_sector}"'/'"${cham}" + let loop++ +# echo -e "$loop\t: $dir_name" >&2 # comment + $myfiles "b_chamber.config" | sed -r s/___dete/$dir_detect/ | \ + sed s/___sect/$dir_sector/g | sed s/___cham/$cham/g >&7 # <-- b + vectype=${vectype/"${cham:0:3} "}"${cham:0:3} " + done + $myfiles 'c_overview1.config' >&7 # <-- c + let ntyp=${#vectype}/4 + if ( ! [ ntyp == 0 ] ) ; then + for (( ityp=0 ; ityp<ntyp ; ityp++ )) ; do + let icha=ityp*4 + type=${vectype:$icha:3} + $myfiles "d_overview2.config" | sed -r s/___type/$type/ >&7 # <-- d + done + fi + $myfiles "e_overview3.config" >&7 # <-- e + echo -e " } ### End of $dir_sector" >&7 + done + echo -e " } ### End of $dir_detect" >&7 +done +echo -e "} ### End of MDT" >&7 +# +# MDTvsRPC and MDTvsTGC (new 2.7.4) +# +let loop=0 +rpcloop=0 +tgcloop=0 +for (( i_detect=1 ; i_detect<=4 ; i_detect++ )) ; do # detector + if ( [ $i_detect == 3 ] && [ $rpcloop == 1 ] ) ; then + echo -e "} ### End of MDTvsRPC\n" >&7 + fi + echo -en "MDTvsRPC/TGC $i_detect ${detect_name[$i_detect]} ${detect_flag[$i_detect]}\n" >&2 + if [ ${detect_flag[$i_detect]} == 0 ] ; then continue ; fi + let n_dete=`get_detect_number` + if [[ $n_dete = 0 ]] ; then continue ; fi + if ( [ $i_detect -lt 3 ] && [ $rpcloop == 0 ] ) ; then + vsname="MDTvsRPC" + rpcloop=1 + fi + if ( [ $i_detect -gt 2 ] && [ $tgcloop == 0 ] ) ; then + vsname="MDTvsTGC" + tgcloop=1 + fi + echo -e "dir $vsname {" >&7 + dir_detect=${detect_nam1[$i_detect]} + echo -e " dir $dir_detect {" >&7 + for (( i_sector=$sector_start; i_sector<=$sector_end ; i_sector++ )) ; do # sector + dir_sector='Sector0'$i_sector + if (( $i_sector >= 10 )) ; then dir_sector='Sector'$i_sector ; fi + let n_sect=`get_sector_number` + if [[ $n_sect = 0 ]] ; then continue ; fi + let loop++ + echo -e "$loop\t: $dir_sector" >&2 + $myfiles "f_trigdaq.config" | sed -r s/___dete/$dir_detect/ | \ + sed s/___sect/$dir_sector/g | sed s/MDTvs___/$vsname/g >&7 # <-- f + done + echo -e " } ### End of $dir_detect" >&7 +done +if [ $tgcloop == 1 ] ; then + echo -e "} ### End of MDTvsTGC\n" >&7 +fi +# +# output +# +################################################################################ +ginfile="g_output_temp.txt" +function put_g_values() { + declare -a vline=(`grep -e "^$2" -m 1 $ginfile`) + if [ "${vline[0]}" == "" ] ; then + echo -en "no line for tag $2\n" > /dev/stdout ; exit + fi + echo -en "$1 algorithm = ${vline[1]}\n" >&7 + echo -en "$1 weight = ${vline[2]}\n" >&7 + } +function put_g_bracket() { echo -en "$1} ### End of $2\n" >&7 ;} +function put_g_valbra() { put_g_values "$1" "$3" ; put_g_bracket "$1" "$2" ;} +# +s0="" ; s1=" " ; s2=" " ; s3=" " ; s4=" " ; s5=" " +echo -en "#############\n" >&7 +echo -en "# Output\n" >&7 +echo -en "#############\n\n" >&7 +echo -en "## The 'top_level' must always be defined\n" >&7 +echo -en "${s0}output top_level {\n" >&7 +put_g_values "$s0" "/top_level/NULL/NULL/NULL/NULL/" +# +echo -en "${s1}output ALLMDTs {\n" >&7 +put_g_valbra "$s1" "ALLMDTs" "/ALLMDTs/NULL/NULL/NULL/NULL/" +# +for (( i_detect=1; i_detect<=4 ; i_detect++ )) ; do # detector + echo -en "detector $i_detect ${detect_name[$i_detect]} ${detect_flag[$i_detect]}\n" >&2 + if [ ${detect_flag[$i_detect]} == 0 ] ; then continue ; fi + dir_detect=${detect_nam1[$i_detect]} + let n_dete=`get_detect_number` + echo -e "\t\t\t\t\t$dir_detect\t\t: $n_dete chambers" >&2 + if [[ $n_dete = 0 ]] ; then continue ; fi + echo -en "${s1}output $dir_detect {\n" >&7 + put_g_values "$s1" "/$dir_detect/NULL/NULL/NULL/NULL/" +# + echo -en "${s2}output MDT {\n" >&7 + put_g_values "$s2" "/$dir_detect/MDT/NULL/NULL/NULL/" + echo -en "${s3}output AllSectors {\n" >&7 + put_g_valbra "$s3" "AllSectors" "/$dir_detect/MDT/AllSectors/NULL/NULL/" + for (( i_sector=$sector_start; i_sector<=$sector_end ; i_sector++ )) ; do # sector + dir_sector='Sector0'$i_sector + if (( $i_sector >= 10 )) ; then dir_sector='Sector'$i_sector ; fi + let n_sect=`get_sector_number` + echo -e "\t\t\t\t\t$dir_detect $dir_sector \t: $n_sect chambers" >&2 + if [[ $n_sect = 0 ]] ; then continue ; fi + echo -en "${s3}output $dir_sector {\n" >&7 + put_g_values "$s3" "/$dir_detect/MDT/$dir_sector/NULL/NULL/" + echo -en "${s4}output AllChambers {\n" >&7 + put_g_valbra "$s4" "AllChambers" "/$dir_detect/MDT/$dir_sector/AllChambers/NULL/" + for cham in `get_chamber` ; do + echo -en "${s4}output $cham {\n" >&7 # chamber + put_g_values "$s4" "/$dir_detect/MDT/$dir_sector/$cham/NULL/" + echo -en "${s5}output Chamber {\n" >&7 # chamber + put_g_valbra "$s5" "Chamber" "/$dir_detect/MDT/$dir_sector/$cham/Chamber/" + echo -en "${s5}output Occupancy {\n" >&7 + put_g_valbra "$s5" "Occupancy" "/$dir_detect/MDT/$dir_sector/$cham/Occupancy/" + echo -en "${s5}output DeadStatus {\n" >&7 + put_g_valbra "$s5" "DeadStatus" "/$dir_detect/MDT/$dir_sector/$cham/DeadStatus/" + echo -en "${s5}output Efficiency {\n" >&7 + put_g_valbra "$s5" "Efficiency" "/$dir_detect/MDT/$dir_sector/$cham/Efficiency/" + put_g_bracket "$s4" "$cham" # End of chamber + done + put_g_bracket "$s3" "$dir_sector" # End of sector + done + put_g_bracket "$s2" "MDT" # End of MDT +# +# MDTvsXXX +# + vstag="MDTvsRPC" + if [ $i_detect -gt 2 ] ; then vstag="MDTvsTGC" ; fi + echo -en "${s2}output $vstag {\n" >&7 + put_g_values "$s2" "/$dir_detect/$vstag/NULL/NULL/NULL/" + for (( i_sector=$sector_start; i_sector<=$sector_end ; i_sector++ )) ; do # sector + dir_sector='Sector0'$i_sector + if (( $i_sector >= 10 )) ; then dir_sector='Sector'$i_sector ; fi + let n_sect=`get_sector_number` + echo -e "\t\t\t\t\t$dir_detect $dir_sector \t: $n_sect chambers" >&2 + if [[ $n_sect = 0 ]] ; then continue ; fi + echo -en "${s3}output $dir_sector {\n" >&7 + put_g_values "$s3" "/$dir_detect/$vstag/$dir_sector/NULL/NULL/" + put_g_bracket "$s3" "$dir_sector" # End of sector + done + put_g_bracket "$s2" "$vstag" # End of MDTvsXXX + put_g_bracket "$s1" "$dir_detect" # End of detector +done +put_g_bracket "$s0" "top_level" # End of top_level +################################################################################ +# +# references, algorithms, thresholds +# +$myfiles "h_refe_algo_thr.config" | sed -r s\\___refroot\\$rootfile\\ >&7 # <-- h +echo -en "\n\n `date +'%d-%b-%y %T'` - preconfig - vers $vers - end\n\n" >&2 +echo -en "#\n# end - `date +"%d-%b-%y %T"`\n" >&7 +exec 7>&- +exit +# diff --git a/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_files.sh b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_files.sh new file mode 100755 index 0000000000000000000000000000000000000000..6f8e5710ed5a0512d9a664bf49b09b2ef13950b8 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_files.sh @@ -0,0 +1,706 @@ +#!/bin/bash --norc +# +# Author Paolo Bagnaia <paolo.bagnaia@cern.ch> +# and Elena Solfaroli Camillocci <elena.solfaroli.camillocci@cern.ch> +# [Manual in CreateMDTConfig_readme.sh] +# +# a simple way to produce some standard output files - PB 100108 v 3.1.2 +# +# ./CreateMDTConfig_files.sh "file_tag" +# +# e.g. +# ./CreateMDTConfig_files.sh a_detect.config | sed -r s/___dete/"Barrel_A"/ +# +# echo "CreateMDTConfig_files.sh for \"$1\"" >> /dev/stderr +# echo "##### $1" +case "$1" in +################################################################################ +#### Region/MDT/AllSectors + 'a_detect.config') cat << E_O_F + ## DeadElements, ResidualsMean, ResidualsWidth + ## adc_Fit_, hits_perML_belowADCCUT, + ## time_Fit_ + hist all_in_dir { + algorithm = GatherData + reference = BasicRef + weight = 1 + } + hist A_HitsPerML_extra { + algorithm = MDTOverview_Station + display = LogZ + reference = BasicRef + weight = 1 + } + hist A_HitsPerML_Inner { + algorithm = MDTOverview_Station + display = LogZ + reference = BasicRef + weight = 1 + } + hist A_HitsPerML_Middle { + algorithm = MDTOverview_Station + display = LogZ + reference = BasicRef + weight = 1 + } + hist A_HitsPerML_Outer { + algorithm = MDTOverview_Station + display = LogZ + reference = BasicRef + weight = 1 + } + hist DeadElements { + algorithm = GatherData + display = Draw=(COL),Draw=(TEXT) + } + hist TubeEfficiency_extra { + algorithm = MDTpercent_under_thresh + display = LogY + weight = 0 + } + hist TubeEfficiency_Inner { + algorithm = MDTpercent_under_thresh + display = LogY + weight = 0 + } + hist TubeEfficiency_Middle { + algorithm = MDTpercent_under_thresh + display = LogY + weight = 0 + } + hist TubeEfficiency_Outer { + algorithm = MDTpercent_under_thresh + display = LogY + weight = 0 + } + hist t0PerSector_extra { + algorithm = GatherData + display = NoNorm,AxisRange(350.,700.,"Y") + } + hist t0PerSector_Inner { + algorithm = GatherData + display = NoNorm,AxisRange(350.,700.,"Y") + } + hist t0PerSector_Middle { + algorithm = GatherData + display = NoNorm,AxisRange(350.,700.,"Y") + } + hist t0PerSector_Outer { + algorithm = GatherData + display = NoNorm,AxisRange(350.,700.,"Y") + } + hist tdriftPerSector_extra { + algorithm = GatherData + display = NoNorm,AxisRange(700.,800.,"Y") + } + hist tdriftPerSector_Inner { + algorithm = GatherData + display = NoNorm,AxisRange(700.,800.,"Y") + } + hist tdriftPerSector_Middle { + algorithm = GatherData + display = NoNorm,AxisRange(700.,800.,"Y") + } + hist tdriftPerSector_Outer { + algorithm = GatherData + display = NoNorm,AxisRange(700.,800.,"Y") + } +E_O_F + exit;; +################################################################################ +#### Region/MDT/SectorXX/ChamberXXX/Chamber + 'b_chamber.config') cat << E_O_F + dir ___cham { + output = ___dete/MDT/___sect/___cham/Chamber + hist A_TDC_ML1 { + algorithm = MDTTDCspectrum + weight = 1 + } + hist A_TDC_ML2 { + algorithm = MDTTDCspectrum + weight = 1 + } + hist B_ChamberHitMultiplicity { + algorithm = MDTmultiplicity + weight = 0 + } + hist C_ADC_ML1 { + algorithm = MDTADCspectrum + weight = 1 + } + hist C_ADC_ML2 { + algorithm = MDTADCspectrum + weight = 1 + } + hist D_ChamberHitsOnSegment { + algorithm = MDTmultiplicity + weight = 0 + } + hist a_HitsPerTube { + algorithm = MDTcluster_all_chamber_tubes + weight = 0 + } + hist a_HitsPerTubeAdcCut { + algorithm = MDTcluster_all_chamber_tubes + weight = 2 + } + hist b_DeadTubeStatus { + algorithm = MDTTubeCheck + display = NoNorm,AxisRange(0.,1.1,"Y") + weight = 2 + } + hist b_EfficiencyPerTube { + algorithm = MDTTubeCheckError + display = NoNorm,AxisRange(0.,1.1,"Y") + weight = 2 + } + ## a_ChamberHitOccupancy + ## b_SegResidVsRadius + ## Residuals + ## tdc_Vs_adc_mezz_XX + hist all_in_dir { + algorithm = GatherData + reference = BasicRef + weight = 0 + } + dir Occupancy { + hist all_in_dir { ## HitsPerTube_MLX_LX + algorithm = MDTcluster + reference = BasicRef + output = ___dete/MDT/___sect/___cham/Occupancy + } + } + dir DeadStatus { + output = ___dete/MDT/___sect/___cham/DeadStatus + hist ChamberDeadTubes { + algorithm = GatherData + reference = BasicRef + } + hist all_in_dir { ## DeadTubes_MLX_LX + algorithm = MDTTubeCheck + reference = BasicRef + display = NoNorm,AxisRange(0.,1.1,"Y") + } + } + dir Efficiency { + hist all_in_dir { ## EffiPerTube_MLX_LX + algorithm = MDTTubeCheckError + reference = BasicRef + output = ___dete/MDT/___sect/___cham/Efficiency + display = NoNorm,AxisRange(0.,1.1,"Y") + } + } + } ### End of ___cham +E_O_F + exit;; +################################################################################ +#### Region/MDT/SectorXX/AllChambers + 'c_overview1.config') cat << E_O_F + dir OVERVIEW { + hist all_in_dir { + algorithm = GatherData + reference = BasicRef + } + hist TDC_AllChambers_Inner { + algorithm = MDTTDCspectrum_AllChambers + weight = 0 + } + hist TDC_AllChambers_Middle { + algorithm = MDTTDCspectrum_AllChambers + weight = 0 + } + hist TDC_AllChambers_Outer { + algorithm = MDTTDCspectrum_AllChambers + weight = 0 + } + hist TDC_AllChambers_extra { + algorithm = MDTTDCspectrum_AllChambers + weight = 0 + } + hist HitsPerML_Inner { ##MDTMLoverview + algorithm = Chi2_per_NDF + reference = BasicRef + weight = 1 + } + hist HitsPerML_Middle { ##MDTMLoverview + algorithm = Chi2_per_NDF + reference = BasicRef + weight = 1 + } + hist HitsPerML_Outer { ##MDTMLoverview + algorithm = Chi2_per_NDF + reference = BasicRef + weight = 1 + } + hist HitsPerML_extra { ##MDTMLoverview + algorithm = Chi2_per_NDF + reference = BasicRef + weight = 1 + } +E_O_F + exit;; +################################################################################ +'d_overview2.config') cat << E_O_F + hist t0PerML___type { ##t0BinsLTThre&t0BinsGTThre + algorithm = t0tdriftMDTTubeCheckError + display = NoNorm,AxisRange(350.,700.,"Y") + weight = 1 + } + hist tdriftPerML___type { ##t0BinsLTThre&t0BinsGTThre + algorithm = t0tdriftMDTTubeCheckError + display = NoNorm,AxisRange(700.,800.,"Y") + weight = 1 + } + hist HitsOnSegment___type { + algorithm = MDTmultiplicity + reference = BasicRef + weight = 0 + } +E_O_F + exit;; +################################################################################ +'e_overview3.config') cat << E_O_F + ## + hist z_HitsVsMezzanine { + algorithm = GatherData + } + } ### End of OVERVIEW +E_O_F + exit;; +################################################################################ +#### Region/MDTvsRPC or MDTvsTGC +'f_trigdaq.config') cat << E_O_F + dir ___sect { + output = ___dete/MDTvs___/___sect + hist all_in_dir { + algorithm = GatherData + #reference histo is mandatory for all_in_dir + reference = BasicRef + } + } ### End of ___sect +E_O_F + exit;; +################################################################################ +'h_refe_algo_thr.config') cat << E_O_F +############# +# References +############# + +# references need not be nested; "default" is an optional name +reference BasicRef { + file = ___refroot + + ## the next line specifies the reference histogram to have the + ## same name as the input histogram; one may also + ## provide a specific name, for example if the same reference is + ## to be used for many input histograms + name = same_name +} + + +############# +# Algorithms +############# + +algorithm MDTADCspectrum { + libname = libdqm_algorithms.so + name = MDTADCspectrum + reference = BasicRef + thresholds = MDTADCspectrumThre + # setting the parameters + thresh = 50 + MinStat = 1500 +} + +algorithm MDTpercent_under_thresh { + libname = libdqm_algorithms.so + name = MDTpercent_under_thresh + thresholds = MDTpercent_under_threshThre + # setting the parameters + Thresh = 0.95 + MinStat = 1000 +} + +algorithm MDTcluster { + libname = libdqm_algorithms.so + name = MDTcluster + reference = BasicRef + thresholds = MDTclusterThre + # setting the parameters + N_sigma = 3 + MinStat = 1000 +} + +algorithm MDTcluster_all_chamber_tubes { + libname = libdqm_algorithms.so + name = MDTcluster + reference = BasicRef + thresholds = MDTcluster_all_chamber_tubesThre + # setting the parameters + N_sigma = 3 + MinStat = 2500 +} + +algorithm MDTMLoverview { + libname = libdqm_algorithms.so + name = MDTMLoverview + reference = BasicRef + thresholds = MDTMLoverviewThre + # setting the parameters + thresh = 10 + MinStat = 2500 + ref = 1 +} + +algorithm Chi2_per_NDF { + libname = libdqm_algorithms.so + name = Chi2Test_Chi2_per_NDF + reference = BasicRef + thresholds = Chi2_per_NDFThre + # setting the parameters + MinStat = 2500 +} + +algorithm MDTChi2 { + libname = libdqm_algorithms.so + name = MDTchi2 + reference = BasicRef + thresholds = MDTchi2Thre + # setting the parameters + MinStat = 2500 +} + +algorithm MDTmultiplicity { + libname = libdqm_algorithms.so + name = MDTmultiplicity + reference = BasicRef + thresholds = MDTmultiplicityThre + # setting the parameters + MinStat = 2500 + IsolationThresh = 75 # percentage + StatisticThresh = 15 # percentage + NumberOfPeaks = 2 + FirstPeakPosition = 4 + SecondPeakPosition = 7 +# ThirdPeakPosition = -1 + UseRef = 1 #using 1 with the same run as reference it set green flag +} + +algorithm MDTOverview_Global { + libname = libdqm_algorithms.so + name = MDTOverview_Global + reference = BasicRef + thresholds = MDTOverview_GlobalThre + thresh = 10 # percentage + MinStat = 5000 + using_ref_for_flag = 0 +} + +algorithm MDTOverview_Station { + libname = libdqm_algorithms.so + name = MDTOverview_Station + reference = BasicRef + thresholds = MDTOverview_StationThre + thresh = 1 # percentage + MinStat = 5000 + using_ref_for_flag = 1 +} + +algorithm MDTTDCspectrum_AllChambers { + libname = libdqm_algorithms.so + name = MDTTDCspectrum + reference = BasicRef + thresholds = MDTTDCspectrumThre + # setting the parameters + MinStat = 5000 + chi2 = 100 +} + +algorithm MDTTDCspectrum { + libname = libdqm_algorithms.so + name = MDTTDCspectrum + reference = BasicRef + thresholds = MDTTDCspectrumThre + # setting the parameters + MinStat = 1500 + chi2 = 20 +# max_shift = 20 +} + +algorithm MDTTubeCheckError { + libname = libdqm_algorithms.so + name = MDTTubeCheckError + reference = BasicRef + thresholds = MDTTubeCheckErrThre + BinThreshold = 0.85 + nErrBin = 5 + LowStatErr = 0.2 + LowStatThre = 0.4 + ReferenceCheck = 1 #0=NO + MinStat = 10 +# xmin = 1 +# xmax = 30 +} + +algorithm MDTTubeCheck { + libname = libdqm_algorithms.so + name = MDTTubeCheck + reference = BasicRef + thresholds = MDTTubeCheckThre + BinThreshold = 0.3 + LowStatLevel = 0.5 + ReferenceCheck = 1 #0=NO + MinStat = 10 +# xmin = 1 +# xmax = 30 +} + +algorithm t0tdriftMDTTubeCheckError { + libname = libdqm_algorithms.so + name = MDTTubeCheckError + reference = BasicRef + thresholds = t0tdriftMDTTubeCheckErrThre + BinThreshold = 700 + nErrBin = 5 + ReferenceCheck = 1 #0=NO + MinStat = 5 +# xmin = 1 +# xmax = 30 +} + + +compositeAlgorithm tdriftBinsLTThre&tdriftBinsGTThre { + subalgs = Bins_LessThan_Threshold,Bins_GreaterThan_Threshold + libnames = libdqm_algorithms.so,libdqm_algorithms.so +} +algorithm tdriftBinsLTThre&tdriftBinsGTThre { + + name = tdriftBinsLTThre&tdriftBinsGTThre + + Bins_LessThan_Threshold|BinThreshold = 600 + Bins_LessThan_Threshold|thresholds = tdriftBinsLTThre + Bins_LessThan_Threshold|MinStat = 1 + Bins_GreaterThan_Threshold|BinThreshold = 800 + Bins_GreaterThan_Threshold|thresholds = tdriftBinsGTThre + Bins_GreaterThan_Threshold|MinStat = 1 +} + +compositeAlgorithm t0BinsLTThre&t0BinsGTThre { + subalgs = Bins_LessThan_Threshold,Bins_GreaterThan_Threshold + libnames = libdqm_algorithms.so,libdqm_algorithms.so +} +algorithm t0BinsLTThre&t0BinsGTThre { + + name = t0BinsLTThre&t0BinsGTThre + + Bins_LessThan_Threshold|BinThreshold = 200 + Bins_LessThan_Threshold|thresholds = t0BinsLTThre + Bins_LessThan_Threshold|MinStat = 1 + Bins_GreaterThan_Threshold|BinThreshold = 1000 + Bins_GreaterThan_Threshold|thresholds = t0BinsGTThre + Bins_GreaterThan_Threshold|MinStat = 1 +} + + +algorithm t0BinsLessThanThreshold { + libname = libdqm_algorithms.so + name = Bins_LessThan_Threshold + # setting the parameters + BinThreshold = 400 + thresholds = t0BinsLTThre + MinStat = 3 +} + +algorithm tdriftBinsLessThanThreshold { + libname = libdqm_algorithms.so + name = Bins_LessThan_Threshold + # setting the parameters + BinThreshold = 600 + thresholds = tdriftBinsLTThre + MinStat = 3 +} + +algorithm GatherData { + libname = libdqm_algorithms.so + name = GatherData + reference = BasicRef +} + +algorithm SimpleSummary { + libname = libdqm_summaries.so + name = SimpleSummary +} + +algorithm WorstCaseSummary { + libname = libdqm_summaries.so + name = WorstCaseSummary +} + +algorithm WorstCaseYellow { + libname = libdqm_summaries.so + name = WorstCaseYellow +} + + +############# +# Thresholds +############# + +thresholds MDTADCspectrumThre { + limits Limits { + warning = 0.15 + error = 0.3 + } +} + +thresholds MDTpercent_under_threshThre { + limits Percent { + warning = 95 + error = 90 + } +} + +thresholds MDTclusterThre { + limits ClusterSize { + warning = 6 + error = 80 + } +} + +thresholds MDTcluster_all_chamber_tubesThre { + limits ClusterSize { + warning = 8 + error = 100 + } +} + +thresholds MDTMLoverviewThre { + limits Limits { + warning = 1 + error = 2 + } +} + +thresholds Chi2_per_NDFThre { + limits Chi2_per_NDF { + warning = 5000 + error = 10000 + } +} +thresholds MDTchi2Thre { + limits Limits { + warning = 0.1 + error = 0.05 + } +} + +thresholds MDTmultiplicityThre { + limits PeakShift { + warning = 3 + error = 10 + } +} + +thresholds MDTOverview_StationThre { + limits Limits { + warning = 0 + error = 1 + } +} + +thresholds MDTOverview_GlobalThre { + limits Percentage { + warning = 90 + error = 90 + } +} + +thresholds MDTTDCspectrumThre { + limits Limits { + warning = 4 + error = 7 + } +} +thresholds MDTTubeCheckErrThre { + limits NBins { + warning = 0 # Max value for green + error = 1 # Value for red + } +} + +thresholds MDTTubeCheckThre { + limits NBins { + warning = 0 # Max value for green + error = 1 # Value for red + } +} + + +thresholds t0tdriftMDTTubeCheckErrThre { + limits NBins { + warning = 0 # Max value for green + error = 1 # Value for red + } +} + +thresholds t0BinsLTThre { + limits NBins { + warning = 1 + error = 2 + } +} + +thresholds tdriftBinsLTThre { + limits NBins { + warning = 1 + error = 2 + } +} + +thresholds t0BinsGTThre { + limits NBins { + warning = 1 + error = 2 + } +} + +thresholds tdriftBinsGTThre { + limits NBins { + warning = 1 + error = 2 + } +} +E_O_F + exit;; +################################################################################ +'user_algos.txt') cat << E_O_F +# +#-pb - 090208 - default +# +/*/*/*/*/*/ algo_error -777. +/*/MDT/*/*/Chamber/ WorstCaseSummary 1. +/*/MDT/*/*/Occupancy/ WorstCaseSummary 0. +/*/MDT/*/*/DeadStatus/ WorstCaseSummary 0. +/*/MDT/*/*/Efficiency/ WorstCaseSummary 0. +/*/MDT/*/*/NULL/ WorstCaseSummary 1. # chamberXX +/*/MDT/*/AllChambers/NULL/ WorstCaseSummary 1. +/*/MDT/*/NULL/NULL/ WorstCaseYellow 1. # sectorXX +/*/MDT/AllSectors/NULL/NULL/ WorstCaseSummary 1. +/*/MDT/NULL/NULL/NULL/ WorstCaseYellow 1. +/*/NULL/NULL/NULL/NULL/ WorstCaseSummary 0. # Detector +/ALLMDTs/NULL/NULL/NULL/NULL/ WorstCaseSummary 1. +/top_level/NULL/NULL/NULL/NULL/ WorstCaseSummary 1. +/*/MDTvsRPC/*/NULL/NULL/ SimpleSummary 1. +/*/MDTvsTGC/*/NULL/NULL/ SimpleSummary 1. +/*/MDTvsRPC/NULL/NULL/NULL/ WorstCaseYellow 0. +/*/MDTvsTGC/NULL/NULL/NULL/ WorstCaseYellow 0. +# end +E_O_F + exit;; +################################################################################ +*) cat << E_O_F +error error error error in CreateMDTConfig_files.sh called with argument "$1" +E_O_F + exit;; +esac +exit diff --git a/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_readme.sh b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_readme.sh new file mode 100755 index 0000000000000000000000000000000000000000..cf22ae91957f24a991fef0ce66000d5bbf5ed429 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/CreateMDTConfig_readme.sh @@ -0,0 +1,71 @@ +#!/bin/bash --norc +# +# Author Paolo Bagnaia <paolo.bagnaia@cern.ch> +# and Elena Solfaroli Camillocci <elena.solfaroli.camillocci@cern.ch> +# MANUAL +# +cat << E_O_F +# +# readme for CreateMDTConfig package - PB + ESC 100108 v 3.1.2 +# +# !!! ROOT has to be configured !!! +# +# CreateMDTConfig_chambers.sh [-i input1-root-file] [-o output1-text-file] +# CreateMDTConfig_algos.sh -c chamber_list_input +# [ output NOT changeable -o g_output_temp.txt] +# CreateMDTConfig_config.sh -i input2-text-file -o output2-text-file +# -r reference-root-file [-d "BA BC EA EC"] [-s 1-16] [-h] +# CreateMDTConfig_files.sh tag +# +# where : +# +# input2-text-file = output1-text-file +# +# if [-i file] is missing, then input from stdin +# if [-o file] is missing, then output to stdout +# if [-r file] is missing, then it searches for "ref_file.root" in the dir +# +# ================================================================= +# The "-d" option requires a list of detectors, included in " " : +# Barrel_A : BA (default, if option "d" is missing) +# Barrel_C : BC +# Endcap_A : EA +# Endcap_C : EC +# +# example to select Barrel_C and Endcap_A : -d "EA BC" +# ================================================================= +# +# Some files are now included in "CreateMDTConfig_files.sh". +# They are prototypes for the config files for a generic chamber. +# the elements "___xxx" are replaced by the specific barrel, sector +# and chamber names (e.g. "MDT/___barr/___sect/___name" becomes +# "MDT/Barrel_C/Sector07/BIL1C07". Their tags are : +# a_detect.config : detector algorithms +# b_overview.config : OVERVIEW +# c_chamber.config : chamber algorithms +# d_trigdaq.config : sector algorithms +# e_output.config : chamber output +# f_trigdaq.config : trigger and daq part +# h_refe_algo_thr.config : algorithm definitions and thresholds +# +# ================================================================ +# +# Example : +# +# !!! ROOT has to be configured !!! +# +# ./CreateMDTConfig_chambers -i Run_FDR2_Run52306_Sect1to10_effi.root -o temp.txt +# ./CreateMDTConfig_algos -c temp.txt +# ./CreateMDTConfig_config -i temp.txt -o file.config -r ref.root -d "BA EC" -s 1-16 +# rm -f temp.txt +# +# [for smart people, there is also another running mode with a "|", +# but smart people does not need examples] +# +# ================================================================ +# +# Enjoy it. +# +# Elena & Paolo +# +E_O_F diff --git a/DataQuality/DataQualityUtils/scripts/DQFileMove.py b/DataQuality/DataQualityUtils/scripts/DQFileMove.py new file mode 100755 index 0000000000000000000000000000000000000000..7de8a88c4d2be5a7501f30fe9c0007dd822090b9 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/DQFileMove.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## ***************************************************************************** +VERSION = '$Id $' +## ***************************************************************************** +def importConfiguration(modname): + from DataQualityConfigurations import getmodule + print 'getting configuration', modname + return getmodule(modname) + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "" + print "Usage: ", cmd, "<config> <prefix>" + print "" + print "This is a production utility; use TEST config for development and testing." + print "" + +if __name__ == '__main__': + import sys + from DataQualityUtils import filemovemod + + if len(sys.argv) != 3: + usage() + sys.exit(1) + + configModule = sys.argv[1] + + try: + cmod = importConfiguration(configModule) + except Exception, e: + print "Could not import configuration module \'" + configModule + "\'" + sys.exit(1) + + try: + config = cmod.dqconfig + except Exception, e: + print "Configuration object 'dqconfig' not defined in module \'" + configModule + "\'" + sys.exit(1) + + filemovemod.move_files(sys.argv[2], config) diff --git a/DataQuality/DataQualityUtils/scripts/DQHistogramMerge.py b/DataQuality/DataQualityUtils/scripts/DQHistogramMerge.py new file mode 100755 index 0000000000000000000000000000000000000000..598bd841fe422b37f6062fa63a4f192cd8a207eb --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/DQHistogramMerge.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## ***************************************************************************** +VERSION = '$Id: DQHistogramMerge.py 509709 2012-07-10 16:03:00Z vogel $' +## ***************************************************************************** + +import DataQualityUtils.DQHistogramMergeMod as mod +import sys, os + +## Get usable signal handlers +os.environ['TDAQ_ERS_NO_SIGNAL_HANDLERS'] = '1' + +def usage(): + cmd = sys.argv[0].split("/")[-1] + print "Usage: ", cmd, "<input_list_file_name> <merged_file_name> [run_post_processing] [is_incremental_merge] [output_file_compression_level] [debugLevel]" + print " run_post_processing False/True/0/1 default=0" + print " is_incremental_merge False/True/0/1 default=0" + print " output_file_compression_level see ROOT TFile doc. default=1" + print " debugLevel integer default=0" + print " You need to pass all preceding parameters to set a parameter." + +######################################## + +if __name__ == "__main__": + argc = len(sys.argv) + + if argc < 3 or argc > 7: + usage() + sys.exit(0) + + runPostProcessing = False + if argc >= 4: + runPostProcessing = sys.argv[3] in ["True", "1"] + + isIncremental = False + if argc >= 5: + isIncremental = sys.argv[4] in ["True", "1"] + + compressionLevel = 1 + if argc >= 6: + compressionLevel = int(sys.argv[5]) + + debugLevel = 0 + if argc >= 7: + debugLevel = int(sys.argv[6]) + + mod.DQHistogramMerge(sys.argv[1], sys.argv[2], runPostProcessing, isIncremental=isIncremental, compressionLevel=compressionLevel, debugLevel=debugLevel) diff --git a/DataQuality/DataQualityUtils/scripts/DQHistogramMergeRegExp.py b/DataQuality/DataQualityUtils/scripts/DQHistogramMergeRegExp.py new file mode 100755 index 0000000000000000000000000000000000000000..2386a188d48813556a6ee27aab17a2d1a0212961 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/DQHistogramMergeRegExp.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## ***************************************************************************** +VERSION = '$Id: DQHistogramMergeRegExp.py 509709 2012-07-10 16:03:00Z vogel $' +## ***************************************************************************** + +import DataQualityUtils.DQHistogramMergeMod as mod +import sys, os + +## Get usable signal handlers +os.environ['TDAQ_ERS_NO_SIGNAL_HANDLERS'] = '1' + +def usage(): + cmd = sys.argv[0].split("/")[-1] + print "Usage: ", cmd, "<input_list_file_name> <merged_file_name> [directory_regexp] [histogram_regexp] [run_post_processing [is_incremental_merge]]" + print "If you don't give any regular expressions, this script will act like DQHistogramMerge.py <infilelist> <outfile> False" + +######################################## + +if __name__ == "__main__": + argc = len(sys.argv) + + if argc < 3 or argc > 7: + usage() + sys.exit(0) + + dirRegex = ".*" + if argc >= 4: + dirRegex = sys.argv[3] + + histRegex = ".*" + if argc >= 5: + histRegex = sys.argv[4] + + runPostProcessing = False + if argc >= 6: + runPostProcessing = sys.argv[5] in ["True", "1"] + + isIncremental = False + if argc >= 7: + isIncremental = sys.argv[6] in ["True", "1"] + + mod.DQHistogramMerge(sys.argv[1], sys.argv[2], runPostProcessing, dirRegex, histRegex, isIncremental=isIncremental) diff --git a/DataQuality/DataQualityUtils/scripts/DQHistogramPrintStatistics.py b/DataQuality/DataQualityUtils/scripts/DQHistogramPrintStatistics.py new file mode 100755 index 0000000000000000000000000000000000000000..30c251ffdf79c115f83735ba83da9d34e0135102 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/DQHistogramPrintStatistics.py @@ -0,0 +1,51 @@ +#!/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## ***************************************************************************** +VERSION = '$Id: DQHistogramPrintStatistics.py 354890 2011-03-28 16:30:59Z kama $' +## ***************************************************************************** + +import os +## Needed to correct ROOT behavior; see below +CWD = os.getcwd() + +import sys + +import ROOT +## Importing gSystem may change the current directory to one of the +## command-line arguments; chdir to original directory to have +## predictable behavior +from ROOT import gSystem +os.chdir(CWD) + +## Import the ROOT library for reading han results +gSystem.Load('libDataQualityUtils') +from ROOT import dqutils + + +def DQHistogramPrintStatistics( inputFileName ): + + mf = dqutils.MonitoringFile(inputFileName) + mf.printStatistics() + + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "Usage: ", cmd, "<input_file_name>" + + + +######################################## +## main() +######################################## + +if __name__ == "__main__": + + if len(sys.argv) != 2: + usage() + sys.exit(0) + + DQHistogramPrintStatistics( sys.argv[1] ) + diff --git a/DataQuality/DataQualityUtils/scripts/DQM_Tier0Wrapper_trf.py b/DataQuality/DataQualityUtils/scripts/DQM_Tier0Wrapper_trf.py new file mode 100755 index 0000000000000000000000000000000000000000..04e67e97fac93a6fbdcfe2247857af4cf6a9bd7f --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/DQM_Tier0Wrapper_trf.py @@ -0,0 +1,429 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +######################################################################### +## +## Tier-0 combined transformation for DQM histogram merging +## and web display creation +## +## - to be run in two modes: +## 1. in regular (15min?) intervals, merges the new results with +## the statistics accumulated so far (cached on DQM AFS area) +## 2. at the end of a run, to obtain the final statistics/results +## (replaces all temporary histograms/results) +## +## - input parameter: file containing a pickled dictionary consisting of the key/value pairs +## 1) 'inputHistFiles': python list +## ['datasetname#filename1', 'datasetname#filename2', ...] (input HIST_TMP dataset + file names) +## or list of file dictionaries +## [{'lfn':'fname1', 'checksum':'cks1', 'dsn':'dsn1', 'size':sz1, 'guid':'guid1', 'events':nevts1, ...}, +## {'lfn':'fname2', 'checksum':'cks2', 'dsn':'dsn2', 'size':sz2, 'guid':'guid2', 'events':nevts2, ...}, ...] +## 2) 'outputHistFile': string 'datasetname#filename' +## (HIST output dataset name + file) +## optional parameters: +## 3) 'incrementalMode': string ('True'/'False', default: 'False') +## ('True': do incremental update of DQM webpages on top of existing statistics; +## 'False': create final DQM webpages, replace temporary ones) +## 4) 'postProcessing': string ('True'/'False', default: 'True') +## ('False': run histogram merging and DQ assessment only; +## 'True': run additional post-processing step (fitting, etc.)) +## 5) 'procNumber': int (number of processing pass, e.g. 1,2, ...) +## 6) 'runNumber': int +## 7) 'streamName': string (e.g., physics_IDCosmic, physics_Express, ...) +## 8) 'projectTag': string (e.g., data10_7TeV, TrigDisplay) +## 9) 'allowCOOLUpload': string ('True'/'False', default: 'True') +## ('True': allow upload of defects to database; +## 'False': do not upload defects to database) +## 10) 'doWebDisplay': string ('True'/'False', default: 'True') +## ('True': run the web display; +## 'False': do not run the web display) +## +## (C) N. Boelaert, L. Goossens, A. Nairz, P. Onyisi, S. Schaetzel, M. Wilson +## (April 2008 - July 2010) +## Modified for dumping resource log in case of problems +## S. Kama (March 2011) +######################################################################### + +import sys, string, commands, os.path, os, pickle, time, pprint, xmlrpclib +#sami +import hashlib + +######################################################################### + +# Utility function + +def getFileMap(fname, dsname, nevts=0) : + if os.path.isfile(fname) : + sz = os.path.getsize(fname) + map = { 'lfn': fname, + 'dataset' : dsname, + 'size' : sz, + 'events' : nevts + } + else : + map = {} + return map + +######################################################################### + +def genmd5sum(filename): + md5summer=hashlib.md5() + if os.path.isfile(filename): + try: + infil=open(filename,'rb') + while True: + fs=infil.read(8192) + if not fs: + break + md5summer.update(fs) + finally: + infil.close() + print "md5 sum of the \"%s\" is %s"%(filename,md5summer.hexdigest()) + return + +def dq_combined_trf(picklefile): + + tstart = time.time() + + print "\n##################################################################" + print "## ATLAS Tier-0 Offline DQM Processing ##" + print "##################################################################\n" + + print "\n##################################################################" + print "## STEP 1: creating file with list of root files ..." + print "##################################################################\n" + + # extract parameters from pickle file + print "Using pickled file ", picklefile, " for input parameters" + f = open(picklefile, 'r') + parmap = pickle.load(f) + f.close() + + print "\nFull Tier-0 run options:\n" + pprint.pprint(parmap) + + inputfilelist = parmap.get('inputHistFiles', []) + nfiles = len(inputfilelist) + histMergeCompressionLevel=parmap.get('histMergeCompressionLevel', 1) + histMergeDebugLevel=parmap.get('histMergeDebugLevel', 0) + + if not nfiles : # problem with job definition or reading pickle file + dt = int(time.time() - tstart) + retcode = 1 + acronym = 'TRF_NOINPUT' + txt = 'empty input file list' + reportmap = { 'prodsys': { 'trfCode': retcode, + 'trfAcronym': acronym, + 'jobOutputs': [], + 'jobInputs': [], + 'nevents': 0, + 'more': { 'num1': 0, 'num2': dt, 'txt1': txt } + } + } + + else : + histtmpflist = [] + nevts = 0 + + if isinstance(inputfilelist[0], str) : + histtmpdsname = (inputfilelist[0]).split('#')[0] + for val in inputfilelist : + histtmpflist.append(val.split('#')[1]) + + elif isinstance(inputfilelist[0], dict) : + histtmpdsname = inputfilelist[0]['dsn'] + for fdict in inputfilelist : + histtmpflist.append(fdict['lfn']) + nevt = fdict.get('events', 0) + if nevt is None: + nevt=0 + print "WARNING Can't get number of events from input pickle file" + nevts+=nevt + + f = open('hist_merge.list', 'w') + txtstr = "" + for hf in histtmpflist : + txtstr += "%s\n" % hf + f.write(txtstr) + f.close() + + cmd = "cat hist_merge.list" + (s,o) = commands.getstatusoutput(cmd) + print "\nContents of file hist_merge.list:\n" + print o + + + print "\n##################################################################" + print "## STEP 2: determining job parameters..." + print "##################################################################\n" + + # output file + histdsname = (parmap['outputHistFile']).split('#')[0] + histfile = (parmap['outputHistFile']).split('#')[1] + + # incremental mode on/off + incr = parmap.get('incrementalMode', 'False') + + # post-processing on/off + postproc = parmap.get('postProcessing', 'True') + + # database uploading on/off + allowCOOLUpload = parmap.get('allowCOOLUpload', 'True') + + # do web display + doWebDisplay = parmap.get('doWebDisplay', 'True') + + # extract info from dataset name + # AMI project name + # override if tag has been specified in parmap + try : + dqproject = histdsname.split('.')[0] + except : + dqproject = 'data_test' + dqproject = parmap.get('projectTag', dqproject) + + # run number + if parmap.has_key('runNumber') : + runnr = parmap['runNumber'] + else : + try : + runnr = int(histdsname.split('.')[1]) + except : + runnr = 1234567890 + + # stream name + if parmap.has_key('streamName') : + stream = parmap['streamName'] + else : + try : + stream = histdsname.split('.')[2] + except : + stream = 'test_dummy' + + # processing pass number + MAX_XMLRPC_TRIES = 5 + if parmap.has_key('procNumber') : + procnumber = parmap['procNumber'] + else : + n_xmlrpc_tries = 1 + while n_xmlrpc_tries <= MAX_XMLRPC_TRIES : + procnumber = 99 + try : + xmlrpcserver = xmlrpclib.ServerProxy('http://atlasdqm.cern.ch:8888') + procnumber = xmlrpcserver.get_next_proc_pass(runnr, stream, 'tier0') + break + except : + print 'Web service connection failed, attempt', n_xmlrpc_tries, 'of', MAX_XMLRPC_TRIES + n_xmlrpc_tries += 1 + if n_xmlrpc_tries <= MAX_XMLRPC_TRIES: + time.sleep(20*2**n_xmlrpc_tries) + + print "Job parameters:\n" + print " Run number: ", runnr + print " Stream name: ", stream + print " Processing pass: ", procnumber + print " Incremental mode:", incr + print " Post-processing: ", postproc + print " COOL uploads: ", allowCOOLUpload + + + print "\n##################################################################" + print "## STEP 3: running histogram merging procedure ..." + print "##################################################################\n" + + # environment setting + os.environ['DQPRODUCTION'] = '1' + print "Setting env variable DQPRODUCTION to %s\n" % os.environ['DQPRODUCTION'] + os.environ['COOLUPLOADS'] = '1' if allowCOOLUpload == 'True' else '0' + print "Setting env variable COOLUPLOADS to %s\n" % os.environ['COOLUPLOADS'] + + if postproc == 'True' : + if incr == 'True': + cmd = "python -u `which DQHistogramMerge.py` hist_merge.list %s 1 1 %d %d " % (histfile,histMergeCompressionLevel,histMergeDebugLevel) + else: + cmd = "python -u `which DQHistogramMerge.py` hist_merge.list %s 1 0 %d %d" % (histfile,histMergeCompressionLevel,histMergeDebugLevel) + else : + cmd = "python -u `which DQHistogramMerge.py` hist_merge.list %s 0 0 %d %d" % (histfile,histMergeCompressionLevel,histMergeDebugLevel) + + print "Histogram merging command:\n" + print cmd + print "\n##################################################################\n" + + print "## ... logfile from DQHistogramMerge.py: " + print "--------------------------------------------------------------------------------" + # execute command + retcode1 = os.system(cmd) + print "--------------------------------------------------------------------------------" + t1 = time.time() + dt1 = int(t1 - tstart) + + print "\n## DQHistogramMerge.py finished with retcode = %s" % retcode1 + print "## ... elapsed time: ", dt1, " sec" + + if retcode1 == 0 : + if postproc == 'True' and incr == 'False': + print "\n##################################################################" + print "## STEP 3b: copying postprocessing output to AFS ..." + print "##################################################################\n" + + cmd = "python -u `which DQFileMove.py` %s %s_%s_%s" % (dqproject, runnr, stream, procnumber) + + print "File move command:\n" + print cmd + print "\n##################################################################\n" + + print "## ... logfile from DQFileMove.py: " + print "--------------------------------------------------------------------------------" + # execute command + retcode1b = os.system(cmd) + print "--------------------------------------------------------------------------------" + t1b = time.time() + dt1b = int(t1b - t1) + t1 = t1b + + print "\n## DQFileMove.py finished with retcode = %s" % retcode1b + print "## ... elapsed time: ", dt1b, " sec" + + if doWebDisplay == 'True': + print "\n##################################################################" + print "## STEP 4: running web-display creation procedure ..." + print "##################################################################\n" + + cmd = "python -u `which DQWebDisplay.py` %s %s %s %s stream=%s" % (histfile, dqproject, procnumber, incr, stream) + + print "Web display creation command:\n" + print cmd + print "\n##################################################################\n" + + print "## ... logfile from DQWebDisplay.py: " + print "--------------------------------------------------------------------------------" + # execute command + retcode2 = os.system(cmd) + print 'DO NOT REPORT "Error in TH1: cannot merge histograms" ERRORS! THESE ARE IRRELEVANT!' + print "--------------------------------------------------------------------------------" + t2 = time.time() + dt2 = int(t2 - t1) + + print "\n## DQWebDisplay.py finished with retcode = %s" % retcode2 + print "## ... elapsed time: ", dt2, " sec" + else: + print "\n##################################################################" + print "## WEB DISPLAY CREATION SKIPPED BY USER REQUEST" + print "##################################################################\n" + retcode2 = 0 + dt2 = 0 + + print "\n##################################################################" + print "## STEP 5: finishing the job ..." + print "##################################################################\n" + + # assemble report gpickle file + outfiles = [] + infiles = [] + + retcode = 0 + acronym = 'OK' + txt = 'trf finished OK' + + # get info for report gpickle file + if retcode1 == 0 : + dt = dt1 + if (retcode2 >> 8) in (0, 5) : + # if success, or if unable to acquire cache lock + histmap = getFileMap(histfile, histdsname, nevts=nevts) + outfiles = [histmap] + dt += dt2 + else : + txt = 'DQWebDisplay.py execution problem' + print "ERROR: DQWebDisplay.py execution problem!" + retcode = retcode2 + acronym = 'TRF_DQMDISPLAY_EXE' + try: + infilelist=open('hist_merge.list','r') + for infname in infilelist: + genmd5sum(infname.rstrip(os.linesep)) + finally: + infilelist.close() + genmd5sum(histfile) + else : + print "ERROR: DQHistogramMerge.py execution problem!" + retcode = retcode1 + acronym = 'TRF_DQMHISTMERGE_EXE' + dt = 0 + txt = 'DQHistogramMerge.py execution problem' + try: + infilelist=open('hist_merge.list','r') + for infname in infilelist: + genmd5sum(infname.rstrip(os.linesep)) + finally: + infilelist.close() + genmd5sum(histfile) + DQResFile="DQResourceUtilization.txt" + if os.path.exists(DQResFile): + print "dumping resource utilization log" + with open(DQResFile) as resfile: + for resline in resfile: + print resline, + + # assemble job report map + reportmap = { 'prodsys': { 'trfCode': retcode, + 'trfAcronym': acronym, + 'jobOutputs': outfiles, + 'jobInputs': infiles, + 'nevents': int(nevts), + 'more': { 'num1': int(nevts), 'num2': int(dt), 'txt1': txt } + } + } + + # pickle report map + f = open('jobReport.gpickle', 'w') + pickle.dump(reportmap, f) + f.close() + + print "\n## ... job finished with retcode : %s" % reportmap['prodsys']['trfCode'] + print "## ... error acronym: ", reportmap['prodsys']['trfAcronym'] + print "## ... elapsed time: ", reportmap['prodsys']['more']['num2'], "sec" + print "##" + print "##################################################################" + print "## End of job." + print "##################################################################\n" + + +######################################## +## main() +######################################## + +if __name__ == "__main__": + + if (len(sys.argv) != 2) and (not sys.argv[1].startswith('--argdict=')) : + print "Input format wrong --- use " + print " --argdict=<pickled-dictionary containing input info> " + print " with key/value pairs: " + print " 1) 'inputHistFiles': python list " + print " ['datasetname#filename1', 'datasetname#filename2',...] (input dataset + file names) " + print " or list of file dictionaries " + print " [{'lfn':'fname1', 'checksum':'cks1', 'dsn':'dsn1', 'size':sz1, 'guid':'guid1', 'events':nevts1, ...}, " + print " {'lfn':'fname2', 'checksum':'cks2', 'dsn':'dsn2', 'size':sz2, 'guid':'guid2', 'events':nevts2, ...}, ...] " + print " 2) 'outputHistFile': string 'datasetname#filename' " + print " (HIST output dataset name + file) " + print " optional parameters: " + print " 3) 'incrementalMode': string ('True'/'False') " + print " ('True': do incremental update of DQM webpages on top of existing statistics; " + print " 'False': create final DQM webpages, replace temporary ones) " + print " 4) 'postProcessing': string ('True'/'False', default: 'True') " + print " ('False': run histogram merging and DQ assessment only; " + print " 'True': run additional post-processing step (fitting, etc.)) " + print " 5) 'procNumber': int (number of processing pass, e.g. 1,2, ...) " + print " 6) 'runNumber': int " + print " 7) 'streamName': string (e.g., physics_IDCosmic, physics_Express, ...) " + print " 8) 'projectTag': string (e.g., data10_7TeV, TrigDisplay)" + print " 9) 'allowCOOLUpload': string ('True'/'False', default: 'True')" + print " ('True': allow upload of defects to database; " + print " 'False': do not upload defects to database)" + sys.exit(-1) + + else : + picklefile = sys.argv[1][len('--argdict='):] + dq_combined_trf(picklefile) + diff --git a/DataQuality/DataQualityUtils/scripts/DQPostProcessTest.py b/DataQuality/DataQualityUtils/scripts/DQPostProcessTest.py new file mode 100644 index 0000000000000000000000000000000000000000..6ab86563d9cbe16372493e3d279b1e741cf4f1e2 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/DQPostProcessTest.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## ***************************************************************************** +VERSION = '$Id: DQPostProcessTest.py 514510 2012-08-22 16:02:43Z vogel $' +## ***************************************************************************** + +#import DataQualityUtils.DQHistogramMergeMod as mod + +import sys + +import ROOT +from ROOT import gROOT +gROOT.SetBatch(True) + + + +from ROOT import gSystem +gSystem.Load('libDataQualityUtils') +from ROOT import dqutils + + +mf = dqutils.MonitoringFile() + +def rpc_create(dummy): + from DataQualityUtils.createRpcFolders import (createRPCDQMFDB, + createRPCConditionDB) + createRPCDQMFDB() + createRPCConditionDB() + +def mdt_create(dummy): + from DataQualityUtils.createMdtFolders import (createMDTConditionDBDead, + createMDTConditionDBNoisy) + createMDTConditionDBDead() + createMDTConditionDBNoisy() + +########################################## +##Comment Out Those You do not wish to run +########################################## + +outFile = sys.argv[1] + +isIncremental=False +if len(sys.argv) == 3: + if sys.argv[2] == "True" or sys.argv[2] == "1": + isIncremental = True + +print '==================== Starting first round of checks ====================\n\n' + +mf.fitMergedFile_IDPerfMonManager(outFile, isIncremental) +mf.fitMergedFile_DiMuMonManager(outFile, isIncremental) +mf.fitMergedFile_IDAlignMonManager(outFile, isIncremental) +rpc_create(outFile) +mf.RPCPostProcess(outFile, isIncremental) +mdt_create(outFile) +mf.CSCPostProcess(outFile, isIncremental) +mf.MDTPostProcess(outFile, isIncremental) +mf.TGCPostProcess(outFile, isIncremental) +mf.MDTvsTGCPostProcess(outFile, isIncremental) +mf.HLTEgammaPostProcess(outFile, isIncremental) +mf.HLTMuonPostProcess(outFile, isIncremental) +mf.HLTTauPostProcess(outFile, isIncremental) +mf.HLTMETPostProcess(outFile, isIncremental) +mf.HLTJetPostProcess(outFile, isIncremental) +mf.MuonTrkPhys(outFile, isIncremental) +mf.BJetTaggingPostProcess(outFile, isIncremental) +mf.L1CaloPostProcess(outFile, isIncremental) +mf.SCTPostProcess(outFile, isIncremental) +mf.VxMon_move(outFile, isIncremental) # may print a harmless error message about write access to EOS + +print '\n\n====================== First round of checks are completed=============' +print '==================== Starting second round ====================\n\n' + +mf.fitMergedFile_IDPerfMonManager(outFile, isIncremental) +mf.fitMergedFile_DiMuMonManager(outFile, isIncremental) +mf.fitMergedFile_IDAlignMonManager(outFile, isIncremental) +rpc_create(outFile) +mf.RPCPostProcess(outFile, isIncremental) +mdt_create(outFile) +mf.CSCPostProcess(outFile, isIncremental) +mf.MDTPostProcess(outFile, isIncremental) +mf.TGCPostProcess(outFile, isIncremental) +mf.MDTvsTGCPostProcess(outFile, isIncremental) +mf.HLTEgammaPostProcess(outFile, isIncremental) +mf.HLTMuonPostProcess(outFile, isIncremental) +mf.HLTTauPostProcess(outFile, isIncremental) +mf.HLTMETPostProcess(outFile, isIncremental) +mf.HLTJetPostProcess(outFile, isIncremental) +mf.MuonTrkPhys(outFile, isIncremental) +mf.BJetTaggingPostProcess(outFile, isIncremental) +mf.L1CaloPostProcess(outFile, isIncremental) +mf.SCTPostProcess(outFile, isIncremental) +mf.VxMon_move(outFile, isIncremental) # may print a harmless error message about write access to EOS + +print '\n\n====================== Second round of checks are completed=============' +print 'Postprocessing code should run in T0 without crashes ' diff --git a/DataQuality/DataQualityUtils/scripts/DQWebDisplay.py b/DataQuality/DataQualityUtils/scripts/DQWebDisplay.py new file mode 100755 index 0000000000000000000000000000000000000000..a308f4176f3703f7593eb039db3489c881b51dd2 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/DQWebDisplay.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# -*- coding: utf-8 -*- + +## ***************************************************************************** +VERSION = '$Id: DQWebDisplay.py 587229 2014-03-11 23:26:39Z ponyisi $' +## ***************************************************************************** + +import os + +## Needed to correct ROOT behavior; see below +CWD = os.getcwd() +os.chdir(CWD) + +## Get usable signal handlers +os.environ['TDAQ_ERS_NO_SIGNAL_HANDLERS'] = '1' + +import sys +sys.argv.append( '-b-' ) +import ROOT +## Importing gSystem may change the current directory to one of the +## command-line arguments; chdir to original directory to have +## predictable behavior +from ROOT import gSystem +os.chdir(CWD) + +from DataQualityUtils.DQWebDisplayMod import DQWebDisplay + +def importConfiguration(modname): + from DataQualityConfigurations import getmodule + print 'getting configuration', modname + return getmodule(modname) + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "" + print "Usage: ", cmd, "<data_file> <config> <processing_version> [run_accumulating [conditions_string]]" + print "" + print "This is a production utility; use TEST config for development and testing." + print "" + print "Processing version is an integer, starting from 1 (not 0)" + print "" + +if __name__ == "__main__": + if len(sys.argv) < 4 or len(sys.argv) > 7: + usage() + sys.exit(0) + + inputFile = sys.argv[1] # data file + runAccumulating = False + if len(sys.argv) in (6,7): + if sys.argv[4] == "True" or sys.argv[4] == "1": + runAccumulating = True + + if len(sys.argv) == 7: + ROOT.gSystem.Load('libDataQualityInterfaces') + ROOT.dqi.ConditionsSingleton.getInstance().setCondition(sys.argv[5]) + + configModule = "" + + if sys.argv[2] == "TEST": + configModule = "TestDisplay" + elif sys.argv[2] == "RTT": + configModule = "RTTDisplay" + elif sys.argv[2] == "TCT": + configModule = "TCTDisplay" + elif sys.argv[2] == "FDR1": + configModule = "fdr08_run1" + elif sys.argv[2] == "FDR2" or sys.argv[2] == "FDR2a" or sys.argv[2] == "FDR2b" or sys.argv[2] == "FDR2c": + configModule = "fdr08_run2" + elif sys.argv[2] == "Cosmics08": + configModule = "data08_cos" + elif sys.argv[2] == "SingleBeam08": + configModule = "data08_1beam" + else: + configModule = sys.argv[2] + + try: + cmod = importConfiguration(configModule) + except Exception, e: + print "Could not import configuration module \'" + configModule + "\'" + sys.exit(1) + + try: + config = cmod.dqconfig + except Exception, e: + print "Configuration object 'dqconfig' not defined in module \'" + configModule + "\'" + sys.exit(1) + + + DQWebDisplay( inputFile, runAccumulating, config ) + diff --git a/DataQuality/DataQualityUtils/scripts/GetHistogram.py b/DataQuality/DataQualityUtils/scripts/GetHistogram.py new file mode 100755 index 0000000000000000000000000000000000000000..f53d6d7c4bc776b61fb7ef45937f9d86b06ec22a --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/GetHistogram.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# +---------------------------------------------+ +# | Vassilis D. Kazazakis, GetHistogram.py v1.0 | +# | Extracts histograms from ROOT files | +# | Interface used by QuerryDB.py application | +# +---------------------------------------------+ + +import DataQualityUtils.DQGetHistogramMod as mod + + +def usage(): + print "Usage:", sys.argv[0] , "[options]" + print """ + -i/--input filename Input ROOT file + -o/--output filename Output ROOT file + -n/--name histogram Name of the histogram to extract + -d/--directory directory[:flag] Name of the directory from which to extract all[or flagged] histograms + -f/--flag flag Flag of the histograms to extract (shift/expert/etc) + """ + + +if __name__ == "__main__": + input = output = None + nameList = [] + try: + optlist, unparsed = getopt.getopt(sys.argv[1:], + "i:o:n:d:f:", + ["input=", "output=", "name=", "directory=", "flag="]) + except getopt.GetoptError: + usage() + sys.exit(-1) + + if len(optlist) == 0: + usage() + sys.exit(0) + + if len(unparsed) != 0: + print "Extra arguments", unparsed, "not used." + + for opt, arg in optlist: + if opt in ("-i", "--input"): + input = arg + elif opt in ("-o", "--output"): + output = arg + elif opt in ("-n", "--name"): + nameList.append(arg) + elif opt in ("-d", "--directory"): + tmpList = arg.split(":") + if len(tmpList) < 2: + tmpList.append("") + if not tmpList[0].endswith('/'): + if tmpList[1] != "": + tmpList[1] = ":" + tmpList[1] + arg = tmpList[0] + "/" + tmpList[1] + nameList.append(arg) + elif opt in ("-f", "--flag"): + nameList.append(":" + arg) + + if None in (input, output): + print >>sys.stderr, "Error: Must define input/output files." + usage() + sys.exit(-1) + if len(nameList) == 0: + print >>sys.stderr, "Error: Must give at least one histogram or directory name." + usage() + sys.exit(-1) + mod.GetHistogram(input, output, nameList) diff --git a/DataQuality/DataQualityUtils/scripts/QuerryDB.py b/DataQuality/DataQualityUtils/scripts/QuerryDB.py new file mode 100755 index 0000000000000000000000000000000000000000..8f76680837da641d08b2bed2d8b22a29c335aff5 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/QuerryDB.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# +-----------------------------------------------------------------------------+ +# | Vassilis D. Kazazakis, QuerryDB.py v1.0 | +# | Uses plugins to querry the cool database for the retrieval of ROOT files. | +# | Then, it extracts the requested histograms. | +# +-----------------------------------------------------------------------------+ + +import sys +import getopt +import os + +from PyCool import cool, coral +import DataQualityUtils.DQGetHistogramMod as mod + +CurrentPlugin = "DefaultPlugin" +PluginDict = dict([]) + +def usage(): + print "Usage:", sys.argv[0], "[options] -- [plugin-options]" + print """ + Options: + --about print this help + -d/--data {histogram, directory[:flag]} path name of histogram or directory in ROOT file (flag should only be used in case of directory) + -f/--flag flag all histograms with specified flag will be retrieved + + -o/--outputdir dir directory to store output files (default value = "./") + -p/--pattern pattern output filename pattern (default value = "querryOutput") + Final output form: outputdir/pattern<fileNum>.root + + -u/--useplugin plugin name of the plugin to use + -s/--plugindir directory directory path in which to search for plugins + -l/--list list all available plugins + """ + try: + PluginDict[CurrentPlugin].usage() + except KeyError: + pass + +def loadPlugins(pluginDirList): + sys.path.extend(pluginDirList) + + pluginFileList = [] + for pluginDir in pluginDirList: + pluginFileList.extend(os.listdir(pluginDir)) + + for file in pluginFileList[:]: + if not file.endswith(".py"): + pluginFileList.remove(file) + + for file in pluginFileList: + name = file[:len(file)-3] + try: + plugin = __import__(name) + PluginDict[plugin.PluginName] = plugin + #print plugin.PluginName, "loaded." + except: + #print "Loading of", name, "failed." + #raise + pass + +def listPlugins(): + print "Loaded plugins:" + for name, plugin in PluginDict.iteritems(): + print "\t ", name + +def ExtractData(fileList, dataList, pattern): +# print "ExtractData(",fileList,",",dataList,",",pattern,")" + + fileNum = 0 + for file in fileList: + print "Getting histograms from", file, "...", + outputFile = pattern + str(fileNum) + ".root" + if mod.DQGetHistogramMod(file, outputFile, dataList): # DQGetHistogramMod returns True when + fileNum = fileNum + 1 # new file created + print "OK" + else: + print "Not found" + + return fileNum + +if __name__ == "__main__": + try: + optlist, unparsed = getopt.getopt(sys.argv[1:], + "d:o:p:s:u:lf:", + ["data=", "outputdir=", "pattern=", "useplugin=", "plugindir=", "about", "list", "flag="]) + except getopt.GetoptError: + usage() + sys.exit(-1) + + dataList = [] + outputdir = "./" + pattern = "querryOutput" #.root + pluginDirList = [ os.path.realpath(os.path.dirname(sys.argv[0]))+"/plugins" ] + + for opt, arg in optlist: + if opt in ("-o", "--outputdir"): + outputdir = arg + elif opt in ("-p", "--pattern"): + pattern = arg + elif opt in ("-d", "--data"): + dataList.append(arg) + elif opt in ("-f", "--flag"): + dataList.append(":"+arg) + elif opt in ("-s", "--plugindir"): + pluginDirList.append(arg) + elif opt in ("-u", "--useplugin"): + CurrentPlugin = arg + elif opt in ("--about"): + usage() + sys.exit(0) + elif opt in ("-l", "--list"): + loadPlugins(pluginDirList) + listPlugins() + sys.exit(0) + + loadPlugins(pluginDirList) + + if len(sys.argv[1:]) == 0: + usage() + sys.exit(0) + + if len(dataList) == 0: + print >>sys.stderr, "WARNING: No histogram/directory name given" + + if pattern == "": + print >>sys.stderr, "ERROR: Output filename pattern must be non-empty." + sys.exit(-1) + + if pattern.count('/') > 0: + print >>sys.stderr, "ERROR: Output filename pattern must not contain '/' characters" + sys.exit(-1) + + if not os.access(outputdir, os.F_OK): + print >>sys.stderr, "ERROR: Output directory", outputdir, "does not exist." + sys.exit(-1) + if not os.access(outputdir, os.R_OK): + print >>sys.stderr, "ERROR: Output directory", outputdir, "is not readable." + sys.exit(-1) + + if not outputdir.endswith('/'): + outputdir = outputdir + '/' + pattern = outputdir + pattern + + try: + pluginArgs = PluginDict[CurrentPlugin].ParseArguments(unparsed) + querryList = PluginDict[CurrentPlugin].QuerryDB(pluginArgs) + ExtractData(querryList, dataList, pattern) + except KeyError: + print >>sys.stderr, "ERROR:", CurrentPlugin, "not found." diff --git a/DataQuality/DataQualityUtils/scripts/ScanHistFile.py b/DataQuality/DataQualityUtils/scripts/ScanHistFile.py new file mode 100755 index 0000000000000000000000000000000000000000..c6b1efacbae53dc770fbd72969b563416b6f88aa --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/ScanHistFile.py @@ -0,0 +1,98 @@ +#!/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +#copied from DQPostProcessi.py and modified +# Sami Kama +import sys +def _dolsrwrapper(fname): + import ROOT + rf = ROOT.TFile.Open(fname, 'READ') + if not rf or not rf.IsOpen(): + print ' %s is empty or not accessible' % fname + return 3 + if rf.TestBit(ROOT.TFile.kRecovered): + print " %s is recovered. It means it was corrupt" % fname + return 7 + cleancache = ROOT.gROOT.MustClean(); ROOT.gROOT.SetMustClean(False) + RV=_dolsr(rf) + print "dolsr returned %s "%(RV) + rf.Close() + ROOT.gROOT.SetMustClean(cleancache) + return RV +def _dolsr(dir): + import ROOT + resultdir = dir.Get('Results'); statusobj = None + if resultdir: + statusobj = resultdir.Get('Status') + if statusobj: + l = statusobj.GetListOfKeys() + l[0].GetName() + keys = dir.GetListOfKeys() + for key in keys: + name = key.GetName() + #print "Reading key named %s"%name + keyClass=ROOT.TClass.GetClass(key.GetClassName()) + if keyClass.InheritsFrom('TDirectory'): + dirobj = key.ReadObj() + resultdir = dirobj.Get('Results'); statusobj = None + if resultdir: + statusobj = resultdir.Get('Status') + # is a check? is a summary? or recurse? + if name[-1] == '_' and resultdir: + hist = dir.Get(name[:-1]) + subkeys = resultdir.GetListOfKeys() + for subkey in subkeys: + ressub = subkey.GetName() + if ressub not in ('Status', 'Reference', 'ResultObject') and ROOT.TClass.GetClass(subkey.GetClassName()).InheritsFrom('TDirectory'): + subObj=subkey.ReadObj() + l = subObj.GetListOfKeys() + l[0].GetName() + # status flag + l = statusobj.GetListOfKeys() + l[0].GetName() + + else: + _dolsr(dirobj) + del dirobj + elif keyClass.InheritsFrom("TTree"): + currObj=key.ReadObj() + if currObj == None: + print "WARNING TTree Object \"%s\" in file:directory \"%s\" is corrupt "\ + "keylen=%s numbytes=%s objlen=%s fseekkey=%s"%(name,dir.GetPath(),key.GetKeylen(), + key.GetNbytes(),key.GetObjlen(),key.GetSeekKey()) + return 9 + else: + nentries=currObj.GetEntriesFast() + #print "Scanning tree Object \"%s\" in file:directory \"%s\" is corrupt "\ + #"keylen=%s numbytes=%s objlen=%s fseekkey=%s "%(name,dir.GetPath(),key.GetKeylen(), + # key.GetNbytes(),key.GetObjlen(),key.GetSeekKey()), + #print "Scanning tree %s"%name, + for j in xrange(nentries): + ientry=currObj.LoadTree(j) + if ientry<0: + break + nb=currObj.GetEntry(j) + if nb<=0: + continue + #print " Done" + currObj.Delete() + del currObj + else: + currObj=key.ReadObj() + if currObj == None: + print "WARNING Object \"%s\" in file:directory \"%s\" is corrupt "\ + "keylen=%s numbytes=%s objlen=%s fseekkey=%s"%(name,dir.GetPath(),key.GetKeylen(), + key.GetNbytes(),key.GetObjlen(),key.GetSeekKey()) + return 5 + currObj.Delete() + del currObj + return 0 +def scanFiles(globstr='testOutFile*'): + RV=_dolsrwrapper(globstr) + return RV +if __name__ == "__main__" : + if len(sys.argv)<2: + RV=scanFiles() + else: + RV=scanFiles("%s"%(sys.argv[1])) + sys.exit(RV) diff --git a/DataQuality/DataQualityUtils/scripts/StandAloneDisplay.py b/DataQuality/DataQualityUtils/scripts/StandAloneDisplay.py new file mode 100755 index 0000000000000000000000000000000000000000..abf6138c6c2dddabab75c476dc6630dc873cf1da --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/StandAloneDisplay.py @@ -0,0 +1,270 @@ +#!/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +import os +## Needed to correct ROOT behavior; see below +CWD = os.getcwd() + +import sys + +import ROOT +## Importing gSystem may change the current directory to one of the +## command-line arguments; chdir to original directory to have +## predictable behavior +from ROOT import gSystem +os.chdir(CWD) + +## Import the ROOT library for reading han results +gSystem.Load('libDataQualityUtils') +from ROOT import dqutils + + +def handi( name, resultsFile, htmlDir ): + + if ( htmlDir.rfind("/")!=(len(htmlDir)-1) ): # htmlDir needs "/" at the end + htmlDir+="/" + + of = dqutils.HanOutputFile(resultsFile) + + dirsstring = of.stringListSystemPaths(htmlDir) + dirs = dirsstring.rsplit() + for subHtmlDir in dirs: + if( not os.access(subHtmlDir,os.F_OK) ): + try: + os.makedirs(subHtmlDir) + except os.error: + print 'Cannot create directory "' + subHtmlDir + '"; exiting.' + sys.exit(-1) + + total=of.stringAllHistograms() + of.saveAllHistograms(htmlDir,False) + + s=total.rsplit('\n') + # number = number of lines in total + number=len(s) + if (len(s[number-1])<1): # last line is empty + number-=1 + + list, namelist = makeAllDirsFile( htmlDir, name, s, number, resultsFile ) + + for x in range(0,len(list)): + makeSubDirFile( htmlDir, name, s, number, namelist[x], list[x] ) + makeCSSFile( htmlDir,"", namelist[x] ) + + makeCSSFile( htmlDir,"", "." ) + + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "Usage: ", cmd, "<imput_file> <html_output_directory>" + +def makeAllDirsFile( htmlDir, name, s, number, resultsFile ): + g=open(htmlDir+'index.html','w') + g.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + g.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + g.write('<head>\n') + g.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + g.write('<title>'+ name+ '</title>\n') + g.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n') + g.write('</head>\n') + g.write('<body>') + g.write('<font class="DQGroup">[<a href="../index.html">Back</a>]</font>\n') + g.write('<h1>' + name + ': Monitoring</h1>\n') + + # initial number of white spaces, will change to positive value once we go over the lines + spaces=-1 + # list = list with directories (the line number) that contain histos + list=[] + # namelist = list with corresponding direcotory names + namelist=[] + + num_lists=0 + + g.write('<table>\n<tr valign="top">\n<td width="500">\n') + for x in range(0,number): + sp=s[x].rsplit() + if sp[3]=='dir': # a directory + namedir=sp[0] + shortNameDir = namedir + namediri = namedir.rfind("/") + if( namediri != -1 ): + shortNameDir = namedir[namediri+1:] + if namedir=='<top_level>': + shortNameDir='Overall Status' + spaces_new=s[x].find(sp[0][0]) + if spaces_new > spaces: # current dir is subdir of previous dir -> new item in new list + g.write('<ul>\n<li>') + num_lists+=1 + elif spaces_new==spaces: # current en previous dir in same motherdir -> new item + g.write('</li>\n<li>') + else: # close list and open new one + g.write('</li>') + diff = spaces - spaces_new + while diff > 0: + g.write('</ul></li>\n') + diff -= 2 + num_lists-=1 + g.write('<li>') + if namedir!='<top_level>': + g.write('<img src="pixel.png" width="0" height="13" alt="" />') + if ( (x<number-1) and (s[x+1].rsplit())[3]=='ass' ): # check that dir contains histos + if namedir=='<top_level>': + namedir = '.' + g.write('<font class="DQGroup"><a href="'+namedir +'/toplevel.html">'+shortNameDir+ '</a></font>') + else: + g.write('<font class="DQGroup"><a href="'+namedir +'/index.html" >'+shortNameDir+ '</a></font>') + list.append(x) + namelist.append(namedir) + else: + g.write('<font class="DQGroup">'+shortNameDir+ '</font>') + spaces=spaces_new + if num_lists>0: + g.write('</li>') + for x in range(0,num_lists-1): + g.write('</ul></li>\n') + if num_lists>0: + g.write('</ul>\n') + g.write('</td>\n<td><font class="Info">From file:</font><br/><font class="Note">' + resultsFile + '</font></td>\n</tr>\n</table>') + g.write('</body>\n</html>') + g.close() + return list, namelist + + +def makeSubDirFile( htmlDir, name, s, number, subname, assessIndex ): + + if( subname == '.' ): + h=open(htmlDir+'/'+subname+'/toplevel.html','w') + subnameTitle = 'Top Level' + else: + h=open(htmlDir+'/'+subname+'/index.html','w') + subnameTitle = subname + h.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + h.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + h.write('<head>\n') + h.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + h.write('<title>'+ name + ' ' + subnameTitle + '</title>\n') + h.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n') + h.write('</head>\n') + h.write('<body>\n') + h.write('<font class="DQGroup">[<a href="') + for x in range(subname.count("/")): + h.write('../') + h.write('../index.html">Back</a>]</font>\n') + h.write('<center>') + h.write('<table>\n<tr valign="top">\n<td width="250"></td>\n') + h.write('<td width="300"><h2>'+name+' '+subnameTitle+'</h2></td>\n') + h.write('<td width="250">\n<font class="Note">Click on images for details and full size.</font>\n') + h.write('</td>\n</tr>\n</table>\n') + h.write('<table cellpadding="4" cellspacing="20">\n') + y=assessIndex+1 + sp=s[y].rsplit() + col=0 + while(sp[3]=='ass' and y<number): + sp=s[y].rsplit() + col+=1 + if col==1: + h.write('<tr>\n<td class="' + sp[1] + '"><a href="'+sp[0]+'.html"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + elif col==3: + h.write('<td class="' + sp[1] + '"><a href="'+sp[0]+'.html"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n</tr>\n') + col=0 + else: + h.write('<td class="' + sp[1] + '"><a href="'+sp[0]+'.html"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + makeOneHistFile( htmlDir, name, subname, sp ) + y=y+1 + if y< number-1: + sp=s[y].rsplit() + if not (col==3): + h.write('</tr>\n') + h.write('</table>\n</center>\n</body>\n</html>\n') + h.close() + + +def makeOneHistFile( htmlDir, name, subname, sp ): + k=open(htmlDir+'/'+subname+'/'+sp[0]+'.html','w') + k.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + k.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + k.write('<head>\n') + k.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + k.write('<title>'+name+ ' ' + subname+ ' ' + sp[0]+'</title>\n') + k.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n') + k.write('</head>\n') + k.write('<body>\n') + k.write('<center>\n') + k.write('<table>\n<tr valign="top">\n') + if subname=='.': + k.write('<td width="250"><font class="DQGroup">[<a href="toplevel.html">Back</a></font>]</td>\n') + else: + k.write('<td width="250"><font class="DQGroup">[<a href="index.html">Back</a></font>]</td>\n') + k.write('<td width="500"><h2>'+name + ' ' + subname+'/'+sp[0]+'</h2></td>\n') + k.write('<td width="250"></td>\n</tr></table>\n') + k.write('<table cellpadding="10">\n<tr>\n') + k.write('<td>\n<table width="400">\n') + k.write('<tr><td colspan="2"><font class="Heading">Details:</font></td></tr>\n') + k.write('<tr><td> </td></tr>\n') + k.write('<tr><td align="right"><font class="DatumName">Name:</font></td>') + k.write('<td>' +sp[0] +'</td></tr>\n' ) + k.write('</table>\n</td>\n') + if subname == '.': + k.write('<td><a href="toplevel.html"><img src="'+ sp[0] +'.png" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + else: + k.write('<td><a href="index.html"><img src="'+ sp[0] +'.png" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n') + k.write('</tr></table>\n') + k.write('</center>\n</body>\n</html>\n') + k.close() + + +def makeRootFile( htmlDir, name, subname ): + k=open(htmlDir+'index.html','w') + k.write('<html>\n<frameset rows="200,*">\n') + k.write('<frame src="'+name+'AllDirs.html">\n') + if subname != "": + if subname != '.': + k.write('<frame src="'+subname+'/index.html" name="showframe"> \n') + else: + k.write('<frame src="'+subname+'/toplevel.html" name="showframe"> \n') + k.write('</frameset>\n</html> \n') + k.close() + + +def makeCSSFile( htmlDir, name, subname ): + css=open(htmlDir+'/'+subname+'/'+name+'AutomChecks.css','w') + css.write('BODY\n{\n background: #E6E6FA;\n color: #000000;\n font-family: helvetica,sans-serif;\n}\n') + css.write('H1\n{\n font-family: helvetica,sans-serif;\n font-size: x-large;\n text-align: left;\n}\n') + css.write('H2\n{\n font-family: helvetica,sans-serif;\n font-size: large;\n text-align: center;\n}\n') + css.write('H3\n{\n font-family: helvetica,sans-serif;\n font-size: medium;\n text-align: left;\n}\n') + css.write('FONT.Info\n{\n color: black;\n font-style: italic;\n}\n') + css.write('FONT.Heading\n{\n color: black;\n font-weight: bold;\n font-size: large;\n}\n') + css.write('FONT.DatumName\n{\n color: black;\n font-weight: bold;\n}\n') + css.write('FONT.Note\n{\n color: black;\n font-size: small;\n}\n') + css.write('FONT.DQGroup\n{\n font-size: small;\n}\n') + css.write('FONT.Red\n{\n color: red;\n font-weight: bold;\n}\n') + css.write('FONT.Yellow\n{\n color: #ffd700;\n font-weight: bold;\n}\n') + css.write('FONT.Green\n{\n color: green;\n font-weight: bold;\n}\n') + css.write('FONT.Undef\n{\n color: gray;\n font-weight: bold;\n}\n') + css.write('FONT.NoCheck\n{\n color: black;\n font-weight: bold;\n}\n') + css.write('TD.Red\n{\n background-color: red;\n}\n') + css.write('TD.Yellow\n{\n background-color: #ffd700;\n}\n') + css.write('TD.Green\n{\n background-color: green;\n}\n') + css.write('TD.Undef\n{\n background-color: gray;\n}\n') + css.write('TD.NoCheck\n{\n background-color: #E6E6FA;\n}\n') + css.close() + + +######################################## +## main() +######################################## + +if __name__ == "__main__": + + if len(sys.argv) != 3: + usage() + sys.exit(0) + + # Input + resultsFile = sys.argv[1] # input .root file + html_dir=sys.argv[2] # destination directory for html files + name=resultsFile + handi( name, resultsFile, html_dir ) + diff --git a/DataQuality/DataQualityUtils/scripts/StoreDB.py b/DataQuality/DataQualityUtils/scripts/StoreDB.py new file mode 100755 index 0000000000000000000000000000000000000000..b5a3a17108de9eb94f0c86bf9bcf94b232f3cb3b --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/StoreDB.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# +-----------------------------------------------------+ +# | Vassilis D. Kazazakis, StoreDB.py v1.1 | +# | Stores ROOT file information in the COOL database | +# +-----------------------------------------------------+ + +import sys +import getopt +import DataQualityUtils.DBInfo as DBInfo + +from PyCool import cool, coral + +# user & password information should be handled by each individual program +# if you have authentication file, this works + +home = os.environ.get('HOME') +os.environ['CORAL_AUTH_PATH'] = home+"/private" + +##userName = "ATLAS_COOLOFL_GLOBAL_W" +##password = "*******" ### + +connectString = "oracle://" + DBInfo.getWriteServer() +connectString += ";schema=" + DBInfo.getSchema() +#connectString += ";user=" + userName +connectString += ";dbname=" + DBInfo.getDbName() +#connectString += ";password=" + password + +folderName = DBInfo.getFolder() + +def usage(): + print "Usage:", sys.argv[0], "[options]" + print """ + -f/--filename ROOT filename to enter to the database + -g/--guid GUID of the file + -s/--start Starting run:lumiBlock number + -e/--end Ending run:lumiBlock (defaults to valid until next insertion) + -c/--channel Channel name + -l/--list List all available channels + """ + +def addToDatabase(filename, guid, channelName, runStart, runEnd = None): + dbSvc = cool.DatabaseSvcFactory.databaseService() + + try: + channel_id = DBInfo.getChannelDict()[channelName] + except KeyError: + print >>sys.stderr, "Channel", channelName, "does not exist." + sys.exit(-1) + + if runEnd == None: + timeEnd = cool.ValidityKeyMax + else: + timeEnd = runEnd[0] << 32 + timeEnd += runEnd[1] + timeStart = runStart[0] << 32 ## Since the 32 low bits are reserved for LumiBlocks... + timeStart += runStart[1] ## add lumiblock + + if timeStart >= timeEnd: + print >>sys.stderr, "Starting timestamp must be LESS than ending timestamp." + sys.exit(-1) + + try: + db = dbSvc.openDatabase( connectString, False ) + except: + print >>sys.stderr, "Error opening database." + sys.exit(-1) + + if db.existsFolder(folderName): + folder = db.getFolder(folderName) + spec = folder.payloadSpecification() + else: + print >>sys.stderr, "Error: Folder", folderName,"does not exist in database." + sys.exit(-1) + + data = cool.Record(spec) + data["filename"] = filename + data["guid"] = guid + folder.storeObject( timeStart, timeEnd, data, channel_id) + +if __name__ == "__main__": + + try: + optlist, unparsed = getopt.getopt(sys.argv[1:], + "f:s:e:c:lg:", + ["filename=", "start=", "end=", "channel=", "list", "guid="]) + except getopt.GetoptError: + print >>sys.stderr, "Error parsing arguments." + usage() + sys.exit(-1) + + filename = None + channelName = "default" + guid = 0 + runStart = (0, 0) + runEnd = None + + for opt, arg in optlist: + if opt in ("-f", "--filename"): + filename = arg + elif opt in ("-g", "--guid"): + guid = int(arg) + elif opt in ("-s", "--start"): + startList = arg.split(":") + if len(startList) == 1: + startList.append("0") + for i in range(2): + if startList[i] == "": + startList[i] = "0" + runStart = ( int(startList[0]), int(startList[1]) ) + elif opt in ("-e", "--end"): + endList = arg.split(":") + if len(endList) == 1: + endList.append("0") + for i in range(2): + if endList[i] == "": + endList[i] = "0" + runEnd = ( int(endList[0]), int(endList[1]) ) + elif opt in ("-c", "--channel"): + channelName = arg + elif opt in ("-l", "--list"): + print "Available channels:" + for key in DBInfo.getChannelDict().keys(): + print " ",key + sys.exit(0) + + if filename == None: + print >>sys.stderr, "Must define ROOT file." + usage() + sys.exit(-1) + + #guid = generateGUID(filename) + + addToDatabase(filename, guid, channelName, runStart, runEnd) diff --git a/DataQuality/DataQualityUtils/scripts/dq_make_web_display.py b/DataQuality/DataQualityUtils/scripts/dq_make_web_display.py new file mode 100755 index 0000000000000000000000000000000000000000..7c38dc2b8c3212fbed1c054b21ecfa04416a11a7 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/dq_make_web_display.py @@ -0,0 +1,222 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +""" +Transate arbitrary root file into a han config file with the "GatherData" algorithm +@author: ponyisi@hep.uchicago.edu +9 Oct 2008 +Adapted for fast physics monitoring 14 April 2011 +""" + +#HANDIR='/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/fastphysmon/1' + +from DQConfMakerBase.DQElements import * +from DQConfMakerBase.Helpers import IDHelper, make_thresholds +from DQHanConfMaker.hanwriter import writeHanConfiguration +import ROOT + +gatherdata = DQAlgorithm(id='GatherData', + libname='libdqm_algorithms.so') +worst = DQAlgorithm(id='WorstCaseSummary',libname='libdqm_summaries.so') + +def recurse(rdir, dqregion, ignorepath, reffile=None): +## print [x.__class__ for x in toList(dqregion.getSubRegions()) ] + for key in rdir.GetListOfKeys(): + cl = key.GetClassName(); rcl = ROOT.TClass.GetClass(cl) + #print key.GetName(), cl + if ' ' in key.GetName(): + print 'WARNING: cannot have spaces in histogram names for han config; not including %s %s' % (cl, key.GetName()) + continue + if rcl.InheritsFrom('TH1'): + if '/' in key.GetName(): + print 'WARNING: cannot have slashes in histogram names, encountered in directory %s, histogram %s' % (rdir.GetPath(), key.GetName()) + continue + if key.GetName() == 'summary': + print 'WARNING: cannot have histogram named summary, encountered in %s' % rdir.GetPath() + continue + name = rdir.GetPath().replace(ignorepath, '') + '/' + key.GetName() + dqpargs = { 'id' :name, + 'algorithm': gatherdata, + 'inputdatasource': name, + } + if reffile: + dqpargs['references'] = DQReference(reference='%s:same_name' % reffile) + dqpar = dqregion.newDQParameter( **dqpargs) + dqpar.addAnnotation('display', 'NoNorm') + + elif rcl.InheritsFrom('TDirectory'): + #print key.GetName() + newregion = dqregion.newDQRegion( key.GetName(), algorithm=worst ) + recurse(key.ReadObj(), newregion, ignorepath, reffile) + +def prune(dqregion): + """ + returns True if we should kill this node + False if we should not + """ + params = dqregion.getDQParameters() + if params == None: + params = [] + subregions = dqregion.getSubRegions() + if subregions == None: + subregions = [] + else: + subregions = subregions[:] + # kill subregions + for sr in subregions: + if sr == None: + continue + if prune(sr): + dqregion.delRelation('DQRegions', sr) + subregions = dqregion.getSubRegions() + if subregions == None: + subregions = [] + if len(subregions) + len(params) == 0: + return True + else: + return False + +def paramcount(dqregion): + params = dqregion.getDQParameters() + if params == None: + params = [] + subregions = dqregion.getSubRegions() + if subregions == None: + subregions = [] + + return len(params) + sum([paramcount(region) for region in subregions]) + +def process(infname, confname, reffile=None): + f = ROOT.TFile(infname, 'READ') + if not f.IsOpen(): + print 'ERROR: cannot open %s' % infname + return + + top_level = DQRegion(id='topRegion',algorithm=worst) + print 'Building tree...' + recurse(f, top_level, f.GetPath(), reffile) + print 'Pruning dead branches...' + prune(top_level) + pc = paramcount(top_level) + + sublevel = top_level.getSubRegions()[:] + for x in sublevel: + top_level.delRelation('DQRegions', x) + + print 'Writing output' + writeHanConfiguration( filename = confname , roots = sublevel) + return pc + +def super_process(fname, options): + import shutil, os, sys, contextlib + import ROOT + han_is_found = (ROOT.gSystem.Load('libDataQualityInterfaces') == 0) + if not han_is_found: + print 'ERROR: unable to load offline DQMF; unable to proceed' + sys.exit(1) + bname = os.path.basename(fname) + + run = options.run + hanconfig = None + hanhcfg = None + hanoutput = None + + failed = False + + @contextlib.contextmanager + def tmpdir(): + import tempfile + td = tempfile.mkdtemp() + yield td + shutil.rmtree(td) + + with tmpdir() as hantmpdir: + try: + print '====> Processing file %s' % (fname) + print '====> Generating han configuration file' + hantmpinput = os.path.join(hantmpdir, bname) + shutil.copyfile(fname, hantmpinput) + haninput = hantmpinput + hanconfig = os.path.join(hantmpdir, 'han.config') + rv = process(hantmpinput, hanconfig, options.reffile) + # bad hack. rv = number of histogram nodes + if rv == 0: + print 'No histograms to display; exiting with code 0' + sys.exit(0) + + print '====> Compiling han configuration' + hanhcfg = os.path.join(hantmpdir, 'han.hcfg') + ## os.system('han-config-gen.exe %s' % hanconfig) + ROOT.dqi.HanConfig().AssembleAndSave( hanconfig, hanhcfg ) + + print '====> Executing han' + import resource + memlimit = resource.getrlimit(resource.RLIMIT_AS) + resource.setrlimit(resource.RLIMIT_AS, (memlimit[1], memlimit[1])) + hanoutput = haninput.rpartition('.')[0] + '_han.root' + + rv = ROOT.dqi.HanApp().Analyze( hanhcfg, haninput, hanoutput, '' ) + ## rv = os.system('han.exe %s %s' % (hanhcfg, hantmpinput)) + if rv != 0: + raise Exception('failure in han') + hantargetdir = os.path.join(options.webdir, str(options.iteration), + options.dispname, 'run_%s' % run) + print '====> Copying to', hantargetdir + hantargetfile = os.path.join(hantargetdir, 'run_%s_han.root' % run) + if not os.access(hantargetdir, os.W_OK): + try: + os.makedirs(hantargetdir) + except Exception, e: + print 'Unable to create %s for some reason: %s' % (hantargetdir, e) + raise Exception('Error during execute') + shutil.copy2(hanoutput, hantargetfile) + print '====> Cleaning up' + except Exception, e: + print e + if 'canonical format' not in str(e): + failed = True + finally: + try: + if not prebuilt_hcfg: + os.unlink(hantmpinput) + os.unlink(hanconfig) + os.unlink(hanhcfg) + os.unlink(hanoutput) + except: + pass + + return not failed + + +if __name__=="__main__": + import sys, optparse, shutil + parser = optparse.OptionParser(usage='usage: %prog [options] inputfile run') + parser.add_option('--webdir', default='/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/fastphysmon', + help='Change directory to store web display files') + parser.add_option('--dispname', default='Summary', + help='Set "stream" name on web display') + parser.add_option('--iteration', default=1, type='int', + help='Set iteration number for web display') + parser.add_option('--reffile', default=None, + help='Reference file to use. Must have same structure as inputfile') + + options, args = parser.parse_args() + + if not 2 == len(args): + parser.print_help() + sys.exit(1) + fname = args[0] + try: + run = int(args[1]) + options.run = run + except ValueError: + parser.print_help() + print 'Specified run', args[1], 'doesn\'t seem to be an integer' + sys.exit(1) + + rv = super_process(fname, options) + if rv == True: + sys.exit(0) + else: + sys.exit(1) diff --git a/DataQuality/DataQualityUtils/scripts/hancool.py b/DataQuality/DataQualityUtils/scripts/hancool.py new file mode 100755 index 0000000000000000000000000000000000000000..10230eb0d681b16b76038cc00324a0cdd2508ea6 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/hancool.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +import DataQualityUtils.hancoolmod as mod + +import sys + + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "" + print "Usage: ", cmd, "<runnumber> <path> <dbConnection> <detstatus> <dbtag>" + print "or" + print "Usage: ", cmd, "(picking up default settings)" + print "" + + +if __name__ == "__main__": + + if (not ((len(sys.argv) == 1) or (len(sys.argv) == 5) or (len(sys.argv) == 6))): + usage() + sys.exit(0) + + runNumber = -1 + filePath = "" + dbConnection = "" + dqmfOfl = "" + db_tag = "" + + if (len(sys.argv) == 6): + runNumber = int(sys.argv[1]) # run number + filePath = sys.argv[2] # histograms file path + dbConnection = sys.argv[3] # COOL db connection string + dqmfOfl = sys.argv[4] # dqmfOfl + db_tag = sys.argv[5] # COOL db folder tag + + elif (len(sys.argv) == 5): + runNumber = int(sys.argv[1]) # run number + filePath = sys.argv[2] # histograms file path + dbConnection = sys.argv[3] # COOL db connection string + dqmfOfl = sys.argv[4] # dqmfOfl + db_tag = "HEAD" + + else: # set to defaults + runNumber = 52280 + filePath = "/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/FDR2a/1/physics_Express/" + dbConnection = "sqlite://;schema=MyCOOL_histo.db;dbname=COMP200" + dqmfOfl = "/GLOBAL/DETSTATUS/DQMFOFL" + db_tag = "HEAD" + + mod.hancool(runNumber,filePath,dbConnection,dqmfOfl, db_tag) + diff --git a/DataQuality/DataQualityUtils/scripts/hancool_histo.py b/DataQuality/DataQualityUtils/scripts/hancool_histo.py new file mode 100755 index 0000000000000000000000000000000000000000..4145936a6c2a3fff624cca8ce3ec8d064637debf --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/hancool_histo.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + + +import DataQualityUtils.hancool_histo_mod as mod + +import sys + + +##------------------------------------------------------------- + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "" + print "Usage: ", cmd, "<runnumber> <path> <dbConnection> <detstatus> <dbtag>" + print "or" + print "Usage: ", cmd, "(picking up default settings)" + print "" + + +######################################## +## main() +######################################## + +if __name__ == "__main__": + + if (not ((len(sys.argv) == 1) or (len(sys.argv) == 6) or (len(sys.argv) == 3))): + usage() + sys.exit(0) + + inputFilePath = "" + input_run = -1 + dbConnectionHisto = "" + dqmfOflHisto = "" + dbTagName = "" + + # Input + + if (len(sys.argv) == 6): + inputFilePath=sys.argv[1] # path name + input_run = sys.argv[2] # run number + dbConnectionHisto = sys.argv[3] # COOL db connection string + dqmfOflHisto = sys.argv[4] # dqmfOfl + dbTagName = sys.argv[5] # dbTagName + + elif (len(sys.argv) == 3): + inputFilePath=sys.argv[1] # path name + input_run = sys.argv[2] # run number +# dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio/DQMFTutorial_2/14.0.0/WorkArea/MyCOOL_histo_FDR2b.db;dbname=OFLP200" + dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio/DQMF_08112008/14.2.10/WorkArea/python/MyCOOL_histo_FDR2c.db;dbname=OFLP200" + dqmfOflHisto = "/GLOBAL/DETSTATUS/DQMFOFLH" + dbTagName = "DetStatusDQMFOFLH-FDR2-01" + + else: # set to defaults + input_run = 52280 + inputFilePath = "/afs/cern.ch/user/a/atlasdqm/dqmdisk1/han_results/tier0/FDR2b/1/physics_Express/" +# dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio/DQMFTutorial_2/14.0.0/WorkArea/MyCOOL_histo_FDR2b.db;dbname=OFLP200" + dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio/DQMF_08112008/14.2.10/WorkArea/python/MyCOOL_histo_FDR2c.db;dbname=OFLP200" + dqmfOflHisto = "/GLOBAL/DETSTATUS/DQMFOFLH" + dbTagName = "DetStatusDQMFOFLH-FDR2-02" + + mod.hancool_histo( inputFilePath, input_run, dbConnectionHisto,dqmfOflHisto, dbTagName) + diff --git a/DataQuality/DataQualityUtils/scripts/handi.py b/DataQuality/DataQualityUtils/scripts/handi.py new file mode 100755 index 0000000000000000000000000000000000000000..eeb41cacaebdba459fa52446d21d920c9ebf6a53 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/handi.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## ***************************************************************************** +VERSION = '$Id: handi.py 598803 2014-05-24 10:52:51Z ponyisi $' +## ***************************************************************************** + +import DataQualityUtils.handimod as mod + +import sys + +import getopt + +def handi( name, resultsFile, htmlDir, browserMenu=False, allDirsScriptLoc="https://atlasdqm.cern.ch/static/js/" ): + + ## Instructions for the compare button and the browser menu: + + ## Compare buttons only work with the typical run/stream structure. See DQWebDisplay.py for more info + compare = False + javaScriptLoc ="" + HjavaScriptLoc ="" + runListLoc = "" + + ## If you want a browser menu instead of the default directory listing, put browserMenu = True ... + #browserMenu = False + ## ... and give in the url of the script AllDirs.js, eg: + ## allDirsScriptLoc="http://atlasdqm.web.cern.ch/atlasdqm/tier0/AllDirs.js" + #allDirsScriptLoc="" + + mod.handiWithComparisons( name, resultsFile, htmlDir, runListLoc, compare, browserMenu, allDirsScriptLoc ) + + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "Usage: ", cmd, "[-m|--browser-menu] [-s|--script-loc=<URL>] <name_of_system> <results_file_name> <html_output_directory>" + + +######################################## +## main() +######################################## + +short_options = "hms:" +long_options = ["help","browser-menu","script-loc="] + +if __name__ == "__main__": + + # Default + browserMenu = False + allDirsScriptLoc = "" + + try: + opts, args = getopt.getopt(sys.argv[1:], short_options, long_options) + except getopt.GetoptError: + usage() + sys.exit(1) + for cmd, arg in opts: + if(cmd in ('--help',) or cmd in ('-h',)): + usage() + sys.exit(0) + if (cmd in ('--browser-menu',) or cmd in ('-m',)): + browserMenu = True + if (cmd in ('--script-loc',) or cmd in ('-s',)): + allDirsScriptLoc = arg + + if len(args) != 3: + usage() + sys.exit(0) + + # Input + name = args[0] # name of the subdetector + resultsFile = args[1] # root file with output + html_dir = args[2] # destination directory for html files + handi( name, resultsFile, html_dir, browserMenu, allDirsScriptLoc ) diff --git a/DataQuality/DataQualityUtils/scripts/historyDisplay.py b/DataQuality/DataQualityUtils/scripts/historyDisplay.py new file mode 100755 index 0000000000000000000000000000000000000000..c7fd7f7425986d25480fb5bbbdee107799ed25bc --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/historyDisplay.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +import DataQualityUtils.historyDisplayMod as mod + +import sys + + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "" + print "Usage: ", cmd, " ''<run list xml >'' <output html dir> <dbConnection> <detstatus> <config>" + print "" + print " This is a test" + + +######################################## +## main() +######################################## + + +if __name__ == "__main__": + + # Input + + + if (len(sys.argv) ==7 ): + xml=sys.argv[1] # xml list + htmlDirectory = sys.argv[2] # output html directory + dbConnectionHisto = sys.argv[3] # Cool DB connection string + dqmfOflHisto = sys.argv[4] # DB Histo folder + dbTagName = sys.argv[5] # DB Folder tag name + configuration = sys.argv[6] + + elif (len(sys.argv) == 3): + xml=sys.argv[1] # xml list + htmlDirectory = sys.argv[2] # output html directory +# dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio/DQMFTutorial_2/14.0.0/WorkArea/MyCOOL_histo_FDR2b.db;dbname=OFLP200" + dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio//DQMF_08112008/14.2.10/WorkArea/python/MyCOOL_histo_FDR2c.db;dbname=OFLP200" + dqmfOflHisto = "/GLOBAL/DETSTATUS/DQMFOFLH" + dbTagName = "DetStatusDQMFOFLH-FDR2-02" + configuration = "TEST" + else: + usage() + sys.exit(0) + +# xml="/afs/cern.ch/user/a/atlasdqm/dqmdisk/www/tier0/FDR2a/runlist_FDR2a.xml" +# htmlDirectory = "./" +# dbConnectionHisto = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/w0/users/onofrio/DQMFTutorial/14.0.0/MyCOOL_histo.db;dbname=COMP200" +# dqmfOflHisto = "/GLOBAL/DETSTATUS/DQMFOFLH" +# configuration = "TEST" + +# check of CPU time (test-mode only) + if (configuration.find('TEST')>-1): + start = cpu_time() + mod.historyDisplay( xml, htmlDirectory, dbConnectionHisto, dqmfOflHisto, dbTagName, configuration ) + dt = cpu_time() - start + print dt + else: + mod.historyDisplay( xml, htmlDirectory, dbConnectionHisto, dqmfOflHisto, dbTagName, configuration ) diff --git a/DataQuality/DataQualityUtils/scripts/hotSpotInTAG.py b/DataQuality/DataQualityUtils/scripts/hotSpotInTAG.py new file mode 100644 index 0000000000000000000000000000000000000000..4d088c9ce8a1c4c65d28f868077b3e126c37faf3 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/hotSpotInTAG.py @@ -0,0 +1,260 @@ +#!/usr/bin env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +# Author : Benjamin Trocme / Summer 2012 +# Make use of extractPath library to retrieve the correct castor path + +# Script to browse a TAG file and extract LBs for which at least N occurences of an object is found +# in a region defined as noisy. +#Options: +# -h, --help show this help message and exit +# -r RUN, --run=RUN Run number +# -s STREAMS, --stream=STREAMS Data stream : express/CosmicCalo/JetTauEtmiss/Egamma +# -a AMI, --amiTag=AMI ami Tag - Simply set x/f to choose express/bulk processing +# -e ETA, --eta=ETA Eta of hot spot +# -p PHI, --phi=PHI Phi of hot spot (or MET bump) +# -t THRESHOLD, --treshold=THRESHOLD Et/pt threshold (in MeV) +# -d DELTA, --delta=DELTA Distance to look around hot spot (or MET bump) +# -o OBJECT, --object=OBJECT TopoCluster/Jet/LoosePhoton/TauJet/MET +# -m MIN, --min=MIN Min number of object in a LB +# -n, --noplot Do not plot LB map +# The -h does not work. I should move to argpars... + +import os, sys +import string +import subprocess as sp +from optparse import OptionParser + +#sys.path.append("/afs/cern.ch/user/t/trocme/public/libraries") +import pathExtract + +import ROOT +from ROOT import * +from ROOT import gROOT, gDirectory +from ROOT import gStyle, TCanvas, TString +from ROOT import TFile, TTree, TRFIOFile +from ROOT import TH1F,TH2F,TBrowser +from ROOT import TPaveText + +gROOT.Reset() +gStyle.SetPalette(1) +gStyle.SetOptStat("em") + +def analyzeTree(): + global nbHitInHot + global cumEnergInHot + global nbLArNoisyRO_Std + global nbLArNoisyRO_SatTight + if (tree.LArFlags & 8):nbNoiseBurstVeto[tree.LumiBlockN] = nbNoiseBurstVeto[tree.LumiBlockN] + 1 + # Fill the list of coordinates depending on the object type + if ("TopoCluster" in objectType): + coordEnergy = [[tree.TopoClusterEt1,tree.TopoClusterEta1,tree.TopoClusterPhi1]] + if ("Jet" in objectType): + coordEnergy = [[tree.JetPt1,tree.JetEta1,tree.JetPhi1],[tree.JetPt2,tree.JetEta2,tree.JetPhi2],[tree.JetPt3,tree.JetEta3,tree.JetPhi3],[tree.JetPt4,tree.JetEta4,tree.JetPhi4],[tree.JetPt5,tree.JetEta5,tree.JetPhi5],[tree.JetPt6,tree.JetEta6,tree.JetPhi6]] + if ("LoosePhoton" in objectType): + coordEnergy = [[tree.LoosePhotonPt1,tree.LoosePhotonEta1,tree.LoosePhotonPhi1],[tree.LoosePhotonPt2,tree.LoosePhotonEta2,tree.LoosePhotonPhi2]] + if ("Tau" in objectType): + coordEnergy = [[tree.TauJetPt1,tree.TauJetEta1,tree.TauJetPhi1],[tree.TauJetPt2,tree.TauJetEta2,tree.TauJetPhi2]] + if ("MET" in objectType): + coordEnergy = [[tree.CellMissingET,0,tree.CellMissingETPhi]] + # Loop on the list of coordinates to analyze them + for iCE in coordEnergy: + if (iCE[0] > thresholdE): + if ("MET" in objectType): # Fill general map + h0map.Fill(iCE[2]) + if not (tree.LArFlags & 8): + h0mapClean.Fill(iCE[2]) + else: + h0map.Fill(iCE[1],iCE[2]) + if not (tree.LArFlags & 8): + h0mapClean.Fill(iCE[1],iCE[2]) + if not ((not options.larcleaning) and tree.LArFlags & 8): # Explicit cut LArEventInfo != ERROR to remove noise bursts is larcleaning is false + if (fabs(iCE[1]-etaSpot)<deltaSpot and fabs(iCE[2]-phiSpot)<deltaSpot): # A candidate has been found in suspicious region - Explict cut LArEventInfo != ERROR to remove noise bursts +# if (fabs(iCE[1]-etaSpot)<deltaSpot and fabs(iCE[2]-phiSpot)<deltaSpot and not (tree.LArFlags & 8)): # A candidate has been found in suspicious region - Explict cut LArEventInfo != ERROR to remove noise bursts + nbHitInHot[tree.LumiBlockN]=nbHitInHot[tree.LumiBlockN] + 1 + cumEnergInHot[tree.LumiBlockN]=cumEnergInHot[tree.LumiBlockN]+iCE[0] + if (tree.LArFlags & 1): nbLArNoisyRO_Std[tree.LumiBlockN] = nbLArNoisyRO_Std[tree.LumiBlockN] + 1 + if (tree.LArFlags & 4): nbLArNoisyRO_SatTight[tree.LumiBlockN] = nbLArNoisyRO_SatTight[tree.LumiBlockN] + 1 + + return + + +# Main=========================================================================================================== +usage = 'usage: %prog [options] arg' +parser = OptionParser(usage) +parser.add_option('-r','--run',type='str',dest='run',default='',help='Run number',action='store') +parser.add_option('-s','--stream',type='str',dest='streams',default='express',help='Data stream : express/CosmicCalo/JetTauEtmiss/Egamma',action='store') +parser.add_option('-a','--amiTag',type='str',dest='ami',default='f',help='ami Tag - Simply set x/f to choose express/bulk processing',action='store') +parser.add_option('-e','--eta',type='float',dest='eta',default='0.',help='Eta of hot spot',action='store') +parser.add_option('-p','--phi',type='float',dest='phi',default='0.',help='Phi of hot spot (or MET bump)',action='store') +parser.add_option('-t','--treshold',type='int',dest='threshold',default='1000',help='Et/pt threshold (in MeV)',action='store') +parser.add_option('-d','--delta',type='float',dest='delta',default='0.1',help='Distance to look around hot spot (or MET bump)',action='store') +parser.add_option('-o','--object',type='string',dest='object',default='TopoCluster',help='TopoCluster/Jet/LoosePhoton/TauJet/MET',action='store') +parser.add_option('-m','--min',type='int',dest='min',default='5',help='Min number of object in a LB',action='store') +parser.add_option('-n','--noplot',dest='noplot',help='Do not plot LB map',action='store_true') +parser.add_option('-l','--larcleaning',dest='larcleaning',help='Ignore LAr cleaning to find hot spot',action='store_true') + +parser.print_help() + +usage = 'usage: %prog [options] arg' +(options, args) = parser.parse_args() +run = options.run +stream = options.streams +amiTag = options.ami +etaSpot = options.eta +phiSpot = options.phi +deltaSpot = options.delta +objectType = options.object +minInLB = options.min +thresholdE = options.threshold + +if ("MET" in objectType): + etaSpot=0 + +print '\n' +print '---------------------------------' +print "Investigation on run "+str(run)+"/"+stream+" stream with ami TAG "+amiTag +listOfFiles = pathExtract.returnTAGPath(run,stream,amiTag) + +tree = TChain("POOLCollectionTree") + +for files in listOfFiles: + tree.AddFile(files) + +entries = tree.GetEntries() +#entries = 100 + +nLB=2000 +nbHitInHot = [0] * nLB +cumEnergInHot = [0] * nLB +nbNoiseBurstVeto = [0] * nLB +nbLArNoisyRO_Std = [0] * nLB +nbLArNoisyRO_SatTight = [0] * nLB + +if ("MET" in objectType): + h0map = TH1D("map","General map of %s with MET > %d MeV"%(objectType,thresholdE),64,-3.14,3.14) + h0mapClean = TH1D("mapClean","General map of %s with MET > %d MeV - LArFlags != ERROR"%(objectType,thresholdE),64,-3.14,3.14) +else: + h0map = TH2D("map","General map of %s with Et/Pt > %d MeV"%(objectType,thresholdE),90,-4.5,4.5,64,-3.14,3.14) + h0mapClean = TH2D("mapClean","General map of %s with MET > %d MeV - LArFlags != ERROR"%(objectType,thresholdE),90,-4.5,4.5,64,-3.14,3.14) + +for jentry in xrange( entries ): # Loop on all events + if (jentry % 100000 == 0): + print "%d / %d evnt processed"%(jentry,entries) + nb = tree.GetEntry( jentry ) + analyzeTree() + +print "I have looked for LBs with at least %d %s in a region of %.2f around (%.2f,%.2f) and Et/Pt > %d MeV"%(minInLB,objectType,deltaSpot,etaSpot,phiSpot,thresholdE) +if (options.larcleaning): + print "WARNING : The LArCleaning for noise bursts (LArEventInfo != ERROR) has been DEACTIVATED!!!" +else: + print "The LArCleaning (LArEventInfo != ERROR) for noise bursts has been activated" + +nLB_offending = [] +lowerLB = 2000 +upperLB = 0 +for i in range(nLB): + if nbHitInHot[i]>minInLB: + print "LB: %d -> %d hits (LAr flag in this LB : %d veto / In these events : %d Std / %d SatTight)"%(i,nbHitInHot[i],nbNoiseBurstVeto[i],nbLArNoisyRO_Std[i],nbLArNoisyRO_SatTight[i]) + nLB_offending.append(i) + if i<lowerLB : lowerLB = i + if i>upperLB : upperLB = i + + +if (options.larcleaning): + suffix = "NO LArFlags cut" +else: + suffix = "LArFlags != ERROR" + +# Plot evolution vs LB +if (upperLB>lowerLB): # check that at least one noisy LB was found + c0 = TCanvas() + h0Evol = TH1I("h0Evol","Nb of hits in a region of %.2f around (%.2f,%.2f) and Et/Pt > %d MeV - %s"%(deltaSpot,etaSpot,phiSpot,thresholdE,suffix),upperLB-lowerLB+1,lowerLB-0.5,upperLB+0.5) + h0Evol.SetXTitle("LumiBlock") + h0Evol_E = TH1I("h0Evol_E","Mean E/pt in a region of %.2f around (%.2f,%.2f) and Et/Pt > %d MeV - %s"%(deltaSpot,etaSpot,phiSpot,thresholdE,suffix),upperLB-lowerLB+1,lowerLB-0.5,upperLB+0.5) + h0Evol_E.SetXTitle("LumiBlock") + if ("MET" in objectType): + h0Evol.SetTitle("Nb of events with MET in a phi region of %.2f around %.2f and MET > %d MeV - %s"%(deltaSpot,phiSpot,thresholdE,suffix)) + h0Evol_E.SetTitle("Mean MET in a phi region of %.2f around %.2f and MET > %d MeV - %s"%(deltaSpot,phiSpot,thresholdE,suffix)) + for i in range(lowerLB,upperLB+1): + h0Evol.Fill(i,nbHitInHot[i]) + if (nbHitInHot[i]>0): + h0Evol_E.Fill(i,cumEnergInHot[i]/nbHitInHot[i]) + c0.Divide(1,2) + c0.cd(1) + h0Evol.Draw() + c0.cd(2) + h0Evol_E.Draw() + c0.Update() + +c0_2 = TCanvas() +if (objectType == "MET"): + h0map.Draw() +else: + h0map.Draw("COLZ") + +c0_3 = TCanvas() +if (objectType == "MET"): + h0mapClean.Draw() +else: + h0mapClean.Draw("COLZ") + +# Plot individual map for each LB. Can be switched off with "-n" +if (not options.noplot): + canvas = [] + for i in range(min(len(nLB_offending),2)): + canvas.append(TCanvas()) + iCurrent = len(canvas)-1 + + if (options.larcleaning): + cutC = "1" # Accept all events + else: + cutC = "!(LArFlags & 8)" # Reject events flagged with LArEventInfo::ERROR + + if ("TopoCluster" in objectType): +# tree.Draw("TopoClusterPhi1:TopoClusterEta1 >> h1_%d"%(nLB_offending[i]),"TopoClusterEt1 > %d && LumiBlockN==%d && !(LArFlags & 8)"%(thresholdE,nLB_offending[i]),"COLZ") + tree.Draw("TopoClusterPhi1:TopoClusterEta1 >> h1_%d"%(nLB_offending[i]),"TopoClusterEt1 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + if ("Jet" in objectType): + tree.Draw("JetPhi1:JetEta1 >> h1_%d"%(nLB_offending[i]),"JetPt1 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + tree.Draw("JetPhi2:JetEta2 >> +h1_%d"%(nLB_offending[i]),"JetPt2 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + tree.Draw("JetPhi3:JetEta3 >> +h1_%d"%(nLB_offending[i]),"JetPt3 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + tree.Draw("JetPhi4:JetEta4 >> +h1_%d"%(nLB_offending[i]),"JetPt4 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + tree.Draw("JetPhi5:JetEta5 >> +h1_%d"%(nLB_offending[i]),"JetPt5 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + tree.Draw("JetPhi6:JetEta6 >> +h1_%d"%(nLB_offending[i]),"JetPt6 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + if ("MET" in objectType): + tree.Draw("CellMissingETPhi >> h1_%d"%(nLB_offending[i]),"CellMissingET > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC)) + if ("LoosePhoton" in objectType): + tree.Draw("LoosePhotonPhi1:LoosePhotonEta1 >> h1_%d"%(nLB_offending[i]),"LoosePhotonPt1 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + tree.Draw("LoosePhotonPhi2:LoosePhotonEta2 >> +h1_%d"%(nLB_offending[i]),"LoosePhotonPt2 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + if ("Tau" in objectType): + tree.Draw("TauJetPhi1:TauJetEta1 >> h1_%d"%(nLB_offending[i]),"TauJetPt1 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + tree.Draw("TauJetPhi2:TauJetEta2 >> +h1_%d"%(nLB_offending[i]),"TauJetPt2 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ") + + canvas[iCurrent].SetGridx(1) + canvas[iCurrent].SetGridy(1) +# canvas[iCurrent].SetLogz(1) + + canvas.append(TCanvas()) + + if ("TopoCluster" in objectType): +# tree.Draw("TopoClusterEt1 >> h1Et_%d"%(nLB_offending[i]),"abs(TopoClusterEta1-%.3f) < %.3f && abs(TopoClusterPhi1-%.3f) < %.3f && LumiBlockN==%d && !(LArFlags & 8)"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i])) + tree.Draw("TopoClusterEt1 >> h1Et_%d"%(nLB_offending[i]),"abs(TopoClusterEta1-%.3f) < %.3f && abs(TopoClusterPhi1-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + if ("Jet" in objectType): + tree.Draw("JetPt1 >> h1Pt_%d"%(nLB_offending[i]),"abs(JetEta1-%.3f) < %.3f && abs(JetPhi1-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + tree.Draw("JetPt2 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta2-%.3f) < %.3f && abs(JetPhi2-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + tree.Draw("JetPt3 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta3-%.3f) < %.3f && abs(JetPhi3-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + tree.Draw("JetPt4 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta4-%.3f) < %.3f && abs(JetPhi4-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + tree.Draw("JetPt5 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta5-%.3f) < %.3f && abs(JetPhi5-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + tree.Draw("JetPt6 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta6-%.3f) < %.3f && abs(JetPhi6-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + if ("MET" in objectType): + tree.Draw("CellMissingET >> h1Pt_%d"%(nLB_offending[i]),"abs(CellMissingETPhi-%.3f) < %.3f && LumiBlockN==%d && %s"%(phiSpot,deltaSpot,nLB_offending[i],cutC)) + if ("LoosePhoton" in objectType): + tree.Draw("LoosePhotonPt1 >> h1Pt_%d"%(nLB_offending[i]),"abs(LoosePhotonEta1-%.3f) < %.3f && abs(LoosePhotonPhi1-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + tree.Draw("LoosePhotonPt2 >> +h1Pt_%d"%(nLB_offending[i]),"abs(LoosePhotonEta2-%.3f) < %.3f && abs(LoosePhotonPhi2-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + if ("Tau" in objectType): + tree.Draw("TauJetPt1 >> h1Pt_%d"%(nLB_offending[i]),"abs(TauJetEta1-%.3f) < %.3f && abs(TauJetPhi1-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + tree.Draw("TauJetPt2 >> +h1Pt_%d"%(nLB_offending[i]),"abs(TauJetEta2-%.3f) < %.3f && abs(TauJetPhi2-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC)) + +if ("Tau" in objectType): + print 'WARNING : in recent TAGs, the TauJet were not filled - A double check is welcome: tree.Draw(\"TauJetEta1\")' diff --git a/DataQuality/DataQualityUtils/scripts/pathExtract.py b/DataQuality/DataQualityUtils/scripts/pathExtract.py new file mode 100644 index 0000000000000000000000000000000000000000..d39d28f41079bbd70cfa2606ba4a1cc5367416c0 --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/pathExtract.py @@ -0,0 +1,150 @@ +#!/usr/bin env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# arguments : list of run + +import os, sys +import string +import subprocess as sp + +from ROOT import * +from ROOT import gROOT, gDirectory, gPad + + +# Return the path of the output of tier0 monitoring +def returnTier0HistPath(run,stream,amiTag,tag="data12_8TeV"): + os.putenv("STAGE_SVCCLASS","atlcal") + prefix = {'express':'express_','Egamma':'physics_','CosmicCalo':'physics_','JetTauEtmiss':'physics_'} + path="/castor/cern.ch/grid/atlas/tzero/prod1/perm/"+tag+"/"+prefix[stream]+stream+"/" + P = sp.Popen(['nsls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + if p[1]=='': + listOfRuns = p[0].split('\n') + for iRun in listOfRuns: + if (str(run) in iRun): + path = "/castor/cern.ch/grid/atlas/tzero/prod1/perm/"+tag+"/"+prefix[stream]+stream+"/"+iRun + P = sp.Popen(['nsls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + listOfDirs = p[0].split('\n') + for iDir in listOfDirs: + dotAmiTag=".%s"%(amiTag) + if ("HIST" in iDir and dotAmiTag in iDir): + path = "/castor/cern.ch/grid/atlas/tzero/prod1/perm/"+tag+"/"+prefix[stream]+stream+"/"+iRun+"/"+iDir + P = sp.Popen(['nsls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + listOfFiles = p[0].split('\n') + path = "/castor/cern.ch/grid/atlas/tzero/prod1/perm/"+tag+"/"+prefix[stream]+stream+"/"+iRun+"/"+iDir+"/"+listOfFiles[0] + P = sp.Popen(['stager_get','-M',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + if p[1]=='': + if ("Insufficient" in p[0]): + print "File NOT STAGED : missing %s"%(path) + return "NOFILE" + else: + print "I found %s"%(path) + return path + print "Failed - Aborted at %s level"%(path) + return "NOFILE" + +# Return the list of TAGs files on castor +def returnTAGPath(run,stream,amiTag="f",tag ="data12_8TeV"): + os.putenv("STAGE_SVCCLASS","atlcal") + prefix = {'express':'express_','Egamma':'physics_','CosmicCalo':'physics_','JetTauEtmiss':'physics_'} + found = False + list = [] + path = '/castor/cern.ch/grid/atlas/tzero/prod1/perm/'+tag+'/'+prefix[stream]+stream+'/00'+str(run)+'/' + P = sp.Popen(['nsls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + if p[1]=='': + files = p[0] + files = files.split('\n') + for f in files: + dotAmiTag=".%s"%(amiTag) + if ('TAG' in f and dotAmiTag in f): + path += f+'/' + found=True + break + if not found: + print 'no TAG directory found in %s'%(path) + return + + P = sp.Popen(['nsls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + if p[1]=='': + files = p[0].split('\n') + for iFile in files: + if (len(iFile)>0): + # Has found a file- Check that it is staged + pathFile = path+iFile + P = sp.Popen(['stager_get','-M',pathFile],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + if p[1]=='': + if ("Insufficient" in p[0]): + print "File NOT STAGED=== Skipping file %s"%(pathFile) + else: + print "I found %s"%(pathFile) + list.append(pathFile) + else: + return 'no TAG file' + return list + +# Add new run to noise bursts tchain - 2011 data stored on castor +def addRun(newRun,chain): + path='/castor/cern.ch/grid/atlas/atlasgroupdisk/det-larg/data11_7TeV/NTUP_LARNOISE/' + P = sp.Popen(['nsls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + print p + if p[1]=='': + tags = p[0] + tags = tags.split('\n') + print tags + for t in tags: + path='/castor/cern.ch/grid/atlas/atlasgroupdisk/det-larg/data11_7TeV/NTUP_LARNOISE/'+t + P = sp.Popen(['nsls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + if p[1]=='': + runs = p[0] + runs = runs.split('\n') + for iRun in runs: + if (str(newRun) in iRun) and ('CosmicCalo' in iRun): + path='/castor/cern.ch/grid/atlas/atlasgroupdisk/det-larg/data11_7TeV/NTUP_LARNOISE/'+t+'/'+iRun + P = sp.Popen(['nsls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + print path + if p[1]=='': + files = p[0] + files = files.split('\n') + for iFile in files: + if 'root' in iFile: + path='rfio:/castor/cern.ch/grid/atlas/atlasgroupdisk/det-larg/data11_7TeV/NTUP_LARNOISE/'+t+'/'+iRun+'/'+iFile + print "Adding :",path + chain.Add(path) + +# Add new run to noise bursts TChain - 2012 data stored on EOS +def eosChainInclude(newRun,stream,chain): + path="/eos/atlas/atlasgroupdisk/det-larg/data12_8TeV/NTUP_LARNOISE/" + P = sp.Popen(["/afs/cern.ch/project/eos/installation/0.1.0-22d/bin/eos.select","ls",path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + if p[1]=='': + tags = p[0] + tags = tags.split('\n') + for t in tags: + path='/eos/atlas/atlasgroupdisk/det-larg/data12_8TeV/NTUP_LARNOISE/'+t + P = sp.Popen(['/afs/cern.ch/project/eos/installation/0.1.0-22d/bin/eos.select','ls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + if p[1]=='': + runs = p[0] + runs = runs.split('\n') + for iRun in runs: + if (str(newRun) in iRun) and (stream in iRun): + path='/eos/atlas/atlasgroupdisk/det-larg/data12_8TeV/NTUP_LARNOISE/'+t+'/'+iRun + P = sp.Popen(['/afs/cern.ch/project/eos/installation/0.1.0-22d/bin/eos.select','ls',path],stdout=sp.PIPE,stderr=sp.PIPE) + p = P.communicate() + if p[1]=='': + files = p[0] + files = files.split('\n') + for iFile in files: + if 'root' in iFile: + path='root://eosatlas//eos/atlas/atlasgroupdisk/det-larg/data12_8TeV/NTUP_LARNOISE/'+t+'/'+iRun+'/'+iFile + print "Adding %s"%(path) + chain.Add(path) diff --git a/DataQuality/DataQualityUtils/scripts/physval_make_web_display.py b/DataQuality/DataQualityUtils/scripts/physval_make_web_display.py new file mode 100755 index 0000000000000000000000000000000000000000..bf8aaed7b37fc8996f6480055762fd043a75905b --- /dev/null +++ b/DataQuality/DataQualityUtils/scripts/physval_make_web_display.py @@ -0,0 +1,269 @@ +#!/usr/bin/env python + +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +""" +Transate arbitrary root file into a han config file +@author: ponyisi@utexas.edu +9 Oct 2008 +Adapted for physics validation 14 May 2014 +""" + +from DQConfMakerBase.DQElements import * +from DQConfMakerBase.Helpers import IDHelper, make_thresholds +from DataQualityUtils.hanwriter import writeHanConfiguration +import ROOT + +repeatalgorithm = DQAlgorithm(id='RepeatAlgorithm', + libname='libdqm_algorithms.so') +worst = DQAlgorithm(id='WorstCaseSummary',libname='libdqm_summaries.so') + +### SOME THINGS YOU MIGHT WANT TO EDIT +# Edit this to change what algorithm is applied (AuxAlgName--xxx) +# or to disable printing the number of entries for each reference +algorithmparameters = [DQAlgorithmParameter('AuxAlgName--Chi2Test_Chi2_per_NDF', 1), + DQAlgorithmParameter('RepeatAlgorithm--ResultsNEntries', 1)] + +# Edit this to change thresholds +chi2thresh = make_thresholds('Chi2_per_NDF', 1, 1.5, 'Chi2Thresholds') + +def recurse(rdir, dqregion, ignorepath, refs=None, displaystring='Draw=PE', regex=None, startpath=None): + for key in rdir.GetListOfKeys(): + cl = key.GetClassName(); rcl = ROOT.TClass.GetClass(cl) + if ' ' in key.GetName(): + print 'WARNING: cannot have spaces in histogram names for han config; not including %s %s' % (cl, key.GetName()) + continue + if rcl.InheritsFrom('TH1'): + if '/' in key.GetName(): + print 'WARNING: cannot have slashes in histogram names, encountered in directory %s, histogram %s' % (rdir.GetPath(), key.GetName()) + continue + if key.GetName() == 'summary': + print 'WARNING: cannot have histogram named summary, encountered in %s' % rdir.GetPath() + continue + fpath = rdir.GetPath().replace(ignorepath, '') + name = (fpath + '/' + key.GetName()).lstrip('/') + #print rdir.GetPath(), ignorepath, name + if regex: + #print name + if not regex.match(name): continue + dqpargs = { 'id' : ('' if fpath else 'top_level/') + name, + 'algorithm': repeatalgorithm, + 'inputdatasource': (startpath + '/' if startpath else '') + name, + 'algorithmparameters': algorithmparameters, + 'thresholds': chi2thresh, + } + if refs: + dqpargs['references'] = refs + dqpar = dqregion.newDQParameter( **dqpargs) + drawstrs = [] + if not options.normalize: drawstrs.append('NoNorm') + if options.logy: drawstrs.append('LogY') + if cl.startswith('TH1'): drawstrs.append(displaystring) + drawstrs.append('DataName=%s' % options.title) + dqpar.addAnnotation('display', ','.join(drawstrs)) + + elif rcl.InheritsFrom('TDirectory'): + newregion = dqregion.newDQRegion( key.GetName(), algorithm=worst ) + recurse(key.ReadObj(), newregion, ignorepath, refs, displaystring, regex, startpath) + +def prune(dqregion): + """ + returns True if we should kill this node + False if we should not + """ + params = dqregion.getDQParameters() + if params == None: + params = [] + subregions = dqregion.getSubRegions() + if subregions == None: + subregions = [] + else: + subregions = subregions[:] + # kill subregions + for sr in subregions: + if sr == None: + continue + if prune(sr): + dqregion.delRelation('DQRegions', sr) + subregions = dqregion.getSubRegions() + if subregions == None: + subregions = [] + if len(subregions) + len(params) == 0: + return True + else: + return False + +def paramcount(dqregion): + params = dqregion.getDQParameters() + if params == None: + params = [] + subregions = dqregion.getSubRegions() + if subregions == None: + subregions = [] + + return len(params) + sum([paramcount(region) for region in subregions]) + +def process(infname, confname, options, refs=None): + import re + f = ROOT.TFile(infname, 'READ') + if not f.IsOpen(): + print 'ERROR: cannot open %s' % infname + return + + top_level = DQRegion(id='topRegion',algorithm=worst) + print 'Building tree...' + refpairs = refs.split(',') + try: + refdict = dict(_.split(':') for _ in refpairs) + except e: + print e + dqrs = [DQReference(reference='%s:same_name' % v, id=k) + for k, v in refdict.items()] + displaystring = options.drawopt + if options.refdrawopt: + displaystring += ',' + (','.join('DrawRef=%s' % _ for _ in options.refdrawopt.split(','))) + if options.startpath: + topindir = f.Get(options.startpath) + if not topindir: + raise ValueError("Path %s doesn't exist in input file" % options.startpath) + topindirname = f.GetPath() + options.startpath.strip('/') + startpath = options.startpath.strip('/') + else: + topindir = f + topindirname = f.GetPath() + startpath = None + recurse(topindir, top_level, topindirname, dqrs, displaystring, + re.compile(options.pathregex), startpath) + print 'Pruning dead branches...' + prune(top_level) + pc = paramcount(top_level) + + sublevel = top_level.getSubRegions()[:] + for x in sublevel: + top_level.delRelation('DQRegions', x) + + print 'Writing output' + writeHanConfiguration( filename = confname , roots = sublevel) + return pc + +def super_process(fname, options): + import shutil, os, sys, contextlib + import ROOT + han_is_found = (ROOT.gSystem.Load('libDataQualityInterfaces') == 0) + if not han_is_found: + print 'ERROR: unable to load offline DQMF; unable to proceed' + sys.exit(1) + bname = os.path.basename(fname) + + hanconfig = None + hanhcfg = None + hanoutput = None + + failed = False + + @contextlib.contextmanager + def tmpdir(): + import tempfile + td = tempfile.mkdtemp() + yield td + shutil.rmtree(td) + + with tmpdir() as hantmpdir: + try: + print '====> Processing file %s' % (fname) + print '====> Generating han configuration file' + hantmpinput = os.path.join(hantmpdir, bname) + shutil.copyfile(fname, hantmpinput) + haninput = hantmpinput + hanconfig = os.path.join(hantmpdir, 'han.config') + rv = process(hantmpinput, hanconfig, options, options.reffile) + #shutil.copy(hanconfig, os.getcwd()) + + # bad hack. rv = number of histogram nodes + if rv == 0: + print 'No histograms to display; exiting with code 0' + sys.exit(0) + + print '====> Compiling han configuration' + hanhcfg = os.path.join(hantmpdir, 'han.hcfg') + ROOT.dqi.HanConfig().AssembleAndSave( hanconfig, hanhcfg ) + print '====> Executing han' + import resource + memlimit = resource.getrlimit(resource.RLIMIT_AS) + resource.setrlimit(resource.RLIMIT_AS, (memlimit[1], memlimit[1])) + hanoutput = haninput.rpartition('.')[0] + '_han.root' + + rv = ROOT.dqi.HanApp().Analyze( hanhcfg, haninput, hanoutput ) + if rv != 0: + raise Exception('failure in han') + print '====> Dumping web display output' + from DataQualityUtils import handimod + handimod.handiWithComparisons( options.title, + hanoutput, + options.outdir, + '', False, False, + 'https://atlasdqm.web.cern.ch/atlasdqm/js/') +## print '====> Copying to', hantargetdir +## hantargetfile = os.path.join(hantargetdir, 'out_han.root') +## if not os.access(hantargetdir, os.W_OK): +## try: +## os.makedirs(hantargetdir) +## except Exception, e: +## print 'Unable to create %s for some reason: %s' % (hantargetdir, e) +## raise Exception('Error during execute') +## shutil.copy2(hanoutput, hantargetfile) +## print '====> Cleaning up' + os.unlink(hanoutput) + except Exception, e: + print e + if 'canonical format' not in str(e): + failed = True + finally: + try: + if not prebuilt_hcfg: + os.unlink(hantmpinput) + os.unlink(hanconfig) + os.unlink(hanhcfg) + os.unlink(hanoutput) + except: + pass + + return not failed + + +if __name__=="__main__": + import sys, optparse, shutil, os + os.environ['TDAQ_ERS_NO_SIGNAL_HANDLERS']='1' + parser = optparse.OptionParser(usage='usage: %prog [options] inputfile') + parser.add_option('--reffile', default=None, + help='Reference files to use. Must have same structure as inputfile. Format: tag1:reffile1.root,tag2:reffile2.root,...') + parser.add_option('--outdir', default='./handi', + help='Directory for web ouptut') + parser.add_option('--normalize', default=False, action='store_true', + help='Normalize reference histograms for display') + parser.add_option('--title', default='Summary', + help='Title for histograms being tested') + parser.add_option('--refdrawopt', + help='ROOT Draw option for reference histograms (e.g. HIST)') + parser.add_option('--drawopt', default='Draw=PE', + help='Draw options for tested histograms (only use if you know what you are doing)') + parser.add_option('--logy', action='store_true', + help='Display on log Y scale') + parser.add_option('--pathregex', default='.*', + help='Specify regex to match histograms, e.g. "(Btag|Jets)"') + parser.add_option('--startpath', default=None, + help='Start from this subdirectory of the file') + + + options, args = parser.parse_args() + + if not 1 == len(args): + parser.print_help() + sys.exit(1) + fname = args[0] + + rv = super_process(fname, options) + if rv == True: + sys.exit(0) + else: + sys.exit(1) diff --git a/DataQuality/DataQualityUtils/share/AllDirs.js b/DataQuality/DataQualityUtils/share/AllDirs.js new file mode 100644 index 0000000000000000000000000000000000000000..87ec5c8632327c4eeb7589c6136668c994aab648 --- /dev/null +++ b/DataQuality/DataQualityUtils/share/AllDirs.js @@ -0,0 +1,378 @@ + +// ************************************************************ +// $Id: AllDirs.js,v 1.3 2009-03-16 19:42:18 boelaert Exp $ +// ************************************************************ + + +var xmlDoc; +var xmlhttp; +var y; +var selectionList; +var htmlIndex; +var Dir; +var Selection = new Array(); +var CountSel=0; + +function createMenu(){ + selectionList = xmlDoc; + Selection = new Array(); + CountSel =0; + createSubMenu("subdir"); +} + + +function loadXMLDoc(url) +{ + xmlhttp=null; + if (window.XMLHttpRequest) + {// code for IE7, Firefox, Mozilla, etc. + xmlhttp=new XMLHttpRequest(); + } + else if (window.ActiveXObject) + {// code for IE5, IE6 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + if (xmlhttp!=null) + { + xmlhttp.onreadystatechange=function(){ + onResponse(); + } + xmlhttp.open("GET",url,true); + xmlhttp.send(null); + } + else + { + alert("Your browser does not support XMLHTTP."); + } +} + + +function onResponse() +{ + if(xmlhttp.readyState!=4) return; + if(xmlhttp.status!=200) + { + alert("Problem retrieving XML data"); + return; + } + xmlDoc = xmlhttp.responseXML; + createMenu(); + displaySubdirs(); +} + + +function containsHistos(system) +{ + subs = system.getElementsByTagName("dir"); + value = false; + var k1=0; + if(system.getAttribute('histo')=='yes'){ + value = true; + } + while (k1<subs.length && !value){ + if (subs[k1].getAttribute('histo')=='yes') + { + value = true; + } + k1++; + } + return value; +} + + +function createSubMenu(tagDir) +{ + var htmlIndex = String(window.location); + Dir = tagDir; + id = htmlIndex.indexOf("index.html"); + if (id>0){ + htmlIndex = htmlIndex.substring(0,id-1); + } + txt =""; + if (tagDir == "subdir"){ + temp=selectionList.getElementsByTagName("dir"); + templi = temp[0].childNodes; + var y = new Array(); + var counter = 0; + for (k=0;k<templi.length;k++){ + if(templi[k].nodeName=="dir" && containsHistos(templi[k])) { + y[counter]=templi[k]; + counter++; + } + } + for (j=0;j<y.length;j++){ + tempList=y[j].getElementsByTagName("a"); + if (tempList.length>0){ + txt ="<select id=\"menu_"+tagDir + "\" onchange=\"createSubMenu(\'sub"+tagDir+"\');\" >\n"; + txt +="<option>--select directory--</option>\n"; + break; + } + } + if (txt ==""){ + txt +="<select id=\"menu_"+tagDir + "\" onchange=\"createSubMenu(\'sub"+tagDir+"\');\" >\n"; + txt +="<option>--no histograms--</option>\n"; + } + } + else { + txt +="<select id=\"menu_"+tagDir + "\" onchange=\"createSubMenu(\'sub"+tagDir+"\');\" >\n"; + prevDir = tagDir.substring(3); + CountSel2 =Math.round(prevDir.length/3-2); + if (CountSel2<CountSel) { + var Selection2 = new Array(); + for (i=0;i<CountSel2;i++) { + Selection2[i]=Selection[i]; + } + for (i = CountSel2; i<CountSel; i++){ + tagD = "sub" + prevDir; + document.getElementById("Select_"+tagD).innerHTML=" "; + selectionList=selectionList.parentNode; + } + Selection = Selection2; + CountSel = CountSel2; + } + var mylist = document.getElementById("menu_"+prevDir); + prevDirIDStat = mylist.options[mylist.selectedIndex].text; + templi=prevDirIDStat.split(" -"); + prevDirID = templi[0]; + Selection[CountSel]=prevDirID; + CountSel++; + x = selectionList.getElementsByTagName("dir"); + for (i=0;i<x.length;i++) + { + if (x[i].getAttribute("tag")==prevDir && x[i].getAttribute("id")==prevDirID){ + selectionList = x[i]; + templi=x[i].childNodes; + var y = new Array(); + var counter = 0; + for (k=0;k<templi.length;k++){ + if(templi[k].nodeName=="dir" && containsHistos(templi[k])){ + y[counter]=templi[k]; + counter++; + } + } + templi =x[i].getElementsByTagName("a"); + if (templi.length==1){ + pageLink = templi[0].getAttribute("href"); + window.location = htmlIndex+"/"+pageLink ; + return; + } + + } + } + txt +="<option>--select subdirectory--</option>\n"; +} +for (j=0;j<y.length;j++) + { + txt +="<option>"+ y[j].getAttribute("id")+" - "+ y[j].getAttribute("status")+ "</option>"; + + } + txt +="</select>\n"; + txt +="<p></p>\n<div id=\"Select_sub"+tagDir + "\"> </div>"; + document.getElementById("Select_"+tagDir).innerHTML=txt; + displaySubdirs(); + } + + function displaySubdirs() + { + x = xmlDoc.getElementsByTagName("dir"); + var directory; + var globalName=""; + if (CountSel!=0) { + globalName+="Overall Status/"; + } + var DirName=""; + if(CountSel==0){ + Selection[CountSel]="Overall Status"; + for (i=0;i<x.length;i++) + { + if (x[i].getAttribute("id")==Selection[0]){ + directory = x[i]; + DirName = directory.getAttribute("id"); + globalName += DirName +"/"; + DirStatus = directory.getAttribute("status"); + histo = directory.getAttribute("histo"); + temp = x[i].childNodes; + } + } + } + else { + for (i=0;i<x.length;i++) + { + if (x[i].getAttribute("id")==Selection[CountSel-1]){ + directory = x[i]; + DirName = directory.getAttribute("id"); + globalName += DirName +"/"; + DirStatus = directory.getAttribute("status"); + histo = directory.getAttribute("histo"); + + } + } + } + + + if (globalName!="Overall Status/"){ +// document.write(x.length + " name: " + globalName + " status " + DirStatus + " histo " + histo); + } + var htmlIndex = String(window.location); + id = htmlIndex.indexOf("index.html"); + if (id>0){ + htmlIndex = htmlIndex.substring(0,id-1); + } + dirList = directory.getElementsByTagName("dir"); + txt = '<hr />\n<h2>' + globalName+ '</h2> \n<font class="DQGroup">\n' + txt += '<ul><li>\n'; + num_lists = 1; + if (histo=="yes"){ + html = directory.firstChild; + while(html.nodeName!="a"){ + html=html.nextSibling; + } + txt +='<a href=\"'+htmlIndex + '/' + html.getAttribute("href")+'\">'+DirName+':</a>'; + } + else { + txt +=DirName +':' + } + txt+= ' <font class=\"'+DirStatus+'\">'+DirStatus+'</font>\n'; + prevDirTag = directory.getAttribute("tag"); + for (i=0;i<dirList.length;i++) + { + DirTag = dirList[i].getAttribute("tag"); + if (DirTag.length > prevDirTag.length) { // current dir is subdirectory of previous dir -> new item in new list + txt += '<ul><li>\n'; + num_lists++; + } + else if ( DirTag.length == prevDirTag.length ) { // current dir and previous dir in same motherdir -> new item + txt+='</li>\n<li>\n'; + } + else { // close list + txt+='</li>'; + diff = (prevDirTag.length-DirTag.length)/3; // count how many lists (= number of "sub" differences) to close + //document.write(diff +'\n'); + while (diff>0){ + txt+='</ul>\n</li>\n'; + diff--; + num_lists--; + } + txt+='<li>\n'; + } + DirName = dirList[i].getAttribute("id"); + DirStatus = dirList[i].getAttribute("status"); + histo = dirList[i].getAttribute("histo"); + if (histo=="yes") { // dir contains histos + html = dirList[i].firstChild; + while(html.nodeName!="a"){ + html=html.nextSibling; + } + txt +='<a href=\"'+htmlIndex + '/' + html.getAttribute("href")+'\">'+DirName+':</a>'; + } + else { + txt +=DirName +':' + } + txt+= ' <font class=\"'+DirStatus+'\">'+DirStatus+'</font>\n'; + prevDirTag = DirTag; + } + if (num_lists > 0) { + txt +='</li>\n'; + } + for(i=0; i<num_lists-1; i++){ + txt+='</ul>\n</li>\n'; + } + if (num_lists > 0) { + txt +='</ul>\n'; + } + txt+='</font>'; + document.getElementById("Display_dir").innerHTML=txt; +// createMenu('All') + } + +function cursor(message) +{ + document.getElementById("trail").innerHTML=message; + document.getElementById("trail").style.visibility="visible"; + // trail.innerHTML=message; + // trail.style.visibility="visible"; + // trail.style.position="absolute"; + // trail.style.left=event.clientX+10; + // trail.style.top=event.clientY; +// document.write("ok"); +} + +function hidecursor() +{ + trail.style.visibility="hidden"; +} + +var horizontal_offset="9px" //horizontal offset of hint box from anchor link + +/////No further editting needed + +var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change. +var ie=document.all +var ns6=document.getElementById&&!document.all + +function getposOffset(what, offsettype){ +var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop; +var parentEl=what.offsetParent; +while (parentEl!=null){ + totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop; + parentEl=parentEl.offsetParent; +} +return totaloffset; +} + +function iecompattest(){ +return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body +} + +function clearbrowseredge(obj, whichedge){ +var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1 +if (whichedge=="rightedge"){ + var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40 + dropmenuobj.contentmeasure=dropmenuobj.offsetWidth + if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) + edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset) +} +else{ + var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18 + dropmenuobj.contentmeasure=dropmenuobj.offsetHeight + if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) + edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight +} +return edgeoffset +} + +function showhint(menucontents, obj, e, tipwidth){ +if ((ie||ns6) && document.getElementById("hintbox")){ + dropmenuobj=document.getElementById("hintbox") + dropmenuobj.innerHTML=menucontents + dropmenuobj.style.left=dropmenuobj.style.top=-500 + if (tipwidth!=""){ + dropmenuobj.widthobj=dropmenuobj.style + dropmenuobj.widthobj.width=tipwidth + } + dropmenuobj.x=getposOffset(obj, "left") + dropmenuobj.y=getposOffset(obj, "top") + dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px" + dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px" + dropmenuobj.style.visibility="visible" + obj.onmouseout=hidetip +} +} + +function hidetip(e){ +dropmenuobj.style.visibility="hidden" +dropmenuobj.style.left="-500px" +} + +function createhintbox(){ +var divblock=document.createElement("div") +divblock.setAttribute("id", "hintbox") +document.body.appendChild(divblock) +} + +if (window.addEventListener) +window.addEventListener("load", createhintbox, false) +else if (window.attachEvent) +window.attachEvent("onload", createhintbox) +else if (document.getElementById) +window.onload=createhintbox diff --git a/DataQuality/DataQualityUtils/share/HanResultsTest.cxx b/DataQuality/DataQualityUtils/share/HanResultsTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..dd99280cf969ceab8c0f464ec3dfa1ea4ef4d4e2 --- /dev/null +++ b/DataQuality/DataQualityUtils/share/HanResultsTest.cxx @@ -0,0 +1,19 @@ +#include "DataQualityUtils/MonitoringFile.h" +#include <iostream> +#include <string> + +int main(int argc,char* argv[]){ + if(argc<6){ + std::cout<<"need ResultsDir, inputFile, hanconfig.hcfg ,min10_config.hcfg,min30_config.hcfg"<<std::endl; + return 5; + } + std::string outDir=std::string(argv[1]); + std::string inFile(argv[2]); + std::string conf(argv[3]); + std::string conf10(argv[4]); + std::string conf30(argv[5]); + dqutils::MonitoringFile mf(inFile); + std::cout<<"Running GetHanResults"<<std::endl; + mf.getHanResults(outDir,inFile,conf,conf10,conf30 ); + return 0; +} diff --git a/DataQuality/DataQualityUtils/share/MergeFilesTest.cxx b/DataQuality/DataQualityUtils/share/MergeFilesTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..aafee1797448eca6a19214ae8c18f15b1eb1ccf4 --- /dev/null +++ b/DataQuality/DataQualityUtils/share/MergeFilesTest.cxx @@ -0,0 +1,19 @@ +#include "DataQualityUtils/MonitoringFile.h" +#include <iostream> +#include <string> + +int main(int argc,char* argv[]){ + if(argc<3){ + std::cout<<"need listFilename outfilename"<<std::endl; + return 5; + } + std::string listFileName=std::string(argv[1]); + std::string outFileName(argv[2]); + dqutils::MonitoringFile mf; + std::cout<<"Running MergeFiles"<<std::endl; + mf.mergeFiles( outFileName, listFileName ); + std::cout<<"Running MergeLBintervals"<<std::endl; + mf.mergeLBintervals( outFileName ); + + return 0; +} diff --git a/DataQuality/DataQualityUtils/share/authentication.xml b/DataQuality/DataQualityUtils/share/authentication.xml new file mode 100644 index 0000000000000000000000000000000000000000..ca12e782a4ac65a55da6505d2790f81a29ab6024 --- /dev/null +++ b/DataQuality/DataQualityUtils/share/authentication.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" ?> +<connectionlist> + +<connection name="oracle://ATLAS_COOLPROD/ATLAS_COOLONL_TRIGGER"> + <parameter name="user" value="ATLAS_COOL_READER" /> + <parameter name="password" value="COOLRED4PRO" /> +</connection> + +<connection name="oracle://ATLAS_COOLPROD/ATLAS_COOL_SCT"> + <parameter name="user" value="ATLAS_COOL_READER" /> + <parameter name="password" value="COOLRED4PRO" /> +</connection> + +<connection name="oracle://ATLAS_COOLPROD/ATLAS_COOLOFL_DCS"> + <parameter name="user" value="ATLAS_COOL_READER" /> + <parameter name="password" value="COOLRED4PRO" /> +</connection> + +<connection name="oracle://ATLAS_COOLPROD/ATLAS_COOLONL_SCT"> + <parameter name="user" value="ATLAS_COOL_READER" /> + <parameter name="password" value="COOLRED4PRO" /> +</connection> + +# remove displaced pwd for ATLAS_COOLOFL_GLOBAL +<connection name="oracle://ATLAS_COOLWRITE/ATLAS_COOLOFL_GLOBAL"> + <parameter name="user" value="ATLAS_COOLOFL_GLOBAL_W" /> + <parameter name="password" value="" /> +</connection> + +</connectionlist> diff --git a/DataQuality/DataQualityUtils/share/compare.js b/DataQuality/DataQualityUtils/share/compare.js new file mode 100644 index 0000000000000000000000000000000000000000..8849e55822144cd0e779eeebc4cefe26713cc8d8 --- /dev/null +++ b/DataQuality/DataQualityUtils/share/compare.js @@ -0,0 +1,156 @@ + +// ************************************************************ +// $Id: compare.js,v 1.1 2008-09-17 12:36:36 mgwilson Exp $ +// ************************************************************ + +var xmlDoc; +var xmlhttp; + +function loadXMLDoc(url,hisname) +{ +xmlhttp=null; +if (window.XMLHttpRequest) + {// code for IE7, Firefox, Mozilla, etc. + xmlhttp=new XMLHttpRequest(); + } +else if (window.ActiveXObject) + {// code for IE5, IE6 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } +if (xmlhttp!=null) + { + xmlhttp.onreadystatechange=function(){ + onResponse(hisname); + } + xmlhttp.open("GET",url,true); + xmlhttp.send(null); + } +else + { + alert("Your browser does not support XMLHTTP."); + } +} + + + function isThere(url) { + var req= new XMLHttpRequest(); // XMLHttpRequest object + try { + req.open("HEAD", url, false); + req.send(null); + return req.status== 200 ? true : false; + } + catch (er) { + return false; + } + } + +function onResponse(hisname) +{ +if(xmlhttp.readyState!=4) return; +if(xmlhttp.status!=200) + { + alert("Problem retrieving XML data"); + return; + } +xmlDoc = xmlhttp.responseXML; +createStreamMenu(hisname); +} + +function createStreamMenu(hisname){ + x=xmlDoc.getElementsByTagName("Stream"); + text ="<select id=\"StreamInput\" onchange=\"createRunMenu(\'"+hisname+"\');\" >\n"; + text +="<option>Select Stream</option>\n"; + for (i=0;i<x.length;i++) + { + urlList = x[i].getElementsByTagName("html"); + url = urlList[urlList.length-1].childNodes[0].nodeValue+"/"+hisname+".html"; + if (isThere(url)) + { + text +="<option>"; + text +=x[i].getAttribute("id"); + text += "</option>\n"; + } + } + text +="</select>\n"; + document.getElementById("streamSelect").innerHTML=text; +} + +function createRunMenu(hisname){ + var mylist = document.getElementById("StreamInput"); + stream = mylist.options[mylist.selectedIndex].text; + x=xmlDoc.getElementsByTagName("Stream"); + text = " "; + for (i=0;i<x.length;i++){ + y = x[i].getAttribute("id"); + if (y==stream){ + runs = x[i].getElementsByTagName("Run"); + text +="<select id=\"RunInput\" onchange=\"find2ndHisto(\'"+hisname+"\',\'"+stream+"\');\" >\n"; + text +="<option>Select Run</option>\n"; + for (j=0;j<runs.length;j++){ + urlList = runs[j].getElementsByTagName("html"); + url = urlList[0].childNodes[0].nodeValue+"/"+hisname+".html"; + if (isThere(url)) + { + text +="<option>"; + text +=runs[j].getAttribute("runNumber"); + text += "</option>\n"; + } + } + } + } + text +="</select>\n"; + document.getElementById("runSelect").innerHTML=text; +} + + +function compare(runlist,hisname){ + loadXMLDoc(runlist,hisname); +} + +function insertIFrame(fromSource,tag){ + var insertionPt = document.getElementById(tag); + insertionPt.innerHTML=''; + var iframe=document.createElement('iframe'); + iframe.setAttribute('id', 'contentFRM'); + iframe.setAttribute('frameborder', '0'); + iframe.setAttribute('src',fromSource); + iframe.setAttribute('width', '100%'); + iframe.setAttribute('height','900'); + // iframe.setAttribute('scrolling','no'); + insertionPt.appendChild(iframe); +} + +function find2ndHisto(hisname,stream){ + mydiv = document.getElementById("compareButton"); + mydiv.style.display = "none"; //to hide it + var mylist = document.getElementById("RunInput"); + run = mylist.options[mylist.selectedIndex].text; + x=xmlDoc.getElementsByTagName("Stream"); + html=""; + for (i=0;i<x.length;i++){ + y = x[i].getAttribute("id"); + if (y==stream){ + runs = x[i].getElementsByTagName("Run"); + for (j=0;j<runs.length;j++){ + if(runs[j].getAttribute("runNumber")==run){ + html += (runs[j].getElementsByTagName("html")[0].childNodes[0].nodeValue+"/"+hisname+".html"); + } + } + } + } +// document.write(html); + insertIFrame(html,'secondHisto'); + mydiv = document.getElementById("compareButton"); + mydiv.style.display = "none"; //to hide it + test =document.getElementById('contentFRM'); + mydiv = test.getElementById("compareButton"); + document.write(mydiv.style.display); + mydiv.style.display = "none"; + document.write(mydiv.style.display); + +} + + + + + diff --git a/DataQuality/DataQualityUtils/share/generateDQIndexFiles.py b/DataQuality/DataQualityUtils/share/generateDQIndexFiles.py new file mode 100755 index 0000000000000000000000000000000000000000..476b69cc85f2e6c89dae64f645111ec9ecef4ff3 --- /dev/null +++ b/DataQuality/DataQualityUtils/share/generateDQIndexFiles.py @@ -0,0 +1,308 @@ +#!/bin/env python + +## ***************************************************************************** +VERSION = '$Id: generateDQIndexFiles.py,v 1.4 2009-03-31 15:49:37 ponyisi Exp $' +## ***************************************************************************** + +import os +import sys + + +def generateDQIndexFiles( installPath, project, indexFile, runListFile, htmlAddress ): + + print "" + print "!! generateDQIndexFiles !!" + print "CVS version:" + print VERSION + + origdir = os.getcwd() + os.chdir( installPath ) + + runDict, tmpDirList = buildRunDictionary() + + #printRunDictionary( runDict ) + deleteTmpDirectories( runDict, tmpDirList ) + writeIndexFile( runDict, indexFile, project ) + writeRunListXML( runDict, runListFile, htmlAddress ) + + os.chdir( origdir ) + print "" + + +def buildRunDictionary(): + + ## runDict is a dictionary of (run --> procDict) + ## procDict is a dictionary of (proc --> streamList) + + runDict = { } + allTmpDirList = [ ] + tmpDirList = [ ] + + for root, dirs, files in os.walk("."): + removeDir = [] + if "history_plot" in dirs: + dirs.remove("history_plot") + for name in dirs: + if( name.find('run_') > -1 ): + removeDir.append(name) + if len(removeDir) > 0: + stream = root.replace("./","") + proc = 0 + proci = stream.find("/") + if proci != -1: + try: + proc = int(stream[:proci]) + except ValueError: + proc = 0 + if proc != 0: + for rundir in dirs: + run = rundir.replace("run_","") + procDict = { } + streamList = [ ] + if run in runDict: + procDict = runDict[run] + if proc in procDict.keys(): + streamList = procDict[proc] + procText = str(proc) + "/" + shortStream = stream.replace(procText,"") + if shortStream.find("tmp_") == 0: + allTmpDirList.append( (stream,run,proc) ) + streamList.append(stream) + procDict[proc] = streamList + runDict[run] = procDict + for name in removeDir: + dirs.remove(name) + + for tmpStream,run,proc in allTmpDirList: + stream = tmpStream.replace("tmp_","") + procDict = runDict[run] + streamList = procDict[proc] + if stream in streamList: + tmpDir = tmpStream + "/run_" + run + tmpDirList.append(tmpDir) + streamList.remove(tmpStream) + + return runDict, tmpDirList + + +def deleteTmpDirectories( runDict, tmpDirList ): + for tmpDir in tmpDirList: + cmd = "rm -rf %s" % tmpDir + print cmd + os.system( cmd ) + + +def printRunDictionary( runDict ): + reversedRunKeys = [(int(x), x) for x in runDict.keys()] + reversedRunKeys.sort() + reversedRunKeys.reverse() + reversedRunKeys = [x[1] for x in reversedRunKeys]; del x + for run in reversedRunKeys: + margin = run + ": " + procDict = runDict[run] + sortedProcDictKeys = procDict.keys() + sortedProcDictKeys.sort() + for proc in sortedProcDictKeys: + streamList = procDict[proc] + sortedStreamList = [ ] + for stream in streamList: + if stream.find("Express") != -1: + sortedStreamList.append(stream) + streamList.remove(stream) + break + tmpSortedList = streamList + tmpSortedList.sort() + for stream in tmpSortedList: + sortedStreamList.append(stream) + print margin, sortedStreamList + margin = " " + + +def writeIndexFile( runDict, indexFile, project ): + import xmlrpclib, time + s = xmlrpclib.ServerProxy('http://atlasdqm.cern.ch:8080') + print "Writing HTML index file..." + f = open(indexFile,'w') + f.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') + f.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n') + f.write('<head>\n') + f.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n') + f.write('<title>ATLAS Data-Quality Monitoring: '+project+'</title>\n') + f.write('<link rel="stylesheet" href="atlasdqm.css" type="text/css" />\n') + f.write('<script type="text/javascript" src="AllDirs.js"><!-- dont contract--></script>') + f.write('</head>\n') + f.write('<body>\n\n') + f.write('<h1>'+project+' Monitoring</h1>\n\n') + f.write('<p><font class="Note">\n') + f.write('***Indicates reconstruction is in progress; histograms represent accumulated statistics and are temporary.\n') + f.write('</font></p>\n\n') + f.write('<table class="Catalogue">\n') + f.write('<tr><td><b>Run Number</b></td><td width="20"> </td>\n') + f.write(' <td><b>T0 Iteration</b></td><td width="20"> </td>\n') + f.write(' <td><b>Streams</b></td></tr>\n') + f.write('\n') + + bgcolor = '#bbffff' + writeBGColor = False + reversedRunDictKeys = [(int(x), x) for x in runDict.keys()] + reversedRunDictKeys.sort() + reversedRunDictKeys.reverse() + reversedRunDictKeys = [x[1] for x in reversedRunDictKeys]; del x + for run in reversedRunDictKeys: + mouseovertext = '' + try: + runinfo = s.get_run_information({'low_run': run, 'high_run': run}).get(run, None) + if runinfo != None: + mouseovertext = 'Run %s<br/>Run Start: %s<br/>' % (run, time.strftime('%Y-%m-%d %H:%M %Z', time.localtime(runinfo[4]))) + if runinfo[5] != 0: + mouseovertext += ('Run End: %s<br/>' % time.strftime('%Y-%m-%d %H:%M %Z', time.localtime(runinfo[5]))) + if runinfo[3] != -1: + mouseovertext += ('Event Filter Events: %s<br/>' % runinfo[3]) + mouseovertext += ('Project Tag: %s<br/>' % runinfo[1]) + if runinfo[2] != '': + mouseovertext += ('Partition: %s<br/>' % runinfo[2]) + except Exception, e: + print e + procDict = runDict[run] + nproc = len(procDict.keys()) + margin = ' <td rowspan="' + str(nproc) + '" valign="top" align="right">' + margin += '<a href="http://atlas-service-db-runlist.web.cern.ch/atlas-service-db-runlist/cgi-bin/runDetails.py?run=' + str(run) + """" onMouseover="showhint('""" + mouseovertext + """', this, event, '400px')">""" + margin += str(run) + '</a></td>\n' + margin += ' <td rowspan="' + str(nproc) + '"></td>\n' + sortedProcKeys = procDict.keys() + sortedProcKeys.sort() + for proc in sortedProcKeys: + if(writeBGColor): + f.write('<tr bgcolor="' + bgcolor + '">\n') + else: + f.write('<tr>\n') + f.write(margin) + f.write(' <td align="right">' + str(proc) + '</td>\n') + f.write(' <td></td>\n') + f.write(' <td>\n') + + endtext = "" + + streamList = procDict[proc] + sortedStreamList = [ ] + for stream in streamList: + if stream.find("Express") != -1: + sortedStreamList.append(stream) + streamList.remove(stream) + break + tmpSortedList = streamList + streamList.sort() + for stream in streamList: + sortedStreamList.append(stream) + + for stream in sortedStreamList: + link = stream + '/run_' + run + proci = stream.rfind("/") + shortStream = stream[proci+1:] + if shortStream.find("tmp_") == 0: + shortStream = shortStream.replace("tmp_","") + shortStream += "***" + f.write(endtext) + f.write(' [<a href="' + link + '">' + shortStream + '</a>]') + endtext = ' \n' + + f.write('\n </td>\n') + f.write('</tr>\n') + margin = "" + writeBGColor = not writeBGColor + + f.write('</table>\n') + f.write('</body>\n') + f.write('</html>\n') + f.close() + + +def writeRunListXML( runDict, runListFile, htmlAddress ): + print "Writing run list XML file..." + + f = open(runListFile,'w') + f.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n') + f.write('<DqFileCatalogue>\n') + + streamDict = {} + + for root, dirs, files in os.walk("."): + removeDir = [] + for name in dirs: + if( name.find('run_') > -1 ): + removeDir.append(name) + if len(removeDir) > 0: + stream = root.replace("./","") + runList = [] + proc = 0 + proci = stream.find("/") + if proci != -1: + try: + proc = int(stream[:proci]) + except ValueError: + proc = 0 + if proc != 0: + #f.write('<Stream id=\'' + stream + '\'>\n') + for rundir in dirs: + run = rundir.replace("run_","") + runList.append(run) + #address = htmlAddress + "/" + stream + "/run_" + run + #f.write('<Run runNumber=\'' + run + '\'>\n') + #f.write('<html>' + address + '</html>\n') + #f.write('</Run>\n') + #f.write('</Stream>\n') + streamDict[stream] = runList + + for name in removeDir: + dirs.remove(name) + + streamList = streamDict.keys() + sortedStreamList = [] + for stream in streamList: + if stream.find("Express") != -1: + sortedStreamList.append(stream) + streamList.remove(stream) + break + tmpSortedList = streamList + tmpSortedList.sort() + for stream in tmpSortedList: + sortedStreamList.append(stream) + + for stream in sortedStreamList: + f.write('<Stream id=\'' + stream + '\'>\n') + runList = streamDict[stream] + reversedRunList = runList + reversedRunList.sort() + reversedRunList.reverse() + for run in reversedRunList: + address = htmlAddress + "/" + stream + "/run_" + run + f.write('<Run runNumber=\'' + run + '\'>\n') + f.write('<html>' + address + '</html>\n') + f.write('</Run>\n') + f.write('</Stream>\n') + + f.write('</DqFileCatalogue>\n') + + +def usage(): + cmdi = sys.argv[0].rfind("/") + cmd = sys.argv[0][cmdi+1:] + print "" + print "Usage: ", cmd, "<installPath> <project> <indexFile> <runListFile> <htmlAddress>" + print "" + + +if __name__ == "__main__": + + if len(sys.argv) != 6: + usage() + sys.exit(0) + + installPath = sys.argv[1] + project = sys.argv[2] + indexFile = sys.argv[3] + runListFile = sys.argv[4] + htmlAddress = sys.argv[5] + + generateDQIndexFiles( installPath, project, indexFile, runListFile, htmlAddress ) + diff --git a/DataQuality/DataQualityUtils/share/returnHistory.js b/DataQuality/DataQualityUtils/share/returnHistory.js new file mode 100644 index 0000000000000000000000000000000000000000..80f5d4ebe49a209b798a908ccef0c167b4e1a4bc --- /dev/null +++ b/DataQuality/DataQualityUtils/share/returnHistory.js @@ -0,0 +1,24 @@ +function returnHistory (hisname) { + +//Define contents of page + contents= + '<body bgcolor="beige">'+ + '<IMG SRC='+ + hisname+ + '><p>'+ + '<A HREF="javascript:window.close()" >'+ + <h2>Close histo</h2> + + '</A>' + +//Create new Window + + options ="toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1"; + newwindow=window.open("","mywindow", options); + newwindow.document.write(contents); + newwindow.document.close(); + +} + + + + diff --git a/DataQuality/DataQualityUtils/src/CoolMdt.cxx b/DataQuality/DataQualityUtils/src/CoolMdt.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0183914b7b0173e3c5bd1e19d57b4683f4538b88 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/CoolMdt.cxx @@ -0,0 +1,360 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//************************************************* +// Class for the MDT interface with the COOL DB +// author Monica Verducci monica.verducci@cern.ch +//************************************************ +#include "DataQualityUtils/CoolMdt.h" + +//CORAL API include files +#include "CoralBase/Attribute.h" + +//COOL API include files (CoolKernel) +#include "CoolKernel/IDatabase.h" +#include "CoolKernel/IFolder.h" +#include "CoolKernel/IObjectIterator.h" +#include "CoolKernel/IObject.h" +#include "CoolKernel/Record.h" +#include "CoolKernel/Exception.h" +#include "CoolKernel/IDatabaseSvc.h" +#include "CoolKernel/StorageType.h" + +ClassImp(dqutils::CoolMdt) + +namespace dqutils{ + + void CoolMdt::initialize(){ m_fist_folder = true; } + + cool::IDatabasePtr + CoolMdt:: + coolDbInstance(std::string dbStr, bool readOnly) { + try { + // std::cout << "Opening database '" << dbStr << "'..."; + cool::IDatabaseSvc& dbSvc = this->databaseService(); + // std::cout << "done." << std::endl; + return dbSvc.openDatabase(dbStr.c_str(), readOnly); + } + catch (cool::DatabaseDoesNotExist&) { + std::cerr << "Error! Database does not exist!" << std::endl; + throw; + } + } + + cool::IFolderPtr + CoolMdt:: + coolFolderInstance(std::string folderStr) { + try { + cool::IFolderPtr folder = coolDb->getFolder(folderStr.c_str()); + // std::cout << "Browsing objects of '" << folderStr << "'" << std::endl; + return folder; + } + catch (cool::FolderNotFound& ) { + std::cerr << "Error! Folder '" << folderStr << "' does not exist!" << std::endl; + throw; + } + } + + +void + CoolMdt::coolDbFolder(std::string dbStr, std::string folderStr) { + coolDb = this->coolDbInstance(dbStr, false); + coolFolder=this->coolFolderInstance(folderStr); + } + + + void + CoolMdt:: + setSince(cool::Int64 run, cool::Int64 lumi) { + since = ((run << 32) + lumi); + } + + void + CoolMdt:: + setUntil(cool::Int64 run, cool::Int64 lumi) { + until = ((run << 32) + lumi); + } + + void + CoolMdt:: + setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU) { + this->setSince(runS, lumiS); + this->setUntil(runU, lumiU); + this->printIOV(); + } + + void + CoolMdt:: + setIOV(cool::Int64 run) { + this->setSince(run, 0); + this->setUntil(run, 4294967295U); + this->printIOV(); + } + + + void + CoolMdt:: + printIOV(){ + cool::Int64 runS=since>>32; + cool::Int64 lumiS=since-(runS<<32); + cool::Int64 runU=until>>32; + cool::Int64 lumiU=until-(runU<<32); + std::cout << "Using IOVrange [(" << runS << "," << lumiS << "),(" << runU << "," << lumiU << ")] " << "[" << since << "," << until << "]" << std::endl; + } + + + void + CoolMdt:: + CoolOpen(std::string dbStr) { + coolDb = this->coolDbInstance(dbStr, false); + + } + + CoolMdt:: + ~CoolMdt () { + coolFolder->flushStorageBuffer(); + coolDb->closeDatabase(); + // std::cout << "Cleared!" << std::endl; + } + + + cool::RecordSpecification + CoolMdt:: + createSpecDataDead() { + //std::cout << "Preparing RecordSpecification" << std::endl; + cool::RecordSpecification spec; + spec.extend("Chamber_Name",cool::StorageType::String255); + spec.extend("Dead_multilayer",cool::StorageType::String255); + spec.extend("Dead_layer",cool::StorageType::String255); + spec.extend("Dead_mezz",cool::StorageType::String255); + spec.extend("Dead_asd",cool::StorageType::String255); + spec.extend("Dead_tube",cool::StorageType::String4k); + + if(m_fist_folder){ + coolFolder=this->coolFolderInstance("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_DEAD"); + coolFolder->setupStorageBuffer(); + //std::cout << "Storage Buffer Setup Dead" << std::endl; + m_fist_folder = false; + } + if (!(spec==coolFolder->payloadSpecification())) { + std::cerr << "ERROR Source and destination folder specifications differ." << std::endl; + } + // std::cout << "CREATE DONE" << std::endl; + return spec; + } + + + coral::AttributeList + CoolMdt:: + createPayloadDataDead(std::string ChamberName, std::string DeadMultilayer, std::string DeadLayer, std::string DeadMezz, std::string DeadAsd, std::string DeadTube, const cool::RecordSpecification& spec) { + // std::cout << "createPayloadData "<< std::endl; + + coral::AttributeList payload = cool::Record( spec ).attributeList(); + + payload["Chamber_Name"].data<cool::String255>() = ChamberName; + payload["Dead_multilayer"].data<cool::String255>() = DeadMultilayer; + payload["Dead_layer"].data<cool::String255>() = DeadLayer; + payload["Dead_mezz"].data<cool::String255>() = DeadMezz; + payload["Dead_asd"].data<cool::String255>() = DeadAsd; + payload["Dead_tube"].data<cool::String4k>() = DeadTube; + + return payload; + } + + // noisy + + cool::RecordSpecification + CoolMdt:: + createSpecDataNoisy() { + //std::cout << "Preparing RecordSpecification" << std::endl; + cool::RecordSpecification spec; + spec.extend("Chamber_Name",cool::StorageType::String255); + spec.extend("Noisy_multilayer",cool::StorageType::String255); + spec.extend("Noisy_layer",cool::StorageType::String255); + spec.extend("Noisy_mezz",cool::StorageType::String255); + spec.extend("Noisy_asd",cool::StorageType::String255); + spec.extend("Noisy_tube",cool::StorageType::String4k); + + if(m_fist_folder){ + coolFolder=this->coolFolderInstance("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_NOISY"); + coolFolder->setupStorageBuffer(); + //std::cout << "Storage Buffer Setup Noisy" << std::endl; + m_fist_folder = false; + } + if (!(spec==coolFolder->payloadSpecification())) { + std::cerr << "ERROR Source and destination folder specifications differ." << std::endl; + } + // std::cout << "CREATE DONE" << std::endl; + return spec; + } + + + coral::AttributeList + CoolMdt:: + createPayloadDataNoisy(std::string ChamberName, std::string NoisyMultilayer, std::string NoisyLayer, std::string NoisyMezz, std::string NoisyAsd, std::string NoisyTube, const cool::RecordSpecification& spec) { + // std::cout << "createPayloadData "<< std::endl; + + coral::AttributeList payload = cool::Record( spec ).attributeList(); + + payload["Chamber_Name"].data<cool::String255>() = ChamberName; + payload["Noisy_multilayer"].data<cool::String255>() = NoisyMultilayer; + payload["Noisy_layer"].data<cool::String255>() = NoisyLayer; + payload["Noisy_mezz"].data<cool::String255>() = NoisyMezz; + payload["Noisy_asd"].data<cool::String255>() = NoisyAsd; + payload["Noisy_tube"].data<cool::String4k>() = NoisyTube; + + return payload; + } + // + + + void + CoolMdt:: + dump(cool::ChannelSelection selection) { + try { + cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until, selection,""); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + std::cout << element << std::endl; + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + std::cout << " dentro create payload" << std::endl; + } + } + + std::string + CoolMdt:: + dumpField(cool::ChannelId channelId, std::string field) { + std::string result =""; + try { + cool::ChannelSelection selection = cool::ChannelSelection(channelId); + cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until, selection,""); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + result = element.payloadValue(field); + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + return result; + } + + + int + CoolMdt:: + dumpCode(std::string channelName) { + std::string result = this->dumpField(this->getCoolFolder()->channelId(channelName.c_str()), "Code"); + return atoi(result.c_str()); + +} + + void + CoolMdt:: + dumpall() { + this->dump(cool::ChannelSelection::all()); + } + + + + void + CoolMdt:: + insertDeadFlag_withTag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string DeadMultilayer, std::string DeadLayer, std::string DeadMezz, std::string DeadAsd, std::string DeadTube, std::string cool_tag) { + + try { + + cool::RecordSpecification spec = this->createSpecDataDead(); + coral::AttributeList payload = this->createPayloadDataDead(ChamberName,DeadMultilayer , DeadLayer, DeadMezz, DeadAsd, DeadTube, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId, cool_tag); + // std::cout << "stored! With Tag =" << cool_tag <<std::endl; + } + catch (cool::Exception& e) { + std::cerr << " dentro create insert" << std::endl; + std::cerr << "Unknown exception caught!" << e.what() << std::endl; + } + } + + + void + CoolMdt:: + insertDeadFlag(cool::Int64 run, cool::ChannelId channelId,std::string ChamberName, std::string DeadMultilayer, std::string DeadLayer, std::string DeadMezz, std::string DeadAsd, std::string DeadTube) { + std::cout << "Trying to store payload [channel " << std::endl; + try { + + cool::RecordSpecification spec = this->createSpecDataDead(); + coral::AttributeList payload = this->createPayloadDataDead(ChamberName,DeadMultilayer , DeadLayer, DeadMezz, DeadAsd, DeadTube, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId); + // std::cout << "stored! without Tag" << std::endl; + } + catch (cool::Exception& e) { + std::cerr << " dentro create insert" << std::endl; + std::cerr << "Unknown exception caught!" << e.what() << std::endl; + } + } + // + + + + void + CoolMdt:: + insertNoisyFlag_withTag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string NoisyMultilayer, std::string NoisyLayer, std::string NoisyMezz, std::string NoisyAsd, std::string NoisyTube, std::string cool_tag) { + + try { + + cool::RecordSpecification spec = this->createSpecDataNoisy(); + coral::AttributeList payload = this->createPayloadDataNoisy(ChamberName,NoisyMultilayer , NoisyLayer, NoisyMezz, NoisyAsd, NoisyTube, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId, cool_tag); + // std::cout << "stored! With Tag =" << cool_tag <<std::endl; + } + catch (cool::Exception& e) { + std::cerr << " dentro create insert" << std::endl; + std::cerr << "Unknown exception caught!" << e.what() << std::endl; + } + } + + + void + CoolMdt:: + insertNoisyFlag(cool::Int64 run, cool::ChannelId channelId,std::string ChamberName, std::string NoisyMultilayer, std::string NoisyLayer, std::string NoisyMezz, std::string NoisyAsd, std::string NoisyTube) { + std::cout << "Trying to store payload [channel " << std::endl; + try { + + cool::RecordSpecification spec = this->createSpecDataNoisy(); + coral::AttributeList payload = this->createPayloadDataNoisy(ChamberName,NoisyMultilayer , NoisyLayer, NoisyMezz, NoisyAsd, NoisyTube, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId); + // std::cout << "stored! without Tag" << std::endl; + } + catch (cool::Exception& e) { + std::cerr << " dentro create insert" << std::endl; + std::cerr << "Unknown exception caught!" << e.what() << std::endl; + } + } + + + + + cool::IFolderPtr + CoolMdt:: + getCoolFolder() { + return this->coolFolder; + } + + cool::IDatabasePtr + CoolMdt:: + getCoolDb() { + return this->coolDb; + } + + +} //namespace dqutils diff --git a/DataQuality/DataQualityUtils/src/CoolRpc.cxx b/DataQuality/DataQualityUtils/src/CoolRpc.cxx new file mode 100644 index 0000000000000000000000000000000000000000..adc22d4e2201dbbbd9b11d6027cf71ed1fc3c450 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/CoolRpc.cxx @@ -0,0 +1,314 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//************************************************* +// Class for the RPC interface with the COOL DB +// author Monica Verducci monica.verducci@cern.ch +//************************************************ +#include "DataQualityUtils/CoolRpc.h" + +//CORAL API include files +#include "CoralBase/Attribute.h" + +//COOL API include files (CoolKernel) +#include "CoolKernel/IDatabase.h" +#include "CoolKernel/IFolder.h" +#include "CoolKernel/IObjectIterator.h" +#include "CoolKernel/IObject.h" +#include "CoolKernel/Record.h" +#include "CoolKernel/Exception.h" +#include "CoolKernel/IDatabaseSvc.h" +#include "CoolKernel/StorageType.h" + +ClassImp(dqutils::CoolRpc) + +namespace dqutils{ + + cool::IDatabasePtr + CoolRpc:: + coolDbInstance(std::string dbStr, bool readOnly) { + try { + //std::cout << "Opening database '" << dbStr << "'..."; + cool::IDatabaseSvc& dbSvc = this->databaseService(); + // std::cout << "done." << std::endl; + return dbSvc.openDatabase(dbStr.c_str(), readOnly); + } + catch (cool::DatabaseDoesNotExist&) { + std::cout << "Error! Database does not exist!" << std::endl; + throw; + } + } + + cool::IFolderPtr + CoolRpc:: + coolFolderInstance(std::string folderStr) { + try { + cool::IFolderPtr folder = coolDb->getFolder(folderStr.c_str()); + // std::cout << "Browsing objects of '" << folderStr << "'" << std::endl; + return folder; + } + catch (cool::FolderNotFound& ) { + std::cout << "Error! Folder '" << folderStr << "' does not exist!" << std::endl; + throw; + } + } + + +void + CoolRpc::coolDbFolder(std::string dbStr, std::string folderStr) { + coolDb = this->coolDbInstance(dbStr, false); + coolFolder=this->coolFolderInstance(folderStr); + } + + + void + CoolRpc:: + setSince(cool::Int64 run, cool::Int64 lumi) { + since = ((run << 32) + lumi); + } + + void + CoolRpc:: + setUntil(cool::Int64 iovmax, cool::Int64 lumi) { + until = ((iovmax << 32) + lumi); + } + + void + CoolRpc:: + setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU) { + this->setSince(runS, lumiS); + this->setUntil(runU, lumiU); + this->printIOV(); + } + + void + CoolRpc:: + setIOV(cool::Int64 run) { + this->setSince(run, 0); + this->setUntil(run, 4294967295U); + this->printIOV(); + } + + + void + CoolRpc:: + printIOV(){ + cool::Int64 runS=since>>32; + cool::Int64 lumiS=since-(runS<<32); + cool::Int64 runU=until>>32; + cool::Int64 lumiU=until-(runU<<32); + std::cout << "Using IOVrange [(" << runS << "," << lumiS << "),(" << runU << "," << lumiU << ")] " << "[" << since << "," << until << "]" << std::endl; + } + + + void + CoolRpc:: + CoolOpen(std::string dbStr) { + coolDb = this->coolDbInstance(dbStr, false); + + } + + CoolRpc:: + ~CoolRpc () { + coolDb->closeDatabase(); + std::cout << "Cleared!" << std::endl; + } + + + cool::RecordSpecification + CoolRpc:: + createSpecData() { + //std::cout << "Preparing RecordSpecification" << std::endl; + cool::RecordSpecification spec; + spec.extend("recEta",cool::StorageType::String4k); + spec.extend("detEta",cool::StorageType::String4k); + spec.extend("recPhi1",cool::StorageType::String4k); + spec.extend("recPhi2",cool::StorageType::String4k); + spec.extend("detPhi1",cool::StorageType::String4k); + spec.extend("detPhi2",cool::StorageType::String4k); + coolFolder=this->coolFolderInstance("/OFFLINE/OFFLINE_DQMF"); + if (!(spec==coolFolder->payloadSpecification())) { + std::cout << "ERROR Source and destination folder specifications differ." << std::endl; + } + // std::cout << "CREATE DONE" << std::endl; + return spec; + } + + + cool::RecordSpecification + CoolRpc:: + createSpecDataCondDB() { + //std::cout << "Preparing RecordSpecification" << std::endl; + cool::RecordSpecification spec; + spec.extend("PanelRes", cool::StorageType::String255); + spec.extend("StripStatus",cool::StorageType::String255); + coolFolder=this->coolFolderInstance("/OFFLINE/FINAL"); + if (!(spec==coolFolder->payloadSpecification())) { + std::cout << "ERROR Source and destination folder specifications differ." << std::endl; + } + // std::cout << "CREATE DONE" << std::endl; + return spec; + } + + coral::AttributeList + CoolRpc:: + createPayloadData(std::string recEta, std::string detEta, std::string recPhi1, std::string recPhi2, std::string detPhi1, std::string detPhi2, const cool::RecordSpecification& spec) { + // std::cout << "createPayloadData "<< std::endl; + + coral::AttributeList payload = cool::Record( spec ).attributeList(); + + payload["recEta"].data<cool::String4k>() = recEta; + payload["detEta"].data<cool::String4k>() = detEta; + payload["recPhi1"].data<cool::String4k>() = recPhi1; + + payload["recPhi2"].data<cool::String4k>() = recPhi2; + payload["detPhi1"].data<cool::String4k>() = detPhi1; + payload["detPhi2"].data<cool::String4k>() = detPhi2; + + // std::cout << "Creating payload: "; + // std::cout << "[RecEta : " << recEta << "],"; + // std::cout << "[DetEta : " << detEta << "],"<< std::endl; + return payload; + } + + coral::AttributeList + CoolRpc:: + createPayloadDataCondDB(std::string PanelRes,std::string StripStatus, const cool::RecordSpecification& spec) { + // std::cout << "createPayloadData "<< std::endl; + + coral::AttributeList payload = cool::Record( spec ).attributeList(); + + payload["PanelRes"].data<cool::String255>() = PanelRes; + payload["StripStatus"].data<cool::String255>() = StripStatus; + + return payload; + } + + void + CoolRpc:: + dump(cool::ChannelSelection selection) { + try { + cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until, selection,""); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + std::cout << element << std::endl; + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + std::cout << " dentro create payload" << std::endl; + } + } + + std::string + CoolRpc:: + dumpField(cool::ChannelId channelId, std::string field) { + std::string result =""; + try { + cool::ChannelSelection selection = cool::ChannelSelection(channelId); + cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until, selection,""); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + result = element.payloadValue(field); + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + return result; + } + + + int + CoolRpc:: + dumpCode(std::string channelName) { + std::string result = this->dumpField(this->getCoolFolder()->channelId(channelName.c_str()), "Code"); + return atoi(result.c_str()); + +} + + void + CoolRpc:: + dumpall() { + this->dump(cool::ChannelSelection::all()); + } + + + + // efficiency/calibration + + void + CoolRpc:: + insert_withTag(cool::Int64 run, cool::ChannelId channelId, std::string recEta, std::string detEta, std::string recPhi1, std::string recPhi2, std::string detPhi1, std::string detPhi2 , std::string cool_tag) { + // std::cout << "Trying to store payload [channel " << std::endl; + try { + + cool::RecordSpecification spec = this->createSpecData(); + coral::AttributeList payload = this->createPayloadData(recEta, detEta, recPhi1, recPhi2, detPhi1, detPhi2, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId, cool_tag); + // std::cout << "stored! With Tag =" << cool_tag <<std::endl; + } + catch (cool::Exception& e) { + std::cout << " dentro create insert" << std::endl; + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + } + + void + CoolRpc:: + insertCondDB_withTag(cool::Int64 run, cool::ChannelId channelId, std::string PanelRes, std::string StripStatus, std::string cool_tag) { + // std::cout << "Trying to store payload [channel " << std::endl; + try { + + cool::RecordSpecification spec = this->createSpecDataCondDB(); + coral::AttributeList payload = this->createPayloadDataCondDB(PanelRes, StripStatus, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId, cool_tag); + // std::cout << "stored! With Tag =" << cool_tag <<std::endl; + } + catch (cool::Exception& e) { + std::cout << " dentro create insert" << std::endl; + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + } + + void + CoolRpc:: + insert(cool::Int64 run, cool::ChannelId channelId, std::string recEta, std::string detEta, std::string recPhi1, std::string recPhi2, std::string detPhi1, std::string detPhi2) { + std::cout << "Trying to store payload [channel " << std::endl; + try { + + cool::RecordSpecification spec = this->createSpecData(); + coral::AttributeList payload = this->createPayloadData(recEta, detEta, recPhi1, recPhi2, detPhi1, detPhi2, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId); + std::cout << "stored! without Tag" << std::endl; + } + catch (cool::Exception& e) { + std::cout << " dentro create insert" << std::endl; + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + } + + + + + cool::IFolderPtr + CoolRpc:: + getCoolFolder() { + return this->coolFolder; + } + + cool::IDatabasePtr + CoolRpc:: + getCoolDb() { + return this->coolDb; + } + + +} //namespace dqutils diff --git a/DataQuality/DataQualityUtils/src/CoolTgc.cxx b/DataQuality/DataQualityUtils/src/CoolTgc.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4c36c4af27b2a82dfd0af4999e056cf062d7169f --- /dev/null +++ b/DataQuality/DataQualityUtils/src/CoolTgc.cxx @@ -0,0 +1,336 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//************************************************* +// Class for the TGC interface with the COOL DB +// copy of CoolMdt.cxx by Monica Verducci +// author Akimasa Ishikawa +//************************************************ +#include "DataQualityUtils/CoolTgc.h" + +//CORAL API include files +#include "CoralBase/Attribute.h" + +//COOL API include files (CoolKernel) +#include "CoolKernel/IDatabase.h" +#include "CoolKernel/IFolder.h" +#include "CoolKernel/IObjectIterator.h" +#include "CoolKernel/IObject.h" +#include "CoolKernel/Record.h" +#include "CoolKernel/Exception.h" +#include "CoolKernel/IDatabaseSvc.h" +#include "CoolKernel/StorageType.h" + +ClassImp(dqutils::CoolTgc) + +namespace dqutils{ + + cool::IDatabasePtr + CoolTgc:: + coolDbInstance(std::string dbStr, bool readOnly) { + try { + std::cout << "Opening database '" << dbStr << "'..."; + cool::IDatabaseSvc& dbSvc = this->databaseService(); + std::cout << "done." << std::endl; + return dbSvc.openDatabase(dbStr.c_str(), readOnly); + } + catch (cool::DatabaseDoesNotExist&) { + std::cout << "Error! Database does not exist!" << std::endl; + throw; + } + } + + cool::IFolderPtr + CoolTgc:: + coolFolderInstance(std::string folderStr) { + try { + cool::IFolderPtr folder = coolDb->getFolder(folderStr.c_str()); + // std::cout << "Browsing objects of '" << folderStr << "'" << std::endl; + return folder; + } + catch (cool::FolderNotFound& ) { + std::cout << "Error! Folder '" << folderStr << "' does not exist!" << std::endl; + throw; + } + } + + +void + CoolTgc::coolDbFolder(std::string dbStr, std::string folderStr) { + coolDb = this->coolDbInstance(dbStr, false); + coolFolder=this->coolFolderInstance(folderStr); + } + + + void + CoolTgc:: + setSince(cool::Int64 run, cool::Int64 lumi) { + since = ((run << 32) + lumi); + } + + void + CoolTgc:: + setUntil(cool::Int64 run, cool::Int64 lumi) { + until = ((run << 32) + lumi); + } + + void + CoolTgc:: + setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU) { + this->setSince(runS, lumiS); + this->setUntil(runU, lumiU); + this->printIOV(); + } + + void + CoolTgc:: + setIOV(cool::Int64 run) { + this->setSince(run, 0); + this->setUntil(run, 4294967295U); + this->printIOV(); + } + + + void + CoolTgc:: + printIOV(){ + cool::Int64 runS=since>>32; + cool::Int64 lumiS=since-(runS<<32); + cool::Int64 runU=until>>32; + cool::Int64 lumiU=until-(runU<<32); + std::cout << "Using IOVrange [(" << runS << "," << lumiS << "),(" << runU << "," << lumiU << ")] " << "[" << since << "," << until << "]" << std::endl; + } + + + void + CoolTgc:: + CoolOpen(std::string dbStr) { + coolDb = this->coolDbInstance(dbStr, false); + + } + + CoolTgc:: + ~CoolTgc () { + coolDb->closeDatabase(); + std::cout << "Cleared!" << std::endl; + } + + + cool::RecordSpecification + CoolTgc:: + createSpecDataDead() { + //std::cout << "Preparing RecordSpecification" << std::endl; + cool::RecordSpecification spec; + spec.extend("Chamber_Name",cool::StorageType::String255); + spec.extend("Dead_multilayer",cool::StorageType::String255); + spec.extend("Dead_tube",cool::StorageType::String4k); + + coolFolder=this->coolFolderInstance("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_DEAD"); + if (!(spec==coolFolder->payloadSpecification())) { + std::cout << "ERROR Source and destination folder specifications differ." << std::endl; + } + // std::cout << "CREATE DONE" << std::endl; + return spec; + } + + + coral::AttributeList + CoolTgc:: + createPayloadDataDead(std::string ChamberName, std::string DeadMultilayer, std::string DeadTube, const cool::RecordSpecification& spec) { + // std::cout << "createPayloadData "<< std::endl; + + coral::AttributeList payload = cool::Record( spec ).attributeList(); + + payload["Chamber_Name"].data<cool::String255>() = ChamberName; + payload["Dead_multilayer"].data<cool::String255>() = DeadMultilayer; + payload["Dead_tube"].data<cool::String4k>() = DeadTube; + + return payload; + } + + // noisy + + cool::RecordSpecification + CoolTgc:: + createSpecDataNoisy() { + //std::cout << "Preparing RecordSpecification" << std::endl; + cool::RecordSpecification spec; + spec.extend("Chamber_Name",cool::StorageType::String255); + spec.extend("Noisy_multilayer",cool::StorageType::String255); + spec.extend("Noisy_tube",cool::StorageType::String4k); + + coolFolder=this->coolFolderInstance("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_NOISY"); + if (!(spec==coolFolder->payloadSpecification())) { + std::cout << "ERROR Source and destination folder specifications differ." << std::endl; + } + // std::cout << "CREATE DONE" << std::endl; + return spec; + } + + + coral::AttributeList + CoolTgc:: + createPayloadDataNoisy(std::string ChamberName, std::string NoisyMultilayer, std::string NoisyTube, const cool::RecordSpecification& spec) { + // std::cout << "createPayloadData "<< std::endl; + + coral::AttributeList payload = cool::Record( spec ).attributeList(); + + payload["Chamber_Name"].data<cool::String255>() = ChamberName; + payload["Noisy_multilayer"].data<cool::String255>() = NoisyMultilayer; + payload["Noisy_tube"].data<cool::String4k>() = NoisyTube; + + return payload; + } + // + + + void + CoolTgc:: + dump(cool::ChannelSelection selection) { + try { + cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until, selection,""); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + std::cout << element << std::endl; + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + std::cout << " dentro create payload" << std::endl; + } + } + + std::string + CoolTgc:: + dumpField(cool::ChannelId channelId, std::string field) { + std::string result =""; + try { + cool::ChannelSelection selection = cool::ChannelSelection(channelId); + cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until, selection,""); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + result = element.payloadValue(field); + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + return result; + } + + + int + CoolTgc:: + dumpCode(std::string channelName) { + std::string result = this->dumpField(this->getCoolFolder()->channelId(channelName.c_str()), "Code"); + return atoi(result.c_str()); + +} + + void + CoolTgc:: + dumpall() { + this->dump(cool::ChannelSelection::all()); + } + + + + void + CoolTgc:: + insertDeadFlag_withTag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string DeadMultilayer, std::string DeadTube, std::string cool_tag) { + + try { + + cool::RecordSpecification spec = this->createSpecDataDead(); + coral::AttributeList payload = this->createPayloadDataDead(ChamberName,DeadMultilayer , DeadTube, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId, cool_tag); + std::cout << "stored! With Tag =" << cool_tag <<std::endl; + } + catch (cool::Exception& e) { + std::cout << " dentro create insert" << std::endl; + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + } + + + void + CoolTgc:: + insertDeadFlag(cool::Int64 run, cool::ChannelId channelId,std::string ChamberName, std::string DeadMultilayer, std::string DeadTube) { + std::cout << "Trying to store payload [channel " << std::endl; + try { + + cool::RecordSpecification spec = this->createSpecDataDead(); + coral::AttributeList payload = this->createPayloadDataDead(ChamberName,DeadMultilayer , DeadTube, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId); + std::cout << "stored! without Tag" << std::endl; + } + catch (cool::Exception& e) { + std::cout << " dentro create insert" << std::endl; + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + } + // + + + + void + CoolTgc:: + insertNoisyFlag_withTag(cool::Int64 run, cool::ChannelId channelId, std::string ChamberName, std::string NoisyMultilayer, std::string NoisyTube, std::string cool_tag) { + + try { + + cool::RecordSpecification spec = this->createSpecDataNoisy(); + coral::AttributeList payload = this->createPayloadDataNoisy(ChamberName,NoisyMultilayer , NoisyTube, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId, cool_tag); + std::cout << "stored! With Tag =" << cool_tag <<std::endl; + } + catch (cool::Exception& e) { + std::cout << " dentro create insert" << std::endl; + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + } + + + void + CoolTgc:: + insertNoisyFlag(cool::Int64 run, cool::ChannelId channelId,std::string ChamberName, std::string NoisyMultilayer, std::string NoisyTube) { + std::cout << "Trying to store payload [channel " << std::endl; + try { + + cool::RecordSpecification spec = this->createSpecDataNoisy(); + coral::AttributeList payload = this->createPayloadDataNoisy(ChamberName,NoisyMultilayer , NoisyTube, spec); + cool::ValidityKey since_u = (run << 32); + cool::ValidityKey until_u = (run+1) << 32; + coolFolder->storeObject(since_u, until_u, payload, channelId); + std::cout << "stored! without Tag" << std::endl; + } + catch (cool::Exception& e) { + std::cout << " dentro create insert" << std::endl; + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + } + + + + + cool::IFolderPtr + CoolTgc:: + getCoolFolder() { + return this->coolFolder; + } + + cool::IDatabasePtr + CoolTgc:: + getCoolDb() { + return this->coolDb; + } + + +} //namespace dqutils diff --git a/DataQuality/DataQualityUtils/src/HanOutputFile.cxx b/DataQuality/DataQualityUtils/src/HanOutputFile.cxx new file mode 100644 index 0000000000000000000000000000000000000000..54dee5dfc5b4dc18ab7a532400b0d94e78fb6f84 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/HanOutputFile.cxx @@ -0,0 +1,2144 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: HanOutputFile.cxx,v 1.59 2009-05-18 15:37:12 ponyisi Exp $ +// ********************************************************************** + +#include "DataQualityUtils/HanOutputFile.h" +#include "DataQualityInterfaces/HanUtils.h" + +#include <sstream> +#include <cstdlib> +#include <boost/algorithm/string/case_conv.hpp> +#include <TCanvas.h> +#include <TDirectory.h> +#include <TFile.h> +#include <TGraph.h> +#include <TH1.h> +#include <TH2.h> +#include <TIterator.h> +#include <TKey.h> +#include <TLegend.h> +#include <TProfile.h> +#include <TROOT.h> +#include <TStyle.h> +#include <TLatex.h> +#include <TLine.h> +#include <TText.h> +#include <TF1.h> +#include <TMath.h> +#include <THStack.h> + +ClassImp(dqutils::HanOutputFile) + +namespace { + +// class DisableMustClean { +// public: +// inline DisableMustClean() : useRecursiveDelete(gROOT->MustClean()) { gROOT->SetMustClean(false); } +// inline ~DisableMustClean() { gROOT->SetMustClean(useRecursiveDelete); } +// private: +// bool useRecursiveDelete; +// }; + +} // end unnamed namespace + + +namespace dqutils { + +// ********************************************************************* +// Public Methods +// ********************************************************************* + + std::vector<int> root_color_choices = { kBlue, kRed, kGray, kOrange, kViolet, kGreen+1 }; + +HanOutputFile:: +HanOutputFile() + : m_file(0) + , m_style(0) +{ + clearData(); +} + + +HanOutputFile:: +HanOutputFile( std::string fileName ) + : m_file(0) + , m_style(0) +{ + clearData(); + setFile( fileName ); +} + + +HanOutputFile:: +~HanOutputFile() +{ +// bool useRecursiveDelete = gROOT->MustClean(); +// gROOT->SetMustClean(false); + + clearData(); + +// gROOT->SetMustClean(useRecursiveDelete); +} + + +void +HanOutputFile:: +getAllGroupDirs( DirMap_t& dirmap, TDirectory* dir, std::string dirName ) +{ + if( dir == 0 ) + return; + + if( dirName != "" ) { + std::string name( dir->GetName() ); + if( name == "Config" || name == "Results" ) { + delete dir; + return; + } + + std::string::size_type i = name.find_last_of( '_' ); + if( i == (name.size()-1) ) { + delete dir; + return; + } + + DirMap_t::value_type dirmapVal( dirName, dir ); + dirmap.insert( dirmapVal ); + } + else { + DirMap_t::value_type dirmapVal( "<top_level>", dir ); + dirmap.insert( dirmapVal ); + } + + dir->cd(); + + TIter next( dir->GetListOfKeys() ); + TKey* key; + while( (key = dynamic_cast<TKey*>( next() )) != 0 ) { + // don't delete TDirectories + TObject* obj = key->ReadObj(); + TDirectory* subdir = dynamic_cast<TDirectory*>( obj ); + if( subdir != 0 ) { + std::string subdirName( subdir->GetName() ); + std::string fName(""); + if( dirName != "" ) { + fName += dirName; + fName += "/"; + } + fName += subdirName; + getAllGroupDirs( dirmap, subdir, fName ); + } + else { + delete obj; + } + } +} + + +void +HanOutputFile:: +getAllAssessments( AssMap_t& dirmap, TDirectory* dir ) +{ + dqi::DisableMustClean disabled; + + dir->cd(); + TIter next(dir->GetListOfKeys() ); + TKey* key; + while( (key = dynamic_cast<TKey*>( next() )) != 0 ) { + TObject* obj = key->ReadObj(); + //TH1* h = dynamic_cast<TH1*>( obj ); + if( dynamic_cast<TH1*>(obj) || dynamic_cast<TGraph*>(obj) ) { + const char * path(dir->GetPath() ); + std::string assName( obj->GetName() ); + AssMap_t::value_type AssmapVal(assName, path); + dirmap.insert( AssmapVal ); + } + delete obj; + } +} + + + +std::string +HanOutputFile:: +getStringName(std::string location) +{ + // bool success = gROOT->cd(location.c_str() ); + // if( !success ) { + if( gROOT->cd(location.c_str())==0 ){ + // std::cout << "Directory \"" << location << "\" is not in han output file\n"; + return "Undefined"; + } + TIter mylist(gDirectory->GetListOfKeys()); + std::string stringName("Undefined"); + TKey* key; + while( (key = dynamic_cast<TKey*>( mylist.Next() )) != 0 ) { + TObject* obj = key->ReadObj(); + stringName = (obj->GetName() ); + delete obj; + } + return stringName; +} + + +bool +HanOutputFile:: +containsDir(std::string dirname, std::string maindir) { + while (dirname.size()>0 && dirname[dirname.size()-1]=='/'){ + dirname = dirname.substr(0,dirname.size()-2); + } + while (dirname.size()>0 && dirname[0]=='/'){ + dirname = dirname.substr(1,dirname.size()); + } + std::size_t found = dirname.find_first_of("/",1); + std::string str = dirname.substr(0,found); + gROOT->cd(maindir.c_str()); + TKey* key = gDirectory->FindKey(str.c_str()); + bool status = false; + TObject* obj(0); + TDirectory* dirobj(0); + if ( key != 0 ) { + obj = key->ReadObj(); + dirobj = dynamic_cast<TDirectory*>( obj ); + } + if ( dirobj != 0 ) { + if(found!=std::string::npos) { + maindir = maindir + "/" + str; + dirname = dirname.substr(found+1,dirname.size()); + status = containsDir(dirname,maindir); + } + else { + status = true; + } + } + delete obj; + return status; +} + + +double +HanOutputFile:: +getNEntries( std::string location, std::string histname ) +{ + + if( m_file == 0 ) { + std::cerr << "HanOutputFile::getNEntries(): " + << "No input file is open\n"; + return 0.0; + } + + double Nentries = 0.0; + m_file->cd(location.c_str()); + //gdirectory->cd(location.c_str() ); + TH1* h(0); + gDirectory->GetObject( histname.c_str(),h ); + if( h != 0 ) { + Nentries = h->GetEntries(); + delete h; + } + TGraph* g(0); + gDirectory->GetObject( histname.c_str(),g ); + if ( g != 0 ) { + Nentries = g->GetN(); + delete g; + } + + return Nentries; +} + +double +HanOutputFile:: +getNEntries( const TObject* obj ) +{ + if (const TH1* h = dynamic_cast<const TH1*>(obj)) { + return h->GetEntries(); + } else if (const TGraph* g = dynamic_cast<const TGraph*>(obj)) { + return g->GetN(); + } else { + std::cerr << "HanOutputFile::getNEntries(): " + << "provided object is not a histogram or graph\n"; + return 0.0; + } +} + +std::string +HanOutputFile:: +getInfo(std::string location) +{ + dqi::DisableMustClean disabled; + + gROOT->cd(location.c_str() ); + TIter mylist(gDirectory->GetListOfKeys()); + std::string value; + TKey* key; + while( (key = dynamic_cast<TKey*>( mylist.Next() )) != 0 ) { + TObject* obj = key->ReadObj(); + TDirectory* subdir = dynamic_cast<TDirectory*>( obj ); + if(subdir!=0){ + std::string name_subdir=subdir->GetName(); + gROOT->cd((location+"/"+name_subdir).c_str() ); + TIter mylist1( gDirectory->GetListOfKeys() ); + TKey* key1; + while( (key1 = dynamic_cast<TKey*>( mylist1.Next() )) != 0 ) { + TObject* obj1 = key1->ReadObj(); + TDirectory* subsubdir = dynamic_cast<TDirectory*>( obj1 ); + if(subsubdir!=0){ + std::string name_subsubdir=obj1->GetName(); + gROOT->cd((location+"/"+name_subdir+"/"+name_subsubdir).c_str() ); + TIter mylist2( gDirectory->GetListOfKeys() ); + TKey* key2; + while( (key2 = dynamic_cast<TKey*>( mylist2.Next() )) != 0 ) { + TObject* obj2 = key2->ReadObj(); + TDirectory* finaldir = dynamic_cast<TDirectory*>( obj2 ); + if (finaldir!=0){ + std::string name_finaldir=obj2->GetName(); + gROOT->cd((location+"/"+name_subdir+"/"+name_subsubdir+"/"+name_finaldir).c_str() ); + TIter mylist3( gDirectory->GetListOfKeys() ); + TKey* key3; + while( (key3 = dynamic_cast<TKey*>( mylist3.Next() )) != 0 ) { + TObject* obj3 = key3->ReadObj(); + std::string value_info=obj3->GetName(); + value+=(name_subsubdir+name_finaldir+": "+value_info+" "); + delete obj3; + } + gROOT->cd((location+"/"+name_subdir+"/"+name_subsubdir).c_str() ); + } + else if(name_subsubdir!="name" && name_subsubdir!="Status" && name_subsubdir != "display" ){ + //else if(name_subsubdir!="name" && name_subsubdir!="Status"){ + std::string value_info=obj2->GetName(); + value+=(name_subsubdir+": "+value_info+" "); + } + delete obj2; + } + gROOT->cd((location+"/"+name_subdir).c_str() ); + } + else if(name_subdir!="name" && name_subdir!="Status"){ + std::string value_info=obj1->GetName(); + value+=(name_subdir+": "+value_info+" "); + } + delete obj1; + } + gROOT->cd((location).c_str() ); + } + delete obj; + } + return value; +} + + +std::string +HanOutputFile:: +getIndentation( std::string pathName, std::string leadingSpace ) +{ + std::string space = leadingSpace; + std::string::size_type i = pathName.find_first_of('/'); + if( i != std::string::npos ) { + std::string subPath( pathName, i+1, std::string::npos ); + space += " "; + return getIndentation( subPath, space ); + } + return space; +} + + +bool +HanOutputFile:: +setFile( std::string fileName ) +{ + clearData(); + if (fileName == "") return false; + m_file = TFile::Open( fileName.c_str() ); + if( m_file != 0 ) + return true; + + return false; +} + + +void +HanOutputFile:: +printAllDQGroups() +{ + if( m_file == 0 ) { + std::cerr << "HanOutputFile::printAllGroupDirs(): " + << "No input file is open\n"; + return; + } + + if( m_indirMap.size() == 0 ) { + getAllGroupDirs( m_indirMap, m_file, "" ); + } + + DirMap_t::const_iterator idirend = m_indirMap.end(); + for( DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir ) { + std::string idirName = idir->first; + const char * path(idir->second->GetPath() ); + std::cout << "name: " << idirName << ", path: " << path << "\n"; + } +} + + +void +HanOutputFile:: +printAllDQAssessments() +{ + streamAllDQAssessments( std::cout, false ); +} + +void +HanOutputFile:: +printHistoAssessments() +{ + streamHistoAssessments( std::cout, false ); +} + + +std::string +HanOutputFile:: +stringListSystemPaths( std::string location ) +{ + if( m_file == 0 ) { + std::cerr << "HanOutputFile::stringListSystemPaths(): " + << "No input file is open\n"; + return ""; + } + + if( m_indirMap.size() == 0 ) { + getAllGroupDirs( m_indirMap, m_file, "" ); + } + + std::string result(""); + + DirMap_t::const_iterator idirend = m_indirMap.end(); + for(DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir ) { + + DirToAssMap_t::const_iterator aMapIter = m_assessMap.find( idir->first ); + if( aMapIter == m_assessMap.end() ) { + AssMap_t* aMap = new AssMap_t(); + DirToAssMap_t::value_type aMapVal( idir->first, aMap ); + aMapIter = m_assessMap.insert( aMapVal ).first; + getAllAssessments( *aMap, idir->second ); + } + + AssMap_t::const_iterator ias = aMapIter->second->begin(); + if( ias != aMapIter->second->end() ) { + std::string hisPath = ias->second; + std::string::size_type sepi = hisPath.find(':'); + if( sepi != std::string::npos ) { + hisPath = std::string( hisPath, sepi+1, std::string::npos ); + } + std::string completeDir(location); + completeDir += hisPath; + result += completeDir; + result += " "; + } + } + return result; +} + + +std::string +HanOutputFile:: +stringAllDQAssessments() +{ + std::ostringstream result; + streamAllDQAssessments( result, true ); + return result.str(); +} + +std::string +HanOutputFile:: +stringHistoAssessments() +{ + std::ostringstream result; + streamHistoAssessments( result, true ); + return result.str(); +} + +std::string +HanOutputFile:: +stringAllHistograms() +{ + std::ostringstream result; + streamAllHistograms( result, true ); + return result.str(); +} + +void +HanOutputFile:: +streamAllDQAssessments( std::ostream& o, bool streamAll ) +{ + if( m_file == 0 ) { + std::cerr << "HanOutputFile::streamAllDQAssessments(): " + << "No input file is open\n"; + return; + } + + if( m_indirMap.size() == 0 ) { + getAllGroupDirs( m_indirMap, m_file, "" ); + } + + DirMap_t::const_iterator idirend = m_indirMap.end(); + for(DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir ) { + std::string idirName = idir->first; + std::string pathname( idir->second->GetPath() ); + std::string::size_type i = pathname.find_last_of( '/' ); + if( i != (pathname.size()-1) ) { + pathname+="/"; + } + std::string pathnameS=pathname+"Results/Status"; + std::string pathnameA=pathname+"Config/name"; + std::string idirStatus =getStringName(pathnameS); + std::string idirAlg =getStringName(pathnameA); + std::string indent = (idirName == "<top_level>") ? "" : getIndentation( idirName, " " ); + if( !streamAll ) { + std::string::size_type idirNamei = idirName.find_last_of('/'); + if( idirNamei != std::string::npos ) { + idirName = std::string( idirName, idirNamei+1, std::string::npos ); + } + } + std::string formattedName(indent); + formattedName += idirName; + + // left-align this text + const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield); + // set the width of the next item to be printed + o.width(40); + o << formattedName << " "; + // return to normal right-alignment + o.setf(std::ios_base::right, std::ios_base::adjustfield); + o.width(9); + o << idirStatus << " "; + o.width(30); + o << idirAlg; + if( streamAll ) { + o << " dir\n"; + } + else { + o << "\n"; + } + o.flags(savedFlags); + + DirToAssMap_t::const_iterator aMapIter = m_assessMap.find( idir->first ); + if( aMapIter == m_assessMap.end() ) { + AssMap_t* aMap = new AssMap_t(); + DirToAssMap_t::value_type aMapVal( idir->first, aMap ); + aMapIter = m_assessMap.insert( aMapVal ).first; + getAllAssessments( *aMap, idir->second ); + } + + AssMap_t::const_iterator aend = aMapIter->second->end(); + for( AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias ) { + std::string hisName = ias->first; + std::string hisPath = ias->second; + std::string Path1 = hisPath + "/"+ hisName + "_/Results"; + std::string info1 = getInfo(Path1); + std::string Path2 = hisPath + "/"+ hisName + "_/Config"; + std::string info2 = getInfo(Path2); + std::string formattedHistName(indent); + std::string status = getStringName(Path1+"/Status"); + std::string algo = getStringName(Path2+"/name"); + gDirectory->cd(pathname.c_str() ); + //TH1 *h; + TObject* h; + gDirectory->GetObject(hisName.c_str() ,h); + std::string hisTitle = h->GetTitle(); + formattedHistName += " "; + formattedHistName += hisName; + // left-align this text + const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield); + // set the width of the next item to be printed + o.width(40); + o << formattedHistName << " "; + // return to normal right-alignment + o.setf(std::ios_base::right, std::ios_base::adjustfield); + o.width(9); + o << status << " "; + o.width(30); + o << algo; + if( streamAll ) { + o << " ass entries: " << getNEntries(h) << " "; + TH1* h1; + if ((h1 = dynamic_cast<TH1*>(h)) && h1->GetDimension() == 1) { + o << " Underflow: " << h1->GetBinContent(0) << " Overflow: " << h1->GetBinContent(h1->GetNbinsX()+1) << " " ; + } + if( info1 != "" && info2 != "" ) { + o <<"Config " << "Config " << info2 << " Results " << "Results " << info1 << " title " << hisTitle << "\n"; + } + else if( info1 != "" ) { + o << "Results Results "<< info1 << " title " << hisTitle << "\n"; + } + else if( info2 != "" ) { + o << "Config Config " << info2 << " title " << hisTitle << "\n"; + } + else { + o << " title " << hisTitle << "\n"; + } + } + else { + o << "\n"; + } + o.flags(savedFlags); + } + } +} + + +void +HanOutputFile:: +streamHistoAssessments( std::ostream& o, bool streamAll ) +{ + if( m_file == 0 ) { + std::cerr << "HanOutputFile::streamHistoAssessments(): " + << "No input file is open\n"; + return; + } + + if( m_indirMap.size() == 0 ) { + getAllGroupDirs( m_indirMap, m_file, "" ); + } + + DirMap_t::const_iterator idirend = m_indirMap.end(); + for(DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir ) { + std::string idirName = idir->first; + std::string pathname( idir->second->GetPath() ); + std::string::size_type i = pathname.find_last_of( '/' ); + if( i != (pathname.size()-1) ) { + pathname+="/"; + } + std::string idirStatus = "Undefined"; + std::string idirAlg = "Undefined"; + std::string indent = (idirName == "<top_level>") ? "" : getIndentation( idirName, " " ); + if( !streamAll ) { + std::string::size_type idirNamei = idirName.find_last_of('/'); + if( idirNamei != std::string::npos ) { + idirName = std::string( idirName, idirNamei+1, std::string::npos ); + } + } + std::string formattedName; + formattedName += idirName; + + DirToAssMap_t::const_iterator aMapIter = m_assessMap.find( idir->first ); + if( aMapIter == m_assessMap.end() ) { + AssMap_t* aMap = new AssMap_t(); + DirToAssMap_t::value_type aMapVal( idir->first, aMap ); + aMapIter = m_assessMap.insert( aMapVal ).first; + getAllAssessments( *aMap, idir->second ); + } + + AssMap_t::const_iterator aend = aMapIter->second->end(); + for( AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias ) { + std::string hisName = ias->first; + std::string hisPath = ias->second; + std::string formattedHistName; + gDirectory->cd(pathname.c_str() ); + //TH1 *h; + TObject* h; + gDirectory->GetObject(hisName.c_str() ,h); + std::string hisTitle(h->GetTitle()); + formattedHistName += ""; + formattedHistName += hisName; + // left-align this text + const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield); + o.width(40); + + if( streamAll ) { + o << hisPath << "/" << formattedHistName << " " << "\n"; + } + else { + o << "\n"; + } + o.flags(savedFlags); + } + } +} + +void +HanOutputFile:: +streamAllHistograms( std::ostream& o, bool streamAll ) +{ + if( m_file == 0 ) { + std::cerr << "HanOutputFile::streamAllDQAssessments(): " + << "No input file is open\n"; + return; + } + + if( m_indirMap.size() == 0 ) { + getAllGroupDirs( m_indirMap, m_file, "" ); + } + + DirMap_t::const_iterator idirend = m_indirMap.end(); + for(DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir ) { + std::string idirName = idir->first; + std::string pathname( idir->second->GetPath() ); + std::string::size_type i = pathname.find_last_of( '/' ); + if( i != (pathname.size()-1) ) { + pathname+="/"; + } + std::string idirStatus = "Undefined"; + std::string idirAlg = "Undefined"; + std::string indent = (idirName == "<top_level>") ? "" : getIndentation( idirName, " " ); + if( !streamAll ) { + std::string::size_type idirNamei = idirName.find_last_of('/'); + if( idirNamei != std::string::npos ) { + idirName = std::string( idirName, idirNamei+1, std::string::npos ); + } + } + std::string formattedName(indent); + formattedName += idirName; + + // left-align this text + const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield); + // set the width of the next item to be printed + o.width(40); + o << formattedName << " "; + // return to normal right-alignment + o.setf(std::ios_base::right, std::ios_base::adjustfield); + o.width(9); + o << idirStatus << " "; + o.width(30); + o << idirAlg; + if( streamAll ) { + o << " dir\n"; + } + else { + o << "\n"; + } + o.flags(savedFlags); + + DirToAssMap_t::const_iterator aMapIter = m_assessMap.find( idir->first ); + if( aMapIter == m_assessMap.end() ) { + AssMap_t* aMap = new AssMap_t(); + DirToAssMap_t::value_type aMapVal( idir->first, aMap ); + aMapIter = m_assessMap.insert( aMapVal ).first; + getAllAssessments( *aMap, idir->second ); + } + + AssMap_t::const_iterator aend = aMapIter->second->end(); + for( AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias ) { + std::string hisName = ias->first; + std::string hisPath = ias->second; + // std::string Path1 = hisPath + "/"+ hisName + "_/Results"; + // std::string info1 = getInfo(Path1); + std::string info1, info2; + // std::string Path2 = hisPath + "/"+ hisName + "_/Config"; + // std::string info2 = getInfo(Path2); + std::string formattedHistName(indent); + std::string status = "Undefined"; + std::string algo = "Undefined"; + gDirectory->cd(pathname.c_str() ); + //TH1 *h; + TObject* h; + gDirectory->GetObject(hisName.c_str() ,h); + std::string hisTitle(h->GetTitle()); + formattedHistName += " "; + formattedHistName += hisName; + // left-align this text + const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield); + // set the width of the next item to be printed + o.width(40); + o << formattedHistName << " "; + // return to normal right-alignment + o.setf(std::ios_base::right, std::ios_base::adjustfield); + o.width(9); + o << status << " "; + o.width(30); + o << algo; + if( streamAll ) { + o << " ass entries: " << getNEntries(h) << " "; + if( info1 != "" && info2 != "" ) { + o <<"Config " << "Config " << info2 << " Results " << "Results " << info1 << " title " << hisTitle << "\n"; + } + else if( info1 != "" ) { + o << "Results Results "<< info1 << " title " << hisTitle << "\n"; + } + else if( info2 != "" ) { + o << "Config Config " << info2 << " title " << hisTitle << "\n"; + } + else { + o << " title " << hisTitle << "\n"; + } + } + else { + o << "\n"; + } + o.flags(savedFlags); + } + } +} + +int +HanOutputFile:: +saveAllHistograms( std::string location, bool drawRefs, std::string run_min_LB ) +{ + if( m_file == 0 ) { + std::cerr << "HanOutputFile::saveAllHistograms(): " + << "No input file is open\n"; + return 0; + } + + if( m_indirMap.size() == 0 ) { + getAllGroupDirs( m_indirMap, m_file, "" ); + } + + int nSaved = 0; + + DirMap_t::const_iterator idirend = m_indirMap.end(); + for(DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir ) { + DirToAssMap_t::const_iterator aMapIter = m_assessMap.find( idir->first ); + if( aMapIter == m_assessMap.end() ) { + AssMap_t* aMap = new AssMap_t(); + DirToAssMap_t::value_type aMapVal( idir->first, aMap ); + aMapIter = m_assessMap.insert( aMapVal ).first; + getAllAssessments( *aMap, idir->second ); + } + AssMap_t::const_iterator aend = aMapIter->second->end(); + for( AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias ) { + std::string hisName = ias->first; + std::string hisPath = ias->second; + std::string::size_type sepi = hisPath.find(':'); + if( sepi != std::string::npos ) { + hisPath = std::string( hisPath, sepi+1, std::string::npos ); + } + std::string completeDir(location); + // completeDir += "/"; + completeDir += hisPath; + completeDir += "/"; + std::cout << "Saving " << completeDir << " " << hisName << "\n" << std::flush; + bool isSaved = saveHistogramToFile(hisName,completeDir,idir->second,drawRefs,run_min_LB, + (hisPath + "/" + hisName)); + if( isSaved ) + ++nSaved; + } + } + return nSaved; +} + + +bool +HanOutputFile:: +saveHistogramToFile( std::string nameHis, std::string location, TDirectory* groupDir, bool drawRefs,std::string run_min_LB, std::string pathName){ + dqi::DisableMustClean disabled; + groupDir->cd(); + + gStyle->SetFrameBorderMode(0); + gStyle->SetFrameFillColor(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetCanvasColor(0); + gStyle->SetTitleColor(0); + gStyle->SetStatColor(0); + gStyle->SetFillColor(1); + gStyle->SetPalette(1,0); + gStyle->SetTitleFontSize(0.06); + gStyle->SetTitleH(0.06); + gStyle->SetMarkerStyle(20); + gStyle->SetOptStat(111100); + gStyle->SetStatBorderSize(0); + gStyle->SetStatX(0.99); + gStyle->SetStatY(0.99); + gStyle->SetStatW(0.2); + gStyle->SetStatH(0.1); + + + gROOT->SetBatch(); + std::string pathname( groupDir->GetPath() ); + std::string display =""; + bool WasCollectionReference = false; + bool LookForDisplay = containsDir("Config/annotations/display",(pathname + "/"+ nameHis + "_")); + if(LookForDisplay) { + display = getStringName(pathname + "/"+ nameHis + "_/Config/annotations/display" ); + } + // Look for Draw Options + std::size_t found = display.find("Draw="); + std::string drawopt =""; + while (found!=std::string::npos){ + std::size_t found1 = display.find_first_of(",",found+1); + if (found1!=std::string::npos){ + drawopt +=boost::algorithm::to_lower_copy(display.substr(found+5,found1-found-5)); + } + else { + drawopt +=boost::algorithm::to_lower_copy(display.substr(found+5,display.size())); + } + found=display.find("Draw=",found+1); + } + // Look for Draw Options + found = display.find("DrawRef="); + std::string drawrefopt =""; + while (found!=std::string::npos){ + std::size_t found1 = display.find_first_of(",",found+1); + if (found1!=std::string::npos){ + drawrefopt +=boost::algorithm::to_lower_copy(display.substr(found+8,found1-found-8)); + } + else { + drawrefopt +=boost::algorithm::to_lower_copy(display.substr(found+8,display.size())); + } + found=display.find("DrawRef=",found+1); + } + if (drawrefopt=="") { drawrefopt = drawopt; } + + // should we rename "Data" ? + found = display.find("DataName"); + std::string datatitle; + if (found == std::string::npos) { + datatitle = "Data"; + } + while (found!=std::string::npos){ + std::size_t found1 = display.find_first_of(",",found+1); + if (found1!=std::string::npos){ + datatitle += display.substr(found+9,found1-found-9); + } + else { + datatitle += display.substr(found+9,display.size()); + } + found=display.find("DataName",found+1); + } + + groupDir->cd(); + TKey* hkey = groupDir->FindKey( nameHis.c_str() ); + if( hkey == 0 ) { + std::cerr << "Did not find TKey for \"" << nameHis << "\", will not save this histogram.\n"; + return false; + } + TLegend* legend(0); + TObject* hobj = hkey->ReadObj(); + TObject* ref(0); + TH1* hRef(0); + std::vector<TH1*> hRefs; + bool hasPlotted(false); + TH1* h = dynamic_cast<TH1*>( hobj ); + TH2* h2 = dynamic_cast<TH2*>( h ); + TGraph* g = dynamic_cast<TGraph*>( hobj ); + + std::string name=nameHis; + name+=".png"; + std::string::size_type i = location.find_last_of( '/' ); + if( i != (location.size()-1) ) { + location+="/"; + } + name=location + name; + std::string AlgoName=getStringName(pathname+"/"+nameHis+"_/Config/name"); + int ww = 550; + int wh = 490; + found = display.find("TCanvas",found+1); + if (found!=std::string::npos){ + std::size_t found1 = display.find_first_of(",",found+1); + ww = std::atoi((display.substr(found+8,found1-found-8)).c_str() ); + found = display.find_first_of(")",found1+1); + wh = std::atoi((display.substr(found1+1,found-found1-1)).c_str() ); + } + + if( h!=0 ){ + + TCanvas *myC = new TCanvas( nameHis.c_str(), "myC", ww, wh ); + + // if( h->GetMinimum() >= 0) { + // gPad->SetLogy(display.find("LogY")!=std::string::npos ); + // } + // if( h->GetBinLowEdge(1) > 0) { + // gPad->SetLogx(display.find("LogX")!=std::string::npos ); + // } + gPad->SetGridx(display.find("SetGridx")!=std::string::npos ); + gPad->SetGridy(display.find("SetGridy")!=std::string::npos ); + std::size_t found = display.find("SetPalette"); + if (found!=std::string::npos) { + std::size_t found1 = display.find_first_of("(",found+1); + std::size_t found2 = display.find_first_of(",)",found+1); + std::string cn =display.substr(found1+1,found2-found1-1); + int n1=std::strtol(cn.c_str(),NULL,0); + gStyle->SetPalette((Int_t) n1); + } + found = display.find("SetGridStyle"); + if (found!=std::string::npos) { + std::size_t found1 = display.find_first_of("(",found+1); + std::size_t found2 = display.find_first_of(",)",found+1); + std::string cn =display.substr(found1+1,found2-found1-1); + int n1=std::strtol(cn.c_str(),NULL,0); + gStyle->SetGridStyle((Style_t) n1); + } + + /******************* for plotting fit function on top of histogram ******************/ + found = display.find("gaus"); + if (found!=std::string::npos ) { + Double_t minstat=0.; + std::size_t fpos1,fpos2,fpos; + fpos=display.find("MinStat"); + if (fpos!= std::string::npos){ + fpos1=display.find("(",fpos+1); + if (fpos1!=std::string::npos) { + fpos2 = display.find(")",fpos1+1); + if (fpos2!=std::string::npos) { + std::string s_minstat=display.substr(fpos1+1,fpos2-fpos1-1); + minstat=std::strtod(s_minstat.c_str(),NULL); + } + + } + } + std::string fitopt(""); + fpos=display.find("FitOption"); + if (fpos!= std::string::npos){ + fpos1=display.find("(",fpos+1); + if (fpos1!=std::string::npos) { + fpos2 = display.find(")",fpos1+1); + if (fpos2!=std::string::npos) { + fitopt=display.substr(fpos1+1,fpos2-fpos1-1); + } + } + } + //plot double gaus + std::size_t found1 = display.find("doublegaus"); + if (found1!=std::string::npos) { + std::size_t found2 = display.find("(",found1+1); + if (found2!=std::string::npos) { + std::size_t found3 = display.find(")",found2+1); + if (found3 != std::string::npos){ + std::string range = display.substr(found2+1,found3-found2-1); + Double_t xmin = std::strtod(range.c_str(),NULL); + std::size_t found4 = display.find(",",found2+1); + if ( found4 != std::string::npos) { + range = display.substr(found4+1,found3-found4-1); + Double_t xmax = std::strtod(range.c_str(),NULL); + TF1* f1 = new TF1("f1","gaus",xmin,xmax); + h->Fit(f1,"q"); + Double_t par[6]; + f1->GetParameters(par); + TF1* func = new TF1("func","gaus(0)+gaus(3)",xmin,xmax); + func->SetParameters(par); + func->SetParameter(3,h->GetBinContent(h->GetMaximumBin())); + func->SetParameter(4,h->GetMean()); + func->SetParameter(5,par[2]); + func->SetLineColor(kRed); + func->SetLineWidth(2); + if (h->GetEffectiveEntries()>minstat) { + h->Fit(func,("rq"+fitopt).c_str()); + } + delete f1; + delete func; + } + } + } + }else { + //draw gaus+pol1 + std::size_t found1 = display.find("gauspluspol1"); + if (found1!=std::string::npos) { + std::size_t found2 = display.find("(",found1+1); + if (found2!=std::string::npos) { + std::size_t found3 = display.find(")",found2+1); + if (found3 != std::string::npos){ + std::string range = display.substr(found2+1,found3-found2-1); + Double_t xmin = std::strtod(range.c_str(),NULL); + std::size_t found4 = display.find(",",found2+1); + if ( found4 != std::string::npos) { + range = display.substr(found4+1,found3-found4-1); + Double_t xmax = std::strtod(range.c_str(),NULL); + TF1* func = new TF1("func","gaus(0)+pol1(3)",xmin,xmax); + func->SetLineColor(kRed); + func->SetLineWidth(2); + func->SetParameters(h->GetBinContent(h->GetMaximumBin()),h->GetMean(),h->GetRMS()); + if (h->GetEffectiveEntries()>minstat) { + h->Fit(func,("rq"+fitopt).c_str()); + } + delete func; + } + + } + } + }else { + //draw gaus+expo + found1 = display.find("gausplusexpo"); + if (found1!=std::string::npos) { + std::size_t found2 = display.find("(",found1+1); + if (found2!=std::string::npos) { + std::size_t found3 = display.find(")",found2+1); + if (found3 != std::string::npos){ + std::string range = display.substr(found2+1,found3-found2-1); + Double_t xmin = std::strtod(range.c_str(),NULL); + std::size_t found4 = display.find(",",found2+1); + if ( found4 != std::string::npos) { + range = display.substr(found4+1,found3-found4-1); + Double_t xmax = std::strtod(range.c_str(),NULL); + + TF1* func = new TF1("func","gaus(0)+expo(3)",xmin,xmax); + func->SetLineColor(kRed); + func->SetLineWidth(2); + func->SetParameters(h->GetBinContent(h->GetMaximumBin()),h->GetMean(),h->GetRMS()); + if (h->GetEffectiveEntries()>minstat) { + h->Fit(func,("rq"+fitopt).c_str()); + } + delete func; + } + + } + } + }else { + // the last case: single gaus + std::size_t found2 = display.find("(",found+1); + if (found2!=std::string::npos) { + std::size_t found3 = display.find(")",found2+1); + if (found3 != std::string::npos){ + std::string range = display.substr(found2+1,found3-found2-1); + Double_t xmin = std::strtod(range.c_str(),NULL); + std::size_t found4 = display.find(",",found2+1); + if ( found4 != std::string::npos) { + range = display.substr(found4+1,found3-found4-1); + Double_t xmax = std::strtod(range.c_str(),NULL); + TF1* func = new TF1("func","gaus",xmin,xmax); + func->SetLineColor(kRed); + func->SetLineWidth(2); + if (h->GetEffectiveEntries()>minstat) { + h->Fit(func,("rq"+fitopt).c_str()); + } + delete func; + } + } + } + } + + } + } + } + + + +/*************************************************************************************************************/ + + + if( h2 != 0 ) { + myC->cd(); + if( h2->GetMinimum() >= 0 && h2->GetMaximum()>0.) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + gPad->SetLogz(display.find("LogZ")!=std::string::npos ); + } + if( h2->GetBinLowEdge(1) > 0) { + gPad->SetLogx(display.find("LogX")!=std::string::npos ); + } + + formatTH2( myC, h2 ); + if( h->GetXaxis()->GetXmin() >= h->GetXaxis()->GetXmax() ) { + std::cerr << "HanOutputFile::saveHistogramToFile(): " + << "Inconsistent x-axis settings: min=" << h->GetXaxis()->GetXmin() << ", " + << "max=" << h->GetXaxis()->GetXmax() << ", " + << "Will not save this histogram.\n"; + return false; + } + if( h->GetYaxis()->GetXmin() >= h->GetYaxis()->GetXmax() ) { + std::cerr << "HanOutputFile::saveHistogramToFile(): " + << "Inconsistent y-axis settings: min=" << h->GetYaxis()->GetXmin() << ", " + << "max=" << h->GetYaxis()->GetXmax() << ", " + << "Will not save this histogram.\n"; + return false; + } + axisOption(display,h2); + if (drawopt =="") { + drawopt = "COLZ"; + } + h2->Draw(drawopt.c_str() ); + displayExtra(myC,display); + if (drawopt.find("lego") == std::string::npos) { + myC->RedrawAxis(); + } + TLatex t; + t.SetNDC(); + t.SetTextSize(0.03); + t.DrawLatex(0.02,0.04,run_min_LB.c_str()); + TLatex tt; + tt.SetNDC(); + tt.SetTextSize(0.03); + tt.DrawLatex(0.02,0.01,pathName.c_str()); + myC->SaveAs( name.c_str() ); + } else if( h != 0 ){ + formatTH1( myC, h ); + if(display.find("StatBox")!=std::string::npos){ + h->SetStats(kTRUE); + } + if( h->GetXaxis()->GetXmin() >= h->GetXaxis()->GetXmax() ) { + std::cerr << "HanOutputFile::saveHistogramToFile(): " + << "Inconsistent x-axis settings: min=" << h->GetXaxis()->GetXmin() << ", " + << "max=" << h->GetXaxis()->GetXmax() << ", " + << "Will not save this histogram.\n"; + return false; + } + h->SetLineColor(kBlack); + h->SetMarkerColor(1); + h->SetFillStyle(0); + h->SetLineWidth(2); + myC->cd(); + if( drawRefs ) { + groupDir->cd((nameHis+"_/Results").c_str()); + gDirectory->GetObject("Reference;1",ref); + hRef = dynamic_cast<TH1*>(ref); + if (hRef) { + hRefs.push_back(hRef); + } else { + TCollection* colln = dynamic_cast<TCollection*>(ref); + if (colln) { + WasCollectionReference = true; + TIterator* icolln = colln->MakeIterator(); + TObject* ref2; + while ((ref2=icolln->Next())) { + hRef = dynamic_cast<TH1*>(ref2); + if (hRef) hRefs.push_back(hRef); + else std::cout << "hRef cast failed!!!" << std::endl; + } + } + } + groupDir->cd(); + } + if( hRefs.size() > 0 ){ + legend = new TLegend(0.70,0.77,0.95,0.87); + legend->SetTextFont(62); + legend->SetMargin(0.15); + legend->SetFillStyle(0); + legend->SetBorderSize(0); + legend->AddEntry(h,datatitle.c_str()); + int itrcolor(0); + for (auto hRef : hRefs) { + int local_color = root_color_choices[itrcolor]; + itrcolor++; + formatTH1( myC, hRef ); + TProfile* pRef = dynamic_cast<TProfile*>( hRef ); + if( pRef != 0 ) { + hRef->SetMarkerColor(local_color); + hRef->SetLineColor(local_color); + hRef->SetLineWidth(local_color); + double ymin = ( hRef->GetMinimum() < h->GetMinimum() )? hRef->GetMinimum(): h->GetMinimum(); + double ymax = ( hRef->GetMaximum() > h->GetMaximum() )? hRef->GetMaximum(): h->GetMaximum(); + double xmin = ( hRef->GetBinLowEdge(1) < h->GetBinLowEdge(1)) ? hRef->GetBinLowEdge(1)-hRef->GetBinWidth(1) : h->GetBinLowEdge(1)-h->GetBinWidth(1); + double xmax = ( hRef->GetBinLowEdge( hRef->GetNbinsX() ) + hRef->GetBinWidth( hRef->GetNbinsX() ) > h->GetBinLowEdge( h->GetNbinsX() ) + h->GetBinWidth( h->GetNbinsX() ) ) ? + hRef->GetBinLowEdge( hRef->GetNbinsX() ) + 2.0*hRef->GetBinWidth( hRef->GetNbinsX() ): h->GetBinLowEdge( h->GetNbinsX() ) + 2.0*h->GetBinWidth( h->GetNbinsX() ) ; + // double y_av = (ymax + ymin)/2; + // double y_halv = (ymax-ymin)*0.6; + bool isLogY=(display.find("LogY")!=std::string::npos); + if(isLogY){ + if(ymax<=0.)ymax=5.0; + if (ymin>0.){ + double lymax=log(ymax); + double lymin=log(ymin); + h->SetAxisRange(exp(lymin-(lymax-lymin)*0.05),exp(lymax+(lymax-lymin)*0.05),"Y");// leave 5% gap on above and below + }else{ + std::cerr<<"ymin is <0. and LogY requested for histogram \"" + <<pathname+"/"+nameHis<<"\", ymin="<<ymin<<std::endl; + } + }else{ + double yMargin=(ymax-ymin)*0.05; + h->SetAxisRange(ymin-yMargin,ymax+yMargin,"Y"); + } + h->SetAxisRange(xmin,xmax,"X"); + axisOption(display,h); + if( h->GetMinimum()>= 0. && hRef->GetMinimum()>= 0. && h->GetMaximum()> 0. && hRef->GetMaximum()> 0.) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + } + if( h->GetBinLowEdge(1)>0 && hRef->GetBinLowEdge(1) > 0) { + gPad->SetLogx(display.find("LogX")!=std::string::npos ); + } + if (!hasPlotted) { + h->Draw(drawopt.c_str()); + hasPlotted=true; + } + hRef->Draw(("SAME"+drawrefopt).c_str()); + } else { + double scale = 1.0; + if ( h->Integral("width") > 0.0 && hRef->Integral("width") > 0.0 && (AlgoName.find("BinContentComp")==std::string::npos) && (display.find("NoNorm")==std::string::npos) ) { + scale = h->Integral("width")/hRef->Integral("width"); + } + hRef->Scale( scale ); + hRef->SetMarkerColor(local_color); + //hRef->SetFillColor(local_color); + hRef->SetLineColor(local_color); + double ymin = ( hRef->GetMinimum() < h->GetMinimum() )? hRef->GetMinimum(): h->GetMinimum(); + double ymax = ( hRef->GetMaximum() > h->GetMaximum() )? hRef->GetMaximum(): h->GetMaximum(); + double xmin = ( hRef->GetBinLowEdge(1) < h->GetBinLowEdge(1)) ? hRef->GetBinLowEdge(1)-hRef->GetBinWidth(1) : h->GetBinLowEdge(1)-h->GetBinWidth(1); + double xmax = ( hRef->GetBinLowEdge( hRef->GetNbinsX() ) + hRef->GetBinWidth( hRef->GetNbinsX() ) > h->GetBinLowEdge( h->GetNbinsX() ) + h->GetBinWidth( h->GetNbinsX() ) ) ? hRef->GetBinLowEdge( hRef->GetNbinsX() ) + 2.0*hRef->GetBinWidth( hRef->GetNbinsX() ): h->GetBinLowEdge( h->GetNbinsX() ) + 2.0*h->GetBinWidth( h->GetNbinsX() ) ; + // double y_av = (ymax + ymin)/2; + // double y_halv = (ymax-ymin)*0.6; + bool isLogY=(display.find("LogY")!=std::string::npos); + // if ( ymin == 0.0 && display.find("LogY")!=std::string::npos ){ + + if(isLogY){ + if(ymax<=0.)ymax=5.0; + if (ymin>0.){ + double lymax=log(ymax); + double lymin=log(ymin); + h->SetAxisRange(exp(lymin-(lymax-lymin)*0.05),exp(lymax+(lymax-lymin)*0.05),"Y");// leave 5% gap on above and below + }else{ + std::cerr<<"ymin is <=0. and LogY requested for histogram \"" + <<pathname+"/"+nameHis<<"\", ymin="<<ymin<<std::endl; + } + }else{ + double yDiff=ymax-ymin; + h->SetAxisRange(ymin-yDiff*0.05,ymax+yDiff*0.05,"Y"); // leave 5% gap above and below + } + + h->SetAxisRange(xmin,xmax,"X"); + myC->cd(); + if( h->GetMinimum()>= 0 && hRef->GetMinimum()>= 0 && h->GetMaximum()> 0. && hRef->GetMaximum()> 0.) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + } + if( h->GetBinLowEdge(1)>0 && hRef->GetBinLowEdge(1) > 0) { + gPad->SetLogx(display.find("LogX")!=std::string::npos ); + } + axisOption(display,h); + if (!hasPlotted) { + h->Draw(drawopt.c_str()); + hasPlotted=true; + } + hRef->Draw(("SAME"+drawrefopt).c_str()); + } + legend->AddEntry(hRef, WasCollectionReference ? hRef->GetName() : "Reference"); + } + h->Draw(("SAME"+drawopt).c_str()); + legend->Draw(); + } else { + myC->cd(); + if( h->GetMinimum() >= 0) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + } + if( h->GetBinLowEdge(1) > 0) { + gPad->SetLogx(display.find("LogX")!=std::string::npos ); + } + axisOption(display,h); + h->Draw(drawopt.c_str()); + } + myC->cd(); + displayExtra(myC,display); + myC->RedrawAxis(); + TLatex t; + t.SetNDC(); + t.SetTextSize(0.03); + t.DrawLatex(0.02,0.04,run_min_LB.c_str()); + TLatex tt; + tt.SetNDC(); + tt.SetTextSize(0.03); + tt.DrawLatex(0.02,0.01,pathName.c_str()); + myC->SaveAs(name.c_str()); + } + delete myC; + gStyle->Reset(); + } + +/*************************************************************************************************************/ + + + if( g ) { + TCanvas *myC = new TCanvas( nameHis.c_str(), "myC", ww, wh ); + myC->cd(); + if( g->GetMinimum() >= 0. && g->GetMaximum()>0.) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + } +// if( h2->GetBinLowEdge(1) > 0) { +// gPad->SetLogx(display.find("LogX")!=std::string::npos ); +// } +// gPad->SetLogz(display.find("LogZ")!=std::string::npos ); + formatTGraph( myC, g ); +// axisOption(display,g); + g->Draw((std::string("AP") + drawopt).c_str()); + displayExtra(myC,display); + TLatex t; + t.SetNDC(); + t.SetTextSize(0.03); + t.DrawLatex(0.02,0.04,run_min_LB.c_str()); + TLatex tt; + tt.SetNDC(); + tt.SetTextSize(0.03); + tt.DrawLatex(0.02,0.01,pathName.c_str()); + myC->SaveAs( name.c_str() ); + delete myC; + gStyle->Reset(); + } + + delete hobj; + delete hRef; + delete legend; + return true; +} + +bool HanOutputFile::saveHistogramToFileSuperimposed( std::string nameHis, std::string location, + TDirectory* groupDir1, TDirectory* groupDir2, + bool drawRefs,std::string run_min_LB, std::string pathName){ + dqi::DisableMustClean disabled; + groupDir1->cd(); + gStyle->SetFrameBorderMode(0); + gStyle->SetFrameFillColor(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetCanvasColor(0); + gStyle->SetTitleColor(0); + gStyle->SetStatColor(0); + gStyle->SetFillColor(1); + gStyle->SetPalette(1,0); + gStyle->SetTitleFontSize(0.06); + gStyle->SetTitleH(0.06); + gStyle->SetMarkerStyle(20); + gStyle->SetOptStat(111100); + gStyle->SetStatBorderSize(0); + gStyle->SetStatX(0.99); + gStyle->SetStatY(0.99); + gStyle->SetStatW(0.2); + gStyle->SetStatH(0.1); + + + gROOT->SetBatch(); + std::string pathname( groupDir1->GetPath() ); + std::string display =""; + bool LookForDisplay = containsDir("Config/annotations/display",(pathname + "/"+ nameHis + "_")); + if(LookForDisplay) { + display = getStringName(pathname + "/"+ nameHis + "_/Config/annotations/display" ); + } + // Look for Draw Options + std::size_t found = display.find("Draw"); + std::string drawopt =""; + while (found!=std::string::npos){ + std::size_t found1 = display.find_first_of(",",found+1); + if (found1!=std::string::npos){ + drawopt +=boost::algorithm::to_lower_copy(display.substr(found+5,found1-found-5)); + } + else { + drawopt +=boost::algorithm::to_lower_copy(display.substr(found+5,display.size())); + } + found=display.find("Draw",found+1); + } + + groupDir1->cd(); + TKey* hkey = groupDir1->FindKey( nameHis.c_str() ); + groupDir2->cd(); + TKey* hkey2 = groupDir2->FindKey( nameHis.c_str() ); + if( hkey == 0 || hkey2 == 0 ) { + std::cerr << "Did not find TKey for \"" << nameHis << "\", will not save this histogram.\n"; + return false; + } + groupDir1->cd(); + TLegend* legend(0); + TObject* hobj = hkey->ReadObj(); + TObject* hobj2 = hkey2->ReadObj(); + TH1* hRef(0); + TH1* h(0),*hist2(0); + TH2* h2(0),*h2_2(0),*h2Diff(0); + TGraph* g(0),*g2(0); + + std::string name=nameHis; + name+=".png"; + std::string::size_type i = location.find_last_of( '/' ); + if( i != (location.size()-1) ) { + location+="/"; + } + name=location + name; + std::string AlgoName=getStringName(pathname+"/"+nameHis+"_/Config/name"); + int ww = 550; + int wh = 490; + found = display.find("TCanvas",found+1); + if (found!=std::string::npos){ + std::size_t found1 = display.find_first_of(",",found+1); + ww = std::atoi((display.substr(found+8,found1-found-8)).c_str() ); + found = display.find_first_of(")",found1+1); + wh = std::atoi((display.substr(found1+1,found-found1-1)).c_str() ); + } + + if( (h = dynamic_cast<TH1*>( hobj ))!=0 && (hist2= dynamic_cast<TH1*>( hobj2 ))!=0 ){ + TCanvas *myC = new TCanvas( nameHis.c_str(), "myC", ww, wh ); + setupCanvas(drawopt,display); + attachFits(h,drawopt,display); + /******************* for plotting fit function on top of histogram ******************/ + +/*************************************************************************************************************/ + std::string tmpdraw(drawopt); + if((h2 = dynamic_cast<TH2*>( h )) != 0 &&((h2_2= dynamic_cast<TH2*>( hist2 ))!=0) ) { + //if(tmpdraw=="") + h2Diff=(TH2*)h2->Clone("difference"); +// tmpdraw="box";//we don't want colz for overlaid histos +// h2->SetLineColor(2); +// h2->SetMarkerColor(2); +// if(!drawH2(myC,h2,tmpdraw,display))return false; +// h2_2->SetMarkerColor(4); +// //h2_2->SetFillColor(4); +// h2_2->SetLineWidth(2); +// h2_2->SetLineColor(4); +// tmpdraw=" box same"; +// if(!drawH2(myC,h2_2,tmpdraw,display))return false; + h2Diff->Add(h2,h2_2,1.0,-1.0); + h2Diff->SetLineColor(2); + h2Diff->SetMarkerColor(2); + if(!drawH2(myC,h2Diff,tmpdraw,display))return false; + TLatex t; + t.SetNDC(); + t.SetTextSize(0.03); + t.DrawLatex(0.02,0.04,(run_min_LB+" difference").c_str()); + TLatex tt; + tt.SetNDC(); + tt.SetTextSize(0.03); + tt.DrawLatex(0.02,0.01,pathName.c_str()); + + myC->SaveAs( name.c_str() ); + } else if( h != 0 && hist2!=0){ + h->SetMarkerColor(1); + h->SetFillStyle(0); + h->SetLineWidth(2); + hist2->SetMarkerColor(4); + hist2->SetLineColor(4); + hist2->SetFillStyle(0); + hist2->SetLineWidth(2); + if( drawRefs ) { + groupDir1->cd((nameHis+"_/Results").c_str()); + gDirectory->GetObject("Reference;1",hRef); + groupDir1->cd(); + } + if(!drawH1(myC,h,hRef,tmpdraw,display,AlgoName))return false; + tmpdraw+="same"; + if(!drawH1(myC,hist2,0,tmpdraw,display,AlgoName))return false; + legend = new TLegend(0.70,0.77,0.95,0.87); + legend->SetTextFont(62); + legend->SetMargin(0.15); + legend->SetFillStyle(0); + legend->SetBorderSize(0); + legend->AddEntry(h,"Data1"); + legend->AddEntry(hist2,"Data2"); + if(hRef){ + legend->AddEntry(hRef,"Reference"); + } + legend->Draw(); + + TLatex t; + t.SetNDC(); + t.SetTextSize(0.03); + t.DrawLatex(0.02,0.04,run_min_LB.c_str()); + TLatex tt; + tt.SetNDC(); + tt.SetTextSize(0.03); + tt.DrawLatex(0.02,0.01,pathName.c_str()); + myC->SaveAs(name.c_str()); + } //end histogram drawing + delete myC; + delete h2Diff; + gStyle->Reset(); + } + +/*************************************************************************************************************/ + if(((g = dynamic_cast<TGraph*>(hobj))!=0 ) && ((g2=dynamic_cast<TGraph*>(hobj2))!=0) ){ + TCanvas *myC = new TCanvas( nameHis.c_str(), "myC", ww, wh ); + myC->cd(); + if( g->GetMinimum() >= 0. && g2->GetMinimum() >=0. && g->GetMaximum() > 0. && g2->GetMaximum() >0.) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + } + formatTGraph( myC, g ); + formatTGraph( myC, g2 ); + g->Draw((std::string("AP") + drawopt).c_str()); + displayExtra(myC,display); + g2->SetMarkerColor(2); + g2->SetLineColor(2); + g2->Draw((std::string("P") + drawopt+" same").c_str()); + TLatex t; + t.SetNDC(); + t.SetTextSize(0.03); + t.DrawLatex(0.02,0.04,run_min_LB.c_str()); + TLatex tt; + tt.SetNDC(); + tt.SetTextSize(0.03); + tt.DrawLatex(0.02,0.01,pathName.c_str()); + myC->SaveAs( name.c_str() ); + delete myC; + gStyle->Reset(); + } + + delete hobj; + delete hobj2; + delete hRef; + delete legend; + return true; +} + +bool HanOutputFile::drawH2(TCanvas* myC,TH2* h2,std::string &drawop,std::string &display){ + std::string drawopt(drawop); + myC->cd(); + if( h2->GetMinimum() >= 0 && h2->GetMaximum()>0) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + gPad->SetLogz(display.find("LogZ")!=std::string::npos ); + }else{ + gPad->SetLogy(false ); + } + if( h2->GetBinLowEdge(1) > 0) { + gPad->SetLogx(display.find("LogX")!=std::string::npos ); + }else{ + gPad->SetLogx(false ); + } + formatTH2( myC, h2 ); + if( h2->GetXaxis()->GetXmin() >= h2->GetXaxis()->GetXmax() ) { + std::cerr << "HanOutputFile::saveHistogramToFile(): " + << "Inconsistent x-axis settings: min=" << h2->GetXaxis()->GetXmin() << ", " + << "max=" << h2->GetXaxis()->GetXmax() << ", " + << "Will not save this histogram.\n"; + return false; + } + if( h2->GetYaxis()->GetXmin() >= h2->GetYaxis()->GetXmax() ) { + std::cerr << "HanOutputFile::saveHistogramToFile(): " + << "Inconsistent y-axis settings: min=" << h2->GetYaxis()->GetXmin() << ", " + << "max=" << h2->GetYaxis()->GetXmax() << ", " + << "Will not save this histogram.\n"; + return false; + } + axisOption(display,h2); + if (drawopt =="") { + drawopt = "COLZ"; + } + h2->Draw(drawopt.c_str() ); + displayExtra(myC,display); + // std::cout<<"drawh2 drawopt="<<drawopt<<",display="<<display<<std::endl; + // if (drawopt.find("lego") == std::string::npos) { + myC->RedrawAxis(); + //} + return true; +} + +void HanOutputFile::setupCanvas(std::string &drawopt,std::string &display){ + gPad->SetGridx(display.find("SetGridx")!=std::string::npos ); + gPad->SetGridy(display.find("SetGridy")!=std::string::npos ); + std::size_t found = display.find("SetPalette"); + if (found!=std::string::npos) { + std::size_t found1 = display.find_first_of("(",found+1); + std::size_t found2 = display.find_first_of(",)",found+1); + std::string cn =display.substr(found1+1,found2-found1-1); + int n1=std::strtol(cn.c_str(),NULL,0); + gStyle->SetPalette((Int_t) n1); + } + found = display.find("SetGridStyle"); + if (found!=std::string::npos) { + std::size_t found1 = display.find_first_of("(",found+1); + std::size_t found2 = display.find_first_of(",)",found+1); + std::string cn =display.substr(found1+1,found2-found1-1); + int n1=std::strtol(cn.c_str(),NULL,0); + gStyle->SetGridStyle((Style_t) n1); + } + if(!drawopt.empty()){ + //do any modifications coming from drawopt + } +} + +void HanOutputFile::attachFits(TH1* h,std::string &drawopt,std::string &display){ + size_t found = display.find("gaus"); + if (found!=std::string::npos ) { + Double_t minstat=0.; + std::size_t fpos1,fpos2,fpos; + fpos=display.find("MinStat"); + if (fpos!= std::string::npos){ + fpos1=display.find("(",fpos+1); + if (fpos1!=std::string::npos) { + fpos2 = display.find(")",fpos1+1); + if (fpos2!=std::string::npos) { + std::string s_minstat=display.substr(fpos1+1,fpos2-fpos1-1); + minstat=std::strtod(s_minstat.c_str(),NULL); + } + + } + } + std::string fitopt(""); + fpos=display.find("FitOption"); + if (fpos!= std::string::npos){ + fpos1=display.find("(",fpos+1); + if (fpos1!=std::string::npos) { + fpos2 = display.find(")",fpos1+1); + if (fpos2!=std::string::npos) { + fitopt=display.substr(fpos1+1,fpos2-fpos1-1); + } + } + } + //plot double gaus + std::size_t found1 = display.find("doublegaus"); + if (found1!=std::string::npos) { + std::size_t found2 = display.find("(",found1+1); + if (found2!=std::string::npos) { + std::size_t found3 = display.find(")",found2+1); + if (found3 != std::string::npos){ + std::string range = display.substr(found2+1,found3-found2-1); + Double_t xmin = std::strtod(range.c_str(),NULL); + std::size_t found4 = display.find(",",found2+1); + if ( found4 != std::string::npos) { + range = display.substr(found4+1,found3-found4-1); + Double_t xmax = std::strtod(range.c_str(),NULL); + TF1* f1 = new TF1("f1","gaus",xmin,xmax); + h->Fit(f1,"q"); + Double_t par[6]; + f1->GetParameters(par); + TF1* func = new TF1("func","gaus(0)+gaus(3)",xmin,xmax); + func->SetParameters(par); + func->SetParameter(3,h->GetBinContent(h->GetMaximumBin())); + func->SetParameter(4,h->GetMean()); + func->SetParameter(5,par[2]); + func->SetLineColor(kRed); + func->SetLineWidth(2); + if (h->GetEffectiveEntries()>minstat) { + h->Fit(func,("rq"+fitopt).c_str()); + } + delete f1; + delete func; + } + } + } + }else { + //draw gaus+pol1 + std::size_t found1 = display.find("gauspluspol1"); + if (found1!=std::string::npos) { + std::size_t found2 = display.find("(",found1+1); + if (found2!=std::string::npos) { + std::size_t found3 = display.find(")",found2+1); + if (found3 != std::string::npos){ + std::string range = display.substr(found2+1,found3-found2-1); + Double_t xmin = std::strtod(range.c_str(),NULL); + std::size_t found4 = display.find(",",found2+1); + if ( found4 != std::string::npos) { + range = display.substr(found4+1,found3-found4-1); + Double_t xmax = std::strtod(range.c_str(),NULL); + TF1* func = new TF1("func","gaus(0)+pol1(3)",xmin,xmax); + func->SetLineColor(kRed); + func->SetLineWidth(2); + func->SetParameters(h->GetBinContent(h->GetMaximumBin()),h->GetMean(),h->GetRMS()); + if (h->GetEffectiveEntries()>minstat) { + h->Fit(func,("rq"+fitopt).c_str()); + } + delete func; + } + + } + } + }else { + //draw gaus+expo + found1 = display.find("gausplusexpo"); + if (found1!=std::string::npos) { + std::size_t found2 = display.find("(",found1+1); + if (found2!=std::string::npos) { + std::size_t found3 = display.find(")",found2+1); + if (found3 != std::string::npos){ + std::string range = display.substr(found2+1,found3-found2-1); + Double_t xmin = std::strtod(range.c_str(),NULL); + std::size_t found4 = display.find(",",found2+1); + if ( found4 != std::string::npos) { + range = display.substr(found4+1,found3-found4-1); + Double_t xmax = std::strtod(range.c_str(),NULL); + + TF1* func = new TF1("func","gaus(0)+expo(3)",xmin,xmax); + func->SetLineColor(kRed); + func->SetLineWidth(2); + func->SetParameters(h->GetBinContent(h->GetMaximumBin()),h->GetMean(),h->GetRMS()); + if (h->GetEffectiveEntries()>minstat) { + h->Fit(func,("rq"+fitopt).c_str()); + } + delete func; + } + + } + } + }else { + // the last case: single gaus + std::size_t found2 = display.find("(",found+1); + if (found2!=std::string::npos) { + std::size_t found3 = display.find(")",found2+1); + if (found3 != std::string::npos){ + std::string range = display.substr(found2+1,found3-found2-1); + Double_t xmin = std::strtod(range.c_str(),NULL); + std::size_t found4 = display.find(",",found2+1); + if ( found4 != std::string::npos) { + range = display.substr(found4+1,found3-found4-1); + Double_t xmax = std::strtod(range.c_str(),NULL); + TF1* func = new TF1("func","gaus",xmin,xmax); + func->SetLineColor(kRed); + func->SetLineWidth(2); + if (h->GetEffectiveEntries()>minstat) { + h->Fit(func,("rq"+fitopt).c_str()); + } + delete func; + } + } + } + } + } + } + } + if(!drawopt.empty()){ + //do drawopt related stuff here + } + +} + +bool HanOutputFile::drawH1(TCanvas* myC,TH1* h,TH1* hRef,std::string &drawopt,std::string &display,std::string &AlgoName){ + formatTH1( myC, h ); + if(display.find("StatBox")!=std::string::npos){ + h->SetStats(kTRUE); + } + if( h->GetXaxis()->GetXmin() >= h->GetXaxis()->GetXmax() ) { + std::cerr << "HanOutputFile::saveHistogramToFile(): " + << "Inconsistent x-axis settings: min=" << h->GetXaxis()->GetXmin() << ", " + << "max=" << h->GetXaxis()->GetXmax() << ", " + << "Will not save this histogram.\n"; + return false; + } + myC->cd(); + if( hRef != 0 ){ + drawReference(myC,hRef,h,drawopt,display,AlgoName); + + } else { + myC->cd(); + if( h->GetMinimum() >= 0 && h->GetMaximum()>0.) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + }else{ + gPad->SetLogy(false); + } + if( h->GetBinLowEdge(1) > 0) { + gPad->SetLogx(display.find("LogX")!=std::string::npos ); + }else{ + gPad->SetLogx(false ); + } + axisOption(display,h); + h->Draw(drawopt.c_str()); + } + myC->cd(); + displayExtra(myC,display); + myC->RedrawAxis(); + return true; +} + +bool HanOutputFile::drawReference(TCanvas* myC,TH1* hRef,TH1* h,std::string &drawopt,std::string &display,std::string &AlgoName){ + formatTH1( myC, hRef ); + TProfile* pRef = dynamic_cast<TProfile*>( hRef ); + if( pRef != 0 ) {//profile reference + hRef->SetMarkerColor(2); + hRef->SetLineColor(2); + hRef->SetLineWidth(2); + double ymin = ( hRef->GetMinimum() < h->GetMinimum() )? hRef->GetMinimum(): h->GetMinimum(); + double ymax = ( hRef->GetMaximum() > h->GetMaximum() )? hRef->GetMaximum(): h->GetMaximum(); + double xmin = ( hRef->GetBinLowEdge(1) < h->GetBinLowEdge(1)) ? hRef->GetBinLowEdge(1)-hRef->GetBinWidth(1) : h->GetBinLowEdge(1)-h->GetBinWidth(1); + double xmax = ( hRef->GetBinLowEdge( hRef->GetNbinsX() ) + hRef->GetBinWidth( hRef->GetNbinsX() ) > h->GetBinLowEdge( h->GetNbinsX() ) + h->GetBinWidth( h->GetNbinsX() ) ) ? + hRef->GetBinLowEdge( hRef->GetNbinsX() ) + 2.0*hRef->GetBinWidth( hRef->GetNbinsX() ): h->GetBinLowEdge( h->GetNbinsX() ) + 2.0*h->GetBinWidth( h->GetNbinsX() ) ; + // double y_av = (ymax + ymin)/2; + // double y_halv = (ymax-ymin)*0.6; + bool isLogY=(display.find("LogY")!=std::string::npos); + if(isLogY){ + if(ymax<=0.0) ymax=5.0; + if (ymin>0.){ + double lymax=log(ymax); + double lymin=log(ymin); + h->SetAxisRange(exp(lymin-(lymax-lymin)*0.05),exp(lymax+(lymax-lymin)*0.05),"Y");// leave 5% gap on above and below + }else{ + std::cerr<<"ymin is <0. and LogY requested for histogram \"" + <<h->GetName()<<" "<<h->GetDirectory()->GetPath()<<"\", ymin="<<ymin<<std::endl; + } + }else{ + double yMargin=(ymax-ymin)*0.05; + h->SetAxisRange(ymin-yMargin,ymax+yMargin,"Y"); + } + h->SetAxisRange(xmin,xmax,"X"); + axisOption(display,h); + if( h->GetMinimum()>= 0 && hRef->GetMinimum()>= 0 && h->GetMaximum()> 0 && hRef->GetMaximum()> 0 ) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + } + if( h->GetBinLowEdge(1)>0 && hRef->GetBinLowEdge(1) > 0) { + gPad->SetLogx(display.find("LogX")!=std::string::npos ); + } + h->Draw(drawopt.c_str()); + hRef->Draw(("SAME"+drawopt).c_str()); + h->Draw(("SAME"+drawopt).c_str()); + } else {//ordinary reference + double scale = 1.0; + if ( h->Integral("width") > 0.0 && hRef->Integral("width") > 0.0 && (AlgoName.find("BinContentComp")==std::string::npos) && (display.find("NoNorm")==std::string::npos) ) { + scale = h->Integral("width")/hRef->Integral("width"); + } + hRef->Scale( scale ); + hRef->SetMarkerColor(15); + hRef->SetFillColor(15); + hRef->SetLineColor(15); + double ymin = ( hRef->GetMinimum() < h->GetMinimum() )? hRef->GetMinimum(): h->GetMinimum(); + double ymax = ( hRef->GetMaximum() > h->GetMaximum() )? hRef->GetMaximum(): h->GetMaximum(); + double xmin = ( hRef->GetBinLowEdge(1) < h->GetBinLowEdge(1)) ? hRef->GetBinLowEdge(1)-hRef->GetBinWidth(1) : h->GetBinLowEdge(1)-h->GetBinWidth(1); + double xmax = ( hRef->GetBinLowEdge( hRef->GetNbinsX() ) + hRef->GetBinWidth( hRef->GetNbinsX() ) > h->GetBinLowEdge( h->GetNbinsX() ) + h->GetBinWidth( h->GetNbinsX() ) ) ? hRef->GetBinLowEdge( hRef->GetNbinsX() ) + 2.0*hRef->GetBinWidth( hRef->GetNbinsX() ): h->GetBinLowEdge( h->GetNbinsX() ) + 2.0*h->GetBinWidth( h->GetNbinsX() ) ; + // double y_av = (ymax + ymin)/2; + // double y_halv = (ymax-ymin)*0.6; + bool isLogY=(display.find("LogY")!=std::string::npos); + // if ( ymin == 0.0 && display.find("LogY")!=std::string::npos ){ + + if(isLogY){ + if(ymax<=0.0) ymax=5.0; + if (ymin>0.){ + double lymax=log(ymax); + double lymin=log(ymin); + h->SetAxisRange(exp(lymin-(lymax-lymin)*0.05),exp(lymax+(lymax-lymin)*0.05),"Y");// leave 5% gap on above and below + }else{ + std::cerr<<"ymin is <=0. and LogY requested for histogram \"" + <<h->GetName()<<" "<<h->GetDirectory()->GetPath()<<"\", ymin="<<ymin<<std::endl; + } + }else{ + double yDiff=ymax-ymin; + h->SetAxisRange(ymin-yDiff*0.05,ymax+yDiff*0.05,"Y"); // leave 5% gap above and below + } + + h->SetAxisRange(xmin,xmax,"X"); + myC->cd(); + if( h->GetMinimum()>= 0. && hRef->GetMinimum()>= 0. && h->GetMaximum()> 0. && hRef->GetMaximum()> 0. ) { + gPad->SetLogy(display.find("LogY")!=std::string::npos ); + } + if( h->GetBinLowEdge(1)>0 && hRef->GetBinLowEdge(1) > 0) { + gPad->SetLogx(display.find("LogX")!=std::string::npos ); + } + axisOption(display,h); + h->Draw(drawopt.c_str()); + hRef->Draw(("SAME"+drawopt).c_str()); + h->Draw(("SAME"+drawopt).c_str()); + } + return true; +} + +// bool HanOutputFile::drawGraph(TCanvas* canv,TGraph* hist,std::string &drawopt,std::string &display){ +// return false; +// } + +void +HanOutputFile:: +axisOption( std::string str, TH1* h ) +{ + std::size_t found = str.find("AxisRange"); + while (found!=std::string::npos) + { + std::string coordinates, cx1,cy1 =""; + std::size_t found1 = str.find_first_of(")",found+1); + std::size_t found2 = str.find_first_of("\'",found+1); + if (found2!=std::string::npos){ + found2 = str.find_first_of("\'",found2+1); + if (found1 < found2) { + found1 = str.find_first_of(")",found2+1); + } + } + if (found1!=std::string::npos){ + coordinates = str.substr(found+10,found1-found-10); + found1 = coordinates.find_first_of(","); + if (found1!=std::string::npos){ + cx1 = coordinates.substr(0,found1); + double x1=std::strtod(cx1.c_str(),NULL); + found2 = coordinates.find_first_of(",",found1+1); + if (found2!=std::string::npos){ + cy1 = coordinates.substr(found1+1,found2-found1-1); + double y1=std::strtod(cy1.c_str(),NULL); + std::string txt = coordinates.substr(found2+2,coordinates.size() ); + txt = txt.substr(0,txt.size()-1 ); + if (txt == "X" && x1 < y1) + { + h->SetAxisRange(x1,y1,"X"); + } + if (txt == "Y" && x1 < y1) + { + h->SetAxisRange(x1,y1,"Y"); + } + if (txt == "Z" && x1 < y1) + { + h->SetAxisRange(x1,y1,"Z"); + } + } + } + } + found=str.find("AxisRange",found+1); + } +} + +void +HanOutputFile:: +displayExtra( TCanvas* c, std::string str ) +{ + std::size_t found = str.find("TLine"); + while (found!=std::string::npos) + { + std::size_t found1 = str.find_first_of(")",found+1); + if (found1!=std::string::npos){ + std::string coordinates = str.substr(found+6,found1-found-6); + bool NDC = false; + if (found1 < str.size()-3 && str.substr(found1+1,3)=="NDC") { + NDC = true; + } + found1 = coordinates.find_first_of(","); + if (found1!=std::string::npos){ + std::string cx1 = coordinates.substr(0,found1); + double x1=std::strtod(cx1.c_str(),NULL); + std::size_t found2 = coordinates.find_first_of(",",found1+1); + if (found2!=std::string::npos){ + std::string cy1 = coordinates.substr(found1+1,found2-found1-1); + double y1=std::strtod(cy1.c_str(),NULL); + found1 = coordinates.find_first_of(",",found2+1); + if (found1!=std::string::npos){ + std::string cx2 = coordinates.substr(found2+1,found1-found2-1); + double x2=std::strtod(cx2.c_str(),NULL); + std::string cy2 = coordinates.substr(found1+1,coordinates.size() ); + double y2=std::strtod(cy2.c_str(),NULL); + c->cd(); + TLine *L = new TLine; + if (NDC){ + if ( x1<=1.0 && x1>=0.0 && x2<=1.0 && x2>=0.0 && y1<=1.0 && y1>=0.0 && y2<=1.0 && y2>=0.0) { + L->DrawLineNDC(x1,y1,x2,y2); + } + } + else { + L->DrawLine(x1,y1,x2,y2); + } + } + } + } + } + found=str.find("TLine",found+1); + } + + found = str.find("TText"); + while (found!=std::string::npos) + { + std::string coordinates, cx1,cy1 =""; + std::size_t found1 = str.find_first_of(")",found+1); + std::size_t found2 = str.find_first_of("\'",found+1); + if (found2!=std::string::npos){ + found2 = str.find_first_of("\"",found2+1); + if (found2!=std::string::npos && found1 < found2) { + found1 = str.find_first_of(")",found2+1); + } + } + if (found1!=std::string::npos){ + coordinates = str.substr(found+6,found1-found-6); + bool NDC = false; + if (found1 < str.size()-3 && str.substr(found1+1,3)=="NDC") { + NDC = true; + } + found1 = coordinates.find_first_of(","); + if (found1!=std::string::npos){ + cx1 = coordinates.substr(0,found1); + double x1=std::strtod(cx1.c_str(),NULL); + found2 = coordinates.find_first_of(",",found1+1); + if (found2!=std::string::npos){ + cy1 = coordinates.substr(found1+1,found2-found1-1); + double y1=std::strtod(cy1.c_str(),NULL); + std::string txt = coordinates.substr(found2+2,coordinates.size() ); + txt = txt.substr(0,txt.size()-1 ); + c->cd(); + TText *T = new TText; + if (NDC) { + if ( x1<=1.0 && x1>=0.0 && y1<=1.0 && y1>=0.0) { + T->DrawTextNDC(x1,y1,txt.c_str() ); + } + } + else { + T->DrawText(x1,y1,txt.c_str() ); + } + } + } + } + found=str.find("TText",found+1); + } +} + + +void +HanOutputFile:: +formatTH1( TCanvas* c, TH1* h ) const +{ + if( c == 0 || h == 0 ) + return; + + c->SetLeftMargin(0.15); + c->SetRightMargin(0.13); + c->SetBottomMargin(0.15); + c->SetTopMargin(0.12); + + h->SetStats(kFALSE); + h->SetLabelSize(0.04,"X"); + h->SetLabelSize(0.04,"Y"); + h->SetLabelFont(62,"X"); + h->SetLabelFont(62,"Y"); + h->SetTitleSize(0.04,"X"); + h->SetTitleSize(0.04,"Y"); + h->GetXaxis()->SetTitleFont(62); + h->GetXaxis()->SetTitleSize(0.04); + h->GetYaxis()->SetTitleFont(62); + h->GetYaxis()->SetTitleSize(0.04); + + h->SetTitleOffset(1.5,"y"); + h->SetTitleOffset(0.9,"x"); + + h->SetNdivisions( 504, "X" ); + h->SetNdivisions( 504, "Y" ); +} + + +void +HanOutputFile:: +formatTH2( TCanvas* c, TH2* h ) const +{ + if( c == 0 || h == 0 ) + return; + + c->SetLeftMargin(0.15); + c->SetRightMargin(0.13); + c->SetBottomMargin(0.15); + c->SetTopMargin(0.12); + + + h->SetStats(kFALSE); + + h->SetLabelSize(0.04,"X"); + h->SetLabelSize(0.04,"Y"); + h->SetLabelSize(0.04,"Z"); + h->SetLabelFont(62,"X"); + h->SetLabelFont(62,"Y"); + h->SetLabelFont(62,"Z"); + h->SetTitleSize(0.04,"X"); + h->SetTitleSize(0.04,"Y"); + h->SetTitleSize(0.04,"Z"); + h->GetXaxis()->SetTitleFont(62); + h->GetXaxis()->SetTitleSize(0.04); + h->GetYaxis()->SetTitleFont(62); + h->GetYaxis()->SetTitleSize(0.04); + + h->SetTitleOffset(1.5,"y"); + h->SetTitleOffset(0.9,"x"); + + h->SetNdivisions( 504, "X" ); + h->SetNdivisions( 504, "Y" ); +} + +void +HanOutputFile:: +formatTGraph( TCanvas* c, TGraph* g ) const +{ + if( c == 0 || g == 0 ) + return; + + c->SetLeftMargin(0.15); + c->SetRightMargin(0.13); + c->SetBottomMargin(0.15); + c->SetTopMargin(0.12); + + g->SetMarkerStyle(20); +} + +// ********************************************************************* +// Protected Methods +// ********************************************************************* + +void +HanOutputFile:: +clearData() +{ + dqi::DisableMustClean disabled; +// bool useRecursiveDelete = gROOT->MustClean(); +// gROOT->SetMustClean(false); + + delete m_file; + delete m_style; + m_file = 0; + m_style = 0; + m_indirMap.clear(); + + DirToAssMap_t::const_iterator assessMapEnd = m_assessMap.end(); + for( DirToAssMap_t::const_iterator i = m_assessMap.begin(); i != assessMapEnd; ++i ) { + delete i->second; + } + m_assessMap.clear(); + +// gROOT->SetMustClean(useRecursiveDelete); +} + + +} // namespace dqutils + diff --git a/DataQuality/DataQualityUtils/src/HistogramDataCOOL.cxx b/DataQuality/DataQualityUtils/src/HistogramDataCOOL.cxx new file mode 100644 index 0000000000000000000000000000000000000000..50cfa227c777306206264dfcbfae081b853f9ac3 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/HistogramDataCOOL.cxx @@ -0,0 +1,1280 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: HistogramDataCOOL.cxx,v 1.9 2009-02-13 12:32:11 ponyisi Exp $ +// Last Modified 07/18/2008 by M.D'Onofrio +// ********************************************************************** + +#include "DataQualityUtils/HistogramDataCOOL.h" + +//CORAL API include files +#include "CoralBase/Attribute.h" + +//COOL API include files (CoolKernel) +#include "CoolKernel/IDatabase.h" +#include "CoolKernel/IFolder.h" +#include "CoolKernel/IObjectIterator.h" +#include "CoolKernel/IObject.h" +#include "CoolKernel/Record.h" +#include "CoolKernel/Exception.h" +#include "CoolKernel/IDatabaseSvc.h" +#include "CoolKernel/StorageType.h" + +#include <sstream> +#include <fstream> +#include <string> +#include <TCanvas.h> +#include <TDirectory.h> +#include <TFile.h> +#include <TGraph.h> +#include <TGraphErrors.h> +#include <TH1.h> +#include <TH2.h> +#include <TIterator.h> +#include <TKey.h> +#include <TLegend.h> +#include <TProfile.h> +#include <TROOT.h> +#include <TStyle.h> +#include <TLatex.h> +#include <TMath.h> +#include <TColor.h> +#include <TTree.h> + +ClassImp(dqutils::HistogramDataCOOL) + +namespace dqutils{ + +cool::IDatabasePtr +HistogramDataCOOL:: +coolDbInstance(std::string dbStr, bool readOnly) { + try { + std::cout << "Opening database '" << dbStr << "'..."; + cool::IDatabaseSvc& dbSvc = this->databaseService(); + std::cout << "done." << std::endl; + return dbSvc.openDatabase(dbStr.c_str(), readOnly); + } + catch (cool::DatabaseDoesNotExist&) { + std::cout << "Error! Database does not exist!" << std::endl; + throw; + } +} + +cool::IFolderPtr +HistogramDataCOOL:: +coolFolderInstance(std::string folderStr) { + try { + cool::IFolderPtr folder = coolDb->getFolder(folderStr.c_str()); + std::cout << "Browsing objects of '" << folderStr << "'" << std::endl; + return folder; + } + catch (cool::FolderNotFound& ) { + std::cout << "Error! Folder '" << folderStr << "' does not exist!" << std::endl; + throw; + } +} + +void +HistogramDataCOOL:: +setSince(cool::Int64 run, cool::Int64 lumi) { + since = ((run << 32) + lumi); +} + +void +HistogramDataCOOL:: +setUntil(cool::Int64 run, cool::Int64 lumi) { + until = ((run << 32) + lumi); +} + +void +HistogramDataCOOL:: +setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU) { + this->setSince(runS, lumiS); + this->setUntil(runU, lumiU); + this->printIOV(); +} + +void +HistogramDataCOOL:: +setIOV(cool::Int64 run) { + this->setSince(run, 0); + this->setUntil(run, cool::UInt32Max); + //this->printIOV(); +} + + +void +HistogramDataCOOL:: +printIOV(){ + cool::Int64 runS=since>>32; + cool::Int64 lumiS=since-(runS<<32); + cool::Int64 runU=until>>32; + cool::Int64 lumiU=until-(runU<<32); + std::cout << "Using IOVrange [(" << runS << "," << lumiS << "),(" << runU << "," << lumiU << ")] " << "[" << since << "," << until << "]" << std::endl; +} + +HistogramDataCOOL:: +HistogramDataCOOL (std::string dbStr, std::string folderStr, int runS, int lumiS, int runU, int lumiU) { + coolDb = this->coolDbInstance(dbStr, false); + coolFolder = this->coolFolderInstance(folderStr); + coolFolderH = this->coolFolderInstance(folderStr); + this->setIOV(runS, lumiS, runU, lumiU); +} + +HistogramDataCOOL:: +HistogramDataCOOL (int runS, int lumiS, int runU, int lumiU) { + coolDb = this->coolDbInstance("COOLOFL_GLOBAL/OFLP200", false); + coolFolder = this->coolFolderInstance("/GLOBAL/DETSTATUS/DQMFOFL"); + coolFolderH = this->coolFolderInstance("/GLOBAL/DETSTATUS/DQMFOFLH"); + this->setIOV(runS, lumiS, runU, lumiU); +} + +HistogramDataCOOL:: +HistogramDataCOOL() { + coolDb = this->coolDbInstance("COOLOFL_GLOBAL/OFLP200", false); + coolFolder = this->coolFolderInstance("/GLOBAL/DETSTATUS/DQMFOFL"); + coolFolderH = this->coolFolderInstance("/GLOBAL/DETSTATUS/DQMFOFLH"); + this->setIOV(0, 0, 0, 0); +} + +HistogramDataCOOL:: +~HistogramDataCOOL () { + coolDb->closeDatabase(); + std::cout << "Cleared!" << std::endl; +} + +cool::RecordSpecification +HistogramDataCOOL:: +createSpec() { + //std::cout << "Preparing RecordSpecification" << std::endl; + cool::RecordSpecification spec; + spec.extend("Code",cool::StorageType::Int32); + spec.extend("deadFrac",cool::StorageType::Float); + spec.extend("Thrust",cool::StorageType::Float); + if (!(spec==coolFolder->payloadSpecification())) { + std::cout << "ERROR Source and destination folder specifications differ." << std::endl; + } + return spec; +} + +coral::AttributeList +HistogramDataCOOL:: +createPayload(int colourCode, float dfrac, float thrust, const cool::RecordSpecification& spec) { + coral::AttributeList payload = cool::Record( spec ).attributeList(); + payload["Code"].data<cool::Int32>() = colourCode; + payload["deadFrac"].data<cool::Float>() = dfrac; + payload["Thrust"].data<cool::Float>() = thrust; + //std::cout << "Creating payload: "; + //std::cout << "[Code : " << colourCode << "],"; + //std::cout << "[DeadFraction : " << dfrac << "],"; + //std::cout << "[Thrust : " << thrust << "]" << std::endl; + return payload; +} + + // Monica 4/6/2008, modified 24/6/2008 to allocate more quantities +cool::RecordSpecification +HistogramDataCOOL:: +createSpecH() { + cool::RecordSpecification specH; + specH.extend("Code",cool::StorageType::Int32); + specH.extend("Algo",cool::StorageType::String255); + specH.extend("Entries",cool::StorageType::Int32); + specH.extend("Par1",cool::StorageType::Float); + specH.extend("Par2",cool::StorageType::Float); + specH.extend("Par3",cool::StorageType::Float); + specH.extend("Par4",cool::StorageType::Float); + specH.extend("Par5",cool::StorageType::Float); + + if (!(specH==coolFolderH->payloadSpecification())) { + std::cout << "ERROR Source and destination folder specifications differ. histos" << std::endl; + } + return specH; +} + +coral::AttributeList +HistogramDataCOOL:: +createPayloadH(int colourCode, std::string algo, int entries, float par1, float par2, float par3, float par4, float par5, const cool::RecordSpecification& specH) { + coral::AttributeList payloadH = cool::Record( specH ).attributeList(); + payloadH["Code"].data<cool::Int32>() = colourCode; + payloadH["Algo"].data<cool::String255>() = algo; + payloadH["Entries"].data<cool::Int32>() = entries; + payloadH["Par1"].data<cool::Float>() = par1; + payloadH["Par2"].data<cool::Float>() = par2; + payloadH["Par3"].data<cool::Float>() = par3; + payloadH["Par4"].data<cool::Float>() = par4; + payloadH["Par5"].data<cool::Float>() = par5; + std::cout << "Creating payload histos: "; + std::cout << "[Code : " << colourCode << "],"; + std::cout << "[Algo : " << algo << "],"; + std::cout << "[Entries : " << entries << "],"; + std::cout << "[Par1 : " << par1 << "],"; + std::cout << "[Par2 : " << par2 << "],"; + std::cout << "[Par3 : " << par3 << "],"; + std::cout << "[Par4 : " << par4 << "],"; + std::cout << "[Par5 : " << par5 << "]" << std::endl; + return payloadH; +} + // end of modification in create new folder and payload (Monica 4/6/2008) + +void +HistogramDataCOOL:: +dump(cool::ChannelSelection selection, std::string tag_name) { + try { + // cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until, selection,"DetStatusDQMFOFLH-FDR2-01"); + cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until, selection,tag_name); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + std::cout << element << std::endl; + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } +} + +int +HistogramDataCOOL:: +dumpCode(std::string channelName, std::string tag_name) { + std::string result = this->dumpHisto(this->getCoolFolderH()->channelId(channelName.c_str()), "Code", tag_name); + return atoi(result.c_str()); +} + +void +HistogramDataCOOL:: +dumpall(std::string tag_name) { + this->dump(cool::ChannelSelection::all(), tag_name); +} + + // Monica 4/6/2208 +std::string +HistogramDataCOOL:: +dumpHisto(cool::ChannelId channelId, std::string field, std::string tag_name) { + std::string result =""; + try { + cool::ChannelSelection selection = cool::ChannelSelection(channelId); + // cool::IObjectIteratorPtr objects = coolFolderH->browseObjects(since, until, selection,"DetStatusDQMFOFLH-FDR2-01"); + cool::IObjectIteratorPtr objects = coolFolderH->browseObjects(since, until, selection,tag_name); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + result = element.payloadValue(field); + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + return result; +} + +void +HistogramDataCOOL:: +insertH(cool::ChannelId channelId, int code, std::string algo, int entries, float par1, float par2, float par3, float par4, float par5, std::string tag_name) { + try { + cool::RecordSpecification specH = this->createSpecH(); + coral::AttributeList payloadH = this->createPayloadH(code, algo, entries, par1, par2, par3, par4, par5, specH); + std::cout << "Trying to store payload histos [channel " << this->getCoolFolderH()->channelName(channelId) <<" ("<< channelId <<")]..."; + // coolFolderH->storeObject(since, until, payloadH, channelId, "DetStatusDQMFOFLH-FDR2-01", true); + coolFolderH->storeObject(since, until, payloadH, channelId, tag_name, true); + std::cout << "stored!" << std::endl; + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } +} + +void +HistogramDataCOOL:: +insertH(std::string channelName, int code, std::string algo, int entries, float par1, float par2, float par3, float par4, float par5, std::string tag_name) { + try { + this->insertH(this->getCoolFolderH()->channelId(channelName), code, algo, entries, par1, par2, par3, par4, par5, tag_name); + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } +} + +cool::IFolderPtr +HistogramDataCOOL:: +getCoolFolderH() { + return this->coolFolderH; +} + +void +HistogramDataCOOL:: +ntupleDB( int HistoId, std::string nameHisto, std::string configuration, int Irun, int Frun) +{ + + gROOT->Reset(); + gROOT->SetBatch(); + gStyle->SetFrameBorderMode(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetCanvasColor(0); + gStyle->SetTitleColor(1); + gStyle->SetStatColor(0); + gStyle->SetFillColor(1); + gStyle->SetPalette(1,0); + gStyle->SetTitleFontSize(0.06); + gStyle->SetTitleH(0.06); + + // Declaration of leave types + UInt_t RunSince; + UInt_t RunUntil; + UInt_t LBSince; + UInt_t LBUntil; + UInt_t ChannelID; + Char_t TagID[26]; + Int_t Code; + Char_t Algo[100]; + Int_t Entries; + Float_t Par1; + Float_t Par2; + Float_t Par3; + Float_t Par4; + Float_t Par5; + + // List of branches + TBranch *b_RunSince; + TBranch *b_RunUntil; + TBranch *b_LBSince; + TBranch *b_LBUntil; + TBranch *b_ChannelID; + TBranch *b_TagID; + TBranch *b_Code; + TBranch *b_Algo; + TBranch *b_Entries; + TBranch *b_Par1; + TBranch *b_Par2; + TBranch *b_Par3; + TBranch *b_Par4; + TBranch *b_Par5; + + unsigned int i = HistoId; + unsigned int init_run = Irun; + unsigned int last_run = Frun; + std::string nameh = nameHisto; + std::string config = configuration; + + char f_name[200]; + char dir_name[200]; + sprintf(f_name,"dqmfoflh_%s.root",config.c_str()); + sprintf(dir_name,"dqmfoflh_%s.root:/COOL/GLOBAL/DETSTATUS",config.c_str()); + TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(f_name); + if (!f) { + f = new TFile(f_name); + f->cd(dir_name); + } + TTree *tree = (TTree*)gDirectory->Get("DQMFOFLH"); + + if (!tree) return; + + tree->SetBranchAddress("RunSince", &RunSince, &b_RunSince); + tree->SetBranchAddress("RunUntil", &RunUntil, &b_RunUntil); + tree->SetBranchAddress("LBSince", &LBSince, &b_LBSince); + tree->SetBranchAddress("LBUntil", &LBUntil, &b_LBUntil); + tree->SetBranchAddress("ChannelID", &ChannelID, &b_ChannelID); + tree->SetBranchAddress("TagID", TagID, &b_TagID); + tree->SetBranchAddress("Code", &Code, &b_Code); + tree->SetBranchAddress("Algo", Algo, &b_Algo); + tree->SetBranchAddress("Entries", &Entries, &b_Entries); + tree->SetBranchAddress("Par1", &Par1, &b_Par1); + tree->SetBranchAddress("Par2", &Par2, &b_Par2); + tree->SetBranchAddress("Par3", &Par3, &b_Par3); + tree->SetBranchAddress("Par4", &Par4, &b_Par4); + tree->SetBranchAddress("Par5", &Par5, &b_Par5); + + TGraphErrors *entr_g = new TGraphErrors(); + TGraphErrors *par1_g[4]; + TGraphErrors *par2_g[4]; + TGraphErrors *par3_g[4]; + TGraphErrors *par4_g[4]; + TGraphErrors *par5_g[4]; + + for (int k=0;k<4;k++) { + par1_g[k] = new TGraphErrors(); + par2_g[k] = new TGraphErrors(); + par3_g[k] = new TGraphErrors(); + par4_g[k] = new TGraphErrors(); + par5_g[k] = new TGraphErrors(); + } + + std::string Algorithm; + + Int_t nentries = tree->GetEntries(); + + if (nentries<1) { + std::cout << " The TTree is empty! Check if the right Folder DB Tag is used" << std::endl; + return; + } + + for (Int_t jj=0; jj<nentries; jj++) { + tree->GetEntry(jj); + + if (i==ChannelID && ((RunSince>=init_run) && (RunSince<=last_run))) { + Algorithm=Algo; + if (Algorithm=="BinContentComp" && Par5!=0.) { + int npoints = 0; + + // N Entries + npoints=entr_g->GetN(); + npoints++; + entr_g->Set(npoints); + entr_g->SetPoint(npoints-1,RunSince,Entries); + entr_g->SetPointError(npoints-1,0.,sqrt(Entries)); + + // Par 1 + int npoints1=0; int npoints2=0; int npoints3=0; int npoints4=0; int npoints5=0; + npoints1=0; npoints2=0; npoints3=0; npoints4=0; npoints5=0; + for (int k=0;k<4;k++) npoints1=par1_g[k]->GetN(); + for (int k=0;k<4;k++) npoints2=par2_g[k]->GetN(); + for (int k=0;k<4;k++) npoints3=par3_g[k]->GetN(); + for (int k=0;k<4;k++) npoints4=par4_g[k]->GetN(); + for (int k=0;k<4;k++) npoints5=par5_g[k]->GetN(); + npoints1++; + npoints2++; + npoints3++; + npoints4++; + npoints5++; + for (int k=0;k<4;k++) { + par1_g[k]->Set(npoints1); + par2_g[k]->Set(npoints2); + par3_g[k]->Set(npoints3); + par4_g[k]->Set(npoints4); + par5_g[k]->Set(npoints5); + } + par1_g[0]->SetPoint(npoints1-1,RunSince,Par1); + par2_g[0]->SetPoint(npoints2-1,RunSince,Par2); + par3_g[0]->SetPoint(npoints3-1,RunSince,Par3); + par4_g[0]->SetPoint(npoints4-1,RunSince,Par4); + par5_g[0]->SetPoint(npoints5-1,RunSince,Par5); + if (Code==1) { + par1_g[1]->SetPoint(npoints1-1,RunSince,Par1); + par2_g[1]->SetPoint(npoints2-1,RunSince,Par2); + par3_g[1]->SetPoint(npoints3-1,RunSince,Par3); + par4_g[1]->SetPoint(npoints4-1,RunSince,Par4); + par5_g[1]->SetPoint(npoints5-1,RunSince,Par5); + } + if (Code==2) { + par1_g[2]->SetPoint(npoints1-1,RunSince,Par1); + par2_g[2]->SetPoint(npoints2-1,RunSince,Par2); + par3_g[2]->SetPoint(npoints3-1,RunSince,Par3); + par4_g[2]->SetPoint(npoints4-1,RunSince,Par4); + par5_g[2]->SetPoint(npoints5-1,RunSince,Par5); + } + if (Code==3) { + par1_g[3]->SetPoint(npoints1-1,RunSince,Par1); + par2_g[3]->SetPoint(npoints2-1,RunSince,Par2); + par3_g[3]->SetPoint(npoints3-1,RunSince,Par3); + par4_g[3]->SetPoint(npoints4-1,RunSince,Par4); + par5_g[3]->SetPoint(npoints5-1,RunSince,Par5); + } + + par1_g[0]->SetPointError(npoints1-1,0.,0.); + par2_g[0]->SetPointError(npoints2-1,0.,Par2/sqrt(Entries)); + par3_g[0]->SetPointError(npoints3-1,0.,Par3/sqrt(Entries)); + par4_g[0]->SetPointError(npoints4-1,0.,Par4/sqrt(Entries)); + par5_g[0]->SetPointError(npoints5-1,0.,Par5/sqrt(Entries)); + } + } + + if (i==ChannelID && ((RunSince>=init_run) && (RunSince<=last_run))) { + Algorithm=Algo; + int npoints=0; + // N Entries + npoints=entr_g->GetN(); + npoints++; + entr_g->Set(npoints); + entr_g->SetPoint(npoints-1,RunSince,Entries); + entr_g->SetPointError(npoints-1,0.,sqrt(Entries)); + + // Par 1 + npoints=0; + for (int k=0;k<4;k++) npoints=par1_g[k]->GetN(); + npoints++; + for (int k=0;k<4;k++) par1_g[k]->Set(npoints); + par1_g[0]->SetPoint(npoints-1,RunSince,Par1); + if (Code==1) par1_g[1]->SetPoint(npoints-1,RunSince,Par1); + if (Code==2) par1_g[2]->SetPoint(npoints-1,RunSince,Par1); + if (Code==3) par1_g[3]->SetPoint(npoints-1,RunSince,Par1); + + + std::string::size_type loc = Algorithm.find( "CheckHisto_Mean&GatherData", 0 ); + if( loc != std::string::npos ) { + Algorithm="CheckHisto_Mean&GatherData"; + } + + if (Algorithm=="GatherData" || Algorithm=="Histogram_Not_Empty&GatherData" || + Algorithm=="CheckHisto_Mean&GatherData" || Algorithm=="BinContentComp&GatherData") { + // in this case, Par1=Mean, error depends on the algorithm + if (Par3> 0 || Par4>0) { + // this is the new GatherData: return Mean, EMean, RMS, ERMS or + // Mean, EMean, RMS, ERMS + XMean or Mean, EMean, NBins, RMS, ERMS + par1_g[0]->SetPointError(npoints-1,0.,Par2); + } else { + // this is the old GatherData: return Mean and RMS only + if (Entries>0.) { + par1_g[0]->SetPointError(npoints-1,0.,Par2/sqrt(Entries)); + } else { + par1_g[0]->SetPointError(npoints-1,0.,0.); + } + } + } else { + if (Entries>0.) { + if (Algorithm=="Simple_gaus_Fit") { + par1_g[0]->SetPointError(npoints-1,0.,Par2/sqrt(Entries)); + } else { + par1_g[0]->SetPointError(npoints-1,0.,Par1/sqrt(Entries)); + } + } else { + par1_g[0]->SetPointError(npoints-1,0.,0.); + } + } + + // Par2 + npoints=0; + for (int k=0;k<4;k++) npoints=par2_g[k]->GetN(); + npoints++; + for (int k=0;k<4;k++) par2_g[k]->Set(npoints); + par2_g[0]->SetPoint(npoints-1,RunSince,Par2); + if (Code==1) par2_g[1]->SetPoint(npoints-1,RunSince,Par2); + if (Code==2) par2_g[2]->SetPoint(npoints-1,RunSince,Par2); + if (Code==3) par2_g[3]->SetPoint(npoints-1,RunSince,Par2); + if (Entries>0.) { + par2_g[0]->SetPointError(npoints-1,0.,Par2/sqrt(Entries)); + } else { + par2_g[0]->SetPointError(npoints-1,0.,0.); + } + + if ((Algorithm=="GatherData" || Algorithm=="Histogram_Not_Empty&GatherData") && + (Par3> 0 || Par4>0) ) { + // this is the new GatherData: return Mean, EMean, RMS, ERMS + par2_g[0]->SetPoint(npoints-1,RunSince,Par3); + if (Code==1) par2_g[1]->SetPoint(npoints-1,RunSince,Par3); + if (Code==2) par2_g[2]->SetPoint(npoints-1,RunSince,Par3); + if (Code==3) par2_g[3]->SetPoint(npoints-1,RunSince,Par3); + par2_g[0]->SetPointError(npoints-1,0.,Par4); + } + + if ((Algorithm=="CheckHisto_Mean&GatherData" || Algorithm=="BinContentComp&GatherData" + ) && (Par5!= 0)) { + // this is the new GatherData: return Mean, EMean, RMS, ERMS + XMean or Mean, EMean, NBins, RMS, ERMS + if (Algorithm=="BinContentComp&GatherData") { + par2_g[0]->SetPoint(npoints-1,RunSince,Par4); + if (Code==1) par2_g[1]->SetPoint(npoints-1,RunSince,Par4); + if (Code==2) par2_g[2]->SetPoint(npoints-1,RunSince,Par4); + if (Code==3) par2_g[3]->SetPoint(npoints-1,RunSince,Par4); + par2_g[0]->SetPointError(npoints-1,0.,Par5); + } + if (Algorithm=="CheckHisto_Mean&GatherData") { + par2_g[0]->SetPoint(npoints-1,RunSince,Par3); + if (Code==1) par2_g[1]->SetPoint(npoints-1,RunSince,Par3); + if (Code==2) par2_g[2]->SetPoint(npoints-1,RunSince,Par3); + if (Code==3) par2_g[3]->SetPoint(npoints-1,RunSince,Par3); + par2_g[0]->SetPointError(npoints-1,0.,Par4); + } + } + + //Par3 + npoints=0; + if (Algorithm=="Simple_gaus_Fit" || Algorithm=="BinContentComp&GatherData" + || Algorithm=="CheckHisto_Mean&GatherData") { //currently the only algorithms with third parameter filled + for (int k=0;k<4;k++) npoints=par3_g[k]->GetN(); + npoints++; + for (int k=0;k<4;k++) par3_g[k]->Set(npoints); + par3_g[0]->SetPoint(npoints-1,RunSince,Par3); + if (Code==1) par3_g[1]->SetPoint(npoints-1,RunSince,Par3); + if (Code==2) par3_g[2]->SetPoint(npoints-1,RunSince,Par3); + if (Code==3) par3_g[3]->SetPoint(npoints-1,RunSince,Par3); + if (Entries>0.) { + par3_g[0]->SetPointError(npoints-1,0.,Par3/sqrt(Entries)); + } else { + par3_g[0]->SetPointError(npoints-1,0.,0.); + } + if (Algorithm=="CheckHisto_Mean&GatherData") { + if (Par5!=0) { + par3_g[0]->SetPoint(npoints-1,RunSince,Par5); + if (Code==1) par3_g[1]->SetPoint(npoints-1,RunSince,Par5); + if (Code==2) par3_g[2]->SetPoint(npoints-1,RunSince,Par5); + if (Code==3) par3_g[3]->SetPoint(npoints-1,RunSince,Par5); + par3_g[0]->SetPointError(npoints-1,0.,Par4); + } else { + par3_g[0]->SetPoint(npoints-1,RunSince,Par3); + if (Code==1) par3_g[1]->SetPoint(npoints-1,RunSince,Par3); + if (Code==2) par3_g[2]->SetPoint(npoints-1,RunSince,Par3); + if (Code==3) par3_g[3]->SetPoint(npoints-1,RunSince,Par3); + if (Entries>0.) par3_g[0]->SetPointError(npoints-1,0.,Par2/sqrt(Entries)); + } + } + } + } // end channel selection and run range selection + } + + TFile *hfile = (TFile*)gROOT->GetListOfFiles()->FindObject("c1.root"); + if (hfile) hfile->Close(); + hfile = new TFile("c1.root","RECREATE","ROOT file with graphs"); + + std::string par1_name= defParName(Algorithm, nameh, 1); + std::string par2_name= defParName(Algorithm, nameh, 2); + std::string par3_name= defParName(Algorithm, nameh, 3); + std::string par4_name= defParName(Algorithm, nameh, 4); + std::string par5_name= defParName(Algorithm, nameh, 5); + + std::string status_code[4]; + status_code[0]=""; + status_code[1]="Red"; + status_code[2]="Yellow"; + status_code[3]="Green"; + + std::string par1_g_name[4]; std::string par2_g_name[4]; std::string par3_g_name[4]; std::string par4_g_name[4]; std::string par5_g_name[4]; + for (int k=0;k<4;k++) { + par1_g_name[k] = "Par1, Algo:"+Algorithm+" "+status_code[k]; par2_g_name[k] = "Par2, Algo:"+Algorithm+" "+status_code[k]; + par3_g_name[k] = "Par3, Algo:"+Algorithm+" "+status_code[k]; par4_g_name[k] = "Par4, Algo:"+Algorithm+" "+status_code[k]; + par5_g_name[k] = "Par5, Algo:"+Algorithm+" "+status_code[k]; + } + + TCanvas *c1 = new TCanvas("c1"," History "); + if (Algorithm=="Simple_gaus_Fit" || Algorithm=="BinContentComp&GatherData" || Algorithm=="CheckHisto_Mean&GatherData") { //currently the only algorithms with third parameter filled + c1->SetCanvasSize(900,900); c1->Divide(2,2); + } else { + if (Algorithm=="BinContentComp") { + c1->SetCanvasSize(900,900); c1->Divide(2,3); + } else { + c1->SetCanvasSize(1000,450); c1->Divide(3,1); + } + } + c1->Update(); + int green = TColor::GetColor("#009900"); + int yellow = TColor::GetColor("#ff9933"); + + c1->cd(1); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,entr_g); + entr_g->SetTitle("N Entries"); + entr_g->GetYaxis()->SetTitle("N entries"); + entr_g->SetMarkerStyle(20); + + bool non_zero=false; + + if (entr_g->GetMaxSize()!=0) { + entr_g->Draw("ap"); + non_zero=true; + } + + c1->cd(2); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,par1_g[0]); + for (int k=0;k<4;k++) { + par1_g[k]->SetTitle(par1_g_name[k].c_str()); + par1_g[k]->SetMarkerStyle(20); + } + par1_g[0]->GetYaxis()->SetTitle(par1_name.c_str()); + par1_g[1]->SetMarkerColor(2); + par1_g[2]->SetMarkerColor(yellow); + par1_g[3]->SetMarkerColor(green); + if (non_zero) { + par1_g[0]->Draw("ap"); + par1_g[1]->Draw("p"); + par1_g[2]->Draw("p"); + par1_g[3]->Draw("p"); + } + c1->cd(3); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,par2_g[0]); + par2_g[0]->GetYaxis()->SetTitle(par2_name.c_str()); + for (int k=0;k<4;k++) { + par2_g[k]->SetTitle(par2_g_name[k].c_str()); + par2_g[k]->SetMarkerStyle(20); + } + par2_g[1]->SetMarkerColor(2); + par2_g[2]->SetMarkerColor(yellow); + par2_g[3]->SetMarkerColor(green); + if (non_zero) { + par2_g[0]->Draw("ap"); + par2_g[1]->Draw("p"); + par2_g[2]->Draw("p"); + par2_g[3]->Draw("p"); + } + if (Algorithm=="Simple_gaus_Fit" || Algorithm=="BinContentComp&GatherData" || (Algorithm=="BinContentComp") || + Algorithm=="CheckHisto_Mean&GatherData") { //currently the only algorithm with third parameter filled + c1->cd(4); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,par3_g[0]); + par3_g[0]->GetYaxis()->SetTitle(par3_name.c_str()); + for (int k=0;k<4;k++) { + par3_g[k]->SetMarkerStyle(20); + par3_g[k]->SetTitle(par3_g_name[k].c_str()); + } + par3_g[1]->SetMarkerColor(2); + par3_g[2]->SetMarkerColor(yellow); + par3_g[3]->SetMarkerColor(green); + if (non_zero) { + par3_g[0]->Draw("ap"); + par3_g[1]->Draw("p"); + par3_g[2]->Draw("p"); + par3_g[3]->Draw("p"); + } + } + + if (Algorithm=="BinContentComp") { + c1->cd(5); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,par4_g[0]); + par4_g[0]->GetYaxis()->SetTitle(par4_name.c_str()); + for (int k=0;k<4;k++) { + par4_g[k]->SetMarkerStyle(20); + par4_g[k]->SetTitle(par4_g_name[k].c_str()); + } + par4_g[1]->SetMarkerColor(2); + par4_g[2]->SetMarkerColor(yellow); + par4_g[3]->SetMarkerColor(green); + if (non_zero) { + par4_g[0]->Draw("ap"); + par4_g[1]->Draw("p"); + par4_g[2]->Draw("p"); + par4_g[3]->Draw("p"); + } + + c1->cd(6); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,par5_g[0]); + par5_g[0]->GetYaxis()->SetTitle(par5_name.c_str()); + for (int k=0;k<4;k++) { + par5_g[k]->SetMarkerStyle(20); + par5_g[k]->SetTitle(par5_g_name[k].c_str()); + } + par5_g[1]->SetMarkerColor(2); + par5_g[2]->SetMarkerColor(yellow); + par5_g[3]->SetMarkerColor(green); + if (non_zero) { + par5_g[0]->Draw("ap"); + par5_g[1]->Draw("p"); + par5_g[2]->Draw("p"); + par5_g[3]->Draw("p"); + } + + } + + entr_g->Write("Nentr"); + for (int k=0;k<4;k++) { + if (par1_g[k]) par1_g[k]->Write(par1_g_name[k].c_str()); + if (par2_g[k]) par2_g[k]->Write(par2_g_name[k].c_str()); + if (par3_g[k]) par3_g[k]->Write(par3_g_name[k].c_str()); + if (par4_g[k]) par4_g[k]->Write(par4_g_name[k].c_str()); + if (par5_g[k]) par5_g[k]->Write(par5_g_name[k].c_str()); + } + + hfile->Close(); + if (non_zero) { + c1->Print("c1.gif"); + } + delete entr_g; + for (int k=0;k<4;k++) { + if (par1_g[k]) delete par1_g[k]; + if (par2_g[k]) delete par2_g[k]; + if (par3_g[k]) delete par3_g[k]; + if (par4_g[k]) delete par4_g[k]; + if (par5_g[k]) delete par5_g[k]; + } + f->Close(); + +} + +void +HistogramDataCOOL:: +historyDB( int HistoId, std::string nameHisto, std::string tag_name ) +{ + gStyle->SetFrameBorderMode(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetCanvasColor(0); + gStyle->SetTitleColor(1); + gStyle->SetStatColor(0); + gStyle->SetFillColor(1); + gStyle->SetPalette(1,0); + gStyle->SetTitleFontSize(0.06); + gStyle->SetTitleH(0.06); + + int run[10000]; + float StatusH[1000]; + float Entries[1000]; + float Par1[1000]; + float Par2[1000]; + float Par3[1000]; + float Par4[1000]; + float Par5[1000]; + std::string Algorithm; + std::string Algorithm1; + + gROOT->SetBatch(); + + for (int j=0;j<1000;j++) { + StatusH[j]=-2.; + Par1[j]=0.; + Par2[j]=0.; + Par3[j]=0.; + Par4[j]=0.; + Par5[j]=0.; + } + + std::ifstream tmp_run("runxml"); + if (!tmp_run.is_open()) + { + std::cout << " Could not open the run list file " << std::endl; + return; + } + + Int_t dummy=0; + while(tmp_run.good()) { + tmp_run >> run[dummy]; + dummy++; + } + int ALL = dummy-1; + int i = HistoId; + std::string nameh = nameHisto; + std::string tagDB = tag_name; + + for (int j=0;j<ALL;j++) { + setIOV(run[j]); + StatusH[j]=dumpCode(nameh, tagDB); + std::string entr=dumpHisto(i,"Entries", tagDB); + std::string alg=dumpHisto(i,"Algo", tagDB); + std::string aa=dumpHisto(i,"Par1", tagDB); + std::string cc=dumpHisto(i,"Par2", tagDB); + std::string ee=dumpHisto(i,"Par3", tagDB); + std::string gg=dumpHisto(i,"Par4", tagDB); + std::string ll=dumpHisto(i,"Par5", tagDB); + + std::istringstream entri(entr); + std::istringstream algo(alg); + std::istringstream bb(aa); + std::istringstream dd(cc); + std::istringstream ff(ee); + std::istringstream hh(gg); + std::istringstream mm(ll); + + entri >> Entries[j]; + algo >> Algorithm1; + bb >> Par1[j]; + dd >> Par2[j]; + ff >> Par3[j]; + hh >> Par4[j]; + mm >> Par5[j]; + if (alg.length()>0) Algorithm = Algorithm1; + } + + TFile *hfile = (TFile*)gROOT->GetListOfFiles()->FindObject("c1.root"); + if (hfile) hfile->Close(); + hfile = new TFile("c1.root","RECREATE","ROOT file with graphs"); + + TGraphErrors *entr_g = new TGraphErrors(); + TGraphErrors *par1_g[4]; + TGraphErrors *par2_g[4]; + TGraphErrors *par3_g[4]; + TGraphErrors *par4_g[4]; + // TGraphErrors *par5_g[4]; + + for (int k=0;k<4;k++) { + par1_g[k] = new TGraphErrors(); + par2_g[k] = new TGraphErrors(); + par3_g[k] = new TGraphErrors(); + par4_g[k] = new TGraphErrors(); + // par5_g[k] = new TGraphErrors(); + } + + + std::string par1_name= defParName(Algorithm, nameh, 1); + std::string par2_name= defParName(Algorithm, nameh, 2); + std::string par3_name= defParName(Algorithm, nameh, 3); + std::string par4_name= defParName(Algorithm, nameh, 4); + std::string par5_name= defParName(Algorithm, nameh, 5); + + std::string status_code[4]; + status_code[0]=""; + status_code[1]="Red"; + status_code[2]="Yellow"; + status_code[3]="Green"; + + std::string par1_g_name[4]; std::string par2_g_name[4]; std::string par3_g_name[4]; std::string par4_g_name[4]; std::string par5_g_name[4]; + for (int k=0;k<4;k++) { + par1_g_name[k] = "Par1, Algo:"+Algorithm+" "+status_code[k]; par2_g_name[k] = "Par2, Algo:"+Algorithm+" "+status_code[k]; + par3_g_name[k] = "Par3, Algo:"+Algorithm+" "+status_code[k]; par4_g_name[k] = "Par4, Algo:"+Algorithm+" "+status_code[k]; + par5_g_name[k] = "Par5, Algo:"+Algorithm+" "+status_code[k]; + } + + for (int j=0;j<(ALL);j++) { + int npoints=entr_g->GetN(); + npoints++; + entr_g->Set(npoints); + entr_g->SetPoint(npoints-1,run[j],Entries[j]); + entr_g->SetPointError(npoints-1,0.,sqrt(Entries[j])); + } + + std::string::size_type loc = Algorithm.find( "CheckHisto_Mean&GatherData", 0 ); + if( loc != std::string::npos ) { + Algorithm="CheckHisto_Mean&GatherData"; + } + + //Par1 + for (int j=0;j<(ALL);j++) { + int npoints; + for (int k=0;k<4;k++) npoints=par1_g[k]->GetN(); + npoints++; + for (int k=0;k<4;k++) par1_g[k]->Set(npoints); + par1_g[0]->SetPoint(npoints-1,run[j],Par1[j]); + if (StatusH[j]==1) par1_g[1]->SetPoint(npoints-1,run[j],Par1[j]); + if (StatusH[j]==2) par1_g[2]->SetPoint(npoints-1,run[j],Par1[j]); + if (StatusH[j]==3) par1_g[3]->SetPoint(npoints-1,run[j],Par1[j]); + + if (Algorithm=="GatherData" || Algorithm=="Histogram_Not_Empty&GatherData" || + Algorithm=="CheckHisto_Mean&GatherData" || Algorithm=="BinContentComp&GatherData") { + // in this case, Par1=Mean, error depends on the algorithm + if (Par3[j]> 0 || Par4[j]>0) { + // this is the new GatherData: return Mean, EMean, RMS, ERMS or + // Mean, EMean, RMS, ERMS + XMean or Mean, EMean, NBins, RMS, ERMS + par1_g[0]->SetPointError(npoints-1,0.,Par2[j]); + } else { + // this is the old GatherData: return Mean and RMS only + if (Entries[j]>0.) { + par1_g[0]->SetPointError(npoints-1,0.,Par2[j]/sqrt(Entries[j])); + } else { + par1_g[0]->SetPointError(npoints-1,0.,0.); + } + } + } else { + if (Entries[j]>0.) { + if (Algorithm=="Simple_gaus_Fit") { + par1_g[0]->SetPointError(npoints-1,0.,Par2[j]/sqrt(Entries[j])); + } else { + par1_g[0]->SetPointError(npoints-1,0.,Par1[j]/sqrt(Entries[j])); + } + } else { + par1_g[0]->SetPointError(npoints-1,0.,0.); + } + } + } + + //Par2 + for (int j=0;j<(ALL);j++) { + int npoints; + for (int k=0;k<4;k++) npoints=par2_g[k]->GetN(); + npoints++; + for (int k=0;k<4;k++) par2_g[k]->Set(npoints); + par2_g[0]->SetPoint(npoints-1,run[j],Par2[j]); + if (StatusH[j]==1) par2_g[1]->SetPoint(npoints-1,run[j],Par2[j]); + if (StatusH[j]==2) par2_g[2]->SetPoint(npoints-1,run[j],Par2[j]); + if (StatusH[j]==3) par2_g[3]->SetPoint(npoints-1,run[j],Par2[j]); + if (Entries[j]>0.) { + par2_g[0]->SetPointError(npoints-1,0.,Par2[j]/sqrt(Entries[j])); + } else { + par2_g[0]->SetPointError(npoints-1,0.,0.); + } + + if ((Algorithm=="GatherData" || Algorithm=="Histogram_Not_Empty&GatherData") && + (Par3[j]> 0 || Par4[j]>0) ) { + // this is the new GatherData: return Mean, EMean, RMS, ERMS + par2_g[0]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==1) par2_g[1]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==2) par2_g[2]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==3) par2_g[3]->SetPoint(npoints-1,run[j],Par3[j]); + par2_g[0]->SetPointError(npoints-1,0.,Par4[j]); + } + + if ((Algorithm=="CheckHisto_Mean&GatherData" || Algorithm=="BinContentComp&GatherData" + ) && (Par5[j]!= 0)) { + // this is the new GatherData: return Mean, EMean, RMS, ERMS + XMean or Mean, EMean, NBins, RMS, ERMS + if (Algorithm=="BinContentComp&GatherData") { + par2_g[0]->SetPoint(npoints-1,run[j],Par4[j]); + if (StatusH[j]==1) par2_g[1]->SetPoint(npoints-1,run[j],Par4[j]); + if (StatusH[j]==2) par2_g[2]->SetPoint(npoints-1,run[j],Par4[j]); + if (StatusH[j]==3) par2_g[3]->SetPoint(npoints-1,run[j],Par4[j]); + par2_g[0]->SetPointError(npoints-1,0.,Par5[j]); + } + if (Algorithm=="CheckHisto_Mean&GatherData") { + par2_g[0]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==1) par2_g[1]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==2) par2_g[2]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==3) par2_g[3]->SetPoint(npoints-1,run[j],Par3[j]); + par2_g[0]->SetPointError(npoints-1,0.,Par4[j]); + } + } + } + + //Par3 + if (Algorithm=="Simple_gaus_Fit" || Algorithm=="BinContentComp&GatherData" + || Algorithm=="CheckHisto_Mean&GatherData") { //currently the only algorithms with third parameter filled + for (int j=0;j<(ALL);j++) { + int npoints; + for (int k=0;k<4;k++) npoints=par3_g[k]->GetN(); + npoints++; + for (int k=0;k<4;k++) par3_g[k]->Set(npoints); + par3_g[0]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==1) par3_g[1]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==2) par3_g[2]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==3) par3_g[3]->SetPoint(npoints-1,run[j],Par3[j]); + if (Entries[j]>0.) { + par3_g[0]->SetPointError(npoints-1,0.,Par3[j]/sqrt(Entries[j])); + } else { + par3_g[0]->SetPointError(npoints-1,0.,0.); + } + if (Algorithm=="CheckHisto_Mean&GatherData") { + if (Par5[j]!=0) { + par3_g[0]->SetPoint(npoints-1,run[j],Par5[j]); + if (StatusH[j]==1) par3_g[1]->SetPoint(npoints-1,run[j],Par5[j]); + if (StatusH[j]==2) par3_g[2]->SetPoint(npoints-1,run[j],Par5[j]); + if (StatusH[j]==3) par3_g[3]->SetPoint(npoints-1,run[j],Par5[j]); + par3_g[0]->SetPointError(npoints-1,0.,Par4[j]); + } else { + par3_g[0]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==1) par3_g[1]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==2) par3_g[2]->SetPoint(npoints-1,run[j],Par3[j]); + if (StatusH[j]==3) par3_g[3]->SetPoint(npoints-1,run[j],Par3[j]); + if (Entries[j]>0.) par3_g[0]->SetPointError(npoints-1,0.,Par2[j]/sqrt(Entries[j])); + } + } + } + } + + TCanvas *c1 = new TCanvas("c1"," History "); + if (Algorithm=="Simple_gaus_Fit" || Algorithm=="BinContentComp&GatherData" + || (Algorithm=="CheckHisto_Mean&GatherData")) { //currently the only algorithms with third parameter filled + c1->SetCanvasSize(900,900); c1->Divide(2,2); + } else { + c1->SetCanvasSize(1000,450); c1->Divide(3,1); + } + + c1->Update(); + int green = TColor::GetColor("#009900"); + int yellow = TColor::GetColor("#ff9933"); + + c1->cd(1); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,entr_g); + entr_g->SetTitle("N Entries"); + entr_g->GetXaxis()->SetRange(run[0],run[ALL-1]); + entr_g->GetYaxis()->SetTitle("N entries"); + entr_g->SetMarkerStyle(20); + entr_g->Draw("ap"); + + c1->cd(2); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,par1_g[0]); + for (int k=0;k<4;k++) { + par1_g[k]->SetTitle(par1_g_name[k].c_str()); + par1_g[k]->SetMarkerStyle(20); + } + par1_g[0]->GetYaxis()->SetTitle(par1_name.c_str()); + par1_g[1]->SetMarkerColor(2); + par1_g[2]->SetMarkerColor(yellow); + par1_g[3]->SetMarkerColor(green); + par1_g[0]->Draw("ap"); + par1_g[1]->Draw("p"); + par1_g[2]->Draw("p"); + par1_g[3]->Draw("p"); + + c1->cd(3); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,par2_g[0]); + par2_g[0]->GetYaxis()->SetTitle(par2_name.c_str()); + for (int k=0;k<4;k++) { + par2_g[k]->SetTitle(par2_g_name[k].c_str()); + par2_g[k]->SetMarkerStyle(20); + } + par2_g[1]->SetMarkerColor(2); + par2_g[2]->SetMarkerColor(yellow); + par2_g[3]->SetMarkerColor(green); + par2_g[0]->Draw("ap"); + par2_g[1]->Draw("p"); + par2_g[2]->Draw("p"); + par2_g[3]->Draw("p"); + + + if (Algorithm=="Simple_gaus_Fit" || Algorithm=="BinContentComp&GatherData" || + Algorithm=="CheckHisto_Mean&GatherData") { //currently the only algorithm with third parameter filled + c1->cd(4); + gPad->SetGridx(); gPad->SetGridy(); + formatGraph( c1,par3_g[0]); + par3_g[0]->GetYaxis()->SetTitle(par3_name.c_str()); + for (int k=0;k<4;k++) { + par3_g[k]->SetMarkerStyle(20); + par3_g[k]->SetTitle(par3_g_name[k].c_str()); + } + par3_g[1]->SetMarkerColor(2); + par3_g[2]->SetMarkerColor(yellow); + par3_g[3]->SetMarkerColor(green); + par3_g[0]->Draw("ap"); + par3_g[1]->Draw("p"); + par3_g[2]->Draw("p"); + par3_g[3]->Draw("p"); + + } + + + entr_g->Write("Nentr"); + for (int k=0;k<4;k++) { + if (par1_g[k]) par1_g[k]->Write(par1_g_name[k].c_str()); + if (par2_g[k]) par2_g[k]->Write(par2_g_name[k].c_str()); + if (par3_g[k]) par3_g[k]->Write(par3_g_name[k].c_str()); + if (par4_g[k]) par4_g[k]->Write(par4_g_name[k].c_str()); + } + + hfile->Close(); + c1->Print("c1.gif"); + + delete entr_g; + for (int k=0;k<4;k++) { + if (par1_g[k]) delete par1_g[k]; + if (par2_g[k]) delete par2_g[k]; + if (par3_g[k]) delete par3_g[k]; + if (par4_g[k]) delete par4_g[k]; + } + + return; +} + +std::string +HistogramDataCOOL:: +defParName(std::string algo, std::string nameHisto, int i) +{ + std::string Algorithm = algo; + std::string nameh = nameHisto; + std::string par1_name="Par1"; std::string par2_name="Par2"; std::string par3_name="Par3"; + std::string par4_name="Par4"; std::string par5_name="Par5"; + + + if (Algorithm=="GatherData" || Algorithm=="Histogram_Not_Empty&GatherData") { + par1_name = "Mean"; + par2_name = "RMS"; + } + if (Algorithm=="CheckHisto_Mean&GatherData") { + par1_name = "Mean"; + par2_name = "RMS"; + par3_name = "XMean"; + par4_name = "YMean"; + } + if (Algorithm=="BinContentComp&GatherData") { + par1_name = "Mean"; + par2_name = "RMS"; + par3_name = "NBins"; + } + if (Algorithm=="Bins_Diff_FromAvg") { + par1_name = "Average"; + par2_name = "NBins_above_Av"; + } + if (Algorithm=="Simple_pol1_Fit") { + par1_name = "par[0]"; + par2_name = "par[1]"; + } + if (Algorithm=="Simple_gaus_Fit") { + par1_name = "Mean gaus"; + par2_name = "RMS gaus"; + par3_name = "Constant gaus"; + } + if (Algorithm=="SideBand_Absolute" || + Algorithm=="SideBand_Relative") { + par1_name = "SideBands"; + par2_name = "Total Integral"; + } + if (Algorithm=="CheckHisto_Mean") { + par1_name = "XMean"; + par2_name = "YMean"; + } + if (Algorithm=="CheckHisto_RMS") { + par1_name = "XRMS"; + par2_name = "YRMS"; + } + if (Algorithm=="Histogram_Not_Empty" || + Algorithm=="Histogram_Empty" || + Algorithm=="No_OverFlows" || + Algorithm=="No_UnderFlows" || + Algorithm=="Histogram_Effective_Empty") { + + par1_name = "NULL par"; + par2_name = "NULL par"; + } + + if (Algorithm=="Bins_LessThan_Threshold" || + Algorithm=="Bins_LessThanEqual_Threshold" || + Algorithm=="Bins_GreaterThan_Threshold" || + Algorithm=="Bins_GreaterThanEqual_Threshold" || + Algorithm=="Bins_Equal_Threshold" || + Algorithm=="Bins_NotEqual_Threshold" ) { + + par1_name = "NBins Less/Equal/NotEqual/Above Threshold"; + par2_name = "NULL par"; + } + + if (Algorithm=="BinContentComp") { + par1_name = "NBins"; + par2_name = "Pix L0"; + par3_name = "Pix L1"; + par4_name = "Pix L2"; + par5_name = "SCT L0 S0"; + } + + if (i==1) { + return par1_name; + } else { + if (i==2) { + return par2_name; + } else { + if (i==3) { + return par3_name; + } else { + if (i==4) { + return par4_name; + } else { + if (i==5) { + return par5_name; + } else + return 0; + } + } + } + } + +} + +void +HistogramDataCOOL:: +formatGraph( TCanvas* c, TGraphErrors* gr ) const +{ + if( c == 0 || gr == 0 ) + return; + + c->SetLeftMargin(0.15); + c->SetRightMargin(0.13); + c->SetBottomMargin(0.15); + c->SetTopMargin(0.12); + + gr->GetXaxis()->SetLabelSize(0.04); + gr->GetYaxis()->SetLabelSize(0.04); + gr->GetXaxis()->SetLabelFont(62); + gr->GetYaxis()->SetLabelFont(62); + + gr->GetXaxis()->SetTitleSize(0.04); + gr->GetYaxis()->SetTitleSize(0.04); + gr->GetXaxis()->SetTitleFont(62); + gr->GetYaxis()->SetTitleFont(62); + gr->GetXaxis()->SetTitle("Runs"); + + gr->GetYaxis()->SetTitleOffset(1.5); + gr->GetXaxis()->SetTitleOffset(0.9); + + gr->GetXaxis()->SetNdivisions(504); + +} + + // end of modification in insert functions (Monica 4/6/2008) + +cool::IDatabasePtr +HistogramDataCOOL:: +getCoolDb() { + return this->coolDb; +} + + + +} //namespace dqutils diff --git a/DataQuality/DataQualityUtils/src/MdtDeadNoisyUtils.cxx b/DataQuality/DataQualityUtils/src/MdtDeadNoisyUtils.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4f0cc54d13fd4a87172b0b9e773c2c7f3dbee7a0 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MdtDeadNoisyUtils.cxx @@ -0,0 +1,1714 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//Method To Calculate MDT Dead Noisy Tubes +//Author Orin Harris omh@cern.ch University of Washington +// Justin Griffiths griffith@cern.ch University of Washington +//Aug 2009 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#include "DataQualityUtils/MdtDeadNoisyUtils.h" +#include <cmath> +#include <algorithm> +#include <TLine.h> +#include <TText.h> + +using std::sort; +using std::vector; + +#define STDDEV_POS 1.0 +#define MARKER_POS_RED 0.6 +#define MEZZ_POS 0.4 +#define LAYER_POS 0.3 +#define ML_POS 0.22 +#define MARKER_POS_BLUE 0.15 + +namespace dqutils_mdtdeadnoisy { + + double sqr( double x ) { + return x*x; + } + + void displayList( std::vector<int> & v ) { + std::cout << "{ "; + if(v.size()>1) { + if( v.at(0)+1 != v.at(1) ) std::cout << v.at(0) << ", "; + else if( v.at(0)+1 == v.at(1) ) std::cout << v.at(0) << "-"; + for(unsigned int i=1; i<v.size()-1; i++) { + if( v.at(i)+1 != v.at(i+1) ) std::cout << v.at(i) << ", "; + else if( v.at(i-1)+1 != v.at(i) && v.at(i)+1 == v.at(i+1) ) std::cout << v.at(i) << "-"; + } + std::cout << v.back(); + } + else if(v.size()>0) + std::cout << v.at(0); + std::cout << " }" << std::endl; + } + + void displayList( std::vector<int> & v, ofstream & outputfile ) { + outputfile << "{ "; + if(v.size()>1) { + if( v.at(0)+1 != v.at(1) ) outputfile << v.at(0) << ", "; + else if( v.at(0)+1 == v.at(1) ) outputfile << v.at(0) << "-"; + for(unsigned int i=1; i<v.size()-1; i++) { + if( v.at(i)+1 != v.at(i+1) ) outputfile << v.at(i) << ", "; + else if( v.at(i-1)+1 != v.at(i) && v.at(i)+1 == v.at(i+1) ) outputfile << v.at(i) << "-"; + } + outputfile << v.back(); + } + else if(v.size()>0) + outputfile << v.at(0); + outputfile << " }" << std::endl; + } + + void getDeadList( TH1F* h, std::vector<int> & v ) { + v.clear(); + for(int i=1; i<=h->GetNbinsX(); i++) { + if( h->At(i) <= 0 ) + v.push_back( i ); + } + } + + bool find( std::vector<int> & v, unsigned int x ) { + for(unsigned int i=0; i<v.size(); i++) + if( (int)x == v.at(i) ) + return true; + return false; + } + + void getSurelyDeadList( TH1F* h, std::vector<int> & v, std::vector<int> & betweenlist ) { + v.clear(); + if( h->At(1) <= 0 && h->At(2) != 0 && !find(betweenlist, 1) ) + v.push_back( 1 ); + for(int i=2; i<=h->GetNbinsX()-1; i++) { + if( h->At(i-1) > 0 && h->At(i) <= 0 && h->At(i+1) > 0 && !find(betweenlist, i) ) + v.push_back( i ); + } + if( h->At(h->GetNbinsX()) <= 0 && h->At(h->GetNbinsX()-1) != 0 && !find(betweenlist, h->GetNbinsX()) ) + v.push_back( h->GetNbinsX() ); + } + + void getNotBetweenList( std::vector<int> & v, std::vector<int> & surely_v, std::vector<int> & betweenlist ) { + surely_v.clear(); + for(unsigned int i=0; i<v.size(); i++) { + if( !find(betweenlist, v.at(i)) ) { + surely_v.push_back( v.at(i) ); + } + } + } + + void getAllBins( TH1F* h, std::vector<int> & v ) { + v.clear(); + for(int i=1; i<=h->GetNbinsX(); i++) + v.push_back( (int)(h->At(i)) ); + } + + void getAllBinsInRange( TH1F* h, std::vector<int> & v, int x1, int x2 ) { + v.clear(); + if( x1 < 1 || x2 > h->GetNbinsX() ) { + std::cout << "WARNING in " << ((TString)h->GetName())(0,7) << ": in getAllBinsInRange: (" << x1 << "," << x2 << ") outside histo range!" << std::endl; + return; + } + for(int i=x1; i<=x2; i++) + v.push_back( (int)(h->At(i)) ); + } + + void getAllBinsInRangeBelowCrustCutoff( TH1F* h, std::vector<int> & v, int crustCutoff, int x1, int x2 ) { + v.clear(); + if( x1 < 1 || x2 > h->GetNbinsX() ) { + std::cout << "WARNING in " << ((TString)h->GetName())(0,7) << ": in getAllBinsInRangeBelowCrustCutoff: (" << x1 << "," << x2 << ") outside histo range!" << std::endl; + return; + } + for(int i=x1; i<=x2; ++i) { + if( h->At(i) < crustCutoff ) v.push_back( (int)(h->At(i)) ); + else v.push_back( crustCutoff ); + } + } + + void getAllUnmaskedBinsInRangeBelowCrustCutoff( TH1F* h, std::vector<int> & v, int crustCutoff, int x1, int x2 ) { + vector<int> maskedTubes = GetMaskedTubesForDead(h); + v.clear(); + if( x1 < 1 || x2 > h->GetNbinsX() ) { + std::cout << "WARNING in " << ((TString)h->GetName())(0,7) << ": in getAllUnmaskedBinsInRangeBelowCrustCutoff: (" << x1 << "," << x2 << ") outside histo range!" << std::endl; + return; + } + for(int i=x1; i<=x2; ++i) { + if( (h->At(i)<crustCutoff) && !AinB(i,maskedTubes) ) v.push_back( (int)(h->At(i)) ); + else v.push_back( crustCutoff ); + } + } + + void getBins( TH1F* h, std::vector<int> & indices, std::vector<int> & content ) { + content.clear(); + for(unsigned int i=0; i<indices.size(); ++i) { + content.push_back( (int)(h->At(indices.at(i))) ); + } + } + + void removeZeros( std::vector<int> & v ) { + std::vector<int> tmp; + for(unsigned int i=0; i<v.size(); ++i) { + if( v.at(i) > 0 ) + tmp.push_back( v.at(i) ); + } + v = tmp; + } + + void getNonEmptyBins( TH1F* h, std::vector<int> & v ) { + v.clear(); + for(int i=1; i<=h->GetNbinsX(); ++i) { + if( h->At(i) > 0 ) + v.push_back( (int)(h->At(i)) ); + } + } + + void getAllTubes( TH1F* h, std::vector<int> & v ) { + v.clear(); + for(int i=1; i<=h->GetNbinsX(); ++i) { + v.push_back( i ); + } + } + + void getNonEmptyTubes( TH1F* h, std::vector<int> & v ) { + v.clear(); + for(int i=1; i<=h->GetNbinsX(); ++i) { + if( h->At(i) > 0 ) + v.push_back( i ); + } + } + + void getNotMasked( std::vector<int> & v, TH1F* h ) { + vector<int> maskedTubes = GetMaskedTubesForDead(h); + + if(maskedTubes.empty()) + return; + + std::vector<int> tmp; + for(unsigned int i=0; i<v.size(); ++i) { + if( !AinB( v.at(i), maskedTubes ) ) { + tmp.push_back( v.at(i) ); + } + } + v = tmp; + } + + void getNotInDeadMezz( std::vector<int> & v, std::vector<int> & deadMezz_v, const TString & hardware_name, int totalTubes) { + if(deadMezz_v.empty()) + return; +// std::cout << "Mezz dead! Trying to mask out...\n"; + + int groupsPerLayer; + std::vector<TubeRange> tubeRanges = getMezzRanges( hardware_name, totalTubes, groupsPerLayer); + + std::vector<int> tmp; + for(unsigned int i=0; i<v.size(); ++i) { + if( !AinB( Get_Mezz_of_Tube(v.at(i),hardware_name/*,totalTubes*/,tubeRanges,groupsPerLayer), deadMezz_v ) ) { +// std::cout << "Mezz of tube " << v.at(i) << ": " << Get_Mezz_of_Tube(v.at(i),hardware_name/*,totalTubes*/,tubeRanges,groupsPerLayer) << ", dead Mezz: " << deadMezz_v.at(0) << std::endl; + tmp.push_back( v.at(i) ); + } + } + v = tmp; + } + + void getNotInDeadLayer( std::vector<int> & v, std::vector<int> & deadLayer_v, const TString & hardware_name, int totalTubes) { + if(deadLayer_v.empty()) + return; + std::vector<int> tmp; + for(unsigned int i=0; i<v.size(); ++i) { + if( !AinB( Get_Layer_of_Tube(v.at(i),hardware_name,totalTubes), deadLayer_v ) ) { + tmp.push_back( v.at(i) ); + } + } + v = tmp; + } + + void getNotInDeadML( std::vector<int> & v, std::vector<int> & deadML_v, const TString & hardware_name, int totalTubes) { + if(deadML_v.empty()) + return; +// std::cout << "ML dead! Trying to mask out...\n"; + std::vector<int> tmp; + for(unsigned int i=0; i<v.size(); ++i) { + if( !AinB( Get_ML_of_Tube(v.at(i),hardware_name,totalTubes), deadML_v ) ) { +// std::cout << "ML of tube " << v.at(i) << ": " << Get_ML_of_Tube(v.at(i),hardware_name,totalTubes) << ", dead ML: " << deadML_v.at(0) << std::endl; + tmp.push_back( v.at(i) ); + } + } + v = tmp; + } + + template <class T> + double getMean( std::vector<T> & v ) { + double runningMean = 0; + for(unsigned int i=0; i<v.size(); i++) { + runningMean = ( runningMean*(i) + v.at(i) ) / (double)(i+1); + } + return runningMean; + } + + double getMean_WithCut( std::vector<int> & v, double cut ) { + double runningMean = 0; + int counter = 0; + for(unsigned int i=0; i<v.size(); ++i) { + if( (double)v.at(i) < cut ) { + runningMean = ( runningMean*(counter) + v.at(i) ) / (double)(counter+1); + counter++; + } + } + return runningMean; + } + + void getNoBetweens( TH1F* h, std::vector<int> & no_dead, std::vector<int> & no_betweens, std::vector<int> & betweenlist, float minBinContent ) { + no_betweens.clear(); + betweenlist.clear(); + std::vector<int> tmp_no_dead_pruned; + getNoBetweens_middle_aggressive(no_dead, tmp_no_dead_pruned); + double no_dead_mean = getMean( tmp_no_dead_pruned ); + std::vector<int> tmp_no_betweens, tmp_betweenlist; + for(int i=1; i<=h->GetNbinsX(); i++) { + if( h->At(i) > minBinContent * no_dead_mean ) { + tmp_no_betweens.push_back( (int)(h->At(i)) ); + tmp_betweenlist.push_back(i); + } + else { + if( tmp_no_betweens.size() >= 1 && getMean_WithCut( tmp_no_betweens, 2.*no_dead_mean ) < 0.25 * no_dead_mean ) { + betweenlist.insert(betweenlist.end(), tmp_betweenlist.begin(), tmp_betweenlist.end()); + tmp_no_betweens.clear(); + tmp_betweenlist.clear(); + } + else if( tmp_no_betweens.size() >= 1 ) { + no_betweens.insert(no_betweens.end(), tmp_no_betweens.begin(), tmp_no_betweens.end()); + tmp_no_betweens.clear(); + tmp_betweenlist.clear(); + } + betweenlist.push_back(i); // look into this -- shouldn't have 'else' for this somewhere? displayList(betweenlist) should get to the bottom if duplicates + } + } + if( tmp_no_betweens.size() >= 1 && getMean_WithCut( tmp_no_betweens, 2.*no_dead_mean ) < 0.25 * no_dead_mean ) { + betweenlist.insert(betweenlist.end(), tmp_betweenlist.begin(), tmp_betweenlist.end()); + } + else if( tmp_no_betweens.size() >= 1 ) { + no_betweens.insert(no_betweens.end(), tmp_no_betweens.begin(), tmp_no_betweens.end()); + } + } + + void removeNonContiguous( std::vector<int> & betweenlist, unsigned int sz ) { + std::vector<int> betweenlist_copy = betweenlist; + std::vector<int> tmp_betweenlist; + betweenlist.clear(); + if( betweenlist_copy.size() <= 2 ) return; + for(unsigned int i=0; i<betweenlist_copy.size()-1; i++) { + if( betweenlist_copy.at(i)+1 == betweenlist_copy.at(i+1) ) { + tmp_betweenlist.push_back(betweenlist_copy.at(i)); + if( i == betweenlist_copy.size()-2 ) tmp_betweenlist.push_back(betweenlist_copy.at(i+1)); + } + else { + if( tmp_betweenlist.size() >= 1 ) tmp_betweenlist.push_back(betweenlist_copy.at(i)); + if( tmp_betweenlist.size() >= sz ) betweenlist.insert(betweenlist.end(), tmp_betweenlist.begin(), tmp_betweenlist.end()); + tmp_betweenlist.clear(); + } + } + if( tmp_betweenlist.size() >= sz ) betweenlist.insert(betweenlist.end(), tmp_betweenlist.begin(), tmp_betweenlist.end()); + } + + void getNoBetweens_middle( std::vector<int> no_betweens, std::vector<int> & no_betweens_middle ) { + no_betweens_middle.clear(); + sort(no_betweens.begin(), no_betweens.end()); + int crustSize = no_betweens.size() / 20; + no_betweens_middle.insert( no_betweens_middle.begin(), no_betweens.begin()+crustSize, no_betweens.end()-crustSize ); + } + + void getNoBetweens_lowmiddle( std::vector<int> no_betweens, std::vector<int> & no_betweens_lowmiddle ) { + no_betweens_lowmiddle.clear(); + sort(no_betweens.begin(), no_betweens.end()); + int crustSize = no_betweens.size() / 4; + no_betweens_lowmiddle.insert( no_betweens_lowmiddle.begin(), no_betweens.begin()+crustSize, no_betweens.begin()+2*crustSize ); + } + + void getNoBetweens_middle_aggressive( std::vector<int> no_betweens, std::vector<int> & no_betweens_middle_aggressive ) { + no_betweens_middle_aggressive.clear(); + sort(no_betweens.begin(), no_betweens.end()); + int crustSize = no_betweens.size() / 4; + no_betweens_middle_aggressive.insert( no_betweens_middle_aggressive.begin(), no_betweens.begin()+crustSize, no_betweens.end()-crustSize ); + } + + void getNoBetweens_middle_semiaggressive( std::vector<int> no_betweens, std::vector<int> & no_betweens_middle_aggressive ) { + no_betweens_middle_aggressive.clear(); + sort(no_betweens.begin(), no_betweens.end()); + int crustSize = no_betweens.size() / 8; + no_betweens_middle_aggressive.insert( no_betweens_middle_aggressive.begin(), no_betweens.begin()+crustSize, no_betweens.end()-crustSize ); + } + + void getNoBetweens_lowmiddle_aggressive( std::vector<int> no_betweens, std::vector<int> & no_betweens_lowmiddle_aggressive ) { + no_betweens_lowmiddle_aggressive.clear(); + sort(no_betweens.begin(), no_betweens.end()); + int crustSize = no_betweens.size() / 10; + no_betweens_lowmiddle_aggressive.insert( no_betweens_lowmiddle_aggressive.begin(), no_betweens.begin()+crustSize, no_betweens.begin()+2*crustSize ); + } + + void getNoBetweens_highmiddle_aggressive( std::vector<int> no_betweens, std::vector<int> & no_betweens_lowmiddle_aggressive ) { + no_betweens_lowmiddle_aggressive.clear(); + sort(no_betweens.begin(), no_betweens.end()); + int crustSize = no_betweens.size() / 10; + no_betweens_lowmiddle_aggressive.insert( no_betweens_lowmiddle_aggressive.begin(), no_betweens.end()-2*crustSize, no_betweens.end()-crustSize ); + } + + double getStandardDevFromMean( std::vector<int> & v, double mean ) { + double sum = 0; + for(unsigned int i=0; i<v.size(); i++) { + double diff = (double)v.at(i) - mean; + if( diff > 100.0 * mean ) // lines to avoid bias due to very noisy tubes + diff = 100.0 * mean; + sum += sqr( diff ); + } + return std::sqrt(sum/(double)v.size()); + } + + double getStandardDevFromMean_neg( std::vector<int> & v, double mean ) { + double sum = 0; + for(unsigned int i=0; i<v.size(); i++) { + double diff = (double)v.at(i) - mean; + if( diff > 100.0 * mean ) // avoid bias due to very noisy tubes + diff = 100.0 * mean; + if( diff < 0. ) + sum += sqr( diff ); + } + return std::sqrt(sum/(double)v.size()); + } + + double getStandardDevFromMean_pos( std::vector<int> & v, double mean ) { + double sum = 0; + for(unsigned int i=0; i<v.size(); i++) { + double diff = (double)v.at(i) - mean; + if( diff > 100.0 * mean ) // avoid bias due to very noisy tubes + diff = 100.0 * mean; + if( diff > 0. ) + sum += sqr( diff ); + } + return std::sqrt(sum/(double)v.size()); + } + + void getNoisyList( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_middle_aggressive, double num_std_dev, std::vector<int> & noisylist) { + noisylist.clear(); + double mean = getMean(no_betweens_middle_aggressive); // a fancy median + double stddev = getStandardDevFromMean(no_betweens_middle, mean); + for(int i=1; i<=h->GetNbinsX(); i++) { + if( h->At(i) - mean > num_std_dev*stddev ) + noisylist.push_back(i); + } + } + + void getNoisyList2( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_middle_aggressive, double num_pct, std::vector<int> & noisylist) { + if(false) no_betweens_middle.size(); // just to avoid compilation warnings + noisylist.clear(); + double mean = getMean(no_betweens_middle_aggressive); // a fancy median + if( mean > 0 ) { + for(int i=1; i<=h->GetNbinsX(); i++) { + if( h->At(i) > (mean) * ( (num_pct/100.) + (500.-25.*(num_pct/100.))/(mean*mean) ) ) { + noisylist.push_back(i); + } + } + } + } + + void getIneffList( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_std_dev, std::vector<int> & inefflist) { + inefflist.clear(); + double mean = getMean(no_betweens_lowmiddle_aggressive); // a fancy median + double stddev = getStandardDevFromMean(no_betweens_middle, mean); + for(int i=1; i<=h->GetNbinsX(); i++) { + if( mean - h->At(i) > num_std_dev*stddev ) + inefflist.push_back(i); + } + } + + void getIneffList( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_std_dev_1, double num_std_dev_2, std::vector<int> & inefflist) { + inefflist.clear(); + double mean = getMean(no_betweens_lowmiddle_aggressive); // a fancy median + double stddev = getStandardDevFromMean(no_betweens_middle, mean); + for(int i=1; i<=h->GetNbinsX(); i++) { + if( mean - h->At(i) > num_std_dev_1*stddev && mean - h->At(i) <= num_std_dev_2*stddev ) + inefflist.push_back(i); + } + } + + void getIneffList2( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_pct, std::vector<int> & inefflist) { + if(false) no_betweens_middle.size(); // just to avoid compilation warnings + inefflist.clear(); + double mean = getMean(no_betweens_lowmiddle_aggressive); // a fancy median + for(int i=1; i<=h->GetNbinsX(); i++) { + if( h->At(i) < mean*num_pct/100. ) + inefflist.push_back(i); + } + } + + void getIneffList2( std::vector<int> & indices, TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_pct, std::vector<int> & inefflist) { + if(false) no_betweens_middle.size(); // just to avoid compilation warnings + inefflist.clear(); + double mean = getMean(no_betweens_lowmiddle_aggressive); // a fancy median + for(unsigned int i=0; i<indices.size(); ++i) { + int index = indices.at(i); + if( h->At(index) < mean*num_pct/100. ) + inefflist.push_back(index); + } + } + + void getIneffList2( TH1F* h, std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle_aggressive, double num_pct_1, double num_pct_2, std::vector<int> & inefflist) { + if(false) no_betweens_middle.size(); // just to avoid compilation warnings + inefflist.clear(); + double mean = getMean(no_betweens_lowmiddle_aggressive); // a fancy median + for(int i=1; i<=h->GetNbinsX(); i++) { + if( h->At(i) < mean*num_pct_2/100. && h->At(i) > mean*num_pct_1/100. ) + inefflist.push_back(i); + } + } + + // for deads + bool validityCheckDead( std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_lowmiddle ) { + bool isOK = true; + double mean = getMean( no_betweens_lowmiddle ); + + if( no_betweens_middle.size() < 60 ) { +// std::cout << " WARNING: few non-empty bins" << std::endl; + isOK = false; + } +// std::cout << " " << mean << " " << getStandardDevFromMean_neg( no_betweens_middle, mean ) << std::endl; + if( mean < 25. || (mean < 50. && getStandardDevFromMean_neg( no_betweens_middle, mean ) > 0.2 * mean) || (mean < 100. && getStandardDevFromMean_neg( no_betweens_middle, mean ) > 0.3 * mean) ) { +// std::cout << " WARNING: low Mean" << std::endl; +// std::cout << " MEAN: " << mean << std::endl; +// std::cout << " STDV: " << getStandardDevFromMean_neg( no_betweens_middle, mean ) << std::endl; + isOK = false; + } + if( getStandardDevFromMean_neg( no_betweens_middle, mean ) > 0.5 * mean ) { +// std::cout << " WARNING: large Standard Dev relative to mean" << std::endl; + isOK = false; + } + + return isOK; + } + + // for noisy: this inlcudes max for the noisies only (even at low stat could have very noisy tube) + // the max parameter is not currently used. + bool validityCheckNoise( std::vector<int> & no_betweens_middle, std::vector<int> & no_betweens_middle_aggressive +/*, int max*/ ) { + bool isOK = true; + double mean = getMean( no_betweens_middle_aggressive ); + +// std::cout << " val check mean: " << mean << std::endl; +// std::cout << " val check stdev: " << getStandardDevFromMean( no_betweens_middle, mean ) << std::endl; + + if( no_betweens_middle.size() < 60 ) { +// std::cout << " WARNING: few non-empty bins" << std::endl; + isOK = false; + } + if( mean < 5. ) { +// std::cout << " WARNING: low Mean" << std::endl; + isOK = false; + } + if( getStandardDevFromMean( no_betweens_middle, mean ) > 2. * mean ) { +// std::cout << " WARNING: large Standard Dev relative to mean" << std::endl; + isOK = false; + } + + return isOK; + } + + void getNonEmptyNonNoisyTubes( TH1F* h_tube_fornoise, TH1F* h_tube, std::vector<int> & non_dead_non_noisy) { + std::vector<int> no_deads, non_noisy, no_betweens, no_betweens_middle, no_betweens_middle_aggressive, no_betweens_highmiddle_aggressive, betweenlist, noisylist; + non_dead_non_noisy.clear(); + + getNonEmptyBins( h_tube_fornoise, no_deads ); + getNoBetweens( h_tube_fornoise, no_deads, no_betweens, betweenlist, .05 ); + getNoBetweens_middle( no_betweens, no_betweens_middle ); + getNoBetweens_middle_aggressive( no_betweens, no_betweens_middle_aggressive ); + getNoBetweens_highmiddle_aggressive( no_betweens, no_betweens_highmiddle_aggressive ); + getNoisyList2( h_tube_fornoise, no_betweens_middle, no_betweens_highmiddle_aggressive, 300.0, noisylist); + + // std::cout << "h_tube->GetNbinsX(): " << h_tube->GetNbinsX() << ", noisylist.size(): " << noisylist.size() << std::endl; + std::vector<int> tmp_non_dead_non_noisy; + for(int i=1; i<=h_tube->GetNbinsX(); i++) { + if( h_tube->At(i) > 0 ) { + bool dopush = true; + for(unsigned int j=0; j<noisylist.size(); j++) { + if(i == noisylist.at(j)) { + dopush = false; + break; + } + } + if(dopush) tmp_non_dead_non_noisy.push_back((int)h_tube->At(i)); + } + } + non_dead_non_noisy = tmp_non_dead_non_noisy; + } + + void CatalogNoisyEff( TH1F* h_tube_bkd, TH1F* h_tube_fornoise, TH1F* num, TH1F* den, int nTriggers, TH1F* EffVSNoise_num, TH1F* EffVSNoise_den, TH1F* EffVSNoise_ADCCut_num, TH1F* EffVSNoise_ADCCut_den, TH1F* EffVSBkd_num, TH1F* EffVSBkd_den) { + TH1F* h = (TH1F*) h_tube_bkd->Clone(); + h->Scale(1./nTriggers/300.*1e9); + TH1F* h2 = (TH1F*) h_tube_fornoise->Clone(); + h2->Scale(1./nTriggers/300.*1e9); + + for(int i = 1; i != h->GetNbinsX()+1; ++i) { + if(den->At(i)>0) { + EffVSNoise_ADCCut_num->Fill(h->At(i)/1000.,num->At(i)); + EffVSNoise_ADCCut_den->Fill(h->At(i)/1000.,den->At(i)); + if(h2->At(i)<2000) { + EffVSBkd_num->Fill(h->At(i)/1000.,num->At(i)); + EffVSBkd_den->Fill(h->At(i)/1000.,den->At(i)); + } + EffVSNoise_num->Fill(h2->At(i)/1000.,num->At(i)); + EffVSNoise_den->Fill(h2->At(i)/1000.,den->At(i)); + } + } + + delete h; + delete h2; + } + + std::vector<int> GetNoisyTubes( TH1F* h_tube_fornoise, int nTriggers, float frequency){ //Simply determine noisy tubes from freq. + TH1F* h = (TH1F*) h_tube_fornoise->Clone(); + h->Scale(1./nTriggers/300.*1e9); + std::vector<int> noisyTubes; + for(int i = 1; i != h->GetNbinsX()+1; ++i) if(h->At(i)>frequency) noisyTubes.push_back(i); + delete h; + return noisyTubes; + } + + std::vector<int> GetNoisyTubes( TH1F* h_tube_fornoise, TH1F* h_tube, TString chamber, int & validity) { + validity = 1; + + // std::cout << "In GetNoisyTubes" << std::endl; + if(chamber=="TEST") std::cout << chamber << std::endl; + std::vector<int> no_deads, no_betweens, no_betweens_middle, no_betweens_middle_aggressive, no_betweens_highmiddle_aggressive, betweenlist, noisylist; + + getNonEmptyBins( h_tube_fornoise, no_deads ); + // std::cout << " no_deads for " << chamber << ": " << no_deads.size() << std::endl; + getNoBetweens( h_tube_fornoise, no_deads, no_betweens, betweenlist, .05 ); + // std::cout << " no_betweens for " << chamber << ": " << no_betweens.size() << std::endl; + // std::cout << " betweenlist for " << chamber << ": " << betweenlist.size() << std::endl; + getNoBetweens_middle( no_betweens, no_betweens_middle ); + // std::cout << "no_betweens_middle for " << chamber << ": " << no_betweens_middle.size() << std::endl; + getNoBetweens_middle_aggressive( no_betweens, no_betweens_middle_aggressive ); + // std::cout << "no_betweens_middle_aggressive for " << chamber <<": " << no_betweens_middle_aggressive.size() << std::endl; + getNoBetweens_highmiddle_aggressive( no_betweens, no_betweens_highmiddle_aggressive ); + // std::cout << "no_betweens_highmiddle_aggressive for " << chamber <<": " << no_betweens_highmiddle_aggressive.size() << std::endl; + getNoisyList2( h_tube_fornoise, no_betweens_middle, no_betweens_highmiddle_aggressive, 300.0, noisylist); + + // std::cout << "Before Validity Check for " << chamber <<": " << std::endl; + // displayList(noisylist); + if( validityCheckNoise(no_betweens_middle, no_betweens_middle_aggressive /*, (int) h_tube_fornoise->GetMaximum()*/ ) ) { + return noisylist; + } + else { + validity = 2; + // std::cout << " ... validity check failed for noisy, trying with h_tube" << std::endl; + // return GetNoisyTubes_WithoutForNoise( h_tube_fornoise, h_tube, chamber); + return GetNoisyTubes_WithoutForNoise( h_tube, validity, chamber ); + } + } + + std::vector<int> GetNoisyTubes_WithoutForNoise( TH1F* h_tube, int & validity, TString chamber ) { + // std::cout << "In GetNoisyTubes_withoutfornoise" << std::endl; + if(chamber=="TEST") std::cout << chamber << std::endl; + + std::vector<int> no_deads, no_betweens, no_betweens_middle, no_betweens_middle_aggressive, no_betweens_highmiddle_aggressive, betweenlist, noisylist; + + getNonEmptyBins( h_tube, no_deads ); + // std::cout << "no_deads for " << chamber << ": " << no_deads.size() << std::endl; + getNoBetweens( h_tube, no_deads, no_betweens, betweenlist, .05 ); + // std::cout << "no_betweens for " << chamber << ": " << no_betweens.size() << std::endl; + getNoBetweens_middle( no_betweens, no_betweens_middle ); + // std::cout << "no_betweens_middle for " << chamber << ": " << no_betweens_middle.size() << std::endl; + getNoBetweens_middle_aggressive( no_betweens, no_betweens_middle_aggressive ); + // std::cout << "no_betweens_middle_aggressive for " << chamber <<": " << no_betweens_middle_aggressive.size() << std::endl; + getNoBetweens_highmiddle_aggressive( no_betweens, no_betweens_highmiddle_aggressive ); + // std::cout << "no_betweens_highmiddle_aggressive for " << chamber <<": " << no_betweens_highmiddle_aggressive.size() << std::endl; + getNoisyList2( h_tube, no_betweens_middle, no_betweens_highmiddle_aggressive, 500.0, noisylist); // <--- use a higher tolerance + +// std::cout << "(Without fornoise) Before Validity Check for " << chamber <<": " << std::endl; +// displayList(noisylist); + if( validityCheckNoise(no_betweens_middle, no_betweens_middle_aggressive /*, (int) h_tube->GetMaximum()*/ ) ) { + return noisylist; + } + else { + validity = 0; +// std::cout << " ... validity check failed for noisy." << std::endl; + } + + return std::vector<int>(); + } + + int GetNumNonMaskedTubes( TH1F* h_tube ) { + std::vector<int> tubes; + + // index-based + getAllTubes( h_tube, tubes ); + getNotMasked( tubes, h_tube ); + + return tubes.size(); + } + + std::vector<int> GetDeadTubes( TH1F* h_tube, int & validity, std::vector<int> & deadML_v, std::vector<int> & deadLayer_v, std::vector<int> & deadMezz_v) { + validity = 1; + TString chamber = ((TString) h_tube->GetName())(0,7); + int totalTubes = h_tube->GetNbinsX(); + + std::vector<int> non_empty, non_empty_non_noisy, no_betweens, no_betweens_middle, no_betweens_lowmiddle, no_betweens_middle_aggressive, no_betweens_lowmiddle_aggressive, deadlist, surelydeadlist, betweenlist, inefflist, surelyinefflist; + std::vector<int> all_tubes_DeadRegionsRemoved; + + // index-based + getAllTubes( h_tube, all_tubes_DeadRegionsRemoved ); + getNotInDeadML( all_tubes_DeadRegionsRemoved, deadML_v, chamber, totalTubes ); + getNotInDeadLayer( all_tubes_DeadRegionsRemoved, deadLayer_v, chamber, totalTubes ); + getNotInDeadMezz( all_tubes_DeadRegionsRemoved, deadMezz_v, chamber, totalTubes ); + getNotMasked( all_tubes_DeadRegionsRemoved, h_tube ); + + // bin-content-based (for calculation of mean) + getBins( h_tube, all_tubes_DeadRegionsRemoved, no_betweens ); + removeZeros( no_betweens ); + getNoBetweens_middle( no_betweens, no_betweens_middle ); + getNoBetweens_lowmiddle( no_betweens, no_betweens_lowmiddle ); + getNoBetweens_middle_aggressive( no_betweens, no_betweens_middle_aggressive ); + getNoBetweens_lowmiddle_aggressive( no_betweens, no_betweens_lowmiddle_aggressive ); + + // give indicies to consider, the histo (for bin-content), a couple vectors for mean calculation, the definition of a dead tube (percent of mode), and the vector to fill + getIneffList2( all_tubes_DeadRegionsRemoved, h_tube, no_betweens_middle, no_betweens_lowmiddle_aggressive, 10.0, deadlist ); + + // make sure the histo has enough statistics, etc + if( validityCheckDead(no_betweens_middle, no_betweens_lowmiddle) ) { + return deadlist; + } + else { + validity = 0; +// std::cout << " ... validity check failed for dead tubes in " << std::endl; + } + + return std::vector<int>(); + } + + std::vector<int> GetMaskedTubesForDead(TH1F* h_tube) { + // std::cout << "In GetMaskedTubesForDead" << std::endl; + + TString hardware_name = ((TString) h_tube->GetName())(0,7); + int numLayers = GetNumLayersPerML( hardware_name ); + + if(hardware_name(0,4)=="BMS4" || hardware_name(0,4)=="BMS6"){//layer 1-4 tubeId 41-48 cut out + if( numLayers <= 3 ) { + int cutouts[] = {41,42,43,44,45,46,47,48,89,90,91,92,93,94,95,96,137,138,139,140,141,142,143,144}; + return std::vector<int>(cutouts,cutouts+24); + } + } + if(hardware_name(0,3)=="BIR" && numLayers <= 4 ){ + if(hardware_name(5,2)=="11"||hardware_name(5,2)=="15") { + if(hardware_name(3,1)=="1") { //layer 1-4 tube id 1-6 cut out + int cutouts[] = {1,2,3,4,5,6,31,32,33,34,35,36,61,62,63,64,65,66,91,92,93,94,95,96}; + return std::vector<int>(cutouts,cutouts+24); + } + if(hardware_name(3,1)=="2") { //layer 1-4 tube id 28-30 cut out + int cutouts[] = {28,29,30,58,59,60,88,89,90,118,119,120}; + return std::vector<int>(cutouts,cutouts+12); + } + if(hardware_name(3,1)=="4") { //layer 1-4 tube id 1-3 cut out + int cutouts[] = {1,2,3,31,32,33,61,62,63,91,92,93}; + return std::vector<int>(cutouts,cutouts+12); + } + if(hardware_name(3,1)=="5") {//layer 1-4 tube id 22-24 cut out + int cutouts[] = {22,23,24,46,47,48,70,71,72,94,95,96}; + return std::vector<int>(cutouts,cutouts+12); + } + } + } + if( hardware_name(0,3)=="BIR" && hardware_name(3,1)=="3") { //cut out on both ML + int cutouts[] = {34,35,36,70,71,72,106,107,108,142,143,144,178,179,180,214,215,216,250,251,252,286,287,288}; + return std::vector<int>(cutouts,cutouts+24); + } + + return std::vector<int>(); + } + + std::vector<int> GetMaskedTubesForNoisy( TH1F* h_tube_fornoise){ + // std::cout << "In GetMaskedTubesForNoisy" << std::endl; + + std::vector<int> no_deads, no_betweens, no_betweens_middle, no_betweens_middle_aggressive, betweenlist; + + getNonEmptyBins( h_tube_fornoise, no_deads ); + // std::cout << " no_deads for " << chamber << ": " << no_deads.size() << std::endl; + getNoBetweens( h_tube_fornoise, no_deads, no_betweens, betweenlist, .05 ); + // std::cout << " no_betweens for " << chamber << ": " << no_betweens.size() << std::endl; + // std::cout << " betweenlist for " << chamber << ": " << betweenlist.size() << ": "; displayList(betweenlist); std::cout << std::endl; + + // if( validityCheckNoise(no_betweens_middle, no_betweens_middle_aggressive, (int) h_tube_fornoise->GetMaximum() ) ) { + return betweenlist; + // } else { + // return std::vector<int>(); + // } + } + + double GetMeanFromHist( TH1F* h_tube ) { + // std::cout << "In GetMeanForDead" << std::endl; + + std::vector<int> non_empty, no_betweens, no_betweens_middle, no_betweens_middle_aggressive, betweenlist; + + getNonEmptyBins( h_tube, non_empty ); + getNoBetweens( h_tube, non_empty, no_betweens, betweenlist, .05 ); + getNoBetweens_middle( no_betweens, no_betweens_middle ); + getNoBetweens_middle_aggressive( no_betweens, no_betweens_middle_aggressive ); + + double mean = getMean( no_betweens_middle_aggressive ); + return mean; + } + + double GetStandardDevFromHist( TH1F* h_tube, double mean ) { + // std::cout << "In GetStandardDevFromHist" << std::endl; + + std::vector<int> non_empty, no_betweens, no_betweens_middle, betweenlist; + + getNonEmptyBins( h_tube, non_empty ); + getNoBetweens( h_tube, non_empty, no_betweens, betweenlist, .05 ); + getNoBetweens_middle( no_betweens, no_betweens_middle ); + + return getStandardDevFromMean( no_betweens_middle, mean ); + } + + int GetNumLayersPerML(const TString & hardware_name) { + // Get Number of X + int derived_NumLayerPerML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + } + else { + derived_NumLayerPerML = 3; + } + + return derived_NumLayerPerML; + } + + int GetNumTubesPerMezz(const TString &hardware_name, int mezz){ + if( hardware_name(0,3)=="BIR"){ + if( hardware_name(3,1)=="2" && mezz==5 ) return 12; + else if( hardware_name(3,1)=="3" && (mezz==6 || mezz==12)) return 12; + else if( hardware_name(3,1)=="4" && mezz==1 ) return 12; + else if( hardware_name(3,1)=="5" && mezz==4 ) return 12; + } + return 24; + } + + int GetNumTubesPerML(const TString &hardware_name, int ML, int TotalTubes){ + if( hardware_name(0,3)=="BIR" || hardware_name(0,4)=="BMS4" || hardware_name(0,4)=="BMS6"){ + if( hardware_name(0,4)=="BIR3" ) return 132; + if( ML == 1){ + if( hardware_name(0,3)=="BMS" ) return 120; + if( hardware_name(3,1)=="1" ) return 120; + if( hardware_name(3,1)=="2" ) return 108; + if( hardware_name(3,1)=="4" ) return 108; + if( hardware_name(3,1)=="5" ) return 84; + } + return (int) TotalTubes/GetNumML(hardware_name); + } + return (int) TotalTubes/GetNumML(hardware_name); + } + + int GetNumTubesPerLayer(const TString &hardware_name, int layer, int TotalTubes){ + if( hardware_name(0,3)=="BIR" || hardware_name(0,4)=="BMS4" || hardware_name(0,4)=="BMS6"){ + if( hardware_name(0,4)=="BIR3" ) return 33; + if( layer <= 4){ + if( hardware_name(0,3)=="BMS" ) return 40; + if( hardware_name(3,1)=="1" ) return 24; + if( hardware_name(3,1)=="2" ) return 27; + if( hardware_name(3,1)=="4" ) return 27; + if( hardware_name(3,1)=="5" ) return 21; + } + return (int) TotalTubes/GetNumML(hardware_name)/GetNumLayersPerML(hardware_name); + } + return (int) TotalTubes/GetNumML(hardware_name)/GetNumLayersPerML(hardware_name); + } + + int GetNumML(const TString & hardware_name) { + int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumML = 2; + } + else { + derived_NumML = 2; + } + + return derived_NumML; + } + + int getLastTubeInLayer(int & firstTubeInLayer, const TString & hardware_name, int totalTubes) { + int tubeID = firstTubeInLayer; + + // int derived_tube = 1; + int derived_layer = 1; + // int derived_ML = 1; + + // Get Number of X + int derived_NumTubePerLayer = 1; + // int derived_NumTubePerML = 1; + int derived_NumLayer = 1; + int derived_NumLayerPerML = 1; + int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + derived_NumML = 2; + } + else { + derived_NumLayerPerML = 3; + derived_NumML = 2; + } + + derived_NumLayer = derived_NumLayerPerML * derived_NumML; + // derived_NumTubePerML = totalTubes / derived_NumML; + derived_NumTubePerLayer = totalTubes / derived_NumLayer; + + // Corrections for derived_NumTubePerLayer + if( hardware_name(0,4) == "BMS4" || hardware_name(0,4) == "BMS6" ) + derived_NumTubePerLayer = 48; + if((hardware_name(5,2) == "11" || hardware_name(5,2) == "15")) { + if( hardware_name(0,4) == "BIR1" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR2" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR3" ) + derived_NumTubePerLayer = 36; + if( hardware_name(0,4) == "BIR4" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR5" ) + derived_NumTubePerLayer = 24; + } +// if( hardware_name(0,4)=="EIL4" && ( hardware_name(5,2)=="09" || hardware_name(5,2)=="01" ) ) // possible MdtIdHelper problem +// derived_NumTubePerLayer = 54; + + // Now get X + // derived_ML = (tubeID-1)/derived_NumTubePerML + 1; + derived_layer = (tubeID-1)/derived_NumTubePerLayer + 1; + // derived_tube = tubeID - (derived_layer - 1) * derived_NumTubePerLayer; + // if(derived_ML==2) derived_layer -= derived_NumLayerPerML; + + // final info + int lastTubeInLayer = -1; + if(derived_layer <= derived_NumLayer) + lastTubeInLayer = tubeID + derived_NumTubePerLayer - 1; + + return lastTubeInLayer; + } + + int Get_ML_of_Layer(int & layer, const TString & hardware_name) { + int derived_ML = 1; + + // Get Number of X + // int derived_NumLayer = 1; + int derived_NumLayerPerML = 1; + // int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + // derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + // derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + // derived_NumML = 2; + } + else { + derived_NumLayerPerML = 3; + // derived_NumML = 2; + } + // derived_NumLayer = derived_NumLayerPerML * derived_NumML; + + // Now get X + derived_ML = (layer-1)/derived_NumLayerPerML + 1; + + return derived_ML; + } + + int getLastTubeInML(int & firstTubeInML, const TString & hardware_name, int totalTubes) { + int tubeID = firstTubeInML; + + // int derived_tube = 1; + int derived_layer = 1; + int derived_ML = 1; + + // Get Number of X + int derived_NumTubePerLayer = 1; + int derived_NumTubePerML = 1; + int derived_NumLayer = 1; + int derived_NumLayerPerML = 1; + int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + derived_NumML = 2; + } + else { + derived_NumLayerPerML = 3; + derived_NumML = 2; + } + + derived_NumLayer = derived_NumLayerPerML * derived_NumML; + derived_NumTubePerML = totalTubes / derived_NumML; + derived_NumTubePerLayer = totalTubes / derived_NumLayer; + + // Corrections for derived_NumTubePerLayer + if( hardware_name(0,4) == "BMS4" || hardware_name(0,4) == "BMS6" ) + derived_NumTubePerLayer = 48; + if((hardware_name(5,2) == "11" || hardware_name(5,2) == "15")) { + if( hardware_name(0,4) == "BIR1" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR2" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR3" ) + derived_NumTubePerLayer = 36; + if( hardware_name(0,4) == "BIR4" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR5" ) + derived_NumTubePerLayer = 24; + } +// if( hardware_name(0,4)=="EIL4" && ( hardware_name(5,2)=="09" || hardware_name(5,2)=="01" ) ) // possible MdtIdHelper problem +// derived_NumTubePerLayer = 54; + + // Now get X + derived_ML = (tubeID-1)/derived_NumTubePerML + 1; + derived_layer = (tubeID-1)/derived_NumTubePerLayer + 1; + // derived_tube = tubeID - (derived_layer - 1) * derived_NumTubePerLayer; + if(derived_ML==2) derived_layer -= derived_NumLayerPerML; + + // final info + int lastTubeInML = -1; + if(derived_ML <= derived_NumML) + lastTubeInML = tubeID + derived_NumTubePerML - 1; + + return lastTubeInML; + } + + int GetNumMezz( TH1F* h_tube ) { + int totalTubes = h_tube->GetNbinsX(); + TString hardware_name = ((TString) h_tube->GetName())(0,7); + int groupsPerLayer; + std::vector<TubeRange> tubeRange = getMezzRanges(hardware_name, totalTubes, groupsPerLayer); + return tubeRange.size(); + } + + std::vector<TubeRange> getMezzRanges(const TString & hardware_name, int totalTubes, int & groupsPerLayer) { + // Get Number of X + int derived_NumTubePerLayer = 1; + // int derived_NumTubePerML = 1; + int derived_NumLayer = 1; + int derived_NumLayerPerML = 1; + int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + derived_NumML = 2; + } + else { + derived_NumLayerPerML = 3; + derived_NumML = 2; + } + + derived_NumLayer = derived_NumLayerPerML * derived_NumML; + // derived_NumTubePerML = totalTubes / derived_NumML; + derived_NumTubePerLayer = totalTubes / derived_NumLayer; + + // below is for the tube range + int groupSize = 6; + if( derived_NumLayerPerML == 3 ) + groupSize = 8; + + groupsPerLayer = derived_NumTubePerLayer / groupSize; + +// if( hardware_name == "EIL4A01" ) std::cout << "Chamber: " << hardware_name << ", #T: " << totalTubes << ", #L: " << derived_NumLayer << ", #T/ML: " << derived_NumTubePerML << ", #T/L: " << derived_NumTubePerLayer << ", #G/L: " << groupsPerLayer << ", GrpSz: " << groupSize << std::endl; + + int firstTubeID = 1; + int lastTubeID = firstTubeID + groupSize - 1; + std::vector<TubeRange> ranges; + while ( lastTubeID <= totalTubes ) { + TubeRange r(firstTubeID,lastTubeID); + ranges.push_back(r); + firstTubeID = lastTubeID+1; + lastTubeID += groupSize; + } + + return ranges; + } + + int Get_ML_of_Mezz_degenerate(int &mezz, const TString & hardware_name, int totalTubes) { + // Get Number of X + int derived_NumTubePerLayer = 1; + // int derived_NumTubePerML = 1; + int derived_NumLayer = 1; + int derived_NumLayerPerML = 1; + int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + derived_NumML = 2; + } + else { + derived_NumLayerPerML = 3; + derived_NumML = 2; + } + + derived_NumLayer = derived_NumLayerPerML * derived_NumML; + // derived_NumTubePerML = totalTubes / derived_NumML; + derived_NumTubePerLayer = totalTubes / derived_NumLayer; + + // below is for the tube range + int groupSize = 6; + if( derived_NumLayerPerML == 3 ) + groupSize = 8; + + int groupsPerLayer = derived_NumTubePerLayer / groupSize; + + if(mezz > groupsPerLayer) { + mezz -= groupsPerLayer; + return 2; + } + + return 1; + } + + // This version does not account for multilayers (on purpose, so it is single-valued) + int Get_ML_of_Mezz(int &mezz, const TString & hardware_name, int totalTubes) { + // Get Number of X + int derived_NumTubePerLayer = 1; + // int derived_NumTubePerML = 1; + int derived_NumLayer = 1; + int derived_NumLayerPerML = 1; + int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + derived_NumML = 2; + } + else { + derived_NumLayerPerML = 3; + derived_NumML = 2; + } + + derived_NumLayer = derived_NumLayerPerML * derived_NumML; + // derived_NumTubePerML = totalTubes / derived_NumML; + derived_NumTubePerLayer = totalTubes / derived_NumLayer; + + // below is for the tube range + int groupSize = 6; + if( derived_NumLayerPerML == 3 ) + groupSize = 8; + + int groupsPerLayer = derived_NumTubePerLayer / groupSize; + + if(mezz > groupsPerLayer) { + return 2; + } + + return 1; + } + + // This function does not account for multilayers (on purpose, so it is single-valued) + int Get_Mezz_of_Tube(int & tubeID, const TString & hardware_name/*, int totalTubes*/, std::vector<TubeRange> & tubeRanges, int groupsPerLayer) { + unsigned int rangeIndexOfTube = 9999; + + for(unsigned int i=0; i<tubeRanges.size(); i++) { + if( tubeRanges.at(i).InRange(tubeID) ) { + rangeIndexOfTube = i; + break; + } + } + if( rangeIndexOfTube == 9999 ) { + std::cout << "ERROR: tubeRange problem in Get_Mezz_of_Tube()!" << std::endl; + return 0; + } + + unsigned int mezz = rangeIndexOfTube % groupsPerLayer + 1; + unsigned int numML = GetNumML(hardware_name); + if(numML==2 && rangeIndexOfTube>=tubeRanges.size()/2) { + mezz += groupsPerLayer; + } + + return mezz; + } + + // This function does not account for multilayers (on purpose, so it is single-valued) + int Get_Layer_of_Tube(int & tubeID, const TString & hardware_name, int totalTubes) { + int derived_layer = 1; + + // Get Number of X + int derived_NumTubePerLayer = 1; + int derived_NumLayer = 1; + int derived_NumLayerPerML = 1; + int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + derived_NumML = 2; + } + else { + derived_NumLayerPerML = 3; + derived_NumML = 2; + } + + derived_NumLayer = derived_NumLayerPerML * derived_NumML; + derived_NumTubePerLayer = totalTubes / derived_NumLayer; + + // Corrections for derived_NumTubePerLayer + if( hardware_name(0,4) == "BMS4" || hardware_name(0,4) == "BMS6" ) + derived_NumTubePerLayer = 48; + if((hardware_name(5,2) == "11" || hardware_name(5,2) == "15")) { + if( hardware_name(0,4) == "BIR1" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR2" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR3" ) + derived_NumTubePerLayer = 36; + if( hardware_name(0,4) == "BIR4" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR5" ) + derived_NumTubePerLayer = 24; + } +// if( hardware_name(0,4)=="EIL4" && ( hardware_name(5,2)=="09" || hardware_name(5,2)=="01" ) ) // possible MdtIdHelper problem +// derived_NumTubePerLayer = 54; + + // Now get X + derived_layer = (tubeID-1)/derived_NumTubePerLayer + 1; + + return derived_layer; + } + + int Get_ML_of_Tube(int & tubeID, const TString & hardware_name, int totalTubes) { + int derived_ML = 1; + + // Get Number of X + int derived_NumTubePerML = 1; + int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumML = 2; + } + else { + derived_NumML = 2; + } + + derived_NumTubePerML = totalTubes / derived_NumML; + + // Now get X + derived_ML = (tubeID-1)/derived_NumTubePerML + 1; + + return derived_ML; + } + + std::vector<TubeRange> getLayerRanges(const TString & hardware_name, int totalTubes) { + int firstTubeID = 1; + int lastTubeID; + std::vector<TubeRange> ranges; + while ( (lastTubeID = getLastTubeInLayer(firstTubeID, hardware_name, totalTubes)) != -1 ) { + TubeRange r(firstTubeID,lastTubeID); + ranges.push_back(r); + firstTubeID = lastTubeID+1; + } + return ranges; + } + + std::vector<TubeRange> getMLRanges(const TString & hardware_name, int totalTubes) { + int firstTubeID = 1; + int lastTubeID; + std::vector<TubeRange> ranges; + while ( (lastTubeID = getLastTubeInML(firstTubeID, hardware_name, totalTubes)) != -1 ) { + TubeRange r(firstTubeID,lastTubeID); + ranges.push_back(r); + firstTubeID = lastTubeID+1; + } + return ranges; + } + + std::vector<int> + /*void*/ FindDeadMezz( TH1F* h_tube, const TString & hardware_name, std::vector<int> & deadML_v) { +// std::cout << "In FindDeadMezz for " << hardware_name << std::endl; + + int totalTubes = h_tube->GetNbinsX(); + int groupsPerLayer; + int numML = GetNumML(hardware_name); + std::vector<TubeRange> tubeRange = getMezzRanges(hardware_name, totalTubes, groupsPerLayer); + int numMezz = groupsPerLayer * numML; + std::vector<double> means; + std::vector<int> valuesAll; + getAllBins(h_tube, valuesAll); + sort(valuesAll.begin(), valuesAll.end()); + int crustSize = (valuesAll.size()) / 3; + int crustCutoff = 0; + if( valuesAll.size() > 0 ) + crustCutoff = valuesAll.at(valuesAll.size()-1-crustSize); + for(unsigned int i=0; i<tubeRange.size(); i++) { + std::vector<int> valuesInRange_crusted; + getAllUnmaskedBinsInRangeBelowCrustCutoff(h_tube, valuesInRange_crusted, crustCutoff, tubeRange.at(i).x1, tubeRange.at(i).x2); +// std::cout << " values in range:"; for(int j=0; j<valuesInRange_crusted.size(); ++j) std::cout << " " << valuesInRange_crusted.at(j); std::cout << std::endl; + if(valuesInRange_crusted.size() > 0) { + means.push_back(getMean(valuesInRange_crusted)); + } + else means.push_back(crustCutoff); +// std::cout << " mean in range (" << tubeRange.at(i).x1 << "-" << tubeRange.at(i).x2 << "), #" << i << ": " << means.at(i) << ", (crustCutoff = " << crustCutoff << ")" << std::endl; + } + + // order into mezzes + std::vector<std::vector<double> > mezz_means(numMezz); //outer vector indexes vectors of groups that belong to the mezz with that index +// std::cout << " mezz_means: " << mezz_means.size() << std::endl; + for(unsigned int k=0; k<means.size(); k++) { + if(numML==2 && k>=means.size()/2) { +// std::cout << " k: " << k << ", (k % groupsPerLayer): " << (k % groupsPerLayer) << ", groupsPerLayer: " << groupsPerLayer << " (this is 2nd ML)" << std::endl; + mezz_means.at( (k % groupsPerLayer) + groupsPerLayer ).push_back(means.at(k)); + } + else { +// std::cout << " k: " << k << ", (k % groupsPerLayer): " << (k % groupsPerLayer) << ", groupsPerLayer: " << groupsPerLayer << std::endl; + mezz_means.at( (k % groupsPerLayer) ).push_back(means.at(k)); + } + } + + double mean_of_means = getMean(means); + std::vector<int> deviant_mezz; + for(unsigned int i=0; i<mezz_means.size(); ++i) { + int mezz = i+1; + bool deviant = true; + for(unsigned int j=0; j<mezz_means.at(i).size(); j++ ) { +// std::cout << " mezz_means.at(" << i << ").at(" << j << "): " << mezz_means.at(i).at(j) << ", mean_of_means: " << mean_of_means << std::endl; + if( !(mezz_means.at(i).at(j) < 0.25 * mean_of_means) ) + deviant = false; + } + if( deviant && !AinB(Get_ML_of_Mezz(mezz,hardware_name,totalTubes), deadML_v) ) + deviant_mezz.push_back(mezz); + } +// if( deviant_mezz.size() > 0 ) { +// std::cout << "Dead mezz: "; displayList(deviant_mezz); +// } + + return deviant_mezz; + } + + std::vector<int> + /*void*/ FindDeadLayer( TH1F* h_tube, const TString & hardware_name, std::vector<int> & deadML_v) { + // std::cout << "In FindDeadLayer" << std::endl; + + int totalTubes = h_tube->GetNbinsX(); + std::vector<TubeRange> tubeRange = getLayerRanges(hardware_name, totalTubes); + std::vector<double> means; + std::vector<int> valuesAll; + + getAllBins(h_tube, valuesAll); + sort(valuesAll.begin(), valuesAll.end()); + + int crustSize = (valuesAll.size()) / 3; + int crustCutoff = 0; + if( valuesAll.size() > 0 ) + crustCutoff = valuesAll.at(valuesAll.size()-1-crustSize); + + for(unsigned i=0; i<tubeRange.size(); i++) { + std::vector<int> valuesInRange_crusted; + getAllUnmaskedBinsInRangeBelowCrustCutoff(h_tube, valuesInRange_crusted, crustCutoff, tubeRange.at(i).x1, tubeRange.at(i).x2); + if(valuesInRange_crusted.size() > 0) { + means.push_back(getMean(valuesInRange_crusted)); + } + else means.push_back(crustCutoff); + // std::cout << " mean " << i << ": " << means.at(i) << std::endl; + } + + double mean_of_means = getMean(means); + std::vector<int> deviant_layers; + for(unsigned i=0; i<means.size(); ++i) { + if( means.at(i) < 0.25 * mean_of_means ) { + int layer = i+1; + if( !AinB(Get_ML_of_Layer(layer,hardware_name), deadML_v) ) + deviant_layers.push_back(layer); + } + } + if( deviant_layers.size() > 0 ) { + // std::cout << "Dead layers: "; displayList(deviant_layers); + } + + return deviant_layers; + } + + bool AinB( int A, std::vector<int> & B ) { + for(unsigned int i=0; i<B.size(); ++i) { + if( B.at(i) == A ) + return true; + } + return false; + } + + bool AinB( int A, const std::vector<int> * B ) { + for(unsigned int i=0; i<B->size(); ++i) { + if( B->at(i) == A ) + return true; + } + return false; + } + + std::vector<int> + /*void*/ FindDeadML( TH1F* h_tube, const TString & hardware_name) { + // std::cout << "In FindDeadML" << std::endl; + + int totalTubes = h_tube->GetNbinsX(); + std::vector<TubeRange> tubeRange = getMLRanges(hardware_name, totalTubes); + std::vector<double> means; + std::vector<int> valuesAll; + getAllBins(h_tube, valuesAll); + sort(valuesAll.begin(), valuesAll.end()); + int crustSize = (valuesAll.size()) / 3; + int crustCutoff = 0; + if( valuesAll.size() > 0 ) + crustCutoff = valuesAll.at(valuesAll.size()-1-crustSize); + for(unsigned int i=0; i<tubeRange.size(); i++) { + std::vector<int> valuesInRange_crusted; + getAllUnmaskedBinsInRangeBelowCrustCutoff(h_tube, valuesInRange_crusted, crustCutoff, tubeRange.at(i).x1, tubeRange.at(i).x2); + if(valuesInRange_crusted.size() > 0) { + means.push_back(getMean(valuesInRange_crusted)); + } + else means.push_back(crustCutoff); + // std::cout << " mean " << i << ": " << means.at(i) << std::endl; + } + + double mean_of_means = getMean(means); + std::vector<int> deviant_ML; + for(unsigned i=0; i<means.size(); ++i) { + if( means.at(i) < 0.25 * mean_of_means ) + deviant_ML.push_back(i+1); + } + if( deviant_ML.size() > 0 ) { + // std::cout << "Dead MLs: "; displayList(deviant_ML); + } + + // if(means.size() == 2) { + // if(means.at(0) < 0.25*means.at(1)) + // std::cout << " ML " << 1 << " is dead!" << std::endl; + // else if(means.at(1) < 0.25*means.at(0)) + // std::cout << " ML " << 2 << " is dead!" << std::endl; + // } + + return deviant_ML; + } + + void FillPDF(std::string inFilename, TH1F* hDead, TH1F* hNoise, TCanvas* c, + const vector<int>* deadTubes, const vector<int>* deadASD, const vector<int>* deadMEZZ, const vector<int>* deadLayer, const vector<int>* deadML, + const vector<int>* noisyTubes, const vector<int>* noisyASD, const vector<int>* noisyMEZZ, const vector<int>* noisyLayer, const vector<int>* noisyML, + int deadTubesChamberValidity, int noisyTubesChamberValidity, + bool draw_Mezz_L_ML_guidlines, bool draw_mean, bool draw_masked_tubes, bool separate_dead_noisy_histos, bool draw_validity_message, bool draw_histo_if_nothing_to_report) { + + if(noisyML && !noisyML) return; + if(noisyLayer && !noisyLayer) return; + if(noisyMEZZ && !noisyMEZZ) return; + if(noisyASD && !noisyASD) return; + if(deadASD && !deadASD) return; + + if( !draw_histo_if_nothing_to_report && deadTubes->size()==0 && noisyTubes->size()==0 && deadML->size()==0 && deadLayer->size()==0 && deadMEZZ->size()==0 ) return; + + if(!hDead) return; + if(!hNoise) return; + + c->Clear(); + if( separate_dead_noisy_histos ) + c->Divide(2,1); + TString chamberName = ((TString) hDead->GetName())(0,7); + c->SetTitle(chamberName); + + vector<int> maskedTubesForDead = GetMaskedTubesForDead(hDead); +// vector<int> maskedTubesForNoisy = GetMaskedTubesForNoisy(hNoise); + TH1F* hOnlyDead = new TH1F(hDead->GetName(), hDead->GetTitle(), hDead->GetNbinsX(), 1, hDead->GetNbinsX()); + TH1F* hOnlyNoise = new TH1F(hNoise->GetName(), hNoise->GetTitle(), hNoise->GetNbinsX(), 1, hNoise->GetNbinsX()); + + TString maskedStr = hDead->GetName(); + maskedStr += "_masked"; + TH1F* hOnlyMaskedDead = new TH1F(maskedStr, hDead->GetTitle(), hDead->GetNbinsX(), 1, hDead->GetNbinsX()); + +// maskedStr = hNoise->GetName(); +// maskedStr += "_masked"; +// TH1F* hOnlyMaskedNoisy = new TH1F(maskedStr, hNoise->GetTitle(), hNoise->GetNbinsX(), 1, hNoise->GetNbinsX()); + + // fill the layer range histo + std::vector<TLine> rangeLines; + std::vector<TLine> rangeLines_onlyMLLMezz; + std::vector<TubeRange> tubeRange = getLayerRanges( chamberName, hDead->GetNbinsX()); + for(unsigned int i=0; i<tubeRange.size(); i++) { + TLine l( hDead->GetBinLowEdge(tubeRange.at(i).x1)+hDead->GetBinWidth(tubeRange.at(i).x1)/2.0, LAYER_POS, hDead->GetBinLowEdge(tubeRange.at(i).x2)+hDead->GetBinWidth(tubeRange.at(i).x2)/2.0, LAYER_POS); + if( i % 2 == 0 ) + l.SetLineColor(kViolet); + else + l.SetLineColor(kViolet+6); + int layer = i+1; + l.SetLineWidth(3); + rangeLines_onlyMLLMezz.push_back(l); + if( AinB(layer,deadLayer) ) { // mark dead if in dead list + l.SetLineColor(kRed); + l.SetLineWidth(6); + rangeLines.push_back(l); + } + else if( draw_Mezz_L_ML_guidlines ) { + rangeLines.push_back(l); + } + } + // fill the ML range histo + tubeRange = getMLRanges( chamberName, hDead->GetNbinsX()); + for(unsigned int i=0; i<tubeRange.size(); i++) { + TLine l( hDead->GetBinLowEdge(tubeRange.at(i).x1)+hDead->GetBinWidth(tubeRange.at(i).x1)/2.0, ML_POS, hDead->GetBinLowEdge(tubeRange.at(i).x2)+hDead->GetBinWidth(tubeRange.at(i).x2)/2.0, ML_POS); + if( i % 2 == 0 ) + l.SetLineColor(kViolet); + else + l.SetLineColor(kViolet+6); + int multilayer = i+1; + l.SetLineWidth(3); + rangeLines_onlyMLLMezz.push_back(l); + if( AinB(multilayer,deadML) ) { // mark dead if in dead list + l.SetLineColor(kRed); + l.SetLineWidth(6); + rangeLines.push_back(l); + } + else if( draw_Mezz_L_ML_guidlines ) { + l.SetLineWidth(3); + rangeLines.push_back(l); + } + } + // fill the mezz range histo + int groupsPerLayer; + tubeRange = getMezzRanges( chamberName, hDead->GetNbinsX(), groupsPerLayer); + for(unsigned int i=0; i<tubeRange.size(); i++) { + TLine l( hDead->GetBinLowEdge(tubeRange.at(i).x1)+hDead->GetBinWidth(tubeRange.at(i).x1)/2.0, MEZZ_POS, hDead->GetBinLowEdge(tubeRange.at(i).x2)+hDead->GetBinWidth(tubeRange.at(i).x2)/2.0, MEZZ_POS); + l.SetLineColor(kViolet+(i % groupsPerLayer)); + int mezz = i % groupsPerLayer + 1; + int numML = GetNumML(chamberName); + if(numML==2 && i>=tubeRange.size()/2) { + mezz += groupsPerLayer; + } + l.SetLineWidth(3); + rangeLines_onlyMLLMezz.push_back(l); + if( AinB(mezz,deadMEZZ) ) { // mark dead if in dead list + l.SetLineColor(kRed); + l.SetLineWidth(6); + rangeLines.push_back(l); + } + else if( draw_Mezz_L_ML_guidlines ) { + l.SetLineWidth(3); + rangeLines.push_back(l); + } + } + + // draw the mean/stddev + std::vector<TLine> rangeLines_dead; + double mean = GetMeanFromHist(hDead); + double stddev = GetStandardDevFromHist(hDead, mean); + double dev_low = mean - stddev; + double dev_high = mean + stddev; + if( dev_low < 1. ) dev_low = STDDEV_POS; + if( dev_high > 2.*hDead->GetMaximum() ) dev_high = 2.*hDead->GetMaximum() - 1. ; + if( mean > 1. ) { + TLine l_mean( hDead->GetBinLowEdge(1), mean, hDead->GetBinLowEdge(hDead->GetNbinsX()), mean); + l_mean.SetLineColor(kGreen+3); + l_mean.SetLineWidth(2); + rangeLines_dead.push_back(l_mean); + TLine l_dev_low( hDead->GetBinLowEdge(1), dev_low, hDead->GetBinLowEdge(hDead->GetNbinsX()), dev_low); + l_dev_low.SetLineColor(kGreen); + l_dev_low.SetLineWidth(2); + rangeLines_dead.push_back(l_dev_low); + TLine l_dev_high( hDead->GetBinLowEdge(1), dev_high, hDead->GetBinLowEdge(hDead->GetNbinsX()), dev_high); + l_dev_high.SetLineColor(kGreen); + l_dev_high.SetLineWidth(2); + rangeLines_dead.push_back(l_dev_high); + } + std::vector<TLine> rangeLines_noise; + mean = GetMeanFromHist(hNoise); + stddev = GetStandardDevFromHist(hNoise, mean); + dev_low = mean - stddev; + dev_high = mean + stddev; + if( dev_low < 1. ) dev_low = STDDEV_POS; + if( dev_high > 2.*hNoise->GetMaximum() ) dev_high = 2.*hNoise->GetMaximum() - 1. ; + if( mean > 1. ) { + TLine l_mean( hNoise->GetBinLowEdge(1), mean, hNoise->GetBinLowEdge(hNoise->GetNbinsX()), mean); + l_mean.SetLineColor(kGreen+3); + l_mean.SetLineWidth(2); + rangeLines_noise.push_back(l_mean); + TLine l_dev_low( hNoise->GetBinLowEdge(1), dev_low, hNoise->GetBinLowEdge(hNoise->GetNbinsX()), dev_low); + l_dev_low.SetLineColor(kGreen); + l_dev_low.SetLineWidth(2); + rangeLines_noise.push_back(l_dev_low); + TLine l_dev_high( hNoise->GetBinLowEdge(1), dev_high, hNoise->GetBinLowEdge(hNoise->GetNbinsX()), dev_high); + l_dev_high.SetLineColor(kGreen); + l_dev_high.SetLineWidth(2); + rangeLines_noise.push_back(l_dev_high); + } + + // noisy tubes + for(unsigned i = 0 ; i!= noisyTubes->size(); ++i){ + int TubeId = noisyTubes->at(i); + if( hNoise->At(TubeId) < 1. ) { + hOnlyNoise->SetBinContent(TubeId, MARKER_POS_RED); + hOnlyNoise->SetBinError(TubeId, 0.001); + } + else { + if( separate_dead_noisy_histos ) + hOnlyNoise->SetBinContent(TubeId, hNoise->GetBinContent(TubeId)); + else + hOnlyNoise->SetBinContent(TubeId, hDead->GetBinContent(TubeId)); + hOnlyNoise->SetBinError(TubeId, 0.001); + } + } + // dead tubes + for(unsigned i = 0; i!=deadTubes->size(); ++i){ + int TubeId = deadTubes->at(i); + if( hDead->At(TubeId) < 1. ) { + hOnlyDead->SetBinContent(TubeId, MARKER_POS_RED); + hOnlyDead->SetBinError(TubeId, 0.001); + } + else { + hOnlyDead->SetBinContent(TubeId, hDead->GetBinContent(TubeId)); + hOnlyDead->SetBinError(TubeId, 0.001); + } + } + // masked (cutouts) + for(unsigned i = 0; i!=maskedTubesForDead.size(); ++i){ + int TubeId = maskedTubesForDead.at(i); + if( hDead->At(TubeId) < 1. ) { + hOnlyMaskedDead->SetBinContent(TubeId, MARKER_POS_BLUE); + hOnlyMaskedDead->SetBinError(TubeId, 0.001); + } + else { + hOnlyMaskedDead->SetBinContent(TubeId, hDead->GetBinContent(TubeId)); + hOnlyMaskedDead->SetBinError(TubeId, 0.001); + } + } + +// for(unsigned i = 0; i!=maskedTubesForNoisy.size(); ++i){ +// int TubeId = maskedTubesForNoisy.at(i); +// if( hNoise->At(TubeId) < 1. ) { +// hOnlyMaskedNoisy->SetBinContent(TubeId, MARKER_POS_BLUE); +// hOnlyMaskedNoisy->SetBinError(TubeId, 0.01); +// } +// else { +// hOnlyMaskedNoisy->SetBinContent(TubeId, hNoise->GetBinContent(TubeId)); +// hOnlyMaskedNoisy->SetBinError(TubeId, 0.01); +// } +// } + + double maxy_dead = hDead->GetMaximum()+1.1; + hDead->SetAxisRange(0.1,2*maxy_dead,"y"); + hOnlyDead->SetMarkerColor(kRed); hOnlyDead->SetMarkerStyle(22); hOnlyDead->SetMarkerSize(1); hOnlyDead->SetAxisRange(0.1,2*maxy_dead,"y"); + hOnlyMaskedDead->SetMarkerColor(kBlue); hOnlyMaskedDead->SetMarkerStyle(21); hOnlyMaskedDead->SetMarkerSize(.5); hOnlyMaskedDead->SetAxisRange(0.1,2*maxy_dead,"y"); + + double maxy_noise = hNoise->GetMaximum()+1.1; + hNoise->SetAxisRange(0.1,2*maxy_noise,"y"); + hOnlyNoise->SetMarkerColor(kRed); hOnlyNoise->SetMarkerStyle(22); hOnlyNoise->SetMarkerSize(1); hOnlyNoise->SetAxisRange(0.1,2*maxy_noise,"y"); +// hOnlyMaskedNoisy->SetMarkerColor(kBlue); hOnlyMaskedNoisy->SetMarkerStyle(21); hOnlyMaskedNoisy->SetMarkerSize(.5); hOnlyMaskedNoisy->SetAxisRange(0.1,2*maxy_noise,"y"); + + TText validityFailAll(1,1,"FAILED VALIDITY CHECKS"); + TText validityFailDead(1,1,"FAILED VALIDITY CHECKS FOR DEAD TUBES"); + TText validityFailNoise(2,2,"FAILED VALIDITY CHECKS FOR NOISY TUBES"); + TText validityFailNoiseRetry(1,1,"VALIDITY: USING ALL HITS HISTO"); + + c->cd(1); + gPad->SetLogy(); + hDead->Draw(); + if( draw_masked_tubes ) + hOnlyMaskedDead->Draw("same"); + hOnlyDead->Draw("same"); + for(unsigned int i=0; i<rangeLines.size(); i++) rangeLines.at(i).Draw("same"); + if( draw_mean ) { for(unsigned int i=0; i<rangeLines_dead.size(); i++) rangeLines_dead.at(i).Draw("same"); } + if( deadTubesChamberValidity != 1 && draw_validity_message ) + validityFailDead.Draw("same"); + if( separate_dead_noisy_histos ) { + c->cd(2); + gPad->SetLogy(); + hNoise->Draw(); + hOnlyNoise->Draw("same"); +// if( draw_masked_tubes ) hOnlyMaskedNoisy->Draw("same"); + for(unsigned int i=0; i<rangeLines.size(); i++) rangeLines_onlyMLLMezz.at(i).Draw("same"); + if( draw_mean ) { for(unsigned int i=0; i<rangeLines_dead.size(); i++) rangeLines_noise.at(i).Draw("same"); } + if( draw_validity_message ) { + if( noisyTubesChamberValidity == 2 ) + validityFailNoiseRetry.Draw("same"); + else if( noisyTubesChamberValidity != 1 ) + validityFailAll.Draw("same"); + } + } + else { + if( noisyTubesChamberValidity != 1 && draw_validity_message ) + validityFailNoise.Draw("same"); + hOnlyNoise->Draw("same"); + } + + std::ostringstream Out; + + TString ecapStr = "MDTBADead"; + if(chamberName(0,1)=="B" && chamberName(4,1)=="C") ecapStr = "MDTBCDead"; + else if(chamberName(0,1)=="E" && chamberName(4,1)=="A") ecapStr = "MDTEADead"; + else if(chamberName(0,1)=="E" && chamberName(4,1)=="C") ecapStr = "MDTECDead"; + + // std::cout << ecapStr << " " << chamberName(0,1) << " " << chamberName(3,1) << std::endl; + Out << inFilename << "." << ecapStr << ".pdf"; + + c->Print(Out.str().c_str(), "pdf"); + // delete hNoise; + // delete hDead; + delete hOnlyNoise; + delete hOnlyDead; +// delete hOnlyMaskedNoisy; + delete hOnlyMaskedDead; + +// delete hDeadML; delete hDeadL; delete hDeadMezz; delete hDeadTubes; delete hNoiseTubes; + } + +} diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e2cc425bdfb71fac027e25dee252f8ef23e8d34f --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile.cxx @@ -0,0 +1,2314 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: MonitoringFile.cxx 606175 2014-07-12 13:16:19Z ponyisi $ +// ********************************************************************** + +#include "DataQualityUtils/MonitoringFile.h" +#include "DataQualityInterfaces/HanApp.h" +#include "DataQualityInterfaces/HanUtils.h" + +#include <cmath> +#include <cstdio> +#include <exception> +#include <fstream> +#include <iostream> +#include <memory> +#include <set> +#include <sstream> +#include <vector> +#include <map> + +#include <boost/algorithm/string/split.hpp> +#include <boost/algorithm/string/classification.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/regex.hpp> +#include <TObject.h> +#include <TSystem.h> + +#include <TDirectory.h> +#include <TFile.h> +#include <TGraph.h> +#include <TH1.h> +#include <TH2.h> +#include <TIterator.h> +#include <TKey.h> +#include <TROOT.h> +#include <TTree.h> + +ClassImp(dqutils::MonitoringFile) + + +namespace dqutils { + +bool histOKToMerge(TH1* h) { + Long_t arrsize, computedsize; + switch (h->GetDimension()) { + case 1: + computedsize = h->GetNbinsX()+2; + break; + case 2: + computedsize = (h->GetNbinsX()+2)*(h->GetNbinsY()+2); + break; + case 3: + computedsize = (h->GetNbinsX()+2)*(h->GetNbinsY()+2)*(h->GetNbinsZ()+2); + break; + default: + std::cerr << "Unable to handle dimension of " << h->GetName() << "; refusing to merge"; + return false; + } + TArray* arrptr = dynamic_cast<TArray*>(h); + if (! arrptr) { + std::cerr << "Unable to cast TH1 to TArray for " << h->GetName() << " - saying it's OK and hoping for the best" << std::endl; + return true; + } + arrsize = arrptr->GetSize(); + if (computedsize != arrsize) { + std::cout << "Sizes: computed " << computedsize << " array " << arrsize << std::endl; + } + return computedsize == arrsize; +} + +// ********************************************************************* +// Public Methods +// ********************************************************************* + +MonitoringFile::OutputMetadata:: +OutputMetadata( TTree* metadata ) + : charArrSize(100) + , m_metadata(metadata) + , m_nameData(0) + , m_intervalData(0) + , m_chainData(0) + , m_mergeData(0) +{ + m_nameData = new char[charArrSize]; + m_intervalData = new char[charArrSize]; + m_chainData = new char[charArrSize]; + m_mergeData = new char[charArrSize]; + adjustAddresses( "Name", m_nameData, "Name/C" ); + adjustAddresses( "Interval", m_intervalData, "Interval/C" ); + adjustAddresses( "TriggerChain", m_chainData, "TriggerChain/C" ); + adjustAddresses( "MergeMethod", m_mergeData, "MergeMethod/C" ); +} + +void +MonitoringFile::OutputMetadata:: +adjustAddresses(const char* branchName, void* ptr, const char* branchstr) +{ + if (m_metadata->GetBranch(branchName)) { + m_metadata->SetBranchAddress(branchName, ptr); + } else { + m_metadata->Branch(branchName, ptr, branchstr); + } +} + + +MonitoringFile::OutputMetadata:: +~OutputMetadata() +{ + delete [] m_mergeData; + delete [] m_chainData; + delete [] m_intervalData; + delete [] m_nameData; +} + + +void +MonitoringFile::OutputMetadata:: +fill( std::string name, + std::string interval, + std::string chain, + std::string merge ) +{ + copyString( m_nameData, name ); + copyString( m_intervalData, interval ); + copyString( m_chainData, chain ); + copyString( m_mergeData, merge ); + m_metadata->Fill(); +} + + +void +MonitoringFile::OutputMetadata:: +copyString( char* to, const std::string& from ) +{ + int i = 0; + const char* f = from.c_str(); + while( ++i < charArrSize && (*to++ = *f++) != 0 ) + ; + if( i == charArrSize ) { + *to = 0; + } +} + + +MonitoringFile:: +MonitoringFile() + : m_file(0),m_mergeMatchHistoRE(0),m_mergeMatchDirRE(0), + m_mergeMatchHistoREString(".*"),m_mergeMatchDirREString(".*") +{ + m_debugLevel=0; + m_fileCompressionLevel=1; + clearData(); +} + + +MonitoringFile:: +MonitoringFile( std::string fileName ) + : m_file(0),m_mergeMatchHistoRE(0),m_mergeMatchDirRE(0), + m_mergeMatchHistoREString(".*"),m_mergeMatchDirREString(".*") +{ + m_debugLevel=0; + m_fileCompressionLevel=1; + clearData(); + setFile( fileName ); +} + + +MonitoringFile:: +~MonitoringFile() +{ + dqi::DisableMustClean disabled; + // bool useRecursiveDelete = gROOT->MustClean(); + // gROOT->SetMustClean(false); + + delete m_file; + delete m_mergeMatchDirRE; + delete m_mergeMatchHistoRE; + // gROOT->SetMustClean(useRecursiveDelete); +} + +bool MonitoringFile::setHistogramRegEx(const std::string& re){ + if(re.empty()){ + std::cerr<<__PRETTY_FUNCTION__<<"Warning empty regular expression string is given. Old RegEx \""<<m_mergeMatchHistoREString<<"\" is not changed"<<std::endl; + std::cerr<<__PRETTY_FUNCTION__<<"See http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/boost_regex/syntax.html for allowed regular expression syntax"<<std::endl; + return false; + } + boost::regex *reNew=0; + try{ + reNew=new boost::regex(re); + // this should fail if there are any problems with re! + std::string test("Test String"); + boost::regex_match(test,*reNew); + }catch(std::exception& e){ + std::cerr<<__PRETTY_FUNCTION__<<"Invalid RegEx string \""<<re<<"\". Old RegEx \""<<m_mergeMatchHistoREString<<"\" is not changed"<<std::endl; + std::cerr<<__PRETTY_FUNCTION__<<"See http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/boost_regex/syntax.html for allowed regular expression syntax"<<std::endl; + delete reNew; + return false; + } + delete m_mergeMatchHistoRE; + m_mergeMatchHistoREString=re; + m_mergeMatchHistoRE=reNew; + //delete reNew; + m_useRE=true; + return true; +} + +bool MonitoringFile::setDirectoryRegEx(const std::string& re){ + if(re.empty()){ + std::cerr<<__PRETTY_FUNCTION__<<"Warning empty regular expression string is given. Old RegEx \""<<m_mergeMatchDirREString<<"\" is not changed"<<std::endl; + std::cerr<<__PRETTY_FUNCTION__<<"See http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/boost_regex/syntax.html for allowed regular expression syntax"<<std::endl; + return false; + } + boost::regex *reNew=0; + try{ + reNew=new boost::regex(re); + boost::regex_match("Test string",*reNew); + }catch(std::exception& e){ + std::cerr<<__PRETTY_FUNCTION__<<"Invalid RegEx string \""<<re<<"\". Old RegEx \""<<m_mergeMatchDirREString<<"\" is not changed"<<std::endl; + std::cerr<<__PRETTY_FUNCTION__<<"See http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/boost_regex/syntax.html for allowed regular expression syntax"<<std::endl; + delete reNew; + return false; + } + delete m_mergeMatchDirRE; + m_mergeMatchDirREString=re; + m_mergeMatchDirRE=reNew; + //delete reNew; + m_useRE=true; + return true; +} + +void +MonitoringFile:: +getAllDirs( DirMap_t& dirmap, TDirectory* dir, std::string dirName ) +{ + if( dir == 0 ) + return; + + if( dirName != "" ) { + DirMap_t::value_type dirmapVal( dirName, dir ); + dirmap.insert( dirmapVal ); + } + + TIter next( dir->GetListOfKeys() ); + TKey* key; + while( (key = dynamic_cast<TKey*>( next() )) != 0 ) { + // don't delete TDirectories + TObject* obj = key->ReadObj(); + TDirectory* subdir = dynamic_cast<TDirectory*>( obj ); + if( subdir != 0 ) { + std::string subdirName( subdir->GetName() ); + std::string fName(""); + if( dirName != "" ) { + fName += dirName; + fName += "/"; + } + fName += subdirName; + getAllDirs( dirmap, subdir, fName ); + } + else { + delete obj; + } + } +} + + +TDirectory* +MonitoringFile:: +createDir( DirMap_t& dirmap, TDirectory* dir, std::string parent, std::string path ) +{ + if( dir == 0 ) + return 0; + + TDirectory* subdir(0); + DirMap_t::const_iterator diter; + std::string::size_type i = path.find_first_of('/'); + std::string fName(""); + if( parent != "" ) { + fName += parent; + fName += "/"; + } + + if( i != std::string::npos ) { + std::string dName( path, 0, i ); + std::string pName( path, i+1, std::string::npos ); + fName += dName; + if( dName != "" ) { + diter = dirmap.find( fName ); + if( diter != dirmap.end() ) { + subdir = diter->second; + } + else { + subdir = dir->mkdir( dName.c_str() ); + DirMap_t::value_type dirmapVal( fName, subdir ); + dirmap.insert( dirmapVal ); + } + } + else { + subdir = dir; + } + return createDir( dirmap, subdir, fName, pName ); + } + + fName += path; + + diter = dirmap.find( fName ); + if( diter != dirmap.end() ) { + return diter->second; + } + + subdir = dir->mkdir( path.c_str() ); + DirMap_t::value_type dirmapVal( fName, subdir ); + dirmap.insert( dirmapVal ); + return subdir; +} + + +TKey* +MonitoringFile:: +getObjKey( TDirectory* dir, std::string path ) +{ + if( dir == 0 ) + return 0; + + TKey* key(0); + + std::string::size_type i = path.find_first_of('/'); + if( i != std::string::npos ) { + std::string dName( path, 0, i ); + std::string pName( path, i+1, std::string::npos ); + if( dName != "" ) { + key = dir->FindKey( dName.c_str() ); + if( key != 0 ) { + TDirectory* subDir = dynamic_cast<TDirectory*>( key->ReadObj() ); + if (subDir) { + return getObjKey( subDir, pName ); + } // else fall through + } + return 0; + } + return getObjKey( dir, pName ); + } + + return dir->FindKey( path.c_str() ); + +} + +std::string getInputDirectory(std::string outputDirName, TFile* input, bool has_multiple_runs, std::map< TFile*, std::string >* prefixes) { + if (! has_multiple_runs) { + return outputDirName; + } else { + std::string retval(outputDirName); + std::string::size_type sepi = retval.find("run_multiple"); + if (sepi != std::string::npos && prefixes->find(input) != prefixes->end()) { + retval.replace(sepi, 12, (*prefixes)[input]); + } + return retval; + } +} + +std::string getOutputDirectory(std::string inputDirName, TFile* input, bool has_multiple_runs, std::map< TFile*, std::string >* prefixes) { + if (! has_multiple_runs) { + return inputDirName; + } else { + std::string retval(inputDirName); + if (prefixes->find(input) == prefixes->end()) { + return retval; + } + std::string::size_type sepi = retval.find((*prefixes)[input]); + if (sepi != std::string::npos) { + retval.replace(sepi, (*prefixes)[input].length(), "run_multiple"); + } + return retval; + } +} + +std::string getOutputDirectory(TKey* key, TFile* input, bool has_multiple_runs, std::map< TFile*, std::string >* prefixes) { + if (TClass::GetClass(key->GetClassName())->InheritsFrom("TDirectory")) { + return getOutputDirectory(key->GetName(), input, has_multiple_runs, prefixes); + } else { + return key->GetName(); + } +} + +// This function will populate a mapping between key names and vectors of cycles +void populateKeyMapping(TDirectory* dir, keycyclemap& kcmap) { + TIter nextKey( dir->GetListOfKeys() ); + TKey* key; + std::string keyName(""); + while( (key = dynamic_cast<TKey*>( nextKey() )) != 0 ) { + kcmap[key->GetName()].push_back(key->GetCycle()); + } +} + +// This function will merge objects given a name, a vector of cycles, +// a directory, a merge type, and optionally an object to merge into. +// Return value is a merged object. +TObject* MonitoringFile::mergeObjsMultiCycles(const std::string& keyname, + const std::vector<int>& cycles, + TDirectory* dir, + std::string & mergeType, + TObject* obj) { + if (cycles.size() == 0) { + return obj; + } + int start_idx = 0; + if (obj == 0) { + TKey* key(dir->GetKey(keyname.c_str(), cycles[0])); + obj = key->ReadObj(); + start_idx = 1; + TH1* h = dynamic_cast<TH1*>(obj); + if (h && !histOKToMerge(h)) { + // histogram is damaged goods + std::cerr << "WARNING: HISTOGRAM " << h->GetName() << " IS INTERNALLY INCONSISTENT, NOT MERGING" << std::endl; + return obj; + } + } + for (std::vector<int>::size_type idx = start_idx; + idx < cycles.size(); ++idx) { + TKey* nextKey = dir->GetKey(keyname.c_str(), cycles[idx]); + if (nextKey != 0) { + std::auto_ptr<TObject> nextObj(nextKey->ReadObj()); + if (nextObj.get() == 0) { + std::cerr << "MonitoringFile::mergeObjsMultiCycles(): " + << "In directory \"" << dir->GetPath() << "\",\n" + << " Object \"" << keyname << "\" cannot be read from file: skipping\n"; + continue; + } + TH1* h = dynamic_cast<TH1*>(nextObj.get()); + if (h && !histOKToMerge(h)) { + // histogram is damaged goods; even deleting it may be dangerous + std::cerr << "WARNING: HISTOGRAM " << h->GetName() << " IS INTERNALLY INCONSISTENT, NOT MERGING" << std::endl; + nextObj.release(); + continue; + } + MonitoringFile::mergeObjs(obj, nextObj.get(), mergeType,m_debugLevel>VERBOSE?VERBOSE: (dqutils::MonitoringFile::debugLevel_t)m_debugLevel); + } else { + std::cerr << "MonitoringFile::mergeObjsMultiCycles(): NULL KEY; corrupt file?" << std::endl; + } + } + return obj; +} + + +void getListOfKeysWithName(TDirectory* dir, const std::string& keyname, + TCollection* target) +{ + target->Clear(); + TIter keyit(dir->GetListOfKeys()); + TKey* key; + while ( (key = dynamic_cast<TKey*>(keyit())) != 0 ) { + if (keyname == key->GetName()) { + target->Add(key); + } + } +} + +void populateCycleVector(const TCollection& source, std::vector<int>& target) +{ + TKey* key; + TIter keyit(&source); + while ( (key = dynamic_cast<TKey*>(keyit())) != 0 ) { + target.push_back(key->GetCycle()); + } +} + + +// 'mergeDirectory(...)' is based on 'MergeRootfile(...)' in the hadd.cxx utility in ROOT, using +// the same algorithm for looping over files, directories and histograms. + +void +MonitoringFile:: +mergeDirectory( TDirectory* outputDir, const std::vector<TFile*>& inputFiles, bool has_multiple_runs, std::map< TFile*, std::string >* prefixes ) +{ + typedef std::set< std::string > ObjNameSet_t; + typedef std::map< std::string, MetaData > MetaDataMap_t; + + if( outputDir == 0 ) { + return; + } + + gROOT->cd(); + + std::string outputDirPath( outputDir->GetPath() ); + std::string outputDirName( outputDirPath ); + std::string::size_type sepi = outputDirPath.find_last_of(':'); + if( sepi != std::string::npos ) { + outputDirName = std::string( outputDirPath, sepi+2, std::string::npos ); + } + //std::cout << outputDirName << std::endl; + bool metadataInDir = false; + bool targetDir=!m_useRE; + if(m_useRE && (boost::regex_search(outputDirName,*m_mergeMatchDirRE))){ + //std::cout<<"Found target dir \""<<outputDirName<<"\""<<std::endl; + targetDir=true; + } + TTree* mdTree = new TTree( "metadata", "Monitoring Metadata" ); + mdTree->SetDirectory(0); + OutputMetadata outputmd( mdTree ); + + ObjNameSet_t mergedObjs; + MetaDataMap_t mdMap; + + std::vector<TFile*>::const_iterator inputFilesEnd = inputFiles.end(); + for( std::vector<TFile*>::const_iterator i = inputFiles.begin(); i != inputFilesEnd; ++i ) { + TFile* inputFile = *i; + TDirectory* inputDir = inputFile->GetDirectory( getInputDirectory(outputDirName, inputFile, has_multiple_runs, prefixes).c_str() ); + if( inputDir == 0 ) { + // Directory is not present in this file; try next file + continue; + } + //std::cout<<"inputdir=\""<<inputDir->GetPath()<<"\""<<std::endl; + if( inputDir == outputDir ) { + continue; + } + + inputDir->cd(); + fillMetaDataMap( mdMap, inputDir ); + gROOT->cd(); + + TIter nextKey( inputDir->GetListOfKeys() ); + TKey* key; + std::string keyName(""); + keycyclemap kcmap; + populateKeyMapping(inputDir, kcmap); + + for (keycyclemap::iterator kcit = kcmap.begin(); + kcit != kcmap.end(); + ++kcit) { + key = inputDir->GetKey(kcit->first.c_str(), kcit->second.back()); + if (! key) { + std::cout << "Key " << kcit->first.c_str() << ";" << kcit->second.back() << " not readable" << std::endl; + continue; + } + kcit->second.pop_back(); + keyName = getOutputDirectory(key, inputFile, has_multiple_runs, prefixes); + ObjNameSet_t::iterator obji = mergedObjs.find( keyName ); + if( obji != mergedObjs.end() ) { + // Object has already been processed + continue; + } + // we only need to read the non-dir objects below target directory. skip the rest + bool isDir=false; + if(m_useRE && key->IsFolder()){ + //std::cout<<"Key "<<keyName<<" is a folder"<<std::endl; + if(keyName!="metadata")isDir=true; //metadata is not going to be merged, treat it as a regular obj + } + if(!targetDir && !isDir){ + //std::cerr<<"Skipping keyname "<keyname<<std::endl; + continue; //skip everything except directories + } + std::auto_ptr<TObject> obj(key->ReadObj()); + if (obj.get() == 0) { + std::cerr << "MonitoringFile::mergeDirectory(): " + << "In directory \"" << inputDir->GetPath() << "\",\n" + << " Object \"" << key->GetName() << "\" cannot be read from file: skipping\n"; + continue; + } + + // we actually have an object, and it hasn't been done before + mergedObjs.insert( keyName ); + + TH1* h(0); + TGraph* g(0); + TDirectory* d(0); + TTree* t(0); + TObject* targetObj(0); + //moved inside if to speedup +// h = dynamic_cast<TH1*>( obj.get() ); +// d = dynamic_cast<TDirectory*>( obj.get() ); +// g = dynamic_cast<TGraph*>( obj.get() ); +// t = dynamic_cast<TTree*>( obj.get() ); + + if((targetDir)&&((h = dynamic_cast<TH1*>( obj.get() )) || //merge only objects below target directory + (g = dynamic_cast<TGraph*>( obj.get() ))|| + ((keyName != "metadata") && (t = dynamic_cast<TTree*>( obj.get() ))))) { + //skip cases where regexp doesn't match object name, all directories are processed by default + if(m_useRE){ + if(!boost::regex_search(keyName,*m_mergeMatchHistoRE)){ + //std::cerr<<" skipping keyName=\""<<outputDirName+"/"+keyName<<"\""<<std::endl; + continue; // not the histogram we want + } + } + std::string mergeType("<default>"); + MetaDataMap_t::iterator mdi = mdMap.find( keyName ); + if( mdi != mdMap.end() ) { + metadataInDir = true; + const MetaData& md = mdi->second; + if (has_multiple_runs && + (md.interval != "run" && + md.interval != "fill" && + md.interval != "all" && + md.interval != "file")){ + continue; + } + outputmd.fill( md.name, md.interval, md.chain, md.merge ); + mergeType = md.merge; + if( g && (md.merge != "<default>") ) { + std::cerr << "MonitoringFile::mergeDirectory(): " + << "In directory \"" << inputDir->GetPath() << "\",\n" + << " TGraph \"" << keyName << "\" requests merging type " << mergeType + << " but only default merging implemented for TGraphs\n"; + } + if( t && (md.merge != "<default>") ) { + std::cerr << "MonitoringFile::mergeDirectory(): " + << "In directory \"" << inputDir->GetPath() << "\",\n" + << " TTree \"" << keyName << "\" requests merging type " << mergeType + << " but only default merging implemented for TTrees\n"; + } + }else { + std::cerr << "MonitoringFile::mergeDirectory(): " + << "In directory \"" << inputDir->GetPath() << "\",\n" + << " object \"" << keyName << "\" has no metadata\n"; + } + if(t){ + TDirectory* currentDir = gDirectory; + outputDir->cd(); + TTree* t2 = t->CloneTree(); + targetObj = t2; + currentDir->cd(); + } else { + targetObj = obj.get(); + } + mergeObjsMultiCycles(keyName, kcit->second, inputDir, + mergeType, targetObj); + for( std::vector<TFile*>::const_iterator j = i+1; j!= inputFilesEnd; ++j ) { + TFile* nextInputFile = *j; + TDirectory* nextInputDir = nextInputFile->GetDirectory( getInputDirectory(outputDirName, *j, has_multiple_runs, prefixes).c_str() ); + if( nextInputDir == 0 ) { + // Directory is not present in this file; try next file + continue; + } + + TObjArray tl; std::vector<int> nextCycles; + getListOfKeysWithName(nextInputDir, kcit->first, &tl); + populateCycleVector(tl, nextCycles); + + mergeObjsMultiCycles(kcit->first, nextCycles, + nextInputDir, mergeType, targetObj); + + } + outputDir->cd(); + if (h) { + h->SetDirectory(outputDir); + } + + targetObj->Write(); + }else if( (targetDir) && (t = dynamic_cast<TTree*>(obj.get())) ) { + // do not merge metadata + }else if((d = dynamic_cast<TDirectory*>( obj.get() ))) { + // Do not run the multicycle merge on directories; + // haven't seen one yet that has multiple keys... + // Merge TDirectory + outputDir->cd(); + std::string outputSubDirName(getOutputDirectory(d->GetName(), inputFile, has_multiple_runs, prefixes)); + TDirectory* outputSubDir = outputDir->mkdir( outputSubDirName.c_str(), d->GetTitle() ); + mergeDirectory( outputSubDir, inputFiles, has_multiple_runs, prefixes ); + }else { + std::cout << "MonitoringFile::mergeDirectory(): " + << "In directory \"" << inputDir->GetPath() << "\",\n" + << " Object \"" << key->GetName() << "\" will not be merged\n"; + } + + //delete obj; + } + } + + // Write metadata TTree to output directory + if( metadataInDir ) { + outputDir->cd(); + mdTree->SetDirectory(outputDir); + mdTree->Write(); + } + delete mdTree; +} + + +void +MonitoringFile:: +fillMetaDataMap( std::map<std::string,dqutils::MonitoringFile::MetaData>& mdMap, TDirectory* dir ) +{ + if (dir == 0) return; + TKey *mdKey = dynamic_cast<TKey*>(dir->GetListOfKeys()->FindObject("metadata")); + if (mdKey == 0) return; + TTree *md = dynamic_cast<TTree*>(mdKey->ReadObj()); + if (md == 0) return; + + char* i_name = new char[100]; + char* i_interval = new char[100]; + char* i_chain = new char[100]; + char* i_merge = new char[100]; + + md->SetBranchStatus( "Name", 1 ); + md->SetBranchAddress( "Name", i_name ); + md->SetBranchStatus( "Interval", 1 ); + md->SetBranchAddress( "Interval", i_interval ); + md->SetBranchStatus( "TriggerChain", 1 ); + md->SetBranchAddress( "TriggerChain", i_chain ); + md->SetBranchStatus( "MergeMethod", 1 ); + md->SetBranchAddress( "MergeMethod", i_merge ); + int counter = 0; + int nEntries = int( md->GetEntries() ); + + while( counter < nEntries ) { + try { + md->GetEntry(counter); + } + catch( const std::exception& e ) { + std::cerr << "Exception: \"" << e.what() << "\" in directory \"" + << dir->GetName() << "\"\n" << std::flush; + return; + } + + std::string nameStr(i_name); + if( mdMap.find(nameStr) == mdMap.end() ) { + MetaData md( i_name, i_interval, i_chain, i_merge ); + std::map<std::string,MetaData>::value_type mdVal( nameStr, md ); + mdMap.insert( mdVal ); + } + ++counter; + } + delete [] i_name; + delete [] i_interval; + delete [] i_chain; + delete [] i_merge; + delete md; +} + + +// 'mergeFiles(...)' is based on the hadd.cxx utility distributed with ROOT + +void +MonitoringFile:: +mergeFiles( std::string outFileName, const std::vector<std::string>& files ) +{ + dqi::DisableMustClean disabled; + TH1::AddDirectory(false); + if(m_useRE){ + std::cout<<" ========== Using regular expressions for selective merging ========== "<<std::endl; + std::cout<<" Directory selection RE=\""<<m_mergeMatchDirREString<<"\""<<std::endl; + std::cout<<" Object selection RE=\""<<m_mergeMatchHistoREString<<"\""<<std::endl; + } + typedef std::vector<TFile*> TFileList_t; + typedef std::map<TFile*, std::string> PrefixIgnore_t; + + std::auto_ptr<TFile> outfile( TFile::Open(outFileName.c_str(),"RECREATE",outFileName.c_str(),m_fileCompressionLevel) ); + if( outfile.get() == 0 ) { + std::cerr << "MonitoringFile::mergeFiles(): " + << "Output file not opened\n"; + return; + } + + TFileList_t tfiles; + PrefixIgnore_t prefix_ignore; + + std::vector< std::string >::const_iterator filesEnd = files.end(); + std::vector< std::string >::const_iterator fi; + for( fi = files.begin(); fi != filesEnd; ++fi ) { + std::cout << "Opening file: " << *fi << "\n"; + TFile* f = TFile::Open( fi->c_str() ); + if( f == 0 || ! f->IsOpen()) { + std::cerr << "MonitoringFile::mergeFiles(): " + << "Input file not opened\n"; + delete f; + continue; + } + TList* keys = f->GetListOfKeys(); + if (keys->GetSize() == 0) { + std::cerr << "MonitoringFile::mergeFiles(): " + << "Input file " << *fi << " has no keys!" + << std::endl; + delete f; + continue; + } + std::vector< std::string > runkeys; + TIter keyitr(keys); + TKey* key; + + while ( (key = dynamic_cast<TKey*>(keyitr())) != 0 ) { + std::string keyname(key->GetName()); + if (keyname.substr(0,4) == "run_") { + runkeys.push_back(keyname); + } + } + if (runkeys.size() > 1) { + std::cerr << "MonitoringFile::mergeFiles():\n" + << " Input root file " << *fi << " has multiple top-level run_* keys\n" + << " Assuming " << runkeys[0] << " is the run key" + << std::endl; + } + if (runkeys.size() > 0) { + prefix_ignore[f] = runkeys[0]; + } + tfiles.push_back(f); + } + + // check to see if all run keys are the same + bool has_multiple_runs = false; + std::string prev_key_name(""); + + for (PrefixIgnore_t::const_iterator pi_it = prefix_ignore.begin(); + pi_it != prefix_ignore.end(); + ++pi_it) { + if (prev_key_name != pi_it->second) { + if (prev_key_name == "") { + prev_key_name = pi_it->second; + } else { + has_multiple_runs = true; + break; + } + } + } + + if (has_multiple_runs) { + std::cout << "Multiple runs detected in input files.\n" + << "Will merge ONLY RUN, FILL, FILE, or ALL histograms to run_multiple directory.\n" + << "(That is, no event block, lumi block, lowStat, medStat,\n" + << "or higStat histograms will be in the output.)" + << std::endl; + } + + std::cout << "Writing file: " << outFileName << "\n"; + std::cout << "\nWarning messages from merging follow:\n\n"; + + mergeDirectory( outfile.get(), tfiles, has_multiple_runs, &prefix_ignore ); + + outfile->Close(); + + TFileList_t::const_iterator tfilesEnd = tfiles.end(); + TFileList_t::const_iterator tfi; + for( tfi = tfiles.begin(); tfi != tfilesEnd; ++tfi ) { + TFile* tf = *tfi; + tf->Delete(""); + tf->Close(); + delete tf; + } + + std::cout << "\n"; + std::cout << "****************************************\n\n"; +} + + +void +MonitoringFile:: +mergeFiles( std::string outFileName, std::string listFileName ) +{ + typedef std::vector< std::string > FileList_t; + + const unsigned int nFilesAtOnce = 10; + + FileList_t allFiles; + bool success = setListFromFile( allFiles, listFileName ); + if( !success ) { + std::cerr << "MonitoringFile::mergeFiles(): Cannot merge files\n"; + return; + } + + if( allFiles.size() <= nFilesAtOnce ) { + mergeFiles( outFileName, allFiles ); + return; + } + + FileList_t procFiles; + + + FileList_t::const_iterator filesEnd = allFiles.end(); + FileList_t::const_iterator fi = allFiles.begin(); + + unsigned int counter = 0; + std::string tmpInputFile(""); + std::string tmpOutputFile(""); + + while( fi != filesEnd ) { + + if( counter == 0 ) { + tmpOutputFile = *fi; + } + + ++counter; + ++fi; + + if( counter % nFilesAtOnce == 0 || fi == filesEnd ) { + tmpInputFile = tmpOutputFile; + procFiles.push_back( tmpInputFile ); + std::ostringstream nameStream; + nameStream << "tmp_merge_" << counter << ".root"; + tmpOutputFile = nameStream.str(); + mergeFiles( tmpOutputFile, procFiles ); + if( counter > nFilesAtOnce ) { + std::remove( tmpInputFile.c_str() ); + } + procFiles.clear(); + } + + if( fi != filesEnd ) { + procFiles.push_back( *fi ); + } + + } + + if( std::rename(tmpOutputFile.c_str(),outFileName.c_str()) == 0 ) { + std::cout << "Renaming " << tmpOutputFile << " as " << outFileName << "\n"; + } + else { + std::cerr << "Cannot rename " << tmpOutputFile << " as " << outFileName << "\n"; + } + +} + + + +bool +MonitoringFile:: +setFile( std::string fileName ) +{ + clearData(); + m_file = TFile::Open( fileName.c_str() ); + if( m_file != 0 ) + return true; + + return false; +} + + +void +MonitoringFile:: +printDirectories() const +{ + if( m_file == 0 ) { + std::cerr << "MonitoringFile::printDirectories(): " + << "No input file is open\n"; + return; + } + + DirMap_t indirmap; + + getAllDirs( indirmap, m_file, "" ); + + DirMap_t::const_iterator idirend = indirmap.end(); + for( DirMap_t::const_iterator idir = indirmap.begin(); idir != idirend; ++idir ) { + std::string idirName = idir->first; + std::cout << idirName << "\n"; + } +} + + +void +MonitoringFile:: +printStatistics() const +{ + if( m_file == 0 ) { + std::cerr << "MonitoringFile::printStatistics(): " + << "No input file is open\n"; + return; + } + + DirMap_t indirmap; + + getAllDirs( indirmap, m_file, "" ); + + DirMap_t::const_iterator idirend = indirmap.end(); + for( DirMap_t::const_iterator idir = indirmap.begin(); idir != idirend; ++idir ) { + std::string idirName = idir->first; + + GatherStatistics stat_shift( idirName ); + GatherStatistics stat_all( idirName ); + + loopOnHistogramsInMetadata( stat_shift, idir->second ); + loopOnHistograms( stat_all, idir->second ); + + std::cout.setf(std::ios_base::left,std::ios_base::adjustfield); + std::cout.width(80); + std::cout << idirName << " "; + + std::cout.setf(std::ios_base::right,std::ios_base::adjustfield); + std::cout << " shift: "; + std::cout.width(3); + std::cout << stat_shift.m_nHist1D << " "; + std::cout.width(5); + std::cout << stat_shift.m_nHist1DBins << " "; + std::cout.width(3); + std::cout << stat_shift.m_nHist2D << " "; + std::cout.width(7); + std::cout << stat_shift.m_nHist2DBins << " "; + std::cout.width(3); + std::cout << stat_shift.m_nGraph << " "; + std::cout.width(5); + std::cout << stat_shift.m_nGraphPoints << " "; + + + std::cout << " all: "; + std::cout.width(3); + std::cout << stat_all.m_nHist1D << " "; + std::cout.width(5); + std::cout << stat_all.m_nHist1DBins << " "; + std::cout.width(3); + std::cout << stat_all.m_nHist2D << " "; + std::cout.width(7); + std::cout << stat_all.m_nHist2DBins << " "; + std::cout.width(3); + std::cout << stat_all.m_nGraph << " "; + std::cout.width(5); + std::cout << stat_all.m_nGraphPoints << "\n"; + + std::cout << std::flush; + } +} + + +bool +MonitoringFile:: +copyHistograms( std::string outFileName, std::string dirName ) +{ + dqi::DisableMustClean disabled; + // bool useRecursiveDelete = gROOT->MustClean(); + // gROOT->SetMustClean(false); + + if( m_file == 0 ) { + std::cerr << "MonitoringFile::copyHistograms(): " + << "No input file is open\n"; + return false; + } + + DirMap_t indirmap; + DirMap_t reducedmap; + DirMap_t outdirmap; + + if( dirName != "all" ) { + TKey* dkey = getObjKey( m_file, dirName ); + if( dkey == 0 ) { + std::cerr << "MonitoringFile::copyHistograms(): " + << "Directory \'" << dirName << "\' not found in input file\n"; + return false; + } + + TDirectory* fromDir = dynamic_cast<TDirectory*>(dkey->ReadObj()); + + DirMap_t::value_type dirmapVal( dirName, fromDir ); + indirmap.insert( dirmapVal ); + } + else { + std::cout << "Building list of all TDirectories in file...\n" << std::flush; + getAllDirs( indirmap, m_file, "" ); + } + + DirMap_t::const_iterator idirend = indirmap.end(); + for( DirMap_t::const_iterator idir = indirmap.begin(); idir != idirend; ++idir ) { + + std::string idirName = idir->first; + std::cout << "Checking " << idirName << "\n" << std::flush; + //std::string::size_type j = idirName.find( "L1Calo/1_PPr_EmFADCTiming" ); + //if( j != std::string::npos ) { + // std::cerr << "Skipping directory \"" << idirName << "\"\n"; + // std::cerr << std::flush; + // continue; + //} + + if( !dirHasHistogramsInMetadata(idir->second) ) { + continue; + } + + reducedmap.insert( *idir ); + } + + std::auto_ptr<TFile> outfile( TFile::Open(outFileName.c_str(),"RECREATE",outFileName.c_str(),m_fileCompressionLevel) ); + if( outfile.get() == 0 ) { + std::cerr << "MonitoringFile::copyHistograms(): " + << "Output file not opened\n"; + return false; + } + + idirend = reducedmap.end(); + for( DirMap_t::const_iterator idir = reducedmap.begin(); idir != idirend; ++idir ) { + + std::string idirName = idir->first; + std::cout << "Processing " << idirName << "\n" << std::flush; + + TDirectory* toDir = createDir( outdirmap, outfile.get(), "", idirName ); + if( toDir == 0 ) { + std::cerr << "MonitoringFile::copyHistograms(): " + << "Directory \'" << idirName << "\' not created in output file\n"; + return false; + } + + CopyHistogram copyFcn( toDir, idirName ); + + loopOnHistogramsInMetadata( copyFcn, idir->second ); + } + + outfile->Write(); + outfile->Close(); + + // gROOT->SetMustClean(useRecursiveDelete); + return true; +} + + + +std::string +MonitoringFile:: +getHanResults( std::string hanResultsDir, std::string input, + std::string hcfg, std::string hcfg_lowStat, std::string hcfg_medStat ) +{ + //DisableMustClean disabled; + + std::cout << "\nUsing han configurations:\n" + << " entire run: " << hcfg << "\n" + << " low stat interval: " << hcfg_lowStat << "\n" + << " medium stat interval: " << hcfg_medStat << "\n\n" << std::flush; + + + TFile* infile = TFile::Open( input.c_str() ); + if( infile == 0 ) { + std::cerr << "MonitoringFile::getHanResults(): " + << "Cannot open input file \"" << input << "\"\n"; + return ""; + } + + std::vector<std::string> run_dirs; + std::vector<std::string> lowStat_dirs; + std::vector<std::string> medStat_dirs; + + TIter next_run( infile->GetListOfKeys() ); + TKey* key_run(0); + while( (key_run = dynamic_cast<TKey*>( next_run() )) != 0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if( tdir_run != 0 ) { + std::string tdir_run_name( tdir_run->GetName() ); + if( tdir_run_name.find("run") != std::string::npos ) { + run_dirs.push_back( tdir_run_name ); + TIter next_minutes( tdir_run->GetListOfKeys() ); + TKey* key_minutes(0); + while( (key_minutes = dynamic_cast<TKey*>( next_minutes() )) != 0 ) { + TObject* obj_minutes = key_minutes->ReadObj(); + TDirectory* tdir_minutes = dynamic_cast<TDirectory*>( obj_minutes ); + if( tdir_minutes != 0 ) { + std::string tdir_minutes_name( tdir_minutes->GetName() ); + if( tdir_minutes_name.find("lowStat") != std::string::npos ) { + lowStat_dirs.push_back( tdir_run_name + "/" + tdir_minutes_name ); + } + else if( tdir_minutes_name.find("medStat") != std::string::npos ) { + medStat_dirs.push_back( tdir_run_name + "/" + tdir_minutes_name ); + } + } + delete obj_minutes; + } + } + } + delete obj_run; + } + + delete infile; + + dqi::HanApp han; + + std::string fileList =" "; + std::vector<std::string>::const_iterator dirs_end; + std::vector<std::string>::const_iterator dir; + + dirs_end = run_dirs.end(); + for( dir = run_dirs.begin(); dir != dirs_end; ++dir ) { + const std::string& tdir_run_name = *dir; + std::string han_output_run = hanResultsDir+"/"+tdir_run_name+"_han.root"; + std::cout << "Calling han( " << hcfg << ", " << input << ", " << tdir_run_name + << ", " << han_output_run << " ):\n" << std::flush; + han.Analyze( hcfg, input, han_output_run, tdir_run_name ); + std::cout << "\n"; + fileList += han_output_run + " " + tdir_run_name + "\n" ; + } + + dirs_end = lowStat_dirs.end(); + for( dir = lowStat_dirs.begin(); dir != dirs_end; ++dir ) { + const std::string& tdir_minutes_path = *dir; + + std::string tdir_minutes_underscore = tdir_minutes_path; + std::string::size_type tdir_minutes_i = tdir_minutes_underscore.find("/"); + tdir_minutes_underscore.replace( tdir_minutes_i, 1, "_" ); + + std::string han_output_lowStat = hanResultsDir+"/"+tdir_minutes_underscore+"_han.root"; + std::cout << "Running han, writing to " << han_output_lowStat << ":\n" << std::flush; + han.Analyze( hcfg_lowStat, input, han_output_lowStat, tdir_minutes_path ); + std::cout << "\n"; + std::string subdirname( tdir_minutes_path, tdir_minutes_i+1, std::string::npos ); + std::string dirname( tdir_minutes_path, 0, tdir_minutes_i ); + fileList += han_output_lowStat + " " + subdirname + " " + dirname + " " + subdirname +"\n" ; + } + + dirs_end = medStat_dirs.end(); + for( dir = medStat_dirs.begin(); dir != dirs_end; ++dir ) { + const std::string& tdir_minutes_path = *dir; + + std::string tdir_minutes_underscore = tdir_minutes_path; + std::string::size_type tdir_minutes_i = tdir_minutes_underscore.find("/"); + tdir_minutes_underscore.replace( tdir_minutes_i, 1, "_" ); + + std::string han_output_medStat = hanResultsDir+"/"+tdir_minutes_underscore+"_han.root"; + std::cout << "Running han, writing to " << han_output_medStat << ":\n" << std::flush; + han.Analyze( hcfg_medStat, input, han_output_medStat, tdir_minutes_path ); + std::cout << "\n"; + std::string subdirname( tdir_minutes_path, tdir_minutes_i+1, std::string::npos ); + std::string dirname( tdir_minutes_path, 0, tdir_minutes_i ); + fileList += han_output_medStat + " " + subdirname + " " + dirname + " " + subdirname +"\n" ; + } + + return fileList; +} + + +void +MonitoringFile:: +printHanConfig() const +{ + if( m_file == 0 ) { + std::cerr << "MonitoringFile::printHanConfig(): " + << "No input file is open\n"; + return; + } + + DirMap_t indirmap; + + getAllDirs( indirmap, m_file, "" ); + + std::string indent, indent_p,indent_c; + std::string idirName_p; + DirMap_t::const_iterator idirend = indirmap.end(); + for( DirMap_t::const_iterator idir = indirmap.begin(); idir != idirend; ++idir ) { + std::string idirName = idir->first; + std::string::size_type shortNameIndex = idirName.rfind( '/' ); + std::string shortName = idirName.substr( shortNameIndex+1, std::string::npos ); + + std::string::size_type fsIndex = idirName.find( '/' ); + std::string shortPath; + if( fsIndex != shortNameIndex ) + shortPath = idirName.substr( fsIndex+1, shortNameIndex ); + else + shortPath = idirName.substr( fsIndex+1, std::string::npos ); + + std::cout << idirName << "\n"; + std::cout << shortPath << ", " << shortName << "\n"; + /* + indent = getIndentation(idirName,""); + if(int(indent.size())==in_p){ + std::cout << indent << "} \n"; + std::cout << indent << "dir " << shortName << " { \n"; + std::cout << indent << " output " << idirName << "\n"; + std::cout << indent << " hist all_in_dir { \n " << indent << " } \n"; + } + else if (int(indent.size()) > in_p){ + std::cout << indent << "dir " << shortName << " { \n"; + std::cout << indent << " output " << idirName << "\n"; + std::cout << indent << " hist all_in_dir { \n " << indent << " } \n"; + } + else{ + //find common part + number of common "/" + std::string common = FindCommon(idirName,idirName_p); + indent_c = getIndentation(common,""); + int counter = (indent_p.size() - indent_c.size())/2; + for (int i = counter; i>0; i--){ + std::string temp = indent_c; + for (int j = 0; j< i; j++){ + temp+=" "; + } + std::cout << temp << "} \n" ; + } + std::cout << indent << "} \n"; + std::cout << indent << "dir " << shortName << " { \n"; + std::cout << indent << " output " << idirName << "\n"; + std::cout << indent << " hist all_in_dir { \n " << indent << " } \n"; + } + indent_p = indent; + in_p = indent_p.size(); + idirName_p = idirName; + */ + } +} + + + +std::string +MonitoringFile:: +getIndentation( std::string pathName, std::string leadingSpace ) +{ + std::string space = leadingSpace; + std::string::size_type i = pathName.find_first_of('/'); + if( i != std::string::npos ) { + std::string subPath( pathName, i+1, std::string::npos ); + space += " "; + return getIndentation( subPath, space ); + } + return space; +} + +std::string +MonitoringFile:: +FindCommon(std::string name1,std::string name2) const +{ + int length = ( name1.size() < name2.size() ) ? name1.size() : name2.size(); + bool found = true; + int count = 0; + while (found==true && count < length){ + if (name1[count]==name2[count]){ + count++; + } + else { + found = false; + } + } + return (name1.substr(0,count)); +} + + + +// ********************************************************************* +// Protected Methods +// ********************************************************************* + +MonitoringFile::CopyHistogram:: +CopyHistogram( TDirectory* target, std::string dirName ) + : m_target(target) + , m_dirName(dirName) + , m_charArrSize(1000) + , m_metadata(0) + , m_nameData(0) + , m_intervalData(0) + , m_chainData(0) + , m_mergeData(0) +{ + m_metadata = new TTree( "metadata", "Monitoring Metadata" ); + m_metadata->SetDirectory(0); + m_nameData = new char[m_charArrSize]; + m_intervalData = new char[m_charArrSize]; + m_chainData = new char[m_charArrSize]; + m_mergeData = new char[m_charArrSize]; + m_metadata->Branch( "Name", m_nameData, "Name/C" ); + m_metadata->Branch( "Interval", m_intervalData, "Interval/C" ); + m_metadata->Branch( "TriggerChain", m_chainData, "TriggerChain/C" ); + m_metadata->Branch( "MergeMethod", m_mergeData, "MergeMethod/C" ); +} + + +MonitoringFile::CopyHistogram:: +~CopyHistogram() +{ + m_target->cd(); + m_metadata->SetDirectory(m_target); + m_metadata->Write(); + delete m_metadata; + delete [] m_nameData; + delete [] m_intervalData; + delete [] m_chainData; + delete [] m_mergeData; +} + + +bool +MonitoringFile::CopyHistogram:: +execute( TH1* hist ) +{ + m_target->cd(); + hist->SetDirectory(m_target); + hist->Write(); + + return true; +} + + +bool +MonitoringFile::CopyHistogram:: +execute( TGraph* graph ) +{ + m_target->cd(); + graph->Write(); + + return true; +} + + +bool +MonitoringFile::CopyHistogram:: +executeMD( TH1* hist, const MetaData& md ) +{ + m_target->cd(); + hist->SetDirectory(m_target); + hist->Write(); + + copyString( m_nameData, md.name ); + copyString( m_intervalData, md.interval ); + copyString( m_chainData, md.chain ); + copyString( m_mergeData, md.merge ); + m_metadata->Fill(); + + return true; +} + + +bool +MonitoringFile::CopyHistogram:: +executeMD( TGraph* graph, const MetaData& md ) +{ + m_target->cd(); + graph->Write(); + + copyString( m_nameData, md.name ); + copyString( m_intervalData, md.interval ); + copyString( m_chainData, md.chain ); + copyString( m_mergeData, md.merge ); + m_metadata->Fill(); + + return true; +} + + +void +MonitoringFile::CopyHistogram:: +copyString( char* to, const std::string& from ) +{ + int i = 0; + const char* f = from.c_str(); + while( ++i < m_charArrSize && (*to++ = *f++) != 0 ) + ; + if( i == m_charArrSize ) { + *to = 0; + } +} + + +MonitoringFile::GatherStatistics:: +GatherStatistics( std::string dirName ) + : m_dirName(dirName) + , m_nHist1D(0) + , m_nHist1DBins(0) + , m_nGraph(0) + , m_nGraphPoints(0) + , m_nHist2D(0) + , m_nHist2DBins(0) +{ +} + + +bool +MonitoringFile::GatherStatistics:: +execute( TH1* hist ) +{ + TH2* hist2d = dynamic_cast<TH2*>( hist ); + if( hist2d != 0 ) { + ++m_nHist2D; + m_nHist2DBins += (hist2d->GetNbinsX() * hist2d->GetNbinsY()); + return true; + } + ++m_nHist1D; + m_nHist1DBins += hist->GetNbinsX(); + return true; +} + + +bool +MonitoringFile::GatherStatistics:: +execute( TGraph* graph ) +{ + ++m_nGraph; + m_nGraphPoints += graph->GetMaxSize(); + return true; +} + + +MonitoringFile::GatherNames:: +GatherNames() +{ +} + + +bool +MonitoringFile::GatherNames:: +execute( TH1* hist ) +{ + m_names.push_back( std::string(hist->GetName()) ); + return true; +} + + +bool +MonitoringFile::GatherNames:: +execute( TGraph* graph ) +{ + m_names.push_back( std::string(graph->GetName()) ); + return true; +} + + +void +MonitoringFile:: +clearData() +{ + dqi::DisableMustClean disabled; + // bool useRecursiveDelete = gROOT->MustClean(); + // gROOT->SetMustClean(false); + + delete m_file; + m_file = 0; + m_debugLevel=0; + m_fileCompressionLevel=1; + delete m_mergeMatchHistoRE; + delete m_mergeMatchDirRE; + m_mergeMatchHistoREString=".*"; + m_mergeMatchDirREString=".*"; + m_mergeMatchHistoRE=new boost::regex(m_mergeMatchHistoREString); + m_mergeMatchDirRE=new boost::regex(m_mergeMatchDirREString); + m_useRE=false; + // gROOT->SetMustClean(useRecursiveDelete); +} + + +bool +MonitoringFile:: +dirHasHistogramsInMetadata( TDirectory* dir ) +{ + dir->cd(); + + TKey* mdKey = dir->FindKey( "metadata" ); + if( mdKey == 0 ) { + return false; + } + + TTree* md = dynamic_cast<TTree*>( mdKey->ReadObj() ); + if ( md == 0 ) { + return false; + } + + int counter = 0; + int nEntries = int( md->GetEntries() ); + + while( counter < nEntries ) { + try { + md->GetEntry(counter); + } + catch( const std::exception& e ) { + std::cerr << "Exception: \"" << e.what() << "\" in directory \"" + << dir->GetName() << "\"\n" << std::flush; + return false; + } + + return true; + ++counter; + } + + return false; +} + + +void +MonitoringFile:: +loopOnHistograms( HistogramOperation& fcn, TDirectory* dir ) +{ + TIter next( dir->GetListOfKeys() ); + TKey* key; + while( (key = dynamic_cast<TKey*>( next() )) != 0 ) { + TObject* obj = key->ReadObj(); + TH1* h = dynamic_cast<TH1*>( obj ); + if( h != 0 ) { + fcn.execute( h ); + } + else { + TGraph* g = dynamic_cast<TGraph*>( obj ); + if( g != 0 ) { + fcn.execute( g ); + } + } + delete obj; + } +} + + +bool +MonitoringFile:: +loopOnHistogramsInMetadata( HistogramOperation& fcn, TDirectory* dir ) +{ + dir->cd(); + TKey* mdKey = dir->FindKey( "metadata" ); + if( mdKey == 0 ) { + //std::cerr << "MonitoringFile::loopOnHistogramsInMetadata(): " + // << "No \'metadata\' object found in directory \"" << dir->GetName() << "\"\n"; + return false; + } + + TTree* md = dynamic_cast<TTree*>( mdKey->ReadObj() ); + if ( md == 0 ) { + return false; + } + + char* i_name = new char[100]; + char* i_interval = new char[100]; + char* i_chain = new char[100]; + char* i_merge = new char[100]; + TKey* i_key; + + md->SetBranchStatus( "Name", 1 ); + md->SetBranchAddress( "Name", i_name ); + md->SetBranchStatus( "Interval", 1 ); + md->SetBranchAddress( "Interval", i_interval ); + md->SetBranchStatus( "TriggerChain", 1 ); + md->SetBranchAddress( "TriggerChain", i_chain ); + md->SetBranchStatus( "MergeMethod", 1 ); + md->SetBranchAddress( "MergeMethod", i_merge ); + + int counter = 0; + int nEntries = int( md->GetEntries() ); + + while( counter < nEntries ) { + dir->cd(); + try { + md->GetEntry(counter); + } + catch( const std::exception& e ) { + std::cerr << "Exception: \"" << e.what() << "\" in directory \"" + << dir->GetName() << "\"\n" << std::flush; + return false; + } + + i_key = dir->FindKey( i_name ); + if( i_key == 0 ) { + std::cerr << "MonitoringFile::loopOnHistogramsInMetadata(): " + << "No \'" << i_name << "\' object found\n"; + return false; + } + MetaData md( i_name, i_interval, i_chain, i_merge ); + TObject* obj = i_key->ReadObj(); + TH1* h = dynamic_cast<TH1*>( obj ); + if( h != 0 ) { + fcn.executeMD( h, md ); + } + else { + TGraph* g = dynamic_cast<TGraph*>( obj ); + if( g != 0 ) { + fcn.executeMD( g, md ); + } + } + delete obj; + ++counter; + } + + delete [] i_name; + delete [] i_interval; + delete [] i_chain; + delete [] i_merge; + delete md; + + return true; +} + + +bool +MonitoringFile:: +setListFromFile( std::vector<std::string>& filelist, const std::string& listFileName ) +{ + using namespace std; + + filelist.clear(); + + ifstream listfile( listFileName.c_str() ); + if(!listfile) { + cerr << "MonitoringFile::setListFromFile(): " + << "cannot read from file: " << listFileName << "\n"; + return false; + } + + string line; + char c; + string filename; + while( getline(listfile,line) ) { + istringstream linestream(line); + while(linestream.get(c)) { + if(!isspace(c)) { + // ignore comments + if(c == '#') { + break; + } + + linestream.putback(c); + linestream >> filename; + if(!linestream) { + cerr << "MonitoringFile::setListFromFile(): " + << "badly formatted line: " << line << "\n"; + break; + } + + filelist.push_back(filename); + } + } + } + + return true; +} + +int MonitoringFile::mergeObjs(TObject *objTarget, TObject *obj, std::string mergeType, debugLevel_t debugLevel) { + // merge obj into objTarget based on method specified in mergeType + // copied in large parts from mergeDirectory + std::string name("mergeObjs"); + if( ! objTarget ) { + std::cerr << name << ": empty target object pointer" << std::endl; + return -1; + } + if( ! obj ) { + std::cerr << name << ": empty object pointer" << std::endl; + return -1; + } + + if( debugLevel >= VERBOSE ) + std::cout << name << ": obj->GetName() = " << obj->GetName() << ", mergeType = " << mergeType << ", class = " << obj->IsA()->GetName() << std::endl; + + TH1 *h=0, *nextH=0; + TH2 *h2=0, *nextH2=0; + TGraph *g=0; + TTree *t=0; + +// h = dynamic_cast<TH1*>( objTarget ); +// g = dynamic_cast<TGraph*>( objTarget ); +// t = dynamic_cast<TTree*>( objTarget ); + if((h = dynamic_cast<TH1*>( objTarget )) ) { // we are dealing with histograms + /* if ( debugLevel >= DEBUG ) + std::cout << " --> " << name << " is a histogram */ + nextH = dynamic_cast<TH1*>( obj ); + if (!nextH) { + std::cerr << objTarget->GetName() << " is a TH1, but " << obj->GetName() << " is not: skip merging" << std::endl; + return -1; + } + if( mergeType == "effAsPerCent" ) { + if((h2 = dynamic_cast<TH2*>( objTarget )) && (nextH2 = dynamic_cast<TH2*>( nextH ))){ + merge_effAsPerCent( *h2, *nextH2 ); + }else{ + merge_effAsPerCentAlt( *h, *nextH ); + } + }else if( mergeType == "perBinEffPerCent" ) { + merge_perBinEffPerCent( *h, *nextH ); + }else if( mergeType == "weightedAverage" ) { + merge_weightedAverage( *h, *nextH ); + }else if( mergeType == "weightedAverage2D" ) { + //if( h2 && nextH2 ) merge_weightedAverage( *h2, *nextH2 ); + merge_weightedAverage( *h, *nextH ); + }else if( mergeType == "weightedEff" ) { + merge_weightedEff( *h, *nextH ); + }else if( mergeType == "mergeRebinned" ) { + merge_Rebinned( *h, *nextH ); + }else if( mergeType == "eventSample" ) { + if((h2 = dynamic_cast<TH2*>( objTarget ))&& (nextH2 = dynamic_cast<TH2*>( nextH ))){ + merge_eventSample( *h2, *nextH2 ); + } + }else if( mergeType == "mergeRMS" ) { + merge_RMS( *h, *nextH ); + }else if( mergeType == "RMSpercentDeviation" ) { + merge_RMSpercentDeviation( *h, *nextH ); + }else if( mergeType == "lowerLB" ) { + merge_lowerLB( *h, *nextH ); + }else { + //TList tl; tl.Add(nextH); h->Merge(&tl); + h->Add( nextH ); + } + }else if( (g = dynamic_cast<TGraph*>( objTarget )) ) { // TGraphs + if( mergeType != "<default>" ) { + std::cerr << name << ": TGraph " << obj->GetName() << " request mergeType = " << mergeType + << " but only default merging implemented for TGraphs\n"; + } + TGraph *nextG = dynamic_cast<TGraph*>( obj ); + TList listG; + listG.Add( nextG ); + g->Merge( &listG ); + listG.Clear(); + }else if ((t = dynamic_cast<TTree*>( objTarget ))) { // TTrees + std::cout << "Merging Tree " << obj->GetName() << std::endl; + if( mergeType != "<default>" ) { + std::cerr << name << ": TTree " << obj->GetName() << " request mergeType = " << mergeType + << " but only default merging implemented for TTrees\n"; + } + TTree *nextT = dynamic_cast<TTree*>( obj ); + TList listT; + listT.Add( nextT ); + t->Merge( &listT ); + listT.Clear(); + } else { + std::cerr << name << ": object is not a histogram or graph, merging not implemented" << std::endl; + } + return 0; +} + +int MonitoringFile::mergeLB_recursiveDirCopy(TDirectory *dir_top_out, TDirectory *dir_out, TDirectory *cwd, + std::vector<std::string>& v_dirsSub, debugLevel_t& debugLevel) { + // store in v_dirsSub the paths (relative to dir_top_out) of all subdirectories of cwd + // copy the subfolder structure from cwd to dir_out + std::string name("mergeLB_recursiveDirCopy"); + if( ! cwd ) { + std::cerr << name << ": empty directory pointer cwd" << std::endl; + return -1; + } + if( ! dir_top_out ) { + std::cerr << name << ": empty directory pointer dir_top_out" << std::endl; + return -1; + } + if( ! dir_out ) { + std::cerr << name << ": empty directory pointer dir_out" << std::endl; + return -1; + } + + TIter next(cwd->GetListOfKeys()); + TKey *key; + while( ( key=(TKey*) next() ) ) { + std::string keyClassName(key->GetClassName()); + if( (keyClassName.size() > 9) && (keyClassName.substr(0,10) == "TDirectory") ) { + TDirectory *dir = (TDirectory*) cwd->Get(key->GetName()); + if( !dir ) { + std::cerr << name << ": could not retrieve directory " << key->GetName() << + " from " << cwd->GetPath() << std::endl; + continue; + } + dir_out->cd(); + std::string p_top(dir_top_out->GetPath()); + std::string p(gDirectory->GetPath()); + if( p_top.size() < p.size() ) { + p = p.substr(p_top.size()+1, p.size()-p_top.size()-1); // strip off the top directory part + p = p + "/"; + } + else p = ""; + + // is this directory already in the list of subdirectories? + std::vector<std::string>::iterator it; + for( it = v_dirsSub.begin(); it != v_dirsSub.end(); it++ ) { + if( *it == (p + dir->GetName()) ) break; + } + if( it == v_dirsSub.end() ) { + // no + v_dirsSub.push_back(p + dir->GetName()); + } + + TKey *test_key = dir_out->FindKey(dir->GetName()); + TDirectory *dir_out_new(0); + if( !test_key ) { + if( debugLevel >= DEBUG ) { + std::cout << name << ": creating subdirectory " << dir->GetName(); + if( p.size() != 0 ) std::cout << " in " << p << std::endl; + else std::cout << std::endl; + } + dir_out_new = (TDirectory*) gDirectory->mkdir(dir->GetName()); + if( ! dir_out_new ) { + std::cerr << name << ": could not create directory " << dir->GetName() + << " in " << gDirectory->GetPath() << std::endl; + } + } + else { + if( debugLevel >= DEBUG ) + std::cout << name << ": " << dir_out->GetPath() << "/" << dir->GetName() << " exists already" << std::endl; + + dir_out_new = (TDirectory*) dir_out->Get(test_key->GetName()); + if( ! dir_out_new ) { + std::cerr << name << ": could not retrieve directory " << test_key->GetName() + << " from " << dir_out->GetPath() << std::endl; + } + } + // go one level deeper in the directory tree + if( dir_out_new ) + mergeLB_recursiveDirCopy(dir_top_out, dir_out_new, dir, v_dirsSub, debugLevel); + + } + } + return 0; +} + +int MonitoringFile::mergeLB_createListOfHistos(TDirectory *dir_top, TDirectory *cwd, std::vector<std::string>& v_histos, debugLevel_t& debugLevel) { + // get paths relative to dir_top of all histograms and graphs in cwd + std::string name("mergeLB_createListOfHistos"); + if( ! cwd ) { + std::cerr << name << ": empty directory pointer" << std::endl; + return -1; + } + + TIter next(cwd->GetListOfKeys()); + TKey *key; + while( ( key=(TKey*) next() ) ) { + std::string keyClassName(key->GetClassName()); + if( ( (keyClassName.size() > 2) && ( (keyClassName.substr(0,3) == "TH1") || (keyClassName.substr(0,3) == "TH2") ) ) || + ( (keyClassName.size() > 7) && ( (keyClassName.substr(0,8) == "TProfile") ) ) || + ( (keyClassName.size() > 5) && ( (keyClassName.substr(0,6) == "TGraph") ) ) ) { + if( debugLevel >= VERBOSE ) + std::cout << name << ": found object: " << key->GetName(); + + // add to v_histos if not already in it + std::string p_top(dir_top->GetPath()); + std::string p(cwd->GetPath()); + if( p_top.size() < p.size() ) { + p = p.substr(p_top.size()+1, p.size()-p_top.size()-1); // strip off the top directory part + p = p + "/"; + } + else p = ""; + + std::vector<std::string>::iterator it; + for( it = v_histos.begin(); it != v_histos.end(); it++ ) { + if( *it == (p + key->GetName()) ) break; + } + + if( it == v_histos.end() ) { + std::string objName(p + key->GetName()); + v_histos.push_back(objName); + if( debugLevel >= VERBOSE ) + std::cout << ", added to list: " << p + key->GetName() << std::endl; + } + else { + if( debugLevel >= VERBOSE ) + std::cout << ", already in list" << std::endl; + } + } + } + return 0; +} + +int MonitoringFile::mergeLB_processLBinterval(std::vector<TDirectory*>& v_dirsStat, TDirectory *dir_run, debugLevel_t& debugLevel) { + // create a directory for merged histograms in dir_run + // loop over v_dirsStat directories (=different LB intervals) + // and merge all histograms and graphs (preserving the subdirectory structure) + std::string name("mergeLB_processLBinterval"); + + if( v_dirsStat.size() == 0 ) return 0; + + if( ! dir_run ) { + std::cerr << name << ": empty pointer dir_run" << std::endl; + return -1; + } + + if( ! v_dirsStat[0] ) { + std::cerr << name << ": empty first directory pointer" << std::endl; + return -1; + } + +/* + // create top-level merged directory + std::string label((v_dirsStat[0])->GetName()); + label = label.substr(0,3); + std::string dirMergedName("merged_" + label + "Stat"); + TDirectory *dir_merged = dir_run->mkdir(dirMergedName.c_str()); + if( !dir_merged ) { + std::cerr << name << ": could not create directory " << dirMergedName << std::endl; + return -1; + } + if( debugLevel >= DEBUG ) + std::cout << name << ": created new directory " << dir_merged->GetPath() << std::endl; +*/ + TDirectory *dir_merged = dir_run; + + // Histograms can be booked on demand in AthenaMonitoring. + // So a histogram might be present in lowStat_LB21-30 but not + // in lowStat_LB1-10. Also entire directories might be missing + // in certain LB intervals. + // Hence, to cope with on-demand-booking have to loop over all + // LB intervals to identify all histograms. + + // To limit memory usage, instead of holding all merged histograms in + // memory, build a list of histogram names (including full path because + // can have same name in different subfolders, like Jets/Topo/JetP and + // Jets/Tower/JetP). + + // Build this list only per subfolder. Then loop over list, merge the + // histograms, write them to ROOT file, and delete them from memory. + + // instead of a list, create a map which also holds the merging type + // (whether simply TH1F::Add() or more complicated function) from metadata. + + std::vector<TDirectory*>::const_iterator i; + // loop over LB intervals: + // - get list of subdirectories + // - and create subdirectory structure in merged directory + std::vector<std::string> v_dirsSub; + for( i = v_dirsStat.begin(); i != v_dirsStat.end(); i++ ) { + TDirectory *dirStat = *i; + if( debugLevel >= DEBUG ) + if( dirStat ) + std::cout << name << ": getting input from directory " << dirStat->GetPath() << std::endl; + mergeLB_recursiveDirCopy(dir_merged, dir_merged, dirStat, v_dirsSub, debugLevel); + // v_dirsSub are paths relative to dir_merged + } + + // loop over subdirectories: + if( v_dirsSub.size() == 0 ) { + if( debugLevel >= DEBUG ) + std::cout << name << ": no subdirectories found" << std::endl; + return 0; + } + // - create list of histograms + // - loop over all LB intervals because of on-demand-booking + // - loop over histogram list + // - loop over LB intervals + // - merge histograms + // - write merged histogram to file and delete it from memory + std::vector<std::string>::const_iterator it_string; + for( it_string = v_dirsSub.begin(); it_string != v_dirsSub.end(); it_string++ ) { + std::string dirFullName = *it_string; + std::vector<std::string> v_histos; + if( debugLevel >= DEBUG ) + std::cout << name << ": processing " << dirFullName << std::endl; + for( i = v_dirsStat.begin(); i != v_dirsStat.end(); i++ ) { + TDirectory *dirStat = *i; + TDirectory *dir = (TDirectory*) dirStat->Get(dirFullName.c_str()); + if( !dir ) { + std::cerr << name << ": could not retrieve directory " << dirFullName << + " from " << dirStat->GetPath() << std::endl; + continue; + } + if( debugLevel >= DEBUG ) + std::cout << name << ": processing LB folder " << dir->GetPath() << std::endl; + mergeLB_createListOfHistos(dirStat, dir, v_histos, debugLevel); + } + + if( v_histos.size() == 0 ) { + if( debugLevel >= DEBUG ) + std::cout << name << ": no objects found" << std::endl; + continue; + } + + TDirectory *dir_out = (TDirectory*) dir_merged->Get(dirFullName.c_str()); + if( !dir_out ) { + std::cerr << name << ": could not retrieve directory " << dirFullName << + " from " << dir_merged->GetPath() << std::endl; + continue; + } + + // create new metadata tree for current merged directory if not already extant + typedef std::map< std::string, MetaData > MetaDataMap_t; + TTree* mdTree = dynamic_cast<TTree*>(dir_out->Get("metadata")); + if (!mdTree) { + mdTree = new TTree( "metadata", "Monitoring Metadata" ); + } + mdTree->SetDirectory(0); + OutputMetadata outputmd( mdTree ); + + // get metadata from one of the input directories + // this is for caching, could also read the metadata directly from tree in the + // current directory when accessing the histogram + MetaDataMap_t mdMap; + TDirectory *dir_in = (TDirectory*) v_dirsStat[0]->Get(dirFullName.c_str()); + if( !dir_in ) { + std::cerr << name << ": could not retrieve directory " << dirFullName << + " from " << v_dirsStat[0]->GetPath() << std::endl; + continue; + } + fillMetaDataMap( mdMap, dir_in); + + // histogram loop + std::vector<std::string>::const_iterator it_string2; + for( it_string2 = v_histos.begin(); it_string2 != v_histos.end(); it_string2++ ) { + std::string histFullName = *it_string2; // something like Jets/Tower/JetP + + TObject *objMerged(0); + std::string mergeType("<default>"); + // LB interval loop + bool key_checked = false; + for( i = v_dirsStat.begin(); i != v_dirsStat.end(); i++ ) { + // retrieve histogram for current LB interval + TDirectory *dir_current = (*i); + std::auto_ptr<TObject> objThis((TObject*) dir_current->Get(histFullName.c_str())); + + if( ! objThis.get() ) { // histogram does not exist in this LB interval + continue; + } + + // test if histogram exists already in dir_out + if (! key_checked) { + TKey *test_key = dir_out->FindKey(objThis->GetName()); + if( test_key ) { + if( debugLevel >= DEBUG ) + std::cout << name << ": " << dir_out->GetPath() << "/" << objThis->GetName() + << " exists already, not written" << std::endl; + break; + } + key_checked = true; + } + + if( ! objMerged ) { + // clone the current histogram + objMerged = objThis->Clone(); + // retrieve metadata + MetaDataMap_t::iterator mdi = mdMap.find(objThis->GetName()); + const MetaData *md(0); + if( mdi != mdMap.end() ) { + md = &(mdi->second); + } + else { + // it could be that we had just been unlucky (on-demand-booking) + // and this histogram was not available in v_dirsStat[0] + // (or the directory for which we created the map last here). + // remake metadatamap + mdMap.clear(); + fillMetaDataMap( mdMap, dir_current ); + mdi = mdMap.find(objThis->GetName()); + if( mdi != mdMap.end() ) { + md = &(mdi->second); + } + } + + if( ! md ) { + std::cerr << name << ": no metadata for " << histFullName << std::endl; + std::cerr << name << ": => using default merging" << std::endl; + } + else { + outputmd.fill( md->name, md->interval, md->chain, md->merge ); + mergeType = md->merge; + } + } + else { + // objMerged already exists, merge with objThis + mergeObjs(objMerged, objThis.get(), mergeType, debugLevel); + } + //delete objThis; + } + + dir_out->cd(); + // write histogram to file and delete it from memory + if( objMerged ) { + objMerged->Write(); + if( debugLevel >= DEBUG ) + std::cout << name << ": wrote " << dir_out->GetPath() << "/" << objMerged->GetName() << std::endl; + delete objMerged; + } + } + // write metadata tree + dir_out->cd(); + mdTree->SetDirectory(dir_out); + mdTree->Write(0, kOverwrite); + delete mdTree; + + } + + return 0; +} + +void MonitoringFile::buildLBToIntervalMap(std::vector<TDirectory*>& v_dirLBs, std::vector<TDirectory*>& v_dirsInterval, map_dir_vdir& m_mapping, debugLevel_t& debugLevel) { + std::vector<std::string> v_splits; + typedef std::vector<std::pair<TDirectory*, std::pair<int, int> > > range_t; + range_t v_ranges; + for (std::vector<TDirectory*>::const_iterator dirit = v_dirsInterval.begin(); + dirit != v_dirsInterval.end(); + ++dirit) { + std::string dirname((*dirit)->GetName()); + std::string corename(dirname.substr(10, std::string::npos)); + boost::split(v_splits, corename, boost::algorithm::is_any_of(std::string("-"))); + if (v_splits.size() != 2) { + std::cerr << "Unable to properly parse " << (*dirit)->GetName() << std::endl; + continue; + } + if( debugLevel >= DEBUG ) std::cout << "Found " << dirname << " " + << v_splits[0] << " " + << v_splits[1] << std::endl; + try { + v_ranges.push_back(std::make_pair(*dirit, std::make_pair(boost::lexical_cast<int>(v_splits[0]), boost::lexical_cast<int>(v_splits[1])))); + } catch (boost::bad_lexical_cast e) { + std::cerr << "Unable to cast to integers: " << v_splits[0] << " " + << v_splits[1] << std::endl; + } + } + for (std::vector<TDirectory*>::const_iterator dirit = v_dirLBs.begin(); + dirit != v_dirLBs.end(); + ++dirit) { + std::string dirname((*dirit)->GetName()); + int lbnum = boost::lexical_cast<int>(dirname.substr(3, std::string::npos)); + for (range_t::const_iterator rangeit = v_ranges.begin(); + rangeit != v_ranges.end(); ++rangeit) { + if ((*rangeit).second.first <= lbnum && + lbnum <= (*rangeit).second.second) { + map_dir_vdir::iterator mapit = m_mapping.find((*rangeit).first); + (*mapit).second.push_back(*dirit); + } + } + } +} + +int MonitoringFile::mergeLB_processLB(std::vector<TDirectory*>& v_dirLBs, std::vector<TDirectory*>& v_dirsInterval, debugLevel_t& debugLevel) { + std::map<TDirectory*,std::vector<TDirectory*> > m_mapping; + for (std::vector<TDirectory*>::const_iterator dirit = v_dirsInterval.begin(); + dirit != v_dirsInterval.end(); ++dirit) { + m_mapping[*dirit] = std::vector<TDirectory*>(); + } + buildLBToIntervalMap(v_dirLBs, v_dirsInterval, m_mapping, debugLevel); + + for (map_dir_vdir::iterator mapit = m_mapping.begin(); + mapit != m_mapping.end(); ++mapit) { + mergeLB_processLBinterval((*mapit).second, (*mapit).first, debugLevel); + } + + return 0; +} + +int MonitoringFile::mergeLB_processRun(TDirectory *dir_run, debugLevel_t& debugLevel) { + // get lists of "lowStat_", "medStat_", "higStat_" subdirectories in dir_run + // call mergeLB_processLBinterval for each of these lists + std::string name("mergeLB_processRun"); + if( ! dir_run ) { + std::cerr << name << ": empty pointer to run directory" << std::endl; + return -1; + } + + if( debugLevel >= DEBUG ) + std::cout << name << ": processing dir " << dir_run->GetName() << std::endl; + + std::vector<TDirectory*> v_dirsLowStat, v_dirsMedStat, v_dirsHigStat, + v_dirsLB; + + TIter next(dir_run->GetListOfKeys()); + TKey *key; + while( ( key=(TKey*) next() ) ) { + std::string keyClassName(key->GetClassName()); + if( (keyClassName.size() > 9) && (keyClassName.substr(0,10) == "TDirectory") ) { + TDirectory *dir = (TDirectory*) dir_run->Get(key->GetName()); + if( !dir ) { + std::cerr << name << ": could not retrieve " << key->GetName() << " from " << dir_run->GetPath() << std::endl; + continue; + } + std::string dirName(dir->GetName()); + if ( dirName.substr(0,3) == "lb_" ) { + v_dirsLB.push_back(dir); + } else if( dirName.size() > 7 ) { + if( dirName.substr(0,8) == "lowStat_" ) { + v_dirsLowStat.push_back(dir); + } + else if( dirName.substr(0,8) == "medStat_" ) { + v_dirsMedStat.push_back(dir); + } + else if( dirName.substr(0,8) == "higStat_" ) { + v_dirsHigStat.push_back(dir); + } + } + } + } + + if( debugLevel >= DEBUG ) std::cout << "\n" << name << ": processing LB directories" << std::endl; + if( v_dirsLB.size() > 0 ) mergeLB_processLB(v_dirsLB, v_dirsLowStat, debugLevel); + + if( debugLevel >= DEBUG ) std::cout << "\n" << name << ": processing lowStat directories" << std::endl; + if( v_dirsLowStat.size() > 0 ) mergeLB_processLBinterval(v_dirsLowStat, dir_run, debugLevel); + + if( debugLevel >= DEBUG ) std::cout << "\n" << name << ": processing medStat directories" << std::endl; + if( v_dirsMedStat.size() > 0 ) mergeLB_processLBinterval(v_dirsMedStat, dir_run, debugLevel); + + if( debugLevel >= DEBUG ) std::cout << "\n" << name << ": processing higStat directories" << std::endl; + if( v_dirsHigStat.size() > 0 ) mergeLB_processLBinterval(v_dirsHigStat, dir_run, debugLevel); + + return 0; +} + +int MonitoringFile::mergeLBintervals(std::string inFilename, std::string inDebugLevel) { + // open merged file, call mergeLB_processRun for each "run_" directory + // in file, close file + std::string name("mergeLBintervals"); + + debugLevel_t debugLevel = none; + if(inDebugLevel.empty()){ + debugLevel=m_debugLevel>(int)VERBOSE?VERBOSE:(debugLevel_t)m_debugLevel; + }else{ + if( inDebugLevel == "DEBUG" ) debugLevel = DEBUG; + else if( inDebugLevel == "VERBOSE" ) debugLevel = VERBOSE; + } + + //TFile &f = *(TFile::Open(inFilename.c_str(), "UPDATE")); // does a copy and leaks memory + TFile *f = (TFile::Open(inFilename.c_str(), "UPDATE",inFilename.c_str(),m_fileCompressionLevel)); + + TIter next(f->GetListOfKeys()); + TKey *key; + while( ( key=(TKey*) next() ) ) { + std::string keyClassName(key->GetClassName()); + if( (keyClassName.size() > 9) && (keyClassName.substr(0,10) == "TDirectory") ) { + TDirectory *dir = (TDirectory*) f->Get(key->GetName()); + if( !dir ) { + std::cerr << name << ": could not retrieve " << key->GetName() + << " from top level directory of " << inFilename << std::endl; + continue; + } + std::string dirName(dir->GetName()); + if( (dirName.size() > 3) && (dirName.substr(0,4) == "run_") ) { + if( debugLevel == DEBUG ) + std::cout << name << ": found run dir " << dirName << std::endl; + // process this run + mergeLB_processRun(dir, debugLevel); + } + } + } + + f->Close(); + return 0; +} + +bool +MonitoringFile:: +CheckHistogram(TFile* f,const char* HistoName) +{ + std::auto_ptr<TObject> obj(f->Get(HistoName)); + if (! obj.get()) { + //std::cerr<<"No such histogram \""<< HistoName << "\"\n"; + return false; + } + else return true; +} + +int MonitoringFile::getDebugLevel(){return m_debugLevel;} +void MonitoringFile::setDebugLevel(int level){m_debugLevel=level;} +int MonitoringFile::m_fileCompressionLevel=1; +int MonitoringFile::m_debugLevel=0; + +std::string MonitoringFile::getPath(TDirectory *dir){ + + std::string path = dir->GetPath(); + if ( path.find(':') != std::string::npos ) + path = path.substr(path.rfind(':')+1); + + return path; +} + +} // namespace dqutils + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_BJetTaggingAdjustRanges.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_BJetTaggingAdjustRanges.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c1cde8fe42ba1ea26103686ea766115530d2f704 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_BJetTaggingAdjustRanges.cxx @@ -0,0 +1,172 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* Methods to perform post-processing on run_nnnnnn/HLT/JetMon* histograms + * Mainly to adjust the impact parameter ranges according to the recorded lumi blocks. + * + * + * + * Based on the HLTJetCalcEfficiencyAndRate code of Venkatesh Kaushik (venkat.kaushik@cern.ch). + * + * Author : Manuel Neumann (mneumann@cern.ch) + * Date : Aug 2011 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <vector> + +#include "TH1F.h" +#include "TFile.h" +#include "TKey.h" + +namespace dqutils +{ + + void + MonitoringFile::BJetTaggingAdjustRanges(TFile* f) { + + int debugLevel = MonitoringFile::getDebugLevel(); + + if (debugLevel > 1) { + std::cout << "--> BJetTaggingAdjustRanges: Adjusting ranges of d0, z0 and d0Sig, z0Sig" + << std::endl; + + } + f->cd("/"); + // get run directory name + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*) nextcd0(); + TDirectory *dir0 = dynamic_cast<TDirectory*> (key0->ReadObj()); + + if (dir0 != 0) { + dir0->cd(); + + TIter next_run(f->GetListOfKeys()); + TKey* key_run(0); + + // loop through runs in the file + while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) { + if (debugLevel > 1) { + std::cout << "--> BJetTaggingAdjustRanges: Getting run " << key_run << std::endl; + } + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*> (obj_run); + + // Some checks of the run number + if (tdir_run != 0) { + //if (debugLevel > 0) { + // std::cerr << "--> BJetTaggingAdjustRanges: directory " << tdir_run + // << " not found." << std::endl; + //} + //continue; + //delete obj_run; + + TString run_dir = tdir_run->GetName(); + if (!run_dir.Contains("run")) { + std::cerr << "--> BJetTaggingAdjustRanges: no run found" << std::endl; + return; + //delete obj_run; + } + + if (debugLevel > 1) { + std::cout << "--> BJetTaggingAdjustRanges: Getting run no. " << run_dir + << std::endl; + } + + // Setting the branch for the impact parameters + TString jetmon_dir = run_dir + "/JetTagging"; + + TDirectory* dir(0); + //std::cout << "--> BJetTaggingAdjustRanges: directory " << diag_dir + // << std::endl; + + if (!(dir = f->GetDirectory(jetmon_dir))) { + if (debugLevel > 0) + std::cerr << "--> BJetTaggingAdjustRanges: directory " << jetmon_dir + << " not found." << std::endl; + return; + } + // std::cout << "--> BJetTaggingAdjustRanges: Setting d0,z0,d0Sig,z0Sig vectors" << std::endl; + std::vector < TString > impactParameters; + impactParameters.push_back("d0Sig"); + impactParameters.push_back("z0Sig"); + + impactParameters.push_back("d0"); + impactParameters.push_back("z0"); + + std::vector < TString > etaAndPtRanges; + etaAndPtRanges.push_back("_EtaRange_0_PtRange_0"); + etaAndPtRanges.push_back("_EtaRange_0_PtRange_1"); + etaAndPtRanges.push_back("_EtaRange_0_PtRange_2"); + etaAndPtRanges.push_back("_EtaRange_1_PtRange_0"); + etaAndPtRanges.push_back("_EtaRange_1_PtRange_1"); + etaAndPtRanges.push_back("_EtaRange_1_PtRange_2"); + etaAndPtRanges.push_back("_EtaRange_2_PtRange_0"); + etaAndPtRanges.push_back("_EtaRange_2_PtRange_1"); + etaAndPtRanges.push_back("_EtaRange_2_PtRange_2"); + etaAndPtRanges.push_back("_EtaRange_3_PtRange_0"); + etaAndPtRanges.push_back("_EtaRange_3_PtRange_1"); + etaAndPtRanges.push_back("_EtaRange_3_PtRange_2"); + etaAndPtRanges.push_back("_EtaRange_4_PtRange_0"); + etaAndPtRanges.push_back("_EtaRange_4_PtRange_1"); + etaAndPtRanges.push_back("_EtaRange_4_PtRange_2"); + + TH1F* workingHistogram(0); + + TString impactParameterHistos, workingHistogramName; + + for (std::vector<TString>::iterator itT = impactParameters.begin(); itT + != impactParameters.end(); ++itT) { + for (std::vector<TString>::iterator itO = etaAndPtRanges.begin(); itO + != etaAndPtRanges.end(); ++itO) { + + workingHistogramName = (*itT) + (*itO); + impactParameterHistos = jetmon_dir + "/" + workingHistogramName; + + workingHistogram = dynamic_cast<TH1F*> (f->Get(impactParameterHistos)); + if (workingHistogram != 0) { + + if (debugLevel > 1) { + //std::cout << "--> BJetTaggingAdjustRanges: Really doing this stuff" << workingHistogramName<<std::endl; + } + + /* + * Here the bins are initialised and the upper and lower end from the histogram data + * are used as new borders of the updated histogram. + * */ + + int minimalBin = 0; + int maximalBin = 0; + + minimalBin = workingHistogram->FindFirstBinAbove(0.0, 1); + maximalBin = workingHistogram->FindLastBinAbove(0.0, 1); + + workingHistogram->SetAxisRange(TMath::Max(1, (minimalBin - 5)), + (maximalBin + 5), "X"); + + dir->cd(); + workingHistogram->Write("", TObject::kOverwrite); + + } + else { + if (debugLevel > 0) { + std::cerr << "Histogram " << impactParameterHistos << " not found." + << std::endl; + } + + } + + } // for eta/Pt range + } // for TrigItems + if (debugLevel > 1) { + std::cout << "--> BJetTaggingAdjustRanges: Finished" << std::endl; + } + } + } // if tdir_run!=0 + }//while + }//MonitoringFile::BJetTaggingAdjustRanges + + +}//namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_BJetTaggingNormalise.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_BJetTaggingNormalise.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6d8265da011e87cdfae9f8a0bcf79a9cacfe9c76 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_BJetTaggingNormalise.cxx @@ -0,0 +1,223 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* Methods to perform post-processing on "run_nnnnnn/JetTagging/ *2D" histograms + * Mainly to normalise the z axis range to the total number of tracks/jets. + * + * + * + * Based on the HLTJetCalcEfficiencyAndRate code of Venkatesh Kaushik (venkat.kaushik@cern.ch). + * + * Author : Manuel Neumann (mneumann@cern.ch) + * Date : Aug 2011 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <vector> + +#include "TH2F.h" +#include "TFile.h" +#include "TKey.h" + +namespace dqutils{ + + void MonitoringFile::BJetTaggingNormalise(TFile* f) { + + int debugLevel = MonitoringFile::getDebugLevel(); + + if (debugLevel > 1) { + std::cout << "--> BJetTaggingNormalise: Adjusting ranges of d0, z0 and d0Sig, z0Sig" + << std::endl; + } + + f->cd("/"); + // get run directory name + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*) nextcd0(); + + TDirectory *dir0 = dynamic_cast<TDirectory*> (key0->ReadObj()); + if (dir0 != 0) { + + dir0->cd(); + + TIter next_run(f->GetListOfKeys()); + TKey* key_run(0); + + // loop through the runs + while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) { + if (debugLevel > 1) { + std::cout << "--> BJetTaggingNormalise: Getting run " << key_run << std::endl; + } + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*> (obj_run); + + // Some checks of the run number + if (tdir_run != 0) { + //std::cerr << "--> BJetTaggingNormalise: directory " << tdir_run << " not found." + // << std::endl; + //return; + //} + + TString run_dir = tdir_run->GetName(); + if (!run_dir.Contains("run")) { + + std::cerr << "--> BJetTaggingNormalise: no run found" << std::endl; + return; + + } + if (debugLevel > 1) { + std::cout << "--> BJetTaggingNormalise: Getting run no. " << run_dir << std::endl; + } + + // Setting the branch for JetTagging + TString diag_dir = run_dir + "/JetTagging"; + + TDirectory* dir(0); + if (debugLevel > 1) { + std::cout << "--> BJetTaggingNormalise: directory " << diag_dir << std::endl; + } + if (!(dir = f->GetDirectory(diag_dir))) { + std::cerr << "--> BJetTaggingNormalise: directory " << diag_dir << " not found." + << std::endl; + return; + } + if (debugLevel > 1) { + std::cout << "--> BJetTaggingNormalise: Setting the to process histgrams" + << std::endl; + } + std::vector < TString > nomHistosNames; + std::vector < TString > denHistosNames; + + nomHistosNames.push_back("track_selector_eff"); + nomHistosNames.push_back("jet_2D_kinematic"); + + nomHistosNames.push_back("ip3d_tag_def_rate_2D"); + //nomHistosNames.push_back("ip2d_tag_pos_rate_2D"); + nomHistosNames.push_back("ip3d_tag_neg_rate_2D"); + nomHistosNames.push_back("ip3d_tag_pos_rate_2D"); + //nomHistosNames.push_back("sv1_tag_neg_rate_2D"); + //nomHistosNames.push_back("sv1_tag_pos_rate_2D"); + //nomHistosNames.push_back("sv2_tag_neg_rate_2D"); + //nomHistosNames.push_back("sv2_tag_pos_rate_2D"); + + nomHistosNames.push_back("tracks_pTMin_2D"); + nomHistosNames.push_back("tracks_d0Max_2D"); + nomHistosNames.push_back("tracks_z0Max_2D"); + nomHistosNames.push_back("tracks_sigd0Max_2D"); + nomHistosNames.push_back("tracks_sigz0Max_2D"); + nomHistosNames.push_back("tracks_etaMax_2D"); + nomHistosNames.push_back("tracks_nHitBLayer_2D"); + nomHistosNames.push_back("tracks_deadBLayer_2D"); + nomHistosNames.push_back("tracks_nHitPix_2D"); + nomHistosNames.push_back("tracks_nHitSct_2D"); + nomHistosNames.push_back("tracks_nHitSi_2D"); + nomHistosNames.push_back("tracks_nHitTrt_2D"); + nomHistosNames.push_back("tracks_nHitTrtHighE_2D"); + nomHistosNames.push_back("tracks_fitChi2_2D"); + nomHistosNames.push_back("tracks_fitProb_2D"); + nomHistosNames.push_back("tracks_fitChi2OnNdfMax_2D"); + + denHistosNames.push_back("track_selector_all"); + denHistosNames.push_back("jet_2D_all"); + denHistosNames.push_back("jet_2D_all"); + denHistosNames.push_back("jet_2D_all"); + denHistosNames.push_back("jet_2D_all"); + + //denHistosNames.push_back("track_selector_all"); + //denHistosNames.push_back("track_selector_all"); + //denHistosNames.push_back("track_selector_all"); + //denHistosNames.push_back("track_selector_all"); + //denHistosNames.push_back("track_selector_all"); + //denHistosNames.push_back("track_selector_all"); + //denHistosNames.push_back("track_selector_all"); + //denHistosNames.push_back("track_selector_all"); + + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + denHistosNames.push_back("tracks_all_2D"); + + TH2F* workingHistogramNom(0); + TH2F* workingHistogramDen(0); + + TString nomHistos, workingHistogramNameNom; + TString denHistos, workingHistogramNameDen; + + for (unsigned int i = 0; i < nomHistosNames.size(); i++) { + + workingHistogramNameNom = (nomHistosNames[i]); + workingHistogramNameDen = (denHistosNames[i]); + nomHistos = diag_dir + "/" + workingHistogramNameNom; + denHistos = diag_dir + "/" + workingHistogramNameDen; + //std::cout << "--> BJetTaggingNormalise: histogram " << nomHistos << std::endl; + + + // std::cout << "--> BJetTaggingNormalise: Doing the normalisation" << std::endl; + if (!f->Get(nomHistos)) { + if (debugLevel > 0) { + std::cerr << "--> BBJetTaggingNormalise: no such histogram " << nomHistos + << std::endl; + } + continue; + } + if (!f->Get(denHistos)) { + if (debugLevel > 0) { + std::cerr << "--> BJetTaggingNormalise: no such histogram " << denHistos + << std::endl; + } + continue; + + } + + workingHistogramNom = dynamic_cast<TH2F*> (f->Get(nomHistos)); + workingHistogramDen = dynamic_cast<TH2F*> (f->Get(denHistos)); + + if (workingHistogramNom == 0 || workingHistogramDen == 0) { + continue; + } + + /* + * Here the bins are initialised and the upper and lower end from the histogram data + * are used as new borders of the updated histogram. + * */ + + { + if (debugLevel > 1) { + std::cout << nomHistos << "/" << denHistos << " integral before " + << workingHistogramNom->Integral() << std::endl; + } + workingHistogramNom->Divide(workingHistogramDen); + + if (debugLevel > 1) { + std::cout << "integral after " << workingHistogramNom->Integral() << std::endl; + } + } + dir->cd(); + workingHistogramNom->Write("", TObject::kOverwrite); + + // for eta/Pt range + } + if (debugLevel > 1) { + std::cout << "--> BJetTaggingNormalise: Finished" << std::endl; + } + }//tdir_run != 0 + }//while + }//MonitoringFile::BJetTaggingNormalise + } + +}//namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_BJetTaggingPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_BJetTaggingPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..14a85100984ecc281e33ff833bb88ad6f573b0ea --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_BJetTaggingPostProcess.cxx @@ -0,0 +1,92 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* Methods to perform post-processing on run_nnnnnn/HLT/JetMon* histograms + * Mainly to adjust the impact parameter ranges according to the recorded lumi blocks. + * This file does a check of existing input and the calls the actual adjustment. + * + * + * + * + * #################### + * #Notes on debugLevel# + * #################### + * - At all debugLevels > 0 errors will be displayed + * - At debugLevels > 1 hints to the process flow will be shown + * #################### + * + * + * + * + * + * Author : Manuel Neumann (mneumann@cern.ch) + * Date : Aug 2011 + * + * Based on the code of: + * Methods to perform post-processing on run_nnnnnn/HLT/METMon* histograms + * Author : Venkatesh Kaushik (venkat.kaushik@cern.ch) + * Date : Feb 2010 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include "TFile.h" + +namespace dqutils +{ + + void + MonitoringFile::BJetTaggingPostProcess(std::string inFilename, bool isIncremental) { + + if (isIncremental == true) { + return; + } + + int debugLevel = MonitoringFile::getDebugLevel(); + if (debugLevel > 1) { + std::cout << "--> JetTaggingPostProcess: Begin JetTagging post-processing" << std::endl; + } + //open root file + TFile* f = TFile::Open(inFilename.c_str(), "UPDATE"); + + //check files are loaded. + if (f == 0 || !f->IsOpen()) { + std::cerr << "--> BJetTaggingPostProcess: Input file not opened" << std::endl; + return; + } + + if (f->IsZombie()) { + std::cerr << "--> BJetTaggingPostProcess: Input file " << inFilename + << " cannot be opened. " << std::endl; + return; + } + + //check file size is not too small. + if (f->GetSize() < 1000.) { + std::cerr << "--> BJetTaggingPostProcess: Input file empty" << std::endl; + f->Close(); + return; + } + + //start postprocessing + + //here impact parameter histograms get a range in which they are actually filled + BJetTaggingAdjustRanges(f); + + //this will normalise some 2D histograms to the track/jet number + BJetTaggingNormalise(f); + + //close root file + f->Close(); + //delete f; + + if (debugLevel > 1) { + std::cout << "--> BJetTaggingPostProcess: End JetTagging post-processing " << std::endl; + } + return; + + } + +}//namespace + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_CSCChamberEfficiency.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_CSCChamberEfficiency.cxx new file mode 100644 index 0000000000000000000000000000000000000000..44380fd7af8149e5282eb268b143672172bef34f --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_CSCChamberEfficiency.cxx @@ -0,0 +1,185 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* Methods to perform post-processing on run_nnnnnn/Muon/MuonSegmMonitoring/EndCapN/Detail/<Collection>/CSC* histograms + * Author : Jason Veatch (jason.veatch@cern.ch) + * Venkatesh Kaushik (venkat.kaushik@cern.ch) + * Date : March 2011 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + +namespace dqutils { + + void + MonitoringFile::CSCChamberEfficiency(TFile* f, TString& run_dir) { + + bool dbgLevel = false; + if(dbgLevel) std::cout << "--> CSCChamberEfficiency: Calculate chamber efficiency by layer" << std::endl; + std::string endc_label[2] = {"A","C"}; + std::string coll_dir_label[2] = {"ConvertedMBoySegments","MooreSegments"}; + std::string coll_hist_label[2] = {"MuBoy","Moore"}; + + f->cd("/"); + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + run_dir = key_run->GetName(); + if (!run_dir.Contains("run") ) { continue;} + + std::string run_dir2 = run_dir.Data(); + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + for(std::size_t iec = 0; iec < 2; iec++){ + for(std::size_t icoll = 0; icoll < 2; icoll++){ + + TString csc_dir = run_dir + "/Muon/MuonSegmentMonitoring/EndCap" + endc_label[iec]; + + //===CSC detail directory + TString detail_dir = csc_dir + "/Detail/" + coll_dir_label[icoll] + "/CSC"; + + //===CSC overview directory + TString oview_dir = csc_dir + "/Overview/" + coll_dir_label[icoll] + "/CSC"; + + TDirectory* dir(0); + + if( !(f->GetDirectory(detail_dir)) ) { + std::cerr << "--> CSCChamberEfficiency: directory " << detail_dir << " not found." << std::endl; + return; + } + + if( !(dir = f->GetDirectory(oview_dir)) ) { + std::cerr << "--> CSCChamberEfficiency: directory " << oview_dir << " not found." << std::endl; + return; + } + + //===CSC NClus segment histogram + TString nclust_histo = detail_dir + "/" + coll_hist_label[icoll] + "_Segm_NumNClusSegments_E" + endc_label[iec]; + + //===CSC efficiency histogram + TString eff_histo = oview_dir + "/" + coll_hist_label[icoll] + "_Segm_Efficiency_E" + endc_label[iec]; + + if( ! f->Get(nclust_histo) ){ + if(dbgLevel) std::cerr << "--> CSCChamberEfficiency: no such histogram " << nclust_histo << std::endl; + return; + } + + if( ! f->Get(eff_histo) ){ + if(dbgLevel) std::cerr << "--> CSCChamberEfficiency: no such histogram " << eff_histo << std::endl; + return; + } + + TH2F *h2 = (TH2F *) f->Get(nclust_histo); + TH1F *h1_eff = (TH1F *) f->Get(eff_histo); + + for(int layer = 1; layer < 5; layer++){ + + if(iec == 0){ // Endcap A + for(int chamber = 1; chamber < 17; chamber++){ + + float num = h2->GetBinContent(46,1+5*chamber); + float num_err = h2->GetBinError(46,1+5*chamber); + + float den = h2->GetBinContent(10*layer-4,1+5*chamber); + float den_err = h2->GetBinError(10*layer-4,1+5*chamber); + + float eff = 0., err = 0.; + + GetCscEffAndErr(num,num_err,den,den_err,eff,err,0); + h1_eff->SetBinContent(5*chamber+layer-4,eff); + h1_eff->SetBinError(5*chamber+layer-4,err); + } // for loop over bins + } else { // Endcap C + for(int chamber = 1; chamber < 17; chamber++){ + float num = h2->GetBinContent(46,86-5*chamber); + float num_err = h2->GetBinError(46,86-5*chamber); + + float den = h2->GetBinContent(10*layer-4,86-5*chamber); + float den_err = h2->GetBinError(10*layer-4,86-5*chamber); + + float eff = 0., err = 0.; + GetCscEffAndErr(num,num_err,den,den_err,eff,err,0); + h1_eff->SetBinContent(90-layer-5*chamber,eff); + h1_eff->SetBinError(90-layer-5*chamber,err); + } // for loop over bins + } // Endcap C + } // for layers + + //h1_eff->Sumw2(); + + dir->cd(); + h1_eff->Write("",TObject::kOverwrite); + + } // for icolls + } // for iecs + }//while + }//MonitoringFile::CSCChamberEfficiency + + // ------------------------------------------------------------------------------------------------------- + // Compute bin errors a la Ullrich, Paterno and Xu (UPX) variance + // http://arxiv.org/abs/physics/0701199 + // Alternative to "Binomial" variance used by TH1::Divide option "B" + // ------------------------------------------------------------------------------------------------------- + void MonitoringFile::GetCscEffAndErr(float& num, float& num_err, + float& den, float& den_err, float& eff, float& err, int errtype ) { + + // 0 - binomial + // 1 - UPX variance + int binerr = 0; + if(errtype == 1) binerr = errtype; + float epsilon = 1.e-3; + + if (den < epsilon) { eff = 0.; err = 0.; return; } + if(num<(-1.*epsilon)||den<epsilon){ + if(MonitoringFile::getDebugLevel()>0)std::cerr << "--> getCscEffAndErr : ERROR: found negative entries" << num << "\t " << den << std::endl; + return; + } + + // quotient + eff = num/den; + + // error + if(binerr == 1) { + // UPX variance + float num1 = (num+1)*(num+2); + float den1 = (den+2)*(den+3); + float num2 = (num+1)*(num+1); + float den2 = (den+2)*(den+2); + float variance = num1/den1 - num2/den2; + err = sqrt(variance); + } else if(binerr == 0) { + // Binomial error + err = fabs( ( (1.-2.*eff)*num_err*num_err + eff*eff*den_err*den_err )/(den*den) ); + } else { + // Sumw2 error + err = (num_err*num_err*den*den + den_err*den_err*num*num)/(den*den); + } + + } + +}//namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_CSCClusterFit.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_CSCClusterFit.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e42d914429126baa768ddfa6da9de020e1c00de8 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_CSCClusterFit.cxx @@ -0,0 +1,150 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* Methods to perform post-processing on run_nnnnnn/Muon/MuonRawDataMonitoring/CSC/CSCE[AC]/Overview/lfitmean histograms + * Venkatesh Kaushik (venkat.kaushik@cern.ch) + * Date : March 2011 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + +namespace dqutils { + + void + MonitoringFile::CSCClusterFit(TFile* f, TString& run_dir) { + + bool dbgLevel = false; + if(dbgLevel) std::cout << "--> CSCClusterFit: Landau fit to cluster qsum per layer" << std::endl; + + std::vector<std::string> endc_label; + endc_label.push_back("A"); + endc_label.push_back("C"); + + std::vector<std::string> coll_dir_label; + //coll_dir_label.push_back("ConvertedMBoySegments"); + coll_dir_label.push_back("MooreSegments"); + + std::vector<std::string> coll_hist_label; + //coll_hist_label.push_back("MuBoy"); + coll_hist_label.push_back("Moore"); + + f->cd("/"); + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + run_dir = key_run->GetName(); + if (!run_dir.Contains("run") ) { continue;} + + std::string run_dir2 = run_dir.Data(); + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + for(std::size_t iec = 0; iec < endc_label.size(); iec++){ + for(std::size_t icoll = 0; icoll < coll_dir_label.size(); icoll++){ + + TString csc_segmdir = run_dir + "/Muon/MuonSegmentMonitoring/EndCap" + endc_label.at(iec); + TString csc_rawdir = run_dir + "/Muon/MuonRawDataMonitoring/CSC/Overview/CSCE" + endc_label.at(iec) ; + + //===CSC segment overview directory + TString oview_dir = csc_segmdir + "/Overview/" + coll_dir_label.at(icoll) + "/CSC"; + + //===CSC cluster directory + TString csc_clusdir = csc_rawdir + "/Cluster"; + + TDirectory *dir(0); + + if( !(f->GetDirectory(oview_dir)) ) { + std::cerr << "--> CSCClusterFit: directory " << oview_dir << " not found." << std::endl; + return; + } + + if( !(dir = f->GetDirectory(csc_clusdir)) ) { + std::cerr << "--> CSCClusterFit: directory " << oview_dir << " not found." << std::endl; + return; + } + + //===CSC etaClusQSum on segment histogram + TString etaClusQsumHist = oview_dir + "/" + coll_hist_label.at(icoll) + "_Segm_QSumEtaGoodClusPerLayer_E" + endc_label.at(iec); + + //===CSC MPV landau fit per layer histogram + TString lfitMPVHist = csc_clusdir + "/h1csc_clus_qsum_signal_E" + endc_label.at(iec) + "_lfitmean"; + + if( ! f->Get(etaClusQsumHist) ){ + if(dbgLevel) std::cerr << "--> CSCClusterFit: no such histogram " << etaClusQsumHist << std::endl; + return; + } + + if( ! f->Get(lfitMPVHist) ){ + if(dbgLevel) std::cerr << "--> CSCClusterFit: no such histogram " << lfitMPVHist << std::endl; + return; + } + + TH2F *h2 = (TH2F *) f->Get(etaClusQsumHist); + TH1F *h1 = (TH1F *) f->Get(lfitMPVHist); + TH1F *hl(0); TF1 *fl1(0); + int sec = 0; + float mpv = 0, mpv_err = 0; + for(int j = 5; j<=85; j++) { + if (j%5 == 0) { + sec++; + } else { + mpv = 0; mpv_err = 0; + hl = (TH1F *) h2->ProjectionX("_px",j,j); + if(hl) { + hl->SetDirectory(0); + int fit_status = 0; + float flmin = 50, flmax = 700; // fixed range + int entries = hl->GetEntries(); + if(entries > 10) { + if(!fl1) fl1 = new TF1("fland","landau",flmin,flmax); + fit_status = hl->Fit(fl1,"LRQN", "goff"); // log-Likelihood, iMprove, Range, Quiet, No-draw + if(fit_status == 0) { + mpv = fl1->GetParameter(1); // 1 = MPV, 2 = sigma, 0 = Norm + mpv_err = fl1->GetParError(1); // 1 = MPV, 2 = sigma, 0 = Norm + } + } + } // hl + h1->SetBinContent(j,mpv); + h1->SetBinError(j,mpv_err); + } // else + } // j + + // clean up + if(hl) { delete hl; hl = 0; } + if(fl1) { delete fl1; fl1 = 0; } + + if(dir) { + dir->cd(); + h1->Write("",TObject::kOverwrite); + } + + } // for icolls + } // for iecs + }//while + }//MonitoringFile::CSCClusterFit + +}//namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_CSCPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_CSCPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f218f4dfb38ccedd3163a8440a3b4d99a4c7b8db --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_CSCPostProcess.cxx @@ -0,0 +1,82 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* Methods to perform post-processing on run_nnnnnn/Muon/MuonSegmentMonitoring/EndCapN/Detail/<Collection>/CSC* histograms + * Author : Jason Veatch (jason.veatch@cern.ch) + * Date : March 2011 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + + + +namespace dqutils { + + static const bool csc_debug = false; + + void + MonitoringFile::CSCPostProcess( std::string inFilename, bool /* isIncremental */ ) + { + if(csc_debug) std::cout << "--> CSCPostProcess: Begin CSC post-processing" << std::endl; + + //open root file + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + //check files are loaded. + + if (f == 0 || ! f->IsOpen() ) { + std::cerr << "--> CSCPostProcess: Input file not opened" << std::endl; + return; + } + + if(f->IsZombie()) { + std::cerr << "--> CSCPostProcess: Input file " << inFilename << " cannot be opened. " << std::endl; + return; + } + + //check file size is not too small. + if(f->GetSize()<1000.) { + std::cerr << "--> CSCPostProcess: Input file empty" << std::endl; + f->Close(); + return; + } + + //start postprocessing + TString run_dir; + CSCChamberEfficiency( f, run_dir); + CSCClusterFit( f, run_dir); + //close root file + f->Close(); + delete f; + + if(csc_debug) std::cout << "--> CSCPostProcess: End CSC post-processing "<<std::endl; + + return; + + } + +}//namespace + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_DiMuPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_DiMuPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..efd4e4387ee26d7abe687dd61303c0fff8a532ee --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_DiMuPostProcess.cxx @@ -0,0 +1,326 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <cmath> +#include <vector> +#include <sstream> + +#include <TCanvas.h> +#include <TF1.h> +#include <TFile.h> +#include <TH1.h> +#include <TH2.h> +#include <TKey.h> +#include <TMath.h> +#include <TProfile.h> +#include <TTree.h> +#include <TROOT.h> + +#include "RooRealVar.h" +#include "RooDataHist.h" +#include "RooArgList.h" +#include "RooPlot.h" +#include "RooBreitWigner.h" +#include "RooCBShape.h" +#include "RooFFTConvPdf.h" +#include "RooGlobalFunc.h" +#include "RooPlot.h" + +namespace dqutils { + +void +MonitoringFile:: +fitMergedFile_DiMuMonManager( std::string inFilename, bool isIncremental) +{ //adapted from MonitoringFile_IDPerfPostProcess.cxx + + if (isIncremental==true) return; + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + if (f == 0 || ! f->IsOpen()) { + //std::cout<<"Failed to load or open file!"<<endl; + delete f; + return; + } + if(f->GetSize()<1000.) { + //std::cout<<"File is empty!"<<endl; + delete f; + return; + } + std::string run_dir; + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*>( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if (tdir_run !=0 ) { + std::string tdir_run_name( tdir_run->GetName() ); + if (tdir_run_name.find("run")!= std::string::npos ) { + run_dir=tdir_run_name; + TIter next_perf(tdir_run->GetListOfKeys()); + TKey* key_perf(0); + while ((key_perf=dynamic_cast<TKey*>( next_perf() ))!=0 ) { + std::string perf_name(key_perf->GetName()); + if (perf_name.find("DiMuMon")!=std::string::npos){ + TObject* obj_perf = key_perf->ReadObj(); + TDirectory* tdir_perf = dynamic_cast<TDirectory*>( obj_perf ); + if (tdir_perf !=0) { + run_dir=run_dir+'/'; + TIter next_module(tdir_perf->GetListOfKeys()); + TKey* key_module(0); + while ((key_module=dynamic_cast<TKey*>(next_module() )) !=0) { + std::string module_name(key_module->GetName()); + if (module_name.find("Jpsi")!=std::string::npos) { + processModule(f, run_dir, key_module,"Jpsi"); + } else if (module_name.find("Zmumu")!=std::string::npos) { + processModule(f, run_dir, key_module,"Zmumu"); + } + } + } else { + delete obj_perf; + } + } + } + } + + // if without top run_directory + else if (tdir_run_name.find("DiMuMon")!= std::string::npos ) { + TObject* obj_perf = key_run->ReadObj(); + TDirectory* tdir_perf = dynamic_cast<TDirectory*>( obj_perf ); + if (tdir_perf !=0) { + run_dir='/'; + TIter next_module(tdir_perf->GetListOfKeys()); + TKey* key_module(0); + while ((key_module=dynamic_cast<TKey*>(next_module() )) !=0) { + std::string module_name(key_module->GetName()); + if (module_name.find("Jpsi")!=std::string::npos) { + processModule(f, run_dir, key_module,"Jpsi"); + } else if (module_name.find("Zmumu")!=std::string::npos) { + processModule(f, run_dir, key_module,"Zmumu"); + } + } + } else { + delete obj_perf; + } + } + } else { + delete obj_run; + } + } + + f->Close(); + delete f; + // if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "DiMuPostProcessing done!" <<endreq; +} + +void MonitoringFile::processModule( TFile* f, std::string run_dir, TKey* key_module, std::string moduleName){ + TObject *obj_mod = key_module->ReadObj(); + TDirectory *tdir_mod = dynamic_cast<TDirectory*>(obj_mod); + if ( tdir_mod !=0 ) { + TIter next_trigger(tdir_mod->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string triggerName=key_trigger->GetName(); + fitMergedFile_DiMuMonAll( f,run_dir,moduleName,triggerName ); + } + } else { + delete obj_mod; + } +} + + +void +MonitoringFile:: +fitMergedFile_DiMuMonAll( TFile* f, std::string run_dir, std::string resonName, std::string triggerName ) +{ + //std::cout<<"fitMergedFile_DiMuMon has been called"<<endl; + std::string path; + path= run_dir+"DiMuMon/"+resonName+"/"+triggerName; + + if( f->cd(path.c_str())==0 ) { + return; + } + std::vector<std::string> regions; + regions.push_back("All"); + regions.push_back("BB"); + regions.push_back("EAEA"); + regions.push_back("ECEC"); + std::vector<std::string> vars; + vars.push_back("eta"); + vars.push_back("etaAll"); + vars.push_back("etaPos"); + vars.push_back("etaNeg"); + vars.push_back("phi"); + vars.push_back("phiAll"); + vars.push_back("phiPos"); + vars.push_back("phiNeg"); + vars.push_back("pt"); + vars.push_back("ptAll"); + vars.push_back("ptPos"); + vars.push_back("ptNeg"); + vars.push_back("etaDiff"); + vars.push_back("etaSumm"); + vars.push_back("phiDiff"); + vars.push_back("phiSumm"); + vars.push_back("crtDiff"); + + std::map< std::string, TH1D* > m_invmass; + std::map< std::string, std::map< std::string, TH2D*> > m_2DinvmassVSx; + std::map< std::string, std::map< std::string, TH1D*> > m_invmassVSx; + std::map< std::string, std::map< std::string, TH1D*> > m_widthVSx; + TH1D* m_chi2; + + //loop over all possible 2D histos + //check if 2D histo has been filled + //if found the 2D histo, then see whether the mean or width or both 1D histos were also made.-->Decide what to refit ` + if (CheckHistogram(f,(path+"_detail/chi2").c_str())) { + m_chi2 = (TH1D*)(f->Get((path+"_detail/chi2").c_str())->Clone()); + std::vector<std::string> ::iterator ivar = vars.begin(); + std::vector<std::string> ::iterator ireg = regions.begin(); + for (ireg=regions.begin(); ireg!=regions.end(); ireg++) { + for (ivar=vars.begin(); ivar!=vars.end(); ivar++) { + std::string hname2D = resonName + "_2DinvmassVS" + *ivar + "_" + *ireg; + if (CheckHistogram(f,(path+"/"+hname2D).c_str())) { + m_2DinvmassVSx[*ireg][*ivar] = (TH2D*)(f->Get((path+"/"+hname2D).c_str())->Clone()); + std::string hnameMean = resonName + "_invmassVS" + *ivar + "_" + *ireg; + std::string hnameWidth = resonName + "_widthVS" + *ivar + "_" + *ireg; + std::vector<TH1D*> hfitted; + if (CheckHistogram(f,(path+"/"+hnameMean).c_str())) { + m_invmassVSx[*ireg][*ivar] = (TH1D*)(f->Get((path+"/"+hnameMean).c_str())->Clone()); + hfitted.push_back(m_invmassVSx[*ireg][*ivar] ); + if (CheckHistogram(f,(path+"_detail/"+hnameWidth).c_str())) { + m_widthVSx[*ireg][*ivar] = (TH1D*)(f->Get((path+"_detail/"+hnameWidth).c_str())->Clone()); + hfitted.push_back(m_widthVSx[*ireg][*ivar] ); + fitHistos(m_2DinvmassVSx[*ireg][*ivar], hfitted, 0, triggerName, resonName, m_chi2);// 0 means to fill both mean and width results from the fit + f->cd((path+"/").c_str()); + m_invmassVSx[*ireg][*ivar]->Write("",TObject::kOverwrite); + f->cd((path+"_detail/").c_str()); + m_widthVSx[*ireg][*ivar]->Write("",TObject::kOverwrite); + } else { + fitHistos(m_2DinvmassVSx[*ireg][*ivar], hfitted, 1, triggerName, resonName, m_chi2);// 1 means to fill only mean results from the fit + f->cd((path+"/").c_str()); + m_invmassVSx[*ireg][*ivar]->Write("",TObject::kOverwrite); + } + } else { + if (CheckHistogram(f,(path+"_detail/"+hnameWidth).c_str())) { + m_widthVSx[*ireg][*ivar] = (TH1D*)(f->Get((path+"_detail/"+hnameWidth).c_str())->Clone()); + hfitted.push_back(m_widthVSx[*ireg][*ivar] ); + fitHistos(m_2DinvmassVSx[*ireg][*ivar], hfitted, 2, triggerName, resonName, m_chi2);// 2 means to fill only width results from the fit + f->cd((path+"_detail/").c_str()); + m_widthVSx[*ireg][*ivar]->Write((path+"_detail/"+hnameWidth).c_str(),TObject::kOverwrite); + } + } + + + } + + } + } + m_chi2->Write("",TObject::kOverwrite); + } + f->Write(); +} + +void MonitoringFile::fitHistos (TH2D* hin, std::vector<TH1D*> hout, int mode, std::string triggerName, std::string resonName, TH1D* m_chi2){ + bool saveHistos = false; + // a canvas may be needed when implmenting this into the post-processing file + //std::cout<<"The fitHistos method is called"<<endl; + std::string hname = hin->GetName(); + TCanvas* ctemp; + char num2str[50]; + int nbins=hin->GetNbinsX(); + for (int i=0; i<nbins;i++){ + snprintf(num2str,50,"%s_%i",(hname).c_str(),i); + TH1D* htemp = (TH1D*) (hin->ProjectionY(num2str,i+1,i+1)); + //htemp->SetTitle(projName); + htemp->Sumw2(); + if (htemp->GetEntries()>50){ + double mean = 999., meanErr = 999., sigma = 999., sigmaErr = 999., chi2 = 0.; + if (resonName == "Jpsi" || resonName == "Upsi"){ + mean = htemp->GetMean(); + sigma= htemp->GetRMS(); + TF1* fn = new TF1("fn","gaus",mean-2*sigma,mean+2*sigma); + fn->SetParameters(htemp->GetEntries()/4,mean,sigma); + htemp->Fit("fn","RQMN"); + mean = fn->GetParameter(1); + sigma= fn->GetParameter(2); + fn->SetRange(mean-1.2*sigma,mean+1.2*sigma); + + if (saveHistos==false) { + htemp->Fit("fn","RQMN"); + } else { + ctemp= new TCanvas("ctemp","ctemp",500,500); + TString psName = num2str + triggerName + ".ps"; + htemp->Fit("fn","RQM"); + ctemp->Print(psName); + delete ctemp; + } + double frange = 2.4*sigma; + double hrange = htemp->GetXaxis()->GetXmax()-htemp->GetXaxis()->GetXmin(); + double ndf = frange/hrange*(htemp->GetNbinsX()) - 3;//subtract number of fit parameters + //fill results ; + mean = fn->GetParameter(1); + meanErr = fn->GetParError(1); + sigma = fn->GetParameter(2); + sigmaErr = fn->GetParError(2); + chi2 = (fn->GetChisquare())/ndf; + delete fn; + } else { + //fit Z peak with a convolution of BreitWigner and Crystal Ball fns, fit by Louise, implementation by Jike taken from IDPerfMon + RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL); + RooAbsPdf::verboseEval(-100); //sami in order to make roofit quiet + RooRealVar m("mass", "dimuon invariable mass", 91.2, 71., 111., "GeV"); + RooDataHist *data = 0; + data = new RooDataHist("data", "data", m, htemp); + RooRealVar bwm0("bw_#mu", "bw_#mu", 91.2, 85.2, 97.2) ; + RooRealVar bwsg("bw_#sigma","bw_#sigma", 2.4952) ; + RooBreitWigner bw("bw","bw", m, bwm0, bwsg); + + RooRealVar cbm0("cb_#mu", "cb_#mu", 0 ) ; + RooRealVar cbsg("cb_#sigma", "cb_#sigma", 3., 1., 10.) ; + RooRealVar cbal("cb_#alpha", "cb_#alpha",2.0) ; + RooRealVar cbn( "cb_n", "cb_n", 1., 0.05, 3.) ; + RooCBShape cb( "cb", "cb", m, cbm0, cbsg, cbal, cbn); + + m.setBins(5000); + RooFFTConvPdf bxc("bxc", "BW (X) CB", m, bw, cb) ; + bxc.fitTo(*data, RooFit::PrintLevel(-1), RooFit::FitOptions("QN"), RooFit::PrintEvalErrors(-1), RooFit::Warnings(kFALSE)); + RooPlot* frame; + if (saveHistos==true){ + frame= m.frame(); + data->plotOn(frame, RooFit::MarkerSize(0.9)); + bxc.paramOn(frame, RooFit::Format("NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.1,0.4,0.9)); + bxc.plotOn (frame, RooFit::LineColor(kBlue)); + delete frame; + } + mean = bwm0.getVal(); + meanErr = bwm0.getError(); + sigma = cbsg.getVal(); + sigmaErr = cbsg.getError(); + delete data; + } + //fill results + if (mode == 0){//plot both invmass and width vs variable + hout.at(0)->SetBinContent(i+1,mean); + hout.at(0)->SetBinError(i+1,meanErr); + hout.at(1)->SetBinContent(i+1,sigma); + hout.at(1)->SetBinError(i+1,sigmaErr); + } else if (mode==1){//plot only invmass vs variable + hout.at(0)->SetBinContent(i+1,mean); + hout.at(0)->SetBinError(i+1,meanErr); + } else if (mode==2){//plot only width vs variable + hout.at(0)->SetBinContent(i+1,sigma); + hout.at(0)->SetBinError(i+1,sigmaErr); + } + m_chi2->Fill(chi2); + }// more than 50 events + + delete htemp; + } +} + + +} + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTCaloAveragePtPhiEtaMaps.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTCaloAveragePtPhiEtaMaps.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c3076f1a5722c99a371e8f7fe11d7426c45b0b8e --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTCaloAveragePtPhiEtaMaps.cxx @@ -0,0 +1,115 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* HLTCalo Post Processing Method: to produce eta phi map of the average hit energy in each bin, made + * from two 2-d histograms, one with total energy in each bin the + * other with number of hits per bin + * Author : Gareth Brown <gabrown@CERN.CH> based on HLTMET Post Processing + * Date : Oct 2011 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <cstdlib> +#include <vector> +#include <string> + +#include "TH2F.h" +#include "TFile.h" +#include "TKey.h" + +namespace dqutils { + + void MonitoringFile::HLTCaloAveragePtPhiEtaMaps(TFile* f, TString& run_dir) { + + int debugLevel = MonitoringFile::getDebugLevel(); + + if(debugLevel>1) std::cout << "--> HLTCaloAveragePtPhiEtaMaps: <Quantity(eta,phi)> = Quantity(eta,phi)/N(eta,phi) " << std::endl; + + f->cd("/"); + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + run_dir = key_run->GetName(); + if (!run_dir.Contains("run") ) { continue;} + + std::string run_dir2 = run_dir.Data(); + + // all merged root files have the structure "rootfile.root:/run_NNNNNNN" + // use that to extract run number + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + // begin HLTMET + // note 1: prefix all dirs and hists with '/' + // note 2: missing dir => return + // note 3: missing hist => continue + TString hlt_top = run_dir + "/HLT"; // toplevel + + std::vector<TString> calo_fold; + std::vector<std::pair<TString,TString> > hist_numr; + + // The folders that we want to get the hists from + calo_fold.push_back("/CaloMon"); + calo_fold.push_back("/CaloMonL2"); + + // check if the folders are in hlt + for( std::vector<TString>::iterator it = calo_fold.begin(); it != calo_fold.end(); it++ ) { + TString theHistDir = hlt_top + *it; + TDirectory* dir = f->GetDirectory(theHistDir); + if(!dir){ + if(debugLevel>0) std::cerr << "--> HLTCaloAveragePtPhiEtaMaps: directory " << theHistDir << " not found" << std::endl; + return; + } + } + + // pairs of Num and Dem + hist_numr.push_back(std::make_pair<TString,TString>("/EnergyAccetaphiLAr","/HitAccetaphiLAr")); + hist_numr.push_back(std::make_pair<TString,TString>("/EnergyAccetaphiTile","/HitAccetaphiTile")); + + + // we have all dirs, get the component histograms + for( std::vector<TString>::iterator itFex = calo_fold.begin(); itFex != calo_fold.end(); itFex++ ) { + for( std::vector<std::pair<TString,TString> >::iterator itNum = hist_numr.begin(); itNum != hist_numr.end(); itNum++ ) { + TH2F *hnum(0), *hden(0); + + // prepend histogram name with path and append with suffix [_00 .., _24 for each component] + TString thePath = hlt_top + (*itFex); + TString numPath = thePath + (*itNum).first; + TString denPath = thePath + (*itNum).second; + + // get histograms + hnum = (TH2F *) (f->Get(numPath)); + hden = (TH2F *) (f->Get(denPath)); + // test if histograms are present + if(!hnum) { if(debugLevel>0) std::cerr << "--> HLTCaloAveragePtPhiEtaMaps: no histogram " << numPath << std::endl; continue;} + if(!hden) { if(debugLevel>0) std::cerr << "--> HLTCaloAveragePtPhiEtaMaps: no histogram " << denPath << std::endl; continue;} + + + // get directory of histograms + TDirectory* dir = f->GetDirectory(thePath); + + // these are disabled, because we have to worry about updating metadata + // clone numerator histogram in the same directory; prepend with "avg_" + // use numerator to do the job + + // divide num by den to get average quantity. + hnum->Divide(hnum,hden); + + // fix histogram titles + TString title = hnum->GetTitle(); + hnum->SetTitle("Average Transverse Energy per eta/phi bin"); + + dir->cd(); + hnum->Write("",TObject::kOverwrite); + + } // done looping over quantities + } // done looping over directories + + } // end while loop over all keys + } // end method MonitoringFile::HLTCaloAveragePtPhiEtaMaps + +} // end namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTCaloPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTCaloPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ef2dd3c1d9c2ea9ece32dc773b15b774da131a14 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTCaloPostProcess.cxx @@ -0,0 +1,63 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* HLTCalo Post Processing on run_nnnn/HLT/HLTcalo histogram + * Author : Gareth Brown <gabrown@CERN.CH> based on HLTMET Post Processing + * Date : Oct 2011 + */ + +#include "DataQualityUtils/MonitoringFile.h" +#include <iostream> +#include "TFile.h" +#include "TString.h" + +namespace dqutils { + + void MonitoringFile::HLTCaloPostProcess( std::string inFilename, bool isIncremental ) { + if (isIncremental == true) { + return; + } + + int debugLevel = MonitoringFile::getDebugLevel(); + if(debugLevel>1){ + std::cout << "--> HLTCaloPostProcess: Begin HLTCalo post-processing" << std::endl; + } + + //open root file + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + //check files are loaded. + if (f == 0 || ! f->IsOpen() ) { + std::cerr << "--> HLTCaloPostProcess: Input file not opened" << std::endl; + return; + } + + if(f->IsZombie()) { + std::cerr << "--> HLTCaloPostProcess: Input file " << inFilename << " cannot be opened. " << std::endl; + return; + } + + //check file size is not too small. + if(f->GetSize()<1000.) { + std::cerr << "--> HLTCaloPostProcess: Input file empty" << std::endl; + f->Close(); + return; + } + + //start postprocessing + TString run_dir; + HLTCaloAveragePtPhiEtaMaps( f, run_dir); + //close root file + f->Close(); + delete f; + + if(debugLevel>1){ + std::cout << "--> HLTCaloPostProcess: End HLTCalo post-processing "<<std::endl; + } + + return; + } + +}//namespace + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTEgammaEfficiency.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTEgammaEfficiency.cxx new file mode 100644 index 0000000000000000000000000000000000000000..dbc910a45d476b985f64775738e3b529d46f9fd1 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTEgammaEfficiency.cxx @@ -0,0 +1,217 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// HLT Egamma post processing jobs +// 15/03/2012 initial file by Yan-Jie Schnellbach, based on HLT Tau +// ********************************************************************** + +#include "DataQualityUtils/MonitoringFile.h" + +#include <cmath> +#include <vector> + +#include <TCanvas.h> +#include <TF1.h> +#include <TFile.h> +#include <TH1.h> +#include <TH2.h> +#include <TKey.h> +#include <TMath.h> +#include <TProfile.h> + +namespace dqutils { + + //------------------------------------------------------------- + // function to calculate bootstrap efficiency w.r.t to offline + // ------------------------------------------------------------ + void MonitoringFile::HLTEgammaEfficiencyOff( TFile* f, TDirectory* trig_dir, + TDirectory* off_dir, const TString &pathNum, + const TString &pathEff, const std::vector<TString> &varName){ + + //get the relevant paths + std::string chain_path = getPath(trig_dir); + std::string offline_path = getPath(off_dir); + + //establish base path (to save typing "/PassedChain/" over and over) + TString basePath = chain_path + "/PassedChain/"; + if( f->cd(basePath.Data()) == 0 ){ + std::cerr << "----> HLTEgammaPostProcess: basePath not found in " + << chain_path << ", skipping now!\n"; + return; + } + + //create histogram matrix with pointers to our histograms in question + // 3x3 matrix, rows are variables (Et, Eta, Phi), colums the different + // histograms (numerator - matched offline, denominator - offline, eff) + TH1F* histo_matrix[3][3]; + + //check variables to avoid segfaults! + if(varName.size() > 3){ + std::cerr << "----> HLTEgammaPostProcess: Too many variables " + << "used in " << chain_path + "/PassedChain/" + pathEff + << " for bootstrap efficiencies, skipping now!\n"; + return; + } + + + + for(uint iVar = 0; iVar < varName.size(); ++iVar){ + //form names for all variables + TString numName = basePath + pathNum + "eg" + varName[iVar]; + TString denName = offline_path + "/" + "eg" + varName[iVar]; + TString effName = basePath + pathEff + "eg" + varName[iVar]; + + //check histogram existence + if( !CheckHistogram(f, numName.Data())){ + std::cerr << "----> HLTEgammaPostProcess: Histogram " + << numName << " does not exist in file " + << f->GetName() << " - skipping!\n"; + return; + } + if( !CheckHistogram(f, denName.Data())){ + std::cerr << "----> HLTEgammaPostProcess: Histogram " + << denName << " does not exist in file " + << f->GetName() << " - skipping!\n"; + return; + } + if( !CheckHistogram(f, effName.Data())){ + std::cerr << "----> HLTEgammaPostProcess: Histogram " + << effName << " does not exist in file " + << f->GetName() << " - skipping!\n"; + return; + } + + //debug outs + //std::cout << "---->HLTEgammaPostProcess: Taking " << numName << " and divide by " + // << denName << " to get " << effName << std::endl; + + //now get histograms + histo_matrix[iVar][0] = (TH1F*) (f->Get( numName.Data() )); + histo_matrix[iVar][1] = (TH1F*) (f->Get( denName.Data() )); + histo_matrix[iVar][2] = (TH1F*) (f->Get( effName.Data() )); + + //hop into efficiency path + TString writePath = basePath + pathEff; + f->cd( writePath.Data() ); + + //create efficiency histogram by division + histo_matrix[iVar][2]->Divide( histo_matrix[iVar][0], histo_matrix[iVar][1], + 1.0, 1.0, "B"); + histo_matrix[iVar][2]->Scale(100.); + if(histo_matrix[iVar][2]->Write("", TObject::kOverwrite) == 0) + std::cerr << "----> HLTEgammaPostProcess: Efficiency histogram " + << effName << " not written! Histogram will be buggy!\n"; + + } + + //save results now + f->Write(); + + } + + + // -------------------------------------------------- + // function called to calculate relative efficiencies + // --------------------------------------------------- + + void MonitoringFile::HLTEgammaEfficiencyRel( TFile* f, TDirectory* trig_dir, + const TString &pathPre, const TString &pathRej, + const std::vector<TString> &objStage, + const std::vector<TString> &varName){ + + std::string chain_path = getPath(trig_dir); + + // std::cout << "----> HLTEgammaPostProcess in " << chain_path + // << ", pathPre=" << chain_path + "/PassedChain/" + pathPre + // << ", pathRej=" << chain_path + "/PassedChain/" + pathRej + + //establish base path (to save typing) + TString basePath = chain_path + "/PassedChain/"; + if( f->cd(basePath.Data()) == 0 ){ + std::cerr << "----> HLTEgammaPostProcess: basePath not found in " + << chain_path << ", skipping now!\n"; + return; + } + + //create histogram matrix with pointers to our histograms in question + // 5x3x3 tensor, 1st index is the stage 2nd index are variables + // (Et, Eta, Phi), 3rd index the different histograms + // (numerator - n-1 stage, denominator - n stage) + TH1F* histo_tensor[5][3][3]; + + //now check size of our stages and variables to avoid segfaults! + if(objStage.size() > 5){ + std::cerr << "----> HLTEgammaPostProcess: Too many chain stages " + << "found in " << chain_path << " for relative efficiencies, bailing it!\n"; + return; + } + if(varName.size() > 3){ + std::cerr << "----> HLTEgammaPostProcess: Too many variables " + << "used in " << chain_path << " for relative efficiencies, bailing out!\n"; + return; + } + + //iterate through variables (start at 1, as there is no we can't + //calculate rejection efficiency w.r.t n-1 with n = 0 -> segfault!) + for(uint iVar = 0; iVar < varName.size(); ++iVar){ + + //iterate through stages + for(uint iStg = 1; iStg < objStage.size(); ++iStg){ + + //form names for all variables + TString preName = basePath + pathPre + objStage[iStg-1] + varName[iVar]; + TString rejName = basePath + pathPre + objStage[iStg] + varName[iVar]; + TString effName = basePath + pathRej + objStage[iStg] + varName[iVar]; + //check histogram existence + if( !CheckHistogram(f, rejName.Data()) ){ + std::cerr << "----> HLTEgammaPostProcess: Histogram " + << rejName << " does not exist in file " + << f->GetName() << " - skipping it!\n"; + return; + } + if( !CheckHistogram(f, preName.Data()) ){ + std::cerr << "----> HLTEgammaPostProcess: Histogram " + << preName << " does not exist in file " + << f->GetName() << " - skipping it!\n"; + return; + } + if( !CheckHistogram(f, effName.Data()) ){ + std::cerr << "----> HLTEgammaPostProcess: Histogram " + << effName << " does not exist in file " + << f->GetName() << " - skipping it!\n"; + return; + } + + //debug outs + //std::cout << "---->HLTEgammaPostProcess: Taking " << rejName << " and divide by " + // << preName << " to get " << effName << std::endl; + + //now get our histograms + histo_tensor[iStg][iVar][0] = (TH1F*) (f->Get( rejName.Data() )); + histo_tensor[iStg][iVar][1] = (TH1F*) (f->Get( preName.Data() )); + histo_tensor[iStg][iVar][2] = (TH1F*) (f->Get( effName.Data() )); + + //hop into rejection path + TString writePath = basePath + pathRej; + f->cd( writePath.Data() ); + + //create rejection efficiency histograms by division + histo_tensor[iStg][iVar][2]->Divide( histo_tensor[iStg][iVar][0], histo_tensor[iStg][iVar][1], + 1.0, 1.0, "B"); + histo_tensor[iStg][iVar][2]->Scale(100.); + if(histo_tensor[iStg][iVar][2]->Write("", TObject::kOverwrite) == 0) std::cerr + << "---->HLTEgammaPostProcess: Relative efficiency histogram " + << effName << " not written! Histograms will be buggy!\n"; + + } + + } + + //save results now + f->Write(); + + } + +} diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTEgammaPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTEgammaPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ddaade796f4175efeecfc0b4db46339508ecaf55 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTEgammaPostProcess.cxx @@ -0,0 +1,223 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// HLT Egamma post processing jobs +// 15/03/2012 initial file by Yan-Jie Schnellbach, based on HLT Tau +// ********************************************************************** + +#include "DataQualityUtils/MonitoringFile.h" + +#include <cmath> +#include <vector> + +#include <TCanvas.h> +#include <TF1.h> +#include <TFile.h> +#include <TH1.h> +#include <TH2.h> +#include <TKey.h> +#include <TMath.h> +#include <TProfile.h> + +namespace dqutils { + + + //-------------------------------------------------------------------------------- + // main post processing function (opens file, detects trigger chains, calls + // individual efficiency calculations + //-------------------------------------------------------------------------------- + void MonitoringFile::HLTEgammaPostProcess(const std::string &inFilename, bool /* isIncremental */ ){ + // std::cout << "--> HLTEgammaPostProcess: Begin HLT Egamma post-processing" << std::endl; + + // ----- getting file ----- + + //open root file + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + //check files are loaded. + if (f == 0 || ! f->IsOpen() ) { + std::cerr << "--> HLTEgammaPostProcess: Input file not opened" << std::endl; + delete f; + return; + } + + //zombie files? + if(f->IsZombie()) { + std::cerr << "--> HLTEgammaPostProcess: Input file " << inFilename << " cannot be opened. " << std::endl; + delete f; + return; + } + + //check file size is not too small. + if(f->GetSize()<1000.) { + std::cerr << "--> HLTEgammaPostProcess: Input file empty" << std::endl; + f->Close(); + delete f; + return; + } + + //build iterator + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + + //loop over keys in root directory + while ((key_run = dynamic_cast<TKey*>( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + + //check we have a valid pointer + if (tdir_run ==0 ) { + delete obj_run; + continue; + } + + //check name + std::string runDirName( tdir_run->GetName() ); + //std::cout<<"Run_directory: "<<runDirName<<std::endl; + + // check run directory + //(comment this out for local testing with the TrigEgammaMonitoring recipe) + if (runDirName.find("run") == std::string::npos ) { + delete obj_run; + continue; + } + + // ----- find egamma monitoring directory (EgammaSigTE) ------ + TString egammamonDirName = runDirName + "/HLT/EgammaSigTE"; + TDirectory* egammamonDir(0); + if( !(egammamonDir = f->GetDirectory(egammamonDirName)) ) { + std::cout << "--> HLTEgammaPostProcess: directory " << egammamonDirName << " not found." << std::endl; + delete obj_run; + return; + } + + // ----- get handles for offline egamma object directories ----- + TString offgammaDirName = egammamonDirName + "/OfflinePhoton"; + TString offeleDirName = egammamonDirName + "/OfflineElectron"; + TDirectory* offgammaDir(0); TDirectory* offeleDir(0); + if( !(offgammaDir = f->GetDirectory(offgammaDirName))){ + std::cout << "--> HLTEgammaPostProcess: offline directory " << offgammaDirName << " not found, will abort.\n"; + delete obj_run; + return; + } + if( !(offeleDir = f->GetDirectory(offeleDirName))){ + std::cout << "--> HLTEgammaPostProcess: offline directory " << offeleDirName << " not found, will abort.\n"; + delete obj_run; + return; + } + + // ----- list the histograms for offline efficiencies ----- + // word of warning: hardcoded maximum of 3 in the efficiency functions + // if you add stages, increase the size of histo_matrix + // or histo_tensor respectively! + // note: offline effs use "egEt", "egEta" etc., this is hardcoded in the + // variable name formation in the offl. eff function. + // finally: use std::vector<TString> varname = {"Et", "Eta", "Phi"} + // if we're ever going to use C++11 around this place... + + std::vector<TString> varName; + varName.push_back("Et"); + varName.push_back("Eta"); + varName.push_back("Phi"); + + // ----- chain stages for relative effs ----- + // word of warning: hardcoded maximum of 5 in the efficiency functions + // if you add stages, increase the size of histo_matrix + // or histo_tensor respectively! + // finally: use std::vector<TString> phoStage = {"L1", "L2Calo", "EFCalo"} + // and std::vector<TString> phoStage = {"L1", "L2Calo", "L2ID", "EFCalo", "EFID"} + // if we're ever going to use C++11 around this place... + + //photons + std::vector<TString> phoStage; + phoStage.push_back("L1"); + phoStage.push_back("L2Calo"); + phoStage.push_back("EFCalo"); + + //electrons + std::vector<TString> eleStage; + eleStage.push_back("L1"); + eleStage.push_back("L2Calo"); + eleStage.push_back("L2ID"); + eleStage.push_back("EFCalo"); + eleStage.push_back("EFID"); + + // ----- loop over directories (i.e. trigger chains) ------ + TIter next_trig ( egammamonDir->GetListOfKeys() ); + TKey* key_trig(0); + while ( (key_trig = dynamic_cast<TKey*>( next_trig() )) != 0 ) { + + //store chain specific info (and resets them) + bool photon_chain(false); + bool electron_chain(false); + TObject* obj_trig = key_trig->ReadObj(); + TDirectory* dir_trig = dynamic_cast<TDirectory*>( obj_trig ); + + //check we have a valid pointer + if (dir_trig == 0) { + delete obj_trig; + continue; + } + + //get name of the current trigger chain + TString trigger_name = dir_trig->GetName(); + + //bow out of offline containers here (we don't monitor them, they're for bootstrapping) + if (trigger_name.Contains("Offline")) { + delete obj_trig; + continue; + } + + //detect photon/electron chains (checks chain name, skips unrecognised chains) + if(trigger_name.BeginsWith("g") || trigger_name.BeginsWith("2g")) photon_chain = true; + else if(trigger_name.BeginsWith("e") || trigger_name.BeginsWith("2e")) electron_chain = true; + else{ + std::cout << "--> HLTEgammaPostProcess: Non-electron/photon chain detected, will be skipped!\n"; + delete obj_trig; + continue; + } + + //call photon post processing routine (no track directories, only Calo) + if(photon_chain){ + //std::cout<<"--> HLTEgammaPostProcess: calling photon functions for "<<egammamonDirName<<" and trigger item="<<dir_trig->GetName()<<" in directory: "<<getPath(dir_trig)<<endl; + + //calling boostrap efficiency calcs + HLTEgammaEfficiencyOff(f,dir_trig, offgammaDir, "L1/MatchedOffPho/", "L1/EffPho/", varName); + HLTEgammaEfficiencyOff(f,dir_trig, offgammaDir, "L2Calo/MatchedOffPho/", "L2Calo/EffPho/", varName); + HLTEgammaEfficiencyOff(f,dir_trig, offgammaDir, "EFCalo/MatchedOffPho/", "EFCalo/EffPho/", varName); + HLTEgammaEfficiencyOff(f,dir_trig, offgammaDir, "EFeg/MatchedOffPho/", "EFeg/EffPho/", varName); + + //calling relative efficiency calcs + HLTEgammaEfficiencyRel(f,dir_trig, "PreRejection/", "Rejection/", phoStage, varName); + } + + //call electron post processing (the full thing) + if(electron_chain){ + //std::cout<<"--> HLTEgammaPostProcess: calling electron functions for "<<egammamonDirName<<" and trigger item="<<dir_trig->GetName()<<" in directory: "<<getPath(dir_trig)<<endl; + + //calling bootstrap efficiency calcs + HLTEgammaEfficiencyOff(f,dir_trig, offeleDir, "L1/MatchedOffEle/", "L1/EffEle/", varName); + HLTEgammaEfficiencyOff(f,dir_trig, offeleDir, "L2Calo/MatchedOffEle/", "L2Calo/EffEle/", varName); + HLTEgammaEfficiencyOff(f,dir_trig, offeleDir, "L2ID/MatchedOffEle/", "L2ID/EffEle/", varName); + HLTEgammaEfficiencyOff(f,dir_trig, offeleDir, "EFCalo/MatchedOffEle/", "EFCalo/EffEle/", varName); + HLTEgammaEfficiencyOff(f,dir_trig, offeleDir, "EFID/MatchedOffEle/", "EFID/EffEle/", varName); + HLTEgammaEfficiencyOff(f,dir_trig, offeleDir, "EFeg/MatchedOffEle/", "EFeg/EffEle/", varName); + + //calling relative efficiency calcs + HLTEgammaEfficiencyRel(f,dir_trig, "PreRejection/", "Rejection/", eleStage, varName); + } + + + } + + } + + //clean up after ourselves... + f->Close(); + delete f; + //std::cout << "--> HLTEgammaPostProcess: finished HLT Egamma post-processing"<<std::endl; + } + +} diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTJetCalcEfficiencyAndRate.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTJetCalcEfficiencyAndRate.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9c65edc0f187f1b5146d6907bb84d954b72565ac --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTJetCalcEfficiencyAndRate.cxx @@ -0,0 +1,240 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* Methods to perform post-processing on run_nnnnnn/HLT/JetMon* histograms + * Author : Venkatesh Kaushik (venkat.kaushik@cern.ch) + * Date : Apr 2010 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + +namespace dqutils { + + void + MonitoringFile::HLTJetCalcEfficiencyAndRate(TFile* f, TString& run_dir) + { + + bool dbgLevel = false; + if(dbgLevel) std::cout << "--> HLTJetCalcEfficiencyAndRate: Calculate jet trigger efficiency and rate" << std::endl; + + f->cd("/"); + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + run_dir = key_run->GetName(); + if (!run_dir.Contains("run") ) { continue;} + + + std::string run_dir2 = run_dir.Data(); + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + + TString jetmon_dir = run_dir + "/HLT/JetMon"; + + //===HLTJet efficiency histograms + TString akt4topo_dir = jetmon_dir + "/AntiKt4TopoJets/TrigEff"; + //TString akt6topo_dir = jetmon_dir + "/AntiKt6TopoJets/TrigEff"; + + TDirectory* dir(0); + + if( !(dir = f->GetDirectory(akt4topo_dir)) ) { + std::cerr << "--> HLTJetCalcEfficiencyAndRate: directory " << akt4topo_dir << " not found." << std::endl; + return; + } + + TH1F* hnum(0); + TH1F* hden(0); + + + //==Efficiency + std::vector<TString> effobs; + effobs.push_back("_Eff_vs_pt"); + effobs.push_back("_Eff_vs_eta"); + effobs.push_back("_Eff_vs_phi"); + + std::vector<TString> TrigItems; + + // EF_fj30(_a4_EFFS) <-- L2_fj25 <-- L1_FJ10 + // EF_j30(_a4_EFFS) <-- L2_j25 <-- L1_J10 + // EF_j240(_a4_EFFS) <-- L2_j95 <-- L1_J75 + + TrigItems.push_back("EF_fj30"); + TrigItems.push_back("EF_j30"); + TrigItems.push_back("EF_j240"); + //TrigItems.push_back("EF_fj50"); + //TrigItems.push_back("EF_fj75"); + + //TrigItems.push_back("EF_j50"); + //TrigItems.push_back("EF_j75"); + //TrigItems.push_back("EF_j95"); + + TrigItems.push_back("L1_FJ10"); + TrigItems.push_back("L1_J10"); + TrigItems.push_back("L1_J75"); + //TrigItems.push_back("L1_FJ55"); + //TrigItems.push_back("L1_FJ95"); + + //TrigItems.push_back("L1_J30"); + //TrigItems.push_back("L1_J55"); + //TrigItems.push_back("L1_J75"); + + //TrigItems.push_back("L2_fj45"); + //TrigItems.push_back("L2_fj70"); + + TrigItems.push_back("L2_fj25"); + TrigItems.push_back("L2_j25"); + TrigItems.push_back("L2_j95"); + //TrigItems.push_back("L2_j30"); + //TrigItems.push_back("L2_j45"); + //TrigItems.push_back("L2_j70"); + //TrigItems.push_back("L2_j90"); + + TString snum, sden, hnumname; + for( std::vector<TString>::iterator itT = TrigItems.begin(); itT != TrigItems.end(); ++itT ) { + for( std::vector<TString>::iterator itO = effobs.begin(); itO != effobs.end(); ++itO ) { + + hnumname = (*itT) + (*itO) + "_num"; + snum = akt4topo_dir + "/" + hnumname; + sden = akt4topo_dir + "/" + (*itT) + (*itO) + "_den"; + + if( ! f->Get(snum) ){if(dbgLevel) std::cerr <<"--> HLTJetPostProcess: no such histogram "<< snum << std::endl; } + if( ! f->Get(sden) ){if(dbgLevel) std::cerr <<"--> HLTJetPostProcess: no such histogram "<< sden << std::endl; } + + if( f->Get(snum) && f->Get(sden) ){ + + hnum = dynamic_cast<TH1F*>( f->Get(snum) ); + hnum->Sumw2(); + hden = dynamic_cast<TH1F*>( f->Get(sden) ); + hden->Sumw2(); + + Int_t nbins_num = hnum->GetNbinsX(); + Int_t nbins_den = hden->GetNbinsX(); + if(nbins_num != nbins_den) { + if(dbgLevel) std::cerr <<"--> HLTJetPostProcess: cannot divide histogram "<< hnum->GetName() + << " by " << hden->GetName() << ". Different number of bins." << std::endl; + } + + // divide num, den with binomial errors + // note: replacing the numerator by quotient + hnum->Divide(hnum, hden, 1., 1., "B"); + + dir->cd(); + hnum->Write("",TObject::kOverwrite); + } + } // for effobs + } // for TrigItems + + /* + if( !(dir = f->GetDirectory(akt6topo_dir)) ) { + std::cerr << "--> HLTJetCalcEfficiencyAndRate: directory " << akt6topo_dir << " not found." << std::endl; + return; + } + + for( std::vector<TString>::iterator itT = TrigItems.begin(); itT != TrigItems.end(); ++itT ) { + for( std::vector<TString>::iterator itO = effobs.begin(); itO != effobs.end(); ++itO ) { + hnumname = (*itT) + (*itO) + "_num"; + snum = akt6topo_dir + "/" + hnumname; + sden = akt6topo_dir + "/" + (*itT) + (*itO) + "_den"; + + if( ! f->Get(snum) ){std::cerr <<"--> HLTJetPostProcess: no such histogram "<< snum << std::endl; } + if( ! f->Get(sden) ){std::cerr <<"--> HLTJetPostProcess: no such histogram "<< sden << std::endl; } + + if( f->Get(snum) && f->Get(sden) ){ + hnum = dynamic_cast<TH1F*>( f->Get(snum) ); + hnum->Sumw2(); + hden = dynamic_cast<TH1F*>( f->Get(sden) ); + hden->Sumw2(); + + Int_t nbins_num = hnum->GetNbinsX(); + Int_t nbins_den = hden->GetNbinsX(); + if(nbins_num != nbins_den) { + std::cerr <<"--> HLTJetPostProcess: cannot divide histogram "<< hnum->GetName() + << " by " << hden->GetName() << ". Different number of bins." << std::endl; + } + // note: replacing the numerator by quotient + hnum->Divide(hnum, hden, 1., 1., "B"); + dir->cd(); + hnum->Write("",TObject::kOverwrite); + } + } // for effobs + } // for TrigItems + */ + + }//while + }//MonitoringFile::HLTJetCalcEfficiencyAndRate + + // ------------------------------------------------------------------------------------------------------- + // Compute bin errors a la Ullrich, Paterno and Xu (UPX) variance + // http://arxiv.org/abs/physics/0701199 + // Input : Numerator, Denominator histograms and an empty std::vector<float> errors + // Return Value(s): Errors including Overflow/Underflow bins are returned in std::vector<float> errors + // Statuscode is returned as an int + // StatusCode = -1 => either numerator or denominator histogram doesn't exist + // = -2 => number of bins in numerator and denominator are not equal + // = -3 => denominator has zero entries + // = -4 => at least one of the bins has negative entries + // = 1 => ALL OK + // Alternative to "Binomial" variance used by TH1::Divide option "B" + // Thanks to D. Casadei for his macro which is implemented here with minor modifications + // ------------------------------------------------------------------------------------------------------- + int MonitoringFile::ComputeUPXBinErrors(TH1F *hnum, TH1F *hden, std::vector<float>& errors) { + + if(hnum==0 || hden==0) return -1; + + Int_t nbins_num = hnum->GetNbinsX(); + Int_t nbins_den = hden->GetNbinsX(); + + if(nbins_num != nbins_den) return -2; + + if(hden->GetEntries() == 0) return -3; + + errors.clear(); + for (Int_t i = -1; i <= nbins_num; ++i ) { // NB: loop includes under- & overflow + float n = hden->GetBinContent(i); + if (n==0) continue; + float k = hnum->GetBinContent(i); + if(k<0||n<0){ + if(MonitoringFile::getDebugLevel()>0)std::cerr << "--> ComputeUPXBinErrors : ERROR: found negative entries in bin " << i + << " for histograms " << hnum->GetName() << " , " << hden->GetName() << std::endl; + break; + } + float num1 = (k+1)*(k+2); + float den1 = (n+2)*(n+3); + float num2 = (k+1)*(k+1); + float den2 = (n+2)*(n+2); + float variance = num1/den1 - num2/den2; + float err = sqrt(variance); + errors.push_back(err); + } + Int_t num_err = (Int_t) errors.size(); + int retval = 1; + if(num_err != nbins_num) retval = -4; + return retval; + } + +}//namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTJetPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTJetPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1f25a9b566fcde204d5baa1de71095cf5700adca --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTJetPostProcess.cxx @@ -0,0 +1,84 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +/* Methods to perform post-processing on run_nnnnnn/HLT/METMon* histograms + * Author : Venkatesh Kaushik (venkat.kaushik@cern.ch) + * Date : Feb 2010 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + + + +namespace dqutils { + + static const bool hltjet_debug = false; + + void + MonitoringFile::HLTJetPostProcess( std::string inFilename, bool /* isIncremental */ ) + { + bool dbgLevel = false; + + if(dbgLevel) std::cout << "--> HLTJetPostProcess: Begin HLTJet post-processing" << std::endl; + + //open root file + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + //check files are loaded. + + if (f == 0 || ! f->IsOpen() ) { + std::cerr << "--> HLTJetPostProcess: Input file not opened" << std::endl; + return; + } + + if(f->IsZombie()) { + std::cerr << "--> HLTJetPostProcess: Input file " << inFilename << " cannot be opened. " << std::endl; + return; + } + + //check file size is not too small. + if(f->GetSize()<1000.) { + std::cerr << "--> HLTJetPostProcess: Input file empty" << std::endl; + f->Close(); + return; + } + + //start postprocessing + TString run_dir; + HLTJetCalcEfficiencyAndRate( f, run_dir); + //close root file + f->Close(); + delete f; + + if(dbgLevel) std::cout << "--> HLTJetPostProcess: End HLTJet post-processing "<<std::endl; + + return; + + } + +}//namespace + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMETAveragePhivsEtaMaps.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMETAveragePhivsEtaMaps.cxx new file mode 100644 index 0000000000000000000000000000000000000000..817f208398a3e62383b54d252d6038ef3e39b909 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMETAveragePhivsEtaMaps.cxx @@ -0,0 +1,169 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* HLTMET Post Processing Method: Peform bin-wise division for each Phi.vs.Eta maps of MET, SumEt, SumE + * with Phi.vs.Eta map of N to compute <MET>(eta,phi), <SumEt>(eta,phi) + * and <SumE>(eta,phi) + * Author : Venkatesh Kaushik <venkat.kaushik@cern.ch> + * Date : Feb 2010 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + +namespace dqutils { + + void + MonitoringFile::HLTMETAveragePhivsEtaMaps(TFile* f, TString& run_dir) { + + bool dbgLevel = false; + if(dbgLevel) std::cout << "--> HLTMETAveragePhivsEtaMaps: <Quantity(eta,phi)> = Quantity(eta,phi)/N(eta,phi) " << std::endl; + + f->cd("/"); + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + run_dir = key_run->GetName(); + if (!run_dir.Contains("run") ) { continue;} + + + std::string run_dir2 = run_dir.Data(); + + // all merged root files have the structure "rootfile.root:/run_NNNNNNN" + // use that to extract run number + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + // begin HLTMET + // note 1: prefix all dirs and hists with '/' + // note 2: missing dir => return + // note 3: missing hist => continue + TString hlt_top = run_dir + "/HLT"; // toplevel + TString met_efdir = "/EFMissingET_Fex"; // EF dir + + std::vector<TString> met_fexs, hist_numr; + + // expect the following fex dirs + met_fexs.push_back("/METMon"); + //met_fexs.push_back("/METMon_FEB"); + //met_fexs.push_back("/METMon_allCells"); + + // check if fex dirs are in hlt + for( std::vector<TString>::iterator it = met_fexs.begin(); it != met_fexs.end(); it++ ) { + TString theHistDir = hlt_top + *it; + TDirectory* dir = f->GetDirectory(theHistDir); + if(!dir){ + std::cerr << "--> HLTMETAveragePhivsEtaMaps: directory " << theHistDir << " not found" << std::endl; + return; + } + // expect the EF dir inside each fex dir + theHistDir += met_efdir; + dir = f->GetDirectory(theHistDir); + if(!dir){ + std::cerr << "--> HLTMETAveragePhivsEtaMaps: directory " << theHistDir << " not found" << std::endl; + return; + } + } + + // MEt, SumEt, SumE of components (numerator) + // compSumEt_lin_EtaPhi_00 etc.. + hist_numr.push_back("/compEt_lin_"); + hist_numr.push_back("/compSumEt_lin_"); + hist_numr.push_back("/compSumE_lin_"); // need to plot SumE on linear scale (todo) + + // components N (denominator) + TString hist_denr = "/compN_" ; + + // type (eta,phi map) + TString hist_suffix = "EtaPhi_"; // phi vs. eta map + + // each component a 2d hist. get all components + unsigned int comp_num = 25; // 25 components + + // we have all dirs, get the component histograms + for( std::vector<TString>::iterator itFex = met_fexs.begin(); itFex != met_fexs.end(); itFex++ ) { + for( std::vector<TString>::iterator itNum = hist_numr.begin(); itNum != hist_numr.end(); itNum++ ) { + for(unsigned int icomp = 0; icomp < comp_num; icomp++ ) { + TH2F *hnum(0), *hden(0); + + // prepend histogram name with path and append with suffix [_00 .., _24 for each component] + TString thePath = hlt_top + (*itFex) + met_efdir; + TString numHist = (*itNum) + hist_suffix + TString(Form("%02u",icomp)); + TString denHist = hist_denr + hist_suffix + TString(Form("%02u",icomp)); + TString numPath = thePath + numHist; + TString denPath = thePath + denHist; + + // test if histograms are present + if(!f->Get(numPath)) { if(dbgLevel) std::cerr << "--> HLTMETAveragePhivsEtaMaps: no histogram " << numPath << std::endl; continue;} + if(!f->Get(denPath)) { if(dbgLevel) std::cerr << "--> HLTMETAveragePhivsEtaMaps: no histogram " << denPath << std::endl; continue;} + + // get histograms + hnum = (TH2F *) (f->Get(numPath)); + hden = (TH2F *) (f->Get(denPath)); + + // get directory of histograms + TDirectory* dir = f->GetDirectory(thePath); + + // these are disabled, because we have to worry about updating metadata + // clone numerator histogram in the same directory; prepend with "avg_" + // use numerator to do the job + //TString avgHist = TString("avg_") + (*itNum) + hist_suffix + TString(Form("%02u",icomp)); + //havg = (TH2F *) (hnum->Clone(avgHist)); + //havg->SetDirectory(dir); + + // divide num by den to get average quantity. + hnum->Divide(hnum,hden); + + // fix histogram titles + TString title = hnum->GetTitle(); + title.ReplaceAll(": ",": #LT"); + title.ReplaceAll("(#eta","#GT(#eta"); + hnum->SetTitle(title); + + //title = hden->GetTitle(); + ////std::cout << title << std::endl; + //title.ReplaceAll(" #phi VS #eta",": N(#eta, #phi)"); + //hden->SetTitle(title); + + //std::cout << numHist << " div " << denHist << std::endl; + //std::cout << hnum->GetZaxis()->GetTitle() << "\t"; + //std::cout << hden->GetZaxis()->GetTitle() << std::endl; + //std::cout << hnum->GetTitle() << "\t"; + //std::cout << hden->GetTitle() << std::endl; + //std::cout << "-------------------------------------------------------------" << std::endl; + //getchar(); + // cd() into that directory and save the avg histogram in file + dir->cd(); + hnum->Write("",TObject::kOverwrite); + + } // done looping over components + } // done looping over quantities + } // done looping over directories + + } // end while loop over all keys + } // end method MonitoringFile::HLTMETAveragePhivsEtaMaps + +} // end namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMETDQFlagSummary.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMETDQFlagSummary.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1f4c10bf0f6ac4affc40891b5ac74e4da9939436 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMETDQFlagSummary.cxx @@ -0,0 +1,279 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/* HLTMET Post Processing Method: In the HLT/MET[Mon/Mon_allCells/Mon_FEB]/DQPlots directory, there are + * three summary histograms: L2_MET-status, EF_MET_status and and compN_compSumEt_lin + * and lumi-block based histogram: trmet_lbn_flag + * This post-processing method fills these histograms appropriately + * Author : Venkatesh Kaushik <venkat.kaushik@cern.ch> + * Date : Mar 2010 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH1I.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + +namespace dqutils { + + //--------------------------------------------------------------------------------------------------- + // Method to obtain summary DQFlags + //--------------------------------------------------------------------------------------------------- + void MonitoringFile::HLTMETDQFlagSummary(TFile* f, TString& run_dir) { + + bool dbgLevel = false; + if(dbgLevel) std::cout << "--> HLTMETDQFlagSummary: Updating histograms in HLT/METMon*/DQPlots " << std::endl; + + f->cd("/"); + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + run_dir = key_run->GetName(); + if (!run_dir.Contains("run") ) { continue;} + + TDirectory* tdir_run = dynamic_cast<TDirectory*>( key_run ); + + std::string run_dir2 = run_dir.Data(); + + // all merged root files have the structure "rootfile.root:/run_NNNNNNN" + // use that to extract run number + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + // begin HLTMET + // note 1: prefix all dirs and hists with '/' + // note 2: missing dir => return + // note 3: missing hist => continue + TString hlt_top = run_dir + "/HLT"; // toplevel + TString met_efdir = "/EFMissingET_Fex"; // EF dir + TString met_l2dir = "/L2MissingET_Fex"; // L2 dir + TString dqflag_dir = "/DQFlags"; // DQ flags dir + + std::vector<TString> met_fexs, met_l2hists, met_efhists; + // expect the following fex dirs + met_fexs.push_back("/METMon"); + //met_fexs.push_back("/METMon_FEB"); + //met_fexs.push_back("/METMon_allCells"); + + // expect the following histograms + met_l2hists.push_back("/L2_MET_status"); + met_l2hists.push_back("/L2_MEx_log"); + met_l2hists.push_back("/L2_MEy_log"); + met_l2hists.push_back("/L2_MET_log"); + met_l2hists.push_back("/L2_SumEt_log"); + + met_efhists.push_back("/EF_MET_status"); + met_efhists.push_back("/EF_MET_lin"); + met_efhists.push_back("/EF_MET_lin1"); + met_efhists.push_back("/EF_SumEt_lin"); + met_efhists.push_back("/EF_MET_phi"); + met_efhists.push_back("/EF_MET_phi1"); + met_efhists.push_back("/EF_MEx_log"); + met_efhists.push_back("/EF_MEy_log"); + met_efhists.push_back("/compN_compSumEt_lin"); + met_efhists.push_back("/compN_EF_MET_status"); + + std::vector<TString> lbnDirs; + TString lbn_dqhist = "/trmet_lbn_flag"; + size_t lbn_range = HLTMETGetDQLBNRange(tdir_run, lbnDirs); + + //std::cout << "lbn_range = " << lbn_range << std::endl; + + // Get EF/L2 status histograms for default Fex + for( std::vector<TString>::iterator itFex = met_fexs.begin(); itFex != met_fexs.end(); itFex++ ) { + TString theL2Path = hlt_top + (*itFex) + met_l2dir; + TString theEFPath = hlt_top + (*itFex) + met_efdir; + TString theDQPath = hlt_top + (*itFex) + dqflag_dir; + + TDirectory* dirl2 = f->GetDirectory(theL2Path); + if(!dirl2){ + std::cerr << "--> HLTMETDQFlagSummary: directory " << theL2Path << " not found" << std::endl; + return; + } + TDirectory* diref = f->GetDirectory(theEFPath); + if(!diref){ + std::cerr << "--> HLTMETDQFlagSummary: directory " << theEFPath << " not found" << std::endl; + return; + } + TDirectory* dirdq = f->GetDirectory(theDQPath); + if(!dirdq){ + std::cerr << "--> HLTMETDQFlagSummary: directory " << theDQPath << " not found" << std::endl; + return; + } + // loop over L2 hists and copy to DQFlags + for(std::vector<TString>::iterator itHist = met_l2hists.begin(); itHist != met_l2hists.end(); itHist++ ) { + TString histL2 = (theL2Path + *itHist); + TString histL2C = (theDQPath + *itHist); + TH1 *hl2(0), *hl2c(0); + if(!f->Get(histL2)) { if(dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histL2 << std::endl; continue;} + if(!f->Get(histL2C)) { if(dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histL2C << std::endl; continue;} + hl2 = (TH1 *) (f->Get(histL2)); + // check if MET_status histogram is emtpy + bool save_status_hist = false; + if(*itHist == "/L2_MET_status") { + if(hl2->GetMaximum() < 1.e-3) { + save_status_hist = true; + for(int ibin = 1; ibin <= hl2->GetNbinsX(); ibin++) { + hl2->SetBinContent(ibin,0.05); + } + } + } + hl2c = (TH1 *) (f->Get(histL2C)); + hl2c->Reset(); + hl2c->Add(hl2); + //hl2c->Sumw2(); + //std::cout << "--> HLTMETDQFlagSummary: added histograms " << histL2 << "\t and " << histL2C << std::endl; + dirdq->cd(); + hl2c->Write("",TObject::kOverwrite); + if(save_status_hist) { + if(f->cd(theL2Path)) + hl2->Write("",TObject::kOverwrite); + } + + } // end loop over l2 hists + + // loop over EF hists and copy to DQFlags + for(std::vector<TString>::iterator itHist = met_efhists.begin(); itHist != met_efhists.end(); itHist++ ) { + TString histEF = (theEFPath + *itHist); + TString histEFC = (theDQPath + *itHist); + TH1 *hef(0), *hefc(0); + if(!f->Get(histEF)) { if(dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histEF << std::endl; continue;} + if(!f->Get(histEFC)) { if(dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histEFC << std::endl; continue;} + hef = (TH1 *) (f->Get(histEF)); + bool save_status_hist = false; + if(*itHist == "/EF_MET_status") { + if(hef->GetMaximum() < 1.e-3) { + save_status_hist = true; + for(int ibin = 1; ibin <= hef->GetNbinsX(); ibin++) { + hef->SetBinContent(ibin,0.05); + } + } + } + hefc = (TH1 *) (f->Get(histEFC)); + hefc->Reset(); + hefc->Add(hef); + //hefc->Sumw2(); + dirdq->cd(); + if(save_status_hist) { + if(f->cd(theEFPath)) + hef->Write("",TObject::kOverwrite); + } + hefc->Write("",TObject::kOverwrite); + } // end loop over ef hists + + // resize lbn based histogram + if(lbn_range > 0) { + TString histLBN = theDQPath + lbn_dqhist; + TH1 *hlb(0); + if(!f->Get(histLBN)) { if(dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histLBN << std::endl; continue;} + hlb = (TH1 *) (f->Get(histLBN)); + unsigned int nbinx = (unsigned int) hlb->GetNbinsX(), nbiny = (unsigned int) hlb->GetNbinsY(), k = 1; + if(nbinx != nbiny) continue; + + if(lbn_range < nbinx) { + hlb->GetXaxis()->SetRangeUser(0,Double_t(lbn_range)); + hlb->GetYaxis()->SetRangeUser(0,Double_t(lbn_range)); + } + TH1I *hlbstat(0); + for(std::vector<TString>::iterator it = lbnDirs.begin(); it != lbnDirs.end(); it++, k++) { + if(k > nbinx) continue; + TString histLBstat = run_dir + TString("/") + *it + TString("/HLT") + (*itFex) + "/lbnstatus/EF_MET_status"; + if(!f->Get(histLBstat)) { if(dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histLBstat << std::endl; continue; } + hlbstat = (TH1I *) (f->Get(histLBstat)); + int flag = HLTMETGetStatusPerBin(hlbstat,17,29,32,32); + //std::cout << "--> HLTMETDQFlagSummary: " << *it << "\t: flag = " << flag << std::endl; + TString label = *it; + label.ReplaceAll("lowStat_",""); + hlb->GetXaxis()->SetBinLabel(k,label.Data()); + hlb->GetYaxis()->SetBinLabel(k,label.Data()); + hlb->SetBinContent(k,k,flag); + } // end for + hlb->Write("",TObject::kOverwrite); + } else { + std::cerr << "--> HLTMETDQFlagSummary: lowStat_* directories: found none " << std::endl; + } + + + + } // end loop over fexs + + + + } // end while loop over all keys + } // end method MonitoringFile::HLTMETDQFlagSummary + + //--------------------------------------------------------------------------------------------------- + // Method to get lowStat_* directories + //--------------------------------------------------------------------------------------------------- + size_t MonitoringFile::HLTMETGetDQLBNRange(TDirectory*& run_dir, std::vector<TString>& lbnDirs) { + + if(!run_dir) return 0; + lbnDirs.clear(); + + bool dbgLevel = false; + if(dbgLevel) std::cout << "--> HLTMETGetDQLBNRange: lowStat_* directories: "; + run_dir->cd(); + + TIter next_lbn ( run_dir->GetListOfKeys() ); + TKey* key_lbn(0); + TString lbn_dir=""; + // loop over all objects + while ((key_lbn = dynamic_cast<TKey*> ( next_lbn() )) !=0 ) { + if (!key_lbn->IsFolder()) continue; + lbn_dir = key_lbn->GetName(); + if (!lbn_dir.Contains("lowStat_") ) { continue; } + lbnDirs.push_back(lbn_dir); + //std::cout << "dir = " << lbn_dir << "\tuuid = " << uuid.AsString() << "\ttime = " << dtme.GetTime() << std::endl; + } + unsigned int nLBNDirs = lbnDirs.size(); + if(dbgLevel) std::cout << "found " << nLBNDirs << std::endl; + return nLBNDirs; + } // end method MonitoringFile::HLTMETGetDQLBNRange + + //--------------------------------------------------------------------------------------------------- + // Method to Get Status flags per lbn block + //--------------------------------------------------------------------------------------------------- + int MonitoringFile::HLTMETGetStatusPerBin(TH1I *&hist, int yellmin, int yellmax, int redmin, int redmax) { + if(!hist) return 0; + TString hname = hist->GetName(); + int flag = 10; // 1 == GREEN, 2 == YELLOW, 3 == RED + float epsilon = 1.e-3; + int nbins = (int) hist->GetNbinsX(); + yellmin = (yellmin > 0 && yellmin <= nbins) ? yellmin : 1; + yellmax = (yellmax > 0 && yellmax <= nbins) ? yellmax : nbins; + redmin = (redmin > 0 && redmin <= nbins) ? redmin : 1; + redmax = (redmax > 0 && redmax <= nbins) ? redmax : nbins; + for(int k = 1; k <= nbins; k++) { + float theVal = hist->GetBinContent(k); + // at least one bin > 0 + if(theVal > epsilon) { + if(k >= yellmin && k <= yellmax) flag = 100; + if(k >= redmin && k <= redmax) flag = 1000; + } // end if + } // end for + return flag; + } // end method MonitoringFile::HLTMETGetStatusPerBin + +} // end namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMETPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMETPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0fe1fdb0eff4e7c2889e3e08541d26063620d9b5 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMETPostProcess.cxx @@ -0,0 +1,118 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +/* Methods to perform post-processing on run_nnnnnn/HLT/METMon* histograms + * Author : Venkatesh Kaushik (venkat.kaushik@cern.ch) + * Date : Feb 2010 + */ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + + + +namespace dqutils { + + static const bool hltmet_debug = false; + + void + MonitoringFile::HLTMETPostProcess( std::string inFilename, bool /* isIncremental */ ) + { + bool dbgLevel = false; + if(dbgLevel) std::cout << "--> HLTMETPostProcess: Begin HLTMET post-processing" << std::endl; + + //open root file + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + //check files are loaded. + + if (f == 0 || ! f->IsOpen() ) { + std::cerr << "--> HLTMETPostProcess: Input file not opened" << std::endl; + return; + } + + if(f->IsZombie()) { + std::cerr << "--> HLTMETPostProcess: Input file " << inFilename << " cannot be opened. " << std::endl; + return; + } + + //check file size is not too small. + if(f->GetSize()<1000.) { + std::cerr << "--> HLTMETPostProcess: Input file empty" << std::endl; + f->Close(); + return; + } + + //start postprocessing + TString run_dir; + HLTMETAveragePhivsEtaMaps( f, run_dir); + HLTMETDQFlagSummary(f, run_dir); + //close root file + f->Close(); + delete f; + + if(dbgLevel) std::cout << "--> HLTMETPostProcess: End HLTMET post-processing "<<std::endl; + + return; + + } + + /*unsigned int MonitoringFile::HLTMETGetDQLBNRange(TDirectory*& run_dir) { + + if(!run_dir) return 0; + std::cout << "--> : HLTMETGetDQLBNRange: looking for lb_* directories inside " << run_dir->GetName() << " for [L2/EF]_MET_status flags." << std::endl; + run_dir->cd(); + + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(run_dir->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + //dir0->pwd(); //dir0->ls(); + dir0->cd(); + + + TIter next_lbn ( run_dir->GetListOfKeys() ); + TKey* key_lbn(0); + + // loop over all objects + std::vector<TString> lbnDirs; + while ((key_lbn = dynamic_cast<TKey*> ( next_lbn() )) !=0 ) { + TObject* obj_lbn = key_lbn->ReadObj(); + TDirectory* tdir_lbn = dynamic_cast<TDirectory*>( obj_lbn ); + if (tdir_lbn ==0 ){ delete obj_lbn; continue; } + TString lbn_dir = tdir_lbn->GetName(); + if (!lbn_dir.Contains("lb_") ) {delete obj_lbn; continue;} + std::cout << "--> HLTMETGetDQLBNRange: found lbn directory named " << lbn_dir << std::endl; + lbnDirs.push_back(lbn_dir); + } + return lbnDirs.size(); + }*/ + + + +}//namespace + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMuonHistogramDivision.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMuonHistogramDivision.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3cb1df6a0a0cc607b423dc4aa9d3bf442e618761 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMuonHistogramDivision.cxx @@ -0,0 +1,3636 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//Methods to Divide HLTMuon Histograms to calculate efficiency and occupancy after merging. +//Author: Akimasa Ishikawa (akimasa.ishikawa@cern.ch) +//Date: Aug 2009 +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" +#include "TGraph.h" +#include "TGraphAsymmErrors.h" + + +namespace dqutils { + + static const bool fdbg = false; + // static const bool fdbg = true; + + void + MonitoringFile::HLTMuonHistogramDivision(std::string inFilename, TString& run_dir) + { + + if (fdbg) std::cout << " Start to Divide HLTMuon Histograms for Efficiency and Rate Ratio" << std::endl; + + PostProcessorFileWrapper mf( inFilename , "HLT Histogram Division"); + if (!mf.IsOpen()) { + std::cerr << "HLTMuonPostProcess(): " + << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + std::cerr << "HLTMuonPostProcess(): " + << "Input file empty \n"; + return; + } + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + if (key0 == 0) return; + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + if (dir0 == 0) return; + dir0->cd(); + /// + + // 110728: removing the iteration of searching run directory according to the new MDT code + /* TIter next_run (mf.GetListOfKeys()); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { //== the while commented out at the end + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if (tdir_run ==0 ) { + delete obj_run; + continue; + } // no deleting + run_dir = tdir_run->GetName(); + if (!run_dir.Contains("run") ) { + delete obj_run; + continue; + } // no deleting */ + + { + run_dir = dir0->GetName(); + if (fdbg) { + std::cout << "HLTMuon: run directory is " << run_dir << std::endl; + } + std::string run_dir2 = run_dir.Data(); + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + //===HLTMuon + TString muon_dir = run_dir + "/HLT/MuonMon/"; + + TString cm_dir = muon_dir + "Common/"; + TString mf_dir = muon_dir + "muFast/"; + TString mc_dir = muon_dir + "muComb/"; + TString mi_dir = muon_dir + "muIso/"; + TString tm_dir = muon_dir + "TileMu/"; + TString ef_dir = muon_dir + "MuonEF/"; + TString mg_dir = muon_dir + "MuGirl/"; + // YY added + TString ztp_dir = muon_dir + "MuZTP/"; + + TString eff_dir = muon_dir + "Efficiency/"; + TString nd_dir = muon_dir + "Efficiency/NumDenom/"; + TString rate_dir = muon_dir + "Rate/"; + TString rr_dir = muon_dir + "Rate/Ratio/"; + + TString seff; + TString seffg; // YY added + TString snum; + TString sden; + + TH1F* h1eff(0); + TH1F* h1num(0); + TH1F* h1den(0); + TH1F* h1sumeff(0); // new YY + TGraphAsymmErrors* geff(0); + + //==Efficiency + // muFast efficiency + TDirectory* dir = mf.GetDirectory(eff_dir); + if(!dir){ + std::cerr<< "HLTMuonHistogramDivision: directory "<<eff_dir<<" not found"<<std::endl; + return; + } + + std::vector<TString> effnames; + effnames.push_back("muFast_effi_toRecMuonCB_pt"); + effnames.push_back("muFast_effi_toRecMuonCB_pt_barrel"); + effnames.push_back("muFast_effi_toRecMuonCB_pt_endcap"); + effnames.push_back("muFast_effi_toRecMuonCB_eta"); + effnames.push_back("muFast_effi_toRecMuonCB_phi"); + + for( std::vector<TString>::iterator it = effnames.begin(); it != effnames.end(); it++ ){ + seff = eff_dir + (*it); + snum = mf_dir + (*it) + "_numer"; + sden = mf_dir + (*it) + "_denom"; + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if( h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + + }//effnames + mf.Write(); + + // muComb efficiency + effnames.clear(); + effnames.push_back("muComb_effi_toOffl_pt"); + effnames.push_back("muComb_effi_toOffl_pt_barrel"); + effnames.push_back("muComb_effi_toOffl_pt_endcap"); + effnames.push_back("muComb_effi_toOffl_eta"); + effnames.push_back("muComb_effi_toOffl_phi"); + + for( std::vector<TString>::iterator it = effnames.begin(); it != effnames.end(); it++ ){ + seff = eff_dir + (*it); + snum = mc_dir + (*it) + "_numer"; + sden = mc_dir + (*it) + "_denom"; + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if( h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + + }//effnames + mf.Write(); + + // muIso efficiency + effnames.clear(); + effnames.push_back("muIso_effi_toOffl_pt"); + + for( std::vector<TString>::iterator it = effnames.begin(); it != effnames.end(); it++ ){ + seff = eff_dir + (*it); + snum = mi_dir + (*it) + "_numer"; + sden = mi_dir + (*it) + "_denom"; + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if( h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + + }//effnames + mf.Write(); + + // TileMu efficiency + effnames.clear(); + std::vector<TString> numnames; + std::vector<TString> dennames; + effnames.push_back ("TileMu_RecCBMuon_EffEta"); + numnames.push_back ("Rec_Eta_Num"); + dennames.push_back("Rec_Eta"); + effnames.push_back ("TileMu_RecCBMuon_EffPhi"); + numnames.push_back ("Rec_Phi_Num"); + dennames.push_back("Rec_Phi"); + effnames.push_back ("TileTrackMu_RecCBMuon_EffEta"); + numnames.push_back ("TileTrackMu_Eta"); + dennames.push_back("Rec_Eta"); + effnames.push_back ("TileTrackMu_RecCBMuon_EffPhi"); + numnames.push_back ("TileTrackMu_Phi"); + dennames.push_back("Rec_Phi"); + effnames.push_back ("TileTrackMu_RecCBMuon_EffPt"); + numnames.push_back ("TileTrackMu_Pt"); + dennames.push_back("Rec_Pt"); + + for( unsigned int i=0; i < effnames.size() ; i++ ){ + seff = eff_dir + effnames.at(i); + snum = tm_dir + numnames.at(i); + sden = tm_dir + dennames.at(i); + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if( h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + + }//effnames + mf.Write(); + + // MuonEF efficiency + effnames.clear(); + numnames.clear(); + dennames.clear(); + effnames.push_back("EFMS_effi_toOffl_pt"); + effnames.push_back("EFMS_effi_toOffl_eta"); + effnames.push_back("EFMS_effi_toOffl_phi"); + effnames.push_back("EFSA_effi_toOffl_pt"); + effnames.push_back("EFCB_effi_toOffl_pt"); + + for( std::vector<TString>::iterator it = effnames.begin(); it != effnames.end(); it++ ){ + seff = eff_dir + (*it); + snum = ef_dir + (*it) + "_numer"; + sden = ef_dir + (*it) + "_denom"; + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if( h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + + }//effnames + mf.Write(); + + // MuGirl efficiency + //==Turn on + std::vector<TString> m_chainsMSonly; + std::vector<TString> m_chainsStandard; + std::vector<TString> m_chainsMG; + std::vector<TString> m_chainsMI; + std::vector<TString> m_chainsGeneric; + std::vector<TString> m_chainsEFiso; + std::vector<TString> m_chainsEFFS; + + // Generic (EFsuper etc.) + m_chainsGeneric.push_back("mu36_tight"); // v4 primary + + // Generic (Isolated muons) + m_chainsEFiso.push_back("mu24i_tight") ; // v4 primary + + // MSonly + m_chainsMSonly.push_back("mu50_MSonly_barrel_tight"); // v4 primary + + // EFFS triggers (L. Yuan) + m_chainsEFFS.push_back("mu18_tight_mu8_EFFS"); + + enum indexINDEP { INDORTH, INDEGAMMA, INDMET, INDJET, INDTAU, INDMBIAS }; + TString m_trigger[INDMBIAS + 1]; + + m_trigger[INDORTH] = "Orthog";//EGamma + Tau + Jet + MET + m_trigger[INDEGAMMA] = "EGamma"; + m_trigger[INDMET] = "MET"; + m_trigger[INDJET] = "Jet"; + + int m_maxindep = 0; // YY 20.01.2012 + + // YY added: + TString m_ESchainName = "_ES"; + + TString bestr[2] = {"_Barrel", "_Endcap"}; + + // made it as enum: 20.1.2012 + std::string m_triggerES[7] = {"_ESstd", "_EStag", "_ESid", "_ESindep", "_ESHIL1", "_ESHIid", "_ESHIindep"}; + enum indexES { ESSTD, ESTAG, ESID, ESINDEP, ESHIL1, ESHIID, ESHIINDEP }; + + int m_maxESbr = ESINDEP; + + bool CB_mon_ESbr[ESHIINDEP + 1]; + bool MS_mon_ESbr[ESHIINDEP + 1]; + + CB_mon_ESbr[ESSTD] = 0; + CB_mon_ESbr[ESTAG] = 0; + CB_mon_ESbr[ESID] = 1; + CB_mon_ESbr[ESINDEP] = 1; + CB_mon_ESbr[ESHIL1] = 0; + CB_mon_ESbr[ESHIID] = 0; + CB_mon_ESbr[ESHIINDEP] = 0; + + MS_mon_ESbr[ESSTD] = 0; + MS_mon_ESbr[ESTAG] = 1; + MS_mon_ESbr[ESID] = 0; + MS_mon_ESbr[ESINDEP] = 1; + MS_mon_ESbr[ESHIL1] = 0; + MS_mon_ESbr[ESHIID] = 0; + MS_mon_ESbr[ESHIINDEP] = 0; + + std::vector<std::string> m_vectkwd; + + m_vectkwd.push_back(m_triggerES[ESTAG]); + m_vectkwd.push_back(m_triggerES[ESID]); + m_vectkwd.push_back("_Jet"); + m_vectkwd.push_back("_all"); + + TString m_hptName = "_hpt"; + TString m_MSchainName = "_MSb"; + + // YY: pt range. + int iSTDL = 91; // 40 GeV + int iSTDH = 112; // 80 GeV + int iMSL = 105; // 60 GeV + int iMSH = 120; // 100 GeV + + // YY added: + enum ieffAlgo { + iMuFast = 0, // StdAlgo + iMuComb = 1, // StdAlgo + iEFCB = 2, // StdAlgo + iMuGirl = 3, // StdAlgo + + iEFSA = 1 // MSAlgo + }; + + // Standard Chains + //TString m_alg[5] = {"_MuFast", "_MuComb", "_MuonEFMS", "_MuonEFSA", "_MuonEFCB"}; + //TString m_wrtalg[5] = {"_L1", "_MuFast", "_MuComb", "_MuComb", "_MuComb"}; + + + // ******************************************************// + // start the code add by Yuan // + TString FS_pre_trigger = "mu18it_tight"; + for(unsigned int i=0; i<m_chainsEFFS.size(); i++){ + TString chainName = m_chainsEFFS.at(i); + + TString hists_str[9] = {chainName + "_tagMu18it" + "_Turn_On_Curve_wrt_probe_MuidCB", + chainName + "_tagMu18it" + "_Turn_On_Curve_wrt_probe_MuidCB_Barrel", + chainName + "_tagMu18it" + "_Turn_On_Curve_wrt_probe_MuidCB_Endcap", + chainName + "_tagMu18it_mu0_15" + "_Turn_On_Curve_wrt_probe_MuidCB", + chainName + "_tagMu18it_mu15_20" + "_Turn_On_Curve_wrt_probe_MuidCB", + chainName + "_tagMu18it_mu20" + "_Turn_On_Curve_wrt_probe_MuidCB", + chainName + "_Turn_On_Curve_wrt_subleading_MuidCB", + FS_pre_trigger + "_dimuonTP" + "_Turn_On_Curve_wrt_probe_MuidCB", + FS_pre_trigger + "_dimuonTP" + "_Turn_On_Curve_wrt_L1_probe_MuidCB", + }; + + + bool for_mydebug = true; + for(int iROI = 0; iROI < 9; iROI++){ + sden = nd_dir + hists_str[iROI] + "_Denominator"; + snum = nd_dir + hists_str[iROI] + "_Numerator"; + seff = eff_dir + hists_str[iROI]; + seffg = seff + "_Fit"; + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + } // end the loop on individual turn-on curves + + TString L1_TP_str = FS_pre_trigger + "_dimuonTP_L1" + "_Turn_On_Curve_wrt_probe_MuidCB"; + sden = nd_dir + FS_pre_trigger + "_dimuonTP" + "_Turn_On_Curve_wrt_probe_MuidCB" + "_Denominator"; + snum = nd_dir + FS_pre_trigger + "_dimuonTP" + "_Turn_On_Curve_wrt_L1_probe_MuidCB" + "_Denominator"; + seff = eff_dir + L1_TP_str; + seffg = seff + "_Fit"; + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + //**** summargy plot **********// + + TString histNumB = nd_dir + chainName +"_tagMu18it_Turn_On_Curve_wrt_probe_MuidCB_Barrel_Numerator"; + TString histDenB = nd_dir + chainName +"_tagMu18it_Turn_On_Curve_wrt_probe_MuidCB_Barrel_Denominator"; + TString histNumE = nd_dir + chainName +"_tagMu18it_Turn_On_Curve_wrt_probe_MuidCB_Endcap_Numerator"; + TString histDenE = nd_dir + chainName +"_tagMu18it_Turn_On_Curve_wrt_probe_MuidCB_Endcap_Denominator"; + TString histL1sum = eff_dir + chainName + "_EFplateau_wrtOffline"; + + TH1F *h1numb = 0; mf.get(histNumB, h1numb); + if (!h1numb) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histNumB << std::endl; + } + continue; + } + TH1F *h1nume = 0; mf.get(histNumE, h1nume); + if (!h1nume) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histNumE << std::endl; + } + continue; + } + TH1F *h1denb = 0; mf.get(histDenB, h1denb); + if (!h1denb) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histDenB << std::endl; + } + continue; + } + TH1F *h1dene = 0; mf.get(histDenE, h1dene); + if (!h1dene) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histDenE << std::endl; + } + continue; + } + TH1F *h1sumL = 0; mf.get(histL1sum, h1sumL); + if (!for_mydebug) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histL1sum << std::endl; + } + continue; + } + + int m_iSTDL = 39; + int m_iSTDH = 120; + double sumeff, sumerr; + double sumn = h1numb->Integral(m_iSTDL, m_iSTDH); // 10-100 GeV + double sumd = h1denb->Integral(m_iSTDL, m_iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double) sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + + h1sumL->SetBinContent(1, sumeff); + h1sumL->SetBinError(1, sumerr); + + sumn = h1nume->Integral(m_iSTDL, m_iSTDH); + sumd = h1dene->Integral(m_iSTDL, m_iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double) sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + h1sumL->SetBinContent(2, sumeff); + h1sumL->SetBinError(2, sumerr); + + dir->cd(); + h1sumL->Write("",TObject::kOverwrite); + + TString histNum_mu0_15 = nd_dir + chainName +"_tagMu18it_mu0_15_Turn_On_Curve_wrt_probe_MuidCB_Numerator"; + TString histDen_mu0_15 = nd_dir + chainName +"_tagMu18it_mu0_15_Turn_On_Curve_wrt_probe_MuidCB_Denominator"; + TString histNum_mu15_20 = nd_dir + chainName +"_tagMu18it_mu15_20_Turn_On_Curve_wrt_probe_MuidCB_Numerator"; + TString histDen_mu15_20 = nd_dir + chainName +"_tagMu18it_mu15_20_Turn_On_Curve_wrt_probe_MuidCB_Denominator"; + TString histNum_mu20 = nd_dir + chainName +"_tagMu18it_mu20_Turn_On_Curve_wrt_probe_MuidCB_Numerator"; + TString histDen_mu20 = nd_dir + chainName +"_tagMu18it_mu20_Turn_On_Curve_wrt_probe_MuidCB_Denominator"; + TString histEFsum_mu = eff_dir + chainName + "_EFplateau_wrtOffline_mu_dependence"; + + TH1F *h1num_mu0_15 = 0; mf.get(histNum_mu0_15, h1num_mu0_15); + if (!h1num_mu0_15) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histNum_mu0_15 << std::endl; + } + continue; + } + + TH1F *h1num_mu15_20 = 0; mf.get(histNum_mu15_20, h1num_mu15_20); + if (!h1num_mu15_20) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histNum_mu15_20 << std::endl; + } + continue; + } + + TH1F *h1num_mu20 = 0; mf.get(histNum_mu20, h1num_mu20); + if (!h1num_mu20) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histNum_mu20 << std::endl; + } + continue; + } + + TH1F *h1den_mu0_15 = 0; mf.get(histDen_mu0_15, h1den_mu0_15); + if (!h1den_mu0_15) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histDen_mu0_15 << std::endl; + } + continue; + } + + TH1F *h1den_mu15_20 = 0; mf.get(histDen_mu15_20, h1den_mu15_20); + if (!h1den_mu15_20) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histDen_mu15_20 << std::endl; + } + continue; + } + + TH1F *h1den_mu20 = 0; mf.get(histDen_mu20, h1den_mu20); + if (!h1den_mu20) { + if (for_mydebug) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histDen_mu20 << std::endl; + } + continue; + } + + TH1F *h1sum_mu = 0; mf.get(histEFsum_mu, h1sum_mu); + if (!for_mydebug) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histEFsum_mu << std::endl; + } + continue; + } + + sumn = h1num_mu0_15->Integral(m_iSTDL, m_iSTDH); // 10-100 GeV + sumd = h1den_mu0_15->Integral(m_iSTDL, m_iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double) sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + + h1sum_mu->SetBinContent(1, sumeff); + h1sum_mu->SetBinError(1, sumerr); + + sumn = h1num_mu15_20->Integral(m_iSTDL, m_iSTDH); + sumd = h1den_mu15_20->Integral(m_iSTDL, m_iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double) sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + h1sum_mu->SetBinContent(2, sumeff); + h1sum_mu->SetBinError(2, sumerr); + + sumn = h1num_mu20->Integral(m_iSTDL, m_iSTDH); + sumd = h1den_mu20->Integral(m_iSTDL, m_iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double) sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + h1sum_mu->SetBinContent(3, sumeff); + h1sum_mu->SetBinError(3, sumerr); + + dir->cd(); + h1sum_mu->Write("",TObject::kOverwrite); + + + mf.Write(); + } + // end of the code add by Yuan // + // ******************************************************// + + + // ******************************************************// + // ********************* MuGirl ***********************// + // ******************************************************// + for (unsigned int i=0 ; i < m_chainsMG.size() ; i++) { + TString chainName = m_chainsMG.at(i); + + std::string chainName_std = (std::string)chainName; + int nnn = chainName_std.find("_MG"); + if (0 == nnn) { + if (fdbg) { + std::cerr << "ChainName does not look like muGirl chain" << chainName << std::endl; + } + } else { + chainName_std.replace(nnn, 3, ""); + } + + // MuGirl: begin + TString m_alg[2] = {"_MuGirlL2", "_MuGirlEF"}; + TString m_wrtalg[2] = {"_L1", "_MuGirlL2"}; + + // wrt CB Muon && independent trigger + for( int trg = 0 ; trg < m_maxindep ; trg++ ){ + sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidCB" + m_trigger[trg] + "_Triggered_Denominator"; + + for( int alg=0; alg < 2; alg++){ + snum = nd_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt_MuidCB" + m_trigger[trg] + "_Triggered_Numerator"; + seff = eff_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt_MuidCB" + m_trigger[trg] + "_Triggered"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if( h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + if (1 == alg) { // MuGirlEF + if (3 == trg) { // jet + double sumd, sumn, sumeff, sumerr; + sumn = h1num->Integral(iSTDL, iSTDH); + sumd = h1den->Integral(iSTDL, iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double)sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + int iholx = static_cast<int>(iMuGirl); + + + TString s = eff_dir + chainName_std + "_highpt_effsummary_by" + m_vectkwd.at(2); + // std::cout << "hist summary: " << s << " n: " << sumn << " d: " << sumd << " eff: " << sumeff << " err: " << sumerr << std::endl; + mf.get(s, h1sumeff); + if (!h1sumeff) { + if (fdbg) { + std::cerr << "HLTMuon PostProcessing: no such histogram!! " << s << std::endl; + } + continue; + } + h1sumeff->SetBinContent(iholx+1, sumeff); + h1sumeff->SetBinError(iholx+1, sumerr); + // saving + dir->cd(); + h1sumeff->Write("", TObject::kOverwrite); + } + } + } + + }//alg + }//trg + mf.Write(); + + for (int alg = 0; alg < 2; alg++){ + //wrt MuidCB + sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidCB_Denominator"; + snum = nd_dir + chainName + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt_MuidCB"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + + if (1 == alg) { // MuGirlEF, all events + double sumd, sumn, sumeff, sumerr; + sumn = h1num->Integral(iSTDL, iSTDH); + sumd = h1den->Integral(iSTDL, iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double)sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + int iholx = static_cast<int>(iMuGirl); + + TString s = eff_dir + chainName_std + "_highpt_effsummary_by" + m_vectkwd.at(3); + // std::cerr << "hist summary: " << s << " n: " << sumn << " d: " << sumd << " eff: " << sumeff << " err: " << sumerr << std::endl; + mf.get(s, h1sumeff); + if (!h1sumeff) { + if (fdbg) { + std::cerr << "HLTMuon PostProcessing: no such histogram!! " << s << std::endl; + } + continue; + } + h1sumeff->SetBinContent(iholx+1, sumeff); + h1sumeff->SetBinError(iholx+1, sumerr); + // saving + dir->cd(); + h1sumeff->Write("", TObject::kOverwrite); + } + } + + //wrt MuidCB + MSonly-based chain + sden = nd_dir + chainName + m_MSchainName + "_Turn_On_Curve_wrt_MuidCB_Denominator"; + snum = nd_dir + chainName + m_MSchainName + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_MSchainName + m_alg[alg] + "_Turn_On_Curve_wrt_MuidCB"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + // for ES --------------------------------------------------------------------- + for (int ies = 0; ies <= m_maxESbr; ies++) { + sden = nd_dir + chainName + m_triggerES[ies] + "_Turn_On_Curve_wrt_MuidCB_Denominator"; + snum = nd_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_wrt_MuidCB"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + // Summary ESid + if (1 == alg) { // MuGirlEF + if (ESID == ies || ESINDEP == ies) { + double sumd, sumn, sumeff, sumerr; + sumn = h1num->Integral(iSTDL, iSTDH); + sumd = h1den->Integral(iSTDL, iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double)sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + int iholx = static_cast<int>(iMuGirl); + + TString s = eff_dir + chainName_std + "_highpt_effsummary_by" + m_triggerES[ies]; + // std::cerr << "hist summary: " << s << " n: " << sumn << " d: " << sumd << " eff: " << sumeff << " err: " << sumerr << std::endl; + mf.get(s, h1sumeff); + if (!h1sumeff) { + if (fdbg) { + std::cerr << "HLTMuon PostProcessing: no such histogram!! " << s << std::endl; + } + continue; + } + h1sumeff->SetBinContent(iholx+1, sumeff); + h1sumeff->SetBinError(iholx+1, sumerr); + // saving + dir->cd(); + h1sumeff->Write("", TObject::kOverwrite); + } + } + + } + } + // for ES: end --------------------------------------------------------------------- + + if (0 == alg || 1 == alg) { + for (int be = 0; be < 2; be++) { + sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator"; + snum = nd_dir + chainName + m_alg[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidCB"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + // MSonly-based monitor + sden = nd_dir + chainName + m_MSchainName + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator"; + snum = nd_dir + chainName + m_MSchainName + m_alg[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_MSchainName + m_alg[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidCB"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + } + } + + //wrt Upstream + sden = nd_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt"+ m_wrtalg[alg] + "_Denominator"; + snum = nd_dir + chainName + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt" + m_wrtalg[alg]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + + //wrt Upstream - MSonly-based + sden = nd_dir + chainName + m_MSchainName + m_alg[alg] + "_Turn_On_Curve_wrt"+ m_wrtalg[alg] + "_Denominator"; + snum = nd_dir + chainName + m_MSchainName + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_MSchainName + m_alg[alg] + "_Turn_On_Curve_wrt" + m_wrtalg[alg]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + // For ES -------------------------------------------------------------------------- + //wrt Upstream + for (int ies = 0; ies <= m_maxESbr; ies++) { + + sden = nd_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_wrt"+ m_wrtalg[alg] + "_Denominator"; + snum = nd_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_wrt" + m_wrtalg[alg]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + } + // For ES -------------------------------------------------------------------------- + + if (0 == alg || 1 == alg) { + for (int be = 0; be < 2; be++) { + //wrt Upstream + sden = nd_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt"+ m_wrtalg[alg] + bestr[be] + "_Denominator"; + snum = nd_dir + chainName + m_alg[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt" + m_wrtalg[alg] + bestr[be]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + sden = nd_dir + chainName + m_MSchainName + m_alg[alg] + "_Turn_On_Curve_wrt"+ m_wrtalg[alg] + bestr[be] + "_Denominator"; + snum = nd_dir + chainName + m_MSchainName + m_alg[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_MSchainName + m_alg[alg] + "_Turn_On_Curve_wrt" + m_wrtalg[alg] + bestr[be]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + } + }//alg + }//i + mf.Write(); + }// MuGirl: end + + // ******************************************************// + // *********** MuIso: no extention to high pt ***********// + // ******************************************************// + for (unsigned int i=0 ; i < m_chainsMI.size() ; i++) { + TString chainName = m_chainsMI.at(i); + + // MuIso: begin + TString m_alg[2] = {"_MuIso", "_MuonEFCB"}; + TString m_wrtalg[2] = {"_MuComb", "_MuIso"}; + + for( unsigned int i=0 ; i < m_chainsMI.size() ; i++ ){ + TString chainName = m_chainsMI.at(i); + + // wrt CB Muon && independent trigger + for( int trg = 0 ; trg < m_maxindep ; trg++ ){ + sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidCB" + m_trigger[trg] + "_Triggered_Denominator"; + + for( int alg=0; alg < 2; alg++){ + snum = nd_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt_MuidCB" + m_trigger[trg] + "_Triggered_Numerator"; + seff = eff_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt_MuidCB" + m_trigger[trg] + "_Triggered"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if( h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + }//alg + }//trg + mf.Write(); + + for (int alg = 0; alg < 2; alg++){ + //wrt MuidCB + sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidCB_Denominator"; + snum = nd_dir + chainName + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt_MuidCB"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + // for ES ------------------------------------------------------------------------------------ + for (int ies = 0; ies <= m_maxESbr; ies++) { + sden = nd_dir + chainName + m_triggerES[ies] + "_Turn_On_Curve_wrt_MuidCB_Denominator"; + snum = nd_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_wrt_MuidCB"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + } + // for ES : END ------------------------------------------------------------------------------------ + + sden = nd_dir + chainName + "_Efficiency_Curve_wrt_MuidCB_Denominator_vs_etcone40"; + snum = nd_dir + chainName + m_alg[alg] + "_Efficiency_Curve_Numerator_vs_etcone40"; + seff = eff_dir + chainName + m_alg[alg] + "_Efficiency_Curve_wrt_MuidCB_vs_etcone40"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + sden = nd_dir + chainName + "_Efficiency_Curve_wrt_MuidCB_Denominator_vs_ptcone40"; + snum = nd_dir + chainName + m_alg[alg] + "_Efficiency_Curve_Numerator_vs_ptcone40"; + seff = eff_dir + chainName + m_alg[alg] + "_Efficiency_Curve_wrt_MuidCB_vs_ptcone40"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + //wrt Upstream + sden = nd_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt"+ m_wrtalg[alg] + "_Denominator"; + snum = nd_dir + chainName + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg[alg] + "_Turn_On_Curve_wrt" + m_wrtalg[alg]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + // for ES ------------------------------------------------------------------------------------ + for (int ies = 0; ies <= m_maxESbr; ies++) { + sden = nd_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_wrt"+ m_wrtalg[alg] + "_Denominator"; + snum = nd_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_triggerES[ies] + m_alg[alg] + "_Turn_On_Curve_wrt" + m_wrtalg[alg]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + } + + }//alg + mf.Write(); + }//i + }// MuIso: end + + TString m_alg2[3] = {"_MuFast", "_MuonEFMS", "_MuonEFSA"}; + TString m_wrtalg2[3] = {"_L1", "_MuFast", "_MuFast"}; + + // ******************************************************// + // ****************** MSonly Chains ********************// + // ******************************************************// + for( unsigned int i=0 ; i < m_chainsMSonly.size() ; i++ ){ + TString chainName = m_chainsMSonly.at(i); + + for( int trg = 0 ; trg < m_maxindep ; trg++ ){ + sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidSA" + m_trigger[trg] + "_Triggered_Denominator"; + + for(int alg = 0 ; alg < 3 ; alg++ ){ + snum = nd_dir + chainName + m_alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + m_trigger[trg] + "_Triggered_Numerator"; + seff = eff_dir + chainName + m_alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + m_trigger[trg] + "_Triggered"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + + // summary for jet trigger + if (0 == alg || 2 == alg) { + if (3 == trg) { // jet + double sumeff, sumerr; + double sumn = h1num->Integral(iMSL, iMSH); + double sumd = h1den->Integral(iMSL, iMSH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double)sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + int iholx = -1; + if (0 == alg) { + iholx = static_cast<int>(iMuFast); + } else if (2 == alg) { + iholx = static_cast<int>(iEFSA); + } + + if (iholx >= 0) { + TString s = eff_dir + chainName + "_highpt_effsummary_by" + m_vectkwd.at(2); + // std::cerr << "hist summary: " << s << " n: " << sumn << " d: " << sumd << " eff: " << sumeff << " err: " << sumerr << std::endl; + mf.get(s, h1sumeff); + if (!h1sumeff) { + if (fdbg) { + std::cerr << "HLTMuon PostProcessing: no such histogram!! " << s << std::endl; + } + continue; + } + h1sumeff->SetBinContent(iholx+1, sumeff); + h1sumeff->SetBinError(iholx+1, sumerr); + // saving + dir->cd(); + h1sumeff->Write("", TObject::kOverwrite); + } + } + } + } + + }//alg + }//trg + mf.Write(); + + for( int alg = 0 ; alg < 3 ; alg++ ){ + //wrt MuidSA + sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidSA_Denominator"; + snum = nd_dir + chainName + m_alg2[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg2[alg] + "_Turn_On_Curve_wrt_MuidSA"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + if (0 == alg || 2 == alg) { // no condition on ES bits = all events + double sumeff, sumerr; + double sumn = h1num->Integral(iMSL, iMSH); + double sumd = h1den->Integral(iMSL, iMSH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double)sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + int iholx = -1; + if (0 == alg) { + iholx = static_cast<int>(iMuFast); + } else if (2 == alg) { + iholx = static_cast<int>(iEFSA); + } + + if (iholx >= 0) { + TString s = eff_dir + chainName + "_highpt_effsummary_by" + m_vectkwd.at(3); + // std::cerr << "hist summary: " << s << " n: " << sumn << " d: " << sumd << " eff: " << sumeff << " err: " << sumerr << std::endl; + mf.get(s, h1sumeff); + if (!h1sumeff) { + if (fdbg) { + std::cerr << "HLTMuon PostProcessing: no such histogram!! " << s << std::endl; + } + continue; + } + h1sumeff->SetBinContent(iholx+1, sumeff); + h1sumeff->SetBinError(iholx+1, sumerr); + // saving + dir->cd(); + h1sumeff->Write("", TObject::kOverwrite); + } + } + } + //wrt MuidSA + + // for ES ---------------------------------------------------------------- + for (int ies = 0; ies <= m_maxESbr; ies++) { + + if(!MS_mon_ESbr[ies])continue; + // for ES, L1 ------------------------------------------------------------ + if (0 == alg) { + sden = nd_dir + chainName + m_triggerES[ies] + "_Turn_On_Curve_wrt_MuidSA_Denominator"; + snum = nd_dir + chainName + m_triggerES[ies] + "_MuFast" + "_Turn_On_Curve_wrt" + "_L1" + "_Denominator"; + seff = eff_dir + chainName + m_triggerES[ies] + "_L1" + "_Turn_On_Curve_wrt_MuidSA"; + seffg = seff + "_Fit"; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + for (int be = 0; be < 2; be++) { + sden = nd_dir + chainName + m_triggerES[ies] + "_Turn_On_Curve_wrt_MuidSA" + bestr[be] + "_Denominator"; + snum = nd_dir + chainName + m_triggerES[ies] + "_MuFast" + "_Turn_On_Curve_wrt" + "_L1" + bestr[be] + "_Denominator"; + seff = eff_dir + chainName + m_triggerES[ies] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidSA"; + seffg = seff + "_Fit"; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + } + + } + // for ES, L1 end ------------------------------------------------------------ + + + sden = nd_dir + chainName + m_triggerES[ies] + "_Turn_On_Curve_wrt_MuidSA_Denominator"; + snum = nd_dir + chainName + m_triggerES[ies] + m_alg2[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_triggerES[ies] + m_alg2[alg] + "_Turn_On_Curve_wrt_MuidSA"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + + if (0 == alg || 2 == alg) { + if (ESTAG == ies || ESINDEP == ies) { + double sumeff, sumerr; + double sumn = h1num->Integral(iMSL, iMSH); + double sumd = h1den->Integral(iMSL, iMSH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double)sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + int iholx = -1; + if (0 == alg) { + iholx = static_cast<int>(iMuFast); + } else if (2 == alg) { + iholx = static_cast<int>(iEFSA); + } + + if (iholx >= 0) { + TString s = eff_dir + chainName + "_highpt_effsummary_by" + m_triggerES[ies]; + // std::cerr << "hist summary: " << s << " n: " << sumn << " d: " << sumd << " eff: " << sumeff << " err: " << sumerr << std::endl; + mf.get(s, h1sumeff); + if (!h1sumeff) { + if (fdbg) { + std::cerr << "HLTMuon PostProcessing: no such histogram!! " << s << std::endl; + } + continue; + } + h1sumeff->SetBinContent(iholx+1, sumeff); + h1sumeff->SetBinError(iholx+1, sumerr); + // saving + dir->cd(); + h1sumeff->Write("", TObject::kOverwrite); + } + } + } + } + } + // for ES: end ---------------------------------------------------------------- + + + if (0 == alg || 2 == alg) { + for (int be = 0; be < 2; be++) { + //wrt MuidSA + sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidSA" + bestr[be] + "_Denominator"; + snum = nd_dir + chainName + m_alg2[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg2[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidSA"; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + } + } + + //wrt upstream + sden = nd_dir + chainName + m_alg2[alg] + "_Turn_On_Curve_wrt" + m_wrtalg2[alg] + "_Denominator"; + snum = nd_dir + chainName + m_alg2[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg2[alg] + "_Turn_On_Curve_wrt" + m_wrtalg2[alg]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + + //wrt upstream + // for ES -------------------------------------------------------------------- + for (int ies = 0; ies <= m_maxESbr; ies++) { + if(!MS_mon_ESbr[ies])continue; + sden = nd_dir + chainName + m_triggerES[ies] + m_alg2[alg] + "_Turn_On_Curve_wrt" + m_wrtalg2[alg] + "_Denominator"; + snum = nd_dir + chainName + m_triggerES[ies] + m_alg2[alg] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_triggerES[ies] + m_alg2[alg] + "_Turn_On_Curve_wrt" + m_wrtalg2[alg]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + } + // for ES: end -------------------------------------------------------------------- + + + if (0 == alg || 2 == alg) { + for (int be = 0; be < 2; be++) { + //wrt upstream + sden = nd_dir + chainName + m_alg2[alg] + "_Turn_On_Curve_wrt" + m_wrtalg2[alg] + bestr[be] + "_Denominator"; + snum = nd_dir + chainName + m_alg2[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + seff = eff_dir + chainName + m_alg2[alg] + "_Turn_On_Curve_wrt" + m_wrtalg2[alg] + bestr[be]; + seffg = seff + "_Fit"; // YY added 20.04.10 + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + } + } + }//alg + mf.Write(); + }//i + + //==Rate + dir = mf.GetDirectory(rr_dir); + if(!dir){ + if (fdbg) { + std::cerr<< "HLTMuonHistogramDivision: directory "<<rr_dir<<" not found"<<std::endl; + } + return; + } + + // EF rate / offline rate + std::string type[3] = {"MS_", "SA_", "CB_"}; + std::string off[3] = {"Moore_MS_", "Moore_SA_", "Muid_"}; + std::string cut[2] = {"4", "10"}; + + for( int itype = 0 ; itype < 3 ; itype++ ){ + for( int icut = 0 ; icut < 2 ; icut++ ){ + + seff = rr_dir + "EF_" + type[itype] + "Over_" + off[itype] + cut[icut] + "GeV_Cut"; + snum = rate_dir + "Number_Of_EF_" + type[itype] + "Muons_" + cut[icut] + "GeV_Cut"; + sden = rate_dir + "Number_Of_" + off[itype] + "Muons_" + cut[icut] + "GeV_Cut"; + + h1eff = 0; + mf.get(seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + + }//icut + }//itype + mf.Write(); + + // Triggers / Event + std::vector<TString> m_chains; + std::vector<TString> m_chains2; + + { + std::map<std::string, std::string> m_ztpmap; + // pp_v4 menu items for ZTP + m_ztpmap["mu36_tight"] = "L1_MU15"; + m_ztpmap["mu24i_tight"] = "L1_MU15"; + m_ztpmap["mu50_MSonly_barrel_tight"] = "L1_MU15"; + + std::map<std::string, int> m_ztp_isomap; + m_ztp_isomap["mu36_tight"] = 0; + m_ztp_isomap["mu24i_tight"] = 1; + m_ztp_isomap["mu50_MSonly_barrel_tight"] = 0; + + // old menu pp_v3 for ZTP + // m_ztpmap["mu15"]="L1_MU10"; + // m_ztpmap["mu15i"]="L1_MU10"; + // m_ztpmap["mu20i_medium"]="L1_MU11"; + // m_ztpmap["mu20"]="L1_MU10"; + // m_ztpmap["mu20_MG"]="L1_MU10"; + // m_ztpmap["mu22_medium"]="L1_MU11"; // YY + // m_ztpmap["mu22_MG_medium"]="L1_MU11"; + // m_ztpmap["mu40_MSonly_barrel"]="L1_MU10"; + // m_ztpmap["mu40_MSonly_barrel_medium"]="L1_MU11"; + // m_ztpmap["mu40_MSonly_tight"]="L1_MU10"; + // m_ztpmap["mu40_MSonly_tighter"]="L1_MU10"; + + for(std::map<std::string, std::string>::iterator itmap=m_ztpmap.begin();itmap!=m_ztpmap.end();++itmap){ + TString histdirmuztp = run_dir + "/HLT/MuonMon/MuZTP/"+itmap->first; + TDirectory* ztpdir = mf.GetDirectory(histdirmuztp); + bool isefisochain = m_ztp_isomap[itmap->first] > 0; + + //efficiency histograms + std::vector<std::string> var; + var.push_back("_Pt_"); + var.push_back("_Pt_EC_"); + var.push_back("_Pt_B_"); + var.push_back("_Pt_4bins_"); + var.push_back("_Pt_B_4bins_"); + var.push_back("_Eta_"); + var.push_back("_Phi_"); + var.push_back("_Phi_EC_"); + var.push_back("_Phi_B_"); + for(unsigned int k=0;k<var.size();k++){ + std::vector<std::string> level; + level.push_back("L1"); + level.push_back("L2"); + level.push_back("EF"); + if(isefisochain) level.push_back("EFIso"); + for(unsigned int j=0;j<level.size();j++){ + //ABSOLUTE + // dynamic_cast<TGraphAsymmErrors*>( graph(("muZTP_eff_"+level[j]+var[k]+itmap->first).c_str(), histdirmuztp))->BayesDivide(hist(("muZTP"+var[k]+level[j]+"fired_"+itmap->first).c_str(), histdirmuztp), hist(("muZTP"+var[k]+itmap->first).c_str(), histdirmuztp)); + + seffg = histdirmuztp + "/muZTP_eff_"+level[j]+var[k]+itmap->first; + snum = histdirmuztp + "/muZTP"+var[k]+level[j]+"fired_"+itmap->first; + sden = histdirmuztp + "/muZTP"+var[k]+itmap->first; + // for debugging + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1num && h1den){ + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + if (geff) { + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + ztpdir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + mf.Write(); + + // dynamic_cast<TGraphAsymmErrors*>( graph(("muZTP_eff_"+level[j]+"_Eta_1bin_"+itmap->first).c_str(), histdirmuztp))->BayesDivide(hist(("muZTP_Eta_1bin_"+level[j]+"fired_"+itmap->first).c_str(), histdirmuztp), hist(("muZTP_Eta_1bin_"+itmap->first).c_str(), histdirmuztp)); + + seffg = histdirmuztp + "/muZTP_eff_"+level[j]+"_Eta_1bin_"+itmap->first; + snum = histdirmuztp + "/muZTP_Eta_1bin_"+level[j]+"fired_"+itmap->first; + sden = histdirmuztp + "/muZTP_Eta_1bin_"+itmap->first; + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1num && h1den){ + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + if (geff) { + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + ztpdir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + mf.Write(); + + // dynamic_cast<TGraphAsymmErrors*>( graph(("muZTP_eff_"+level[j]+"_Eta_2bins_"+itmap->first).c_str(), histdirmuztp))->BayesDivide(hist(("muZTP_Eta_2bins_"+level[j]+"fired_"+itmap->first).c_str(), histdirmuztp), hist(("muZTP_Eta_2bins_"+itmap->first).c_str(), histdirmuztp)); + seffg = histdirmuztp + "/muZTP_eff_"+level[j]+"_Eta_2bins_"+itmap->first; + snum = histdirmuztp + "/muZTP_Eta_2bins_"+level[j]+"fired_"+itmap->first; + sden = histdirmuztp + "/muZTP_Eta_2bins_"+itmap->first; + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1num && h1den){ + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + if (geff) { + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + ztpdir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + mf.Write(); + + + // dynamic_cast<TGraphAsymmErrors*>( graph(("muZTP_eff_"+level[j]+"_Eta_1bin_cut_"+itmap->first).c_str(), histdirmuztp))->BayesDivide(hist(("muZTP_Eta_1bin_cut_"+level[j]+"fired_"+itmap->first).c_str(), histdirmuztp), hist(("muZTP_Eta_1bin_cut_"+itmap->first).c_str(), histdirmuztp)); + seffg = histdirmuztp + "/muZTP_eff_"+level[j]+"_Eta_1bin_cut_"+itmap->first; + snum = histdirmuztp + "/muZTP_Eta_1bin_cut_"+level[j]+"fired_"+itmap->first; + sden = histdirmuztp + "/muZTP_Eta_1bin_cut_"+itmap->first; + + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1num && h1den){ + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + if (geff) { + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + ztpdir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + mf.Write(); + + // dynamic_cast<TGraphAsymmErrors*>( graph(("muZTP_eff_"+level[j]+"_Eta_2bins_cut_"+itmap->first).c_str(), histdirmuztp))->BayesDivide(hist(("muZTP_Eta_2bins_cut_"+level[j]+"fired_"+itmap->first).c_str(), histdirmuztp), hist(("muZTP_Eta_2bins_cut_"+itmap->first).c_str(), histdirmuztp)); + seffg = histdirmuztp + "/muZTP_eff_"+level[j]+"_Eta_2bins_cut_"+itmap->first; + snum = histdirmuztp + "/muZTP_Eta_2bins_cut_"+level[j]+"fired_"+itmap->first; + sden = histdirmuztp + "/muZTP_Eta_2bins_cut_"+itmap->first; + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1num && h1den){ + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + if (geff) { + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + ztpdir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + mf.Write(); + + //2D ETA_PHI + seff = histdirmuztp + "/muZTP_eff_EtaPhi_"+level[j]+"_" + itmap->first; + snum = histdirmuztp + "/muZTP_EtaPhi_"+level[j]+"_" + itmap->first; + sden = histdirmuztp + "/muZTP_EtaPhi_all_"+ itmap->first; + + TH2F *h2eff(0); + TH2F *h2num(0); + TH2F *h2den(0); + + h2eff = 0; + mf.get(seff, h2eff); + if(!h2eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + continue; + } + h2num = 0; + mf.get(snum, h2num); + if(!h2num){ + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h2den = 0; + mf.get(sden, h2den); + if(!h2den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h2eff && h2num && h2den){ + h2eff->Reset(); + h2eff->Divide(h2num, h2den, 1., 1., "B"); + + ztpdir->cd(); + h2eff->Write("",TObject::kOverwrite); + } + mf.Write(); + + + }//level + + //RELATIVE + // dynamic_cast<TGraphAsymmErrors*>( graph(("muZTP_eff_EFwrtL2"+var[k]+itmap->first).c_str(), histdirmuztp))->BayesDivide(hist(("muZTP"+var[k]+"EFfired_"+itmap->first).c_str(), histdirmuztp), hist(("muZTP"+var[k]+"L2fired_"+itmap->first).c_str(), histdirmuztp)); + seffg = histdirmuztp + "/muZTP_eff_EFwrtL2"+var[k]+itmap->first; + snum = histdirmuztp + "/muZTP"+var[k]+"EFL2fired_"+itmap->first; + sden = histdirmuztp + "/muZTP"+var[k]+"L2fired_"+itmap->first; + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1num && h1den){ + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + if (geff) { + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + ztpdir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + mf.Write(); + + // dynamic_cast<TGraphAsymmErrors*>( graph(("muZTP_eff_EFwrtL1"+var[k]+itmap->first).c_str(), histdirmuztp))->BayesDivide(hist(("muZTP"+var[k]+"EFfired_"+itmap->first).c_str(), histdirmuztp), hist(("muZTP"+var[k]+"L1fired_"+itmap->first).c_str(), histdirmuztp)); + seffg = histdirmuztp + "/muZTP_eff_EFwrtL1"+var[k]+itmap->first; + snum = histdirmuztp + "/muZTP"+var[k]+"EFfired_"+itmap->first; + sden = histdirmuztp + "/muZTP"+var[k]+"L1fired_"+itmap->first; + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1num && h1den){ + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + if (geff) { + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + ztpdir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + mf.Write(); + + // dynamic_cast<TGraphAsymmErrors*>( graph(("muZTP_eff_L2wrtL1"+var[k]+itmap->first).c_str(), histdirmuztp))->BayesDivide(hist(("muZTP"+var[k]+"L2fired_"+itmap->first).c_str(), histdirmuztp), hist(("muZTP"+var[k]+"L1fired_"+itmap->first).c_str(), histdirmuztp)); + seffg = histdirmuztp + "/muZTP_eff_L2wrtL1"+var[k]+itmap->first; + snum = histdirmuztp + "/muZTP"+var[k]+"L2fired_"+itmap->first; + sden = histdirmuztp + "/muZTP"+var[k]+"L1fired_"+itmap->first; + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1num && h1den){ + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + if (geff) { + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + ztpdir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + mf.Write(); + + if(isefisochain){ + seffg = histdirmuztp + "/muZTP_eff_EFIsowrtEF"+var[k]+itmap->first; + snum = histdirmuztp + "/muZTP"+var[k]+"EFIsofired_"+itmap->first; + sden = histdirmuztp + "/muZTP"+var[k]+"EFfired_"+itmap->first; + h1num = 0; + mf.get(snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if(h1num && h1den){ + geff = (TGraphAsymmErrors*) mf.Get(seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + continue; + } + if (geff) { + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + ztpdir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + mf.Write(); + } + + }//var + } + // mf.Write(); + } // procMuZTP + + + { + TDirectory* efdir = mf.GetDirectory(eff_dir); + if(!efdir){ + if (fdbg) { + std::cerr<< "HLTMuonHistogramDivision: directory "<<eff_dir<<" not found"<<std::endl; + } + return; + } + + // procChainDQA_HighPt + // pp_v4 + const int MAXARR = 3; + std::string charr[MAXARR] = {"mu36_tight", "mu24i_tight", "mu50_MSonly_barrel_tight"}; + std::string monarr[MAXARR] = {"_EFmuon", "_EFmuon", "_MuonEFSA"}; + std::string monL2arr[MAXARR] = {"_MuFast", "_MuFast", "_MuFast"}; + bool isBarrelMon[MAXARR] = {false, false, true}; // enable MSonly + bool isMSbMon[MAXARR] = {true, false, false}; // Skip isol and MSonly + bool monL1[MAXARR] = {true, true, false}; // Skip MSonly + bool isefIsolation[MAXARR] = {false, true, false}; // EF isolation add by Yuan + + // I need to prepare maps ... mu20_MG -> MuGirlEF etc. + for (int ialg = 0; ialg < MAXARR; ialg++) { + std::string chainName = charr[ialg]; + std::string MoniAlg = monarr[ialg]; + std::string MoniL2Alg = monL2arr[ialg]; + + /* 1. Picking up ztp graph */ + TString hdirztp = muon_dir + "MuZTP/" + chainName + "/"; + TString histZtpNum, histZtpDen; + if (!isBarrelMon[ialg]) { + histZtpNum = hdirztp + "muZTP_Pt_4bins_EFfired_" + chainName; + histZtpDen = hdirztp + "muZTP_Pt_4bins_L1fired_" + chainName; + } else { + histZtpNum = hdirztp + "muZTP_Pt_B_4bins_EFfired_" + chainName; + histZtpDen = hdirztp + "muZTP_Pt_B_4bins_L1fired_" + chainName; + } + if(isefIsolation[ialg]) histZtpNum = hdirztp + "muZTP_Pt_4bins_EFIsofired_" + chainName; // add by Yuan + TString histZtpEff = eff_dir + chainName + "_highpt3bins_effwrtL1"; + + h1num = 0; mf.get(histZtpNum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpNum << std::endl; + } + continue; + } + h1den = 0; mf.get(histZtpDen, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpDen << std::endl; + } + continue; + } + h1eff = 0; mf.get(histZtpEff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpEff << std::endl; + } + continue; + } + + /* 2. Filling summary histogram from ZTP values */ + if (h1num && h1den && h1eff) { + for (int ibin = 2; ibin <= 3; ibin++) { + // at the moment it is not correct if we run the algorithm # 4: mu40_MSonly_barrel . + double sumeff, sumerr; + double sumn = h1num->Integral(ibin, ibin); //// + double sumd = h1den->Integral(ibin, ibin); //// + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double) sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + h1eff->SetBinContent(ibin-1, sumeff); //// + h1eff->SetBinError(ibin-1, sumerr); //// + } + } + + /* 3. Picking up chainDQ MSonly graph */ + /* EF efficiency wrt L1, as for the ztp graph = overall HLT efficiency wrt L1: not possible, wrt offline */ + if (isMSbMon[ialg]) { // skip muIso and MSonly !!! + TString histChNum = nd_dir + chainName + m_MSchainName + MoniAlg + "_Turn_On_Curve_Numerator"; + TString histChDen = nd_dir + chainName + m_MSchainName + MoniL2Alg + "_Turn_On_Curve_wrt_L1_Denominator"; + + h1num = 0; mf.get(histChNum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpNum << std::endl; + } + continue; + } + h1den = 0; mf.get(histChDen, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpDen << std::endl; + } + continue; + } + + if (h1num && h1den) { + // Integrate 100-300 GeV + double sumeff, sumerr; + double sumn = h1num->Integral(21, 28); //// + double sumd = h1den->Integral(21, 28); //// + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double) sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + h1eff->SetBinContent(3, sumeff); //// + h1eff->SetBinError(3, sumerr); //// + } + } + efdir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (monL1[ialg]) { // MUST skip muGirl, muIso and MSonly as histograms are not defined!!! + TString hdirztp = muon_dir + "MuZTP/" + chainName + "/"; + TString histZtpNumB = hdirztp + "muZTP_Pt_B_L1fired_" + chainName; + TString histZtpDenB = hdirztp + "muZTP_Pt_B_" + chainName; + TString histZtpNumE = hdirztp + "muZTP_Pt_EC_L1fired_" + chainName; + TString histZtpDenE = hdirztp + "muZTP_Pt_EC_" + chainName; + TString histZtpL1sum = eff_dir + chainName + "_highptL1plateau_wrtOffline"; + + TH1F *h1numb = 0; mf.get(histZtpNumB, h1numb); + if (!h1numb) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpNumB << std::endl; + } + continue; + } + TH1F *h1nume = 0; mf.get(histZtpNumE, h1nume); + if (!h1nume) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpNumE << std::endl; + } + continue; + } + TH1F *h1denb = 0; mf.get(histZtpDenB, h1denb); + if (!h1denb) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpDenB << std::endl; + } + continue; + } + TH1F *h1dene = 0; mf.get(histZtpDenE, h1dene); + if (!h1dene) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpDenE << std::endl; + } + continue; + } + TH1F *h1sumL = 0; mf.get(histZtpL1sum, h1sumL); + if (!h1sumL) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< histZtpL1sum << std::endl; + } + continue; + } + + double sumeff, sumerr; + double sumn = h1numb->Integral(7, 10); // 30-50 GeV + double sumd = h1denb->Integral(7, 10); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double) sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + h1sumL->SetBinContent(1, sumeff); + h1sumL->SetBinError(1, sumerr); + + sumn = h1nume->Integral(7, 10); + sumd = h1dene->Integral(7, 10); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double) sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + h1sumL->SetBinContent(2, sumeff); + h1sumL->SetBinError(2, sumerr); + efdir->cd(); + h1sumL->Write("",TObject::kOverwrite); + + } + + } + + mf.Write(); + + } //procChainDQA_HighPt + //===End HLTMuonw + + + // ******************************************************// + // ********************* generic ***********************// + // ******************************************************// + TString monalg[3]={"_MuFast", "_MuComb", "_EFmuon"}; + TString wrtalg[3]={"_L1", "_MuFast", "_MuComb"}; + + TString numer, denom, effi; + TString histdireff = eff_dir; + + TDirectory* efdir = mf.GetDirectory(eff_dir); + if(!efdir){ + if (fdbg) { + std::cerr<< "HLTMuonHistogramDivision: directory "<<eff_dir<<" not found"<<std::endl; + } + return; + } + + // processing muIso histograms in the same manner + m_chainsGeneric.insert(m_chainsGeneric.end(), m_chainsEFiso.begin(), m_chainsEFiso.end()); + + for( unsigned int i=0 ; i < m_chainsGeneric.size() ; i++ ){ + TString chainName = m_chainsGeneric.at(i); + if (fdbg) { + std::cout << "proc generic " << chainName << std::endl; + } + + //wrt CB muon && Upstream trigger + for( int alg = 0 ; alg < 3 ; alg++ ){ + denom = chainName + "_Turn_On_Curve_wrt_MuidCB_Denominator"; + numer = chainName + monalg[alg] + "_Turn_On_Curve_Numerator"; + effi = chainName + monalg[alg] + "_Turn_On_Curve_wrt_MuidCB"; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + + denom = chainName + m_MSchainName + "_Turn_On_Curve_wrt_MuidCB_Denominator"; + numer = chainName + m_MSchainName + monalg[alg] + "_Turn_On_Curve_Numerator"; + effi = chainName + m_MSchainName + monalg[alg] + "_Turn_On_Curve_wrt_MuidCB"; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + + // Summary all - removed + + denom = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + "_Denominator"; + numer = chainName + monalg[alg] + "_Turn_On_Curve_Numerator"; + effi = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg]; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + + + denom = chainName + m_MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + "_Denominator"; + numer = chainName + m_MSchainName + monalg[alg] + "_Turn_On_Curve_Numerator"; + effi = chainName + m_MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg]; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + + // for ES ------------------------------------------------------------------------------------ + for (int i = 0; i <= m_maxESbr; i++) { + + if(!CB_mon_ESbr[i]) continue; + if (0 == alg) { + // L1 efficiency: new for 2011 HI runs and afterward + // only division once since it is "the zero-th" algorithm + denom = chainName + m_triggerES[i] + "_Turn_On_Curve_wrt_MuidCB_Denominator"; + numer = chainName + m_triggerES[i] + "_MuFast" + "_Turn_On_Curve_wrt" + "_L1" + "_Denominator"; + effi = chainName + m_triggerES[i] + "_L1" + "_Turn_On_Curve_wrt_MuidCB"; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + + // Need to implement barrel and endcap ... + for (int be = 0; be < 2; be++) { + denom = chainName + m_triggerES[i] + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator"; + numer = chainName + m_triggerES[i] + "_MuFast" + "_Turn_On_Curve_wrt" + "_L1" + bestr[be] + "_Denominator"; + effi = chainName + m_triggerES[i] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidCB"; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + + h1num = 0; + mf.get(nd_dir + numer, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(nd_dir + denom, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + + if (ESINDEP == i) { + // integrating over and fill in a summary histogram + double sumeff, sumerr; + double sumn = h1num->Integral(iSTDL, iSTDH); // 40-80 GeV + double sumd = h1den->Integral(iSTDL, iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double)sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + + TString s = histdireff + chainName + "_L1plateau_wrtOffline_by_ESindep"; + TH1F *h1effL1 = 0; + mf.get(s, h1effL1); + if (!h1effL1) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + h1effL1->SetBinContent(be+1, sumeff); + h1effL1->SetBinError(be+1, sumerr); + efdir->cd(); + h1effL1->Write("",TObject::kOverwrite); + } + } + } + + denom = chainName + m_triggerES[i] + "_Turn_On_Curve_wrt_MuidCB_Denominator"; + numer = chainName + m_triggerES[i] + monalg[alg] + "_Turn_On_Curve_Numerator"; + effi = chainName + m_triggerES[i] + monalg[alg] + "_Turn_On_Curve_wrt_MuidCB"; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + + // Summary ESid and ESindep + h1num = 0; + mf.get(nd_dir + numer, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + continue; + } + h1den = 0; + mf.get(nd_dir + denom, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + if (0 == alg || 1 == alg || 2 == alg) { + // if (ESID == i || ESINDEP == i) { + double sumd, sumn, sumeff, sumerr; + sumn = h1num->Integral(iSTDL, iSTDH); + sumd = h1den->Integral(iSTDL, iSTDH); + if (sumd == 0.) { + sumeff = 0.; + sumerr = 0.; + } else { + sumeff = (double)sumn / (double)sumd; + sumerr = sqrt((double)sumn * (1.-sumeff)) / (double)sumd; + } + int iholx = -1; + if (0 == alg) { + iholx = static_cast<int>(iMuFast); + } else if (1 == alg) { + iholx = static_cast<int>(iMuComb); + } else if (2 == alg) { + iholx = static_cast<int>(iEFCB); + } + + TString s = histdireff + chainName + "_highpt_effsummary_by" + m_triggerES[i]; + TH1F *h1effsum = 0; + mf.get(s, h1effsum); + if (!h1effsum) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + continue; + } + h1effsum->SetBinContent(iholx+1, sumeff); + h1effsum->SetBinError(iholx+1, sumerr); + efdir->cd(); + h1effsum->Write("",TObject::kOverwrite); + } + + denom = chainName + m_triggerES[i] + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + "_Denominator"; + numer = chainName + m_triggerES[i] + monalg[alg] + "_Turn_On_Curve_Numerator"; + effi = chainName + m_triggerES[i] + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg]; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + + } + // for ES : END ------------------------------------------------------------------------------ + + // Barrel/Endcap + if (0 == alg || 1 == alg || 2 == alg) { + for (int be = 0; be < 2; be++) { + denom = chainName + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator"; + numer = chainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + effi = chainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidCB"; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + } + + for (int be = 0; be < 2; be++) { + denom = chainName + m_MSchainName + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator"; + numer = chainName + m_MSchainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + effi = chainName + m_MSchainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidCB"; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + } + + for (int be = 0; be < 2; be++) { + denom = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be] + "_Denominator"; + numer = chainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + effi = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be]; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + } + + + for (int be = 0; be < 2; be++) { + denom = chainName + m_MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be] + "_Denominator"; + numer = chainName + m_MSchainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator"; + effi = chainName + m_MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be]; + // hist(effi, histdireff)->Divide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom), 1, 1, "B" ); + // dynamic_cast<TGraphAsymmErrors*>( graph(effi + "_Fit", histdireff ) )->BayesDivide( hist(numer, histdireffnumdenom), hist(denom, histdireffnumdenom) ); + HLTMuonHDiv(mf, histdireff, numer, denom, effi, effi + "_Fit"); + } + + } + + } + } + }//while (now just open bracket: 110728 + }//MonitoringFile::HLTMuonHistogramDivision + + void MonitoringFile::HLTMuonHDiv(PostProcessorFileWrapper& mf, + TString sdir, TString snum, TString sden, TString seff, TString seffg) + { + TH1F* h1eff(0); + TH1F* h1num(0); + TH1F* h1den(0); + TGraphAsymmErrors* geff(0); + + h1eff = 0; + mf.get(sdir + seff, h1eff); + if (!h1eff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seff << std::endl; + } + return; + } + h1num = 0; + mf.get(sdir + "NumDenom/" + snum, h1num); + if (!h1num) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< snum << std::endl; + } + return; + } + h1den = 0; + mf.get(sdir + "NumDenom/" + sden, h1den); + if (!h1den) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sden << std::endl; + } + return; + } + geff = (TGraphAsymmErrors*) mf.Get(sdir + seffg); + if (!geff) { + if (fdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< seffg << std::endl; + } + return; + } + + TDirectory* dir = mf.GetDirectory(sdir); + + if( h1eff && h1num && h1den){ + h1eff->Reset(); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if (geff) { // YY added 20.04.10 + geff->SetMarkerStyle(20); + geff->BayesDivide(h1num, h1den); + + // saving summary TGraph + dir->cd(); + geff->Write("", TObject::kOverwrite); + } + } + } + + +}//namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMuonPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMuonPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..be5c376d8470cd07bb1e7d3d19532c4b29a2b256 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTMuonPostProcess.cxx @@ -0,0 +1,230 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//Methods to Process HLTMuon Histograms after merging. +//Author: Akimasa Ishikawa (akimasa.ishikawa@cern.ch) +//Date: Jan 2009 +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + + + +namespace dqutils { + + static const bool fpdbg = false; + // static const bool fpdbg = true; + + void + MonitoringFile::HLTMuonPostProcess( std::string inFilename, bool /* isIncremental */ ) + { + if (fpdbg) std::cout << "Start HLTMuon post-processing" << std::endl; + + //start postprocessing + TString run_dir; + HLTMuonHistogramDivision(inFilename , run_dir); + + //trigger overlap matrix + HLTMuonTriggerOverlapMatrix(inFilename , run_dir); + + if (fpdbg) std::cout << "Finish HLTMuon post-processing"<<std::endl; + + return; + }//MonitoringFile::HLTMuonPostProcess + + bool + MonitoringFile::HLTMuonCheckHistogram(TFile* f, TString& hname) + { + if (!(f->Get(hname))) { + if (fpdbg) { + std::cerr << "HLTMuon PostProcessing: no such histogram!! : "<< hname << std::endl; + gDirectory->pwd(); + gDirectory->ls(); + } + return false; + } + return true; + }//MonitoringFile::HLTMuonCheckHistogram + + void + MonitoringFile::HLTMuonTriggerOverlapMatrix(std::string inFilename, TString& run_dir) + { + if (fpdbg) std::cout << " Start to fill HLTMuon Trigger Overlap Matrix" << std::endl; + + PostProcessorFileWrapper mf( inFilename , "HLT Trigger Overlap Matrix"); + if (!mf.IsOpen()) { + std::cerr << "HLTMuonPostProcess(): " + << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + std::cerr << "HLTMuonPostProcess(): " + << "Input file empty \n"; + return; + } + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + dir0->cd(); + /// + + /* + TIter next_run (mf.GetListOfKeys()); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if (tdir_run ==0 ){ + // delete obj_run; + continue; + } + run_dir = tdir_run->GetName(); + if (!run_dir.Contains("run") ) { + // delete obj_run; + continue; + } + */ + int times = 1; + while (times--) { // just once + run_dir = dir0->GetName(); + if (fpdbg) { + std::cout << "HLTMuon: run directory is " << run_dir << std::endl; + } + + std::string run_dir2 = run_dir.Data(); + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + //===HLTMuon + // TString muon_dir = run_dir + "/HLT/MuonMon/"; + TString muon_dir = "/" + run_dir + "/HLT/MuonMon/"; + + TString cm_dir = muon_dir + "Common/"; + + TString sol = cm_dir + "Trigger_Overlap"; + TString solpt = cm_dir + "Trigger_Overlap_Including_Passthrough"; + TString solf = cm_dir + "Trigger_Overlap_Fraction"; + TString solfpt = cm_dir + "Trigger_Overlap_Fraction_Including_Passthrough"; + + TH2F* hol(0); + TH2F* holpt(0); + TH2F* holf(0); + TH2F* holfpt(0); + + //Matrix + TDirectory* dir = mf.GetDirectory(cm_dir); + // if (fpdbg) { std::cerr << "matrix directory: " << cm_dir << std::endl; } + if(!dir){ + if (fpdbg) { + std::cerr<< "HLTMuonTriggerOverlapMatrix: directory "<<cm_dir<<" not found"<<std::endl; + } + return; + } + + mf.get( sol, hol ); + // if (fpdbg) { std::cerr << "matrix file: " << sol << std::endl; } + if (!hol) { + if (fpdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< sol << std::endl; + } + continue; + } + mf.get( solpt, holpt ); + if (!holpt) { + if (fpdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< solpt << std::endl; + } + continue; + } + mf.get( solf, holf ); + if (!holf) { + if (fpdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< solf << std::endl; + } + continue; + } + mf.get( solfpt, holfpt ); + if (!holfpt) { + if (fpdbg) { + std::cerr <<"HLTMuon PostProcessing: no such histogram!! "<< solfpt << std::endl; + } + continue; + } + + if( hol && holpt && holf && holfpt ){ + holf->Reset(); + holfpt->Reset(); + + for( int i = 0 ; i < hol->GetXaxis()->GetNbins(); i ++ ){ + + Float_t diag = hol->GetBinContent(i+1, i+1); + Float_t diagpt = holpt->GetBinContent(i+1, i+1); + + for( int j = 0 ; j < hol->GetXaxis()->GetNbins(); j ++ ){ + + Float_t offdiag = hol->GetBinContent(i+1, j+1); + Float_t offdiagpt = holpt->GetBinContent(i+1, j+1); + + Float_t frac = 0.; + Float_t efrac = 0.; + + if( diag != 0. ){ + frac = offdiag/diag; + efrac = sqrt(frac*(1.-frac)/diag); + } + + Float_t fracpt = 0.; + Float_t efracpt = 0.; + + if( diagpt != 0. ){ + fracpt = offdiagpt/diagpt; + efracpt = sqrt(fracpt*(1.-fracpt)/diagpt); + } + + holf->SetBinContent(i+1,j+1, frac); + holf->SetBinError(i+1,j+1, efrac); + + holfpt->SetBinContent(i+1,j+1, fracpt); + holfpt->SetBinError(i+1,j+1, efracpt); + + }//j + }//i + + dir->cd(); + holf->Write("",TObject::kOverwrite); + holfpt->Write("",TObject::kOverwrite); + + }//if + mf.Write(); + + }//while + }//HLTMuonTriggerOverlapMatrix + +}//namespace + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_HLTTauPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTTauPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..91784eb507a3bbb7b30c80566adfcc6d2fc751f6 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_HLTTauPostProcess.cxx @@ -0,0 +1,227 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// HLT Tau post processing jobs +// 01/03/2011: update by ccuenca +// ********************************************************************** + +#include "DataQualityUtils/MonitoringFile.h" + +#include <cmath> +#include <vector> + +#include <TCanvas.h> +#include <TF1.h> +#include <TFile.h> +#include <TH1.h> +#include <TH2.h> +#include <TKey.h> +#include <TMath.h> +#include <TProfile.h> + +namespace dqutils { + + + //-------------------------------------------------------------------------------- + // main process + //-------------------------------------------------------------------------------- + void MonitoringFile::HLTTauPostProcess( std::string inFilename, bool /* isIncremental */ ){ + //std::cout << "--> HLTTauPostProcess: Begin HLT Tau post-processing" << std::endl; + + //open root file + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + //check files are loaded. + if (f == 0 || ! f->IsOpen() ) { + //std::cerr << "--> HLTTauPostProcess: Input file not opened" << std::endl; + delete f; + return; + } + + //zombie files? + if(f->IsZombie()) { + //std::cerr << "--> HLTTauPostProcess: Input file " << inFilename << " cannot be opened. " << std::endl; + delete f; + return; + } + + //check file size is not too small. + if(f->GetSize()<1000.) { + //std::cerr << "--> HLTTauPostProcess: Input file empty" << std::endl; + f->Close(); + delete f; + return; + } + + + //making sure we are in the right directory + // f->cd("/"); + // f->pwd(); + // f->ls(); + + //build iterator + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + + //loop over keys in root directory + while ((key_run = dynamic_cast<TKey*>( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + + //check we have a valid pointer + if (tdir_run ==0 ) { + delete obj_run; + continue; + } + + //check name + std::string runDirName( tdir_run->GetName() ); + //std::cout<<"Run_directory: "<<runDirName<<std::endl; + + if (runDirName.find("run") == std::string::npos ) { + delete obj_run; + continue; + } + + //find tauMon dir + TString taumonDirName = runDirName + "/HLT/TauMon"; + TDirectory* taumonDir(0); + if( !(taumonDir = f->GetDirectory(taumonDirName)) ) { + //std::cerr << "--> HLTTauPostProcess: directory " << taumonDirName << " not found." << std::endl; + return; + } + + + std::vector<TString> varName; + varName.push_back("Et"); + varName.push_back("Eta"); + varName.push_back("Phi"); + + std::vector<TString> lvlName; + lvlName.push_back("L1"); + lvlName.push_back("L2"); + lvlName.push_back("EF"); + + std::vector< std::pair< int, int > > ratioIndex; + ratioIndex.push_back( std::make_pair(2,0) ); // EF vs L1 + ratioIndex.push_back( std::make_pair(1,0) ); // L2 vs L1 + ratioIndex.push_back( std::make_pair(2,1) ); // EF vs L2 + + + + std::vector<TString> varName0; + varName0.push_back("Pt"); + varName0.push_back("Eta"); + varName0.push_back("Phi"); + varName0.push_back("Nvtx"); + + std::vector<TString> lvlNameO; + lvlNameO.push_back("L1"); + lvlNameO.push_back("L2"); + lvlNameO.push_back("EF"); + lvlNameO.push_back("");//offline + + std::vector< std::pair< int, int > > ratioIndexO; + ratioIndexO.push_back( std::make_pair(0,3) ); // L1 vs off + ratioIndexO.push_back( std::make_pair(1,3) ); // L2 vs off + ratioIndexO.push_back( std::make_pair(2,3) ); // EF vs off + + + //loop over directories + TIter next_trig ( taumonDir->GetListOfKeys() ); + TKey* key_trig(0); + while ( (key_trig = dynamic_cast<TKey*>( next_trig() )) != 0 ) { + TObject* obj_trig = key_trig->ReadObj(); + TDirectory* dir_trig = dynamic_cast<TDirectory*>( obj_trig ); + if (!dir_trig) continue; + //std::cout<<"--> HLTTauPostProcess: calling functions for " << dir_trig->GetName() << endl; + // "<<runDirName<<" and trigger item="<<dir_trig->GetName()<<endl; + + HLTTauPostProcess(f,dir_trig,"/RelativeEfficiency","/RelativeEfficiency/Efficiency", + lvlName,varName,ratioIndex, 1);//name style : 1 (relative eff) + HLTTauPostProcess(f,dir_trig,"/OfflineRatio","/OfflineRatio/Ratio", + lvlNameO,varName0,ratioIndexO, 2);//name style : 2 (offline eff) + HLTTauPostProcess(f,dir_trig,"/OfflineRatio/BDTMedium","/OfflineRatio/Ratio/BDTMedium", + lvlNameO,varName0,ratioIndexO, 2, "BDTMedium");//name style : 2 (offline eff) + + + + } + } + + f->Close(); + delete f; + //std::cout << "--> HLTTauPostProcess: finished HLT Tau post-processing"<<std::endl; + } + + + void MonitoringFile::HLTTauPostProcess( TFile* f, TDirectory* dir, + TString pathApp, TString pathAppEff, + std::vector<TString> lvlN, std::vector<TString> varN, + std::vector< std::pair< int, int > > ratioIndex, int nameStyle, + TString nameApp){ + + std::string path = getPath(dir); + + //cout<<"HLTTauPostProcess in "<< path +// <<" pathApp="<<pathApp +// <<" pathAppEff="<<pathAppEff +// <<" nameStyle="<<nameStyle<<endl; + + TString basePath = path + pathApp + "/"; + if( f->cd(basePath.Data())==0 ) { + //cout<<"basePath isn't there!"<<endl; + return; + } + + //TH1F* hRoI[lvlN.size()][varN.size()]; + TH1F* hRoI[100][100]; + for (unsigned int iLvl = 0; iLvl < lvlN.size(); iLvl ++) { + for (unsigned int iVar = 0; iVar < varN.size(); iVar ++) { + TString hName; + if (nameStyle == 1) hName = basePath + "h" + lvlN[iLvl] + "RoI" + varN[iVar] + (iLvl == 0 ? "Denom" : "Num") + nameApp; + if (nameStyle == 2) hName = basePath + "hTau" + varN[iVar] + lvlN[iLvl] + nameApp; + if ( ! CheckHistogram(f, hName.Data()) ) { + //cout<<" histo "<<hName<<" is not in f "<<f->GetName()<<endl; + return; + } + hRoI[iLvl][iVar] = (TH1F*) ( f->Get( hName.Data() ) ) ->Clone(); + } + } + + + basePath += path + pathAppEff + "/"; + f->cd(basePath.Data()); + TH1F* hEff[100][100]; + for (unsigned int iVar = 0; iVar < varN.size(); iVar ++) { + for (unsigned int iRatio = 0 ; iRatio < ratioIndex.size() ; iRatio ++ ) { + + TString hName; + if (nameStyle == 1) + hName = basePath + "h" + + lvlN[ ratioIndex[ iRatio ].first ] + "vs" + lvlN[ ratioIndex[ iRatio ].second ] + + varN[iVar] + "Efficiency" + nameApp; + + if (nameStyle == 2) + hName = basePath + "h" + + lvlN[ ratioIndex[ iRatio ].first ] + "OfflineRatio" + + varN[iVar] + nameApp; + + if ( ! CheckHistogram(f, hName.Data()) ) return; + hEff[iRatio][iVar] = (TH1F*) ( f->Get(hName.Data()) ); + hEff[iRatio][iVar] -> Divide ( hRoI[ ratioIndex[ iRatio ].first ][iVar], + hRoI[ ratioIndex[ iRatio ].second ][iVar], + 1.0, 1.0, "b" ); + + hEff[iRatio][iVar] -> Write ( "" , TObject::kOverwrite ); + } + } + + f->Write(); + } + +} + + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_IDAlignPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_IDAlignPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f1dd9392f72c17b5912b490755f692a304bb833a --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_IDAlignPostProcess.cxx @@ -0,0 +1,2866 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: MonitoringFile_IDAlignPostProcess.cxx,v 1.1 2009-04-03 08:48:00 ponyisi Exp $ +// Revisited by Pierfrancesco Butti +// ********************************************************************** + +#include "DataQualityUtils/MonitoringFile.h" + +#include <cmath> +#include <vector> +#include <iostream> +#include <sstream> + +#include <TCanvas.h> +#include <TF1.h> +#include <TFile.h> +#include <TH1.h> +#include <TH2.h> +#include <TH3.h> +#include <TKey.h> +#include <TMath.h> +#include <TProfile.h> + +namespace dqutils { + + +void +MonitoringFile:: +fitMergedFile_IDAlignMonManager( std::string inFilename, bool /* isIncremental */ ) +{ + /* std::cout << "\n"; + std::cout << "Running Inner-Detector alignment-monitoring analysis\n"; + std::cout << "\nWarning messages from fitting and histogram updating follow:\n\n"; */ + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + if (f == 0 || ! f->IsOpen()) { + //std::cerr << "MonitoringFile::fitMergedFile_IDAlignMonManager(): " + //<< "Input file not opened\n"; + delete f; + return; + } + if(f->GetSize()<1000.) { + //std::cerr << "MonitoringFile::fitMergedFile_IDAlignMonManager(): " +// << "MonitoringFile empty\n"; + delete f; + return; + } + + std::string run_dir; + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*>( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if (tdir_run !=0 ) { + std::string tdir_run_name( tdir_run->GetName() ); + if (tdir_run_name.find("run")!= std::string::npos ) { + run_dir=tdir_run_name; + // std::cout<<"Run_directory: "<<run_dir<<std::endl; + TIter next_perf(tdir_run->GetListOfKeys()); + TKey* key_perf(0); + while ((key_perf=dynamic_cast<TKey*>( next_perf() ))!=0 ) { + std::string perf_name(key_perf->GetName()); + // for hist file with run_directory + if (perf_name.find("IDAlignMon")!=std::string::npos){ + TObject* obj_perf = key_perf->ReadObj(); + TDirectory* tdir_perf = dynamic_cast<TDirectory*>( obj_perf ); + if (tdir_perf !=0) { + run_dir=run_dir+'/'; + TIter next_tracks(tdir_perf->GetListOfKeys()); + TKey* key_tracks(0); + + while ((key_tracks=dynamic_cast<TKey*>(next_tracks() )) !=0) { + std::string tracks_name(key_tracks->GetName()); + //std::cout<<"looking at tracks dir: "<<tracks_name<<std::endl; + if (tracks_name.find("Tracks")!=std::string::npos) { + //std::cout<<"Found tracks name: "<<tracks_name<<std::endl; + TObject *obj = key_tracks->ReadObj(); + TDirectory *tdir = dynamic_cast<TDirectory*>(obj); + if ( tdir !=0 ) { + TIter next_module(tdir->GetListOfKeys()); + TKey* key_module(0); + while((key_module=dynamic_cast<TKey*>(next_module()))!=0) { + std::string module_name=key_module->GetName(); + //std::cout<<"looking at module: "<<module_name<<std::endl; + if (module_name.find("Residuals")!=std::string::npos) { + //std::cout<<"Find Module: "<<module_name<<std::endl; + fitMergedFile_IDAlignMonResiduals( f,run_dir,tracks_name ); + } + + if (module_name.find("TrackSegments")!=std::string::npos) { + //std::cout<<"Find Module: "<<module_name<<std::endl; + fitMergedFile_IDAlignMonTrackSegments( f,run_dir,tracks_name ); + } + + if (module_name.find("GenericTracks")!=std::string::npos) { + //std::cout<<"Find Module: "<<module_name<<std::endl; + fitMergedFile_IDAlignMonGenericTracks( f,run_dir,tracks_name ); + } + } + } + else // This was not a TDirectory, delete it! + { + delete obj; + } + } + } + } + else // This was not a TDirectory, delete it! + { + delete obj_perf; + } + } + } + } + + // if without top run_directory + else if (tdir_run_name.find("IDAlignMon")!= std::string::npos ) { + //std::cout<<"without run_directory"<<std::endl; + TObject* obj_perf = key_run->ReadObj(); + TDirectory* tdir_perf = dynamic_cast<TDirectory*>( obj_perf ); + if (tdir_perf !=0) { + run_dir='/'; + TIter next_tracks(tdir_perf->GetListOfKeys()); + TKey* key_tracks(0); + + while ((key_tracks=dynamic_cast<TKey*>(next_tracks() )) !=0) { + std::string tracks_name(key_tracks->GetName()); + //std::cout<<"looking at tracks dir: "<<tracks_name<<std::endl; + if (tracks_name.find("Tracks")!=std::string::npos) { + //std::cout<<"Found tracks name: "<<tracks_name<<std::endl; + TObject *obj = key_tracks->ReadObj(); + TDirectory *tdir = dynamic_cast<TDirectory*>(obj); + if ( tdir !=0 ) { + TIter next_module(tdir->GetListOfKeys()); + TKey* key_module(0); + while((key_module=dynamic_cast<TKey*>(next_module()))!=0) { + std::string module_name=key_module->GetName(); + //std::cout<<"looking at module: "<<module_name<<std::endl; + if (module_name.find("Residuals")!=std::string::npos) { + //std::cout<<"Find Module: "<<module_name<<std::endl; + fitMergedFile_IDAlignMonResiduals( f,run_dir,tracks_name ); + } + + if (module_name.find("TrackSegments")!=std::string::npos) { + //std::cout<<"Find Module: "<<module_name<<std::endl; + fitMergedFile_IDAlignMonTrackSegments( f,run_dir,tracks_name ); + } + + if (module_name.find("GenericTracks")!=std::string::npos) { + //std::cout<<"Find Module: "<<module_name<<std::endl; + fitMergedFile_IDAlignMonGenericTracks( f,run_dir,tracks_name ); + } + } + } + else + { + delete obj; + } + } + } + } + else + { + delete obj_perf; + } + } + //else + //std::cerr<<"directory IDAlignMon doesn't exist !"<<std::endl; + } + else + { + delete obj_run; + } + } + + f->Close(); + delete f; + //std::cout << "\n"; + //std::cout << "Finish Inner-Detector alignment-monitoring analysis"<<std::endl; +} + + +void +MonitoringFile:: +fitMergedFile_IDAlignMonTrackSegments( TFile* file, std::string run_dir, std::string tracksName ) +{ + + //std::cout << "in fitMergedFile_IDAlignMonTrackSegments " << std::endl; + + std::string path; + path= run_dir + "IDAlignMon/" + tracksName + "/TrackSegments"; + if( file->cd(path.c_str())==0 ) { + //std::cerr << "MonitoringFile::fitMergedFile_IDAlignMonTrackSegments(): " + // << "No such directory \"" << path << "\"\n"; + return; + } + + //The Charge Mis-Indentification Histograms + //=========================================== + + unsigned int nChargeHistograms = 4; + + //The input/source files + TH2F* m_oldChargeHists[4]; + + //The output/destination files + TH1F* m_newChargeHists[4]; + + //The names of the input files + std::string chargeHistNames[4]; + chargeHistNames[0] = "delta_chargeVsPtLow"; + chargeHistNames[1] = "delta_chargeVsPtUp"; + chargeHistNames[2] = "delta_chargeVsD0"; + chargeHistNames[3] = "delta_chargeVsZ0"; + + std::string chargeHistTitle[4]; + chargeHistTitle[0] = "Mis-Id ratio vs pT (Low)"; + chargeHistTitle[1] = "Mis-Id ratio vs pT (Up)"; + chargeHistTitle[2] = "Mis-Id ratio vs d_{0}"; + chargeHistTitle[3] = "Mis-Id ratio vs Z0"; + + std::string chargeHistXAxisTitles[4]; + chargeHistXAxisTitles[0] = "p_{T} Low (GeV)"; + chargeHistXAxisTitles[1] = "p_{T} Up (GeV)"; + chargeHistXAxisTitles[2] = "d_{0} (mm)"; + chargeHistXAxisTitles[3] = "z_{0} (mm)"; + + //loop over the number of histograms to be created + for(unsigned int j = 0; j< nChargeHistograms; ++j){ + + //We write the hist only if the input exist. + if (!CheckHistogram(file,(path+"/"+chargeHistNames[j]).c_str())) continue; + + //get them + m_oldChargeHists[j] = (TH2F*)(file->Get((path+"/"+chargeHistNames[j]).c_str())); + + //get binning + unsigned int nbinsX = m_oldChargeHists[j]->GetNbinsX(); + float LE = m_oldChargeHists[j]->GetBinLowEdge(1); + float UE = m_oldChargeHists[j]->GetBinLowEdge(nbinsX+1); + + //create the new files + m_newChargeHists[j] = new TH1F(("ratio_"+chargeHistNames[j]).c_str(),"",nbinsX,LE,UE); + + //Fill the new files + for(unsigned int xBin = 1; xBin!=nbinsX+1; xBin++){ + float ChargeMinus2 = m_oldChargeHists[j]->GetBinContent(xBin,2); + float ChargePlus2 = m_oldChargeHists[j]->GetBinContent(xBin,6); + float ChargeCorrect = m_oldChargeHists[j]->GetBinContent(xBin,4); + float ChargeWrong = ChargeMinus2+ChargePlus2; + if(ChargeCorrect > 0){ + m_newChargeHists[j]->SetBinContent(xBin,(ChargeWrong)/(ChargeCorrect+ChargeWrong)); + m_newChargeHists[j]->SetBinError(xBin,1.0/ChargeCorrect * pow(ChargeWrong * (1.0 + ChargeWrong/ChargeCorrect) ,0.5) ); + }else{ + if(ChargeWrong > 0) + m_newChargeHists[j]->SetBinContent(xBin,1); + else + m_newChargeHists[j]->SetBinContent(xBin,0); + m_newChargeHists[j]->SetBinError(xBin,0); + } + }//Fill the new histograms + + m_newChargeHists[j]->SetTitle((chargeHistTitle[j]).c_str()); + m_newChargeHists[j]->GetXaxis()->SetTitle((chargeHistXAxisTitles[j]).c_str()); + + }//over charged hists + + + //Write out the charge mis-id histograms + file->Write(); + for(unsigned int j = 0; j< nChargeHistograms; ++j){ + + //If the original hist dosn't exist, we didnt make a new one, + // so we dont write the new one + if (!CheckHistogram(file,(path+"/"+chargeHistNames[j]).c_str())) continue; + + m_newChargeHists[j]->Write("",TObject::kOverwrite); + } + + + //Delta Track Parameter Vs Track Parameter Profiles + //================================================== + + //The input histograms + TH2F* m_oldHists[30*3]; + + //The output histograms + TH1F* m_newHists[30*3*2]; + + //The names of the input files + std::string histNames[30]; + histNames[0] = "delta_d0VsD0"; + histNames[1] = "delta_d0VsZ0"; + histNames[2] = "delta_d0VsPhi0"; + histNames[3] = "delta_d0VsPt"; + histNames[4] = "delta_d0VsEta"; + + histNames[5] = "delta_eta0VsD0"; + histNames[6] = "delta_eta0VsZ0"; + histNames[7] = "delta_eta0VsPhi0"; + histNames[8] = "delta_eta0VsPt"; + histNames[9] = "delta_eta0VsEta"; + + histNames[10] = "delta_phi0VsD0"; + histNames[11] = "delta_phi0VsZ0"; + histNames[12] = "delta_phi0VsPhi0"; + histNames[13] = "delta_phi0VsPt"; + histNames[14] = "delta_phi0VsEta"; + + histNames[15] = "delta_qOverPtVsD0"; + histNames[16] = "delta_qOverPtVsZ0"; + histNames[17] = "delta_qOverPtVsPhi0"; + histNames[18] = "delta_qOverPtVsPt"; + histNames[19] = "delta_qOverPtVsEta"; + + histNames[20] = "delta_z0VsD0"; + histNames[21] = "delta_z0VsZ0"; + histNames[22] = "delta_z0VsPhi0"; + histNames[23] = "delta_z0VsPt"; + histNames[24] = "delta_z0VsEta"; + + histNames[25] = "delta_nHitsVsD0"; + histNames[26] = "delta_nHitsVsZ0"; + histNames[27] = "delta_nHitsVsPhi0"; + histNames[28] = "delta_nHitsVsPt"; + histNames[29] = "delta_nHitsVsEta"; + + std::string histTitles[30]; + std::string m_titlePrefix[2] = {"average_","sigma_"}; + std::string m_titlePostfix[3] = {"","(Positive Tracks)","(Negative Tracks)"}; + + histTitles[0] = "#Delta d_{0} vs d_{0}^{Upper} "; + histTitles[1] = "#Delta d_{0} vs z_{0}^{Upper} "; + histTitles[2] = "#Delta d_{0} vs #phi_{0}^{Upper} "; + histTitles[3] = "#Delta d_{0} vs p_{T}^{Upper} "; + histTitles[4] = "#Delta d_{0} vs #eta^{Upper} "; + + histTitles[5] = "#Delta #eta vs d_{0}^{Upper} "; + histTitles[6] = "#Delta #eta vs z_{0}^{Upper} "; + histTitles[7] = "#Delta #eta vs #phi_{0}^{Upper} "; + histTitles[8] = "#Delta #eta vs p_{T}^{Upper} "; + histTitles[9] = "#Delta #eta vs #eta^{Upper} "; + + histTitles[10] = "#Delta phi vs d_{0}^{Upper} "; + histTitles[11] = "#Delta phi vs z_{0}^{Upper} "; + histTitles[12] = "#Delta phi vs phi0^{Upper} "; + histTitles[13] = "#Delta phi vs p_{T}^{Upper} "; + histTitles[14] = "#Delta phi vs #eta^{Upper} "; + + histTitles[15] = "#Delta q/p_{T} vs d_{0}^{Upper} "; + histTitles[16] = "#Delta q/p_{T} vs z_{0}^{Upper} "; + histTitles[17] = "#Delta q/p_{T} vs #phi_{0}^{Upper} "; + histTitles[18] = "#Delta q/p_{T} vs p_{T}^{Upper} "; + histTitles[19] = "#Delta q/p_{T} vs #eta^{Upper} "; + + histTitles[20] = "#Delta z_{0} vs d_{0}^{Upper} "; + histTitles[21] = "#Delta z_{0} vs z_{0}^{Upper} "; + histTitles[22] = "#Delta z_{0} vs #phi_{0}^{Upper} "; + histTitles[23] = "#Delta z_{0} vs p_{T}^{Upper} "; + histTitles[24] = "#Delta z_{0} vs #eta^{Upper} "; + + histTitles[25] = "#Delta nHits vs d_{0}^{Upper} "; + histTitles[26] = "#Delta nHits vs z_{0}^{Upper} "; + histTitles[27] = "#Delta nHits vs #phi_{0}^{Upper} "; + histTitles[28] = "#Delta nHits vs p_{T}^{Upper} "; + histTitles[29] = "#Delta nHits vs #eta^{Upper} "; + + std::string histXAxisTitles[5]; + histXAxisTitles[0] = "d_{0}^{Upper} (mm)"; + histXAxisTitles[1] = "z_{0}^{Upper} (mm)"; + histXAxisTitles[2] = "#phi_{0}^{Upper} (rad)"; + histXAxisTitles[3] = "p_{T}^{Upper} (GeV)"; + histXAxisTitles[4] = "#eta^{Upper}"; + + std::string histYAxisTitles[6]; + histYAxisTitles[0] = "#Delta d_{0} (mm)"; + histYAxisTitles[1] = "#Delta #eta"; + histYAxisTitles[2] = "#Delta #phi (rad)"; + histYAxisTitles[3] = "#Delta q/p_{T} (1.0/GeV)"; + histYAxisTitles[4] = "#Delta z_{0} (mm)"; + histYAxisTitles[5] = "#Delta nHits"; + + //loop over combined/positive/negative + for(unsigned int i = 0; i < 3; ++i){ + //loop over the number of profiles to be created + for(unsigned int j = 0; j< 30; ++j){ + + std::string m_histNames; + + //Charged or Combo? + if(i == 0) + m_histNames += histNames[j]; + + if(i == 1) + m_histNames += histNames[j]+"_p"; + + if(i == 2) + m_histNames += histNames[j]+"_n"; + + //We write the hist only if the input exist. + if (!CheckHistogram(file,(path+"/"+m_histNames).c_str())){ + m_oldHists[30*i+j] = 0; + continue; + } + + //get them + m_oldHists[30*i+j] = (TH2F*)(file->Get((path+"/"+m_histNames).c_str())); + + //get binning + unsigned int nbinsX = m_oldHists[30*i+j]->GetNbinsX(); + unsigned int nbinsY = m_oldHists[30*i+j]->GetNbinsY(); + float xLE = m_oldHists[30*i+j]->GetXaxis()->GetBinLowEdge(1); + float xUE = m_oldHists[30*i+j]->GetXaxis()->GetBinLowEdge(nbinsX+1); + float yLE = m_oldHists[30*i+j]->GetYaxis()->GetBinLowEdge(1); + float yUE = m_oldHists[30*i+j]->GetYaxis()->GetBinLowEdge(nbinsY+1); + + //std::cout << "i = " << i << std::endl; + //std::cout << "j = " << j << std::endl; + //loop over Average/Sigma + for(unsigned int k = 0; k < 2; ++k){ + //std::cout << "k = " << k << std::endl; + + //create the new files + m_newHists[2*(30*i+j)+k] = new TH1F((m_titlePrefix[k]+m_histNames).c_str(),"",nbinsX,xLE,xUE); + + //Fill the new histograms + fillGaussianMeanOrWidth(m_oldHists[30*i+j], m_newHists[2*(30*i+j)+k],yLE,yUE,k); + + m_newHists[2*(30*i+j)+k]->SetTitle((m_titlePrefix[k]+m_histNames+m_titlePostfix[i]).c_str()); + m_newHists[2*(30*i+j)+k]->GetXaxis()->SetTitle((histXAxisTitles[j%5]).c_str()); + if(j<5) + m_newHists[2*(30*i+j)+k]->GetYaxis()->SetTitle((histYAxisTitles[0]).c_str()); + else if(j<10) + m_newHists[2*(30*i+j)+k]->GetYaxis()->SetTitle((histYAxisTitles[1]).c_str()); + else if(j<15) + m_newHists[2*(30*i+j)+k]->GetYaxis()->SetTitle((histYAxisTitles[2]).c_str()); + else if(j<20) + m_newHists[2*(30*i+j)+k]->GetYaxis()->SetTitle((histYAxisTitles[3]).c_str()); + else if(j<25) + m_newHists[2*(30*i+j)+k]->GetYaxis()->SetTitle((histYAxisTitles[4]).c_str()); + else if(j<30) + m_newHists[2*(30*i+j)+k]->GetYaxis()->SetTitle((histYAxisTitles[5]).c_str()); + }//over the mean or the sigma + + }//over the histgrams (j) + }//over the charge (i) + + + //loop over combined/positive/negative + for(unsigned int i = 0; i < 3; ++i){ + //loop over the number of profiles to be created + for(unsigned int j = 0; j< 30; ++j){ + //loop over average/mean + for(unsigned int k = 0; k < 2; ++k){ + std::string m_histNames; + if(i == 0) + m_histNames = histNames[j]; + + if(i == 1) + m_histNames = histNames[j]+"_p"; + + if(i == 2) + m_histNames = histNames[j]+"_n"; + + //If the original hist dosn't exist, we didnt make a new one, + // so we dont write the new one + // if (!CheckHistogram(file,(path+"/"+m_histNames).c_str())){ + // continue; + // } + if (m_oldHists[30*i+j] == 0) { + //std::cout << m_histNames << " not found" << std::endl; + continue; + } + + m_newHists[2*(30*i+j)+k]->Write("",TObject::kOverwrite); + } + } + } + + //Write out the delta trackP vs trackP profiles + //20100217 - moved here to avoid file corruption - PUEO + file->Write(); + return; +} + +/// + +void +MonitoringFile:: +fitMergedFile_IDAlignMonResiduals( TFile* f, std::string run_dir, std::string tracksName ) +{ + + const float minSiResMeanWindow = -0.1; + const float maxSiResMeanWindow = 0.1; + const float minSiResWidthWindow = 0.0; + const float maxSiResWidthWindow = 0.3; + const float minSiPullWidthWindow = 0.0; + const float maxSiPullWidthWindow = 2.0; + + bool doOverlapResiduals = false; + + std::string path; + path= run_dir + "IDAlignMon/" + tracksName + "/Residuals"; + if( f->cd(path.c_str())==0 ) { + //std::cerr << "MonitoringFile::fitMergedFile_IDAlignMonResiduals(): " + // << "No such directory \"" << path << "\"\n"; + return; + } + + TObjArray* plots = new TObjArray[10];//used for performing operations on histos + + //2d histograms from which the fits/means will be taken - checking they exist + if (!CheckHistogram(f,(path+"/si_barrel_pullX").c_str())) return; + if (!CheckHistogram(f,(path+"/si_eca_pullX").c_str())) return; + if (!CheckHistogram(f,(path+"/si_ecc_pullX").c_str())) return; + if (!CheckHistogram(f,(path+"/si_barrel_pullY").c_str())) return; + if (!CheckHistogram(f,(path+"/si_eca_pullY").c_str())) return; + if (!CheckHistogram(f,(path+"/si_ecc_pullY").c_str())) return; + + if (!CheckHistogram(f,(path+"/si_barrel_resX").c_str())) return; + if (!CheckHistogram(f,(path+"/si_eca_resX").c_str())) return; + if (!CheckHistogram(f,(path+"/si_ecc_resX").c_str())) return; + if (!CheckHistogram(f,(path+"/si_barrel_resY").c_str())) return; + if (!CheckHistogram(f,(path+"/si_eca_resY").c_str())) return; + if (!CheckHistogram(f,(path+"/si_ecc_resY").c_str())) return; + + if (!CheckHistogram(f,(path+"/pix_eca_xresvsmodphi_2d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_eca_yresvsmodphi_2d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_ecc_xresvsmodphi_2d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_ecc_yresvsmodphi_2d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_eca_xresvsmodphi_2d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_ecc_xresvsmodphi_2d").c_str())) return; + + std::vector<TH3F*> m_pix_b_xresvsmodetaphi_3ds; + for (int i=0; i<4; i++) + { + std::stringstream stm; + stm<<i; + if (CheckHistogram(f,(path+"/pix_b"+stm.str()+"_xresvsmodetaphi_3d").c_str())) + m_pix_b_xresvsmodetaphi_3ds.push_back((TH3F*) (f->Get((path+"/pix_b"+stm.str()+"_xresvsmodetaphi_3d").c_str()))); + else + std::cout<<"WARNING: The histogram "<<(path+"/pix_b"+stm.str()+"_xresvsmodetaphi_3d").c_str()<<" can't be found"<<std::cout; + stm.str(std::string()); + } + + + //if (!CheckHistogram(f,(path+"/pix_b0_xresvsmodetaphi_3d").c_str())) return; + //if (!CheckHistogram(f,(path+"/pix_b1_xresvsmodetaphi_3d").c_str())) return; + //if (!CheckHistogram(f,(path+"/pix_b2_xresvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b0_yresvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b1_yresvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b2_yresvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b0_xresvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b1_xresvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b2_xresvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b3_xresvsmodetaphi_3d").c_str())) return; + + if (CheckHistogram(f,(path+"/pix_b0_Oxresxvsmodetaphi_3d").c_str())) { + + doOverlapResiduals = true; + if (!CheckHistogram(f,(path+"/pix_b0_Oxresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b1_Oxresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b2_Oxresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b0_Oxresyvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b1_Oxresyvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b2_Oxresyvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b0_Oyresyvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b1_Oyresyvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b2_Oyresyvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b0_Oyresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b1_Oyresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/pix_b2_Oyresxvsmodetaphi_3d").c_str())) return; + + if (!CheckHistogram(f,(path+"/sct_b0_Oxresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b1_Oxresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b2_Oxresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b3_Oxresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b0_Oyresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b1_Oyresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b2_Oyresxvsmodetaphi_3d").c_str())) return; + if (!CheckHistogram(f,(path+"/sct_b3_Oyresxvsmodetaphi_3d").c_str())) return; + } + //else std::cout << "no overlap residual histograms found - will not process overlap residuals" << std::endl; + + //get the 2d histograms from the file + TH2F* m_si_barrel_pullX = (TH2F*)(f->Get((path+"/si_barrel_pullX").c_str())); + TH2F* m_si_eca_pullX = (TH2F*)(f->Get((path+"/si_eca_pullX").c_str())); + TH2F* m_si_ecc_pullX = (TH2F*)(f->Get((path+"/si_ecc_pullX").c_str())); + TH2F* m_si_barrel_pullY = (TH2F*)(f->Get((path+"/si_barrel_pullY").c_str())); + TH2F* m_si_eca_pullY = (TH2F*)(f->Get((path+"/si_eca_pullY").c_str())); + TH2F* m_si_ecc_pullY = (TH2F*)(f->Get((path+"/si_ecc_pullY").c_str())); + + TH2F* m_si_barrel_resX = (TH2F*)(f->Get((path+"/si_barrel_resX").c_str())); + TH2F* m_si_eca_resX = (TH2F*)(f->Get((path+"/si_eca_resX").c_str())); + TH2F* m_si_ecc_resX = (TH2F*)(f->Get((path+"/si_ecc_resX").c_str())); + TH2F* m_si_barrel_resY = (TH2F*)(f->Get((path+"/si_barrel_resY").c_str())); + TH2F* m_si_eca_resY = (TH2F*)(f->Get((path+"/si_eca_resY").c_str())); + TH2F* m_si_ecc_resY = (TH2F*)(f->Get((path+"/si_ecc_resY").c_str())); + + TH2F* m_pix_eca_xresvsmodphi_2d = (TH2F*)(f->Get((path+"/pix_eca_xresvsmodphi_2d").c_str())); + TH2F* m_pix_eca_yresvsmodphi_2d = (TH2F*)(f->Get((path+"/pix_eca_yresvsmodphi_2d").c_str())); + TH2F* m_pix_ecc_xresvsmodphi_2d = (TH2F*)(f->Get((path+"/pix_ecc_xresvsmodphi_2d").c_str())); + TH2F* m_pix_ecc_yresvsmodphi_2d = (TH2F*)(f->Get((path+"/pix_ecc_yresvsmodphi_2d").c_str())); + TH2F* m_sct_eca_xresvsmodphi_2d = (TH2F*)(f->Get((path+"/sct_eca_xresvsmodphi_2d").c_str())); + TH2F* m_sct_ecc_xresvsmodphi_2d = (TH2F*)(f->Get((path+"/sct_ecc_xresvsmodphi_2d").c_str())); + + //3-d histograms + TH3F* m_pix_b0_xresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b0_xresvsmodetaphi_3d").c_str())); + TH3F* m_pix_b1_xresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b1_xresvsmodetaphi_3d").c_str())); + TH3F* m_pix_b2_xresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b2_xresvsmodetaphi_3d").c_str())); + TH3F* m_pix_b0_yresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b0_yresvsmodetaphi_3d").c_str())); + TH3F* m_pix_b1_yresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b1_yresvsmodetaphi_3d").c_str())); + TH3F* m_pix_b2_yresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b2_yresvsmodetaphi_3d").c_str())); + TH3F* m_sct_b0_xresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b0_xresvsmodetaphi_3d").c_str())); + TH3F* m_sct_b1_xresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b1_xresvsmodetaphi_3d").c_str())); + TH3F* m_sct_b2_xresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b2_xresvsmodetaphi_3d").c_str())); + TH3F* m_sct_b3_xresvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b3_xresvsmodetaphi_3d").c_str())); + + + + // Ideally we would like to clone the existing histograms from the file instead of recreating them here + // but there seems to be no way to then persistify the cloned histograms (i.e. write them back to the file) + //const Int_t nx = 21; + //TString siliconLayers[nx] = {"Pix L0","Pix L1","Pix L2","SCT L0 S0","S1","SCT L1 S0","S1","SCT L2 S0","S1","SCT L3 S0","S1","SCT L4 S0","S1","SCT L5 S0","S1","SCT L6 S0","S1","SCT L7 S0","S1","SCT L8 S0","S1"}; + + //pull width for each layer in Silicon barrel and endcaps + + TH1F* m_si_barrel_pullX_width = (TH1F*)(f->Get((path+"/si_barrel_pullX_width").c_str())); + std::cout<<"PF VERSION"<<std::endl; + TH1F* m_si_eca_pullX_width = (TH1F*)(f->Get((path+"/si_eca_pullX_width") .c_str())); + TH1F* m_si_ecc_pullX_width = (TH1F*)(f->Get((path+"/si_ecc_pullX_width") .c_str())); + TH1F* m_si_barrel_pullY_width = (TH1F*)(f->Get((path+"/si_barrel_pullY_width").c_str())); + TH1F* m_si_eca_pullY_width = (TH1F*)(f->Get((path+"/si_eca_pullY_width") .c_str())); + TH1F* m_si_ecc_pullY_width = (TH1F*)(f->Get((path+"/si_ecc_pullY_width") .c_str())); + fillGaussianMeanOrWidth(m_si_barrel_pullX,m_si_barrel_pullX_width,-6.0,6.0,1); + fillGaussianMeanOrWidth(m_si_barrel_pullY,m_si_barrel_pullY_width,-6.0,6.0,1); + fillGaussianMeanOrWidth(m_si_eca_pullX,m_si_eca_pullX_width,-6.0,6.0,1); + fillGaussianMeanOrWidth(m_si_eca_pullY,m_si_eca_pullY_width,-6.0,6.0,1); + fillGaussianMeanOrWidth(m_si_ecc_pullX,m_si_ecc_pullX_width,-6.0,6.0,1); + fillGaussianMeanOrWidth(m_si_ecc_pullY,m_si_ecc_pullY_width,-6.0,6.0,1); + + //pull mean for each layer in Silicon barrel and endcaps + TH1F* m_si_barrel_pullX_mean = (TH1F*)(f->Get((path+"/si_barrel_pullX_mean").c_str())); + TH1F* m_si_eca_pullX_mean = (TH1F*)(f->Get((path+"/si_eca_pullX_mean").c_str())); + TH1F* m_si_ecc_pullX_mean = (TH1F*)(f->Get((path+"/si_ecc_pullX_mean").c_str())); + TH1F* m_si_barrel_pullY_mean = (TH1F*)(f->Get((path+"/si_barrel_pullY_mean").c_str())); + TH1F* m_si_eca_pullY_mean = (TH1F*)(f->Get((path+"/si_eca_pullY_mean").c_str())); + TH1F* m_si_ecc_pullY_mean = (TH1F*)(f->Get((path+"/si_ecc_pullY_mean").c_str())); + fillGaussianMeanOrWidth(m_si_barrel_pullX,m_si_barrel_pullX_mean,-6.0,6.0,0); + fillGaussianMeanOrWidth(m_si_barrel_pullY,m_si_barrel_pullY_mean,-6.0,6.0,0); + fillGaussianMeanOrWidth(m_si_eca_pullX,m_si_eca_pullX_mean,-6.0,6.0,0); + fillGaussianMeanOrWidth(m_si_eca_pullY,m_si_eca_pullY_mean,-6.0,6.0,0); + fillGaussianMeanOrWidth(m_si_ecc_pullX,m_si_ecc_pullX_mean,-6.0,6.0,0); + fillGaussianMeanOrWidth(m_si_ecc_pullY,m_si_ecc_pullY_mean,-6.0,6.0,0); + + //residual mean for each layer in Silicon barrel and endcaps + TH1F* m_si_barrel_resX_mean = (TH1F*)(f->Get((path+"/si_barrel_resX_mean").c_str())); + TH1F* m_si_eca_resX_mean =(TH1F*)(f->Get((path+"/si_eca_resX_mean").c_str())); + TH1F* m_si_ecc_resX_mean = (TH1F*)(f->Get((path+"/si_ecc_resX_mean").c_str())); + TH1F* m_si_barrel_resY_mean = (TH1F*)(f->Get((path+"/si_barrel_resY_mean").c_str())); + TH1F* m_si_eca_resY_mean = (TH1F*)(f->Get((path+"/si_eca_resY_mean").c_str())); + TH1F* m_si_ecc_resY_mean = (TH1F*)(f->Get((path+"/si_ecc_resY_mean").c_str())); + meanRMSProjections2D(m_si_barrel_resX,m_si_barrel_resX_mean,2); + meanRMSProjections2D(m_si_barrel_resY,m_si_barrel_resY_mean,2); + meanRMSProjections2D(m_si_eca_resX,m_si_eca_resX_mean,2); + meanRMSProjections2D(m_si_eca_resY,m_si_eca_resY_mean,2); + meanRMSProjections2D(m_si_ecc_resX,m_si_ecc_resX_mean,2); + meanRMSProjections2D(m_si_ecc_resY,m_si_ecc_resY_mean,2); + + //residual width for each layer in Silicon barrel and endcaps + TH1F* m_si_barrel_resX_rms = (TH1F*)(f->Get((path+"/si_barrel_resX_rms").c_str())); + TH1F* m_si_eca_resX_rms = (TH1F*)(f->Get((path+"/si_eca_resX_rms").c_str())); + TH1F* m_si_ecc_resX_rms = (TH1F*)(f->Get((path+"/si_ecc_resX_rms").c_str())); + TH1F* m_si_barrel_resY_rms = (TH1F*)(f->Get((path+"/si_barrel_resY_rms").c_str())); + TH1F* m_si_eca_resY_rms = (TH1F*)(f->Get((path+"/si_eca_resY_rms").c_str())); + TH1F* m_si_ecc_resY_rms = (TH1F*)(f->Get((path+"/si_ecc_resY_rms").c_str())); + meanRMSProjections2D(m_si_barrel_resX,m_si_barrel_resX_rms,3); + meanRMSProjections2D(m_si_barrel_resY,m_si_barrel_resY_rms,3); + meanRMSProjections2D(m_si_eca_resX,m_si_eca_resX_rms,3); + meanRMSProjections2D(m_si_eca_resY,m_si_eca_resY_rms,3); + meanRMSProjections2D(m_si_ecc_resX,m_si_ecc_resX_rms,3); + meanRMSProjections2D(m_si_ecc_resY,m_si_ecc_resY_rms,3); + + //x residual mean as a function of ring in the Pixel barrel + //TH1F* m_pix_b0_xresvsmodeta = new TH1F("pix_b0_xresvsmodeta","X Residual Mean vs Eta-ID Pixel Barrel L0",13,-6.5,6.5); + //m_pix_b0_xresvsmodeta->GetYaxis()->SetTitle("Mean Residual X [mm]"); + //m_pix_b0_xresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + //TH1F* m_pix_b1_xresvsmodeta = new TH1F("pix_b1_xresvsmodeta","X Residual Mean vs Eta-ID Pixel Barrel L1",13,-6.5,6.5); + //m_pix_b1_xresvsmodeta->GetYaxis()->SetTitle("Mean Residual X [mm]"); + //m_pix_b1_xresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + //TH1F* m_pix_b2_xresvsmodeta = new TH1F("pix_b2_xresvsmodeta","X Residual Mean vs Eta-ID Pixel Barrel L2",13,-6.5,6.5); + //m_pix_b2_xresvsmodeta->GetYaxis()->SetTitle("Mean Residual X [mm]"); + //m_pix_b2_xresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + //meanRMSProjections3D_XY(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_xresvsmodeta,0,2); + //meanRMSProjections3D_XY(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_xresvsmodeta,0,2); + //meanRMSProjections3D_XY(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_xresvsmodeta,0,2); + //plots->Add(m_pix_b0_xresvsmodeta); + //plots->Add(m_pix_b1_xresvsmodeta); + //plots->Add(m_pix_b2_xresvsmodeta); + //TH1F* m_pix_b_xresvsmodeta = combineHistos("pix_b_xresvsmodeta","X Residual Mean vs (Modified) Eta-ID Pixel Barrel",plots,10); + //m_pix_b_xresvsmodeta->GetYaxis()->SetTitle("Mean Residual X [mm]"); + //m_pix_b_xresvsmodeta->GetXaxis()->SetTitle("(Modified) Eta-ID"); + //plots->Clear(); + + + //My personal opinion is that this is a waste of resources here. (PF) + std::vector<TH1F*> m_pix_barrel_xresvsmodeta; + + for (int i = 0; i< (int) m_pix_b_xresvsmodetaphi_3ds.size();++i) + { + std::stringstream stm; + stm<<i; + m_pix_barrel_xresvsmodeta.push_back(new TH1F(("pix_b"+stm.str()+"_xresvsmodeta").c_str(), + ("X Residual Mean vs Eta-ID Pixel Barrel L"+stm.str()+";Mean Residual X [mm];Module Eta-ID").c_str(), + m_pix_b_xresvsmodetaphi_3ds.at(i)->GetNbinsX(),((float)m_pix_b_xresvsmodetaphi_3ds.at(i)->GetNbinsX())/2., + -((float)m_pix_b_xresvsmodetaphi_3ds.at(i)->GetNbinsX())/2.)); + + stm.str(std::string()); + meanRMSProjections3D_XY(m_pix_b_xresvsmodetaphi_3ds.at(i),m_pix_barrel_xresvsmodeta.at(i),0,2); + plots->Add(m_pix_barrel_xresvsmodeta.at(i)); + } + TH1F* m_pix_b_xresvsmodeta = combineHistos("pix_b_xresvsmodeta", + "X Residual Mean vs (Modified) Eta-ID Pixel Barrel;Mean Residual X [mm];(Modified) Eta-ID", + plots,10); + plots->Clear(); + + + //x residual mean as a function of ring in the Pixel barrel. Proper function + + //TH1F* m_pix_b_xresvsmodeta = (TH1F*)(f->Get((path+"/pix_b_xresvsmodeta").c_str())); //I load the axes bin properly. + // I don't define TH1F histos. I don't save them. It's useless. So I want to process directly the proper number of + // 3D eta/phi barrel plots. + // The number of 3D eta/phi plots vary with the geometry. Would be better to not use hardcodings + // Solution 1: Loop on Keys. If yes this has to be done only one time at the beginning. + // Solution 2: Use a big number and check that the pointer to the 3D is not NULL <---- I will use this. + + + + + + + + //x residual width as a function of ring in the Pixel barrel + TH1F* m_pix_b0_xresvsmodeta_width = new TH1F("pix_b0_xresvsmodeta_width","X Residual Width vs Eta-ID Pixel Barrel L0",13,-6.5,6.5); + m_pix_b0_xresvsmodeta_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b0_xresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_pix_b1_xresvsmodeta_width = new TH1F("pix_b1_xresvsmodeta_width","X Residual Width vs Eta-ID Pixel Barrel L1",13,-6.5,6.5); + m_pix_b1_xresvsmodeta_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b1_xresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_pix_b2_xresvsmodeta_width = new TH1F("pix_b2_xresvsmodeta_width","X Residual Width vs Eta-ID Pixel Barrel L2",13,-6.5,6.5); + m_pix_b2_xresvsmodeta_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b2_xresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_xresvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_xresvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_xresvsmodeta_width,0,3); + plots->Add(m_pix_b0_xresvsmodeta_width); + plots->Add(m_pix_b1_xresvsmodeta_width); + plots->Add(m_pix_b2_xresvsmodeta_width); + TH1F* m_pix_b_xresvsmodeta_width = combineHistos("pix_b_xresvsmodeta_width","X Residual Width vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_xresvsmodeta_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b_xresvsmodeta_width->GetXaxis()->SetTitle("(Modified) Eta-ID"); + plots->Clear(); + + //y residual mean as a function of ring in the Pixel barrel + TH1F* m_pix_b0_yresvsmodeta = new TH1F("pix_b0_yresvsmodeta","Y Residual Mean vs Eta-ID Pixel Barrel L0",13,-6.5,6.5); + m_pix_b0_yresvsmodeta->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_b0_yresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_pix_b1_yresvsmodeta = new TH1F("pix_b1_yresvsmodeta","Y Residual Mean vs Eta-ID Pixel Barrel L1",13,-6.5,6.5); + m_pix_b1_yresvsmodeta->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_b1_yresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_pix_b2_yresvsmodeta = new TH1F("pix_b2_yresvsmodeta","Y Residual Mean vs Eta-ID Pixel Barrel L2",13,-6.5,6.5); + m_pix_b2_yresvsmodeta->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_b2_yresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_pix_b0_yresvsmodetaphi_3d,m_pix_b0_yresvsmodeta,0,2); + meanRMSProjections3D_XY(m_pix_b1_yresvsmodetaphi_3d,m_pix_b1_yresvsmodeta,0,2); + meanRMSProjections3D_XY(m_pix_b2_yresvsmodetaphi_3d,m_pix_b2_yresvsmodeta,0,2); + plots->Add(m_pix_b0_yresvsmodeta); + plots->Add(m_pix_b1_yresvsmodeta); + plots->Add(m_pix_b2_yresvsmodeta); + TH1F* m_pix_b_yresvsmodeta = combineHistos("pix_b_yresvsmodeta","Y Residual Mean vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_yresvsmodeta->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_b_yresvsmodeta->GetXaxis()->SetTitle("(Modified) Eta-ID"); + plots->Clear(); + + //y residual width as a function of ring in the Pixel barrel + TH1F* m_pix_b0_yresvsmodeta_width = new TH1F("pix_b0_yresvsmodeta_width","Y Residual Width vs Eta-ID Pixel Barrel L0",13,-6.5,6.5); + m_pix_b0_yresvsmodeta_width->GetYaxis()->SetTitle("Width Residual Y [mm]"); + m_pix_b0_yresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_pix_b1_yresvsmodeta_width = new TH1F("pix_b1_yresvsmodeta_width","Y Residual Width vs Eta-ID Pixel Barrel L1",13,-6.5,6.5); + m_pix_b1_yresvsmodeta_width->GetYaxis()->SetTitle("Width Residual Y [mm]"); + m_pix_b1_yresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_pix_b2_yresvsmodeta_width = new TH1F("pix_b2_yresvsmodeta_width","Y Residual Width vs Eta-ID Pixel Barrel L2",13,-6.5,6.5); + m_pix_b2_yresvsmodeta_width->GetYaxis()->SetTitle("Width Residual Y [mm]"); + m_pix_b2_yresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_pix_b0_yresvsmodetaphi_3d,m_pix_b0_yresvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_pix_b1_yresvsmodetaphi_3d,m_pix_b1_yresvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_pix_b2_yresvsmodetaphi_3d,m_pix_b2_yresvsmodeta_width,0,3); + plots->Add(m_pix_b0_yresvsmodeta_width); + plots->Add(m_pix_b1_yresvsmodeta_width); + plots->Add(m_pix_b2_yresvsmodeta_width); + TH1F* m_pix_b_yresvsmodeta_width = combineHistos("pix_b_yresvsmodeta_width","Y Residual Width vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_yresvsmodeta_width->GetYaxis()->SetTitle("Width Residual Y [mm]"); + m_pix_b_yresvsmodeta_width->GetXaxis()->SetTitle("(Modified) Eta-ID"); + plots->Clear(); + + //x residual mean as a function of stave in the Pixel barrel + TH1F* m_pix_b0_xresvsmodphi = new TH1F("pix_b0_xresvsmodphi","X Residual Mean vs Phi-ID Pixel Barrel L0",22,-0.5,21.5); + m_pix_b0_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_pix_b0_xresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_pix_b1_xresvsmodphi = new TH1F("pix_b1_xresvsmodphi","X Residual Mean vs Phi-ID Pixel Barrel L1",38,-0.5,37.5); + m_pix_b1_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_pix_b1_xresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_pix_b2_xresvsmodphi = new TH1F("pix_b2_xresvsmodphi","X Residual Mean vs Phi-ID Pixel Barrel L2",52,-0.5,51.5); + m_pix_b2_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_pix_b2_xresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_xresvsmodphi,1,2); + meanRMSProjections3D_XY(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_xresvsmodphi,1,2); + meanRMSProjections3D_XY(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_xresvsmodphi,1,2); + plots->Add(m_pix_b0_xresvsmodphi); + plots->Add(m_pix_b1_xresvsmodphi); + plots->Add(m_pix_b2_xresvsmodphi); + TH1F* m_pix_b_xresvsmodphi = combineHistos("pix_b_xresvsmodphi","X Residual Mean vs (Modified) Phi-ID Pixel Barrel",plots,10); + m_pix_b_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_pix_b_xresvsmodphi->GetXaxis()->SetTitle("(Modified) Phi-ID"); + plots->Clear(); + + //x residual width as a function of stave in the Pixel barrel + TH1F* m_pix_b0_xresvsmodphi_width = new TH1F("pix_b0_xresvsmodphi_width","X Residual Width vs Phi-ID Pixel Barrel L0",22,-0.5,21.5); + m_pix_b0_xresvsmodphi_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b0_xresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_pix_b1_xresvsmodphi_width = new TH1F("pix_b1_xresvsmodphi_width","X Residual Width vs Phi-ID Pixel Barrel L1",38,-0.5,37.5); + m_pix_b1_xresvsmodphi_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b1_xresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_pix_b2_xresvsmodphi_width = new TH1F("pix_b2_xresvsmodphi_width","X Residual Width vs Phi-ID Pixel Barrel L2",52,-0.5,51.5); + m_pix_b2_xresvsmodphi_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b2_xresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_xresvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_xresvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_xresvsmodphi_width,1,3); + plots->Add(m_pix_b0_xresvsmodphi_width); + plots->Add(m_pix_b1_xresvsmodphi_width); + plots->Add(m_pix_b2_xresvsmodphi_width); + TH1F* m_pix_b_xresvsmodphi_width = combineHistos("pix_b_xresvsmodphi_width","X Residual Width vs (Modified) Phi-ID Pixel Barrel",plots,10); + m_pix_b_xresvsmodphi_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b_xresvsmodphi_width->GetXaxis()->SetTitle("(Modified) Phi-ID"); + plots->Clear(); + + //y residual mean as a function of stave in the Pixel barrel + TH1F* m_pix_b0_yresvsmodphi = new TH1F("pix_b0_yresvsmodphi","Y Residual Mean vs Phi-ID Pixel Barrel L0",22,-0.5,21.5); + m_pix_b0_yresvsmodphi->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_b0_yresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_pix_b1_yresvsmodphi = new TH1F("pix_b1_yresvsmodphi","Y Residual Mean vs Phi-ID Pixel Barrel L1",38,-0.5,37.5); + m_pix_b1_yresvsmodphi->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_b1_yresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_pix_b2_yresvsmodphi = new TH1F("pix_b2_yresvsmodphi","Y Residual Mean vs Phi-ID Pixel Barrel L2",52,-0.5,51.5); + m_pix_b2_yresvsmodphi->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_b2_yresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_pix_b0_yresvsmodetaphi_3d,m_pix_b0_yresvsmodphi,1,2); + meanRMSProjections3D_XY(m_pix_b1_yresvsmodetaphi_3d,m_pix_b1_yresvsmodphi,1,2); + meanRMSProjections3D_XY(m_pix_b2_yresvsmodetaphi_3d,m_pix_b2_yresvsmodphi,1,2); + plots->Add(m_pix_b0_yresvsmodphi); + plots->Add(m_pix_b1_yresvsmodphi); + plots->Add(m_pix_b2_yresvsmodphi); + TH1F* m_pix_b_yresvsmodphi = combineHistos("pix_b_yresvsmodphi","Y Residual Mean vs (Modified) Phi-ID Pixel Barrel",plots,10); + m_pix_b_yresvsmodphi->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_b_yresvsmodphi->GetXaxis()->SetTitle("(Modified) Phi-ID"); + plots->Clear(); + + //y residual width as a function of stave in the Pixel barrel + TH1F* m_pix_b0_yresvsmodphi_width = new TH1F("pix_b0_yresvsmodphi_width","Y Residual Width vs Phi-ID Pixel Barrel L0",22,-0.5,21.5); + m_pix_b0_yresvsmodphi_width->GetYaxis()->SetTitle("Width Residual Y [mm]"); + m_pix_b0_yresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_pix_b1_yresvsmodphi_width = new TH1F("pix_b1_yresvsmodphi_width","Y Residual Width vs Phi-ID Pixel Barrel L1",38,-0.5,37.5); + m_pix_b1_yresvsmodphi_width->GetYaxis()->SetTitle("Width Residual Y [mm]"); + m_pix_b1_yresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_pix_b2_yresvsmodphi_width = new TH1F("pix_b2_yresvsmodphi_width","Y Residual Width vs Phi-ID Pixel Barrel L2",52,-0.5,51.5); + m_pix_b2_yresvsmodphi_width->GetYaxis()->SetTitle("Width Residual Y [mm]"); + m_pix_b2_yresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_pix_b0_yresvsmodetaphi_3d,m_pix_b0_yresvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_pix_b1_yresvsmodetaphi_3d,m_pix_b1_yresvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_pix_b2_yresvsmodetaphi_3d,m_pix_b2_yresvsmodphi_width,1,3); + plots->Add(m_pix_b0_yresvsmodphi_width); + plots->Add(m_pix_b1_yresvsmodphi_width); + plots->Add(m_pix_b2_yresvsmodphi_width); + TH1F* m_pix_b_yresvsmodphi_width = combineHistos("pix_b_yresvsmodphi_width","Y Residual Width vs (Modified) Phi-ID Pixel Barrel",plots,10); + m_pix_b_yresvsmodphi_width->GetYaxis()->SetTitle("Width Residual Y [mm]"); + m_pix_b_yresvsmodphi_width->GetXaxis()->SetTitle("(Modified) Phi-ID"); + plots->Clear(); + + //x residual mean as a function of ring in the SCT barrel + TH1F* m_sct_b0_xresvsmodeta = new TH1F("sct_b0_xresvsmodeta","X Residual Mean vs Eta-ID SCT Barrel L0",13,-0.5,12.5); + m_sct_b0_xresvsmodeta->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_b0_xresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_sct_b1_xresvsmodeta = new TH1F("sct_b1_xresvsmodeta","X Residual Mean vs Eta-ID SCT Barrel L1",13,-0.5,12.5); + m_sct_b1_xresvsmodeta->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_b1_xresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_sct_b2_xresvsmodeta = new TH1F("sct_b2_xresvsmodeta","X Residual Mean vs Eta-ID SCT Barrel L2",13,-0.5,12.5); + m_sct_b2_xresvsmodeta->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_b2_xresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_sct_b3_xresvsmodeta = new TH1F("sct_b3_xresvsmodeta","X Residual Mean vs Eta-ID SCT Barrel L3",13,-0.5,12.5); + m_sct_b3_xresvsmodeta->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_b3_xresvsmodeta->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_sct_b0_xresvsmodetaphi_3d,m_sct_b0_xresvsmodeta,0,2); + meanRMSProjections3D_XY(m_sct_b1_xresvsmodetaphi_3d,m_sct_b1_xresvsmodeta,0,2); + meanRMSProjections3D_XY(m_sct_b2_xresvsmodetaphi_3d,m_sct_b2_xresvsmodeta,0,2); + meanRMSProjections3D_XY(m_sct_b3_xresvsmodetaphi_3d,m_sct_b3_xresvsmodeta,0,2); + plots->Add(m_sct_b0_xresvsmodeta); + plots->Add(m_sct_b1_xresvsmodeta); + plots->Add(m_sct_b2_xresvsmodeta); + plots->Add(m_sct_b3_xresvsmodeta); + TH1F* m_sct_b_xresvsmodeta = combineHistos("sct_b_xresvsmodeta","X Residual Mean vs (Modified) Eta-ID SCT Barrel",plots,10); + m_sct_b_xresvsmodeta->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_b_xresvsmodeta->GetXaxis()->SetTitle("(Modified) Eta-ID"); + plots->Clear(); + + //x residual width as a function of ring in the SCT barrel + TH1F* m_sct_b0_xresvsmodeta_width = new TH1F("sct_b0_xresvsmodeta_width","X Residual Width vs Eta-ID SCT Barrel L0",13,-0.5,12.5); + m_pix_b0_xresvsmodeta_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b0_xresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_sct_b1_xresvsmodeta_width = new TH1F("sct_b1_xresvsmodeta_width","X Residual Width vs Eta-ID SCT Barrel L1",13,-0.5,12.5); + m_sct_b1_xresvsmodeta_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_sct_b1_xresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_sct_b2_xresvsmodeta_width = new TH1F("sct_b2_xresvsmodeta_width","X Residual Width vs Eta-ID SCT Barrel L2",13,-0.5,12.5); + m_sct_b2_xresvsmodeta_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_sct_b2_xresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + TH1F* m_sct_b3_xresvsmodeta_width = new TH1F("sct_b3_xresvsmodeta_width","X Residual Width vs Eta-ID SCT Barrel L3",13,-0.5,12.5); + m_sct_b3_xresvsmodeta_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_sct_b3_xresvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_sct_b0_xresvsmodetaphi_3d,m_sct_b0_xresvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_sct_b1_xresvsmodetaphi_3d,m_sct_b1_xresvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_sct_b2_xresvsmodetaphi_3d,m_sct_b2_xresvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_sct_b3_xresvsmodetaphi_3d,m_sct_b3_xresvsmodeta_width,0,3); + plots->Add(m_sct_b0_xresvsmodeta_width); + plots->Add(m_sct_b1_xresvsmodeta_width); + plots->Add(m_sct_b2_xresvsmodeta_width); + plots->Add(m_sct_b3_xresvsmodeta_width); + TH1F* m_sct_b_xresvsmodeta_width = combineHistos("sct_b_xresvsmodeta_width","X Residual Width vs (Modified) Eta-ID SCT Barrel",plots,10); + m_sct_b_xresvsmodeta_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_sct_b_xresvsmodeta_width->GetXaxis()->SetTitle("(Modified) Eta-ID"); + plots->Clear(); + + //x residual mean as a function of stave in the SCT barrel + TH1F* m_sct_b0_xresvsmodphi = new TH1F("sct_b0_xresvsmodphi","X Residual Mean vs Phi-ID SCT Barrel L0",32,-0.5,31.5); + m_pix_b0_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_pix_b0_xresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_sct_b1_xresvsmodphi = new TH1F("sct_b1_xresvsmodphi","X Residual Mean vs Phi-ID SCT Barrel L1",40,-0.5,39.5); + m_sct_b1_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_b1_xresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_sct_b2_xresvsmodphi = new TH1F("sct_b2_xresvsmodphi","X Residual Mean vs Phi-ID SCT Barrel L2",48,-0.5,47.5); + m_sct_b2_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_b2_xresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_sct_b3_xresvsmodphi = new TH1F("sct_b3_xresvsmodphi","X Residual Mean vs Phi-ID SCT Barrel L3",56,-0.5,55.5); + m_sct_b3_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_b3_xresvsmodphi->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_sct_b0_xresvsmodetaphi_3d,m_sct_b0_xresvsmodphi,1,2); + meanRMSProjections3D_XY(m_sct_b1_xresvsmodetaphi_3d,m_sct_b1_xresvsmodphi,1,2); + meanRMSProjections3D_XY(m_sct_b2_xresvsmodetaphi_3d,m_sct_b2_xresvsmodphi,1,2); + meanRMSProjections3D_XY(m_sct_b3_xresvsmodetaphi_3d,m_sct_b3_xresvsmodphi,1,2); + plots->Add(m_sct_b0_xresvsmodphi); + plots->Add(m_sct_b1_xresvsmodphi); + plots->Add(m_sct_b2_xresvsmodphi); + plots->Add(m_sct_b3_xresvsmodphi); + TH1F* m_sct_b_xresvsmodphi = combineHistos("sct_b_xresvsmodphi","X Residual Mean vs (Modified) Phi-ID SCT Barrel",plots,10); + m_sct_b_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_b_xresvsmodphi->GetXaxis()->SetTitle("(Modified) Phi-ID"); + plots->Clear(); + + //x residual width as a function of stave in the SCT barrel + TH1F* m_sct_b0_xresvsmodphi_width = new TH1F("sct_b0_xresvsmodphi_width","X Residual Width vs Phi-ID SCT Barrel L0",32,-0.5,31.5); + m_pix_b0_xresvsmodphi_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_pix_b0_xresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_sct_b1_xresvsmodphi_width = new TH1F("sct_b1_xresvsmodphi_width","X Residual Width vs Phi-ID SCT Barrel L1",40,-0.5,39.5); + m_sct_b1_xresvsmodphi_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_sct_b1_xresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_sct_b2_xresvsmodphi_width = new TH1F("sct_b2_xresvsmodphi_width","X Residual Width vs Phi-ID SCT Barrel L2",48,-0.5,47.5); + m_sct_b2_xresvsmodphi_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_sct_b2_xresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + TH1F* m_sct_b3_xresvsmodphi_width = new TH1F("sct_b3_xresvsmodphi_width","X Residual Width vs Phi-ID SCT Barrel L3",56,-0.5,55.5); + m_sct_b3_xresvsmodphi_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_sct_b3_xresvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_sct_b0_xresvsmodetaphi_3d,m_sct_b0_xresvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_sct_b1_xresvsmodetaphi_3d,m_sct_b1_xresvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_sct_b2_xresvsmodetaphi_3d,m_sct_b2_xresvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_sct_b3_xresvsmodetaphi_3d,m_sct_b3_xresvsmodphi_width,1,3); + plots->Add(m_sct_b0_xresvsmodphi_width); + plots->Add(m_sct_b1_xresvsmodphi_width); + plots->Add(m_sct_b2_xresvsmodphi_width); + plots->Add(m_sct_b3_xresvsmodphi_width); + TH1F* m_sct_b_xresvsmodphi_width = combineHistos("sct_b_xresvsmodphi_width","X Residual Width vs (Modified) Phi-ID SCT Barrel",plots,10); + m_sct_b_xresvsmodphi_width->GetYaxis()->SetTitle("Width Residual X [mm]"); + m_sct_b_xresvsmodphi_width->GetXaxis()->SetTitle("(Modified) Phi-ID"); + plots->Clear(); + + //residual mean as function of module eta/phi in Silicon endcaps + TH1F* m_pix_eca_xresvsmodphi = new TH1F("pix_eca_xresvsmodphi","X Residual Mean vs (Modified) Module Phi Pixel Endcap A",165,0,165); + m_pix_eca_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_pix_eca_xresvsmodphi->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + meanRMSProjections2D(m_pix_eca_xresvsmodphi_2d,m_pix_eca_xresvsmodphi,2); + TH1F* m_pix_eca_yresvsmodphi = new TH1F("pix_eca_yresvsmodphi","Y Residual Mean vs (Modified) Module Phi Pixel Endcap A",165,0,165); + m_pix_eca_yresvsmodphi->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_eca_yresvsmodphi->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + meanRMSProjections2D(m_pix_eca_yresvsmodphi_2d,m_pix_eca_yresvsmodphi,2); + TH1F* m_pix_ecc_xresvsmodphi = new TH1F("pix_ecc_xresvsmodphi","X Residual Mean vs (Modified) Module Phi Pixel Endcap C",165,0,165); + m_pix_ecc_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_pix_ecc_xresvsmodphi->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + meanRMSProjections2D(m_pix_ecc_xresvsmodphi_2d,m_pix_ecc_xresvsmodphi,2); + TH1F* m_pix_ecc_yresvsmodphi = new TH1F("pix_ecc_yresvsmodphi","Y Residual Mean vs (Modified) Module Phi Pixel Endcap C",165,0,165); + m_pix_ecc_yresvsmodphi->GetYaxis()->SetTitle("Mean Residual Y [mm]"); + m_pix_ecc_yresvsmodphi->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + meanRMSProjections2D(m_pix_ecc_yresvsmodphi_2d,m_pix_ecc_yresvsmodphi,2); + TH1F* m_sct_eca_xresvsmodphi = new TH1F("sct_eca_xresvsmodphi","X Residual Mean vs (Modified) Module Phi SCT Endcap A",495,0,495); + m_sct_eca_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_eca_xresvsmodphi->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + meanRMSProjections2D(m_sct_eca_xresvsmodphi_2d,m_sct_eca_xresvsmodphi,2); + TH1F* m_sct_ecc_xresvsmodphi = new TH1F("sct_ecc_xresvsmodphi","X Residual Mean vs (Modified) Module Phi SCT Endcap C",495,0,495); + m_sct_ecc_xresvsmodphi->GetYaxis()->SetTitle("Mean Residual X [mm]"); + m_sct_ecc_xresvsmodphi->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + meanRMSProjections2D(m_sct_ecc_xresvsmodphi_2d,m_sct_ecc_xresvsmodphi,2); + + + //2-d residual map histograms - pixel barrel residual mean + TH2F* m_pix_b0_xresvsmodetaphi_mean = new TH2F("pix_b0_xresvsmodetaphi_mean","X Residual Mean vs Module Eta-Phi-ID Pixel Barrel L0",13,-6.5,6.5,22,-0.5,21.5); + m_pix_b0_xresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b0_xresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b1_xresvsmodetaphi_mean = new TH2F("pix_b1_xresvsmodetaphi_mean","X Residual Mean vs Module Eta-Phi-ID Pixel Barrel L1",13,-6.5,6.5,38,-0.5,37.5); + m_pix_b1_xresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b1_xresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b2_xresvsmodetaphi_mean = new TH2F("pix_b2_xresvsmodetaphi_mean","X Residual Mean vs Module Eta-Phi-ID Pixel Barrel L2",13,-6.5,6.5,52,-0.5,51.5); + m_pix_b2_xresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b2_xresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b0_yresvsmodetaphi_mean = new TH2F("pix_b0_yresvsmodetaphi_mean","Y Residual Mean vs Module Eta-Phi-ID Pixel Barrel L0",13,-6.5,6.5,22,-0.5,21.5); + m_pix_b0_yresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b0_yresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b1_yresvsmodetaphi_mean = new TH2F("pix_b1_yresvsmodetaphi_mean","Y Residual Mean vs Module Eta-Phi-ID Pixel Barrel L1",13,-6.5,6.5,38,-0.5,37.5); + m_pix_b1_yresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b1_yresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b2_yresvsmodetaphi_mean = new TH2F("pix_b2_yresvsmodetaphi_mean","Y Residual Mean vs Module Eta-Phi-ID Pixel Barrel L2",13,-6.5,6.5,52,-0.5,51.5); + m_pix_b2_yresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b2_yresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_xresvsmodetaphi_mean,2); + meanRMSProjections3D(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_xresvsmodetaphi_mean,2); + meanRMSProjections3D(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_xresvsmodetaphi_mean,2); + meanRMSProjections3D(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_yresvsmodetaphi_mean,2); + meanRMSProjections3D(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_yresvsmodetaphi_mean,2); + meanRMSProjections3D(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_yresvsmodetaphi_mean,2); + + //2-d residual map histograms - pixel barrel residual width + TH2F* m_pix_b0_xresvsmodetaphi_rms = new TH2F("pix_b0_xresvsmodetaphi_rms","X Residual Width vs Module Eta-Phi-ID Pixel Barrel L0",13,-6.5,6.5,22,-0.5,21.5); + m_pix_b0_xresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b0_xresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b1_xresvsmodetaphi_rms = new TH2F("pix_b1_xresvsmodetaphi_rms","X Residual Width vs Module Eta-Phi-ID Pixel Barrel L1",13,-6.5,6.5,38,-0.5,37.5); + m_pix_b1_xresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b1_xresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b2_xresvsmodetaphi_rms = new TH2F("pix_b2_xresvsmodetaphi_rms","X Residual Width vs Module Eta-Phi-ID Pixel Barrel L2",13,-6.5,6.5,52,-0.5,51.5); + m_pix_b2_xresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b2_xresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b0_yresvsmodetaphi_rms = new TH2F("pix_b0_yresvsmodetaphi_rms","Y Residual Width vs Module Eta-Phi-ID Pixel Barrel L0",13,-6.5,6.5,22,-0.5,21.5); + m_pix_b0_yresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b0_yresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b1_yresvsmodetaphi_rms = new TH2F("pix_b1_yresvsmodetaphi_rms","Y Residual Width vs Module Eta-Phi-ID Pixel Barrel L1",13,-6.5,6.5,38,-0.5,37.5); + m_pix_b1_yresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b1_yresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_pix_b2_yresvsmodetaphi_rms = new TH2F("pix_b2_yresvsmodetaphi_rms","Y Residual Width vs Module Eta-Phi-ID Pixel Barrel L2",13,-6.5,6.5,52,-0.5,51.5); + m_pix_b2_yresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b2_yresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_xresvsmodetaphi_rms,3); + meanRMSProjections3D(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_xresvsmodetaphi_rms,3); + meanRMSProjections3D(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_xresvsmodetaphi_rms,3); + meanRMSProjections3D(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_yresvsmodetaphi_rms,3); + meanRMSProjections3D(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_yresvsmodetaphi_rms,3); + meanRMSProjections3D(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_yresvsmodetaphi_rms,3); + + //2-d residual map histograms - SCT barrel residual means + TH2F* m_sct_b0_xresvsmodetaphi_mean = new TH2F("sct_b0_xresvsmodetaphi_mean","X Residual Mean vs Module Eta-Phi-ID SCT Barrel L0",13,-6.5,6.5,32,-0.5,31.5); + m_sct_b0_xresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b0_xresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_sct_b1_xresvsmodetaphi_mean = new TH2F("sct_b1_xresvsmodetaphi_mean","X Residual Mean vs Module Eta-Phi-ID SCT Barrel L1",13,-6.5,6.5,40,-0.5,39.5); + m_sct_b1_xresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b1_xresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_sct_b2_xresvsmodetaphi_mean = new TH2F("sct_b2_xresvsmodetaphi_mean","X Residual Mean vs Module Eta-Phi-ID SCT Barrel L2",13,-6.5,6.5,48,-0.5,47.5); + m_sct_b2_xresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b2_xresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_sct_b3_xresvsmodetaphi_mean = new TH2F("sct_b3_xresvsmodetaphi_mean","X Residual Mean vs Module Eta-Phi-ID SCT Barrel L3",13,-6.5,6.5,56,-0.5,55.5); + m_sct_b3_xresvsmodetaphi_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b3_xresvsmodetaphi_mean->GetYaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D(m_sct_b0_xresvsmodetaphi_3d,m_sct_b0_xresvsmodetaphi_mean,2); + meanRMSProjections3D(m_sct_b1_xresvsmodetaphi_3d,m_sct_b1_xresvsmodetaphi_mean,2); + meanRMSProjections3D(m_sct_b2_xresvsmodetaphi_3d,m_sct_b2_xresvsmodetaphi_mean,2); + meanRMSProjections3D(m_sct_b3_xresvsmodetaphi_3d,m_sct_b3_xresvsmodetaphi_mean,2); + + //2-d residual map histograms - SCT barrel residual widths + TH2F* m_sct_b0_xresvsmodetaphi_rms = new TH2F("sct_b0_xresvsmodetaphi_rms","X Residual Width vs Module Eta-Phi-ID SCT Barrel L0",13,-6.5,6.5,32,-0.5,31.5); + m_sct_b0_xresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b0_xresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_sct_b1_xresvsmodetaphi_rms = new TH2F("sct_b1_xresvsmodetaphi_rms","X Residual Width vs Module Eta-Phi-ID SCT Barrel L1",13,-6.5,6.5,40,-0.5,39.5); + m_sct_b1_xresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b1_xresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_sct_b2_xresvsmodetaphi_rms = new TH2F("sct_b2_xresvsmodetaphi_rms","X Residual Width vs Module Eta-Phi-ID SCT Barrel L2",13,-6.5,6.5,48,-0.5,47.5); + m_sct_b2_xresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b2_xresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + TH2F* m_sct_b3_xresvsmodetaphi_rms = new TH2F("sct_b3_xresvsmodetaphi_rms","X Residual Width vs Module Eta-Phi-ID SCT Barrel L3",13,-6.5,6.5,56,-0.5,55.5); + m_sct_b3_xresvsmodetaphi_rms->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b3_xresvsmodetaphi_rms->GetYaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D(m_sct_b0_xresvsmodetaphi_3d,m_sct_b0_xresvsmodetaphi_rms,3); + meanRMSProjections3D(m_sct_b1_xresvsmodetaphi_3d,m_sct_b1_xresvsmodetaphi_rms,3); + meanRMSProjections3D(m_sct_b2_xresvsmodetaphi_3d,m_sct_b2_xresvsmodetaphi_rms,3); + meanRMSProjections3D(m_sct_b3_xresvsmodetaphi_3d,m_sct_b3_xresvsmodetaphi_rms,3); + + //histograms showing the distribution of Gaussian fitted residual means for pixel and SCT barrel (should add endcaps) + //modules are required to have > 30 hits + TH1F* m_pix_b0_residualmeans = new TH1F("pix_b0_residualmeans","Pixel Barrel Layer 0 Mean of Residual Distributions",100,-0.2,0.2); + m_pix_b0_residualmeans->GetXaxis()->SetTitle("Fitted Residual Mean [mm]"); + m_pix_b0_residualmeans->GetYaxis()->SetTitle("Number of Modules/4#mum"); + TH1F* m_pix_b1_residualmeans = new TH1F("pix_b1_residualmeans","Pixel Barrel Layer 1 Mean of Residual Distributions",100,-0.2,0.2); + m_pix_b1_residualmeans->GetXaxis()->SetTitle("Fitted Residual Mean [mm]"); + m_pix_b1_residualmeans->GetYaxis()->SetTitle("Number of Modules/4#mum"); + TH1F* m_pix_b2_residualmeans = new TH1F("pix_b2_residualmeans","Pixel Barrel Layer 2 Mean of Residual Distributions",100,-0.2,0.2); + m_pix_b2_residualmeans->GetXaxis()->SetTitle("Fitted Residual Mean [mm]"); + m_pix_b2_residualmeans->GetYaxis()->SetTitle("Number of Modules/4#mum"); + meanRMSProjections3D_DMRPlot(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_residualmeans,2); + meanRMSProjections3D_DMRPlot(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_residualmeans,2); + meanRMSProjections3D_DMRPlot(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_residualmeans,2); + + TH1F* m_pix_b_residualmeans = new TH1F("pix_b_residualmeans","Pixel Barrel Mean of Residual Distributions",100,-0.2,0.2); + m_pix_b_residualmeans->GetXaxis()->SetTitle("Fitted Residual Mean [mm]"); + m_pix_b_residualmeans->GetYaxis()->SetTitle("Number of Modules/4#mum"); + m_pix_b_residualmeans->Add(m_pix_b0_residualmeans); + m_pix_b_residualmeans->Add(m_pix_b1_residualmeans); + m_pix_b_residualmeans->Add(m_pix_b2_residualmeans); + + TH1F* m_sct_b0_residualmeans = new TH1F("sct_b0_residualmeans","SCT Barrel Layer 0 Mean of Residual Distributions",100,-0.2,0.2); + m_sct_b0_residualmeans->GetXaxis()->SetTitle("Fitted Residual Mean [mm]"); + m_sct_b0_residualmeans->GetYaxis()->SetTitle("Number of Modules/4#mum"); + TH1F* m_sct_b1_residualmeans = new TH1F("sct_b1_residualmeans","SCT Barrel Layer 1 Mean of Residual Distributions",100,-0.2,0.2); + m_sct_b1_residualmeans->GetXaxis()->SetTitle("Fitted Residual Mean [mm]"); + m_sct_b1_residualmeans->GetYaxis()->SetTitle("Number of Modules/4#mum"); + TH1F* m_sct_b2_residualmeans = new TH1F("sct_b2_residualmeans","SCT Barrel Layer 2 Mean of Residual Distributions",100,-0.2,0.2); + m_sct_b2_residualmeans->GetXaxis()->SetTitle("Fitted Residual Mean [mm]"); + m_sct_b2_residualmeans->GetYaxis()->SetTitle("Number of Modules/4#mum"); + TH1F* m_sct_b3_residualmeans = new TH1F("sct_b3_residualmeans","SCT Barrel Layer 3 Mean of Residual Distributions",100,-0.2,0.2); + m_sct_b3_residualmeans->GetXaxis()->SetTitle("Fitted Residual Mean [mm]"); + m_sct_b3_residualmeans->GetYaxis()->SetTitle("Number of Modules/4#mum"); + meanRMSProjections3D_DMRPlot(m_sct_b0_xresvsmodetaphi_3d,m_sct_b0_residualmeans,2); + meanRMSProjections3D_DMRPlot(m_sct_b1_xresvsmodetaphi_3d,m_sct_b1_residualmeans,2); + meanRMSProjections3D_DMRPlot(m_sct_b2_xresvsmodetaphi_3d,m_sct_b2_residualmeans,2); + meanRMSProjections3D_DMRPlot(m_sct_b3_xresvsmodetaphi_3d,m_sct_b3_residualmeans,2); + + TH1F* m_sct_b_residualmeans = new TH1F("sct_b_residualmeans","SCT Barrel Mean of Residual Distributions",100,-0.2,0.2); + m_sct_b_residualmeans->GetXaxis()->SetTitle("Fitted Residual Mean [mm]"); + m_sct_b_residualmeans->GetYaxis()->SetTitle("Number of Modules/4#mum"); + m_sct_b_residualmeans->Add(m_sct_b0_residualmeans); + m_sct_b_residualmeans->Add(m_sct_b1_residualmeans); + m_sct_b_residualmeans->Add(m_sct_b2_residualmeans); + m_sct_b_residualmeans->Add(m_sct_b3_residualmeans); + + + //histograms showing the distribution of the errors on the Gaussian-fitted residual means for Pixel and SCT + //i.e. the error on the residual mean entries for the plots above - this should not be larger than the bin size! + //modules are required to have > 30 hits + TH1F* m_pix_b0_residualfiterrors = new TH1F("pix_b0_residualfiterrors","Pixel Barrel Layer 0 Residual Gaussian Fit Error",200,0.0,0.02); + m_pix_b0_residualfiterrors->GetXaxis()->SetTitle("Residual Gaus. Fit Error [mm]"); + m_pix_b0_residualfiterrors->GetYaxis()->SetTitle("Number of Modules"); + TH1F* m_pix_b1_residualfiterrors = new TH1F("pix_b1_residualfiterrors","Pixel Barrel Layer 1 Residual Gaussian Fit Error",200,0.0,0.02); + m_pix_b1_residualfiterrors->GetXaxis()->SetTitle("Residual Gaus. Fit Error [mm]"); + m_pix_b1_residualfiterrors->GetYaxis()->SetTitle("Number of Modules"); + TH1F* m_pix_b2_residualfiterrors = new TH1F("pix_b2_residualfiterrors","Pixel Barrel Layer 2 Residual Gaussian Fit Error",200,0.0,0.02); + m_pix_b2_residualfiterrors->GetXaxis()->SetTitle("Residual Gaus. Fit Error [mm]"); + m_pix_b2_residualfiterrors->GetYaxis()->SetTitle("Number of Modules"); + meanRMSProjections3D_DMRPlot(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_residualfiterrors,5); + meanRMSProjections3D_DMRPlot(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_residualfiterrors,5); + meanRMSProjections3D_DMRPlot(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_residualfiterrors,5); + + TH1F* m_pix_b_residualfiterrors = new TH1F("pix_b_residualfiterrors","Pixel Barrel Residual Gaussian Fit Error",200,-0.0,0.02); + m_pix_b_residualfiterrors->GetXaxis()->SetTitle("Residual Gaus. Fit Error [mm]"); + m_pix_b_residualfiterrors->GetYaxis()->SetTitle("Number of Modules"); + m_pix_b_residualfiterrors->Add(m_pix_b0_residualfiterrors); + m_pix_b_residualfiterrors->Add(m_pix_b1_residualfiterrors); + m_pix_b_residualfiterrors->Add(m_pix_b2_residualfiterrors); + + + TH1F* m_sct_b0_residualfiterrors = new TH1F("sct_b0_residualfiterrors","SCT Barrel Layer 0 Residual Gaussian Fit Error",200,0.0,0.02); + m_sct_b0_residualfiterrors->GetXaxis()->SetTitle("Residual Gaus. Fit Error [mm]"); + m_sct_b0_residualfiterrors->GetYaxis()->SetTitle("Number of Modules"); + TH1F* m_sct_b1_residualfiterrors = new TH1F("sct_b1_residualfiterrors","SCT Barrel Layer 1 Residual Gaussian Fit Error",200,0.0,0.02); + m_sct_b1_residualfiterrors->GetXaxis()->SetTitle("Residual Gaus. Fit Error [mm]"); + m_sct_b1_residualfiterrors->GetYaxis()->SetTitle("Number of Modules"); + TH1F* m_sct_b2_residualfiterrors = new TH1F("sct_b2_residualfiterrors","SCT Barrel Layer 2 Residual Gaussian Fit Error",200,0.0,0.02); + m_sct_b2_residualfiterrors->GetXaxis()->SetTitle("Residual Gaus. Fit Error [mm]"); + m_sct_b2_residualfiterrors->GetYaxis()->SetTitle("Number of Modules"); + TH1F* m_sct_b3_residualfiterrors = new TH1F("sct_b3_residualfiterrors","SCT Barrel Layer 3 Residual Gaussian Fit Error",200,0.0,0.02); + m_sct_b3_residualfiterrors->GetXaxis()->SetTitle("Residual Gaus. Fit Error [mm]"); + m_sct_b3_residualfiterrors->GetYaxis()->SetTitle("Number of Modules"); + meanRMSProjections3D_DMRPlot(m_sct_b0_xresvsmodetaphi_3d,m_sct_b0_residualfiterrors,5); + meanRMSProjections3D_DMRPlot(m_sct_b1_xresvsmodetaphi_3d,m_sct_b1_residualfiterrors,5); + meanRMSProjections3D_DMRPlot(m_sct_b2_xresvsmodetaphi_3d,m_sct_b2_residualfiterrors,5); + meanRMSProjections3D_DMRPlot(m_sct_b3_xresvsmodetaphi_3d,m_sct_b3_residualfiterrors,5); + + TH1F* m_sct_b_residualfiterrors = new TH1F("sct_b_residualfiterrors","SCT Barrel Residual Gaussian Fit Error",200,-0.0,0.02); + m_sct_b_residualfiterrors->GetXaxis()->SetTitle("Residual Gaus. Fit Error [mm]"); + m_sct_b_residualfiterrors->GetYaxis()->SetTitle("Number of Modules"); + m_sct_b_residualfiterrors->Add(m_sct_b0_residualfiterrors); + m_sct_b_residualfiterrors->Add(m_sct_b1_residualfiterrors); + m_sct_b_residualfiterrors->Add(m_sct_b2_residualfiterrors); + m_sct_b_residualfiterrors->Add(m_sct_b3_residualfiterrors); + + + // median suffers from 10micron bin size in residual distributions - means that it can only take discreet values at 5 micron intervals + TH1F* m_pix_b0_residualmedians = new TH1F("pix_b0_residualmedians","Pixel Barrel Layer 0 Median of Residual Distributions",20,-0.1,0.1); + m_pix_b0_residualmedians->GetXaxis()->SetTitle("Residual Median [mm]"); + m_pix_b0_residualmedians->GetYaxis()->SetTitle("Number of Modules/10#mum"); + TH1F* m_pix_b1_residualmedians = new TH1F("pix_b1_residualmedians","Pixel Barrel Layer 1 Median of Residual Distributions",20,-0.1,0.1); + m_pix_b1_residualmedians->GetXaxis()->SetTitle("Residual Median [mm]"); + m_pix_b1_residualmedians->GetYaxis()->SetTitle("Number of Modules/10#mum"); + TH1F* m_pix_b2_residualmedians = new TH1F("pix_b2_residualmedians","Pixel Barrel Layer 2 Median of Residual Distributions",20,-0.1,0.1); + m_pix_b2_residualmedians->GetXaxis()->SetTitle("Residual Median [mm]"); + m_pix_b2_residualmedians->GetYaxis()->SetTitle("Number of Modules/10#mum"); + meanRMSProjections3D_DMRPlot(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_residualmedians,6); + meanRMSProjections3D_DMRPlot(m_pix_b1_xresvsmodetaphi_3d,m_pix_b1_residualmedians,6); + meanRMSProjections3D_DMRPlot(m_pix_b2_xresvsmodetaphi_3d,m_pix_b2_residualmedians,6); + + TH1F* m_pix_b_residualmedians = new TH1F("pix_b_residualmedians","Pixel Barrel Median of Residual Distributions",20,-0.1,0.1); + m_pix_b_residualmedians->GetXaxis()->SetTitle("Residual Median [mm]"); + m_pix_b_residualmedians->GetYaxis()->SetTitle("Number of Modules/10#mum"); + m_pix_b_residualmedians->Add(m_pix_b0_residualmedians); + m_pix_b_residualmedians->Add(m_pix_b1_residualmedians); + m_pix_b_residualmedians->Add(m_pix_b2_residualmedians); + + + TH1F* m_sct_b0_residualmedians = new TH1F("sct_b0_residualmedians","SCT Barrel Layer 0 Median of Residual Distributions",20,-0.1,0.1); + m_sct_b0_residualmedians->GetXaxis()->SetTitle("Residual Median [mm]"); + m_sct_b0_residualmedians->GetYaxis()->SetTitle("Number of Modules/10#mum"); + TH1F* m_sct_b1_residualmedians = new TH1F("sct_b1_residualmedians","SCT Barrel Layer 1 Median of Residual Distributions",20,-0.1,0.1); + m_sct_b1_residualmedians->GetXaxis()->SetTitle("Residual Median [mm]"); + m_sct_b1_residualmedians->GetYaxis()->SetTitle("Number of Modules/10#mum"); + TH1F* m_sct_b2_residualmedians = new TH1F("sct_b2_residualmedians","SCT Barrel Layer 2 Median of Residual Distributions",20,-0.1,0.1); + m_sct_b2_residualmedians->GetXaxis()->SetTitle("Residual Median [mm]"); + m_sct_b2_residualmedians->GetYaxis()->SetTitle("Number of Modules/10#mum"); + TH1F* m_sct_b3_residualmedians = new TH1F("sct_b3_residualmedians","SCT Barrel Layer 3 Median of Residual Distributions",20,-0.1,0.1); + m_sct_b3_residualmedians->GetXaxis()->SetTitle("Residual Median [mm]"); + m_sct_b3_residualmedians->GetYaxis()->SetTitle("Number of Modules/10#mum"); + meanRMSProjections3D_DMRPlot(m_sct_b0_xresvsmodetaphi_3d,m_sct_b0_residualmedians,6); + meanRMSProjections3D_DMRPlot(m_sct_b1_xresvsmodetaphi_3d,m_sct_b1_residualmedians,6); + meanRMSProjections3D_DMRPlot(m_sct_b2_xresvsmodetaphi_3d,m_sct_b2_residualmedians,6); + meanRMSProjections3D_DMRPlot(m_sct_b3_xresvsmodetaphi_3d,m_sct_b3_residualmedians,6); + + TH1F* m_sct_b_residualmedians = new TH1F("sct_b_residualmedians","SCT Barrel Median of Residual Distributions",20,-0.1,0.1); + m_sct_b_residualmedians->GetXaxis()->SetTitle("Residual Median [mm]"); + m_sct_b_residualmedians->GetYaxis()->SetTitle("Number of Modules/10#mum"); + m_sct_b_residualmedians->Add(m_sct_b0_residualmedians); + m_sct_b_residualmedians->Add(m_sct_b1_residualmedians); + m_sct_b_residualmedians->Add(m_sct_b2_residualmedians); + m_sct_b_residualmedians->Add(m_sct_b3_residualmedians); + + + //TH2F* m_pix_b0_xresvsmodetaphi_chi2 = new TH2F("pix_b0_xresvsmodetaphi_chi2","X Residual Fit Chi2/DOF vs Module Eta-Phi-ID Pixel Barrel L0",13,-6.5,6.5,22,-0.5,21.5); + //m_pix_b0_xresvsmodetaphi_chi2->GetXaxis()->SetTitle("Module Eta-ID"); + //m_pix_b0_xresvsmodetaphi_chi2->GetYaxis()->SetTitle("Module Phi-ID"); + //meanRMSProjections3D(m_pix_b0_xresvsmodetaphi_3d,m_pix_b0_xresvsmodetaphi_chi2,4); + + + //set y-axis minimum range + setMinWindow(m_si_barrel_pullX_width, minSiPullWidthWindow, maxSiPullWidthWindow); + setMinWindow(m_si_barrel_pullY_width, minSiPullWidthWindow, maxSiPullWidthWindow); + setMinWindow(m_si_eca_pullX_width, minSiPullWidthWindow, maxSiPullWidthWindow); + setMinWindow(m_si_eca_pullY_width, minSiPullWidthWindow, maxSiPullWidthWindow); + setMinWindow(m_si_ecc_pullX_width, minSiPullWidthWindow, maxSiPullWidthWindow); + setMinWindow(m_si_ecc_pullY_width, minSiPullWidthWindow, maxSiPullWidthWindow); + + setMinWindow(m_si_barrel_pullX_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_barrel_pullY_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_eca_pullX_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_eca_pullY_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_ecc_pullX_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_ecc_pullY_mean, minSiResMeanWindow, maxSiResMeanWindow); + + setMinWindow(m_si_barrel_resX_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_barrel_resY_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_eca_resX_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_eca_resY_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_ecc_resX_mean, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_si_ecc_resY_mean, minSiResMeanWindow, maxSiResMeanWindow); + + setMinWindow(m_si_barrel_resX_rms, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_si_barrel_resY_rms, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_si_eca_resX_rms, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_si_eca_resY_rms, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_si_ecc_resX_rms, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_si_ecc_resY_rms, minSiResWidthWindow, maxSiResWidthWindow); + + setMinWindow(m_pix_b_xresvsmodeta, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_pix_b_yresvsmodeta, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_pix_b_xresvsmodphi, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_pix_b_yresvsmodphi, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_sct_b_xresvsmodeta, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_sct_b_xresvsmodphi, minSiResMeanWindow, maxSiResMeanWindow); + + setMinWindow(m_pix_b_xresvsmodeta_width, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_pix_b_yresvsmodeta_width, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_pix_b_xresvsmodphi_width, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_pix_b_yresvsmodphi_width, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_sct_b_xresvsmodeta_width, minSiResWidthWindow, maxSiResWidthWindow); + setMinWindow(m_sct_b_xresvsmodphi_width, minSiResWidthWindow, maxSiResWidthWindow); + + setMinWindow(m_pix_eca_xresvsmodphi, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_pix_eca_yresvsmodphi, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_pix_ecc_xresvsmodphi, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_pix_ecc_yresvsmodphi, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_sct_eca_xresvsmodphi, minSiResMeanWindow, maxSiResMeanWindow); + setMinWindow(m_sct_ecc_xresvsmodphi, minSiResMeanWindow, maxSiResMeanWindow); + + + if( f->cd(path.c_str())==0 ) { + //std::cerr << "MonitoringFile::fitMergedFile_IDAlignMonResiduals(): " + // << "No such directory \"" << path << "\"\n"; + return; + } + + //delete the histograms already in the file with these keys so that + //they can be overwritten - we shouldn't have to do this, but seems to + //be necessary + f->Delete("si_barrel_pullX_width;1"); + f->Delete("si_eca_pullX_width;1"); + f->Delete("si_ecc_pullX_width;1"); + f->Delete("si_barrel_pullY_width;1"); + f->Delete("si_eca_pullY_width;1"); + f->Delete("si_ecc_pullY_width;1"); + + f->Delete("si_barrel_pullX_mean;1"); + f->Delete("si_eca_pullX_mean;1"); + f->Delete("si_ecc_pullX_mean;1"); + f->Delete("si_barrel_pullY_mean;1"); + f->Delete("si_eca_pullY_mean;1"); + f->Delete("si_ecc_pullY_mean;1"); + + f->Delete("si_barrel_resX_mean;1"); + f->Delete("si_eca_resX_mean;1"); + f->Delete("si_ecc_resX_mean;1"); + f->Delete("si_barrel_resY_mean;1"); + f->Delete("si_eca_resY_mean;1"); + f->Delete("si_ecc_resY_mean;1"); + + f->Delete("si_barrel_resX_rms;1"); + f->Delete("si_eca_resX_rms;1"); + f->Delete("si_ecc_resX_rms;1"); + f->Delete("si_barrel_resY_rms;1"); + f->Delete("si_eca_resY_rms;1"); + f->Delete("si_ecc_resY_rms;1"); + + f->Delete("pix_b_xresvsmodeta;1"); + f->Delete("pix_b_xresvsmodphi;1"); + f->Delete("pix_b_yresvsmodeta;1"); + f->Delete("pix_b_yresvsmodphi;1"); + f->Delete("pix_eca_xresvsmodphi;1"); + f->Delete("pix_ecc_xresvsmodphi;1"); + f->Delete("pix_eca_yresvsmodphi;1"); + f->Delete("pix_ecc_yresvsmodphi;1"); + + f->Delete("pix_b_xresvsmodeta_width;1"); + f->Delete("pix_b_yresvsmodeta_width;1"); + f->Delete("pix_b_xresvsmodphi_width;1"); + f->Delete("pix_b_yresvsmodphi_width;1"); + f->Delete("sct_b_xresvsmodeta_width;1"); + f->Delete("sct_b_xresvsmodphi_width;1"); + + f->Delete("sct_b_xresvsmodeta;1"); + f->Delete("sct_b_xresvsmodphi;1"); + f->Delete("sct_eca_xresvsmodphi;1"); + f->Delete("sct_ecc_xresvsmodphi;1"); + + f->Delete("pix_b0_xresvsmodetaphi_mean;1"); + f->Delete("pix_b1_xresvsmodetaphi_mean;1"); + f->Delete("pix_b2_xresvsmodetaphi_mean;1"); + f->Delete("pix_b0_yresvsmodetaphi_mean;1"); + f->Delete("pix_b1_yresvsmodetaphi_mean;1"); + f->Delete("pix_b2_yresvsmodetaphi_mean;1"); + + f->Delete("pix_b0_xresvsmodetaphi_rms;1"); + f->Delete("pix_b1_xresvsmodetaphi_rms;1"); + f->Delete("pix_b2_xresvsmodetaphi_rms;1"); + f->Delete("pix_b0_yresvsmodetaphi_rms;1"); + f->Delete("pix_b1_yresvsmodetaphi_rms;1"); + f->Delete("pix_b2_yresvsmodetaphi_rms;1"); + + f->Delete("sct_b0_xresvsmodetaphi_mean;1"); + f->Delete("sct_b1_xresvsmodetaphi_mean;1"); + f->Delete("sct_b2_xresvsmodetaphi_mean;1"); + f->Delete("sct_b3_xresvsmodetaphi_mean;1"); + + f->Delete("sct_b0_xresvsmodetaphi_rms;1"); + f->Delete("sct_b1_xresvsmodetaphi_rms;1"); + f->Delete("sct_b2_xresvsmodetaphi_rms;1"); + f->Delete("sct_b3_xresvsmodetaphi_rms;1"); + + //writing the histograms to the file + m_si_barrel_pullX_width->Write("",TObject::kOverwrite); + m_si_eca_pullX_width->Write("",TObject::kOverwrite); + m_si_ecc_pullX_width->Write("",TObject::kOverwrite); + m_si_barrel_pullY_width->Write("",TObject::kOverwrite); + m_si_eca_pullY_width->Write("",TObject::kOverwrite); + m_si_ecc_pullY_width->Write("",TObject::kOverwrite); + + m_si_barrel_pullX_mean->Write("",TObject::kOverwrite); + m_si_eca_pullX_mean->Write("",TObject::kOverwrite); + m_si_ecc_pullX_mean->Write("",TObject::kOverwrite); + m_si_barrel_pullY_mean->Write("",TObject::kOverwrite); + m_si_eca_pullY_mean->Write("",TObject::kOverwrite); + m_si_ecc_pullY_mean->Write("",TObject::kOverwrite); + + f->Write(); + + m_si_barrel_resX_mean->Write("",TObject::kOverwrite); + m_si_eca_resX_mean->Write("",TObject::kOverwrite); + m_si_ecc_resX_mean->Write("",TObject::kOverwrite); + m_si_barrel_resY_mean->Write("",TObject::kOverwrite); + m_si_eca_resY_mean->Write("",TObject::kOverwrite); + m_si_ecc_resY_mean->Write("",TObject::kOverwrite); + + m_si_barrel_resX_rms->Write("",TObject::kOverwrite); + m_si_eca_resX_rms->Write("",TObject::kOverwrite); + m_si_ecc_resX_rms->Write("",TObject::kOverwrite); + m_si_barrel_resY_rms->Write("",TObject::kOverwrite); + m_si_eca_resY_rms->Write("",TObject::kOverwrite); + m_si_ecc_resY_rms->Write("",TObject::kOverwrite); + + // Q: why do we need to call f->Write() more than once? + // A: Because root is a pile of horse s**t. + f->Write(); + + m_pix_b_xresvsmodeta->Write("",TObject::kOverwrite); + m_pix_b_xresvsmodphi->Write("",TObject::kOverwrite); + m_pix_b_yresvsmodeta->Write("",TObject::kOverwrite); + m_pix_b_yresvsmodphi->Write("",TObject::kOverwrite); + m_pix_eca_xresvsmodphi->Write("",TObject::kOverwrite); + m_pix_ecc_xresvsmodphi->Write("",TObject::kOverwrite); + m_pix_eca_yresvsmodphi->Write("",TObject::kOverwrite); + m_pix_ecc_yresvsmodphi->Write("",TObject::kOverwrite); + m_sct_b_xresvsmodeta->Write("",TObject::kOverwrite); + m_sct_b_xresvsmodphi->Write("",TObject::kOverwrite); + m_sct_eca_xresvsmodphi->Write("",TObject::kOverwrite); + m_sct_ecc_xresvsmodphi->Write("",TObject::kOverwrite); + + m_pix_b_xresvsmodeta_width->Write("",TObject::kOverwrite); + m_pix_b_yresvsmodeta_width->Write("",TObject::kOverwrite); + m_pix_b_xresvsmodphi_width->Write("",TObject::kOverwrite); + m_pix_b_yresvsmodphi_width->Write("",TObject::kOverwrite); + m_sct_b_xresvsmodeta_width->Write("",TObject::kOverwrite); + m_sct_b_xresvsmodphi_width->Write("",TObject::kOverwrite); + + f->Write(); + + m_pix_b0_xresvsmodetaphi_mean->Write("",TObject::kOverwrite); + m_pix_b1_xresvsmodetaphi_mean->Write("",TObject::kOverwrite); + m_pix_b2_xresvsmodetaphi_mean->Write("",TObject::kOverwrite); + m_pix_b0_yresvsmodetaphi_mean->Write("",TObject::kOverwrite); + m_pix_b1_yresvsmodetaphi_mean->Write("",TObject::kOverwrite); + m_pix_b2_yresvsmodetaphi_mean->Write("",TObject::kOverwrite); + + m_pix_b0_xresvsmodetaphi_rms->Write("",TObject::kOverwrite); + m_pix_b1_xresvsmodetaphi_rms->Write("",TObject::kOverwrite); + m_pix_b2_xresvsmodetaphi_rms->Write("",TObject::kOverwrite); + m_pix_b0_yresvsmodetaphi_rms->Write("",TObject::kOverwrite); + m_pix_b1_yresvsmodetaphi_rms->Write("",TObject::kOverwrite); + m_pix_b2_yresvsmodetaphi_rms->Write("",TObject::kOverwrite); + + //m_pix_b0_xresvsmodetaphi_chi2->Write("",TObject::kOverwrite); + + f->Write(); + + m_sct_b0_xresvsmodetaphi_mean->Write("",TObject::kOverwrite); + m_sct_b1_xresvsmodetaphi_mean->Write("",TObject::kOverwrite); + m_sct_b2_xresvsmodetaphi_mean->Write("",TObject::kOverwrite); + m_sct_b3_xresvsmodetaphi_mean->Write("",TObject::kOverwrite); + + m_sct_b0_xresvsmodetaphi_rms->Write("",TObject::kOverwrite); + m_sct_b1_xresvsmodetaphi_rms->Write("",TObject::kOverwrite); + m_sct_b2_xresvsmodetaphi_rms->Write("",TObject::kOverwrite); + m_sct_b3_xresvsmodetaphi_rms->Write("",TObject::kOverwrite); + + f->Write(); + + m_pix_b0_residualmeans->Write("",TObject::kOverwrite); + m_pix_b1_residualmeans->Write("",TObject::kOverwrite); + m_pix_b2_residualmeans->Write("",TObject::kOverwrite); + m_sct_b0_residualmeans->Write("",TObject::kOverwrite); + m_sct_b1_residualmeans->Write("",TObject::kOverwrite); + m_sct_b2_residualmeans->Write("",TObject::kOverwrite); + m_sct_b3_residualmeans->Write("",TObject::kOverwrite); + m_pix_b_residualmeans->Write("",TObject::kOverwrite); + m_sct_b_residualmeans->Write("",TObject::kOverwrite); + m_pix_b_residualmedians->Write("",TObject::kOverwrite); + m_sct_b_residualmedians->Write("",TObject::kOverwrite); + + f->Write(); + + m_pix_b0_residualfiterrors->Write("",TObject::kOverwrite); + m_pix_b1_residualfiterrors->Write("",TObject::kOverwrite); + m_pix_b2_residualfiterrors->Write("",TObject::kOverwrite); + m_sct_b0_residualfiterrors->Write("",TObject::kOverwrite); + m_sct_b1_residualfiterrors->Write("",TObject::kOverwrite); + m_sct_b2_residualfiterrors->Write("",TObject::kOverwrite); + m_sct_b3_residualfiterrors->Write("",TObject::kOverwrite); + m_pix_b_residualfiterrors->Write("",TObject::kOverwrite); + m_sct_b_residualfiterrors->Write("",TObject::kOverwrite); + + f->Write(); + + + + if(doOverlapResiduals){ + + TH3F* m_pix_b0_Oxresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b0_Oxresxvsmodetaphi_3d").c_str())); + TH3F* m_pix_b1_Oxresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b1_Oxresxvsmodetaphi_3d").c_str())); + TH3F* m_pix_b2_Oxresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b2_Oxresxvsmodetaphi_3d").c_str())); + + TH3F* m_pix_b0_Oxresyvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b0_Oxresyvsmodetaphi_3d").c_str())); + TH3F* m_pix_b1_Oxresyvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b1_Oxresyvsmodetaphi_3d").c_str())); + TH3F* m_pix_b2_Oxresyvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b2_Oxresyvsmodetaphi_3d").c_str())); + + TH3F* m_pix_b0_Oyresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b0_Oyresxvsmodetaphi_3d").c_str())); + TH3F* m_pix_b1_Oyresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b1_Oyresxvsmodetaphi_3d").c_str())); + TH3F* m_pix_b2_Oyresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b2_Oyresxvsmodetaphi_3d").c_str())); + + TH3F* m_pix_b0_Oyresyvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b0_Oyresyvsmodetaphi_3d").c_str())); + TH3F* m_pix_b1_Oyresyvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b1_Oyresyvsmodetaphi_3d").c_str())); + TH3F* m_pix_b2_Oyresyvsmodetaphi_3d = (TH3F*)(f->Get((path+"/pix_b2_Oyresyvsmodetaphi_3d").c_str())); + + TH3F* m_sct_b0_Oxresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b0_Oxresxvsmodetaphi_3d").c_str())); + TH3F* m_sct_b1_Oxresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b1_Oxresxvsmodetaphi_3d").c_str())); + TH3F* m_sct_b2_Oxresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b2_Oxresxvsmodetaphi_3d").c_str())); + TH3F* m_sct_b3_Oxresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b3_Oxresxvsmodetaphi_3d").c_str())); + + TH3F* m_sct_b0_Oyresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b0_Oyresxvsmodetaphi_3d").c_str())); + TH3F* m_sct_b1_Oyresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b1_Oyresxvsmodetaphi_3d").c_str())); + TH3F* m_sct_b2_Oyresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b2_Oyresxvsmodetaphi_3d").c_str())); + TH3F* m_sct_b3_Oyresxvsmodetaphi_3d = (TH3F*)(f->Get((path+"/sct_b3_Oyresxvsmodetaphi_3d").c_str())); + + + //XOverlap residual X mean as a function of ring in the pixel barrel (sensitive to ring-expansion,contraction distortions) + TH1F* m_pix_b0_Oxresxvsmodeta_mean = new TH1F("pix_b0_Oxresxvsmodeta_mean","X-Overlap X Residual Mean vs Eta-ID Pixel Barrel L0",13,-6.5,6.5); + TH1F* m_pix_b1_Oxresxvsmodeta_mean = new TH1F("pix_b1_Oxresxvsmodeta_mean","X-Overlap X Residual Mean vs Eta-ID Pixel Barrel L1",13,-6.5,6.5); + TH1F* m_pix_b2_Oxresxvsmodeta_mean = new TH1F("pix_b2_Oxresxvsmodeta_mean","X-Overlap X Residual Mean vs Eta-ID Pixel Barrel L2",13,-6.5,6.5); + m_pix_b0_Oxresxvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual X"); + m_pix_b1_Oxresxvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual X"); + m_pix_b2_Oxresxvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual X"); + m_pix_b0_Oxresxvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b1_Oxresxvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b2_Oxresxvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_pix_b0_Oxresxvsmodetaphi_3d,m_pix_b0_Oxresxvsmodeta_mean,0,2); + meanRMSProjections3D_XY(m_pix_b1_Oxresxvsmodetaphi_3d,m_pix_b1_Oxresxvsmodeta_mean,0,2); + meanRMSProjections3D_XY(m_pix_b2_Oxresxvsmodetaphi_3d,m_pix_b2_Oxresxvsmodeta_mean,0,2); + plots->Add(m_pix_b0_Oxresxvsmodeta_mean); + plots->Add(m_pix_b1_Oxresxvsmodeta_mean); + plots->Add(m_pix_b2_Oxresxvsmodeta_mean); + TH1F* m_pix_b_Oxresxvsmodeta_mean = combineHistos("pix_b_Oxresxvsmodeta_mean","X-Overlap X Residual Mean vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_Oxresxvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual X"); + m_pix_b_Oxresxvsmodeta_mean->GetXaxis()->SetTitle("(Modified) Module Eta-ID"); + plots->Clear(); + + //XOverlap residual X width as a function of ring in the pixel barrel (sensitive to ring-expansion,contraction distortions) + TH1F* m_pix_b0_Oxresxvsmodeta_width = new TH1F("pix_b0_Oxresxvsmodeta_width","X-Overlap X Residual Width vs Eta-ID Pixel Barrel L0",13,-6.5,6.5); + TH1F* m_pix_b1_Oxresxvsmodeta_width = new TH1F("pix_b1_Oxresxvsmodeta_width","X-Overlap X Residual Width vs Eta-ID Pixel Barrel L1",13,-6.5,6.5); + TH1F* m_pix_b2_Oxresxvsmodeta_width = new TH1F("pix_b2_Oxresxvsmodeta_width","X-Overlap X Residual Width vs Eta-ID Pixel Barrel L2",13,-6.5,6.5); + m_pix_b0_Oxresxvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual X"); + m_pix_b1_Oxresxvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual X"); + m_pix_b2_Oxresxvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual X"); + m_pix_b0_Oxresxvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b1_Oxresxvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b2_Oxresxvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_pix_b0_Oxresxvsmodetaphi_3d,m_pix_b0_Oxresxvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_pix_b1_Oxresxvsmodetaphi_3d,m_pix_b1_Oxresxvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_pix_b2_Oxresxvsmodetaphi_3d,m_pix_b2_Oxresxvsmodeta_width,0,3); + plots->Add(m_pix_b0_Oxresxvsmodeta_width); + plots->Add(m_pix_b1_Oxresxvsmodeta_width); + plots->Add(m_pix_b2_Oxresxvsmodeta_width); + TH1F* m_pix_b_Oxresxvsmodeta_width = combineHistos("pix_b_Oxresxvsmodeta_width","X-Overlap X Residual Width vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_Oxresxvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual X"); + m_pix_b_Oxresxvsmodeta_width->GetXaxis()->SetTitle("(Modified) Module Eta-ID"); + plots->Clear(); + + //XOverlap residual Y mean as a function of ring in the pixel barrel (sensitive to ring shear distortions) + TH1F* m_pix_b0_Oxresyvsmodeta_mean = new TH1F("pix_b0_Oxresyvsmodeta_mean","X-Overlap Y Residual Mean vs Eta-ID Pixel Barrel L0",13,-6.5,6.5); + TH1F* m_pix_b1_Oxresyvsmodeta_mean = new TH1F("pix_b1_Oxresyvsmodeta_mean","X-Overlap Y Residual Mean vs Eta-ID Pixel Barrel L1",13,-6.5,6.5); + TH1F* m_pix_b2_Oxresyvsmodeta_mean = new TH1F("pix_b2_Oxresyvsmodeta_mean","X-Overlap Y Residual Mean vs Eta-ID Pixel Barrel L2",13,-6.5,6.5); + m_pix_b0_Oxresyvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual Y"); + m_pix_b1_Oxresyvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual Y"); + m_pix_b2_Oxresyvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual Y"); + m_pix_b0_Oxresyvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b1_Oxresyvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b2_Oxresyvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_pix_b0_Oxresyvsmodetaphi_3d,m_pix_b0_Oxresyvsmodeta_mean,0,2); + meanRMSProjections3D_XY(m_pix_b1_Oxresyvsmodetaphi_3d,m_pix_b1_Oxresyvsmodeta_mean,0,2); + meanRMSProjections3D_XY(m_pix_b2_Oxresyvsmodetaphi_3d,m_pix_b2_Oxresyvsmodeta_mean,0,2); + plots->Add(m_pix_b0_Oxresyvsmodeta_mean); + plots->Add(m_pix_b1_Oxresyvsmodeta_mean); + plots->Add(m_pix_b2_Oxresyvsmodeta_mean); + TH1F* m_pix_b_Oxresyvsmodeta_mean = combineHistos("pix_b_Oxresyvsmodeta_mean","X-Overlap Y Residual Mean vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_Oxresyvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual Y"); + m_pix_b_Oxresyvsmodeta_mean->GetXaxis()->SetTitle("(Modified) Module Eta-ID"); + plots->Clear(); + + //XOverlap residual X width as a function of ring in the pixel barrel (sensitive to ring shear distortions) + TH1F* m_pix_b0_Oxresyvsmodeta_width = new TH1F("pix_b0_Oxresyvsmodeta_width","X-Overlap Y Residual Width vs Eta-ID Pixel Barrel L0",13,-6.5,6.5); + TH1F* m_pix_b1_Oxresyvsmodeta_width = new TH1F("pix_b1_Oxresyvsmodeta_width","X-Overlap Y Residual Width vs Eta-ID Pixel Barrel L1",13,-6.5,6.5); + TH1F* m_pix_b2_Oxresyvsmodeta_width = new TH1F("pix_b2_Oxresyvsmodeta_width","X-Overlap Y Residual Width vs Eta-ID Pixel Barrel L2",13,-6.5,6.5); + m_pix_b0_Oxresyvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual Y"); + m_pix_b1_Oxresyvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual Y"); + m_pix_b2_Oxresyvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual Y"); + m_pix_b0_Oxresyvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b1_Oxresyvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + m_pix_b2_Oxresyvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_pix_b0_Oxresyvsmodetaphi_3d,m_pix_b0_Oxresyvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_pix_b1_Oxresyvsmodetaphi_3d,m_pix_b1_Oxresyvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_pix_b2_Oxresyvsmodetaphi_3d,m_pix_b2_Oxresyvsmodeta_width,0,3); + plots->Add(m_pix_b0_Oxresyvsmodeta_width); + plots->Add(m_pix_b1_Oxresyvsmodeta_width); + plots->Add(m_pix_b2_Oxresyvsmodeta_width); + TH1F* m_pix_b_Oxresyvsmodeta_width = combineHistos("pix_b_Oxresyvsmodeta_width","X-Overlap Y Residual Width vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_Oxresyvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual Y"); + m_pix_b_Oxresyvsmodeta_width->GetXaxis()->SetTitle("(Modified) Module Eta-ID"); + plots->Clear(); + + //YOverlap residual Y mean as a function of stave in the pixel barrel (sensitive to stave-stretch distortions) + TH1F* m_pix_b0_Oyresyvsmodphi_mean = new TH1F("pix_b0_Oyresyvsmodphi_mean","Y-Overlap Y Residual Mean vs Phi-ID Pixel Barrel L0",22,-0.5,21.5); + TH1F* m_pix_b1_Oyresyvsmodphi_mean = new TH1F("pix_b1_Oyresyvsmodphi_mean","Y-Overlap Y Residual Mean vs Phi-ID Pixel Barrel L1",38,-0.5,37.5); + TH1F* m_pix_b2_Oyresyvsmodphi_mean = new TH1F("pix_b2_Oyresyvsmodphi_mean","Y-Overlap Y Residual Mean vs Phi-ID Pixel Barrel L2",52,-0.5,51.5); + m_pix_b0_Oyresyvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual Y"); + m_pix_b1_Oyresyvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual Y"); + m_pix_b2_Oyresyvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual Y"); + m_pix_b0_Oyresyvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + m_pix_b1_Oyresyvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + m_pix_b2_Oyresyvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_pix_b0_Oyresyvsmodetaphi_3d,m_pix_b0_Oyresyvsmodphi_mean,1,2); + meanRMSProjections3D_XY(m_pix_b1_Oyresyvsmodetaphi_3d,m_pix_b1_Oyresyvsmodphi_mean,1,2); + meanRMSProjections3D_XY(m_pix_b2_Oyresyvsmodetaphi_3d,m_pix_b2_Oyresyvsmodphi_mean,1,2); + plots->Add(m_pix_b0_Oyresyvsmodphi_mean); + plots->Add(m_pix_b1_Oyresyvsmodphi_mean); + plots->Add(m_pix_b2_Oyresyvsmodphi_mean); + TH1F* m_pix_b_Oyresyvsmodphi_mean = combineHistos("pix_b_Oyresyvsmodphi_mean","Y-Overlap Y Residual Mean vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_Oyresyvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual Y"); + m_pix_b_Oyresyvsmodphi_mean->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + plots->Clear(); + + //YOverlap residual Y width as a function of stave in the pixel barrel (sensitive to stave-stretch distortions) + TH1F* m_pix_b0_Oyresyvsmodphi_width = new TH1F("pix_b0_Oyresyvsmodphi_width","Y-Overlap Y Residual Width vs Phi-ID Pixel Barrel L0",22,-0.5,21.5); + TH1F* m_pix_b1_Oyresyvsmodphi_width = new TH1F("pix_b1_Oyresyvsmodphi_width","Y-Overlap Y Residual Width vs Phi-ID Pixel Barrel L1",38,-0.5,37.5); + TH1F* m_pix_b2_Oyresyvsmodphi_width = new TH1F("pix_b2_Oyresyvsmodphi_width","Y-Overlap Y Residual Width vs Phi-ID Pixel Barrel L2",52,-0.5,51.5); + m_pix_b0_Oyresyvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual Y"); + m_pix_b1_Oyresyvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual Y"); + m_pix_b2_Oyresyvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual Y"); + m_pix_b0_Oyresyvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + m_pix_b1_Oyresyvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + m_pix_b2_Oyresyvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_pix_b0_Oyresyvsmodetaphi_3d,m_pix_b0_Oyresyvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_pix_b1_Oyresyvsmodetaphi_3d,m_pix_b1_Oyresyvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_pix_b2_Oyresyvsmodetaphi_3d,m_pix_b2_Oyresyvsmodphi_width,1,3); + plots->Add(m_pix_b0_Oyresyvsmodphi_width); + plots->Add(m_pix_b1_Oyresyvsmodphi_width); + plots->Add(m_pix_b2_Oyresyvsmodphi_width); + TH1F* m_pix_b_Oyresyvsmodphi_width = combineHistos("pix_b_Oyresyvsmodphi_width","Y-Overlap Y Residual Width vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_Oyresyvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual Y"); + m_pix_b_Oyresyvsmodphi_width->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + plots->Clear(); + + //YOverlap residual X mean as a function of stave in the pixel barrel (sensitive to stave-shear distortions) + TH1F* m_pix_b0_Oyresxvsmodphi_mean = new TH1F("pix_b0_Oyresxvsmodphi_mean","Y-Overlap X Residual Mean vs Phi-ID Pixel Barrel L0",22,-0.5,21.5); + TH1F* m_pix_b1_Oyresxvsmodphi_mean = new TH1F("pix_b1_Oyresxvsmodphi_mean","Y-Overlap X Residual Mean vs Phi-ID Pixel Barrel L1",38,-0.5,37.5); + TH1F* m_pix_b2_Oyresxvsmodphi_mean = new TH1F("pix_b2_Oyresxvsmodphi_mean","Y-Overlap X Residual Mean vs Phi-ID Pixel Barrel L2",52,-0.5,51.5); + m_pix_b0_Oyresxvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual X"); + m_pix_b1_Oyresxvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual X"); + m_pix_b2_Oyresxvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual X"); + m_pix_b0_Oyresxvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + m_pix_b1_Oyresxvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + m_pix_b2_Oyresxvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_pix_b0_Oyresxvsmodetaphi_3d,m_pix_b0_Oyresxvsmodphi_mean,1,2); + meanRMSProjections3D_XY(m_pix_b1_Oyresxvsmodetaphi_3d,m_pix_b1_Oyresxvsmodphi_mean,1,2); + meanRMSProjections3D_XY(m_pix_b2_Oyresxvsmodetaphi_3d,m_pix_b2_Oyresxvsmodphi_mean,1,2); + plots->Add(m_pix_b0_Oyresxvsmodphi_mean); + plots->Add(m_pix_b1_Oyresxvsmodphi_mean); + plots->Add(m_pix_b2_Oyresxvsmodphi_mean); + TH1F* m_pix_b_Oyresxvsmodphi_mean = combineHistos("pix_b_Oyresxvsmodphi_mean","Y-Overlap X Residual Mean vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_Oyresxvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual X"); + m_pix_b_Oyresxvsmodphi_mean->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + plots->Clear(); + + //YOverlap residual X width as a function of stave in the pixel barrel (sensitive to stave-shear distortions) + TH1F* m_pix_b0_Oyresxvsmodphi_width = new TH1F("pix_b0_Oyresxvsmodphi_width","Y-Overlap X Residual Width vs Phi-ID Pixel Barrel L0",22,-0.5,21.5); + TH1F* m_pix_b1_Oyresxvsmodphi_width = new TH1F("pix_b1_Oyresxvsmodphi_width","Y-Overlap X Residual Width vs Phi-ID Pixel Barrel L1",38,-0.5,37.5); + TH1F* m_pix_b2_Oyresxvsmodphi_width = new TH1F("pix_b2_Oyresxvsmodphi_width","Y-Overlap X Residual Width vs Phi-ID Pixel Barrel L2",52,-0.5,51.5); + m_pix_b0_Oyresxvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual X"); + m_pix_b1_Oyresxvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual X"); + m_pix_b2_Oyresxvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual X"); + m_pix_b0_Oyresxvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + m_pix_b1_Oyresxvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + m_pix_b2_Oyresxvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_pix_b0_Oyresxvsmodetaphi_3d,m_pix_b0_Oyresxvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_pix_b1_Oyresxvsmodetaphi_3d,m_pix_b1_Oyresxvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_pix_b2_Oyresxvsmodetaphi_3d,m_pix_b2_Oyresxvsmodphi_width,1,3); + plots->Add(m_pix_b0_Oyresxvsmodphi_width); + plots->Add(m_pix_b1_Oyresxvsmodphi_width); + plots->Add(m_pix_b2_Oyresxvsmodphi_width); + TH1F* m_pix_b_Oyresxvsmodphi_width = combineHistos("pix_b_Oyresxvsmodphi_width","Y-Overlap X Residual Width vs (Modified) Eta-ID Pixel Barrel",plots,10); + m_pix_b_Oyresxvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual X"); + m_pix_b_Oyresxvsmodphi_width->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + plots->Clear(); + + //XOverlap residual X mean as a function of ring in the SCT barrel (sensitive to ring-expansion,contraction distortions) + TH1F* m_sct_b0_Oxresxvsmodeta_mean = new TH1F("sct_b0_Oxresxvsmodeta_mean","X-Overlap X Residual Mean vs Eta-ID SCT Barrel L0",13,-6.5,6.5); + TH1F* m_sct_b1_Oxresxvsmodeta_mean = new TH1F("sct_b1_Oxresxvsmodeta_mean","X-Overlap X Residual Mean vs Eta-ID SCT Barrel L1",13,-6.5,6.5); + TH1F* m_sct_b2_Oxresxvsmodeta_mean = new TH1F("sct_b2_Oxresxvsmodeta_mean","X-Overlap X Residual Mean vs Eta-ID SCT Barrel L2",13,-6.5,6.5); + TH1F* m_sct_b3_Oxresxvsmodeta_mean = new TH1F("sct_b3_Oxresxvsmodeta_mean","X-Overlap X Residual Mean vs Eta-ID SCT Barrel L3",13,-6.5,6.5); + m_sct_b0_Oxresxvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual X"); + m_sct_b1_Oxresxvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual X"); + m_sct_b2_Oxresxvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual X"); + m_sct_b3_Oxresxvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual X"); + m_sct_b0_Oxresxvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b1_Oxresxvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b2_Oxresxvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b3_Oxresxvsmodeta_mean->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_sct_b0_Oxresxvsmodetaphi_3d,m_sct_b0_Oxresxvsmodeta_mean,0,2); + meanRMSProjections3D_XY(m_sct_b1_Oxresxvsmodetaphi_3d,m_sct_b1_Oxresxvsmodeta_mean,0,2); + meanRMSProjections3D_XY(m_sct_b2_Oxresxvsmodetaphi_3d,m_sct_b2_Oxresxvsmodeta_mean,0,2); + meanRMSProjections3D_XY(m_sct_b3_Oxresxvsmodetaphi_3d,m_sct_b3_Oxresxvsmodeta_mean,0,2); + plots->Add(m_sct_b0_Oxresxvsmodeta_mean); + plots->Add(m_sct_b1_Oxresxvsmodeta_mean); + plots->Add(m_sct_b2_Oxresxvsmodeta_mean); + plots->Add(m_sct_b3_Oxresxvsmodeta_mean); + TH1F* m_sct_b_Oxresxvsmodeta_mean = combineHistos("sct_b_Oxresxvsmodeta_mean","X-Overlap X Residual Mean vs (Modified) Eta-ID SCT Barrel",plots,10); + m_sct_b_Oxresxvsmodeta_mean->GetYaxis()->SetTitle("X-Overlap Mean Residual X"); + m_sct_b_Oxresxvsmodeta_mean->GetXaxis()->SetTitle("(Modified) Module Eta-ID"); + plots->Clear(); + + + //XOverlap residual X width as a function of ring in the SCT barrel (sensitive to ring-expansion,contraction distortions) + TH1F* m_sct_b0_Oxresxvsmodeta_width = new TH1F("sct_b0_Oxresxvsmodeta_width","X-Overlap X Residual Width vs Eta-ID SCT Barrel L0",13,-6.5,6.5); + TH1F* m_sct_b1_Oxresxvsmodeta_width = new TH1F("sct_b1_Oxresxvsmodeta_width","X-Overlap X Residual Width vs Eta-ID SCT Barrel L1",13,-6.5,6.5); + TH1F* m_sct_b2_Oxresxvsmodeta_width = new TH1F("sct_b2_Oxresxvsmodeta_width","X-Overlap X Residual Width vs Eta-ID SCT Barrel L2",13,-6.5,6.5); + TH1F* m_sct_b3_Oxresxvsmodeta_width = new TH1F("sct_b3_Oxresxvsmodeta_width","X-Overlap X Residual Width vs Eta-ID SCT Barrel L3",13,-6.5,6.5); + m_sct_b0_Oxresxvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual X"); + m_sct_b1_Oxresxvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual X"); + m_sct_b2_Oxresxvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual X"); + m_sct_b3_Oxresxvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual X"); + m_sct_b0_Oxresxvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b1_Oxresxvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b2_Oxresxvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + m_sct_b3_Oxresxvsmodeta_width->GetXaxis()->SetTitle("Module Eta-ID"); + meanRMSProjections3D_XY(m_sct_b0_Oxresxvsmodetaphi_3d,m_sct_b0_Oxresxvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_sct_b1_Oxresxvsmodetaphi_3d,m_sct_b1_Oxresxvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_sct_b2_Oxresxvsmodetaphi_3d,m_sct_b2_Oxresxvsmodeta_width,0,3); + meanRMSProjections3D_XY(m_sct_b3_Oxresxvsmodetaphi_3d,m_sct_b3_Oxresxvsmodeta_width,0,3); + plots->Add(m_sct_b0_Oxresxvsmodeta_width); + plots->Add(m_sct_b1_Oxresxvsmodeta_width); + plots->Add(m_sct_b2_Oxresxvsmodeta_width); + plots->Add(m_sct_b3_Oxresxvsmodeta_width); + TH1F* m_sct_b_Oxresxvsmodeta_width = combineHistos("sct_b_Oxresxvsmodeta_width","X-Overlap X Residual Width vs (Modified) Eta-ID SCT Barrel",plots,10); + m_sct_b_Oxresxvsmodeta_width->GetYaxis()->SetTitle("X-Overlap Width Residual X"); + m_sct_b_Oxresxvsmodeta_width->GetXaxis()->SetTitle("(Modified) Module Eta-ID"); + plots->Clear(); + + + //YOverlap residual X mean as a function of stave in the SCT barrel (sensitive to stave shear distortions) + TH1F* m_sct_b0_Oyresxvsmodphi_mean = new TH1F("sct_b0_Oyresxvsmodphi_mean","Y-Overlap X Residual Mean vs Phi-ID SCT Barrel L0",32,-0.5,31.5); + TH1F* m_sct_b1_Oyresxvsmodphi_mean = new TH1F("sct_b1_Oyresxvsmodphi_mean","Y-Overlap X Residual Mean vs Phi-ID SCT Barrel L1",40,-0.5,39.5); + TH1F* m_sct_b2_Oyresxvsmodphi_mean = new TH1F("sct_b2_Oyresxvsmodphi_mean","Y-Overlap X Residual Mean vs Phi-ID SCT Barrel L2",48,-0.5,47.5); + TH1F* m_sct_b3_Oyresxvsmodphi_mean = new TH1F("sct_b3_Oyresxvsmodphi_mean","Y-Overlap X Residual Mean vs Phi-ID SCT Barrel L3",56,-0.5,55.5); + m_sct_b0_Oyresxvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual X"); + m_sct_b1_Oyresxvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual X"); + m_sct_b2_Oyresxvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual X"); + m_sct_b3_Oyresxvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual X"); + m_sct_b0_Oyresxvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + m_sct_b1_Oyresxvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + m_sct_b2_Oyresxvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + m_sct_b3_Oyresxvsmodphi_mean->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_sct_b0_Oyresxvsmodetaphi_3d,m_sct_b0_Oyresxvsmodphi_mean,1,2); + meanRMSProjections3D_XY(m_sct_b1_Oyresxvsmodetaphi_3d,m_sct_b1_Oyresxvsmodphi_mean,1,2); + meanRMSProjections3D_XY(m_sct_b2_Oyresxvsmodetaphi_3d,m_sct_b2_Oyresxvsmodphi_mean,1,2); + meanRMSProjections3D_XY(m_sct_b3_Oyresxvsmodetaphi_3d,m_sct_b3_Oyresxvsmodphi_mean,1,2); + plots->Add(m_sct_b0_Oyresxvsmodphi_mean); + plots->Add(m_sct_b1_Oyresxvsmodphi_mean); + plots->Add(m_sct_b2_Oyresxvsmodphi_mean); + plots->Add(m_sct_b3_Oyresxvsmodphi_mean); + TH1F* m_sct_b_Oyresxvsmodphi_mean = combineHistos("sct_b_Oyresxvsmodphi_mean","Y-Overlap X Residual Mean vs (Modified) Phi-ID SCT Barrel",plots,10); + m_sct_b_Oyresxvsmodphi_mean->GetYaxis()->SetTitle("Y-Overlap Mean Residual X"); + m_sct_b_Oyresxvsmodphi_mean->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + plots->Clear(); + + //YOverlap residual X width as a function of stave in the SCT barrel (sensitive to stave shear distortions) + TH1F* m_sct_b0_Oyresxvsmodphi_width = new TH1F("sct_b0_Oyresxvsmodphi_width","Y-Overlap X Residual Width vs Phi-ID SCT Barrel L0",32,-0.5,31.5); + TH1F* m_sct_b1_Oyresxvsmodphi_width = new TH1F("sct_b1_Oyresxvsmodphi_width","Y-Overlap X Residual Width vs Phi-ID SCT Barrel L1",40,-0.5,39.5); + TH1F* m_sct_b2_Oyresxvsmodphi_width = new TH1F("sct_b2_Oyresxvsmodphi_width","Y-Overlap X Residual Width vs Phi-ID SCT Barrel L2",48,-0.5,47.5); + TH1F* m_sct_b3_Oyresxvsmodphi_width = new TH1F("sct_b3_Oyresxvsmodphi_width","Y-Overlap X Residual Width vs Phi-ID SCT Barrel L3",56,-0.5,55.5); + m_sct_b0_Oyresxvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual X"); + m_sct_b1_Oyresxvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual X"); + m_sct_b2_Oyresxvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual X"); + m_sct_b3_Oyresxvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual X"); + m_sct_b0_Oyresxvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + m_sct_b1_Oyresxvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + m_sct_b2_Oyresxvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + m_sct_b3_Oyresxvsmodphi_width->GetXaxis()->SetTitle("Module Phi-ID"); + meanRMSProjections3D_XY(m_sct_b0_Oyresxvsmodetaphi_3d,m_sct_b0_Oyresxvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_sct_b1_Oyresxvsmodetaphi_3d,m_sct_b1_Oyresxvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_sct_b2_Oyresxvsmodetaphi_3d,m_sct_b2_Oyresxvsmodphi_width,1,3); + meanRMSProjections3D_XY(m_sct_b3_Oyresxvsmodetaphi_3d,m_sct_b3_Oyresxvsmodphi_width,1,3); + plots->Add(m_sct_b0_Oyresxvsmodphi_width); + plots->Add(m_sct_b1_Oyresxvsmodphi_width); + plots->Add(m_sct_b2_Oyresxvsmodphi_width); + plots->Add(m_sct_b3_Oyresxvsmodphi_width); + TH1F* m_sct_b_Oyresxvsmodphi_width = combineHistos("sct_b_Oyresxvsmodphi_width","Y-Overlap X Residual Width vs (Modified) Phi-ID SCT Barrel",plots,10); + m_sct_b_Oyresxvsmodphi_width->GetYaxis()->SetTitle("Y-Overlap Width Residual X"); + m_sct_b_Oyresxvsmodphi_width->GetXaxis()->SetTitle("(Modified) Module Phi-ID"); + plots->Clear(); + + + //write the overlap histograms to file + m_pix_b_Oxresxvsmodeta_mean->Write("",TObject::kOverwrite); + m_pix_b_Oxresxvsmodeta_width->Write("",TObject::kOverwrite); + m_pix_b_Oxresyvsmodeta_mean->Write("",TObject::kOverwrite); + m_pix_b_Oxresyvsmodeta_width->Write("",TObject::kOverwrite); + m_pix_b_Oyresyvsmodphi_mean->Write("",TObject::kOverwrite); + m_pix_b_Oyresyvsmodphi_width->Write("",TObject::kOverwrite); + + f->Write(); + + m_pix_b_Oyresxvsmodphi_mean->Write("",TObject::kOverwrite); + m_pix_b_Oyresxvsmodphi_width->Write("",TObject::kOverwrite); + m_sct_b_Oxresxvsmodeta_mean->Write("",TObject::kOverwrite); + m_sct_b_Oxresxvsmodeta_width->Write("",TObject::kOverwrite); + m_sct_b_Oyresxvsmodphi_mean->Write("",TObject::kOverwrite); + m_sct_b_Oyresxvsmodphi_width->Write("",TObject::kOverwrite); + + f->Write(); + } + + + + return; + +} +void +MonitoringFile:: +fitMergedFile_IDAlignMonGenericTracks (TFile* file, std::string run_dir, std::string tracksName) +{ + std::string path; + path= run_dir + "IDAlignMon/" + tracksName + "/GenericTracks"; + if( file->cd(path.c_str())==0 ) { + //std::cerr << "MonitoringFile::fitMergedFile_IDAlignMonGenericTracks(): " + // << "No such directory \"" << path << "\"\n"; + return; + } + //charge Asym vs pt + if (CheckHistogram(file,(path+"/trk_pT_asym_barrel").c_str()) && CheckHistogram(file,(path+"/trk_pT_neg_barrel").c_str()) && CheckHistogram(file,(path+"/trk_pT_pos_barrel").c_str()) ) { + TH1F* m_trk_pT_neg_barrel=(TH1F*)(file->Get((path+"/trk_pT_neg_barrel").c_str())->Clone()); + TH1F* m_trk_pT_pos_barrel=(TH1F*)(file->Get((path+"/trk_pT_pos_barrel").c_str())->Clone()); + TH1F* m_trk_pT_asym_barrel=(TH1F*)(file->Get((path+"/trk_pT_asym_barrel").c_str())->Clone()); + ProcessAsymHistograms(m_trk_pT_neg_barrel,m_trk_pT_pos_barrel,m_trk_pT_asym_barrel); + m_trk_pT_asym_barrel->SetXTitle("p_{T} [GeV]"); + m_trk_pT_asym_barrel->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_pT_asym_ecc").c_str()) && CheckHistogram(file,(path+"/trk_pT_neg_ecc").c_str()) && CheckHistogram(file,(path+"/trk_pT_pos_ecc").c_str()) ) { + TH1F* m_trk_pT_neg_ecc=(TH1F*)(file->Get((path+"/trk_pT_neg_ecc").c_str())->Clone()); + TH1F* m_trk_pT_pos_ecc=(TH1F*)(file->Get((path+"/trk_pT_pos_ecc").c_str())->Clone()); + TH1F* m_trk_pT_asym_ecc=(TH1F*)(file->Get((path+"/trk_pT_asym_ecc").c_str())->Clone()); + ProcessAsymHistograms(m_trk_pT_neg_ecc,m_trk_pT_pos_ecc,m_trk_pT_asym_ecc); + m_trk_pT_asym_ecc->SetXTitle("p_{T} [GeV]"); + m_trk_pT_asym_ecc->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_pT_asym_eca").c_str()) && CheckHistogram(file,(path+"/trk_pT_neg_eca").c_str()) && CheckHistogram(file,(path+"/trk_pT_pos_eca").c_str()) ) { + TH1F* m_trk_pT_neg_eca=(TH1F*)(file->Get((path+"/trk_pT_neg_eca").c_str())->Clone()); + TH1F* m_trk_pT_pos_eca=(TH1F*)(file->Get((path+"/trk_pT_pos_eca").c_str())->Clone()); + TH1F* m_trk_pT_asym_eca=(TH1F*)(file->Get((path+"/trk_pT_asym_eca").c_str())->Clone()); + ProcessAsymHistograms(m_trk_pT_neg_eca,m_trk_pT_pos_eca,m_trk_pT_asym_eca); + m_trk_pT_asym_eca->SetXTitle("p_{T} [GeV]"); + m_trk_pT_asym_eca->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_pT_asym").c_str()) && CheckHistogram(file,(path+"/pT_n").c_str()) && CheckHistogram(file,(path+"/pT_p").c_str()) ) { + TH1F* m_trk_pT_neg=(TH1F*)(file->Get((path+"/pT_n").c_str())->Clone()); + TH1F* m_trk_pT_pos=(TH1F*)(file->Get((path+"/pT_p").c_str())->Clone()); + TH1F* m_trk_pT_asym=(TH1F*)(file->Get((path+"/trk_pT_asym").c_str())->Clone()); + ProcessAsymHistograms(m_trk_pT_neg,m_trk_pT_pos,m_trk_pT_asym); + m_trk_pT_asym->SetXTitle("p_{T} [GeV]"); + m_trk_pT_asym->Write("",TObject::kOverwrite); + } + + //charge Asym vs phi + if (CheckHistogram(file,(path+"/trk_phi0_asym_barrel").c_str()) && CheckHistogram(file,(path+"/trk_phi0_neg_barrel").c_str()) && CheckHistogram(file,(path+"/trk_phi0_pos_barrel").c_str()) ) { + TH1F* m_trk_phi0_neg_barrel=(TH1F*)(file->Get((path+"/trk_phi0_neg_barrel").c_str())->Clone()); + TH1F* m_trk_phi0_pos_barrel=(TH1F*)(file->Get((path+"/trk_phi0_pos_barrel").c_str())->Clone()); + TH1F* m_trk_phi0_asym_barrel=(TH1F*)(file->Get((path+"/trk_phi0_asym_barrel").c_str())->Clone()); + ProcessAsymHistograms(m_trk_phi0_neg_barrel,m_trk_phi0_pos_barrel,m_trk_phi0_asym_barrel); + m_trk_phi0_asym_barrel->SetXTitle("track #phi [rad]"); + m_trk_phi0_asym_barrel->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_phi0_asym_ecc").c_str()) && CheckHistogram(file,(path+"/trk_phi0_neg_ecc").c_str()) && CheckHistogram(file,(path+"/trk_phi0_pos_ecc").c_str()) ) { + TH1F* m_trk_phi0_neg_ecc=(TH1F*)(file->Get((path+"/trk_phi0_neg_ecc").c_str())->Clone()); + TH1F* m_trk_phi0_pos_ecc=(TH1F*)(file->Get((path+"/trk_phi0_pos_ecc").c_str())->Clone()); + TH1F* m_trk_phi0_asym_ecc=(TH1F*)(file->Get((path+"/trk_phi0_asym_ecc").c_str())->Clone()); + ProcessAsymHistograms(m_trk_phi0_neg_ecc,m_trk_phi0_pos_ecc,m_trk_phi0_asym_ecc); + m_trk_phi0_asym_ecc->SetXTitle("track #phi [rad]"); + m_trk_phi0_asym_ecc->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_phi0_asym_eca").c_str()) && CheckHistogram(file,(path+"/trk_phi0_neg_eca").c_str()) && CheckHistogram(file,(path+"/trk_phi0_pos_eca").c_str()) ) { + TH1F* m_trk_phi0_neg_eca=(TH1F*)(file->Get((path+"/trk_phi0_neg_eca").c_str())->Clone()); + TH1F* m_trk_phi0_pos_eca=(TH1F*)(file->Get((path+"/trk_phi0_pos_eca").c_str())->Clone()); + TH1F* m_trk_phi0_asym_eca=(TH1F*)(file->Get((path+"/trk_phi0_asym_eca").c_str())->Clone()); + ProcessAsymHistograms(m_trk_phi0_neg_eca,m_trk_phi0_pos_eca,m_trk_phi0_asym_eca); + m_trk_phi0_asym_eca->SetXTitle("track #phi [rad]"); + m_trk_phi0_asym_eca->Write("",TObject::kOverwrite); + } + + //charge Asym vs eta + if (CheckHistogram(file,(path+"/eta_asym").c_str()) && CheckHistogram(file,(path+"/eta_neg").c_str()) && CheckHistogram(file,(path+"/eta_pos").c_str()) ) { + TH1F* m_eta_neg=(TH1F*)(file->Get((path+"/eta_neg").c_str())->Clone()); + TH1F* m_eta_pos=(TH1F*)(file->Get((path+"/eta_pos").c_str())->Clone()); + TH1F* m_eta_asym=(TH1F*)(file->Get((path+"/eta_asym").c_str())->Clone()); + ProcessAsymHistograms(m_eta_neg,m_eta_pos,m_eta_asym); + m_eta_asym->SetXTitle("track #eta"); + m_eta_asym->Write("",TObject::kOverwrite); + } + + //charge Asym vs d0 (corrected for vertex) + if (CheckHistogram(file,(path+"/trk_d0c_asym_barrel").c_str()) && CheckHistogram(file,(path+"/trk_d0c_neg_barrel").c_str()) && CheckHistogram(file,(path+"/trk_d0c_pos_barrel").c_str()) ) { + TH1F* m_trk_d0c_neg_barrel=(TH1F*)(file->Get((path+"/trk_d0c_neg_barrel").c_str())->Clone()); + TH1F* m_trk_d0c_pos_barrel=(TH1F*)(file->Get((path+"/trk_d0c_pos_barrel").c_str())->Clone()); + TH1F* m_trk_d0c_asym_barrel=(TH1F*)(file->Get((path+"/trk_d0c_asym_barrel").c_str())->Clone()); + ProcessAsymHistograms(m_trk_d0c_neg_barrel,m_trk_d0c_pos_barrel,m_trk_d0c_asym_barrel); + m_trk_d0c_asym_barrel->SetXTitle("track d_{0} [mm]"); + m_trk_d0c_asym_barrel->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_d0c_asym_ecc").c_str()) && CheckHistogram(file,(path+"/trk_d0c_neg_ecc").c_str()) && CheckHistogram(file,(path+"/trk_d0c_pos_ecc").c_str()) ) { + TH1F* m_trk_d0c_neg_ecc=(TH1F*)(file->Get((path+"/trk_d0c_neg_ecc").c_str())->Clone()); + TH1F* m_trk_d0c_pos_ecc=(TH1F*)(file->Get((path+"/trk_d0c_pos_ecc").c_str())->Clone()); + TH1F* m_trk_d0c_asym_ecc=(TH1F*)(file->Get((path+"/trk_d0c_asym_ecc").c_str())->Clone()); + ProcessAsymHistograms(m_trk_d0c_neg_ecc,m_trk_d0c_pos_ecc,m_trk_d0c_asym_ecc); + m_trk_d0c_asym_ecc->SetXTitle("track d_{0} [mm]"); + m_trk_d0c_asym_ecc->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_d0c_asym_eca").c_str()) && CheckHistogram(file,(path+"/trk_d0c_neg_eca").c_str()) && CheckHistogram(file,(path+"/trk_d0c_pos_eca").c_str()) ) { + TH1F* m_trk_d0c_neg_eca=(TH1F*)(file->Get((path+"/trk_d0c_neg_eca").c_str())->Clone()); + TH1F* m_trk_d0c_pos_eca=(TH1F*)(file->Get((path+"/trk_d0c_pos_eca").c_str())->Clone()); + TH1F* m_trk_d0c_asym_eca=(TH1F*)(file->Get((path+"/trk_d0c_asym_eca").c_str())->Clone()); + ProcessAsymHistograms(m_trk_d0c_neg_eca,m_trk_d0c_pos_eca,m_trk_d0c_asym_eca); + m_trk_d0c_asym_eca->SetXTitle("track d_{0} [mm]"); + m_trk_d0c_asym_eca->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_d0c_asym").c_str()) && CheckHistogram(file,(path+"/trk_d0c_neg").c_str()) && CheckHistogram(file,(path+"/trk_d0c_pos").c_str()) ) { + TH1F* m_trk_d0c_neg=(TH1F*)(file->Get((path+"/trk_d0c_neg").c_str())->Clone()); + TH1F* m_trk_d0c_pos=(TH1F*)(file->Get((path+"/trk_d0c_pos").c_str())->Clone()); + TH1F* m_trk_d0c_asym=(TH1F*)(file->Get((path+"/trk_d0c_asym").c_str())->Clone()); + ProcessAsymHistograms(m_trk_d0c_neg,m_trk_d0c_pos,m_trk_d0c_asym); + m_trk_d0c_asym->SetXTitle("track d_{0} [mm]"); + m_trk_d0c_asym->Write("",TObject::kOverwrite); + } + //charge Asym vs z0 (corrected for vertex) + if (CheckHistogram(file,(path+"/trk_z0c_asym_barrel").c_str()) && CheckHistogram(file,(path+"/trk_z0c_neg_barrel").c_str()) && CheckHistogram(file,(path+"/trk_z0c_pos_barrel").c_str()) ) { + TH1F* m_trk_z0c_neg_barrel=(TH1F*)(file->Get((path+"/trk_z0c_neg_barrel").c_str())->Clone()); + TH1F* m_trk_z0c_pos_barrel=(TH1F*)(file->Get((path+"/trk_z0c_pos_barrel").c_str())->Clone()); + TH1F* m_trk_z0c_asym_barrel=(TH1F*)(file->Get((path+"/trk_z0c_asym_barrel").c_str())->Clone()); + ProcessAsymHistograms(m_trk_z0c_neg_barrel,m_trk_z0c_pos_barrel,m_trk_z0c_asym_barrel); + m_trk_z0c_asym_barrel->SetXTitle("track z_{0} [mm]"); + m_trk_z0c_asym_barrel->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_z0c_asym_ecc").c_str()) && CheckHistogram(file,(path+"/trk_z0c_neg_ecc").c_str()) && CheckHistogram(file,(path+"/trk_z0c_pos_ecc").c_str()) ) { + TH1F* m_trk_z0c_neg_ecc=(TH1F*)(file->Get((path+"/trk_z0c_neg_ecc").c_str())->Clone()); + TH1F* m_trk_z0c_pos_ecc=(TH1F*)(file->Get((path+"/trk_z0c_pos_ecc").c_str())->Clone()); + TH1F* m_trk_z0c_asym_ecc=(TH1F*)(file->Get((path+"/trk_z0c_asym_ecc").c_str())->Clone()); + ProcessAsymHistograms(m_trk_z0c_neg_ecc,m_trk_z0c_pos_ecc,m_trk_z0c_asym_ecc); + m_trk_z0c_asym_ecc->SetXTitle("track z_{0} [mm]"); + m_trk_z0c_asym_ecc->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_z0c_asym_eca").c_str()) && CheckHistogram(file,(path+"/trk_z0c_neg_eca").c_str()) && CheckHistogram(file,(path+"/trk_z0c_pos_eca").c_str()) ) { + TH1F* m_trk_z0c_neg_eca=(TH1F*)(file->Get((path+"/trk_z0c_neg_eca").c_str())->Clone()); + TH1F* m_trk_z0c_pos_eca=(TH1F*)(file->Get((path+"/trk_z0c_pos_eca").c_str())->Clone()); + TH1F* m_trk_z0c_asym_eca=(TH1F*)(file->Get((path+"/trk_z0c_asym_eca").c_str())->Clone()); + ProcessAsymHistograms(m_trk_z0c_neg_eca,m_trk_z0c_pos_eca,m_trk_z0c_asym_eca); + m_trk_z0c_asym_eca->SetXTitle("track z_{0} [mm]"); + m_trk_z0c_asym_eca->Write("",TObject::kOverwrite); + } + if (CheckHistogram(file,(path+"/trk_z0c_asym").c_str()) && CheckHistogram(file,(path+"/trk_z0c_neg").c_str()) && CheckHistogram(file,(path+"/trk_z0c_pos").c_str()) ) { + TH1F* m_trk_z0c_neg=(TH1F*)(file->Get((path+"/trk_z0c_neg").c_str())->Clone()); + TH1F* m_trk_z0c_pos=(TH1F*)(file->Get((path+"/trk_z0c_pos").c_str())->Clone()); + TH1F* m_trk_z0c_asym=(TH1F*)(file->Get((path+"/trk_z0c_asym").c_str())->Clone()); + ProcessAsymHistograms(m_trk_z0c_neg,m_trk_z0c_pos,m_trk_z0c_asym); + m_trk_z0c_asym->SetXTitle("track z_{0} [mm]"); + m_trk_z0c_asym->Write("",TObject::kOverwrite); + } + file->Write(); +} + +void +MonitoringFile:: +ProcessAsymHistograms(TH1F* m_neg, TH1F* m_pos, TH1F* m_asym) +{ + if (m_neg->GetNbinsX()!=m_pos->GetNbinsX()||m_neg->GetNbinsX()!=m_asym->GetNbinsX()) return; + for (int i=1;i<=m_neg->GetNbinsX();i++) { + float asym=0; + float err=0; + float a=m_neg->GetBinContent(i); + float b=m_pos->GetBinContent(i); + float e1=m_neg->GetBinError(i); + float e2=m_pos->GetBinError(i); + if ((a+b)>0) + { asym=(a-b)/(a+b); + //error propagation + err=sqrt((4*b*b*e1*e1+4*a*a*e2*e2)/pow(a+b,4)); } + m_asym->SetBinContent(i,asym); + m_asym->SetBinError(i,err); + } +} + + +void +MonitoringFile:: +meanRMSProjections2D(TH2F* h2d, TH1F* h, int iopt) +{ + + //fills a 1-D histogram with mean or width of the distribution for each bin in a 2D histogram + //the way in which the mean or width is determined is specified by the iopt option + //can be from a gaussian fit for example + // iopt = 0; fills with statistical mean + // iopt = 1; fills with statistical RMS + // iopt = 2; fills with mean of a two-stage Gaussian fit + // iopt = 3; fills with width of a two-stage Gaussian fit + // iopt = 4; fills with Chi2/DOF of a two-stage Gaussian fit + // iopt = 5; fills with nentries in the bin + + + //std::cout << "In fillGaussianMeanOrWidth for " << h->GetName() << std::endl; + + //calling this means that the histogram bin content is flagged + //as being an average and so adding histos from different jobs + //will produce weighted mean + h->SetBit(TH1::kIsAverage); + + int nbins_2d = h2d->GetNbinsX(); + + // Removed by Alex + //int nbins_h = h->GetNbinsX(); + //if(nbins_2d!=nbins_h) std::cout << "Mean/Width Histograms not set up correctly - nbins mismatch for " << h->GetName() << std::endl; + + for(int i = 1; i!=nbins_2d+1; i++){ + + //std::cout << "Gaussian: processing bin " << i << std::endl; + + TH1F* hproj = (TH1F*)h2d->ProjectionY("proj",i,i,"e"); + + //std::cout << "Gaussian: made projection for bin " << i << std::endl; + + //do not fill if there are few entries in the bin + if(iopt<5 && (hproj->GetEntries()<=30 || hproj->Integral()<=30)) { + delete hproj; + //h->SetBinContent(i,j,0); + //h->SetBinError(i,j,0); + continue; + } + + if(iopt==0){ + h->SetBinContent(i,hproj->GetMean()); + h->SetBinError(i,hproj->GetMeanError()); + } + else if(iopt==1){ + h->SetBinContent(i,hproj->GetRMS()); + h->SetBinError(i,hproj->GetRMSError()); + } + else if(iopt>=2 && iopt<5){ + + //we make a 2-stage Gaussian fit + //first fit is in the range [MEAN + 2*RMS, MEAN - 2*RMS] + //(restricting the range of the first fit has little effect) + //second fit is in the range [mean + 2*width, mean - 2*width] + //using the mean and width of the first fit + + //first fit + float _mean = hproj->GetMean(); + float _rms = hproj->GetRMS(); + float _min = _mean - 2*_rms; + float _max = _mean + 2*_rms; + TF1 *fW = new TF1("fW","gaus",_min,_max); + hproj -> Fit("fW", "RQN"); + + //second fit + _mean = fW->GetParameter(1); + _rms = fW->GetParameter(2); + _min = _mean - 2*_rms; + _max = _mean + 2*_rms; + //if bins are large relative to distribution then + //the above determined range could only be two bins + //or even just fractions of bins + //in this case a gauus fit is meaningless, and can have strange + //chi2 behaviour and large errors on the mean + //therefore make sure we are including full bins in fit and + //have a minimum of 3 bins + int _minBin = hproj->FindBin(_min); + int _maxBin = hproj->FindBin(_max); + if(_maxBin - _minBin < 2) { + //require at least 3 bins for a meaningful gauss fit + //std::cout << "WARNING core had too few bins for fit - expanding core for " << h->GetName() << std::endl; + _maxBin = _maxBin + 1; + _minBin = _minBin - 1; + } + _min = hproj->GetBinLowEdge(_minBin); + _max = (hproj->GetBinLowEdge(_maxBin))+(hproj->GetBinWidth(_maxBin)); + + TF1 *fW2 = new TF1("fW2","gaus",_min,_max); + hproj -> Fit("fW2", "RQN"); + if(iopt==2){ + h->SetBinContent(i,fW2->GetParameter(1)); + h->SetBinError(i,fW2->GetParError(1)); + } else if (iopt==3){ + h->SetBinContent(i,fW2->GetParameter(2)); + h->SetBinError(i,fW2->GetParError(2)); + } else if (iopt==4){ + float _chi2 = fW2->GetChisquare(); + int _ndf = fW2->GetNDF(); + if(_ndf) h->SetBinContent(i,_chi2/_ndf); + else h->SetBinContent(i,0); + } + delete fW; + delete fW2; + } + else if(iopt==5){ + h->SetBinContent(i,hproj->GetEntries()); + } + //else std::cerr << "Incorrect iopt switch in meanRMSProjections2D()" << std::endl; + + delete hproj; + } + + + return; + +} + +void MonitoringFile:: +meanRMSProjections3D(TH3F* h3d, TH2F* h,int iopt) +{ + + //fills a 2-D histogram with mean or width of the distribution for each bin in a 3D histogram + //the way in which the mean or width is determined is specified by the iopt option + //can be from a gaussian fit for example + // iopt = 0; fills with statistical mean + // iopt = 1; fills with statistical RMS + // iopt = 2; fills with mean of a two-stage Gaussian fit + // iopt = 3; fills with width of a two-stage Gaussian fit + // iopt = 4; fills with Chi2/DOF of a two-stage Gaussian fit + // iopt = 5; fills with nentries in the bin + + int nbins_3dX = h3d->GetNbinsX(); + int nbins_3dY = h3d->GetNbinsY(); + int nbins_hX = h->GetNbinsX(); + int nbins_hY = h->GetNbinsY(); + + if(nbins_3dX!=nbins_hX) { + //std::cerr << "meanRMSProjections3D: Mean/RMS Histograms not set up correctly - nbins mismatch for " << h->GetName() << std::endl; + return; + } + if(nbins_3dY!=nbins_hY) { + //std::cerr << "meanRMSProjections3D: Mean/RMS Histograms not set up correctly - nbins mismatch for " << h->GetName() << std::endl; + return; + } + + for(int i = 1; i!=nbins_3dX+1; i++){ + for(int j = 1; j!=nbins_3dY+1; j++){ + + TH1F* hproj = (TH1F*)h3d->ProjectionZ("proj",i,i,j,j,"e"); + + //do not fill if there are 30 or less entries in the bin + if(iopt<5 && (hproj->GetEntries()<=30 || hproj->Integral()<=30)) { + delete hproj; + //h->SetBinContent(i,j,0); + //h->SetBinError(i,j,0); + continue; + } + if(iopt==0){ + h->SetBinContent(i,j,hproj->GetMean()); + h->SetBinError(i,j,hproj->GetMeanError()); + } + else if(iopt==1){ + h->SetBinContent(i,j,hproj->GetRMS()); + h->SetBinError(i,j,hproj->GetRMSError()); + } + else if(iopt>=2 && iopt<5){ + + //we make a 2-stage Gaussian fit + //first fit is in the range [MEAN + 2*RMS, MEAN - 2*RMS] + //(restricting the range of the first fit has little effect) + //second fit is in the range [mean + 2*width, mean - 2*width] + //using the mean and width of the first fit + + //first fit + float _mean = hproj->GetMean(); + float _rms = hproj->GetRMS(); + float _min = _mean - 2*_rms; + float _max = _mean + 2*_rms; + TF1 *fW = new TF1("fW","gaus",_min,_max); + hproj -> Fit("fW", "RQN"); + + //second fit + _mean = fW->GetParameter(1); + _rms = fW->GetParameter(2); + _min = _mean - 2*_rms; + _max = _mean + 2*_rms; + //if bins are large relative to distribution then + //the above determined range could only be two bins + //or even just fractions of bins + //in this case a gauus fit is meaningless, and can have strange + //chi2 behaviour and large errors on the mean + //therefore make sure we are including full bins in fit and + //have a minimum of 3 bins + int _minBin = hproj->FindBin(_min); + int _maxBin = hproj->FindBin(_max); + if(_maxBin - _minBin < 2) { + //require at least 3 bins for a meaningful gauss fit + //std::cout << "WARNING core had too few bins for fit - expanding core for " << h->GetName() << std::endl; + _maxBin = _maxBin + 1; + _minBin = _minBin - 1; + } + _min = hproj->GetBinLowEdge(_minBin); + _max = (hproj->GetBinLowEdge(_maxBin))+(hproj->GetBinWidth(_maxBin)); + + TF1 *fW2 = new TF1("fW2","gaus",_min,_max); + hproj -> Fit("fW2", "RQN"); + if(iopt==2){ + h->SetBinContent(i,j,fW2->GetParameter(1)); + h->SetBinError(i,j,fW2->GetParError(1)); + } else if (iopt==3){ + h->SetBinContent(i,j,fW2->GetParameter(2)); + h->SetBinError(i,j,fW2->GetParError(2)); + } else if (iopt==4){ + float _chi2 = fW2->GetChisquare(); + int _ndf = fW2->GetNDF(); + if(_ndf) h->SetBinContent(i,j,_chi2/_ndf); + else h->SetBinContent(i,j,0); + } + + delete fW; + delete fW2; + } + else if(iopt==5){ + h->SetBinContent(i,j,hproj->GetEntries()); + } + //else std::cerr << "Incorrect iopt switch in meanRMSProjections3D()" << std::endl; + delete hproj; + } + } + + return; +} + +void MonitoringFile:: +meanRMSProjections3D_DMRPlot(TH3F* h3d, TH1F* h,int iopt) +{ + + //fills a 1-D histogram with the mean or width of the distribution for each bin in a 3D histogram + //the way in which the mean or width is determined is specified by the iopt option + //can be from a gaussian fit for example + // iopt = 0; fills with statistical mean + // iopt = 1; fills with statistical RMS + // iopt = 2; fills with mean of a two-stage Gaussian fit + // iopt = 3; fills with width of a two-stage Gaussian fit + // iopt = 4; fills with Chi2/DOF of a two-stage Gaussian fit + // iopt = 5; fills with the error on the fitted mean + // iopt = 6; fills with statistical median + // iopt = 7; fills with nentries in the bin + + int nbins_3dX = h3d->GetNbinsX(); + int nbins_3dY = h3d->GetNbinsY(); + + for(int i = 1; i!=nbins_3dX+1; i++){ + for(int j = 1; j!=nbins_3dY+1; j++){ + + TH1F* hproj = (TH1F*)h3d->ProjectionZ("proj",i,i,j,j,"e"); + + //do not fill if there are 30 or less entries in the bin + if(iopt<7 && (hproj->GetEntries()<=30 || hproj->Integral()<=30)) { + delete hproj; + continue; + } + if(iopt==0){ + h->Fill(hproj->GetMean()); + } + else if(iopt==1){ + h->Fill(hproj->GetRMS()); + } + else if(iopt>=2 && iopt<6){ + + //we make a 2-stage Gaussian fit + //first fit is in the range [MEAN + 2*RMS, MEAN - 2*RMS] + //(restricting the range of the first fit has little effect) + //second fit is in the range [mean + 2*width, mean - 2*width] + //using the mean and width of the first fit + + //first fit + float _mean = hproj->GetMean(); + float _rms = hproj->GetRMS(); + float _min = _mean - 2*_rms; + float _max = _mean + 2*_rms; + TF1 *fW = new TF1("fW","gaus",_min,_max); + hproj -> Fit("fW", "RQN"); + + //second fit + _mean = fW->GetParameter(1); + _rms = fW->GetParameter(2); + _min = _mean - 2*_rms; + _max = _mean + 2*_rms; + //if bins are large relative to distribution then + //the above determined range could only be two bins + //or even just fractions of bins + //in this case a gauus fit is meaningless, and can have strange + //chi2 behaviour and large errors on the mean + //therefore make sure we are including full bins in fit and + //have a minimum of 3 bins + int _minBin = hproj->FindBin(_min); + int _maxBin = hproj->FindBin(_max); + if(_maxBin - _minBin < 2) { + //require at least 3 bins for a meaningful gauss fit + //std::cout << "WARNING core had too few bins for fit - expanding core for " << h->GetName() << std::endl; + _maxBin = _maxBin + 1; + _minBin = _minBin - 1; + } + _min = hproj->GetBinLowEdge(_minBin); + _max = (hproj->GetBinLowEdge(_maxBin))+(hproj->GetBinWidth(_maxBin)); + + TF1 *fW2 = new TF1("fW2","gaus",_min,_max); + hproj -> Fit("fW2", "RQN"); + if(iopt==2){ + h->Fill(fW2->GetParameter(1)); + } else if (iopt==3){ + h->Fill(fW2->GetParameter(2)); + } else if (iopt==4){ + float _chi2 = fW2->GetChisquare(); + int _ndf = fW2->GetNDF(); + if(_ndf) h->Fill(_chi2/_ndf); + else h->Fill(0.0); + }else if (iopt==5){ + h->Fill(fW2->GetParError(1)); + } + + delete fW; + delete fW2; + } + else if(iopt==6){ + h->Fill(getMedian(hproj)); + } + else if(iopt==7){ + h->Fill(hproj->GetEntries()); + } + //else std::cerr << "Incorrect iopt switch in meanRMSProjections3D_DMRPlot()" << std::endl; + delete hproj; + } + } + + return; +} + + void MonitoringFile:: +meanRMSProjections3D_XY(TH3F* h3d, TH1F* h,int iXY,int iopt) +{ + + //fills a 1-D histogram with mean or width of the projected rows/columns of a 3-D histogram + // iXY = 0; project columns (i.e. for each x of the 3D histogram form the distribution of all y-bins) + // iXY = 1; project rows (i.e. for each y of the 3D histogram form the distribution of all x-bins) + //the way in which the mean or width is determined is specified by the iopt option + //can be from a gaussian fit for example + // iopt = 0; fills with statistical mean + // iopt = 1; fills with statistical RMS + // iopt = 2; fills with mean of a two-stage Gaussian fit + // iopt = 3; fills with width of a two-stage Gaussian fit + // iopt = 4; fills with Chi2/DOF of a two-stage Gaussian fit + // iopt = 5; fills with nentries in the bin + + int nbins_3dX = h3d->GetNbinsX(); + int nbins_3dY = h3d->GetNbinsY(); + int nbins_h = h->GetNbinsX(); + int nbins_3d = 0;//will be overridden + + if(iXY==0) { + if(nbins_3dX!=nbins_h) { + //std::cerr << "meanRMSProjections3D_XY: Mean/RMS Histograms not set up correctly - nbins mismatch for " << h->GetName() << std::endl; + return; + } + nbins_3d = nbins_3dX; + } + else if(iXY==1) { + if(nbins_3dY!=nbins_h) { + //std::cerr << "meanRMSProjections3D_XY: Mean/RMS Histograms not set up correctly - nbins mismatch for" << h->GetName() << std::endl; + //std::cout << "nbins_3dY = " << nbins_3dY << ", nbins_h = " << nbins_h << std::endl; + return; + } + nbins_3d = nbins_3dY; + } + else { + //std::cerr << "meanRMSProjections3D_XY: iXY != 1 or 0 exiting" << std::endl; + return; + } + + for(int i = 1; i!=nbins_3d+1; i++){ + + TH1F* hproj; + if(iXY==0){ + h3d->GetXaxis()->SetRange(i,i); + h3d->GetYaxis()->SetRange(1,nbins_3dY); + hproj = (TH1F*)h3d->Project3D("ze"); + } + else { // (iXY == 1), as checked above + h3d->GetYaxis()->SetRange(i,i); + h3d->GetXaxis()->SetRange(1,nbins_3dX); + hproj = (TH1F*)h3d->Project3D("ze"); + } + + //do not fill if there are 30 or less entries in the bin + if(iopt<5 && (hproj->GetEntries()<=30 || hproj->Integral()<=30)) { + delete hproj; + //h->SetBinContent(i,0); + //h->SetBinError(i,0); + continue; + } + if(iopt==0){ + h->SetBinContent(i,hproj->GetMean()); + h->SetBinError(i,hproj->GetMeanError()); + } + else if(iopt==1){ + h->SetBinContent(i,hproj->GetRMS()); + h->SetBinError(i,hproj->GetRMSError()); + } + else if(iopt>=2 && iopt<5){ + + //we make a 2-stage Gaussian fit + //first fit is in the range [MEAN + 2*RMS, MEAN - 2*RMS] + //(restricting the range of the first fit has little effect) + //second fit is in the range [mean + 2*width, mean - 2*width] + //using the mean and width of the first fit + + //first fit + float _mean = hproj->GetMean(); + float _rms = hproj->GetRMS(); + float _min = _mean - 2*_rms; + float _max = _mean + 2*_rms; + TF1 *fW = new TF1("fW","gaus",_min,_max); + hproj -> Fit("fW", "RQN"); + + //second fit + _mean = fW->GetParameter(1); + _rms = fW->GetParameter(2); + _min = _mean - 2*_rms; + _max = _mean + 2*_rms; + //if bins are large relative to distribution then + //the above determined range could only be two bins + //or even just fractions of bins + //in this case a gauus fit is meaningless, and can have strange + //chi2 behaviour and large errors on the mean + //therefore make sure we are including full bins in fit and + //have a minimum of 3 bins + int _minBin = hproj->FindBin(_min); + int _maxBin = hproj->FindBin(_max); + if(_maxBin - _minBin < 2) { + //require at least 3 bins for a meaningful gauss fit + //std::cout << "WARNING core had too few bins for fit - expanding core for " << h->GetName() << std::endl; + _maxBin = _maxBin + 1; + _minBin = _minBin - 1; + } + _min = hproj->GetBinLowEdge(_minBin); + _max = (hproj->GetBinLowEdge(_maxBin))+(hproj->GetBinWidth(_maxBin)); + + TF1 *fW2 = new TF1("fW2","gaus",_min,_max); + hproj -> Fit("fW2", "RQN"); + if(iopt==2){ + h->SetBinContent(i,fW2->GetParameter(1)); + h->SetBinError(i,fW2->GetParError(1)); + } else if (iopt==3){ + h->SetBinContent(i,fW2->GetParameter(2)); + h->SetBinError(i,fW2->GetParError(2)); + } else if (iopt==4){ + float _chi2 = fW2->GetChisquare(); + int _ndf = fW2->GetNDF(); + if(_ndf) h->SetBinContent(i,_chi2/_ndf); + else h->SetBinContent(i,0); + } + delete fW; + delete fW2; + } + else if(iopt==5){ + h->SetBinContent(i,hproj->GetEntries()); + } + //else std::cerr << "Incorrect iopt switch in meanRMSProjections3D_XY()" << std::endl; + delete hproj; + } + + + return; + +} + + + //void MonitoringFile::mean() + //{} + + + //TH1F* MonitoringFile::combineHistos(const char* name, const char* title, const std::vector<TH1F*>& plots,int gap,int options) + //{ + //gap is for the gap between the histograms + //options are the option passed to the meanRMSProjection3D_XY function. Read the function for help. + //histo should be already defined with the proper axes by the IDAlignMonResiduals.cxx + //But I may have problems in getting everything properly since the plots could have different number of bins. + //It's safer to redefine the X axis. + //int n_plots = (int) plots.size(); + //std::cout << "nplots = " << n_plots << std::endl; + //int totalBins = 0; + //for(int i=0;i!=n_plots;++i){ + //int nbins = plots.at(i)->GetNbinsX(); +// totalBins += nbins; +// std::cout << "totalBins = " << totalBins << std::endl; +//} +//totalBins += ((n_plots-1)*gap); +//Define the new histogram +// TH1F* hnew = new TH1F(name,title,totalBins,0,totalBins); + + //Take the RMS or the width + + //int bCount = 1; + //loop over the plots and fill the new one + //for(int i=0;i!=n_plots;++i){ +//int nbins_h = h->GetNbinsX(); +//} + + +TH1F* MonitoringFile:: +combineHistos(const char* name, const char* title, TObjArray* plots,int gap) +{ + + //makes one histogram out of all the histograms in the TObjArray + //this histogram is built such that the histograms are placed side-by-side + //on the same x-axis + + int n_plots = (plots->GetLast())+1;//add one since begins at zero + + std::cout << "nplots = " << n_plots << std::endl; + + //count total bins + int totalBins = 0; + for(int i=0;i!=n_plots;++i){ + + int nbins = ((TH1F*)(plots->At(i)))->GetNbinsX(); + totalBins = totalBins + nbins; + std::cout << "totalBins = " << totalBins << std::endl; + } + //take account of the gap we want to leave between plots + totalBins = totalBins + ((n_plots-1)*gap); + + TH1F* hnew = new TH1F(name,title,totalBins,0,totalBins); + + int bCount = 1; + //loop over the plots and fill the new one + for(int i=0;i!=n_plots;++i){ + + TH1F* h = (TH1F*)(plots->At(i)); + + int nbins_h = h->GetNbinsX(); + //fill the bins with the content of h + for(int j=1;j!=nbins_h+1;++j){ + hnew->SetBinContent(bCount,h->GetBinContent(j)); + hnew->SetBinError(bCount,h->GetBinError(j)); + bCount++; + } + + //skip the next bins to produce a gap + //only if this isn't the last plot + //(don't want a gap at the end) + if(i<(n_plots-1))bCount = bCount + gap; + } + + return hnew; + +} + + +void +MonitoringFile:: +setMinWindow(TH1* h1, float windowMin, float windowMax){ + + //establishes a minimum window size for TH1 histogram + + float min=h1->GetMinimum(); + float max=h1->GetMaximum(); + float margin=0.05*(max-min); + if(min > windowMin) min=windowMin-margin; + if(max < windowMax) max=windowMax+margin; + h1->SetMinimum(min); + h1->SetMaximum(max); + + return; + +} + +float +MonitoringFile:: +getMedian(TH1* h1){ + + //calculates median for a TH1 + + int nBins = h1->GetXaxis()->GetNbins(); + + //double x[nBins]; double y[nBins]; + std::vector<double> x; + std::vector<double> y; + // double x[10000]; double y[10000]; + for (int i = 1; i!=nBins+1; i++){ + + //x[i] = h1->GetBinCenter(i); + //y[i] = h1->GetBinContent(i); + x.push_back(h1->GetBinCenter(i)); + y.push_back(h1->GetBinContent(i)); + } + + //float median = TMath::Median(nBins,x,y); + float median = TMath::Median(nBins,&x[0],&y[0]); + + return median; + +} + +void +MonitoringFile:: +fillMeanOrWidth(TH2F* h2d, TH1F* h,int iopt) +{ + + //fills a 1-D histogram with either the mean or RMS of the 2d histogram in each bin. + //binning of 1d and 2d histograms must match + // iopt=0; Mean + // iopt=1; Width + + //std::cout << "In fillMeanOrWidth" << std::endl; + + int nbins_2d = h2d->GetNbinsX(); + int nbins_h = h->GetNbinsX(); + + if(nbins_2d!=nbins_h) //std::cout << "Mean/RMS Histograms not set up correctly - nbins mismatch for " << h->GetName() << std::endl; + + for(int i = 1; i!=nbins_2d+1; i++){ + + //std::cout << "Processing bin " << i << std::endl; + + TH1F* hproj = (TH1F*)h2d->ProjectionY("proj",i,i,"e"); + + //std::cout << "Made projection for bin " << i << std::endl; + + //do not fill if there are no entries in the bin + if(hproj->GetEntries()<=0) { + delete hproj; + continue; + } + + if(iopt==0){ + h->SetBinContent(i,hproj->GetMean()); + h->SetBinError(i,hproj->GetMeanError()); + //std::cout << "Filled mean results for bin " << i << std::endl; + } + else if(iopt==1){ + h->SetBinContent(i,hproj->GetRMS()); + h->SetBinError(i,hproj->GetRMSError()); + } + //else std::cout << "Incorrect switch in MeanRMSProjectionsBarrel()" << std::endl; + + delete hproj; + } + + //std::cout << "Finished fillMeanOrWidth" << std::endl; + + return; + +} + + /* + //Pierfrancesco: proposal to use this fit: Gaussian + constant to get rid of the need to define the range. + + void MonitoringFile::fillGaussianConstMeanOrWidth(TH2F* h2d, TH1F* h, int iopt) + { + //Makes a Gaussian+constant fit to each bin of a TH2F and fills a TH1F with + //the either the mean or width of this fit + //iopt=0;Mean + //iopt=1;Width + + //std::cout<<"In fillGaussianConstMeanOrWidth for "<<h->GetName()<<std::endl; + //calling this means that the histogram bin content is flagged + //as being an average and so adding histos from different jobs + //will produce weighted mean + + h->SetBit(TH1::kIsAverage); + + in nbins_2d = h2d->GetNbinsX(); + + // Removed by Alex. I'm keeping just for the moment for testing purposes. + int nbins_h = h->GetNbinsX(); + if(nbins_2d!=nbins_h) std::cout << "Mean/Width Histograms not set up correctly - nbins mismatch for " << h->GetName() << std::endl; + + } + */ + +void +MonitoringFile:: +fillGaussianMeanOrWidth(TH2F* h2d, TH1F* h, float fitMin, float fitMax, int iopt) +{ + + //Makes a Gaussian fit to each bin of a TH2F and fills a TH1F with + //the either the mean or width of this Gaussian + // iopt=0; Mean + // iopt=1; Width + + //std::cout << "In fillGaussianMeanOrWidth for " << h->GetName() << std::endl; + + //calling this means that the histogram bin content is flagged + //as being an average and so adding histos from different jobs + //will produce weighted mean + h->SetBit(TH1::kIsAverage); + + //Added by PF for debugging purpose. + //std::cout<<"2D name "<<h2d->GetName()<<std::endl; + //std::cout<<"1D name "<<h->GetName()<<std::endl; + + int nbins_2d = h2d->GetNbinsX(); + + //std::cout<<"h2d->GetNbinsX(); "<< h2d->GetNbinsX()<<std::endl; + + // Removed by Alex + //int nbins_h = h->GetNbinsX(); + //if(nbins_2d!=nbins_h) std::cout << "Mean/Width Histograms not set up correctly - nbins mismatch for " << h->GetName() << std::endl; + + for(int i = 1; i!=nbins_2d+1; i++){ + + //std::cout << "Gaussian: processing bin " << i << std::endl; + + TH1F* hproj = (TH1F*)h2d->ProjectionY("proj",i,i,"e"); + + //std::cout << "Gaussian: made projection for bin " << i << std::endl; + + //do not fill if there are few entries in the bin + if(hproj->GetEntries()<=30 || hproj->Integral()<=30) { + //std::cout << "Skipped bin " << i << std::endl; + delete hproj; + continue; + } + + TF1 *fit = new TF1("fit","gaus",fitMin,fitMax); + + hproj->Fit("fit","RQN"); + float mean = fit->GetParameter(1); + float meanErr = fit->GetParError(1); + float width = fit->GetParameter(2); + float widthErr = fit->GetParError(2); + + //std::cout << "Gaussian: fitted bin " << i << std::endl; + + if(iopt==0){ + h->SetBinContent(i,mean); + h->SetBinError(i,meanErr); + } + else if(iopt==1){ + h->SetBinContent(i,width); + h->SetBinError(i,widthErr); + } + //else std::cout << "Incorrect switch in fillGaussianMeanOrWidth" << std::endl; + + delete hproj; + delete fit; + } + + //std::cout << "leaving fillGaussianMeanOrWidth for " << h->GetName() << std::endl; + + return; + +} + +void +MonitoringFile:: +fillDetPaperMeanRMS(TH2F* h2d, TH1F* h, int iopt) +{ + + //this finds the statistical mean/rms using the detector paper definition + //i.e. the mean and RMS defined using bins which contain 99.7% of entries (symmetrically) around the mean bin + // iopt=0; Mean + // iopt=1; RMS (resolution) + //Note that this method is not reliable if there is large underflow/overflow in the histogram. + + //calling this means that the histogram bin content is flagged + //as being an average and so adding histos from different jobs + //will produce weighted mean + h->SetBit(TH1::kIsAverage); + + int nbins_2d = h2d->GetNbinsX(); + + // Removed by Alex + //int nbins_h = h->GetNbinsX(); + //if(nbins_2d!=nbins_h) std::cout << "Mean/Width Histograms not set up correctly - nbins mismatch for " << h->GetName() << std::endl; + + for(int i = 1; i!=nbins_2d+1; i++){ + + //std::cout << "fillDetPaperMeanRMS: processing bin " << i << std::endl; + + TH1F* hproj = (TH1F*)h2d->ProjectionY("proj",i,i,"e"); + + //std::cout << "fillDetPaperMeanRMS: made projection for bin " << i << std::endl; + + //do not fill if there are few entries in the bin + if(hproj->GetEntries()<=30 || hproj->Integral()<=30) { + delete hproj; + continue; + } + + float hmean = hproj->GetMean(); + // float hRMS = hproj->GetRMS(); + float hFullIntegral = hproj->Integral(1,hproj->GetNbinsX()); + + //std::cout << "fillDetPaperMeanRMS: Original Mean, RMS = " << hmean << ", " << hRMS << std::endl; + + float hTargetIntegral = 0.997*hFullIntegral; + int hMeanBin = hproj->FindBin(hmean); + + //std::cout << "fillDetPaperMeanRMS: NEntries = " << hproj->GetEntries() << ", fullIntegral = " << hFullIntegral << std::endl; + + int lowBin = hMeanBin; + int highBin = hMeanBin; + float hIntegral = 0.0; + + while (hIntegral < hTargetIntegral) { + // find the bin which contains the mean + // then integrate symmetrically around this bin, increasing the range + // until the integral is larger than the target + // this defines your upper and lower bounds for mean/rms. + + lowBin = lowBin - 1; + highBin = highBin + 1; + hIntegral = hproj->Integral(lowBin,highBin); + } + + //std::cout << "fillDetPaperMeanRMS: NBins = " << hproj->GetNbinsX() << " minBin = " << lowBin << " highBin = " << highBin << std::endl; + + TH1F* hclone = (TH1F*)hproj->Clone("clone"); + + hclone->GetXaxis()->SetRange(lowBin,highBin); + float hNewMean = hclone->GetMean(); + float hNewMeanErr = hclone->GetMeanError(); + float hNewRMS = hclone->GetRMS(); + float hNewRMSErr = hclone->GetRMSError(); + + //std::cout << "fillDetPaperMeanRMS: New Mean, RMS = " << hNewMean << ", " << hNewRMS << std::endl; + + if(iopt==0){ + h->SetBinContent(i,hNewMean); + h->SetBinError(i,hNewMeanErr); + } + else if(iopt==1){ + h->SetBinContent(i,hNewRMS ); + h->SetBinError(i,hNewRMSErr); + } + //else std::cout << "Incorrect switch in fillDetPaperMeanRMS" << std::endl; + + delete hproj; + delete hclone; + } + + return; + +} +} diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_IDEnhancedPrimaryVertex.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_IDEnhancedPrimaryVertex.cxx new file mode 100644 index 0000000000000000000000000000000000000000..972ab6c8712eb5f40119ac1bb948a39c0585e62b --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_IDEnhancedPrimaryVertex.cxx @@ -0,0 +1,454 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: MonitoringFile_IDEnhancedPrimaryVertex.cxx,v 1.1 2009-04-03 08:48:00 ponyisi Exp $ +// ********************************************************************** + +#include "DataQualityUtils/MonitoringFile.h" + +// #include <cmath> +#include <vector> + +#include <TGraph.h> +#include <TGraphErrors.h> +#include <TGraphAsymmErrors.h> +#include <TCanvas.h> +#include <TF1.h> +#include <TFile.h> +#include <TH1.h> +#include <TH2.h> +#include <TKey.h> +#include <TProfile.h> +#include <TMath.h> +#include <TString.h> + +namespace dqutils { + +// define helper methods here rather then in this central MonitoringFile.h "beast" +void plotResolution(const TString& coordinate, const TString& versus); +void plotEfficiency(); +double error_func( float x, Double_t *par); +double scaleFactorFitFcn(double *x, double *par); +std::vector<float> stableGaussianFit(TH1 * histo); + +void MonitoringFile::pv_PrimaryVertexMonitoring_calcResoAndEfficiency( std::string inFilename, bool /* isIncremental */ ) +{ +// std::cout << "\n"; +// std::cout << "Running Inner-Detector primary vertexing monitoring analysis\n"; +// std::cout << "\nWarning messages from fitting and histogram updating follow:\n\n"; + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + if (f == 0 || ! f->IsOpen()) { + //std::cerr << "MonitoringFile::PrimaryVertexMonitoring_calcResoAndEfficiency(): " +// << "Input file not opened\n"; + delete f; + return; + } + if(f->GetSize()<1000.) { +// std::cerr << "MonitoringFile::PrimaryVertexMonitoring_calcResoAndEfficiency(): " +// << "MonitoringFile empty\n"; + delete f; + return; + } + + bool dirExists = false; + TString run_dir; + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*>( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if (tdir_run !=0 ) { + std::string tdir_run_name( tdir_run->GetName() ); + if (tdir_run_name.find("run")!= std::string::npos ) { + run_dir=tdir_run_name; + + dirExists = f->GetDirectory(run_dir+"/InDetGlobal/PrimaryVertex"); + if (dirExists) + { +// std::cout << run_dir << "/InDetGlobal/PrimaryVertex exists. Creating and saving plots:" << std::endl; + f->cd(run_dir+"/InDetGlobal/PrimaryVertex"); + } + } + } + else + { + delete obj_run; + } + } + + if (!dirExists) + { + //std::cerr << "Either enhanced vertex info is not there or monitoring file was produced outside T0 context. Trying dir: InDetGlobal/PrimaryVertex\n"; + dirExists = f->GetDirectory("InDetGlobal/PrimaryVertex"); + if (dirExists) f->cd("InDetGlobal/PrimaryVertex"); + } + + if (dirExists) + { + // create histos + plotResolution("X", "Ntrk"); + plotResolution("Y", "Ntrk"); + plotResolution("Z", "Ntrk"); + + plotResolution("X", "SumPt2"); + plotResolution("Y", "SumPt2"); + plotResolution("Z", "SumPt2"); + + plotEfficiency(); + } + + f->Close(); + delete f; +// std::cout << "\n"; +// std::cout << "Finish Inner-Detector primary vertex monitoring analysis"<<std::endl; + return; +} + +void +plotResolution(const TString& coordinate="Z", const TString& versus="Ntrk") +{ +// cout << "Creating and writing histos for resolution " << coordinate << " versus " << versus << endl; + + TH2F* h_Vrt_pullVsSomething_split(0); + TH2F* h_Vrt_err_vs_Something(0); +// TH2F* h_Vrt_Tag_err_vs_Something(0); + TString xAxisLabel(""); + if (versus == "Ntrk") + { + h_Vrt_pullVsSomething_split = (TH2F*)gDirectory->Get("Vrt_"+coordinate+"pullVsNtrkAverage_split"); + h_Vrt_err_vs_Something = (TH2F*)gDirectory->Get("Vrt_"+coordinate+"err_vs_ntrk"); +// h_Vrt_Tag_err_vs_Something = (TH2F*)gDirectory->Get("Vrt_Tag_"+coordinate+"err_vs_ntrk"); + xAxisLabel = "Number of fitted tracks"; + } else if (versus == "SumPt2") + { + h_Vrt_pullVsSomething_split = (TH2F*)gDirectory->Get("Vrt_"+coordinate+"pullVsPt2Average_split"); + h_Vrt_err_vs_Something = (TH2F*)gDirectory->Get("Vrt_"+coordinate+"err_vs_pt2"); +// h_Vrt_Tag_err_vs_Something = (TH2F*)gDirectory->Get("Vrt_Tag_"+coordinate+"err_vs_pt2"); + xAxisLabel = "#sqrt{#sum p_{T}^{2}} [GeV]"; + } else return; + + //if (h_Vrt_pullVsSomething_split == 0) std::cout << "h_Vrt_pullVsSomething_split has zero pointer!" << std::endl; + //if (h_Vrt_err_vs_Something == 0) std::cout << "h_Vrt_err_vs_Something has zero pointer!" << std::endl; + if (h_Vrt_pullVsSomething_split == 0 or h_Vrt_err_vs_Something == 0) return; + + int n_bins = h_Vrt_pullVsSomething_split->GetNbinsX(); + std::vector<float> rms_z; + std::vector<float> rms_z_er; + std::vector<float> sigma_z; + std::vector<float> sigma_z_er; + std::vector<float> bins_z_nt; + std::vector<float> bins_z_nt_er; + +// root starts counting the bins at 1, i.e. bin 1 holds NTrk = 0. or sqrt(sumpt2) = 0. - 0.25. GeV +// std::cout << "n bins: " << n_bins << "\tTotal entries: " << h_Vrt_pullVsSomething_split->GetEntries() << std::endl; +// TH1D * nTrksPerVertex = h_Vrt_pullVsSomething_split->ProjectionX("projectionNTrks_"+coordinate+"_"+versus); + +// TH1D * profileZFull = h_Vrt_pullVsSomething_split->ProjectionY("projectionPullsFull_"+coordinate+"_"+versus); + + Int_t startBin = 0; + TH1D *profileZ = 0; + const Int_t minEntriesForKFactorBin = 1000; + for(int bin_count = 1; bin_count < n_bins+1; bin_count++) + { + //Fixed binning +// TH1D *profileZ = h_Vrt_pullVsSomething_split->ProjectionY("projectionPulls", bin_count, bin_count,"e"); +// Double_t binCenter = h_Vrt_pullVsSomething_split->GetXaxis()->GetBinCenter(bin_count); +// Double_t binWidth = h_Vrt_pullVsSomething_split->GetXaxis()->GetBinWidth(bin_count)/2.; + + //Variable binning + TH1D *profileZTmp = h_Vrt_pullVsSomething_split->ProjectionY("projectionPulls", bin_count, bin_count,"e"); + //cout << "Bin: " << bin_count << ", Entries: " << profileZTmp->GetEntries() << endl; + if (profileZ == 0) { + startBin = bin_count; + profileZ = (TH1D*) profileZTmp->Clone("projectionPulls_Integrated"); + //cout << "StartBin = " << startBin << endl; + } else { + profileZ->Add(profileZTmp); + } + delete profileZTmp; + profileZTmp = 0; + if ((profileZ->GetEntries() < minEntriesForKFactorBin) && (bin_count < n_bins)) //not enough entries, not last bin + continue; + + Double_t lowEdge = h_Vrt_pullVsSomething_split->GetXaxis()->GetBinLowEdge(startBin); + Double_t highEdge = h_Vrt_pullVsSomething_split->GetXaxis()->GetBinLowEdge(bin_count) + h_Vrt_pullVsSomething_split->GetXaxis()->GetBinWidth(bin_count); + Double_t binCenter = (lowEdge + highEdge) / 2; + Double_t binWidth = (highEdge - lowEdge) / 2; //half of the bin width + //cout << "Bin done: " << binCenter << " +/- " << binWidth << ", Entries: " << profileZ->GetEntries() << endl; + // variable binning end + + bins_z_nt.push_back(binCenter); + bins_z_nt_er.push_back(binWidth); // dummy error of binwidth for now + + rms_z.push_back(profileZ->GetRMS()); + rms_z_er.push_back(profileZ->GetRMSError()); + + //making a gaussian fit if there is anough entries + if(profileZ->GetEntries() > 100.) + { + std::vector<float> fit_res = stableGaussianFit(profileZ); + sigma_z.push_back(fit_res[0]); + sigma_z_er.push_back(fit_res[1]); + }else{ + sigma_z.push_back(0.); + sigma_z_er.push_back(0.); + }//end of good number of bins selection + + delete profileZ; // must keep this to delete the projection from memory (next one has same name!) + profileZ = 0; + }//end of loop over all the ntrk bins + + TGraphErrors * krms_z_vs_ntrk = new TGraphErrors(bins_z_nt.size(), &(bins_z_nt[0]),&(rms_z[0]),&(bins_z_nt_er[0]), &(rms_z_er[0]) ); + krms_z_vs_ntrk->GetYaxis()->SetTitle(coordinate+" scale factor from RMS"); + krms_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel); + krms_z_vs_ntrk->SetTitle("scaleFactor"+coordinate+"_RMS"); + krms_z_vs_ntrk->SetName("scaleFactor"+coordinate+"_"+versus+"_RMS"); + + TGraphErrors * kgs_z_vs_ntrk = new TGraphErrors(bins_z_nt.size(), &(bins_z_nt[0]),&(sigma_z[0]),&(bins_z_nt_er[0]), &(sigma_z_er[0]) ); + kgs_z_vs_ntrk->GetYaxis()->SetTitle(coordinate+" scale factor from gauss fit"); + kgs_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel); + kgs_z_vs_ntrk->SetTitle("scaleFactor"+coordinate+"_Fit"); + kgs_z_vs_ntrk->SetName("scaleFactor_"+coordinate+"_"+versus+"_Fit"); + +// approximating the graph with 2nd order polynomial. + float maxFitRange(100.); + float minFitRange(2.); + if (versus == "SumPt2") { + minFitRange = 0.5; + maxFitRange = 20.; + } + TF1 *kgs_z_ntrk_fit; + Double_t *kgs_z_ntrk_fit_er; + int fitResKFactorMethod = 2; // set by hand for now + if (fitResKFactorMethod == 1) { + //Fit with a pol2 + kgs_z_vs_ntrk->Fit("pol2","Q","",minFitRange,maxFitRange); + kgs_z_vs_ntrk->GetFunction("pol2")->SetLineColor(kRed); + kgs_z_ntrk_fit = kgs_z_vs_ntrk->GetFunction("pol2"); + kgs_z_ntrk_fit_er = kgs_z_ntrk_fit->GetParErrors(); + } else if (fitResKFactorMethod == 2) { + //Fit with a pol1 + kgs_z_vs_ntrk->Fit("pol1","Q","",minFitRange,maxFitRange); + kgs_z_vs_ntrk->GetFunction("pol1")->SetLineColor(kRed); + kgs_z_ntrk_fit = kgs_z_vs_ntrk->GetFunction("pol1"); + kgs_z_ntrk_fit_er = kgs_z_ntrk_fit->GetParErrors(); + } else if (fitResKFactorMethod == 3) { + TF1 *kgsFitFcn = new TF1("kgsFitFcn", scaleFactorFitFcn, minFitRange, maxFitRange,3); + kgsFitFcn->SetParameter(0, minFitRange); + kgsFitFcn->SetParameter(1, 1.0); + kgsFitFcn->SetParameter(2, 1.0); + for (int ifit=0; ifit < 1; ifit++) //initial estimation of best parameters + kgs_z_vs_ntrk->Fit(kgsFitFcn, "Q"); + kgs_z_vs_ntrk->Fit(kgsFitFcn, "Q"); //perform actual fit + kgs_z_ntrk_fit = kgsFitFcn; + kgs_z_ntrk_fit_er = kgsFitFcn->GetParErrors(); +/* cout << "ScaleFactor fit for " << coordinate << " vs " << versus << " (method " << fitResKFactorMethod << ")= " + << kgsFitFcn->GetParameter(0) << " +/- " << kgsFitFcn->GetParError(0) << " " + << kgsFitFcn->GetParameter(1) << " +/- " << kgsFitFcn->GetParError(1) << " " + << kgsFitFcn->GetParameter(2) << " +/- " << kgsFitFcn->GetParError(2) << endl; */ + } else if (fitResKFactorMethod == 4) { + //constant fit + kgs_z_vs_ntrk->Fit("pol0","Q","",minFitRange,maxFitRange); + kgs_z_vs_ntrk->GetFunction("pol0")->SetLineColor(kRed); + kgs_z_ntrk_fit = kgs_z_vs_ntrk->GetFunction("pol0"); + kgs_z_ntrk_fit_er = kgs_z_ntrk_fit->GetParErrors(); +/* cout << "ScaleFactor fit for " << coordinate << " vs " << versus << " (method " << fitResKFactorMethod << ")= " + << kgs_z_ntrk_fit->GetParameter(0) << " +/- " << kgs_z_ntrk_fit->GetParError(0) << endl; */ + } + +// plotting the fit error of the unconstrained primary vertex and correcting them + int nbins_z_err_ntrk = h_Vrt_err_vs_Something->GetNbinsX(); + + std::vector<float> av_err_z; + std::vector<float> av_err_z_er; +// std::vector<float> av_err_tag_z; +// std::vector<float> av_err_tag_z_er; + std::vector<float> err_bins_z_nt; + std::vector<float> err_bins_z_nt_er; + std::vector<float> res_z; + std::vector<float> res_z_er; +// std::vector<float> res_tag_z; +// std::vector<float> res_tag_z_er; + + for(int bin_count = 1; bin_count <= nbins_z_err_ntrk; ++bin_count) + { + err_bins_z_nt.push_back(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count)); + err_bins_z_nt_er.push_back(h_Vrt_err_vs_Something->GetXaxis()->GetBinWidth(bin_count)/2.); + + TH1D * profileY = h_Vrt_err_vs_Something->ProjectionY("projectionErrors",bin_count,bin_count,"e"); +// TH1D * profileYTag(0); +// if (h_Vrt_Tag_err_vs_Something) +// profileYTag = h_Vrt_Tag_err_vs_Something->ProjectionY("projectionErrorsTag",bin_count,bin_count,"e"); + + float mean = profileY->GetMean(); + float mean_error = profileY->GetMeanError(); +// float meanTag(0); +// float mean_errorTag(0); +// if (profileYTag) { +// meanTag = profileYTag->GetMean(); +// mean_errorTag = profileYTag->GetMeanError(); +// } + delete profileY; +// delete profileYTag; + + av_err_z.push_back(mean); + av_err_z_er.push_back(mean_error); +// av_err_tag_z.push_back(meanTag); +// av_err_tag_z_er.push_back(mean_errorTag); + + //estimating the approximate k-factor and the error value + double pr_er = 0.0; + float val(0.); + if (fitResKFactorMethod == 1) { + pr_er = error_func( bin_count, kgs_z_ntrk_fit_er ); + } else if (fitResKFactorMethod == 2) { + val = h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count); + pr_er = TMath::Power(kgs_z_ntrk_fit_er[1]*val, 2) + TMath::Power(kgs_z_ntrk_fit_er[0], 2); + pr_er = TMath::Sqrt(pr_er); +// cout << "val = " << val << ", pr_er = " << pr_er << ", p0er = " << kgs_z_ntrk_fit_er[0] << ", p1er = "<< kgs_z_ntrk_fit_er[1] << endl; + } else if (fitResKFactorMethod == 3) { + val = h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count); + //approximately the error on the plateau + pr_er = kgs_z_ntrk_fit_er[2]; + } else if (fitResKFactorMethod == 4) { + pr_er = kgs_z_ntrk_fit_er[0]; + } + + res_z.push_back(mean * kgs_z_ntrk_fit->Eval(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count))); + res_z_er.push_back(TMath::Sqrt(TMath::Power(mean_error * kgs_z_ntrk_fit->Eval(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count)),2) + TMath::Power( pr_er * mean ,2))); +// res_tag_z.push_back(meanTag * kgs_z_ntrk_fit->Eval(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count))); +// res_tag_z_er.push_back(TMath::Sqrt(TMath::Power(mean_errorTag * kgs_z_ntrk_fit->Eval(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count)),2) + TMath::Power( pr_er * mean ,2))); + } + TGraphErrors * res_z_vs_ntrk = new TGraphErrors(err_bins_z_nt.size(), &(err_bins_z_nt[0]),&(res_z[0]),&(err_bins_z_nt_er[0]), &(res_z_er[0]) ); + res_z_vs_ntrk->GetYaxis()->SetTitle(coordinate+" Vertex Resolution [mm]"); + res_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel); + res_z_vs_ntrk->SetTitle(coordinate+" Vertex Resolution"); + res_z_vs_ntrk->SetName("resolution_"+coordinate+"_"+versus); + +// TGraphErrors * res_tag_z_vs_ntrk = new TGraphErrors(err_bins_z_nt.size(), &(err_bins_z_nt[0]),&(res_tag_z[0]),&(err_bins_z_nt_er[0]), &(res_tag_z_er[0]) ); +// res_tag_z_vs_ntrk->GetYaxis()->SetTitle(coordinate+" Tagged Vertex Resolution [mm]"); +// res_tag_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel); +// res_tag_z_vs_ntrk->SetTitle(coordinate+" Tagged Vertex Resolution"); +// res_tag_z_vs_ntrk->SetName("resolution_tag_"+coordinate+"_"+versus); + +// TGraphErrors * mean_err_z_vs_ntrk = new TGraphErrors(err_bins_z_nt.size(), &(err_bins_z_nt[0]),&(av_err_z[0]),&(err_bins_z_nt_er[0]), &(av_err_z_er[0]) ); +// mean_err_z_vs_ntrk->GetYaxis()->SetTitle(coordinate+" mean vertex error [mm]"); +// mean_err_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel); +// mean_err_z_vs_ntrk->SetTitle(coordinate+" Mean Vertex Error"); +// mean_err_z_vs_ntrk->SetName("resolution_"+coordinate+"_"+versus+"_Uncorrected"); //not corrected with k-factor + + /////////////// + // Writing out + /////////////// + if (versus == "Ntrk") res_z_vs_ntrk->GetXaxis()->SetRangeUser(0.,100.); + else res_z_vs_ntrk->GetXaxis()->SetRangeUser(0.,20.); + res_z_vs_ntrk->GetYaxis()->SetRangeUser(0.0025,1.); + res_z_vs_ntrk->Write("", TObject::kOverwrite); + delete res_z_vs_ntrk; + + if (versus == "Ntrk") krms_z_vs_ntrk->GetXaxis()->SetRangeUser(0.,100.); + else krms_z_vs_ntrk->GetXaxis()->SetRangeUser(0.,20.); + krms_z_vs_ntrk->GetYaxis()->SetRangeUser(0.5,1.3); + krms_z_vs_ntrk->Write("", TObject::kOverwrite); + delete krms_z_vs_ntrk; + + if (versus == "Ntrk") kgs_z_vs_ntrk->GetXaxis()->SetRangeUser(0.,100.); + else kgs_z_vs_ntrk->GetXaxis()->SetRangeUser(0.,20.); + kgs_z_vs_ntrk->GetYaxis()->SetRangeUser(0.5,1.3); + kgs_z_vs_ntrk->Write("", TObject::kOverwrite); + delete kgs_z_vs_ntrk; + +// nTrksPerVertex->GetYaxis()->SetTitle("Entries"); +// nTrksPerVertex->Draw(); +// nTrksPerVertex->Write("", TObject::kOverwrite); + + return; +} + +// Reconstruction efficiency +void plotEfficiency() +{ +// cout << "Creating and writing histos for efficiency" << endl; + + // get histos but return if any histo is not there in input + TH1F *h_Vrt_split_tag_ntrk = (TH1F*)gDirectory->Get("Vrt_split_tag_ntrk"); if (h_Vrt_split_tag_ntrk == 0) return; + TH1F *h_Vrt_split_probe_ntrk = (TH1F*)gDirectory->Get("Vrt_split_probe_ntrk"); if (h_Vrt_split_probe_ntrk == 0) return; + TH1F *h_Vrt_split_matched_tag_ntrk = (TH1F*)gDirectory->Get("Vrt_split_matched_tag_ntrk"); if (h_Vrt_split_matched_tag_ntrk == 0) return; + TH1F *h_Vrt_split_matched_probe_ntrk = (TH1F*)gDirectory->Get("Vrt_split_matched_probe_ntrk"); if (h_Vrt_split_matched_probe_ntrk == 0) return; + TH1F *h_Vrt_split_dist_tag = (TH1F*)gDirectory->Get("Vrt_split_dist_tag"); if (h_Vrt_split_dist_tag == 0) return; + TH1F *h_Vrt_split_dist_probe = (TH1F*)gDirectory->Get("Vrt_split_dist_probe"); if (h_Vrt_split_dist_probe == 0) return; + + // Use BayesDivide routing of TGraphAsymmErrors + TGraphAsymmErrors *g_Vrt_rec_eff_m1_split_vs_ntrk = new TGraphAsymmErrors(); + g_Vrt_rec_eff_m1_split_vs_ntrk->BayesDivide(h_Vrt_split_probe_ntrk, h_Vrt_split_tag_ntrk); + g_Vrt_rec_eff_m1_split_vs_ntrk->SetName("g_RecEff_M1"); + + TGraphAsymmErrors *g_Vrt_sel_eff_m1_split_vs_ntrk = new TGraphAsymmErrors(); + g_Vrt_sel_eff_m1_split_vs_ntrk->BayesDivide(h_Vrt_split_matched_probe_ntrk, h_Vrt_split_matched_tag_ntrk); + g_Vrt_sel_eff_m1_split_vs_ntrk->SetName("g_SelEff_M1"); + + // formatting and writing out + g_Vrt_rec_eff_m1_split_vs_ntrk->GetHistogram()->GetXaxis()->SetTitle("Number of tracks"); + g_Vrt_rec_eff_m1_split_vs_ntrk->GetHistogram()->GetYaxis()->SetTitle("Reconstruction efficiency"); + g_Vrt_rec_eff_m1_split_vs_ntrk->SetMarkerStyle(20); + g_Vrt_rec_eff_m1_split_vs_ntrk->Write("", TObject::kOverwrite); + delete g_Vrt_rec_eff_m1_split_vs_ntrk; + + g_Vrt_sel_eff_m1_split_vs_ntrk->GetHistogram()->GetXaxis()->SetTitle("Number of tracks"); + g_Vrt_sel_eff_m1_split_vs_ntrk->GetHistogram()->GetYaxis()->SetTitle("Selection Efficiency"); + g_Vrt_sel_eff_m1_split_vs_ntrk->SetMarkerStyle(20); + g_Vrt_sel_eff_m1_split_vs_ntrk->Write("", TObject::kOverwrite); + delete g_Vrt_sel_eff_m1_split_vs_ntrk; + + return; +} + +std::vector<float> stableGaussianFit(TH1 * histo) +{ + std::vector<float> results; + if(histo) + { + double sigmas = 2.; + + histo->Fit("gaus","Q0","",-2,2); + TF1* func = histo->GetFunction("gaus"); + double actualSigma=func->GetParameter(2); + double actualSigmaErr=func->GetParError(2); + + for (int u=0;u<10;u++) + { + histo->Fit("gaus","Q0","",-sigmas*actualSigma,sigmas*actualSigma); + func = histo->GetFunction("gaus"); + actualSigma = func->GetParameter(2); + actualSigmaErr = func->GetParError(2); + }//end of the fitting loop + + results.push_back(actualSigma); + results.push_back(actualSigmaErr); + }else{ + results.push_back(0.); + results.push_back(0.); + }//end of protection against an empty histogram + + return results; +}//end of stableGaussian Fit function + +double error_func( float x, Double_t *par) +{ +//calculating the square of the propagated error on the fit values + return ( TMath::Power(par[0],2) + x * TMath::Power(par[1],2) + TMath::Power(x * par[2],2)) ; +} + +double scaleFactorFitFcn(double *x, double *par) +{ + // Truncated gaus-smeared step function + // par 0: mean of turn-on (and truncation point) + // par 1: slope of turn-on + // par 2: plateau + return (x[0]>=par[0])*TMath::Erf(par[1]*x[0] - par[0])*par[2]; +} + +} diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_IDPerfPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_IDPerfPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6c83e942a16536d25807b086879652d584c885e9 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_IDPerfPostProcess.cxx @@ -0,0 +1,2025 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: MonitoringFile_IDPerfPostProcess.cxx,v 1.2 2009-04-16 17:49:23 weina Exp $ +// ********************************************************************** + +#include "DataQualityUtils/MonitoringFile.h" + +#include <cmath> +#include <vector> + +#include <TCanvas.h> +#include <TF1.h> +#include <TFile.h> +#include <TH1.h> +#include <TH2.h> +#include <TKey.h> +#include <TMath.h> +#include <TProfile.h> +#include <TTree.h> +#include <TROOT.h> + +#include "RooRealVar.h" +#include "RooDataHist.h" +#include "RooArgList.h" +#include "RooPlot.h" +#include "RooBreitWigner.h" +#include "RooCBShape.h" +#include "RooFFTConvPdf.h" +#include "RooGlobalFunc.h" +#include "RooPlot.h" + +namespace dqutils { + +void +MonitoringFile:: +fitMergedFile_IDPerfMonManager( std::string inFilename, bool /* isIncremental */ ) +{ + //std::cout << "\n"; + //std::cout << "Running Inner-Detector performance-monitoring analysis\n"; + //std::cout << "\nWarning messages from fitting and histogram updating follow:\n\n"; + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + if (f == 0 || ! f->IsOpen()) { + //std::cerr << "MonitoringFile::fitMergedFile_IDPerfMonManager(): " + //<< "Input file not opened\n"; + delete f; + return; + } + if(f->GetSize()<1000.) { + //std::cerr << "MonitoringFile::fitMergedFile_IDPerfMonManager(): " + //<< "MonitoringFile empty\n"; + delete f; + return; + } + std::string run_dir; + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*>( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if (tdir_run !=0 ) { + std::string tdir_run_name( tdir_run->GetName() ); + if (tdir_run_name.find("run")!= std::string::npos ) { + run_dir=tdir_run_name; + // std::cout<<"Run_directory: "<<run_dir<<std::endl; + TIter next_perf(tdir_run->GetListOfKeys()); + TKey* key_perf(0); + while ((key_perf=dynamic_cast<TKey*>( next_perf() ))!=0 ) { + std::string perf_name(key_perf->GetName()); + // for hist file with run_directory + if (perf_name.find("IDPerfMon")!=std::string::npos){ + TObject* obj_perf = key_perf->ReadObj(); + TDirectory* tdir_perf = dynamic_cast<TDirectory*>( obj_perf ); + if (tdir_perf !=0) { + run_dir=run_dir+'/'; + TIter next_module(tdir_perf->GetListOfKeys()); + TKey* key_module(0); + while ((key_module=dynamic_cast<TKey*>(next_module() )) !=0) { + std::string module_name(key_module->GetName()); + if (module_name.find("Kshort")!=std::string::npos) { + TObject *obj_Kshort = key_module->ReadObj(); + TDirectory *tdir_Kshort = dynamic_cast<TDirectory*>(obj_Kshort); + if ( tdir_Kshort !=0 ) { + TIter next_trigger(tdir_Kshort->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonKshort( f,run_dir,TriggerName ); + } + } else { + delete obj_Kshort; + } + } + + if (module_name.find("Jpsi")!=std::string::npos) { + TObject *obj_Jpsi = key_module->ReadObj(); + TDirectory *tdir_Jpsi = dynamic_cast<TDirectory*>(obj_Jpsi); + if ( tdir_Jpsi !=0 ) { + TIter next_trigger(tdir_Jpsi->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonJpsi( f,run_dir,TriggerName ); + } + } else { + delete obj_Jpsi; + } + } + if (module_name.find("Upsilon")!=std::string::npos) { + TObject *obj_Upsilon = key_module->ReadObj(); + TDirectory *tdir_Upsilon = dynamic_cast<TDirectory*>(obj_Upsilon); + if ( tdir_Upsilon !=0 ) { + TIter next_trigger(tdir_Upsilon->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonUpsilon( f,run_dir,TriggerName ); + } + } else { + delete obj_Upsilon; + } + } + if (module_name.find("Zee")!=std::string::npos) { + TObject *obj_Zee = key_module->ReadObj(); + TDirectory *tdir_Zee = dynamic_cast<TDirectory*>(obj_Zee); + if ( tdir_Zee !=0 ) { + TIter next_trigger(tdir_Zee->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonZee( f,run_dir,TriggerName ); + } + } else { + delete obj_Zee; + } + } + if (module_name.find("Wenu")!=std::string::npos) { + TObject *obj_Wenu = key_module->ReadObj(); + TDirectory *tdir_Wenu = dynamic_cast<TDirectory*>(obj_Wenu); + if ( tdir_Wenu !=0 ) { + TIter next_trigger(tdir_Wenu->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonWenu( f,run_dir,TriggerName ); + } + } else { + delete obj_Wenu; + } + } + if (module_name.find("ZMM")!=std::string::npos) { + TObject *obj_ZMM = key_module->ReadObj(); + TDirectory *tdir_ZMM = dynamic_cast<TDirectory*>(obj_ZMM); + if ( tdir_ZMM !=0 ) { + TIter next_trigger(tdir_ZMM->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonZMM( f,run_dir,TriggerName ); + } + } else { + delete obj_ZMM; + } + } + } + } else { + delete obj_perf; + } + } + } + } + + // if without top run_directory + else if (tdir_run_name.find("IDPerfMon")!= std::string::npos ) { + //std::cout<<"without run_directory"<<std::endl; + TObject* obj_perf = key_run->ReadObj(); + TDirectory* tdir_perf = dynamic_cast<TDirectory*>( obj_perf ); + if (tdir_perf !=0) { + run_dir='/'; + TIter next_module(tdir_perf->GetListOfKeys()); + TKey* key_module(0); + while ((key_module=dynamic_cast<TKey*>(next_module() )) !=0) { + std::string module_name(key_module->GetName()); + if (module_name.find("Kshort")!=std::string::npos) { + TObject *obj_Kshort = key_module->ReadObj(); + TDirectory *tdir_Kshort = dynamic_cast<TDirectory*>(obj_Kshort); + if ( tdir_Kshort !=0 ) { + TIter next_trigger(tdir_Kshort->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonKshort( f,run_dir,TriggerName ); + } + } else { + delete obj_Kshort; + } + } + if (module_name.find("Jpsi")!=std::string::npos) { + TObject *obj_Jpsi = key_module->ReadObj(); + TDirectory *tdir_Jpsi = dynamic_cast<TDirectory*>(obj_Jpsi); + if ( tdir_Jpsi !=0 ) { + TIter next_trigger(tdir_Jpsi->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonJpsi( f,run_dir,TriggerName ); + } + } else { + delete obj_Jpsi; + } + } + if (module_name.find("Upsilon")!=std::string::npos) { + TObject *obj_Upsilon = key_module->ReadObj(); + TDirectory *tdir_Upsilon = dynamic_cast<TDirectory*>(obj_Upsilon); + if ( tdir_Upsilon !=0 ) { + TIter next_trigger(tdir_Upsilon->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonUpsilon( f,run_dir,TriggerName ); + } + } else { + delete obj_Upsilon; + } + } + if (module_name.find("Zee")!=std::string::npos) { + TObject *obj_Zee = key_module->ReadObj(); + TDirectory *tdir_Zee = dynamic_cast<TDirectory*>(obj_Zee); + if ( tdir_Zee !=0 ) { + TIter next_trigger(tdir_Zee->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonZee( f,run_dir,TriggerName ); + } + } else { + delete obj_Zee; + } + } + if (module_name.find("Wenu")!=std::string::npos) { + TObject *obj_Wenu = key_module->ReadObj(); + TDirectory *tdir_Wenu = dynamic_cast<TDirectory*>(obj_Wenu); + if ( tdir_Wenu !=0 ) { + TIter next_trigger(tdir_Wenu->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonWenu( f,run_dir,TriggerName ); + } + } else { + delete obj_Wenu; + } + } + if (module_name.find("ZMM")!=std::string::npos) { + TObject *obj_ZMM = key_module->ReadObj(); + TDirectory *tdir_ZMM = dynamic_cast<TDirectory*>(obj_ZMM); + if ( tdir_ZMM !=0 ) { + TIter next_trigger(tdir_ZMM->GetListOfKeys()); + TKey* key_trigger(0); + while((key_trigger=dynamic_cast<TKey*>(next_trigger()))!=0) { + std::string TriggerName=key_trigger->GetName(); + // std::cout<<"Find Module: "<<module_name<<" Trigger: "<<TriggerName<<std::endl; + fitMergedFile_IDPerfMonZMM( f,run_dir,TriggerName ); + } + } else { + delete obj_ZMM; + } + } + } + } else { + delete obj_perf; + } + } + // else + //std::cerr<<"directory IDPerfMon doesn't exist !"<<std::endl; + } else { + delete obj_run; + } + } + + f->Close(); + delete f; + // std::cout << "\n"; + //std::cout << "Finish Inner-Detector performance-monitoring analysis"<<std::endl; +} + + +void +MonitoringFile:: +fitMergedFile_IDPerfMonKshort( TFile* f, std::string run_dir, std::string TriggerName ) +{ + std::string path; + path= run_dir + "IDPerfMon/Kshort/" + TriggerName; + if( f->cd(path.c_str())==0 ) { + //std::cerr << "MonitoringFile::fitMergedFile_IDPerfMonKshort(): " + //<< "No such directory \"" << path << "\"\n"; + return; + } + + Double_t myPi = TMath::Pi(); + + TH1F* m_massVPtBinFittedHistos[5]; + TH1F* m_massVRadiusBinFittedHistos[7]; + TH1F* m_massVEtaBinHistos[10]; + TH1F* m_massVPhiBinHistos[10]; + TH1F* m_massVCurvatureDiffBinHistos[6]; + + if (!CheckHistogram(f,(path+"/ks_mass").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVptBinFitted0").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVptBinFitted1").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVptBinFitted2").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVptBinFitted3").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVptBinFitted4").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVradiusBinFitted0").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVradiusBinFitted1").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVradiusBinFitted2").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVradiusBinFitted3").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVradiusBinFitted4").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVradiusBinFitted5").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVradiusBinFitted6").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin0").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin1").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin2").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin3").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin4").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin5").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin6").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin7").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin8").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVEtaBin9").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin0").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin1").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin2").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin3").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin4").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin5").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin6").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin7").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin8").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVPhiBin9").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVCurvatureDiffBin0").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVCurvatureDiffBin1").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVCurvatureDiffBin2").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVCurvatureDiffBin3").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVCurvatureDiffBin4").c_str())) return; + if (!CheckHistogram(f,(path+"/MassVCurvatureDiffBin5").c_str())) return; + + TH1F* m_mass = (TH1F*)(f->Get((path+"/ks_mass").c_str())->Clone()); + if (CheckHistogram(f,(path+"/Nevents").c_str())) { + TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); + TH1F* m_rate = new TH1F("rate","production rate",1,0,1); + double Ntot =m_Nevents->GetEntries(); + double yield = m_mass->Integral(m_mass->FindBin(0.487), m_mass->FindBin(0.507)); + double rate=yield/Ntot; + double rate_error=sqrt(1/yield+1/Ntot)*yield/Ntot; + m_rate->SetBinContent(1,rate); + m_rate->SetBinError(1,rate_error); + m_rate->Write("",TObject::kOverwrite); + } +// TH1F* m_mass_scaled = (TH1F*)(f->Get((path+"/ks_mass").c_str())->Clone("ks_mass_scaled_copy")); +// TString title(m_mass_scaled->GetTitle()); +// if (CheckHistogram(f,(path+"/ks_mass_scaled").c_str())) { +// if (CheckHistogram(f,(path+"/Nevents").c_str())) { +// TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); +// double Ntot =m_Nevents->GetEntries(); +// if (Ntot!=0.) m_mass_scaled->Scale(1./Ntot); +// m_mass_scaled->SetTitle(title+" (per event)"); +// m_mass_scaled->Write("ks_mass_scaled",TObject::kOverwrite); +// } +// } +// delete m_mass_scaled; + + m_massVPtBinFittedHistos[0] = (TH1F*)(f->Get((path+"/MassVptBinFitted0").c_str())->Clone()); + m_massVPtBinFittedHistos[1] = (TH1F*)(f->Get((path+"/MassVptBinFitted1").c_str())->Clone()); + m_massVPtBinFittedHistos[2] = (TH1F*)(f->Get((path+"/MassVptBinFitted2").c_str())->Clone()); + m_massVPtBinFittedHistos[3] = (TH1F*)(f->Get((path+"/MassVptBinFitted3").c_str())->Clone()); + m_massVPtBinFittedHistos[4] = (TH1F*)(f->Get((path+"/MassVptBinFitted4").c_str())->Clone()); + m_massVRadiusBinFittedHistos[0] = (TH1F*)(f->Get((path+"/MassVradiusBinFitted0").c_str())->Clone()); + m_massVRadiusBinFittedHistos[1] = (TH1F*)(f->Get((path+"/MassVradiusBinFitted1").c_str())->Clone()); + m_massVRadiusBinFittedHistos[2] = (TH1F*)(f->Get((path+"/MassVradiusBinFitted2").c_str())->Clone()); + m_massVRadiusBinFittedHistos[3] = (TH1F*)(f->Get((path+"/MassVradiusBinFitted3").c_str())->Clone()); + m_massVRadiusBinFittedHistos[4] = (TH1F*)(f->Get((path+"/MassVradiusBinFitted4").c_str())->Clone()); + m_massVRadiusBinFittedHistos[5] = (TH1F*)(f->Get((path+"/MassVradiusBinFitted5").c_str())->Clone()); + m_massVRadiusBinFittedHistos[6] = (TH1F*)(f->Get((path+"/MassVradiusBinFitted6").c_str())->Clone()); + m_massVEtaBinHistos[0] = (TH1F*)(f->Get((path+"/MassVEtaBin0").c_str())->Clone()); + m_massVEtaBinHistos[1] = (TH1F*)(f->Get((path+"/MassVEtaBin1").c_str())->Clone()); + m_massVEtaBinHistos[2] = (TH1F*)(f->Get((path+"/MassVEtaBin2").c_str())->Clone()); + m_massVEtaBinHistos[3] = (TH1F*)(f->Get((path+"/MassVEtaBin3").c_str())->Clone()); + m_massVEtaBinHistos[4] = (TH1F*)(f->Get((path+"/MassVEtaBin4").c_str())->Clone()); + m_massVEtaBinHistos[5] = (TH1F*)(f->Get((path+"/MassVEtaBin5").c_str())->Clone()); + m_massVEtaBinHistos[6] = (TH1F*)(f->Get((path+"/MassVEtaBin6").c_str())->Clone()); + m_massVEtaBinHistos[7] = (TH1F*)(f->Get((path+"/MassVEtaBin7").c_str())->Clone()); + m_massVEtaBinHistos[8] = (TH1F*)(f->Get((path+"/MassVEtaBin8").c_str())->Clone()); + m_massVEtaBinHistos[9] = (TH1F*)(f->Get((path+"/MassVEtaBin9").c_str())->Clone()); + m_massVPhiBinHistos[0] = (TH1F*)(f->Get((path+"/MassVPhiBin0").c_str())->Clone()); + m_massVPhiBinHistos[1] = (TH1F*)(f->Get((path+"/MassVPhiBin1").c_str())->Clone()); + m_massVPhiBinHistos[2] = (TH1F*)(f->Get((path+"/MassVPhiBin2").c_str())->Clone()); + m_massVPhiBinHistos[3] = (TH1F*)(f->Get((path+"/MassVPhiBin3").c_str())->Clone()); + m_massVPhiBinHistos[4] = (TH1F*)(f->Get((path+"/MassVPhiBin4").c_str())->Clone()); + m_massVPhiBinHistos[5] = (TH1F*)(f->Get((path+"/MassVPhiBin5").c_str())->Clone()); + m_massVPhiBinHistos[6] = (TH1F*)(f->Get((path+"/MassVPhiBin6").c_str())->Clone()); + m_massVPhiBinHistos[7] = (TH1F*)(f->Get((path+"/MassVPhiBin7").c_str())->Clone()); + m_massVPhiBinHistos[8] = (TH1F*)(f->Get((path+"/MassVPhiBin8").c_str())->Clone()); + m_massVPhiBinHistos[9] = (TH1F*)(f->Get((path+"/MassVPhiBin9").c_str())->Clone()); + m_massVCurvatureDiffBinHistos[0] = (TH1F*)(f->Get((path+"/MassVCurvatureDiffBin0").c_str())->Clone()); + m_massVCurvatureDiffBinHistos[1] = (TH1F*)(f->Get((path+"/MassVCurvatureDiffBin1").c_str())->Clone()); + m_massVCurvatureDiffBinHistos[2] = (TH1F*)(f->Get((path+"/MassVCurvatureDiffBin2").c_str())->Clone()); + m_massVCurvatureDiffBinHistos[3] = (TH1F*)(f->Get((path+"/MassVCurvatureDiffBin3").c_str())->Clone()); + m_massVCurvatureDiffBinHistos[4] = (TH1F*)(f->Get((path+"/MassVCurvatureDiffBin4").c_str())->Clone()); + m_massVCurvatureDiffBinHistos[5] = (TH1F*)(f->Get((path+"/MassVCurvatureDiffBin5").c_str())->Clone()); + + TF1 *func1 = new TF1("func1","gaus",0.460,0.540); + TF1 *func2 = new TF1("func2","expo",0.460,0.540); + TF1 *func = new TF1("func","func1+func2",0.460,0.540); + + func->SetLineColor(4); + func->SetParameters(10.,0.500,0.010,2.,-.001); + // func->SetParLimits(0,0.,10000.); + func->SetParLimits(1,0.460,0.540); + func->SetParLimits(2,0.,0.100); + func->SetParLimits(3,0.,10000.); + func->SetParLimits(4,-1000.,0.); + func->SetParNames("Constant","Mean","Sigma","Constant","Slope"); + + TCanvas *myCanvas = new TCanvas("MyCanvas"); + myCanvas->cd(); + + m_mass->Fit(func,"lmhqnr"); + + Double_t massBins[5], massErrorBins[5], widthBins[5], widthErrorBins[5]; + const Int_t nPtBinsHisto = 5+1; + Double_t ptBins[nPtBinsHisto] = {0.5,1.6,2.1,2.8,3.9,5.1}; + for(int binFill=0;binFill<5;binFill++) { + double max= m_massVPtBinFittedHistos[binFill]->GetBinContent(m_massVPtBinFittedHistos[binFill]->GetMaximumBin()); + func->SetParLimits(0,0,2*max); + m_massVPtBinFittedHistos[binFill]->Fit(func,"lmhqr"); + massBins[binFill] = func->GetParameter(1); + massErrorBins[binFill] = func->GetParError(1); + widthBins[binFill] = func->GetParameter(2); + widthErrorBins[binFill] = func->GetParError(2); + } + + const Double_t* ptBinsFinal = ptBins; + const Double_t* massBinsFinal = massBins; + const Double_t* massErrorBinsFinal = massErrorBins; + const Double_t* widthBinsFinal = widthBins; + const Double_t* widthErrorBinsFinal = widthErrorBins; + + TH1F* m_massVersusPt = new TH1F("KsMassVersusPt_Merged","",5,ptBinsFinal); + m_massVersusPt->SetXTitle("p_{T} (Gev / c)"); + m_massVersusPt->SetYTitle("Mass (Gev / c^{2})"); + m_massVersusPt->SetMarkerStyle(20); + for(int binFill=0;binFill<5;binFill++) { + Double_t binContent = massBinsFinal[binFill]; + Double_t binError = massErrorBinsFinal[binFill]; + m_massVersusPt->SetBinContent(binFill+1,binContent); + m_massVersusPt->SetBinError(binFill+1,binError); + } + + TH1F* m_widthVersusPt = new TH1F("KsWidthVersusPt_Merged","",5,ptBinsFinal); + m_widthVersusPt->SetXTitle("p_{T} (Gev / c)"); + m_widthVersusPt->SetYTitle("Width (Gev / c^{2})"); + m_widthVersusPt->SetMarkerStyle(20); + for(int binFill=0;binFill<5;binFill++) { + Double_t binContent = widthBinsFinal[binFill]; + Double_t binError = widthErrorBinsFinal[binFill]; + m_widthVersusPt->SetBinContent(binFill+1,binContent); + m_widthVersusPt->SetBinError(binFill+1,binError); + } + + Double_t massVradiusBins[7], massVradiusErrorBins[7], widthVradiusBins[7], widthVradiusErrorBins[7]; + const Int_t nRadiusBinsHisto = 7+1; + Double_t radiusBins[nRadiusBinsHisto] = {0.,30.,40.,60.,80.,100.,140.,230}; + for(int binFill=0;binFill<7;binFill++) { + double max= m_massVRadiusBinFittedHistos[binFill]->GetBinContent(m_massVRadiusBinFittedHistos[binFill]->GetMaximumBin()); + func->SetParLimits(0,0,2*max); + m_massVRadiusBinFittedHistos[binFill]->Fit(func,"lmhqr"); + massVradiusBins[binFill] = func->GetParameter(1); + massVradiusErrorBins[binFill] = func->GetParError(1); + widthVradiusBins[binFill] = func->GetParameter(2); + widthVradiusErrorBins[binFill] = func->GetParError(2); + } + + const Double_t* radiusBinsFinal = radiusBins; + const Double_t* massVradiusBinsFinal = massVradiusBins; + const Double_t* massVradiusErrorBinsFinal = massVradiusErrorBins; + const Double_t* widthVradiusBinsFinal = widthVradiusBins; + const Double_t* widthVradiusErrorBinsFinal = widthVradiusErrorBins; + + TH1F* m_massVersusRadius = new TH1F("KsMassVersusRadius_Merged","",7,radiusBinsFinal); + m_massVersusRadius->SetXTitle("Decay Radius (mm)"); + m_massVersusRadius->SetYTitle("Mass (Gev / c^{2})"); + m_massVersusRadius->SetMarkerStyle(20); + for(int binFill=0;binFill<7;binFill++) { + Double_t binContent = massVradiusBinsFinal[binFill]; + Double_t binError = massVradiusErrorBinsFinal[binFill]; + m_massVersusRadius->SetBinContent(binFill+1,binContent); + m_massVersusRadius->SetBinError(binFill+1,binError); + } + TH1F* m_widthVersusRadius = new TH1F("KsWidthVersusRadius_Merged","",7,radiusBinsFinal); + m_widthVersusRadius->SetXTitle("Decay Radius (mm)"); + m_widthVersusRadius->SetYTitle("Width (Gev / c^{2})"); + m_widthVersusRadius->SetMarkerStyle(20); + for(int binFill=0;binFill<7;binFill++) { + Double_t binContent = widthVradiusBinsFinal[binFill]; + Double_t binError = widthVradiusErrorBinsFinal[binFill]; + m_widthVersusRadius->SetBinContent(binFill+1,binContent); + m_widthVersusRadius->SetBinError(binFill+1,binError); + } + + Double_t etaBins[11] = {-2.5,-2.0,-1.5,-1.0,-0.5,0.0,0.5,1.0,1.5,2.0,2.5}; + Double_t massVetaBins[10], massVetaErrorBins[10], widthVetaBins[10], widthVetaErrorBins[10]; + for(int binFill=0;binFill<10;binFill++) { + double max= m_massVEtaBinHistos[binFill]->GetBinContent(m_massVEtaBinHistos[binFill]->GetMaximumBin()); + func->SetParLimits(0,0,2*max); + m_massVEtaBinHistos[binFill]->Fit(func,"lmhqr"); + massVetaBins[binFill] = func->GetParameter(1); + massVetaErrorBins[binFill] = func->GetParError(1); + widthVetaBins[binFill] = func->GetParameter(2); + widthVetaErrorBins[binFill] = func->GetParError(2); + } + TH1F* m_massVersusEta = new TH1F("KsMassVersusEta_Merged","",10,etaBins); + m_massVersusEta->SetXTitle("#eta"); + m_massVersusEta->SetYTitle("Mass (Gev / c^{2})"); + m_massVersusEta->SetMarkerStyle(20); + for(int binFill=0;binFill<10;binFill++) { + Double_t binContent = massVetaBins[binFill]; + Double_t binError = massVetaErrorBins[binFill]; + m_massVersusEta->SetBinContent(binFill+1,binContent); + m_massVersusEta->SetBinError(binFill+1,binError); + } + TH1F* m_widthVersusEta = new TH1F("KsWidthVersusEta_Merged","",10,etaBins); + m_widthVersusEta->SetXTitle("#eta"); + m_widthVersusEta->SetYTitle("Width (Gev / c^{2})"); + m_widthVersusEta->SetMarkerStyle(20); + for(int binFill=0;binFill<10;binFill++) { + Double_t binContent = widthVetaBins[binFill]; + Double_t binError = widthVetaErrorBins[binFill]; + m_widthVersusEta->SetBinContent(binFill+1,binContent); + m_widthVersusEta->SetBinError(binFill+1,binError); + } + + Double_t phiBins[11] = { (-5.0*myPi / 5) , + (-4.0*myPi / 5) , + (-3.0*myPi / 5) , + (-2.0*myPi / 5) , + (-1.0*myPi / 5) , + (0.0*myPi / 5) , + (1.0*myPi / 5) , + (2.0*myPi / 5) , + (3.0*myPi / 5) , + (4.0*myPi / 5) , + (5.0*myPi / 5) }; + Double_t massVphiBins[10], massVphiErrorBins[10], widthVphiBins[10], widthVphiErrorBins[10]; + for(int binFill=0;binFill<10;binFill++) { + double max= m_massVPhiBinHistos[binFill]->GetBinContent(m_massVPhiBinHistos[binFill]->GetMaximumBin()); + func->SetParLimits(0,0,2*max); + m_massVPhiBinHistos[binFill]->Fit(func,"lmhqr"); + massVphiBins[binFill] = func->GetParameter(1); + massVphiErrorBins[binFill] = func->GetParError(1); + widthVphiBins[binFill] = func->GetParameter(2); + widthVphiErrorBins[binFill] = func->GetParError(2); + } + TH1F* m_massVersusPhi = new TH1F("KsMassVersusPhi_Merged","",10,phiBins); + m_massVersusPhi->SetXTitle("#phi"); + m_massVersusPhi->SetYTitle("Mass (Gev / c^{2})"); + m_massVersusPhi->SetMarkerStyle(20); + for(int binFill=0;binFill<10;binFill++) { + Double_t binContent = massVphiBins[binFill]; + Double_t binError = massVphiErrorBins[binFill]; + m_massVersusPhi->SetBinContent(binFill+1,binContent); + m_massVersusPhi->SetBinError(binFill+1,binError); + } + TH1F* m_widthVersusPhi = new TH1F("KsWidthVersusPhi_Merged","",10,phiBins); + m_widthVersusPhi->SetXTitle("#phi"); + m_widthVersusPhi->SetYTitle("Width (Gev / c^{2})"); + m_widthVersusPhi->SetMarkerStyle(20); + for(int binFill=0;binFill<10;binFill++) { + Double_t binContent = widthVphiBins[binFill]; + Double_t binError = widthVphiErrorBins[binFill]; + m_widthVersusPhi->SetBinContent(binFill+1,binContent); + m_widthVersusPhi->SetBinError(binFill+1,binError); + } + + Double_t curvatureDiffBins[7] = {-0.0012,-0.0008,-0.0004,0.0000,0.0004,0.0008,0.0012}; + Double_t massVcurvatureDiffBins[6], massVcurvatureDiffErrorBins[6], widthVcurvatureDiffBins[6], widthVcurvatureDiffErrorBins[6]; + for(int binFill=0;binFill<6;binFill++) { + double max= m_massVCurvatureDiffBinHistos[binFill]->GetBinContent(m_massVCurvatureDiffBinHistos[binFill]->GetMaximumBin()); + func->SetParLimits(0,0,2*max); + m_massVCurvatureDiffBinHistos[binFill]->Fit(func,"lmhqr"); + massVcurvatureDiffBins[binFill] = func->GetParameter(1); + massVcurvatureDiffErrorBins[binFill] = func->GetParError(1); + widthVcurvatureDiffBins[binFill] = func->GetParameter(2); + widthVcurvatureDiffErrorBins[binFill] = func->GetParError(2); + } + TH1F* m_massVersusCurvatureDiff = new TH1F("KsMassVersusCurvatureDiff_Merged","",6,curvatureDiffBins); + m_massVersusCurvatureDiff->SetXTitle("1/p_{T}(#pi^{+}) - 1/p_{T}(#pi^{-}) [GeV^{-1}]"); + m_massVersusCurvatureDiff->SetYTitle("Mass (Gev / c^{2})"); + m_massVersusCurvatureDiff->SetMarkerStyle(20); + for(int binFill=0;binFill<6;binFill++) { + Double_t binContent = massVcurvatureDiffBins[binFill]; + Double_t binError = massVcurvatureDiffErrorBins[binFill]; + m_massVersusCurvatureDiff->SetBinContent(binFill+1,binContent); + m_massVersusCurvatureDiff->SetBinError(binFill+1,binError); + } + TH1F* m_widthVersusCurvatureDiff = new TH1F("KsWidthVersusCurvatureDiff_Merged","",6,curvatureDiffBins); + m_widthVersusCurvatureDiff->SetXTitle("1/p_{T}(#pi^{+}) - 1/p_{T}(#pi^{-}) [GeV^{-1}]"); + m_widthVersusCurvatureDiff->SetYTitle("Width (Gev / c^{2})"); + m_widthVersusCurvatureDiff->SetMarkerStyle(20); + for(int binFill=0;binFill<6;binFill++) { + Double_t binContent = widthVcurvatureDiffBins[binFill]; + Double_t binError = widthVcurvatureDiffErrorBins[binFill]; + m_widthVersusCurvatureDiff->SetBinContent(binFill+1,binContent); + m_widthVersusCurvatureDiff->SetBinError(binFill+1,binError); + } + + if( f->cd(path.c_str())==0 ) { + //std::cerr << "MonitoringFile::fitMergedFile_IDPerfMonKshort(): " + //<< "No such directory \"" << path << "\"\n"; + return; + } + + // f->cd(path.c_str()); + + m_mass->Write("",TObject::kOverwrite); + + m_massVPtBinFittedHistos[0]->Write("",TObject::kOverwrite); + m_massVPtBinFittedHistos[1]->Write("",TObject::kOverwrite); + m_massVPtBinFittedHistos[2]->Write("",TObject::kOverwrite); + m_massVPtBinFittedHistos[3]->Write("",TObject::kOverwrite); + m_massVPtBinFittedHistos[4]->Write("",TObject::kOverwrite); + m_massVRadiusBinFittedHistos[0]->Write("",TObject::kOverwrite); + m_massVRadiusBinFittedHistos[1]->Write("",TObject::kOverwrite); + m_massVRadiusBinFittedHistos[2]->Write("",TObject::kOverwrite); + m_massVRadiusBinFittedHistos[3]->Write("",TObject::kOverwrite); + m_massVRadiusBinFittedHistos[4]->Write("",TObject::kOverwrite); + m_massVRadiusBinFittedHistos[5]->Write("",TObject::kOverwrite); + m_massVRadiusBinFittedHistos[6]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[0]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[1]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[2]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[3]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[4]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[5]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[6]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[7]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[8]->Write("",TObject::kOverwrite); + m_massVEtaBinHistos[9]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[0]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[1]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[2]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[3]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[4]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[5]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[6]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[7]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[8]->Write("",TObject::kOverwrite); + m_massVPhiBinHistos[9]->Write("",TObject::kOverwrite); + m_massVCurvatureDiffBinHistos[0]->Write("",TObject::kOverwrite); + m_massVCurvatureDiffBinHistos[1]->Write("",TObject::kOverwrite); + m_massVCurvatureDiffBinHistos[2]->Write("",TObject::kOverwrite); + m_massVCurvatureDiffBinHistos[3]->Write("",TObject::kOverwrite); + m_massVCurvatureDiffBinHistos[4]->Write("",TObject::kOverwrite); + m_massVCurvatureDiffBinHistos[5]->Write("",TObject::kOverwrite); + + m_massVersusPt->Write("",TObject::kOverwrite); + m_widthVersusPt->Write("",TObject::kOverwrite); + m_massVersusRadius->Write("",TObject::kOverwrite); + m_widthVersusRadius->Write("",TObject::kOverwrite); + m_massVersusEta->Write("",TObject::kOverwrite); + m_widthVersusEta->Write("",TObject::kOverwrite); + m_massVersusPhi->Write("",TObject::kOverwrite); + m_widthVersusPhi->Write("",TObject::kOverwrite); + m_massVersusCurvatureDiff->Write("",TObject::kOverwrite); + m_widthVersusCurvatureDiff->Write("",TObject::kOverwrite); + + myCanvas->Close(); + delete myCanvas; + + f->Write(); + + delete func; + delete func1; + delete func2; +} + + +//Jpsi plots merging +void +MonitoringFile:: +fitMergedFile_IDPerfMonJpsi( TFile* f, std::string run_dir, std::string TriggerName ) +{ + std::string path; + path= run_dir+"IDPerfMon/Jpsi/"+TriggerName; + + if( f->cd(path.c_str())==0 ) { + //std::cerr//<< "MonitoringFile::fitMergedFile_IDPerfMonJpsi(): " + //<<"No such directory \""<< path << "\"\n"; + return; + } + + TH1F* m_jpsi_invmass_vs_pt = new TH1F("Jpsi_invmass_vs_pt","Jpsi invmass-PDGmass vs. Jpsi Pt; p_{T}(J/#psi) [GeV/c]; Mass Shift [GeV/c^{2}]", 6 ,10.,20.); + TH1F* m_jpsi_invmass_vs_z0 = new TH1F("Jpsi_invmass_vs_z0","Jpsi invmass-PDGmass vs. muon z0; z0(#mu) [mm]; Mass Shift [GeV/c^{2}]", 6,-100.,100.); + TH1F* m_jpsi_invmass_vs_phi = new TH1F("Jpsi_invmass_vs_phi","Jpsi invmass-PDGmass vs. Jpsi phi; #phi(J/#psi) [rad]; Mass Shift [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_jpsi_invmass_vs_phiplus = new TH1F("Jpsi_invmass_vs_phiplus","Jpsi invmass-PDGmass vs. Muon+ phi; #phi(#mu^{+}) [rad]; Mass Shift [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_jpsi_invmass_vs_phiminus = new TH1F("Jpsi_invmass_vs_phiminus","Jpsi invmass-PDGmass vs. Muon- phi; #phi(#mu^{-}) [rad]; Mass Shift [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_jpsi_invmass_vs_phidiff=new TH1F("Jpsi_invmass_vs_phidiff","Jpsi invmass-PDGmass vs. |phi(+)-phi(-)|; |#phi(#mu^{+})-#phi(#mu^{-})| [rad]; Mass Shift [GeV/c^{2}]", 6, 0., 0.4); + TH1F* m_jpsi_invmass_vs_phisum = new TH1F("Jpsi_invmass_vs_phisum","Jpsi invmass-PDGmass vs. phi(+)+phi(-);#phi(#mu^{+})+#phi(#mu^{-}) [rad];Mass Shift [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_jpsi_invmass_vs_eta = new TH1F("Jpsi_invmass_vs_eta","Jpsi invmass-PDGmass vs. Jpsi eta; #eta(J/#psi); Mass Shift [GeV/c^{2}]", 6, -2.4, 2.4); + TH1F* m_jpsi_invmass_vs_eta_barrel = new TH1F("Jpsi_invmass_vs_eta_barrel","Jpsi invmass-PDGmass vs. Jpsi eta (barrel); #eta(J/#psi); Mass Shift [GeV/c^{2}]", 2, -0.8, 0.8); + TH1F* m_jpsi_invmass_vs_eta_ecc = new TH1F("Jpsi_invmass_vs_eta_ecc","Jpsi invmass-PDGmass vs. Jpsi eta (endcap C); #eta(J/#psi); Mass Shift [GeV/c^{2}]", 2, -2.4, -0.8); + TH1F* m_jpsi_invmass_vs_eta_eca = new TH1F("Jpsi_invmass_vs_eta_eca","Jpsi invmass-PDGmass vs. Jpsi eta (endcap A); #eta(J/#psi); Mass Shift [GeV/c^{2}]", 2, 0.8, 2.4); + TH1F* m_jpsi_invmass_vs_etaplus= new TH1F("Jpsi_invmass_vs_etaplus","Jpsi invmass-PDGmass vs. Muon+ eta; #eta(#mu^{+}); Mass Shift [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_jpsi_invmass_vs_etaminus= new TH1F("Jpsi_invmass_vs_etaminus","Jpsi invmass-PDGmass vs. Muon- eta; #eta(#mu^{-}); Mass Shift [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_jpsi_invmass_vs_maxeta= new TH1F("Jpsi_invmass_vs_maxeta","Jpsi invmass-PDGmass vs. max Muon |eta|; max|#eta(#mu)|; Mass Shift [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_jpsi_invmass_vs_etadiff = new TH1F("Jpsi_invmass_vs_etadiff","Jpsi invmass-PDGmass vs. eta(+)-eta(-); #eta(#mu^{+})-#eta(#mu^{-}); Mass Shift [GeV/c^{2}]", 6,-0.5,0.5); + TH1F* m_jpsi_invmass_vs_sumeta= new TH1F("Jpsi_invmass_vs_sumeta","Jpsi invmass-PDGmass vs. eta(+)+eta(-); #eta(#mu^{+})+#eta(#mu^{-});Mass Shift [GeV/c^{2}]", 6,-4.8,4.8); + TH1F* m_jpsi_invmass_vs_sumabseta= new TH1F("Jpsi_invmass_vs_sumabseta","Jpsi invmass-PDGmass vs. |eta(+)|+|eta(-)|;|#eta(#mu^{+})|+|#eta(#mu^{-})|;Mass Shift [GeV/c^{2}]", 6,0.,4.8); + TH1F* m_jpsi_invmass_vs_crt= new TH1F("Jpsi_invmass_vs_curvature","Jpsi invmass-PDGmass vs. crt(+)-|crt(-)|; 1/p_{T}(#mu^{+})-1/p_{T}(#mu^{-}) [GeV^{-1}]; Mass Shift [GeV/c^{2}]",6, -0.15, 0.15); + TH1F* m_jpsi_invmass_vs_invpt=new TH1F("Jpsi_invmass_vs_invpt","Jpsi invmass-PDGmass vs. muon 1/Pt; 1/p_{T}(#mu) [(GeV/c)^{-1}]; Mass Shift [GeV/c^{2}]",6,0.05,0.25); + TH1F* m_jpsi_invmass_vs_angle_eta=new TH1F("Jpsi_invmass_vs_angle_eta","Jpsi invmass-PDGmass vs. arccos(#Delta#eta/#DeltaR);arccos(#Delta#eta/#DeltaR); Mass Shift [GeV/c^{2}]",6,0.,90.); + + TH1F* m_jpsi_width_vs_pt = new TH1F("Jpsi_width_vs_pt","Jpsi width vs. Jpsi Pt; p_{T}(J/#psi) [GeV/c]; Width [GeV/c^{2}]", 6 ,10.,20.); + TH1F* m_jpsi_width_vs_z0 = new TH1F("Jpsi_width_vs_z0","Jpsi width vs. muon z0; z0(#mu) [mm]; Width [GeV/c^{2}]", 6,-100.,100.); + TH1F* m_jpsi_width_vs_phi = new TH1F("Jpsi_width_vs_phi","Jpsi width vs. Jpsi phi; #phi(J/#psi) [rad]; Width [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_jpsi_width_vs_phiplus = new TH1F("Jpsi_width_vs_phiplus","Jpsi width vs. Muon+ phi; #phi(#mu^{+}) [rad]; Width [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_jpsi_width_vs_phiminus = new TH1F("Jpsi_width_vs_phiminus","Jpsi width vs. Muon- phi; #phi(#mu^{-}) [rad]; Width [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_jpsi_width_vs_phidiff=new TH1F("Jpsi_width_vs_phidiff","Jpsi width vs. |phi(+)-phi(-)|; |#phi(#mu^{+})-#phi(#mu^{-})| [rad]; Width [GeV/c^{2}]", 6, 0., 0.4); + TH1F* m_jpsi_width_vs_phisum = new TH1F("Jpsi_width_vs_phisum","Jpsi width vs. phi(+)+phi(-);#phi(#mu^{+})+#phi(#mu^{-}) [rad];Width [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_jpsi_width_vs_eta = new TH1F("Jpsi_width_vs_eta","Jpsi width vs. Jpsi eta; #eta(J/#psi); Width[GeV/c^{2}]", 6, -2.4, 2.4); + TH1F* m_jpsi_width_vs_eta_barrel = new TH1F("Jpsi_width_vs_eta_barrel","Jpsi width vs. Jpsi eta (barrel); #eta(J/#psi); Width [GeV/c^{2}]", 2, -0.8, 0.8); + TH1F* m_jpsi_width_vs_eta_ecc = new TH1F("Jpsi_width_vs_eta_ecc","Jpsi width vs. Jpsi eta (endcap C); #eta(J/#psi); Width [GeV/c^{2}]", 2, -2.4, -0.8); + TH1F* m_jpsi_width_vs_eta_eca = new TH1F("Jpsi_width_vs_eta_eca","Jpsi width vs. Jpsi eta (endcap A); #eta(J/#psi); Width [GeV/c^{2}]", 2, 0.8, 2.4); + TH1F* m_jpsi_width_vs_etaplus= new TH1F("Jpsi_width_vs_etaplus","Jpsi width vs. Muon+ eta; #eta(#mu^{+}); Width [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_jpsi_width_vs_etaminus= new TH1F("Jpsi_width_vs_etaminus","Jpsi width vs. Muon- eta; #eta(#mu^{-}); Width [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_jpsi_width_vs_maxeta= new TH1F("Jpsi_width_vs_maxeta","Jpsi width vs. max Muon |eta|; max|#eta(#mu)|; Width[GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_jpsi_width_vs_etadiff = new TH1F("Jpsi_width_vs_etadiff","Jpsi width vs. eta(+)-eta(-); #eta(#mu^{+})-#eta(#mu^{-}); Width [GeV/c^{2}]", 6,-0.5,0.5); + TH1F* m_jpsi_width_vs_sumeta= new TH1F("Jpsi_width_vs_sumeta","Jpsi width vs. eta(+)+eta(-); #eta(#mu^{+})+#eta(#mu^{-});Width [GeV/c^{2}]", 6,-4.8,4.8); + TH1F* m_jpsi_width_vs_sumabseta= new TH1F("Jpsi_width_vs_sumabseta","Jpsi width vs. |eta(+)|+|eta(-)|;|#eta(#mu^{+})|+|#eta(#mu^{-})|;Width [GeV/c^{2}]", 6,0.,4.8); + TH1F* m_jpsi_width_vs_crt= new TH1F("Jpsi_width_vs_curvature","Jpsi width vs. crt(+)-|crt(-)|; 1/p_{T}(#mu^{+})-1/p_{T}(#mu^{-}) [GeV^{-1}]; Width [GeV/c^{2}]",6, -0.15, 0.15); + TH1F* m_jpsi_width_vs_invpt=new TH1F("Jpsi_width_vs_invpt","Jpsi width vs. muon 1/Pt; 1/p_{T}(#mu) [(GeV/c)^{-1}]; Width [GeV/c^{2}]",6,0.05,0.25); + TH1F* m_jpsi_width_vs_angle_eta=new TH1F("Jpsi_width_vs_angle_eta","Jpsi width vs. arccos(#Delta#eta/#DeltaR);arccos(#Delta#eta/#DeltaR); Width [GeV/c^{2}]",6,0.,90.); + + TH1F* m_eff_pt = new TH1F("eff_pt","ID tracking efficiency vs p_{T} (tag-and-probe);p_{T} [GeV]",9, 2., 20.); + TH1F* m_eff_eta = new TH1F("eff_eta","ID tracking efficiency vs #eta (tag-and-probe);#eta",10, -2.5, 2.5); + TH1F* m_eff_phi = new TH1F("eff_phi","ID tracking efficiency vs #phi (tag-and-probe);#phi [rad]",8, -3.15, 3.15); + + TH1F* m_chargeasym_vs_pt = new TH1F("chargeAsym_vs_pt","Charge asymmetry vs. p_{T};p_{T}(#mu) [GeV];#frac{N^{-}-N^{+}}{N^{-}+N^{+}}",10,0.,20.); + + const int nbins=6; + TH1F* hpt[nbins]; + TH1F* hz0[nbins]; + TH1F* hphi[nbins]; + TH1F* hphiplus[nbins]; + TH1F* hphiminus[nbins]; + TH1F* hphidiff[nbins]; + TH1F* heta[nbins]; + TH1F* heta_b[2]; + TH1F* heta_ecc[2]; + TH1F* heta_eca[2]; + TH1F* hetadiff[nbins]; + TH1F* hmaxeta[nbins]; + TH1F* hinvpt[nbins]; + TH1F* hcrt[nbins]; + TH1F* hetaplus[nbins]; + TH1F* hetaminus[nbins]; + TH1F* hangle_eta[nbins]; + TH1F* hsumphi[nbins]; + TH1F* hsumeta[nbins]; + TH1F* hsumabseta[nbins]; + + if (!CheckHistogram( f,(path+"/Jpsi_invmass").c_str())) return; + TH1F* m_mass = (TH1F*)(f->Get((path+"/Jpsi_invmass").c_str())->Clone()); + if (CheckHistogram(f,(path+"/Nevents").c_str())) { + TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); + TH1F* m_rate = new TH1F("rate","production rate",1,0,1); + double Ntot =m_Nevents->GetEntries(); + double yield = m_mass->Integral(m_mass->FindBin(2.95), m_mass->FindBin(3.25)); + double rate=yield/Ntot; + double rate_error=sqrt(1/yield+1/Ntot)*yield/Ntot; + m_rate->SetBinContent(1,rate); + m_rate->SetBinError(1,rate_error); + m_rate->Write("",TObject::kOverwrite); + } +// TH1F* m_mass_scaled = (TH1F*)(f->Get((path+"/Jpsi_invmass").c_str())->Clone("Jpsi_invmass_scaled_copy")); +// m_mass_scaled->SetMarkerStyle(21); +// TString title(m_mass_scaled->GetTitle()); +// if (CheckHistogram(f,(path+"/Jpsi_invmass_scaled").c_str())) { +// if (CheckHistogram(f,(path+"/Nevents").c_str())) { +// TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); +// double Ntot =m_Nevents->GetEntries(); +// if (Ntot!=0.) m_mass_scaled->Scale(1./Ntot); +// m_mass_scaled->SetTitle(title+" (per event)"); +// m_mass_scaled->Write("Jpsi_invmass_scaled",TObject::kOverwrite); +// } +// } +// delete m_mass_scaled; + if (CheckHistogram( f,(path+"/Jpsi_invmass").c_str())) { + TH1F* m_mass_rebin = (TH1F*)(f->Get((path+"/Jpsi_invmass").c_str())->Clone("Jpsi_invmass_rebin")); + TString title = m_mass_rebin->GetTitle(); + m_mass_rebin ->SetMarkerStyle(21); + m_mass_rebin->Rebin(2); + m_mass_rebin->SetTitle(title+" (larger binning for low Stats.)"); + m_mass_rebin->Write("Jpsi_invmass_rebin",TObject::kOverwrite); + } + + if (!CheckHistogram( f,(path+"/probe_all_pt").c_str())) return; + TH1F* m_probe_all_pt = (TH1F*)(f->Get((path+"/probe_all_pt").c_str())->Clone()); + if (!CheckHistogram( f,(path+"/probe_match_pt").c_str())) return; + TH1F* m_probe_match_pt = (TH1F*)(f->Get((path+"/probe_match_pt").c_str())->Clone()); + if (!CheckHistogram( f,(path+"/probe_all_eta").c_str())) return; + TH1F* m_probe_all_eta = (TH1F*)(f->Get((path+"/probe_all_eta").c_str())->Clone()); + if (!CheckHistogram( f,(path+"/probe_match_eta").c_str())) return; + TH1F* m_probe_match_eta = (TH1F*)(f->Get((path+"/probe_match_eta").c_str())->Clone()); + if (!CheckHistogram( f,(path+"/probe_all_phi").c_str())) return; + TH1F* m_probe_all_phi = (TH1F*)(f->Get((path+"/probe_all_phi").c_str())->Clone()); + if (!CheckHistogram( f,(path+"/probe_match_phi").c_str())) return; + TH1F* m_probe_match_phi = (TH1F*)(f->Get((path+"/probe_match_phi").c_str())->Clone()); + if (!CheckHistogram( f,(path+"/Muonplus_pt").c_str())) return; + TH1F* m_ptplus = (TH1F*)(f->Get((path+"/Muonplus_pt").c_str())->Clone()); + if (!CheckHistogram( f,(path+"/Muonminus_pt").c_str())) return; + TH1F* m_ptminus = (TH1F*)(f->Get((path+"/Muonminus_pt").c_str())->Clone()); + + char cpt[100],cz0[100],cphi[100],cphidiff[100],ceta[100],cetadiff[100],cmaxeta[100],ccrt[100],cinvpt[100],cphiplus[100],cphiminus[100],cetaplus[100],cetaminus[100],ceta_b[100],ceta_ecc[100],ceta_eca[100],cangle_eta[100],csumeta[100],csumabseta[100],csumphi[100]; + for (int i=0;i<nbins;i++) + { + + sprintf(cpt,(path+"/pt_bin%d").c_str(),i); + sprintf(cz0,(path+"/z0_bin%d").c_str(),i); + sprintf(cphi,(path+"/phi_bin%d").c_str(),i); + sprintf(cphiplus,(path+"/phiplus_bin%d").c_str(),i); + sprintf(cphiminus,(path+"/phiminus_bin%d").c_str(),i); + sprintf(cphidiff,(path+"/phidiff_bin%d").c_str(),i); + sprintf(ceta,(path+"/eta_bin%d").c_str(),i); + sprintf(cetaplus,(path+"/etaplus_bin%d").c_str(),i); + sprintf(cetaminus,(path+"/etaminus_bin%d").c_str(),i); + sprintf(cmaxeta,(path+"/maxeta_bin%d").c_str(),i); + sprintf(cetadiff,(path+"/etadiff_bin%d").c_str(),i); + sprintf(ccrt,(path+"/crt_bin%d").c_str(),i); + sprintf(cinvpt,(path+"/invpt_bin%d").c_str(),i); + sprintf(cangle_eta,(path+"/angle_eta_bin%d").c_str(),i); + sprintf(csumphi,(path+"/phi_sum%d").c_str(),i); + sprintf(csumeta,(path+"/eta_sum%d").c_str(),i); + sprintf(csumabseta,(path+"/eta_AbsSum%d").c_str(),i); + + if (!CheckHistogram(f,cpt)) return; + if (!CheckHistogram(f,cz0)) return; + if (!CheckHistogram(f,cphi)) return; + if (!CheckHistogram(f,cphiplus)) return; + if (!CheckHistogram(f,cphiminus)) return; + if (!CheckHistogram(f,cphidiff)) return; + if (!CheckHistogram(f,ceta)) return; + if (!CheckHistogram(f,cetaplus)) return; + if (!CheckHistogram(f,cetaminus)) return; + if (!CheckHistogram(f,cmaxeta)) return; + if (!CheckHistogram(f,cetadiff)) return; + if (!CheckHistogram(f,ccrt)) return; + if (!CheckHistogram(f,cinvpt)) return; + if (!CheckHistogram(f,cangle_eta)) return; + if (!CheckHistogram(f,csumphi)) return; + if (!CheckHistogram(f,csumeta)) return; + if (!CheckHistogram(f,csumabseta)) return; + + hpt[i] =(TH1F*)(f->Get(cpt)->Clone()); + hz0[i] =(TH1F*)(f->Get(cz0)->Clone()); + hphi[i]=(TH1F*)(f->Get(cphi)->Clone()); + hphiplus[i]=(TH1F*)(f->Get(cphiplus)->Clone()); + hphiminus[i]=(TH1F*)(f->Get(cphiminus)->Clone()); + hphidiff[i]=(TH1F*)(f->Get(cphidiff)->Clone()); + heta[i]=(TH1F*)(f->Get(ceta)->Clone()); + hetaplus[i]=(TH1F*)(f->Get(cetaplus)->Clone()); + hetaminus[i]=(TH1F*)(f->Get(cetaminus)->Clone()); + hetadiff[i]=(TH1F*)(f->Get(cetadiff)->Clone()); + hmaxeta[i]=(TH1F*)(f->Get(cmaxeta)->Clone()); + hcrt[i] = (TH1F*)(f->Get(ccrt)->Clone()); + hinvpt[i] =(TH1F*)(f->Get(cinvpt)->Clone()); + hangle_eta[i]=(TH1F*)(f->Get(cangle_eta)->Clone()); + hsumphi[i]=(TH1F*)(f->Get(csumphi)->Clone()); + hsumeta[i]=(TH1F*)(f->Get(csumeta)->Clone()); + hsumabseta[i]=(TH1F*)(f->Get(csumabseta)->Clone()); + + if (i<2) { + sprintf(ceta_b,(path+"/eta_b_bin%d").c_str(),i); + sprintf(ceta_eca,(path+"/eta_eca_bin%d").c_str(),i); + sprintf(ceta_ecc,(path+"/eta_ecc_bin%d").c_str(),i); + if (!CheckHistogram(f,ceta_b)) return; + if (!CheckHistogram(f,ceta_eca)) return; + if (!CheckHistogram(f,ceta_ecc)) return; + heta_b[i]=(TH1F*)(f->Get(ceta_b)->Clone()); + heta_ecc[i]=(TH1F*)(f->Get(ceta_ecc)->Clone()); + heta_eca[i]=(TH1F*)(f->Get(ceta_eca)->Clone()); + } + } + m_mass->SetMarkerStyle(21); + + TCanvas *myCanvas = new TCanvas("MyCanvas"); + myCanvas->cd(); + +// m_mass->Fit(f1,"RQMN"); + + fitJpsiHistograms(m_jpsi_invmass_vs_pt,m_jpsi_width_vs_pt,hpt,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_z0,m_jpsi_width_vs_z0,hz0,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_phi,m_jpsi_width_vs_phi,hphi,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_phiplus,m_jpsi_width_vs_phiplus,hphiplus,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_phiminus,m_jpsi_width_vs_phiminus,hphiminus,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_phidiff,m_jpsi_width_vs_phidiff,hphidiff,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_eta,m_jpsi_width_vs_eta,heta,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_etaplus,m_jpsi_width_vs_etaplus,hetaplus,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_etaminus,m_jpsi_width_vs_etaminus,hetaminus,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_maxeta,m_jpsi_width_vs_maxeta,hmaxeta,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_etadiff,m_jpsi_width_vs_etadiff,hetadiff,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_crt,m_jpsi_width_vs_crt,hcrt,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_invpt,m_jpsi_width_vs_invpt,hinvpt,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_eta_barrel,m_jpsi_width_vs_eta_barrel,heta_b,2); + fitJpsiHistograms(m_jpsi_invmass_vs_eta_eca,m_jpsi_width_vs_eta_eca,heta_eca,2); + fitJpsiHistograms(m_jpsi_invmass_vs_eta_ecc,m_jpsi_width_vs_eta_ecc,heta_ecc,2); + fitJpsiHistograms(m_jpsi_invmass_vs_angle_eta,m_jpsi_width_vs_angle_eta,hangle_eta,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_phisum,m_jpsi_width_vs_phisum,hsumphi,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_sumeta,m_jpsi_width_vs_sumeta,hsumeta,nbins); + fitJpsiHistograms(m_jpsi_invmass_vs_sumabseta,m_jpsi_width_vs_sumabseta,hsumabseta,nbins); + if (m_eff_pt->GetNbinsX()==m_probe_match_pt->GetNbinsX()) + { + m_eff_pt->SetMarkerStyle(21); + m_eff_eta->SetMarkerStyle(21); + m_eff_phi->SetMarkerStyle(21); + m_eff_pt->Divide(m_probe_match_pt,m_probe_all_pt,1,1,"B"); + m_eff_eta->Divide(m_probe_match_eta,m_probe_all_eta,1,1,"B"); + m_eff_phi->Divide(m_probe_match_phi,m_probe_all_phi,1,1,"B"); + } + ProcessAsymHistograms(m_ptminus,m_ptplus,m_chargeasym_vs_pt); + m_chargeasym_vs_pt->Write("",TObject::kOverwrite); + + // f->cd(path.c_str()); + if( f->cd(path.c_str())==0 ) { + //std::cerr<< "MonitoringFile::fitMergedFile_IDPerfMonJpsi(): " + //<<"No such directory \""<< path << "\"\n"; + return; + } + + m_mass->Write("",TObject::kOverwrite); + for (int i=0; i<nbins;i++) + { + hpt[i]->Write("",TObject::kOverwrite); + hz0[i]->Write("",TObject::kOverwrite); + hphi[i]->Write("",TObject::kOverwrite); + hphiplus[i]->Write("",TObject::kOverwrite); + hphiminus[i]->Write("",TObject::kOverwrite); + hphidiff[i]->Write("",TObject::kOverwrite); + heta[i]->Write("",TObject::kOverwrite); + hetadiff[i]->Write("",TObject::kOverwrite); + hmaxeta[i]->Write("",TObject::kOverwrite); + hinvpt[i]->Write("",TObject::kOverwrite); + hcrt[i]->Write("",TObject::kOverwrite); + hetaplus[i]->Write("",TObject::kOverwrite); + hetaminus[i]->Write("",TObject::kOverwrite); + hangle_eta[i]->Write("",TObject::kOverwrite); + hsumphi[i]->Write("",TObject::kOverwrite); + hsumeta[i]->Write("",TObject::kOverwrite); + hsumabseta[i]->Write("",TObject::kOverwrite); + if (i<2) { + heta_b[i]->Write("",TObject::kOverwrite); + heta_ecc[i]->Write("",TObject::kOverwrite); + heta_eca[i]->Write("",TObject::kOverwrite); + } + } + + m_jpsi_invmass_vs_pt->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_z0->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_phi->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_phiplus->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_phiminus->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_phidiff->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_eta->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_eta_barrel->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_eta_ecc->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_eta_eca->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_etadiff->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_etaplus->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_etaminus->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_maxeta->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_crt->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_invpt->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_angle_eta->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_phisum->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_sumeta->Write("",TObject::kOverwrite); + m_jpsi_invmass_vs_sumabseta->Write("",TObject::kOverwrite); + + m_jpsi_width_vs_pt->Write("",TObject::kOverwrite); + m_jpsi_width_vs_z0->Write("",TObject::kOverwrite); + m_jpsi_width_vs_phi->Write("",TObject::kOverwrite); + m_jpsi_width_vs_phiplus->Write("",TObject::kOverwrite); + m_jpsi_width_vs_phiminus->Write("",TObject::kOverwrite); + m_jpsi_width_vs_phidiff->Write("",TObject::kOverwrite); + m_jpsi_width_vs_eta->Write("",TObject::kOverwrite); + m_jpsi_width_vs_eta_barrel->Write("",TObject::kOverwrite); + m_jpsi_width_vs_eta_ecc->Write("",TObject::kOverwrite); + m_jpsi_width_vs_eta_eca->Write("",TObject::kOverwrite); + m_jpsi_width_vs_etadiff->Write("",TObject::kOverwrite); + m_jpsi_width_vs_etaplus->Write("",TObject::kOverwrite); + m_jpsi_width_vs_etaminus->Write("",TObject::kOverwrite); + m_jpsi_width_vs_maxeta->Write("",TObject::kOverwrite); + m_jpsi_width_vs_crt->Write("",TObject::kOverwrite); + m_jpsi_width_vs_invpt->Write("",TObject::kOverwrite); + m_jpsi_width_vs_angle_eta->Write("",TObject::kOverwrite); + m_jpsi_width_vs_phisum->Write("",TObject::kOverwrite); + m_jpsi_width_vs_sumeta->Write("",TObject::kOverwrite); + m_jpsi_width_vs_sumabseta->Write("",TObject::kOverwrite); + + m_eff_pt->Write("",TObject::kOverwrite); + m_eff_eta->Write("",TObject::kOverwrite); + m_eff_phi->Write("",TObject::kOverwrite); + + + + myCanvas->Close(); + delete myCanvas; + + f->Write(); + +// delete f1; +} + + +//Upsilon +void +MonitoringFile:: +fitMergedFile_IDPerfMonUpsilon( TFile* f, std::string run_dir, std::string TriggerName ) +{ + std::string path; + path=run_dir+"IDPerfMon/Upsilon/"+TriggerName; + + if( f->cd(path.c_str())==0 ) { + //std::cerr<< "MonitoringFile::fitMergedFile_IDPerfMonUpsilon(): " + //<<"No such directory \""<< path << "\"\n"; + return; + } + + TH1F* m_upsilon_invmass_vs_pt = new TH1F("Upsilon_invmass_vs_pt","Upsilon invmass-PDGmass vs. Upsilon Pt; p_{T}(#Upsilon) [GeV/c]; Mass Shift [GeV/c^{2}]", 6, 4.,20.); + TH1F* m_upsilon_invmass_vs_z0 = new TH1F("Upsilon_invmass_vs_z0","Upsilon invmass-PDGmass vs. muon z0; z0(#mu) [mm]; Mass Shift [GeV/c^{2}]", 6,-100.,100.); + TH1F* m_upsilon_invmass_vs_phi = new TH1F("Upsilon_invmass_vs_phi","Upsilon invmass-PDGmass vs. Upsilon phi; #phi(#Upsilon) [rad]; Mass Shift [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_upsilon_invmass_vs_phiplus = new TH1F("Upsilon_invmass_vs_phiplus","Upsilon invmass-PDGmass vs. Muon+ phi; #phi(#mu^{+}) [rad]; Mass Shift [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_upsilon_invmass_vs_phiminus = new TH1F("Upsilon_invmass_vs_phiminus","Upsilon invmass-PDGmass vs. Muon- phi; #phi(#mu^{-}) [rad]; Mass Shift [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_upsilon_invmass_vs_phidiff = new TH1F("Upsilon_invmass_vs_phidiff","Upsilon invmass-PDGmass vs. |phi(+)-phi(-)|; |#phi(#mu^{+})-#phi(#mu^{-})| [rad]; Mass Shift [GeV/c^{2}]", 6, 0., 2.5); + TH1F* m_upsilon_invmass_vs_eta = new TH1F("Upsilon_invmass_vs_eta","Upsilon invmass-PDGmass vs. Upsilon eta; #eta(#Upsilon); Mass Shift [GeV/c^{2}]", 8, -3.2, 3.2); + TH1F* m_upsilon_invmass_vs_eta_barrel = new TH1F("Upsilon_invmass_vs_eta_barrel","Upsilon invmass-PDGmass vs. Upsilon eta (barrel); #eta(#Upsilon); Mass Shift [GeV/c^{2}]", 2, -0.8, 0.8); + TH1F* m_upsilon_invmass_vs_eta_eca = new TH1F("Upsilon_invmass_vs_eta_eca","Upsilon invmass-PDGmass vs. Upsilon eta (endcap A); #eta(#Upsilon); Mass Shift [GeV/c^{2}]", 3, 0.8, 3.2); + TH1F* m_upsilon_invmass_vs_eta_ecc = new TH1F("Upsilon_invmass_vs_eta_ecc","Upsilon invmass-PDGmass vs. Upsilon eta (endcap C); #eta(#Upsilon); Mass Shift [GeV/c^{2}]", 3,-3.2, -0.8); + TH1F* m_upsilon_invmass_vs_etaplus= new TH1F("Upsilon_invmass_vs_etaplus","Upsilon invmass-PDGmass vs. Muon+ eta; #eta(#mu^{+}); Mass Shift [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_upsilon_invmass_vs_etaminus= new TH1F("Upsilon_invmass_vs_etaminus","Upsilon invmass-PDGmass vs. Muon- eta; #eta(#mu^{-}); Mass Shift [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_upsilon_invmass_vs_maxeta= new TH1F("Upsilon_invmass_vs_maxeta","Upsilon invmass-PDGmass vs. max Muon |eta|; max|#eta(#mu)|; Mass Shift [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_upsilon_invmass_vs_etadiff = new TH1F("Upsilon_invmass_vs_etadiff","Upsilon invmass-PDGmass vs. eta(+)-eta(-); #eta(#mu^{+})-#eta(#mu^{-}); Mass Shift [GeV/c^{2}]", 6 ,-1.5,1.5); + TH1F* m_upsilon_invmass_vs_crt= new TH1F("Upsilon_invmass_vs_curvature","Upsilon invmass-PDGmass vs. crt(+)-|crt(-)|; 1/p_{T}(#mu^{+})-1/p_{T}(#mu^{-}) [GeV^{-1}]; Mass Shift [GeV/c^{2}]",6, -0.15, 0.15); + TH1F* m_upsilon_invmass_vs_invpt=new TH1F("Upsilon_invmass_vs_invpt","Upsilon invmass-PDGmass vs. muon 1/Pt; 1/p_{T}(#mu) [(GeV/c)^{-1}]; Mass Shift [GeV/c^{2}]",6,0.05,0.25); + TH1F* m_upsilon_invmass_vs_angle_eta=new TH1F("Upsilon_invmass_vs_angle_eta","Upsilon invmass-PDGmass vs. arccos(#Delta#eta/#DeltaR);arccos(#Delta#eta/#DeltaR); Mass Shift [GeV/c^{2}]",6,0.,90.); + + TH1F* m_upsilon_width_vs_pt = new TH1F("Upsilon_width_vs_pt","Upsilon width vs. Upsilon Pt; p_{T}(#Upsilon) [GeV/c]; Width [GeV/c^{2}]", 6, 4.,20.); + TH1F* m_upsilon_width_vs_z0 = new TH1F("Upsilon_width_vs_z0","Upsilon width vs. muon z0; z0(#mu) [mm]; Width [GeV/c^{2}]", 6,-100.,100.); + TH1F* m_upsilon_width_vs_phi = new TH1F("Upsilon_width_vs_phi","Upsilon width vs. Upsilon phi; #phi(#Upsilon) [rad]; Width [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_upsilon_width_vs_phiplus = new TH1F("Upsilon_width_vs_phiplus","Upsilon width vs. Muon+ phi; #phi(#mu^{+}) [rad]; Width [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_upsilon_width_vs_phiminus = new TH1F("Upsilon_width_vs_phiminus","Upsilon width vs. Muon- phi; #phi(#mu^{-}) [rad]; Width [GeV/c^{2}]", 6, -3.15, 3.15); + TH1F* m_upsilon_width_vs_phidiff = new TH1F("Upsilon_width_vs_phidiff","Upsilon width vs. |phi(+)-phi(-)|; |#phi(#mu^{+})-#phi(#mu^{-})| [rad]; Width [GeV/c^{2}]", 6, 0., 2.5); + TH1F* m_upsilon_width_vs_eta = new TH1F("Upsilon_width_vs_eta","Upsilon width vs. Upsilon eta; #eta(#Upsilon); Width [GeV/c^{2}]", 8, -3.2, 3.2); + TH1F* m_upsilon_width_vs_eta_barrel = new TH1F("Upsilon_width_vs_eta_barrel","Upsilon width vs. Upsilon eta (barrel); #eta(#Upsilon); Width [GeV/c^{2}]", 2, -0.8, 0.8); + TH1F* m_upsilon_width_vs_eta_eca = new TH1F("Upsilon_width_vs_eta_eca","Upsilon width vs. Upsilon eta (endcap A); #eta(#Upsilon); Width [GeV/c^{2}]", 3, 0.8, 3.2); + TH1F* m_upsilon_width_vs_eta_ecc = new TH1F("Upsilon_width_vs_eta_ecc","Upsilon width vs. Upsilon eta (endcap C); #eta(#Upsilon); Width [GeV/c^{2}]", 3, -3.2, -0.8); + TH1F* m_upsilon_width_vs_etaplus= new TH1F("Upsilon_width_vs_etaplus","Upsilon width vs. Muon+ eta; #eta(#mu^{+}); Width [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_upsilon_width_vs_etaminus= new TH1F("Upsilon_width_vs_etaminus","Upsilon width vs. Muon- eta; #eta(#mu^{-}); Width [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_upsilon_width_vs_maxeta= new TH1F("Upsilon_width_vs_maxeta","Upsilon width vs. max Muon |eta|; max|#eta(#mu)|; Width [GeV/c^{2}]", 6,-2.4,2.4); + TH1F* m_upsilon_width_vs_etadiff = new TH1F("Upsilon_width_vs_etadiff","Upsilon width vs. eta(+)-eta(-); #eta(#mu^{+})-#eta(#mu^{-}); Width [GeV/c^{2}]", 6 ,-1.5,1.5); + TH1F* m_upsilon_width_vs_crt= new TH1F("Upsilon_width_vs_curvature","Upsilon width vs. crt(+)-|crt(-)|; 1/p_{T}(#mu^{+})-1/p_{T}(#mu^{-}) [GeV^{-1}]; Width [GeV/c^{2}]",6, -0.15, 0.15); + TH1F* m_upsilon_width_vs_invpt=new TH1F("Upsilon_width_vs_invpt","Upsilon width vs. muon 1/Pt; 1/p_{T}(#mu) [(GeV/c)^{-1}]; Width [GeV/c^{2}]",6,0.05,0.25); + TH1F* m_upsilon_width_vs_angle_eta=new TH1F("Upsilon_width_vs_angle_eta","Upsilon width vs. arccos(#Delta#eta/#DeltaR);arccos(#Delta#eta/#DeltaR); width [GeV/c^{2}]",6,0.,90.); + + const int nbins=6; + TH1F* hpt[nbins]; + TH1F* hz0[nbins]; + TH1F* hphi[nbins]; + TH1F* hphiplus[nbins]; + TH1F* hphiminus[nbins]; + TH1F* hphidiff[nbins]; + TH1F* heta[8]; + TH1F* heta_b[2]; + TH1F* heta_ecc[3]; + TH1F* heta_eca[3]; + TH1F* hetadiff[nbins]; + TH1F* hmaxeta[nbins]; + TH1F* hinvpt[nbins]; + TH1F* hcrt[nbins]; + TH1F* hetaplus[nbins]; + TH1F* hetaminus[nbins]; + TH1F* hangle_eta[nbins]; + + if (!CheckHistogram(f,(path+"/Upsilon_invmass").c_str())) return; + TH1F* m_mass = (TH1F*)(f->Get((path+"/Upsilon_invmass").c_str())->Clone()); + if (CheckHistogram(f,(path+"/Nevents").c_str())) { + TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); + TH1F* m_rate = new TH1F("rate","production rate",1,0,1); + double Ntot =m_Nevents->GetEntries(); + double yield = m_mass->Integral(m_mass->FindBin(9.1), m_mass->FindBin(9.8)); + double rate=yield/Ntot; + double rate_error=sqrt(1/yield+1/Ntot)*yield/Ntot; + m_rate->SetBinContent(1,rate); + m_rate->SetBinError(1,rate_error); + m_rate->Write("",TObject::kOverwrite); + } +// TH1F* m_mass_scaled = (TH1F*)(f->Get((path+"/Upsilon_invmass").c_str())->Clone("Upsilon_invmass_scaled_copy")); +// m_mass_scaled->SetMarkerStyle(21); +// TString title(m_mass_scaled->GetTitle()); +// if (CheckHistogram(f,(path+"/Upsilon_invmass_scaled").c_str())) { +// if (CheckHistogram(f,(path+"/Nevents").c_str())) { +// TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); +// double Ntot =m_Nevents->GetEntries(); +// if (Ntot!=0.) m_mass_scaled->Scale(1./Ntot); +// m_mass_scaled->SetTitle(title+" (per event)"); +// m_mass_scaled->Write("Upsilon_invmass_scaled",TObject::kOverwrite); +// } +// } +// delete m_mass_scaled; + if (CheckHistogram( f,(path+"/Upsilon_invmass").c_str())) { + TH1F* m_mass_rebin = (TH1F*)(f->Get((path+"/Upsilon_invmass").c_str())->Clone("Upsilon_invmass_rebin")); + TString title = m_mass_rebin->GetTitle(); + m_mass_rebin ->SetMarkerStyle(21); + m_mass_rebin->Rebin(8); + m_mass_rebin->SetTitle(title+" (larger binning for low Stats.)"); + m_mass_rebin->Write("Upsilon_invmass_rebin",TObject::kOverwrite); + } + + char cpt[100],cz0[100],cphi[100],cphidiff[100],ceta[100],cetadiff[100],cmaxeta[100],ccrt[100],cinvpt[100],cphiplus[100],cphiminus[100],cetaplus[100],cetaminus[100],ceta_b[100],ceta_ecc[100],ceta_eca[100],cangle_eta[100]; + + for (int i=0;i<nbins;i++) + { + sprintf(cpt,(path+"/pt_bin%d").c_str(),i); + sprintf(cz0,(path+"/z0_bin%d").c_str(),i); + sprintf(cphi,(path+"/phi_bin%d").c_str(),i); + sprintf(cphiplus,(path+"/phiplus_bin%d").c_str(),i); + sprintf(cphiminus,(path+"/phiminus_bin%d").c_str(),i); + sprintf(cphidiff,(path+"/phidiff_bin%d").c_str(),i); + sprintf(cetaplus,(path+"/etaplus_bin%d").c_str(),i); + sprintf(cetaminus,(path+"/etaminus_bin%d").c_str(),i); + sprintf(cmaxeta,(path+"/maxeta_bin%d").c_str(),i); + sprintf(cetadiff,(path+"/etadiff_bin%d").c_str(),i); + sprintf(ccrt,(path+"/crt_bin%d").c_str(),i); + sprintf(cinvpt,(path+"/invpt_bin%d").c_str(),i); + sprintf(cangle_eta,(path+"/angle_eta_bin%d").c_str(),i); + + if (!CheckHistogram(f,cpt)) return; + if (!CheckHistogram(f,cz0)) return; + if (!CheckHistogram(f,cphi)) return; + if (!CheckHistogram(f,cphiplus)) return; + if (!CheckHistogram(f,cphiminus)) return; + if (!CheckHistogram(f,cphidiff)) return; + if (!CheckHistogram(f,cetaplus)) return; + if (!CheckHistogram(f,cetaminus)) return; + if (!CheckHistogram(f,cmaxeta)) return; + if (!CheckHistogram(f,cetadiff)) return; + if (!CheckHistogram(f,ccrt)) return; + if (!CheckHistogram(f,cinvpt)) return; + if (!CheckHistogram(f,cangle_eta)) return; + + hpt[i] =(TH1F*)(f->Get(cpt)->Clone()); + hz0[i] =(TH1F*)(f->Get(cz0)->Clone()); + hphi[i]=(TH1F*)(f->Get(cphi)->Clone()); + hphiplus[i]=(TH1F*)(f->Get(cphiplus)->Clone()); + hphiminus[i]=(TH1F*)(f->Get(cphiminus)->Clone()); + hphidiff[i]=(TH1F*)(f->Get(cphidiff)->Clone()); + hetaplus[i]=(TH1F*)(f->Get(cetaplus)->Clone()); + hetaminus[i]=(TH1F*)(f->Get(cetaminus)->Clone()); + hetadiff[i]=(TH1F*)(f->Get(cetadiff)->Clone()); + hmaxeta[i]=(TH1F*)(f->Get(cmaxeta)->Clone()); + hcrt[i] = (TH1F*)(f->Get(ccrt)->Clone()); + hinvpt[i] =(TH1F*)(f->Get(cinvpt)->Clone()); + hangle_eta[i]=(TH1F*)(f->Get(cangle_eta)->Clone()); + + if (i<2) { + sprintf(ceta_b,(path+"/eta_b_bin%d").c_str(),i); + if (!CheckHistogram(f,ceta_b)) return; + heta_b[i] = (TH1F*)(f->Get(ceta_b)->Clone()); + } + if(i<3) { + sprintf(ceta_ecc,(path+"/eta_ecc_bin%d").c_str(),i); + sprintf(ceta_eca,(path+"/eta_eca_bin%d").c_str(),i); + if (!CheckHistogram(f,ceta_ecc)) return; + if (!CheckHistogram(f,ceta_eca)) return; + heta_ecc[i] =(TH1F*)(f->Get(ceta_ecc)->Clone()); + heta_eca[i] =(TH1F*)(f->Get(ceta_eca)->Clone()); + } + } + for (int i=0; i<8;i++) + { + sprintf(ceta,(path+"/eta_bin%d").c_str(),i); + if (!CheckHistogram(f,ceta)) return; + heta[i] =(TH1F*)(f->Get(ceta)->Clone()); + } + +// TF1 *f1 = new TF1("f1","gaus",9.,10.); +// f1->SetParameter(1,9.046); +// f1->SetParameter(2,0.15); +// f1->SetLineColor(2); +// f1->SetParNames("Constant","Mean","Width"); + m_mass->SetMarkerStyle(21); + + TCanvas *myCanvas = new TCanvas("MyCanvas"); + myCanvas->cd(); + +// m_mass->Fit(f1,"RQMN"); + + + fitUpsilonHistograms(m_upsilon_invmass_vs_pt,m_upsilon_width_vs_pt,hpt,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_z0,m_upsilon_width_vs_z0,hz0,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_phi,m_upsilon_width_vs_phi,hphi,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_phiplus,m_upsilon_width_vs_phiplus,hphiplus,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_phiminus,m_upsilon_width_vs_phiminus,hphiminus,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_phidiff,m_upsilon_width_vs_phidiff,hphidiff,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_eta,m_upsilon_width_vs_eta,heta,8); + fitUpsilonHistograms(m_upsilon_invmass_vs_eta_barrel,m_upsilon_width_vs_eta_barrel,heta_b,2); + fitUpsilonHistograms(m_upsilon_invmass_vs_eta_eca,m_upsilon_width_vs_eta_eca,heta_eca,3); + fitUpsilonHistograms(m_upsilon_invmass_vs_eta_ecc,m_upsilon_width_vs_eta_ecc,heta_ecc,3); + fitUpsilonHistograms(m_upsilon_invmass_vs_etaplus,m_upsilon_width_vs_etaplus,hetaplus,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_etaminus,m_upsilon_width_vs_etaminus,hetaminus,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_maxeta,m_upsilon_width_vs_maxeta,hmaxeta,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_etadiff,m_upsilon_width_vs_etadiff,hetadiff,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_crt,m_upsilon_width_vs_crt,hcrt,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_invpt,m_upsilon_width_vs_invpt,hinvpt,nbins); + fitUpsilonHistograms(m_upsilon_invmass_vs_angle_eta,m_upsilon_width_vs_angle_eta,hangle_eta,nbins); + + + // f->cd(path.c_str()); + if( f->cd(path.c_str())==0 ) { + //std::cerr<< "MonitoringFile::fitMergedFile_IDPerfMonUpsilon(): " + //<<"No such directory \""<< path << "\"\n"; + return; + } + + m_mass->Write("",TObject::kOverwrite); + for (int i=0; i<nbins;i++) + { + hpt[i]->Write("",TObject::kOverwrite); + hz0[i]->Write("",TObject::kOverwrite); + hphi[i]->Write("",TObject::kOverwrite); + hphiplus[i]->Write("",TObject::kOverwrite); + hphiminus[i]->Write("",TObject::kOverwrite); + hphidiff[i]->Write("",TObject::kOverwrite); + hetadiff[i]->Write("",TObject::kOverwrite); + hmaxeta[i]->Write("",TObject::kOverwrite); + hinvpt[i]->Write("",TObject::kOverwrite); + hcrt[i]->Write("",TObject::kOverwrite); + hetaplus[i]->Write("",TObject::kOverwrite); + hetaminus[i]->Write("",TObject::kOverwrite); + hangle_eta[i]->Write("",TObject::kOverwrite); + if (i<2) { + heta_b[i]->Write("",TObject::kOverwrite); + } + if (i<3) { + heta_ecc[i]->Write("",TObject::kOverwrite); + heta_eca[i]->Write("",TObject::kOverwrite); + } + } + for (int i=0;i<8;i++) + { + heta[i]->Write("",TObject::kOverwrite); + } + m_upsilon_invmass_vs_pt->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_z0->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_phi->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_phiplus->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_phiminus->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_phidiff->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_eta->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_eta_barrel->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_eta_ecc->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_eta_eca->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_etadiff->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_etaplus->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_etaminus->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_maxeta->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_crt->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_invpt->Write("",TObject::kOverwrite); + m_upsilon_invmass_vs_angle_eta->Write("",TObject::kOverwrite); + + m_upsilon_width_vs_pt->Write("",TObject::kOverwrite); + m_upsilon_width_vs_z0->Write("",TObject::kOverwrite); + m_upsilon_width_vs_phi->Write("",TObject::kOverwrite); + m_upsilon_width_vs_phiplus->Write("",TObject::kOverwrite); + m_upsilon_width_vs_phiminus->Write("",TObject::kOverwrite); + m_upsilon_width_vs_phidiff->Write("",TObject::kOverwrite); + m_upsilon_width_vs_eta->Write("",TObject::kOverwrite); + m_upsilon_width_vs_eta_barrel->Write("",TObject::kOverwrite); + m_upsilon_width_vs_eta_ecc->Write("",TObject::kOverwrite); + m_upsilon_width_vs_eta_eca->Write("",TObject::kOverwrite); + m_upsilon_width_vs_etadiff->Write("",TObject::kOverwrite); + m_upsilon_width_vs_etaplus->Write("",TObject::kOverwrite); + m_upsilon_width_vs_etaminus->Write("",TObject::kOverwrite); + m_upsilon_width_vs_maxeta->Write("",TObject::kOverwrite); + m_upsilon_width_vs_crt->Write("",TObject::kOverwrite); + m_upsilon_width_vs_invpt->Write("",TObject::kOverwrite); + m_upsilon_width_vs_angle_eta->Write("",TObject::kOverwrite); + + myCanvas->Close(); + delete myCanvas; + + f->Write(); + +// delete f1; + +} + +void +MonitoringFile:: +fitMergedFile_IDPerfMonZee ( TFile* f, std::string run_dir,std::string TriggerName ) +{ + + std::string path; + path= run_dir + "IDPerfMon/Zee/" + TriggerName; + if( f->cd(path.c_str())==0 ) { + //std::cerr << "MonitoringFile::fitMergedFile_IDPerfMonZee(): " + //<< "No such directory \"" << path << "\"\n"; + return; + } + + f->cd(path.c_str()); + + if (!CheckHistogram(f,(path+"/Zee_invmass").c_str())) return; + TH1F* m_mass = (TH1F*)(f->Get((path+"/Zee_invmass").c_str())->Clone()); + if (CheckHistogram(f,(path+"/Nevents").c_str())) { + TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); + TH1F* m_rate = new TH1F("rate","production rate",1,0,1); + double Ntot =m_Nevents->GetEntries(); + double yield = m_mass->Integral(m_mass->FindBin(80), m_mass->FindBin(105)); + double rate=yield/Ntot; + double rate_error=sqrt(1/yield+1/Ntot)*yield/Ntot; + m_rate->SetBinContent(1,rate); + m_rate->SetBinError(1,rate_error); + m_rate->Write("",TObject::kOverwrite); + } +// TH1F* m_mass_scaled = (TH1F*)(f->Get((path+"/Zee_trk_invmass").c_str())->Clone("Zee_trk_invmass_scaled_copy")); +// TString title(m_mass_scaled->GetTitle()); +// if (CheckHistogram(f,(path+"/Zee_trk_invmass_scaled").c_str())) { +// if (CheckHistogram(f,(path+"/Nevents").c_str())) { +// TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); +// double Ntot =m_Nevents->GetEntries(); +// if (Ntot!=0.) m_mass_scaled->Scale(1./Ntot); +// m_mass_scaled->SetTitle(title+" (per event)"); +// m_mass_scaled->Write("Zee_trk_invmass_scaled",TObject::kOverwrite); +// } +// } +// delete m_mass_scaled; + + enum m_eta_region { incl, barrel, eca, ecc, Nregions }; + std::vector<std::string> region_strings; + region_strings.push_back("incl"); + region_strings.push_back("barrel"); + region_strings.push_back("eca"); + region_strings.push_back("ecc"); + + std::vector<TH1F*> m_Zee_Eopdiff; + std::vector<TH1F*> m_Zee_Eop_plus; + std::vector<TH1F*> m_Zee_Eop_minus; + + std::vector<TProfile*> m_Zee_Eopdiff_vs_p; + std::vector<TProfile*> m_Zee_meanEop_vs_p_plus; + std::vector<TProfile*> m_Zee_meanEop_vs_p_minus; + + std::vector<TProfile*> m_Zee_Eopdiff_vs_invp; + std::vector<TProfile*> m_Zee_meanEop_vs_invp_plus; + std::vector<TProfile*> m_Zee_meanEop_vs_invp_minus; + + std::vector<TProfile*> m_Zee_Eopdiff_vs_E; + std::vector<TProfile*> m_Zee_meanEop_vs_E_plus; + std::vector<TProfile*> m_Zee_meanEop_vs_E_minus; + + std::vector<TProfile*> m_Zee_Eopdiff_vs_phi; + std::vector<TProfile*> m_Zee_meanEop_vs_phi_plus; + std::vector<TProfile*> m_Zee_meanEop_vs_phi_minus; + + std::vector<TProfile*> m_Zee_Eopdiff_vs_eta; + std::vector<TProfile*> m_Zee_meanEop_vs_eta_plus; + std::vector<TProfile*> m_Zee_meanEop_vs_eta_minus; + + std::string str; + + for (int region=0; region!=Nregions; ++region) { + + str = path + "/Zee_Eop_plus_" + region_strings[region]; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_Eop_plus.push_back((TH1F*)(f->Get(str.c_str()))); + m_Zee_Eop_plus[region]->SetTitle(m_Zee_Eop_plus[region]->GetTitle()); + str = path + "/Zee_Eop_minus_" + region_strings[region]; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_Eop_minus.push_back((TH1F*)(f->Get(str.c_str()))); + m_Zee_Eop_minus[region]->SetTitle(m_Zee_Eop_minus[region]->GetTitle()); + str = path + "/Zee_Eopdiff_" + region_strings[region]; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_Eopdiff.push_back((TH1F*)(f->Get(str.c_str()))); + m_Zee_Eopdiff[region]->SetTitle(m_Zee_Eopdiff[region]->GetTitle()); + + m_Zee_Eopdiff[region]->Add(m_Zee_Eop_plus[region],m_Zee_Eop_minus[region],1.,-1); + + if (region == incl) { + + str = path + "/Zee_meanEop_vs_p_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_p_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_p_plus[region]->SetTitle(m_Zee_meanEop_vs_p_plus[region]->GetTitle()); + str = path + "/Zee_meanEop_vs_p_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_p_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_p_minus[region]->SetTitle(m_Zee_meanEop_vs_p_minus[region]->GetTitle()); + str = path + "/Zee_Eopdiff_vs_p"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_Eopdiff_vs_p.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_Eopdiff_vs_p[region]->SetTitle(m_Zee_Eopdiff_vs_p[region]->GetTitle()); + + str = path + "/Zee_meanEop_vs_invp_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_invp_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_invp_plus[region]->SetTitle(m_Zee_meanEop_vs_invp_plus[region]->GetTitle()); + str = path + "/Zee_meanEop_vs_invp_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_invp_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_invp_minus[region]->SetTitle(m_Zee_meanEop_vs_invp_minus[region]->GetTitle()); + str = path + "/Zee_Eopdiff_vs_invp"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_Eopdiff_vs_invp.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_Eopdiff_vs_invp[region]->SetTitle(m_Zee_Eopdiff_vs_invp[region]->GetTitle()); + + str = path + "/Zee_meanEop_vs_E_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_E_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_E_plus[region]->SetTitle(m_Zee_meanEop_vs_E_plus[region]->GetTitle()); + str = path + "/Zee_meanEop_vs_E_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_E_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_E_minus[region]->SetTitle(m_Zee_meanEop_vs_E_minus[region]->GetTitle()); + str = path + "/Zee_Eopdiff_vs_E"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_Eopdiff_vs_E.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_Eopdiff_vs_E[region]->SetTitle(m_Zee_Eopdiff_vs_E[region]->GetTitle()); + + str = path + "/Zee_meanEop_vs_phi_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_phi_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_phi_plus[region]->SetTitle(m_Zee_meanEop_vs_phi_plus[region]->GetTitle()); + str = path + "/Zee_meanEop_vs_phi_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_phi_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_phi_minus[region]->SetTitle(m_Zee_meanEop_vs_phi_minus[region]->GetTitle()); + str = path + "/Zee_Eopdiff_vs_phi"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_Eopdiff_vs_phi.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_Eopdiff_vs_phi[region]->SetTitle(m_Zee_Eopdiff_vs_phi[region]->GetTitle()); + + str = path + "/Zee_meanEop_vs_eta_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_eta_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_eta_plus[region]->SetTitle(m_Zee_meanEop_vs_eta_plus[region]->GetTitle()); + str = path + "/Zee_meanEop_vs_eta_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_meanEop_vs_eta_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_meanEop_vs_eta_minus[region]->SetTitle(m_Zee_meanEop_vs_eta_minus[region]->GetTitle()); + str = path + "/Zee_Eopdiff_vs_eta"; + if (!CheckHistogram(f,str.c_str())) return; + m_Zee_Eopdiff_vs_eta.push_back((TProfile*)(f->Get(str.c_str()))); + m_Zee_Eopdiff_vs_eta[region]->SetTitle(m_Zee_Eopdiff_vs_eta[region]->GetTitle()); + + m_Zee_Eopdiff_vs_p[region]->Add(m_Zee_meanEop_vs_p_plus[region],m_Zee_meanEop_vs_p_minus[region],1.,-1); + m_Zee_Eopdiff_vs_invp[region]->Add(m_Zee_meanEop_vs_invp_plus[region],m_Zee_meanEop_vs_invp_minus[region],1.,-1); + m_Zee_Eopdiff_vs_E[region]->Add(m_Zee_meanEop_vs_E_plus[region],m_Zee_meanEop_vs_E_minus[region],1.,-1); + m_Zee_Eopdiff_vs_phi[region]->Add(m_Zee_meanEop_vs_phi_plus[region],m_Zee_meanEop_vs_phi_minus[region],1.,-1); + m_Zee_Eopdiff_vs_eta[region]->Add(m_Zee_meanEop_vs_eta_plus[region],m_Zee_meanEop_vs_eta_minus[region],1.,-1); + + } + + } + + for (int region=0; region!=Nregions; ++region) { + m_Zee_Eopdiff[region]->Write("",TObject::kOverwrite); + if (region == incl) { + m_Zee_Eopdiff_vs_p[region]->Write("",TObject::kOverwrite); + m_Zee_Eopdiff_vs_invp[region]->Write("",TObject::kOverwrite); + m_Zee_Eopdiff_vs_E[region]->Write("",TObject::kOverwrite); + m_Zee_Eopdiff_vs_phi[region]->Write("",TObject::kOverwrite); + m_Zee_Eopdiff_vs_eta[region]->Write("",TObject::kOverwrite); + } + } + + f->Write(); + +} + +void +MonitoringFile:: +fitMergedFile_IDPerfMonWenu ( TFile* f, std::string run_dir,std::string TriggerName ) +{ + + std::string path; + path= run_dir + "IDPerfMon/Wenu/" + TriggerName; + if( f->cd(path.c_str())==0 ) { + //std::cerr << "MonitoringFile::fitMergedFile_IDPerfMonWenu(): " + //<< "No such directory \"" << path << "\"\n"; + return; + } + + f->cd(path.c_str()); + + if (!CheckHistogram(f,(path+"/Wenu_trk_transmass_sel").c_str())) return; + TH1F* m_mass = (TH1F*)(f->Get((path+"/Wenu_trk_transmass_sel").c_str())->Clone()); + if (CheckHistogram(f,(path+"/Nevents").c_str())) { + TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); + TH1F* m_rate = new TH1F("rate","production rate",1,0,1); + double Ntot =m_Nevents->GetEntries(); + double yield = m_mass->Integral(m_mass->FindBin(50), m_mass->FindBin(80)); + double rate=yield/Ntot; + double rate_error=sqrt(1/yield+1/Ntot)*yield/Ntot; + m_rate->SetBinContent(1,rate); + m_rate->SetBinError(1,rate_error); + m_rate->Write("",TObject::kOverwrite); + } +// TH1F* m_mass_scaled = (TH1F*)(f->Get((path+"/Wenu_trk_transmass_sel").c_str())->Clone("Wenu_trk_transmass_sel_scaled_copy")); +// TString title(m_mass_scaled->GetTitle()); +// if (CheckHistogram(f,(path+"/Wenu_trk_transmass_sel_scaled").c_str())) { +// if (CheckHistogram(f,(path+"/Nevents").c_str())) { +// TH1F* m_Nevents=(TH1F*)f->Get((path+"/Nevents").c_str()); +// double Ntot =m_Nevents->GetEntries(); +// if (Ntot!=0.) m_mass_scaled->Scale(1./Ntot); +// m_mass_scaled->SetTitle(title+" (per event)"); +// m_mass_scaled->Write("Wenu_trk_transmass_sel_scaled",TObject::kOverwrite); +// } +// } +// delete m_mass_scaled; + + enum m_eta_region { incl, barrel, eca, ecc, Nregions }; + std::vector<std::string> region_strings; + region_strings.push_back("incl"); + region_strings.push_back("barrel"); + region_strings.push_back("eca"); + region_strings.push_back("ecc"); + + std::vector<TH1F*> m_Wenu_Eopdiff; + std::vector<TH1F*> m_Wenu_Eop_plus; + std::vector<TH1F*> m_Wenu_Eop_minus; + + std::vector<TProfile*> m_Wenu_Eopdiff_vs_p; + std::vector<TProfile*> m_Wenu_meanEop_vs_p_plus; + std::vector<TProfile*> m_Wenu_meanEop_vs_p_minus; + + std::vector<TProfile*> m_Wenu_Eopdiff_vs_invp; + std::vector<TProfile*> m_Wenu_meanEop_vs_invp_plus; + std::vector<TProfile*> m_Wenu_meanEop_vs_invp_minus; + + std::vector<TProfile*> m_Wenu_Eopdiff_vs_E; + std::vector<TProfile*> m_Wenu_meanEop_vs_E_plus; + std::vector<TProfile*> m_Wenu_meanEop_vs_E_minus; + + std::vector<TProfile*> m_Wenu_Eopdiff_vs_phi; + std::vector<TProfile*> m_Wenu_meanEop_vs_phi_plus; + std::vector<TProfile*> m_Wenu_meanEop_vs_phi_minus; + + std::vector<TProfile*> m_Wenu_Eopdiff_vs_eta; + std::vector<TProfile*> m_Wenu_meanEop_vs_eta_plus; + std::vector<TProfile*> m_Wenu_meanEop_vs_eta_minus; + + std::string str; + + for (int region=0; region!=Nregions; ++region) { + + str = path + "/Wenu_Eop_plus_" + region_strings[region]; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_Eop_plus.push_back((TH1F*)(f->Get(str.c_str()))); + m_Wenu_Eop_plus[region]->SetTitle(m_Wenu_Eop_plus[region]->GetTitle()); + str = path + "/Wenu_Eop_minus_" + region_strings[region]; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_Eop_minus.push_back((TH1F*)(f->Get(str.c_str()))); + m_Wenu_Eop_minus[region]->SetTitle(m_Wenu_Eop_minus[region]->GetTitle()); + str = path + "/Wenu_Eopdiff_" + region_strings[region]; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_Eopdiff.push_back((TH1F*)(f->Get(str.c_str()))); + m_Wenu_Eopdiff[region]->SetTitle(m_Wenu_Eopdiff[region]->GetTitle()); + + m_Wenu_Eopdiff[region]->Add(m_Wenu_Eop_plus[region],m_Wenu_Eop_minus[region],1.,-1); + + if (region == incl) { + + str = path + "/Wenu_meanEop_vs_p_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_p_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_p_plus[region]->SetTitle(m_Wenu_meanEop_vs_p_plus[region]->GetTitle()); + str = path + "/Wenu_meanEop_vs_p_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_p_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_p_minus[region]->SetTitle(m_Wenu_meanEop_vs_p_minus[region]->GetTitle()); + str = path + "/Wenu_Eopdiff_vs_p"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_Eopdiff_vs_p.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_Eopdiff_vs_p[region]->SetTitle(m_Wenu_Eopdiff_vs_p[region]->GetTitle()); + + str = path + "/Wenu_meanEop_vs_invp_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_invp_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_invp_plus[region]->SetTitle(m_Wenu_meanEop_vs_invp_plus[region]->GetTitle()); + str = path + "/Wenu_meanEop_vs_invp_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_invp_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_invp_minus[region]->SetTitle(m_Wenu_meanEop_vs_invp_minus[region]->GetTitle()); + str = path + "/Wenu_Eopdiff_vs_invp"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_Eopdiff_vs_invp.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_Eopdiff_vs_invp[region]->SetTitle(m_Wenu_Eopdiff_vs_invp[region]->GetTitle()); + + str = path + "/Wenu_meanEop_vs_E_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_E_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_E_plus[region]->SetTitle(m_Wenu_meanEop_vs_E_plus[region]->GetTitle()); + str = path + "/Wenu_meanEop_vs_E_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_E_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_E_minus[region]->SetTitle(m_Wenu_meanEop_vs_E_minus[region]->GetTitle()); + str = path + "/Wenu_Eopdiff_vs_E"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_Eopdiff_vs_E.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_Eopdiff_vs_E[region]->SetTitle(m_Wenu_Eopdiff_vs_E[region]->GetTitle()); + + str = path + "/Wenu_meanEop_vs_phi_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_phi_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_phi_plus[region]->SetTitle(m_Wenu_meanEop_vs_phi_plus[region]->GetTitle()); + str = path + "/Wenu_meanEop_vs_phi_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_phi_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_phi_minus[region]->SetTitle(m_Wenu_meanEop_vs_phi_minus[region]->GetTitle()); + str = path + "/Wenu_Eopdiff_vs_phi"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_Eopdiff_vs_phi.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_Eopdiff_vs_phi[region]->SetTitle(m_Wenu_Eopdiff_vs_phi[region]->GetTitle()); + + str = path + "/Wenu_meanEop_vs_eta_plus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_eta_plus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_eta_plus[region]->SetTitle(m_Wenu_meanEop_vs_eta_plus[region]->GetTitle()); + str = path + "/Wenu_meanEop_vs_eta_minus"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_meanEop_vs_eta_minus.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_meanEop_vs_eta_minus[region]->SetTitle(m_Wenu_meanEop_vs_eta_minus[region]->GetTitle()); + str = path + "/Wenu_Eopdiff_vs_eta"; + if (!CheckHistogram(f,str.c_str())) return; + m_Wenu_Eopdiff_vs_eta.push_back((TProfile*)(f->Get(str.c_str()))); + m_Wenu_Eopdiff_vs_eta[region]->SetTitle(m_Wenu_Eopdiff_vs_eta[region]->GetTitle()); + + m_Wenu_Eopdiff_vs_p[region]->Add(m_Wenu_meanEop_vs_p_plus[region],m_Wenu_meanEop_vs_p_minus[region],1.,-1); + m_Wenu_Eopdiff_vs_invp[region]->Add(m_Wenu_meanEop_vs_invp_plus[region],m_Wenu_meanEop_vs_invp_minus[region],1.,-1); + m_Wenu_Eopdiff_vs_E[region]->Add(m_Wenu_meanEop_vs_E_plus[region],m_Wenu_meanEop_vs_E_minus[region],1.,-1); + m_Wenu_Eopdiff_vs_phi[region]->Add(m_Wenu_meanEop_vs_phi_plus[region],m_Wenu_meanEop_vs_phi_minus[region],1.,-1); + m_Wenu_Eopdiff_vs_eta[region]->Add(m_Wenu_meanEop_vs_eta_plus[region],m_Wenu_meanEop_vs_eta_minus[region],1.,-1); + + } + + } + + for (int region=0; region!=Nregions; ++region) { + m_Wenu_Eopdiff[region]->Write("",TObject::kOverwrite); + if (region == incl) { + m_Wenu_Eopdiff_vs_p[region]->Write("",TObject::kOverwrite); + m_Wenu_Eopdiff_vs_invp[region]->Write("",TObject::kOverwrite); + m_Wenu_Eopdiff_vs_E[region]->Write("",TObject::kOverwrite); + m_Wenu_Eopdiff_vs_phi[region]->Write("",TObject::kOverwrite); + m_Wenu_Eopdiff_vs_eta[region]->Write("",TObject::kOverwrite); + } + } + + f->Write(); + +} + + + + +void +MonitoringFile:: +fitMergedFile_IDPerfMonZMM ( TFile* f, std::string run_dir,std::string TriggerName ){ + + std::string path; + std::vector<TH1F*> hvec; + gROOT->SetStyle("Plain"); + + path = run_dir + "IDPerfMon/ZMM/" + TriggerName; + //std::cout <<" ZMM path: "<< path << std::endl; + if( f->cd(path.c_str())==0 ) { + //std::cerr << "MonitoringFile::fitMergedFile_IDPerfMonZMM(): " + //<< "No such directory \"" << path << "\"\n"; + return; + } + f->cd(path.c_str()); + + + + // CB --------- + TH1F* m_ZMass_CB_Shift_vs_Regions = new TH1F("Z_Mass_CB_Shift_vs_Regions", "Z_Mass_CB Shift vs. Regions", 4, 0.5, 4.5 ); + TH1F* m_ZMass_CB_Width_vs_Regions = new TH1F("Z_Mass_CB_Width_vs_Regions", "Z_Mass_CB Width vs. Regions", 4, 0.5, 4.5 ); + + if ( !CheckHistogram( f,(path+"/Z_Mass_CB_All").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_CB_BB").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_CB_BE").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_CB_EE").c_str()) ) return; + + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_CB_All").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_CB_BB").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_CB_BE").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_CB_EE").c_str())->Clone()) ); + fitZmumuHistograms(m_ZMass_CB_Shift_vs_Regions, m_ZMass_CB_Width_vs_Regions, hvec); + hvec.clear(); + m_ZMass_CB_Shift_vs_Regions->SetStats(0); + m_ZMass_CB_Width_vs_Regions->SetStats(0); + m_ZMass_CB_Shift_vs_Regions->Write("",TObject::kOverwrite); + m_ZMass_CB_Width_vs_Regions->Write("",TObject::kOverwrite); + + // ID ---------- + TH1F* m_ZMass_ID_Shift_vs_Regions = new TH1F("Z_Mass_ID_Shift_vs_Regions", "Z_Mass_ID Shift vs. Regions", 4, 0.5, 4.5 ); + TH1F* m_ZMass_ID_Width_vs_Regions = new TH1F("Z_Mass_ID_Width_vs_Regions", "Z_Mass_ID Width vs. Regions", 4, 0.5, 4.5 ); + + if ( !CheckHistogram( f,(path+"/Z_Mass_ID_All").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_ID_BB").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_ID_BE").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_ID_EE").c_str()) ) return; + + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_ID_All").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_ID_BB").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_ID_BE").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_ID_EE").c_str())->Clone()) ); + fitZmumuHistograms(m_ZMass_ID_Shift_vs_Regions, m_ZMass_ID_Width_vs_Regions, hvec); + hvec.clear(); + m_ZMass_ID_Shift_vs_Regions->SetStats(0); + m_ZMass_ID_Width_vs_Regions->SetStats(0); + m_ZMass_ID_Shift_vs_Regions->Write("",TObject::kOverwrite); + m_ZMass_ID_Width_vs_Regions->Write("",TObject::kOverwrite); + + // ME ----------- + TH1F* m_ZMass_ME_Shift_vs_Regions = new TH1F("Z_Mass_ME_Shift_vs_Regions", "Z_Mass_ME Shift vs. Regions", 4, 0.5, 4.5 ); + TH1F* m_ZMass_ME_Width_vs_Regions = new TH1F("Z_Mass_ME_Width_vs_Regions", "Z_Mass_ME Width vs. Regions", 4, 0.5, 4.5 ); + + if ( !CheckHistogram( f,(path+"/Z_Mass_ME_All").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_ME_BB").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_ME_BE").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_ME_EE").c_str()) ) return; + + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_ME_All").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_ME_BB").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_ME_BE").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_ME_EE").c_str())->Clone()) ); + fitZmumuHistograms(m_ZMass_ME_Shift_vs_Regions, m_ZMass_ME_Width_vs_Regions, hvec); + hvec.clear(); + m_ZMass_ME_Shift_vs_Regions->SetStats(0); + m_ZMass_ME_Width_vs_Regions->SetStats(0); + m_ZMass_ME_Shift_vs_Regions->Write("",TObject::kOverwrite); + m_ZMass_ME_Width_vs_Regions->Write("",TObject::kOverwrite); + + // MS ----------- + TH1F* m_ZMass_MS_Shift_vs_Regions = new TH1F("Z_Mass_MS_Shift_vs_Regions", "Z_Mass_MS Shift vs. Regions", 4, 0.5, 4.5 ); + TH1F* m_ZMass_MS_Width_vs_Regions = new TH1F("Z_Mass_MS_Width_vs_Regions", "Z_Mass_MS Width vs. Regions", 4, 0.5, 4.5 ); + + + if ( !CheckHistogram( f,(path+"/Z_Mass_MS_All").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_MS_BB").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_MS_BE").c_str()) || + !CheckHistogram( f,(path+"/Z_Mass_MS_EE").c_str()) ) return; + + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_MS_All").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_MS_BB").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_MS_BE").c_str())->Clone()) ); + hvec.push_back( (TH1F*)(f->Get((path+"/Z_Mass_MS_EE").c_str())->Clone()) ); + fitZmumuHistograms(m_ZMass_MS_Shift_vs_Regions, m_ZMass_MS_Width_vs_Regions, hvec); + hvec.clear(); + m_ZMass_MS_Shift_vs_Regions->SetStats(0); + m_ZMass_MS_Width_vs_Regions->SetStats(0); + m_ZMass_MS_Shift_vs_Regions->Write("",TObject::kOverwrite); + m_ZMass_MS_Width_vs_Regions->Write("",TObject::kOverwrite); + + + + // OLD naming style plots + if (!CheckHistogram(f, (path+"/z-mass_trks").c_str())) return; + TH1F* m_ZMass_ID = (TH1F*)(f->Get((path+"/z-mass_trks").c_str())->Clone()); + m_ZMass_ID->SetTitle("Z Mass ID Tracks"); + //fitZmumuMassPlot(m_ZMass_ID); + //m_ZMass_ID->Write("",TObject::kOverwrite); + + if (!CheckHistogram(f, (path+"/z-mass_comb").c_str())) return; + TH1F* m_ZMass_CB = (TH1F*)(f->Get((path+"/z-mass_comb").c_str())->Clone()); + m_ZMass_CB->SetTitle("Z Mass CB Tracks"); + //fitZmumuMassPlot(m_ZMass_CB); + //m_ZMass_CB->Write("",TObject::kOverwrite); + + + if ( CheckHistogram(f,(path+"/Nevents").c_str()) ) { + TH1F* m_Nevents = (TH1F*)f->Get((path+"/Nevents").c_str()); + TH1F* m_rate = new TH1F("rate","production rate",1,0,1); + double Ntot = m_Nevents->GetEntries(); + double yield = m_ZMass_ID->Integral(m_ZMass_ID->FindBin(80), m_ZMass_ID->FindBin(105)); + double rate = yield/Ntot; + double rate_error = sqrt(1/yield+1/Ntot)*yield/Ntot; + //std::cout <<" rate: "<< rate <<" rate_error: "<< rate_error <<std::endl; + m_rate->SetBinContent(1,rate); + m_rate->SetBinError(1,rate_error); + m_rate->Write("rate",TObject::kOverwrite); + } + + f->Write(); +} + + + + +void +MonitoringFile:: +fitJpsiHistograms(TH1F* hmass, TH1F* hwidth, TH1F* h1[], int n) +{ + double jpsiPDGmass=3.097; + double mass=0.; + double mass_error=0; + double width=0; + double width_error=0; + double maxmass=0.; + double maxwidth=0.; + double minwidth=999; + hmass->SetMarkerStyle(21); + hwidth->SetMarkerStyle(21); +// TF1 *fitjpsi = new TF1("fitjpsi","gaus",2.9,3.3); +// fitjpsi->SetParNames("Constant","Mean","Width"); + TF1 *fitjpsi = new TF1("fitjpsi","gaus",2.6,3.6); + // fitjpsi->SetParNames("Constant","Mean","Sigma","Constant","Slope"); + fitjpsi->SetLineColor(2); + for (int i=0; i<n; i++) { + int h1entries = h1[i]->GetEntries(); + if (h1entries>50) { + double mean = h1[i]->GetMean(); + double spread = 2*(h1[i]->GetRMS()); + double constantGuess = double(h1entries)/10.; + fitjpsi->SetParameters(constantGuess,jpsiPDGmass,0.05); + fitjpsi->SetRange(mean-spread,mean+spread); + h1[i]->Fit("fitjpsi","RQM"); + mean = fitjpsi->GetParameter(1); + spread = 1.2*(fitjpsi->GetParameter(2)); + fitjpsi->SetRange(mean-spread,mean+spread); + h1[i]->Fit("fitjpsi","RQM"); + h1[i]->SetMarkerStyle(21); + mass=fitjpsi->GetParameter(1)-jpsiPDGmass; + mass_error=fitjpsi->GetParError(1); + width=fitjpsi->GetParameter(2); + width_error=fitjpsi->GetParError(2); + hmass->SetBinContent(i+1,mass); + hmass->SetBinError(i+1,mass_error); + hwidth->SetBinContent(i+1,width); + hwidth->SetBinError(i+1,width_error); + if( (fabs(mass)+mass_error)>maxmass ) maxmass=fabs(mass)+mass_error; + if( (fabs(width)+width_error)>maxwidth ) maxwidth=fabs(width)+width_error; + if( (fabs(width)-width_error)<minwidth ) minwidth=fabs(width)-width_error; + } + } + if (maxmass>0.1) maxmass=0.1; + if (maxwidth>0.2) maxwidth=0.2; + if (minwidth<0.) minwidth=0.; + hmass->SetAxisRange(-maxmass*1.05,maxmass*1.05,"Y"); +// hwidth->SetAxisRange(0.,maxwidth*1.05,"Y"); + if (minwidth<maxwidth) hwidth->SetAxisRange(minwidth*0.9,maxwidth*1.05,"Y"); + + delete fitjpsi; +} + + +void +MonitoringFile:: +fitUpsilonHistograms(TH1F* hmass, TH1F* hwidth, TH1F* h1[], int n) +{ + double upsilonPDGmass=9.46; + double mass=0; + double mass_error=0; + double width=0; + double width_error=0; + double maxmass=0.; + double maxwidth=0.; + double minwidth=999; + hmass->SetMarkerStyle(21); + hwidth->SetMarkerStyle(21); +// TF1 *fitupsi = new TF1("fitupsi","gaus",9.,10.); +// fitupsi->SetParNames("Constant","Mean","Width"); + TF1 *fitupsi = new TF1("fitupsi","gaus(0)+pol1(3)",8.5,10.5); + fitupsi->SetParNames("Constant","Mean","Sigma","Constant","Slope"); + fitupsi->SetLineColor(2); + for (int i=0; i<n; i++) { + if (h1[i]->GetEntries()>20) { + double max=h1[i]->GetBinContent(h1[i]->GetMaximumBin()); + fitupsi->SetParameter(1,9.46); + fitupsi->SetParameter(2,0.15); + fitupsi->SetParLimits(1,8.,11.); + fitupsi->SetParLimits(2,0.,0.5); + fitupsi->SetParameter(0,max); + h1[i]->SetMarkerStyle(21); + h1[i]->Fit("fitupsi","RQM"); + mass=fitupsi->GetParameter(1)-upsilonPDGmass; + mass_error=fitupsi->GetParError(1); + width=fitupsi->GetParameter(2); + width_error=fitupsi->GetParError(2); + hmass->SetBinContent(i+1,mass); + hmass->SetBinError(i+1,mass_error); + hwidth->SetBinContent(i+1,width); + hwidth->SetBinError(i+1,width_error); + if( (fabs(mass)+mass_error)>maxmass ) maxmass=fabs(mass)+mass_error; + if( (fabs(width)+width_error)>maxwidth ) maxwidth=fabs(width)+width_error; + if( (fabs(width)-width_error)<minwidth ) minwidth=fabs(width)-width_error; + } + } + if (maxmass>0.1) maxmass=0.1; + if (maxwidth>0.4) maxwidth=0.4; + if (minwidth<0.) minwidth=0.; + hmass->SetAxisRange(-maxmass*1.05,maxmass*1.05,"Y"); + if (minwidth<maxwidth) hwidth->SetAxisRange(minwidth*0.9,maxwidth*1.05,"Y"); + + delete fitupsi; +} + + +void MonitoringFile::fitZmumuHistograms(TH1F* hmass, TH1F* hwidth, std::vector<TH1F*> hvec){ + + const double ZPDGmass = 91.1876; + const int size = (int)hvec.size(); + for(int i = 0; i < size; i++){ + double mass = fitZmumuMass(hvec[i]).first.getVal() - ZPDGmass; + double mass_err = fitZmumuMass(hvec[i]).first.getError(); + double width = fitZmumuMass(hvec[i]).second.getVal(); + double width_err = fitZmumuMass(hvec[i]).second.getError(); + + hmass->SetBinContent(i+1, mass); + hmass->SetBinError(i+1,mass_err); + hmass->GetXaxis()->SetBinLabel(i+1, hvec[i]->GetName()); + hmass->GetXaxis()->SetTitle("Different Detector Regions"); + hmass->SetAxisRange(-3.0, 3.0,"Y"); + + hwidth->SetBinContent(i+1, width); + hwidth->SetBinError(i+1, width_err); + hwidth->GetXaxis()->SetBinLabel(i+1, hvec[i]->GetName()); + hwidth->GetXaxis()->SetTitle("Different Detector Regions"); + hwidth->SetAxisRange(0, 8, "Y"); + } +} + + + +std::pair<RooRealVar, RooRealVar> MonitoringFile::fitZmumuMass( TH1F* hmass ){ + + // gROOT->ProcessLine("gErrorIgnoreLevel=1001;"); + RooAbsPdf::verboseEval(-100); //sami in order to make roofit quiet + RooRealVar m("mass", "dimuon invariable mass", 91.2, 60., 120., "GeV"); + RooDataHist *data = 0; + data = new RooDataHist("data", "data", m, hmass); + RooRealVar bwm0("bw_#mu", "bw_#mu", 91.2, 85., 95.) ; + RooRealVar bwsg("bw_#sigma", "bw_#sigma", 2.4952) ; + RooBreitWigner bw("bw","bw", m, bwm0, bwsg); + + RooRealVar cbm0("cb_#mu", "cb_#mu", 0 ) ; + RooRealVar cbsg("cb_#sigma", "cb_#sigma", 5., 0.1, 10.) ; + RooRealVar cbal("cb_#alpha", "cb_#alpha", 1.5, 0.1, 10.) ; + RooRealVar cbn( "cb_n", "cb_n", 1.5, 0.01, 10.) ; + RooCBShape cb( "cb", "cb", m, cbm0, cbsg, cbal, cbn); + + m.setBins(5000); + RooFFTConvPdf bxc("bxc", "BW (X) CB", m, bw, cb) ; + bxc.fitTo(*data,RooFit::PrintLevel(-1), RooFit::FitOptions("QN"), RooFit::PrintEvalErrors(-1),RooFit::Warnings(kFALSE)); + + RooArgSet* params = bxc.getVariables() ; + //params->Print("v"); + RooRealVar* fit_bwm0 = (RooRealVar*) params->find("bw_#mu"); + RooRealVar* fit_cbsg = (RooRealVar*) params->find("cb_#sigma"); + //double vfit_bwm0 = fit_bwm0->getVal(); + //double vfit_cbsg = fit_cbsg->getVal(); + //std::cout <<" vfit_bwm0: "<< vfit_bwm0 << " vfit_cbsg: " << vfit_cbsg << std::endl; + delete data; + return std::make_pair(*fit_bwm0 , *fit_cbsg); +} + + + +//void MonitoringFile::fitZmumuMass(TH1F* hmass , RooPlot* frame ){ +void MonitoringFile::fitZmumuMassPlot(TH1F* hmass){ + + // gROOT->ProcessLine("gErrorIgnoreLevel=1001;"); + RooAbsPdf::verboseEval(-100); //sami in order to make roofit quiet + RooRealVar m("mass", "dimuon invariable mass", 91.2, 60., 120., "GeV"); + RooDataHist *data = 0; + data = new RooDataHist("data", "data", m, hmass); + RooRealVar bwm0("bw_#mu", "bw_#mu", 91.2, 85., 95.) ; + RooRealVar bwsg("bw_#sigma","bw_#sigma", 2.4952) ; + RooBreitWigner bw("bw","bw", m, bwm0, bwsg); + + RooRealVar cbm0("cb_#mu", "cb_#mu", 0 ) ; + RooRealVar cbsg("cb_#sigma", "cb_#sigma", 5., 0.1, 10.) ; + RooRealVar cbal("cb_#alpha", "cb_#alpha", 1.5, 0.1, 10.) ; + RooRealVar cbn( "cb_n", "cb_n", 1.5, 0.01, 10.) ; + RooCBShape cb( "cb", "cb", m, cbm0, cbsg, cbal, cbn); + + m.setBins(5000); + RooFFTConvPdf bxc("bxc", "BW (X) CB", m, bw, cb) ; + bxc.fitTo(*data, RooFit::PrintLevel(-1), RooFit::FitOptions("QN"), RooFit::PrintEvalErrors(-1),RooFit::Warnings(kFALSE)); + RooPlot* frame = m.frame(); + data->plotOn(frame, RooFit::MarkerSize(0.9)); + bxc.paramOn(frame, RooFit::Format("NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.1,0.4,0.9)); + bxc.plotOn (frame, RooFit::LineColor(kYellow)); + cb.plotOn(frame, RooFit::LineColor(kRed)); + bw.plotOn(frame, RooFit::LineStyle(kDashed)) ; + delete data; +} + + +} diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_L1CaloPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_L1CaloPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..170f8d59159b11970249c7b9b5baa82cb126df03 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_L1CaloPostProcess.cxx @@ -0,0 +1,288 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// L1Calo post processing jobs +// Author: Peter Faulkner +// ********************************************************************** + +#include "DataQualityUtils/MonitoringFile.h" + +#include <string> + +#include <TDirectory.h> +#include <TFile.h> +#include <TH1.h> +#include <TKey.h> +#include <TObject.h> +#include <TString.h> + +#ifndef L1CALOPOSTPROCESSDEBUG +#define L1CALOPOSTPROCESSDEBUG false +#endif + +namespace dqutils { + + + //-------------------------------------------------------------------------------- + // main process + //-------------------------------------------------------------------------------- + void MonitoringFile::L1CaloPostProcess( std::string inFilename, bool /* isIncremental */ ){ + + bool debug = L1CALOPOSTPROCESSDEBUG; + if (debug) std::cout << "--> L1CaloPostProcess: Begin L1Calo post-processing" << std::endl; + + //open root file + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + //check files are loaded. + if (f == 0 || ! f->IsOpen() ) { + std::cerr << "--> L1CaloPostProcess: Input file not opened" << std::endl; + delete f; + return; + } + + //zombie files? + if(f->IsZombie()) { + std::cerr << "--> L1CaloPostProcess: Input file " << inFilename << " cannot be opened. " << std::endl; + delete f; + return; + } + + //check file size is not too small. + if(f->GetSize()<1000.) { + std::cerr << "--> L1CaloPostProcess: Input file empty" << std::endl; + f->Close(); + delete f; + return; + } + + //build iterator + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + + //loop over keys in root directory + while ((key_run = dynamic_cast<TKey*>( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + + //check we have a valid pointer + if (tdir_run ==0 ) { + delete obj_run; + continue; + } + + //check name + std::string runDirName( tdir_run->GetName() ); + if (debug) std::cout << "Run_directory: " << runDirName << std::endl; + + if (runDirName.find("run") == std::string::npos ) { + delete obj_run; + continue; + } + + // Stability RMS histograms + TString stabilityDirName = runDirName + "/L1Calo/PPM/Stability"; + L1CaloStabilityRMS(f, stabilityDirName + "/FineTime", "fineTime"); + L1CaloStabilityRMS(f, stabilityDirName + "/Pedestal", "pedestal"); + L1CaloStabilityRMS(f, stabilityDirName + "/EtCorrelation", "etCorrelation"); + + // Trigger efficiency eta-phi histograms + int items = 16; + int binSkip = 8; + double threshold[6] = { 3., 3., 3., 6., 4., 2. }; + TString energies[6] = { "10", "20", "30", "50", "100", "200" }; + for (int i = 0; i < 3; ++i) { + TString effDir = runDirName + "/L1Calo/Reco/EmEfficiencies/ClusterRaw_" + + energies[i] + "GeV_EtaVsPhi"; + TString nameDen = "ClusterRaw_" + energies[i] + "GeV_Eta_vs_Phi"; + TString nameEff = nameDen + "_trig_Eff"; + L1CaloResetEfficiencies(f, effDir, nameDen, nameEff, items, threshold[i], binSkip); + } + items = 8; + binSkip = 6; + int itemsF = 4; + int binSkipF = 0; + for (int i = 3; i < 6; ++i) { + TString effDir = runDirName + "/L1Calo/Reco/JetEfficiencies/JetEmScale_" + + energies[i] + "GeV_EtaVsPhi"; + TString nameDen = "JetEmScale_" + energies[i] + "GeV_Eta_vs_Phi"; + TString nameEff = nameDen + "_J_Eff_item"; + TString nameEffF = nameDen + "_FJ_J_Eff_item"; + L1CaloResetEfficiencies(f, effDir, nameDen, nameEff, items, threshold[i], binSkip); + L1CaloResetEfficiencies(f, effDir, nameDen, nameEffF, itemsF, threshold[i], binSkipF); + } + } + + f->Close(); + delete f; + if (debug) std::cout << "--> L1CaloPostProcess: finished L1Calo post-processing" + << std::endl; + } + + // Get RMS from stability profiles + + void MonitoringFile::L1CaloStabilityRMS(TFile* f, const TString& nameDir, + const TString& nameTag) { + + TString nameData("ppm_em_2d_profile_etaPhi_adc_" + nameTag); + TString nameError("ppm_em_2d_etaPhi_adc_" + nameTag + "RMS"); + L1CaloFillWithError(f, nameDir, nameData, nameError); + nameData = "ppm_had_2d_profile_etaPhi_adc_" + nameTag; + nameError = "ppm_had_2d_etaPhi_adc_" + nameTag + "RMS"; + L1CaloFillWithError(f, nameDir, nameData, nameError); + } + + // Fill second histogram with error from first + + void MonitoringFile::L1CaloFillWithError(TFile* f, const TString& nameDir, + const TString& nameData, const TString& nameError) { + + const bool debug = L1CALOPOSTPROCESSDEBUG; + + // Check directory + if( !(f->GetDirectory(nameDir)) ) { + if (debug) std::cout << "--> L1CaloPostProcess: directory " + << nameDir << " not found." << std::endl; + return; + } + if (f->cd(nameDir.Data()) == 0) { + if (debug) std::cout << "dir " << nameDir << " isn't there!" << std::endl; + return; + } + + // Data histogram + TString p1 = nameDir + "/" + nameData; + if ( ! CheckHistogram(f, p1.Data()) ) { + if (debug) std::cout << " histo " << p1.Data() << " is not in file " + << f->GetName() << std::endl; + return; + } + TH1* h1 = (TH1*) (f->Get(p1.Data())); + + // Error histogram + TString p2 = nameDir + "/" + nameError; + if ( ! CheckHistogram(f, p2.Data()) ) { + if (debug) std::cout << " histo " << p2.Data() << " is not in file " + << f->GetName() << std::endl; + return; + } + TH1* h2 = (TH1*) (f->Get(p2.Data())); + + // Consistency checks + const int dim = h1->GetDimension(); + if (dim != h2->GetDimension()) { + if (debug) std::cout << "Histograms have different dimension" << std::endl; + return; + } + if (h1->GetNbinsX() != h2->GetNbinsX() || + ((dim == 2) && (h1->GetNbinsY() != h2->GetNbinsY()))) { + if (debug) std::cout << "Histograms have different number of bins" << std::endl; + return; + } + + // Fill error histogram + h2->Reset(); + int nbins = h1->GetNbinsX() + 2; + if (dim == 2) nbins *= (h1->GetNbinsY() + 2); + for (int bin = 0; bin < nbins; ++bin) { + double error = h1->GetBinError(bin); + if (error != 0.) h2->SetBinContent(bin, error); + } + + // And save + h2->Write("", TObject::kOverwrite); + f->Write(); + + } + + // Reset efficiencies to 100% for bins with low stats + + void MonitoringFile::L1CaloResetEfficiencies(TFile* f, const TString& effDir, + const TString& nameDen, const TString& nameEff, + int items, double threshold, int binSkip) { + + const bool debug = L1CALOPOSTPROCESSDEBUG; + + // Check directory + if( !(f->GetDirectory(effDir)) ) { + if (debug) std::cout << "--> L1CaloPostProcess: directory " + << effDir << " not found." << std::endl; + return; + } + if (f->cd(effDir.Data()) == 0) { + if (debug) std::cout << "dir " << effDir << " isn't there!" << std::endl; + return; + } + + // Denominator histogram + TString denPath = effDir + "/denominator/" + nameDen; + TH1* h1 = (TH1*) (f->Get(denPath.Data())); + if ( !h1 ) { + if (debug) std::cout << " histo " << denPath << " is not in file " + << f->GetName() << std::endl; + return; + } + if (h1->GetDimension() != 2) { + if (debug) std::cout << " histo " << denPath << " has unexpected dimension" + << std::endl; + return; + } + + // Efficiency histograms + int xbins = h1->GetNbinsX(); + int ybins = h1->GetNbinsY(); + std::vector<TH1*> effVec; + TString str; + TString effBase = effDir + "/" + nameEff; + for (int i = 0; i < items; ++i) { + str.Form("_%i", i); + TString effPath = effBase + str; + TH1* h2 = (TH1*) (f->Get(effPath.Data())); + if ( !h2 ) { + if (debug) std::cout << " histo " << effPath << " is not in file " + << f->GetName() << std::endl; + continue; + } + if (h2->GetDimension() != 2) { + if (debug) std::cout << " histo " << effPath << " has unexpected dimension" + << std::endl; + continue; + } + if (xbins != h2->GetNbinsX() || ybins != h2->GetNbinsY()) { + if (debug) std::cout << " histos " << denPath << " and " << effPath + << " have different number of bins" << std::endl; + continue; + } + effVec.push_back(h2); + } + if (effVec.empty()) { + if (debug) std::cout << "No valid histograms in " << effDir << std::endl; + return; + } + std::vector<TH1*>::iterator iter; + std::vector<TH1*>::iterator iterEnd = effVec.end(); + + // Loop over bins in denominator looking for entries below threshold + for (int x = 1 + binSkip; x <= xbins - binSkip; ++x) { + for (int y = 1; y <= ybins; ++y) { + if (h1->GetBinContent(x, y) < threshold) { + // Loop over efficiency histograms and set bin to 100% efficiency + for (iter = effVec.begin(); iter != iterEnd; ++iter) { + (*iter)->SetBinContent(x, y, 100.0); + } + } + } + } + + // Save the updated histograms + for (iter = effVec.begin(); iter != iterEnd; ++iter) { + (*iter)->Write("", TObject::kOverwrite); + } + f->Write(); + } + +} + +#undef L1CALOPOSTPROCESSDEBUG diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_MDTPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_MDTPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..61c6c51ccd52e3fa47983f00d2689e0b73c9e00e --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_MDTPostProcess.cxx @@ -0,0 +1,2179 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +///////////////////////////////////////////////////////////////////////////////////////////////// +//Method Process MDT Offline Histos After Merging +//Author Justin Griffiths griffith@cern.ch +// Orin Harris omh@cern.ch +//Created Apr 2009 +//Aug 2009 Major Update To Communicate w/ Database +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <stdio.h> +#include <map> +#include <iomanip> +#include <set> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" +#include "TList.h" + +#include "DataQualityUtils/CoolMdt.h" +#include "DataQualityUtils/MdtDeadNoisyUtils.h" + +namespace dqutils { + + void MonitoringFile::MDTPostProcess( std::string inFilename, bool isIncremental, int txtFileOutputType, bool useOfflineTubeID, bool makePDF, bool doAllPDF ) + { + // std::cout << "Running MDT post processing \n" ; + + bool goodMDTFile = MonitoringFile::MDTCheck( inFilename ); + + if(goodMDTFile){ + MonitoringFile::MDTChamReAlign( inFilename ); + MonitoringFile::MDTChamReAlign( inFilename, "MDT_express"); + MonitoringFile::MDTChamEff( inFilename, isIncremental, "MDT", txtFileOutputType, useOfflineTubeID, makePDF, doAllPDF); + MonitoringFile::MDTChamEff( inFilename, isIncremental, "MDT_express", txtFileOutputType, useOfflineTubeID, makePDF, doAllPDF); + MonitoringFile::MDTChamOcc( inFilename ); + MonitoringFile::MDTTDCSum( inFilename ); + MonitoringFile::MDTTDCSum( inFilename, "MDT_express" ); + MonitoringFile::MDTLowStat( inFilename ); + } + else std::cout << "No MDT Directory!" << std::endl; + +// std::cout << "\n"; +// std::cout << "Finish MDT analysis"<<std::endl; + return; + } + + void MonitoringFile::MDTChamReAlign(std::string inFilename, std::string _title_){ + // std::cout << "Begin ReAlign MDT Chamber by Chamber Plots" << std::endl; + + if(MDTCheckAlign(inFilename, _title_)) {/*std::cout << "File Already Aligned. Exiting..." << std::endl;*/ return;} + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + if (f == 0) { + std::cerr << "MDTPostProcess(): " + << "Input file not opened \n"; + return; + } + if(f->GetSize()<1000.) { + std::cerr << "MDTPostProcess(): " + << "Input file empty \n"; + return; + } + + TIter nextcd0(f->GetListOfKeys()); + while(TKey *key0 = dynamic_cast<TKey*> (nextcd0())){ + if (key0 == 0) continue; + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + if (dir0 == 0) return; + + TString runNumber = dir0->GetName(); + TString mDir = runNumber+"/Muon/MuonRawDataMonitoring/" + _title_; + TDirectory* mdt_base_dir = f->GetDirectory(mDir); + if (! mdt_base_dir) continue; + TIter nextcd1(mdt_base_dir->GetListOfKeys()); + // std::cout << mDir << std::endl; + while(TKey* key1 = dynamic_cast<TKey*>(nextcd1())) {//While in BA/EA/BC/EC + TString ecap_fullStr = mDir+"/"+key1->GetName(); + // TDirectory *dir1 = dynamic_cast<TDirectory*>(key1->ReadObj()); + TDirectory* dir1 = f->GetDirectory(ecap_fullStr); + if(!dir1) continue; + dir1->cd(); + //Determine which directory to put new folders into + if(strncmp(key1->GetName(),"Sum",2)==0)continue; + if(strncmp(key1->GetName(),"Ove",2)==0)continue; + if(gDirectory->GetDirectory("Chambers")) gDirectory->cd("Chambers"); + else if(gDirectory->GetDirectory("Chamber")) gDirectory->cd("Chamber"); + + dir1 = gDirectory; + TIter nextcd2(gDirectory->GetListOfKeys()); + + TString metadataName; + //The following if is a relic the else is what is likely to occur + if(!(strncmp(key1->GetName(),dir1->GetName(),2)==0)) metadataName = mDir+"/"+key1->GetName()+"/"+gDirectory->GetName()+"/metadata"; + else metadataName = mDir +"/"+key1->GetName()+"/metadata"; + TTree* metadata = 0; (f->GetObject(metadataName,metadata)); + char nameData[99]; + char intervalData[99]; + char chainData[99]; + char mergeData[99]; + TBranch* b_nameData; + TBranch* b_intervalData; + TBranch* b_chainData; + TBranch* b_mergeData; + + if(metadata){ + metadata->SetBranchAddress("Interval",intervalData,&b_intervalData); + metadata->SetBranchAddress("Name",nameData,&b_nameData); + metadata->SetBranchAddress("TriggerChain",chainData,&b_chainData); + metadata->SetBranchAddress("MergeMethod",mergeData,&b_mergeData); + } + + int treeCounter = 0; + TTree* metadata_new = 0; + OutputMetadata* outputmd = 0; + TKey* key2 = 0; + TDirectory* chambDir = 0; + TDirectory* lastChamb = 0; + + while( (key2 = dynamic_cast<TKey*> (nextcd2()) ) != 0){ + if(strncmp(key2->GetName(),"metadata",5)==0){ + continue; + } + if(metadata) {metadata->GetEntry(treeCounter); ++treeCounter;} + TString name = key2->GetName(); + if(TClass::GetClass(key2->GetClassName())->InheritsFrom("TDirectory")) { continue; } + TString chamberName = name(0,7); + + if(!(chambDir = dir1->GetDirectory(chamberName))) { + //First Save the new TTree to the last directory + if(metadata_new){ + if(lastChamb) lastChamb->cd(); + metadata_new->Write(); + delete metadata_new; + } + chambDir = dir1->mkdir(chamberName); + if(!chambDir) chambDir = dir1->GetDirectory(chamberName); + //Create New MetaData to be stored later; + metadata_new = new TTree( "metadata", "Monitoring Metadata" ); + metadata_new->SetDirectory(0); + delete outputmd; + outputmd = new OutputMetadata( metadata_new ); + } + lastChamb = chambDir; + // dir1->cd(chamberName); + chambDir->cd(); + // TObject* obj = key2->ReadObj(); + TH1* obj = dynamic_cast<TH1*> (dir1->Get(key2->GetName())); + TH1* obj2 = dynamic_cast<TH1*> (chambDir->Get(key2->GetName())); + if(obj2 && obj) { obj->Add(obj2); } + if(obj) { obj->SetFillColor(42); obj->Write("",TObject::kOverwrite); } + dir1->cd(); + delete obj; + if(obj2) delete obj2; + key2->Delete(); + if(outputmd) outputmd->fill(nameData,intervalData,chainData,mergeData); + } + //Fill the metadata for the last directories + if(metadata_new && chambDir) {chambDir->cd(); metadata_new->Write(); } + + TIter nextcd3(dir1->GetListOfKeys()); + TKey* key3 = 0; + //Delete Straglers (1 Folder for each of BA/BC/EA/EC) + while( (key3 = dynamic_cast<TKey*> (nextcd3()) ) != 0){ + TString histName = key3->GetName(); + if(!TClass::GetClass(key3->GetClassName())->InheritsFrom("TDirectory")) { key3->Delete();} + } + delete outputmd; + } + } + + f->Close(); + // std::cout << "End ReAlign MDT Chamber by Chamber Plots" << std::endl; + delete f; + return; + } + + void MonitoringFile::MDTChamEff( std::string inFilename, bool isIncremental, std::string _title_, int txtFileOutputType, bool useOfflineTubeID, bool makePDF, bool doAllPDF) { + const float m_noiseCut = 100000; + + MDTPostProcessor mf( inFilename, "ChamberEff Calculations"); + + if ( !mf.IsOpen() ) { + std::cerr << "MDTPostProcess(): " + << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + std::cerr << "MDTPostProcess(): " + << "Input file empty \n"; + return; + } + + int numAllTubes = 0; + int numDeadTubes = 0; + int numDeadTubes_All = 0; + int numNoisyTubes = 0; + int numAllMezz = 0; + int numDeadMezz = 0; + int numAllLayers = 0; + int numDeadLayers = 0; + int numAllML = 0; + int numDeadML = 0; + int numDeadChambers = 0; + int totBA = 330; int totBC = 328; + // int totEA = 231; int totEC = 231;// assuming 5 EE chambers on out of 31 + int totEA = 233; int totEC = 257; //assuming 7 EEA chambers, 31 EEC chambers + int numAllChambers = totBA + totBC + totEA + totEC; + //////////////////////////////////////////////////////////////////////////////////////////////////// + //////These Lines Open the Cool DB Files Needed for database Writing + //////////////////////////////////////////////////////////////////////////////////////////////////// + // std::cout << "Opening cool DB..." << std::endl; + CoolMdt* coolmdt_dead = 0; + if(isIncremental == false && _title_ == "MDT") { + coolmdt_dead = new CoolMdt(); + coolmdt_dead->initialize(); + coolmdt_dead->coolDbFolder("sqlite://;schema=MDTDQMFOFFLINE_DEAD.db;dbname=MDT_DQA","/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_DEAD"); + } + CoolMdt* coolmdt_noisy = 0; + if(isIncremental == false && _title_ == "MDT") { + coolmdt_noisy = new CoolMdt(); + coolmdt_noisy->initialize(); + coolmdt_noisy->coolDbFolder("sqlite://;schema=MDTDQMFOFFLINE_NOISY.db;dbname=MDT_DQA","/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_NOISY"); + } + //////////////////////////////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////////////////////////////// + //////Create a PDF of Dead/Noisy Results + //////////////////////////////////////////////////////////////////////////////////////////////////// + std::vector<TCanvas*> myFiles; + std::vector<TString> ecaps; + if(makePDF){ + ecaps.push_back("MDTBADead"); ecaps.push_back("MDTBCDead"); ecaps.push_back("MDTEADead"); ecaps.push_back("MDTECDead"); + for(int i = 0; i != 4; ++i){ + TCanvas* c = new TCanvas(); + myFiles.push_back(c); + } + int DetEleRef = 0; + for(std::vector<TCanvas*>::const_iterator myItr = myFiles.begin();myItr!=myFiles.end(); ++myItr, ++DetEleRef){ + std::ostringstream Out; + Out << inFilename << "." << ecaps.at(DetEleRef) << ".pdf"; + std::ostringstream O_out; + std::ostringstream C_out; + O_out <<Out.str() <<"["; + (*myItr)->Print(O_out.str().c_str(), "pdf"); + } + } + //////////////////////////////////////////////////////////////////////////////////////////////////// + + // TIter next_run ( f->GetListOfKeys() ); + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + TString run_dir = key_run->GetName(); + ////Needed for Database + int runNumber_int = TString(run_dir(4,run_dir.Length()-4)).Atoi(); + if(runNumber_int<0) std::cerr << "Bad Run Number " << runNumber_int << std::endl; + int ChannelIdCounter = 0; + //// + + if (!run_dir.Contains("run") ) continue; + //Compute Tube Effs + TString chamber_Area = run_dir + "/Muon/MuonRawDataMonitoring/"+_title_+"/"; + // if(f->cd(chamber_Area)) f->cd(chamber_Area); + if(mf.GetDirectory(chamber_Area)) mf.cd(chamber_Area); + //else {std::cerr << "No MDT Directory! " << std::endl; f->Close() ; delete f; return; } + else {/*std::cout << "No MDT Directory! " << std::endl;*/ mf.error(); return; } + TIter next_ecap(gDirectory->GetListOfKeys()); + // TDirectory* dir_Overview = f->GetDirectory(chamber_Area+"Overview/"); + TDirectory* dir_Overview = mf.GetDirectory(chamber_Area+"Overview/"); + //Get Global Chamber Effs + if(!dir_Overview) continue; + bool EffG = true; + TH2F* EffBCap = 0; + TH2F* EffECap = 0; + mf.get("EffsInBarrelPerChamber_ADCCut", EffBCap, dir_Overview); + mf.get("EffsInEndCapPerChamber_ADCCut", EffECap, dir_Overview); + if( !EffBCap ) mf.get("effsInBarrelPerChamber_ADCCut", EffBCap, dir_Overview); + if( !EffECap ) mf.get("effsInEndCapPerChamber_ADCCut", EffECap, dir_Overview); + // TH1F* hNTriggers = 0; mf.get("TotalNumber_of_MDT_hits_per_event_ADCCut", hNTriggers, dir_Overview); + //We get the noise and bkgrd hist from the MDT folder, thus nTriggers must come from there as well + TH1F* hNTriggers = 0; mf.get(run_dir + "/Muon/MuonRawDataMonitoring/MDT/Overview/TotalNumber_of_MDT_hits_per_event_ADCCut",hNTriggers); + int nTriggers = 1; + if(hNTriggers) { + nTriggers = (int) hNTriggers->GetEntries(); + } + std::map<TString, float> bkgrd_map; + std::map<TString, float> noise_map; + std::map<TString, int> nTubes_map; + + //Get number_of_Chambers_with_hits_per_event, number_of_Chambers_with_hits_per_event_ADCCut, TotalNumber_of_MDT_hits_per_event_big, TotalNumber_of_MDT_hits_per_event_big_ADCCut + //...for the purpose of changing their directory/metadata + TH1F* hNumChambHitsPerEvt = 0; + TH1F* hNumChambHitsPerEvtADCCut = 0; + TH1F* hTotNumMDTHitsPerEvtBig = 0; + TH1F* hTotNumMDTHitsPerEvtBigADCCut = 0; + mf.get("number_of_Chambers_with_hits_per_event", hNumChambHitsPerEvt, dir_Overview); + mf.get("number_of_Chambers_with_hits_per_event_ADCCut", hNumChambHitsPerEvtADCCut, dir_Overview); + mf.get("TotalNumber_of_MDT_hits_per_event_big", hTotNumMDTHitsPerEvtBig, dir_Overview); + mf.get("TotalNumber_of_MDT_hits_per_event_big_ADCCut", hTotNumMDTHitsPerEvtBigADCCut, dir_Overview); + + //////////////////////////////////////////////////////////////////////////////////////////////////// + ///////Create Noisy/Dead element histos and noise rate////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////// + TH1F* hDeadElements = new TH1F("MDTDeadElements","MDTDeadElements",1,0,1); + TH1F* hNoisyElements = new TH1F("MDTNoisyElements","MDTNoisyElements",1,0,1); + TH1F* hNoiseRate = new TH1F("TubeRate","TubeRate; Rate [kHz]; counts",1000,0,100); + TDirectory* dir_Overview_expert = dir_Overview->GetDirectory("Expert"); + if(!dir_Overview_expert) dir_Overview_expert = dir_Overview->mkdir("Expert"); + mf.setMetaData(dir_Overview_expert,hDeadElements); + mf.setMetaData(dir_Overview_expert,hNoisyElements); + // Create new directory for all the noise/bkd rate info + TDirectory* dir_Overview_expert_noisebkd = dir_Overview_expert->GetDirectory("Noise_Bkgrd_Rate"); + if(!dir_Overview_expert_noisebkd) dir_Overview_expert_noisebkd = dir_Overview_expert->mkdir("Noise_Bkgrd_Rate"); + mf.setMetaData(dir_Overview_expert_noisebkd,hNoiseRate); + //////////////////////////////////////////////////////////////////////////////////////////////////// + ///////Finish Creating histos Noisy/Dead elements/////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////// + + TH2F* EffECap_N = 0; + TH2F* EffBCap_N = 0; + + // Create chamber volume map, for weighting occupancy plots + TH2F * VolumeMapBCap = 0; + TH2F * VolumeMapECap = 0; + TH2F * VolumeMapBCap_noisecut = 0; + TH2F * VolumeMapECap_noisecut = 0; + + // new occ plots, hits/evt/chamber-volume + TH2F* EvtTubeNormOccBCap = 0; + TH2F* EvtTubeNormOccECap = 0; + TH2F* EvtTubeNormOccNoiseCutBCap = 0; + TH2F* EvtTubeNormOccNoiseCutECap = 0; + // raw hits/evt occ plots + TDirectory* dir_Overview_expert_RawHits = dir_Overview_expert->GetDirectory("RawHitsPerChamber"); + if(!dir_Overview_expert_RawHits) dir_Overview_expert_RawHits = dir_Overview_expert->mkdir("RawHitsPerChamber"); + TH2F* EvtOccBCap = 0; + TH2F* EvtOccECap = 0; + TH2F* EvtOccNoiseCutBCap = 0; + TH2F* EvtOccNoiseCutECap = 0; + + // noise vs eff hists + TH1F* EffVSNoise_num = new TH1F("EffVSNoise_num","Tube eff_num vs tube noise rate",50,0,1000); + mf.setDirectory(EffVSNoise_num); + TH1F* EffVSNoise_den = new TH1F("EffVSNoise_den","Tube eff_den vs tube noise rate",50,0,1000); + mf.setDirectory(EffVSNoise_den); + TH1F* EffVSNoise_ADCCut_num = new TH1F("EffVSNoise_ADCCut_num","Tube eff_num vs tube (ADC>80) noise rate",50,0,1); + mf.setDirectory(EffVSNoise_ADCCut_num); + TH1F* EffVSNoise_ADCCut_den = new TH1F("EffVSNoise_ADCCut_den","Tube eff_den vs tube (ADC>80) noise rate",50,0,1); + mf.setDirectory(EffVSNoise_ADCCut_den); + TH1F* EffVSBkd_num = new TH1F("EffVSBkd_num","Tube eff_num vs tube (ADC>80) bkd rate",50,0,1); + mf.setDirectory(EffVSBkd_num); + TH1F* EffVSBkd_den = new TH1F("EffVSBkd_den","Tube eff_den vs tube (ADC>80) bkd rate",50,0,1); + mf.setDirectory(EffVSBkd_den); + + //Plots to Fill Noise/Bkgrd Occupancy + TH2F* NoiseBCap = 0; + TH2F* NoiseECap = 0; + TH2F* BkgrdBCap = 0; + TH2F* BkgrdECap = 0; + + if(!EffBCap || !EffECap) { std::cerr << "No Global Eff Plots" << std::endl; EffG=false; } + if(EffG) { + MDTResetContents(EffBCap); + MDTResetContents(EffECap); + // Create chamber volume map, for weighting occupancy plots + VolumeMapBCap = (TH2F*) EffBCap->Clone(); + VolumeMapECap = (TH2F*) EffECap->Clone(); + VolumeMapBCap->SetName("VolumeMapBarrel"); + VolumeMapBCap->SetTitle("Volume Map (#tubes*tubeVol in m^3) Barrel"); + VolumeMapECap->SetName("VolumeMapEndcap"); + VolumeMapECap->SetTitle("Volume Map (#tubes*tubeVol in m^3) Endcap"); + mf.setMetaData(dir_Overview_expert, VolumeMapBCap, VolumeMapECap); + VolumeMapBCap_noisecut = (TH2F*) EffBCap->Clone(); + VolumeMapECap_noisecut = (TH2F*) EffECap->Clone(); + VolumeMapBCap_noisecut->SetName("VolumeMapBarrel_noisecut"); + VolumeMapBCap_noisecut->SetTitle("Volume Map (m^3) Barrel, 100KHz noise cut"); + VolumeMapECap_noisecut->SetName("VolumeMapEndcap_noisecut"); + VolumeMapECap_noisecut->SetTitle("Volume Map (m^3) Endcap, 100KHz noise cut"); + mf.setMetaData(dir_Overview_expert, VolumeMapBCap_noisecut, VolumeMapECap_noisecut); + EffBCap_N = (TH2F*) EffBCap->Clone(); + EffECap_N = (TH2F*) EffECap->Clone(); + mf.setDirectory(EffBCap_N); + mf.setDirectory(EffECap_N); + NoiseBCap = (TH2F*) EffBCap->Clone(); + NoiseECap = (TH2F*) EffECap->Clone(); + NoiseBCap->SetName("AverageNoisePerTubeBarrel"); + NoiseBCap->SetTitle("Avg # noise-hits/evt/m^3 Barrel"); + NoiseECap->SetName("AverageNoisePerTubeEndcap"); + NoiseECap->SetTitle("Avg # noise-hits/evt/m^3 Endcap"); + mf.setMetaData(dir_Overview_expert_noisebkd, NoiseBCap, NoiseECap); + BkgrdBCap = (TH2F*) EffBCap->Clone(); + BkgrdECap = (TH2F*) EffECap->Clone(); + BkgrdBCap->SetName("AverageBkgrdPerTubeBarrel"); + BkgrdBCap->SetTitle("Avg # bkgrd-hits/evt/m^3 Barrel"); + BkgrdECap->SetName("AverageBkgrdPerTubeEndcap"); + BkgrdECap->SetTitle("Avg # bkgrd-hits/evt/m^3 Endcap"); + mf.setMetaData(dir_Overview_expert_noisebkd, BkgrdECap, BkgrdBCap); + // Raw hits per event + EvtOccBCap = (TH2F*) EffBCap->Clone(); + EvtOccECap = (TH2F*) EffECap->Clone(); + EvtOccBCap->SetName("HitsPerEvtInBarrelPerChamber_ADCCut"); + EvtOccBCap->SetTitle("Avg # hits/evt Barrel, ADCCut"); + EvtOccECap->SetName("HitsPerEvtInEndCapPerChamber_ADCCut"); + EvtOccECap->SetTitle("Avg # hits/evt Endcap, ADCCut"); + mf.setMetaData(dir_Overview_expert_RawHits, EvtOccBCap, EvtOccECap); + EvtOccNoiseCutBCap = (TH2F*) EffBCap->Clone(); + EvtOccNoiseCutECap = (TH2F*) EffECap->Clone(); + EvtOccNoiseCutBCap->SetName("HitsPerEvtInBarrelPerChamber_ADCCut_NoiseCut"); + EvtOccNoiseCutBCap->SetTitle("Avg # hits/evt Barrel, ADCCut, 100KHz noise cut"); + EvtOccNoiseCutECap->SetName("HitsPerEvtInEndCapPerChamber_ADCCut_NoiseCut"); + EvtOccNoiseCutECap->SetTitle("Avg # hits/evt Endcap, ADCCut, 100KHz noise cut"); + mf.setMetaData(dir_Overview_expert_RawHits, EvtOccNoiseCutBCap, EvtOccNoiseCutECap); + } + while( TKey* key_ecap = dynamic_cast<TKey*> (next_ecap()) ) {//BA,BC,EA,EC + if(strncmp(key_ecap->GetName(),"Overvi",6)==0) continue; + if(strncmp(key_ecap->GetName(),"Summar",6)==0) continue; + TString ecap_str = key_ecap->GetName(); + TString ecap_fullStr = ecap_str; + ecap_str = ecap_str(3,2); + TString ecapPath_str = chamber_Area+ecap_fullStr+"/Chambers"; + + // TDirectory* dir1 = f->GetDirectory(ecapPath_str); + TDirectory* dir1 = mf.GetDirectory(ecapPath_str); + if(!dir1) continue; + TIter next_cham(dir1->GetListOfKeys()); + TString overview_str = chamber_Area+ecap_fullStr+"/Overview/"; + // TDirectory* dir_Overview_local = f->GetDirectory(overview_str); + TDirectory* dir_Overview_local = mf.GetDirectory(overview_str); + //Get Local Chamber Effs + bool EffL = true; + bool EffInner_old = true; // protect agains pre-BIR/BIM separation + TH2F* EffExtra = 0; + TH2F* EffInner = 0; + TH2F* EffMiddle = 0; + TH2F* EffOuter = 0; + TH2F* EffExtra_N = 0; + TH2F* EffInner_N = 0; + TH2F* EffMiddle_N = 0; + TH2F* EffOuter_N = 0; + + TString ecap_fullStr_lower = "mdt"+ecap_str; + TH1F* heff = new TH1F(ecap_fullStr_lower+"_TUBE_eff",ecap_fullStr_lower+"_TUBE_eff",100,0,1); + TH1F* heffML = new TH1F(ecap_fullStr_lower+"_ML_eff",ecap_fullStr_lower+"_ML_eff",50,0,1); + //Histogram To Trivially measure coverage per tube + int totalTube_region = 0; + int totalDead_region = 0; + TH1F* hTubeOcc = new TH1F(ecap_fullStr_lower+"_Occupancy",ecap_fullStr_lower+"_Tube_Occupancy",1,0,1); + mf.setMetaData(dir_Overview_local, heff, heffML, hTubeOcc); + + if(dir_Overview_local){ + mf.get("EffsIn"+ecap_str+"InnerPerMultiLayer_ADCCut",EffInner,dir_Overview_local); + mf.get("EffsIn"+ecap_str+"MiddlePerMultiLayer_ADCCut",EffMiddle,dir_Overview_local); + mf.get("EffsIn"+ecap_str+"OuterPerMultiLayer_ADCCut",EffOuter,dir_Overview_local); + mf.get("EffsIn"+ecap_str+"ExtraPerMultiLayer_ADCCut",EffExtra,dir_Overview_local); + if(!EffInner) mf.get("effsIn"+ecap_str+"InnerPerMultiLayer_ADCCut",EffInner,dir_Overview_local); + if(!EffMiddle) mf.get("effsIn"+ecap_str+"MiddlePerMultiLayer_ADCCut",EffMiddle,dir_Overview_local); + if(!EffOuter) mf.get("effsIn"+ecap_str+"OuterPerMultiLayer_ADCCut",EffOuter,dir_Overview_local); + if(!EffExtra) mf.get("effsIn"+ecap_str+"ExtraPerMultiLayer_ADCCut",EffExtra,dir_Overview_local); + } + if(!EffExtra || !EffInner || ! EffMiddle || !EffOuter) { std::cerr << "No Local Chamber Eff Plots" << std::endl; EffL = false;} + + if(EffL) { +// EffExtra->Reset();EffOuter->Reset();EffMiddle->Reset();EffInner->Reset(); + MDTResetContents((TH2F*)EffExtra); MDTResetContents((TH2F*)EffOuter); MDTResetContents((TH2F*)EffMiddle); MDTResetContents((TH2F*)EffInner); + EffExtra_N = (TH2F*) EffExtra->Clone(); + EffInner_N = (TH2F*) EffInner->Clone(); + EffMiddle_N = (TH2F*) EffMiddle->Clone(); + EffOuter_N = (TH2F*) EffOuter->Clone(); + mf.setDirectory(EffExtra_N); + mf.setDirectory(EffInner_N); + mf.setDirectory(EffMiddle_N); + mf.setDirectory(EffOuter_N); + if(EffInner->GetNbinsY() == 36) EffInner_old = false; + } + + std::vector<TString> chamberNames_vec; + std::vector<float> chamberHits_vec;//get median value of hits per chamber in order to count HV off chambers + while( TKey* key_cham = (TKey*) (next_cham()) ){//Chamber Folders + if(strncmp(key_cham->GetName(),"meta",4)==0) continue; + TString chamberStr = chamber_Area+ecap_fullStr+"/Chambers/"+key_cham->GetName(); + TDirectory* dirChamb = mf.GetDirectory(chamberStr); + if(!dirChamb) continue; + if(!(dirChamb)->InheritsFrom("TDirectory")) continue; + TString dirName = dirChamb->GetName(); + chamberNames_vec.push_back(dirName); + TH1F* tube = 0; mf.get(dirName+"_MDT_Station_TUBE_ADCCut",tube,dirChamb); + if(tube) { + chamberHits_vec.push_back((float) tube->GetEntries()); + } + } + std::sort( chamberHits_vec.begin(), chamberHits_vec.end() ); + double medianChamberHits = 0; + unsigned nChambers_ = chamberHits_vec.size(); + if(nChambers_%2==0 && nChambers_ > 2) medianChamberHits = (chamberHits_vec.at(nChambers_/2) + chamberHits_vec.at(nChambers_/2 + 1))/nChambers_; + else if(nChambers_>0) medianChamberHits = chamberHits_vec.at(nChambers_/2); + int chamberCounter = 0; + for(std::vector<TString>::const_iterator chamberStrItr = chamberNames_vec.begin(); chamberStrItr != chamberNames_vec.end(); ++chamberStrItr, ++chamberCounter){ + TString dirName = *chamberStrItr; + // TDirectory* dirChamb = f->GetDirectory(chamber_Area+ecap_fullStr+"/Chambers/"+dirName); + TDirectory* dirChamb = mf.GetDirectory(chamber_Area+ecap_fullStr+"/Chambers/"+dirName); + if(!dirChamb) continue; + if(dirName=="BML6A13"||dirName=="BML6C13") continue;//These chambers do not exist + if(dirName(0,2)=="EE" && dirName(4,1) == "A"){// All EE C chambers are installed. Only 3, 5(1), 11, 13 exist on A + if(!(dirName(3,4)=="1A05" || dirName(5,2) == "03" || dirName(5,2)=="11" || dirName(5,2)=="13")) continue; + } + //////////////////////////////////////////////////////////////////////////////////////////////////// + //////Dead Noisy Tube Calculations + //////////////////////////////////////////////////////////////////////////////////////////////////// + ////Arbitrary counter for database file + bool hvOff = false; + bool noDeadLayer = true; //flag to determine if chamber has dead ml,l, or mezz + ChannelIdCounter++; + TH1F* den = 0; mf.get(dirName+"_MDT_Station_EFFENTRIES",den,dirChamb); + TH1F* num = 0; mf.get(dirName+"_MDT_Station_EFFCOUNTS",num,dirChamb); + TH1F* bkgrd = 0; mf.get(dirName+"_MDT_Station_TUBE_BKGRD_ADCCut",bkgrd,dirChamb); + if(!bkgrd) mf.get(run_dir + "/Muon/MuonRawDataMonitoring/MDT/" + ecap_fullStr + "/Chambers/" + dirName + "/" + dirName + "_MDT_Station_TUBE_BKGRD_ADCCut", bkgrd); + TH1F* noise = 0; mf.get(dirName+"_MDT_Station_TUBE_fornoise",noise,dirChamb); + if(!noise) mf.get(run_dir + "/Muon/MuonRawDataMonitoring/MDT/" + ecap_fullStr + "/Chambers/" + dirName + "/" + dirName + "_MDT_Station_TUBE_fornoise", noise); + TH1F* tube = 0; mf.get(dirName+"_MDT_Station_TUBE_ADCCut",tube,dirChamb); + unsigned numTubesInChamber = tube->GetNbinsX(); + if(noise && tube && bkgrd && den && num) { + totalTube_region += numTubesInChamber; + // std::cout << "Beginning noisy/dead tube calc..." << std::endl; + if( (dirName.BeginsWith("BIS8") || dirName.BeginsWith("BE"))) { + if(tube->GetEntries() < 0.01 * medianChamberHits + 0.1) hvOff = true; + } + else if ( tube->GetEntries() < 0.07 * medianChamberHits + 0.1 ) hvOff = true; + + if(hvOff) { + // std::cout << "Found HV Off " << dirName << std::endl; + numDeadTubes_All += numTubesInChamber; + totalDead_region += numTubesInChamber; + numDeadChambers++; + } + std::string cool_tag="Reco"; + int deadTubesChamberValidity = 1; + int noisyTubesChamberValidity = 1; + std::vector<int> deadML_v = dqutils_mdtdeadnoisy::FindDeadML(tube, dirName); + TString deadML = ConvertVectorToString(deadML_v); + std::vector<int> deadLayer_v = dqutils_mdtdeadnoisy::FindDeadLayer(tube, dirName, deadML_v); + TString deadLayer = ConvertLayerVectorToString(deadLayer_v, dirName); + std::vector<int> deadMezz_v = dqutils_mdtdeadnoisy::FindDeadMezz(tube, dirName, deadML_v); + TString deadMezz = ConvertMezzVectorToString(deadMezz_v, tube, dirName); + std::vector<int> deadASD_v; + TString deadASD = ConvertVectorToString(deadASD_v); + std::vector<int> deadTubes_v = dqutils_mdtdeadnoisy::GetDeadTubes(tube, deadTubesChamberValidity, deadML_v, deadLayer_v, deadMezz_v); + TString deadTubes = ConvertTubeVectorToString(deadTubes_v, tube, dirName); + + std::vector<int> noisyTubes_v = dqutils_mdtdeadnoisy::GetNoisyTubes(noise, nTriggers, m_noiseCut); // Absolute Noise freq-based criteria + std::vector<int> noisyTubes_forCool_v = dqutils_mdtdeadnoisy::GetNoisyTubes(noise, nTriggers, 10000.); // Absolute Noise freq-based criteria + // std::vector<int> noisyTubes_forCool_v = dqutils_mdtdeadnoisy::GetNoisyTubes(noise, tube, dirName, noisyTubesChamberValidity); // Relative-based criteria + if(noisyTubes_forCool_v.size()<=50) { // If the entire chamber is noisy then the reconstruction of segments and therefore effs might be screwed up + dqutils_mdtdeadnoisy::CatalogNoisyEff(bkgrd, noise, num, den, nTriggers, EffVSNoise_num, EffVSNoise_den, EffVSNoise_ADCCut_num, EffVSNoise_ADCCut_den, EffVSBkd_num, EffVSBkd_den); + } + TString noisyTubes_forCool = ConvertTubeVectorToString(noisyTubes_forCool_v,tube,dirName); + if(coolmdt_dead) coolmdt_dead->insertDeadFlag_withTag(runNumber_int, ChannelIdCounter, dirName.Data(), + deadML.Data(), deadLayer.Data(), deadMezz.Data(), "", deadTubes.Data(), cool_tag); + if(coolmdt_noisy) coolmdt_noisy->insertNoisyFlag_withTag(runNumber_int, ChannelIdCounter, dirName.Data(), "", "", "", "", noisyTubes_forCool.Data(), cool_tag); + if(!hvOff) { + numAllTubes += dqutils_mdtdeadnoisy::GetNumNonMaskedTubes(tube); + numAllMezz += dqutils_mdtdeadnoisy::GetNumMezz(tube); + numAllLayers += dqutils_mdtdeadnoisy::GetNumML(dirName) * dqutils_mdtdeadnoisy::GetNumLayersPerML(dirName); + numAllML += dqutils_mdtdeadnoisy::GetNumML(dirName); + if( deadMezz_v.size() || deadML_v.size() || deadLayer_v.size() ) noDeadLayer = false; + numDeadTubes += deadTubes_v.size(); + numNoisyTubes += noisyTubes_v.size(); + numDeadMezz += deadMezz_v.size(); + numDeadLayers += deadLayer_v.size(); + numDeadML += deadML_v.size(); + numDeadTubes_All += deadTubes_v.size(); + totalDead_region += deadTubes_v.size(); + for(unsigned i = 0; i != deadMezz_v.size(); ++i) { + int deadTubes = dqutils_mdtdeadnoisy::GetNumTubesPerMezz( dirName, deadMezz_v.at(i)); + numDeadTubes_All += deadTubes; + totalDead_region += deadTubes; + } + for(unsigned i = 0; i != deadLayer_v.size(); ++i) { + int deadTubes = dqutils_mdtdeadnoisy::GetNumTubesPerLayer( dirName, deadLayer_v.at(i), numTubesInChamber); + numDeadTubes_All += deadTubes; + totalDead_region += deadTubes; + } + for(unsigned i = 0; i != deadML_v.size(); ++i) { + int deadTubes = dqutils_mdtdeadnoisy::GetNumTubesPerML( dirName, deadML_v.at(i), numTubesInChamber); + numDeadTubes_All += deadTubes; + totalDead_region += deadTubes; + } + } + // text file and pdf output + if(txtFileOutputType > 0) { + + int noisyTubesChamberValidityForMasked = 1; + std::vector<int> noisyTubes_forMasked_v = dqutils_mdtdeadnoisy::GetNoisyTubes_WithoutForNoise(tube, noisyTubesChamberValidityForMasked, dirName); // Relative-based criteria + TString noisyTubes_forMasked = ConvertTubeVectorToString(noisyTubes_forMasked_v,tube,dirName); + + if(makePDF) { + int ref = 0; + if(ecap_str=="BC") ref = 1; + else if (ecap_str=="EA") ref = 2; + else ref = 3; + // Here use forMasked (relative-based) in pdfs, meant for checking generated noisy tube list (txtFileOutputType == 3) + std::vector<int> empty_v; + if(txtFileOutputType == 3) dqutils_mdtdeadnoisy::FillPDF(inFilename, tube, noise, myFiles.at(ref), + &empty_v, &empty_v, &empty_v, &empty_v, &empty_v, + &noisyTubes_forMasked_v, 0, 0, 0, 0, + 1, noisyTubesChamberValidityForMasked, + true, false, true, false, true, doAllPDF); + // Otherwise use forCool in pdfs, meant for looking over all issues (dead, noisy elements) + else dqutils_mdtdeadnoisy::FillPDF(inFilename, tube, noise, myFiles.at(ref), + &deadTubes_v, &deadASD_v, &deadMezz_v, &deadLayer_v, &deadML_v, + &noisyTubes_forCool_v, 0, 0, 0, 0, + deadTubesChamberValidity, noisyTubesChamberValidity, + true, false, true, true, true, doAllPDF); + } + + ofstream txtfile; + std::string textfilename = inFilename + ".Summary.txt"; + txtfile.open(textfilename.c_str(), std::ios::app); + if( txtfile.is_open() ) { + if( deadML.Length() != 0 || deadML.Length() != 0 || deadLayer.Length() != 0 || deadASD.Length() != 0 || deadTubes.Length() != 0 || noisyTubes_forCool.Length() != 0 || noisyTubes_forMasked.Length() != 0 ) { + if(txtFileOutputType == 1) { + txtfile << "Chamber: " << dirName.Data() << std::endl; + if( deadML.Length() != 0 ) txtfile << " Dead Multilayers: " << deadML << std::endl; + if( deadLayer.Length() != 0 ) txtfile << " Dead Layers: " << deadLayer << std::endl; + if( deadMezz.Length() != 0 ) txtfile << " Dead Mezz: " << deadMezz << std::endl; + if( deadASD.Length() != 0 ) txtfile << " Dead ASD: " << deadASD << std::endl; + if( deadTubes.Length() != 0 ) txtfile << " Dead Tubes: " << deadTubes << std::endl; + if( noisyTubes_forCool.Length() != 0 ) txtfile << " Noisy Tubes (For COOL DB): " << noisyTubes_forCool << std::endl; + if( noisyTubes_forCool.Length() != 0 ) txtfile << " Noisy Tubes (For our masked list): " << noisyTubes_forMasked << std::endl; + } + if(txtFileOutputType == 2) { //For creation of masked tube list, only output if less than 10% of chamber is noisy (to avoid masking whole noisy chambers) + if(noisyTubes_forCool_v.size() < numTubesInChamber / 10.0 ) { + for(unsigned i=0; i<noisyTubes_forCool_v.size(); ++i) { + if(!useOfflineTubeID) txtfile << dirName.Data() << " " << TubeID_to_ID_L_ML(noisyTubes_forCool_v.at(i), dirName, numTubesInChamber) << std::endl; + else txtfile << dirName.Data() << " " << noisyTubes_forCool_v.at(i) << std::endl; + } +// //For outputting in single-line format +// if( noisyTubes_forCool_v.size() > 0 ) { +// txtfile << dirName.Data() << " "; +// for(unsigned i=0; i<noisyTubes_forCool_v.size(); ++i) { +// if(!useOfflineTubeID) txtfile << TubeID_to_ID_L_ML(noisyTubes_forCool_v.at(i), dirName, numTubesInChamber); +// else txtfile << noisyTubes_forCool_v.at(i); +// if(i<noisyTubes_forCool_v.size() - 1) txtfile << ","; +// } +// txtfile << std::endl; +// } + } + } + if(txtFileOutputType == 3) { //Alternate for creation of masked tube list + for(unsigned i=0; i<noisyTubes_forMasked_v.size(); ++i) { + if(!useOfflineTubeID) txtfile << dirName.Data() << " " << TubeID_to_ID_L_ML(noisyTubes_forMasked_v.at(i), dirName, numTubesInChamber) << std::endl; + else txtfile << dirName.Data() << " " << noisyTubes_forMasked_v.at(i) << std::endl; + } + } + if(txtFileOutputType == 4) { //Output all noisy tubes sent to COOL + for(unsigned i=0; i<noisyTubes_forCool_v.size(); ++i) { + if(!useOfflineTubeID) txtfile << dirName.Data() << " " << TubeID_to_ID_L_ML(noisyTubes_forCool_v.at(i), dirName, numTubesInChamber) << std::endl; + else txtfile << dirName.Data() << " " << noisyTubes_forCool_v.at(i) << std::endl; + } + } + if(txtFileOutputType == 5) { //Output all dead tubes sent to COOL + for(unsigned i=0; i<deadTubes_v.size(); ++i) { + if(!useOfflineTubeID) txtfile << dirName.Data() << " " << TubeID_to_ID_L_ML(deadTubes_v.at(i), dirName, numTubesInChamber) << std::endl; + else txtfile << dirName.Data() << " " << deadTubes_v.at(i) << std::endl; + } + } + if(txtFileOutputType == 6) { //Output Masked Tube List in ROOT file + TH1F* hMask = 0; mf.get(dirName+"_MDT_Station_TUBE_masked", hMask, dirChamb); + std::vector<int> currentNoisyTubes_v; + if(hMask) { + for( int ibin = 1; ibin != hMask->GetNbinsX() + 1; ++ibin){ + if( hMask->At(ibin) > 0.1 ) currentNoisyTubes_v.push_back(ibin); + } + } + for(unsigned i=0; i<currentNoisyTubes_v.size(); ++i) { // only a list of currently masked tubes + if(!useOfflineTubeID) txtfile << dirName.Data() << " " << TubeID_to_ID_L_ML(currentNoisyTubes_v.at(i), dirName, numTubesInChamber) << std::endl; + else txtfile << dirName.Data() << " " << currentNoisyTubes_v.at(i) << std::endl; + } + } + } + } + } + } + // else std::cout << "MDT_Station_TUBE_fornoise or MDT_Station_TUBE_ADCCut histo not found!" << std::endl; + //////////////////////////////////////////////////////////////////////////////////////////////////// + //////End Noisy Tube Calculations + //////////////////////////////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////////////////////////////// + //////FillBackground Plots Calculations + //////////////////////////////////////////////////////////////////////////////////////////////////// + if( noise && tube && bkgrd ) { + TH1F* noise_clone = (TH1F*) noise->Clone(); + noise_clone->Scale(1./nTriggers/300.*1e9); + TH1F* bkgrd_clone = (TH1F*) bkgrd->Clone(); + bkgrd_clone->Scale(1./nTriggers/300.*1e9); + int nTubes_noiseCut = 0; + int nHits_noiseCut = 0; + int nHits = (int)tube->GetEntries(); + + for( int ibin = 1; ibin != bkgrd_clone->GetNbinsX()+1; ++ibin){ + if(noise_clone->At(ibin) <= m_noiseCut) { + nTubes_noiseCut++; + nHits_noiseCut += (int)tube->At(ibin); + } + } + + // For filling Bkgrd/Noise Occupancy plots + TString xAxis = dirName(0,1)+dirName(4,1)+dirName(3,1); + TString yAxis = dirName(1,1)+","+dirName(5,2); + //Seperate BIR/MXA11/15 + if( (dirName(0,3) == "BIR" || dirName(0,3) == "BIM") && (dirName(5,2) == "11" || dirName(5,2) == "15" ) && VolumeMapBCap->GetNbinsY() >= 58){ + yAxis += ","; + yAxis += dirName(2,1); + } + //BML[45][AC]13-->BML[56][AC]13 + if( dirName(0,3) == "BML" && TString(dirName(3,1)).Atoi() >= 4 && dirName(5,2) == "13" && VolumeMapBCap->GetNbinsY() >= 58 ) + xAxis = dirName(0,1) + dirName(4,1) + returnString( TString(dirName(3,1)).Atoi() + 1 ); + double tubeLength = 4.9615; +// double maxTubeLengthBarrel = 4961.5; // just FYI +// double maxTubeLengthEndcap = 5941.5; // just FYI + GetTubeLength(tubeLength,dirName); // should always fill tubeLength + double chamb_vol = (double)numTubesInChamber*tubeLength*0.0006881; // 0.0006881 m2 = pi*tube_r^2 + double noiseCut_vol = (double)nTubes_noiseCut*tubeLength*0.0006881; // these represent the total volume in (m3) covered by the tubes in the chamber + + // Fill volume maps regardless of whether the chamber is called dead + if(xAxis.BeginsWith("B")) { + VolumeMapBCap->Fill(xAxis,yAxis,chamb_vol); + VolumeMapBCap_noisecut->Fill(xAxis,yAxis,noiseCut_vol); + } + else { + VolumeMapECap->Fill(xAxis,yAxis,chamb_vol); + VolumeMapECap_noisecut->Fill(xAxis,yAxis,noiseCut_vol); + } + + // Only do the rest if chamber is not called dead + if( !hvOff ) { + TString eta_ring = dirName(0,2) + dirName(4,1); + TString eta_stat = dirName(3,1); + if(eta_stat=="5"||eta_stat=="6"||eta_stat=="7"||eta_stat=="8") eta_ring+="5,6"; + if(eta_stat=="3"||eta_stat=="4") eta_ring+="3,4"; + if(eta_stat=="1"||eta_stat=="2"||eta_stat=="0") eta_ring+="1,2"; + float noise_rate = 0; + float noise_hits = 0; + float bkgrd_rate = 0; + float bkgrd_hits = 0; + + for( int ibin = 1; ibin != bkgrd_clone->GetNbinsX()+1; ++ibin){ + hNoiseRate->Fill(noise_clone->At(ibin)/1000.); + if(noise_clone->At(ibin) <= m_noiseCut) { + noise_rate += noise_clone->At(ibin); + bkgrd_rate += bkgrd_clone->At(ibin); + noise_hits += noise->At(ibin); + bkgrd_hits += bkgrd->At(ibin); + } + } + + if(xAxis.BeginsWith("B")) { + NoiseBCap->Fill(xAxis, yAxis, noise_hits / ((double)nTriggers) ); + BkgrdBCap->Fill(xAxis, yAxis, bkgrd_hits / ((double)nTriggers) ); + EvtOccBCap->Fill( xAxis, yAxis, nHits / ((double)nTriggers) ); + EvtOccNoiseCutBCap->Fill(xAxis, yAxis, nHits_noiseCut / ((double)nTriggers) ); + } + else { + NoiseECap->Fill(xAxis, yAxis, noise_hits / ((double)nTriggers) ); + BkgrdECap->Fill(xAxis, yAxis, bkgrd_hits / ((double)nTriggers) ); + EvtOccECap->Fill( xAxis, yAxis, nHits / ((double)nTriggers) ); + EvtOccNoiseCutECap->Fill(xAxis, yAxis, nHits_noiseCut / ((double)nTriggers) ); + } + + std::map<TString,float>::iterator noise_itr = noise_map.find(eta_ring); + std::map<TString,float>::iterator bkgrd_itr = bkgrd_map.find(eta_ring); + std::map<TString,int>::iterator nTubes_itr = nTubes_map.find(eta_ring); + if( noise_itr == noise_map.end() ) noise_map.insert(std::make_pair(eta_ring,noise_rate)); + else (*noise_itr).second += noise_rate; + if( bkgrd_itr == bkgrd_map.end() ) bkgrd_map.insert(std::make_pair(eta_ring,bkgrd_rate)); + else (*bkgrd_itr).second += bkgrd_rate; + if( nTubes_itr == nTubes_map.end() ) nTubes_map.insert(std::make_pair(eta_ring,nTubes_noiseCut)); + else (*nTubes_itr).second += nTubes_noiseCut; + + //////////////////////////////////////////////////////////////////////////////////////////////////// + //////End FillBackground Plots Calculations + //////Next do Efficiencies + //////////////////////////////////////////////////////////////////////////////////////////////////// + + TH1F* eff = new TH1F(dirName+"_MDT_Station_EFFPERTUBE",dirName+"_MDT_Station_EFFPERTUBE; tubeID; Number of Entries",numTubesInChamber,1,numTubesInChamber+1); + mf.setMetaData(dirChamb,eff); + if(!eff || !num || !den) continue; + + float countsML1, countsML2, entriesML1, entriesML2; + MDTTubeEff(dirName,num,den,eff,countsML1,countsML2,entriesML1,entriesML2); + //Fill heff if no dead layer,ML, or Mezz + if(noDeadLayer) { + for(int ibin = 1; ibin != eff->GetNbinsX(); ++ibin) { + if( den->At(ibin) > 10 ) heff->Fill( (num->At(ibin))/(den->At(ibin)) ); + } + } + + ///Set the char labels for the efficiency plots + TString stateta_IMO_c; TString statphi_IMO_c; TString stateta_c; TString statphi_c; TString statphi_c2; + MDT2DHWName(dirName, stateta_IMO_c, statphi_IMO_c, stateta_c, statphi_c, statphi_c2); + //correct for BI[R/M][A/C][11/15] + //Move BML[4,5][A/C]13-->BML[5,6][A/C]13 + stateta_IMO_c = xAxis; + statphi_IMO_c = yAxis; + + if(EffG){ + if( entriesML1 + entriesML2 > 10 ) { + if(ecap_str(0,1)=="B") { + EffBCap->Fill(stateta_IMO_c,statphi_IMO_c,countsML1+countsML2); + EffBCap_N->Fill(stateta_IMO_c,statphi_IMO_c,entriesML1+entriesML2); + } + else { + EffECap->Fill(stateta_IMO_c,statphi_IMO_c,countsML1+countsML2); + EffECap_N->Fill(stateta_IMO_c,statphi_IMO_c,entriesML1+entriesML2); + } + } + } + if(EffL){ + if(dirName(1,1)=="E") { + if( entriesML1 > 10 ) { + EffExtra->Fill(stateta_c, statphi_c, countsML1); + EffExtra_N->Fill(stateta_c, statphi_c, entriesML1); + } + if( entriesML2 > 10 ) { + if(dirName(1,0)=="E"){ + EffExtra->Fill(stateta_c, statphi_c2, countsML2); + EffExtra_N->Fill(stateta_c,statphi_c2, entriesML2); + } + } + } + if(dirName(1,1)=="I" && (!EffInner_old || dirName(0,1)=="E")) { + if( entriesML1 > 10 ) { + EffInner->Fill(stateta_c, statphi_c, countsML1); + EffInner_N->Fill(stateta_c, statphi_c, entriesML1); + } + if( entriesML2 > 10 ) { + EffInner->Fill(stateta_c, statphi_c2, countsML2); + EffInner_N->Fill(stateta_c,statphi_c2, entriesML2); + } + } + if(dirName(1,1)=="M") { + if( entriesML1 > 10 ) { + EffMiddle->Fill(stateta_c, statphi_c, countsML1); + EffMiddle_N->Fill(stateta_c, statphi_c, entriesML1); + } + if( entriesML2 > 10 ) { + EffMiddle->Fill(stateta_c, statphi_c2, countsML2); + EffMiddle_N->Fill(stateta_c,statphi_c2, entriesML2); + } + } + if(dirName(1,1)=="O") { + if( entriesML1 > 10 ) { + EffOuter->Fill(stateta_c, statphi_c, countsML1); + EffOuter_N->Fill(stateta_c, statphi_c, entriesML1); + } + if( entriesML2 > 10 ) { + EffOuter->Fill(stateta_c, statphi_c2, countsML2); + EffOuter_N->Fill(stateta_c,statphi_c2, entriesML2); + } + } + } + dirChamb->cd(); + eff->Write("",TObject::kOverwrite); + //Write to the file periodically + //Wish we didn't have to do this + // if(ChannelIdCounter%20==0) mf.Write(); + if(noDeadLayer) { if( entriesML2 > 10 ) heffML->Fill(countsML2/entriesML2); if( entriesML1 > 10 ) heffML->Fill(countsML1/entriesML1); } + } + delete bkgrd_clone; + delete noise_clone; + } + }//Chamber Folders + if(EffL && dir_Overview_local){ + dir_Overview_local->cd(); + heff->Write("",TObject::kOverwrite); + heffML->Write("",TObject::kOverwrite); + EffExtra->Divide(EffExtra_N); + EffInner->Divide(EffInner_N); + EffMiddle->Divide(EffMiddle_N); + EffOuter->Divide(EffOuter_N); + //Only Write Histogram if it originally had 36 y-axis bins + if(ecap_str(0,1)=="E") {EffInner->Write("",TObject::kOverwrite); } + else if(!EffInner_old) {EffInner->Write("",TObject::kOverwrite); } + else delete EffInner_N; + EffMiddle->Write("",TObject::kOverwrite); + EffOuter->Write("",TObject::kOverwrite); + EffExtra->Write("",TObject::kOverwrite); + hTubeOcc->Fill("%_Tubes_On", 1-totalDead_region*1./totalTube_region); + hTubeOcc->Fill("%_Dead_Frac", totalDead_region*1./totalTube_region); + hTubeOcc->LabelsDeflate("x"); + hTubeOcc->Write("",TObject::kOverwrite); + } + }//End BA,BC,EA,EC + if(EffG){ + if(dir_Overview_expert){ + dir_Overview_expert->cd(); + // Few histos moving to expert dir + mf.setMetaData(dir_Overview_expert, hNumChambHitsPerEvt, hNumChambHitsPerEvtADCCut); + if(hTotNumMDTHitsPerEvtBigADCCut && hTotNumMDTHitsPerEvtBig) mf.setMetaData(dir_Overview_expert, hTotNumMDTHitsPerEvtBig, hTotNumMDTHitsPerEvtBigADCCut); + hNumChambHitsPerEvt->Write("",TObject::kOverwrite); + hNumChambHitsPerEvtADCCut->Write("",TObject::kOverwrite); + if(hTotNumMDTHitsPerEvtBig) hTotNumMDTHitsPerEvtBig->Write("",TObject::kOverwrite); + if(hTotNumMDTHitsPerEvtBigADCCut) hTotNumMDTHitsPerEvtBigADCCut->Write("",TObject::kOverwrite); + // Chamber volume maps // these are used below -- make sure they are left before the writes below +// VolumeMapBCap->Scale(1./VolumeMapBCap->GetMaximum()); + MDTSet2DRangeZ(VolumeMapBCap); + VolumeMapBCap->Write("",TObject::kOverwrite); +// VolumeMapECap->Scale(1./VolumeMapECap->GetMaximum()); + MDTSet2DRangeZ(VolumeMapECap); + VolumeMapECap->Write("",TObject::kOverwrite); +// VolumeMapBCap_noisecut->Scale(1./VolumeMapBCap_noisecut->GetMaximum()); + MDTSet2DRangeZ(VolumeMapBCap_noisecut); + VolumeMapBCap_noisecut->Write("",TObject::kOverwrite); +// VolumeMapECap_noisecut->Scale(1./VolumeMapECap_noisecut->GetMaximum()); + MDTSet2DRangeZ(VolumeMapECap_noisecut); + VolumeMapECap_noisecut->Write("",TObject::kOverwrite); + // Hits per vol per event + EvtTubeNormOccBCap = (TH2F*) EvtOccBCap->Clone(); + EvtTubeNormOccECap = (TH2F*) EvtOccECap->Clone(); + EvtTubeNormOccBCap->SetName("NormedHitsInBarrelPerChamber_ADCCut"); + EvtTubeNormOccBCap->SetTitle("Avg # hits/evt/m^3 Barrel, ADCCut"); + EvtTubeNormOccECap->SetName("NormedHitsInEndCapPerChamber_ADCCut"); + EvtTubeNormOccECap->SetTitle("Avg # hits/evt/m^3 Endcap, ADCCut"); + mf.setMetaData(dir_Overview, EvtTubeNormOccBCap, EvtTubeNormOccECap); + EvtTubeNormOccBCap->Divide(VolumeMapBCap); + MDTSet2DRangeZ(EvtTubeNormOccBCap); + EvtTubeNormOccBCap->Write("",TObject::kOverwrite); + EvtTubeNormOccECap->Divide(VolumeMapECap); + MDTSet2DRangeZ(EvtTubeNormOccECap); + EvtTubeNormOccECap->Write("",TObject::kOverwrite); + } + if(dir_Overview) { + dir_Overview->cd(); + // Hits per vol per event, noise cut + EvtTubeNormOccNoiseCutBCap = (TH2F*) EvtOccNoiseCutBCap->Clone(); + EvtTubeNormOccNoiseCutECap = (TH2F*) EvtOccNoiseCutECap->Clone(); + EvtTubeNormOccNoiseCutBCap->SetName("NormedHitsInBarrelPerChamber_ADCCut_NoiseCut"); + EvtTubeNormOccNoiseCutBCap->SetTitle("Avg # hits/evt/m^3 Barrel, ADCCut, 100KHz noise cut"); + EvtTubeNormOccNoiseCutECap->SetName("NormedHitsInEndCapPerChamber_ADCCut_NoiseCut"); + EvtTubeNormOccNoiseCutECap->SetTitle("Avg # hits/evt/m^3 Endcap, ADCCut, 100KHz noise cut"); + mf.setMetaData(dir_Overview, EvtTubeNormOccNoiseCutBCap, EvtTubeNormOccNoiseCutECap); + EvtTubeNormOccNoiseCutBCap->Divide(VolumeMapBCap_noisecut); + MDTSet2DRangeZ(EvtTubeNormOccNoiseCutBCap); + EvtTubeNormOccNoiseCutBCap->Write("",TObject::kOverwrite); + EvtTubeNormOccNoiseCutECap->Divide(VolumeMapECap_noisecut); + MDTSet2DRangeZ(EvtTubeNormOccNoiseCutECap); + EvtTubeNormOccNoiseCutECap->Write("",TObject::kOverwrite); + } + if(dir_Overview_expert_noisebkd){ + dir_Overview_expert_noisebkd->cd(); + NoiseBCap->Divide(VolumeMapBCap_noisecut); + MDTSet2DRangeZ(NoiseBCap); + NoiseBCap->Write("",TObject::kOverwrite); + NoiseECap->Divide(VolumeMapECap_noisecut); + MDTSet2DRangeZ(NoiseECap); + NoiseECap->Write("",TObject::kOverwrite); + BkgrdBCap->Divide(VolumeMapBCap_noisecut); + MDTSet2DRangeZ(BkgrdBCap); + BkgrdBCap->Write("",TObject::kOverwrite); + BkgrdECap->Divide(VolumeMapECap_noisecut); + MDTSet2DRangeZ(BkgrdECap); + BkgrdECap->Write("",TObject::kOverwrite); + } + if(dir_Overview_expert_RawHits) { + dir_Overview_expert_RawHits->cd(); + // Raw hits per event (don't divide by volume map) + MDTSet2DRangeZ(EvtOccBCap); + EvtOccBCap->Write("",TObject::kOverwrite); + MDTSet2DRangeZ(EvtOccECap); + EvtOccECap->Write("",TObject::kOverwrite); + MDTSet2DRangeZ(EvtOccNoiseCutBCap); + EvtOccNoiseCutBCap->Write("",TObject::kOverwrite); + MDTSet2DRangeZ(EvtOccNoiseCutECap); + EvtOccNoiseCutECap->Write("",TObject::kOverwrite); + } + } + //////////////////////////////////////////////////////////////////////////////////////////////////// + //////MakePDF + //////////////////////////////////////////////////////////////////////////////////////////////////// + if(makePDF){ + int DetEleRef = 0; + for(std::vector<TCanvas*>::const_iterator myItr = myFiles.begin();myItr!=myFiles.end(); ++myItr, ++DetEleRef){ + std::ostringstream Out; + Out << inFilename << "." << ecaps.at(DetEleRef) << ".pdf"; + std::ostringstream C_out; + C_out << Out.str() <<"]"; + (*myItr)->Print(C_out.str().c_str(), "pdf"); + delete *myItr; + } + } + // make corresponding summary text file + if(txtFileOutputType > 0) { + ofstream txtfile; + std::string textfilename = inFilename + ".Summary.txt"; + txtfile.open(textfilename.c_str(), std::ios::app); + if( txtfile.is_open() ) { + txtfile.precision(3); + txtfile << "************************************************************************************************" << std::endl; + txtfile << "**** Global summary of dead/noisy analysis: " << std::endl; + txtfile << "******** Tubes: " << std::setw(8) << numAllTubes << ", Dead: " << std::setw(8) << std::fixed << 100.0 * (double)numDeadTubes / (double)numAllTubes << "%, Noisy: " << std::setw(8) << 100.0 * (double)numNoisyTubes / (double)numAllTubes << "%" << std::endl; + txtfile << "******** Mezzanines: " << std::setw(8) << numAllMezz << ", Dead: " << std::setw(8) << std::fixed << 100.0 * (double)numDeadMezz / (double)numAllMezz << "%, Noisy: " << std::setw(9) << "n/a" << std::endl; + txtfile << "******** Layers: " << std::setw(8) << numAllLayers << ", Dead: " << std::setw(8) << std::fixed << 100.0 * (double)numDeadLayers / (double)numAllLayers << "%, Noisy: " << std::setw(9) << "n/a" << std::endl; + txtfile << "******** Multilayers: " << std::setw(8) << numAllML << ", Dead: " << std::setw(8) << std::fixed << 100.0 * (double)numDeadML / (double)numAllML << "%, Noisy: " << std::setw(9) << "n/a" << std::endl; + txtfile << "******** Chambers: " << std::setw(8) << numAllChambers << ", Dead: " << std::setw(8) << std::fixed << 100.0 * (double)numDeadChambers / (double)numAllChambers << "%, Noisy: " << std::setw(9) << "n/a" << std::endl; + txtfile.close(); + } + } + //Fill Dead element info + hDeadElements->Fill("Chambers",numDeadChambers); + hDeadElements->Fill("MultiLayers",numDeadML); + hDeadElements->Fill("Layers",numDeadLayers); + hDeadElements->Fill("Mezzanines",numDeadMezz); + hDeadElements->Fill("Tubes",numDeadTubes); + hDeadElements->Fill("AllTubes",numDeadTubes_All); + hNoisyElements->Fill("Chambers",0); + hNoisyElements->Fill("MultiLayers",0); + hNoisyElements->Fill("Layers",0); + hNoisyElements->Fill("Mezzanines",0); + hNoisyElements->Fill("Tubes",numNoisyTubes); + //Fill Bkgrd/Noise Info + TH1F* bkgrd_summary = new TH1F("bkgrd_summary","Background Rate; Region; average rate per tube [Hz]",1,0,1); + TH1F* noise_summary = new TH1F("noise_summary","Noise Rate; Region; average rate per tube [Hz]",1,0,1); + mf.setMetaData(dir_Overview_expert_noisebkd, bkgrd_summary, noise_summary); + TH1F* BA_bkgrd = new TH1F("BA_bkgrd","Background Rate in Eta Rings BA; Eta Ring; average rate per tube [Hz]",1,0,1); + TH1F* BA_noise = new TH1F("BA_noise","Noise Rate in Eta Rings BA; Eta Ring; average rate per tube [Hz]",1,0,1); + mf.setMetaData(dir_Overview_expert_noisebkd, BA_bkgrd, BA_noise); + TH1F* BC_bkgrd = new TH1F("BC_bkgrd","Background Rate in Eta Rings BC; Eta Ring; average rate per tube [Hz]",1,0,1); + TH1F* BC_noise = new TH1F("BC_noise","Noise Rate in Eta Rings BC; Eta Ring; average rate per tube [Hz]",1,0,1); + mf.setMetaData(dir_Overview_expert_noisebkd, BC_bkgrd, BC_noise); + TH1F* EA_bkgrd = new TH1F("EA_bkgrd","Background Rate in Eta Rings EA; Eta Ring; average rate per tube [Hz]",1,0,1); + TH1F* EA_noise = new TH1F("EA_noise","Noise Rate in Eta Rings EA; Eta Ring; average rate per tube [Hz]",1,0,1); + mf.setMetaData(dir_Overview_expert_noisebkd, EA_bkgrd, EA_noise); + TH1F* EC_bkgrd = new TH1F("EC_bkgrd","Background Rate in Eta Rings EC; Eta Ring; average rate per tube [Hz]",1,0,1); + TH1F* EC_noise = new TH1F("EC_noise","Noise Rate in Eta Rings EC; Eta Ring; average rate per tube [Hz]",1,0,1); + mf.setMetaData(dir_Overview_expert_noisebkd, EC_bkgrd, EC_noise); + float bkgrd_overall = 0; float bkgrd_BA = 0; float bkgrd_BC = 0; float bkgrd_EA = 0; float bkgrd_EC = 0; + float noise_overall = 0; float noise_BA = 0; float noise_BC = 0; float noise_EA = 0; float noise_EC = 0; + int nTubes_overall = 0; int nTubes_BA = 0; int nTubes_BC = 0; int nTubes_EA = 0; int nTubes_EC = 0; + for(std::map<TString,float>::const_iterator m_itr = bkgrd_map.begin(); m_itr != bkgrd_map.end(); ++m_itr){ + TString eta_ring = (*m_itr).first; + float bkgrd = (*m_itr).second; + float noise = 0; + int nTubes = 0; + std::map<TString,float>::const_iterator n_itr = noise_map.find(eta_ring.Data()); + std::map<TString,int>::const_iterator t_itr = nTubes_map.find(eta_ring.Data()); + if( n_itr != noise_map.end()) noise = (*n_itr).second; + if( t_itr != nTubes_map.end()) nTubes = (*t_itr).second; + bkgrd_overall+=bkgrd; + noise_overall+=noise; + nTubes_overall+=nTubes; + if(eta_ring(0,1)=="B" && eta_ring(2,1)=="A") { + bkgrd_BA+=bkgrd; noise_BA+=noise; nTubes_BA+=nTubes; + if( eta_ring.Sizeof() >= 5 && eta_ring(1,1)!="E") { + BA_bkgrd->Fill(eta_ring, bkgrd/nTubes); + BA_noise->Fill(eta_ring, noise/nTubes); + } + } + if(eta_ring(0,1)=="B" && eta_ring(2,1)=="C") { + bkgrd_BC+=bkgrd; noise_BC+=noise; nTubes_BC+=nTubes; + if( eta_ring.Sizeof() >= 5 && eta_ring(1,1)!="E") { + BC_bkgrd->Fill(eta_ring, bkgrd/nTubes); + BC_noise->Fill(eta_ring, noise/nTubes); + } + } + if(eta_ring(0,1)=="E" && eta_ring(2,1)=="A") { + bkgrd_EA+=bkgrd; noise_EA+=noise; nTubes_EA+=nTubes; + if( eta_ring.Sizeof() >= 5 && eta_ring(1,1)!="E") { + EA_bkgrd->Fill(eta_ring, bkgrd/nTubes); + EA_noise->Fill(eta_ring, noise/nTubes); + } + } + if(eta_ring(0,1)=="E" && eta_ring(2,1)=="C") { + bkgrd_EC+=bkgrd; noise_EC+=noise; nTubes_EC+=nTubes; + if( eta_ring.Sizeof() >= 5 && eta_ring(1,1)!="E") { + EC_bkgrd->Fill(eta_ring, bkgrd/nTubes); + EC_noise->Fill(eta_ring, noise/nTubes); + } + } + } + bkgrd_summary->Fill("Overall",bkgrd_overall/nTubes_overall); bkgrd_summary->Fill("BA",bkgrd_BA/nTubes_BA); + bkgrd_summary->Fill("BC",bkgrd_BC/nTubes_BC); bkgrd_summary->Fill("EA",bkgrd_EA/nTubes_EA); bkgrd_summary->Fill("EC",bkgrd_EC/nTubes_EC); + noise_summary->Fill("Overall",noise_overall/nTubes_overall); noise_summary->Fill("BA",noise_BA/nTubes_BA); + noise_summary->Fill("BC",noise_BC/nTubes_BC); noise_summary->Fill("EA",noise_EA/nTubes_EA); noise_summary->Fill("EC",noise_EC/nTubes_EC); + + EffVSNoise_num->Sumw2(); + EffVSNoise_den->Sumw2(); + TH1F* EffVSNoise = (TH1F*)EffVSNoise_num->Clone(); + EffVSNoise->SetName("EffVSNoise"); + EffVSNoise->SetTitle("Tube eff vs tube noise rate"); + EffVSNoise->GetXaxis()->SetTitle("noise rate [KHz]"); + EffVSNoise->GetYaxis()->SetTitle("eff"); + EffVSNoise->Divide(EffVSNoise_num,EffVSNoise_den,1,1,"B"); + mf.setMetaData(dir_Overview_expert_noisebkd,EffVSNoise); + + EffVSNoise_ADCCut_num->Sumw2(); + EffVSNoise_ADCCut_den->Sumw2(); + TH1F* EffVSNoise_ADCCut = (TH1F*)EffVSNoise_ADCCut_num->Clone(); + EffVSNoise_ADCCut->SetName("EffVSNoise_ADCCut"); + EffVSNoise_ADCCut->SetTitle("Tube eff vs tube (ADC>80) noise rate"); + EffVSNoise_ADCCut->GetXaxis()->SetTitle("noise rate [KHz]"); + EffVSNoise_ADCCut->GetYaxis()->SetTitle("eff"); + EffVSNoise_ADCCut->Divide(EffVSNoise_ADCCut_num,EffVSNoise_ADCCut_den,1,1,"B"); + mf.setMetaData(dir_Overview_expert_noisebkd,EffVSNoise_ADCCut); + + EffVSBkd_num->Sumw2(); + EffVSBkd_den->Sumw2(); + TH1F* EffVSBkd = (TH1F*)EffVSBkd_num->Clone(); + EffVSBkd->SetName("EffVSBkd"); + EffVSBkd->SetTitle("Tube eff vs tube (ADC>80) bkd rate"); + EffVSBkd->GetXaxis()->SetTitle("background rate [KHz]"); + EffVSBkd->GetYaxis()->SetTitle("eff"); + EffVSBkd->Divide(EffVSBkd_num,EffVSBkd_den,1,1,"B"); + mf.setMetaData(dir_Overview_expert_noisebkd,EffVSBkd); + + if(dir_Overview_expert){ + dir_Overview_expert->cd(); + MDTFinalizeWriteTH1FChar(hNoisyElements); + MDTFinalizeWriteTH1FChar(hDeadElements); + } + + if(dir_Overview_expert_noisebkd && dir_Overview_expert){ + dir_Overview_expert_noisebkd->cd(); + hNoiseRate->Write("",TObject::kOverwrite); + EffVSNoise->Write("",TObject::kOverwrite); + EffVSNoise_ADCCut->Write("",TObject::kOverwrite); + EffVSBkd->Write("",TObject::kOverwrite); + MDTFinalizeWriteTH1FChar(bkgrd_summary); + MDTFinalizeWriteTH1FChar(noise_summary); + MDTFinalizeWriteTH1FChar(BA_bkgrd); + MDTFinalizeWriteTH1FChar(BA_noise); + MDTFinalizeWriteTH1FChar(BC_bkgrd); + MDTFinalizeWriteTH1FChar(BC_noise); + MDTFinalizeWriteTH1FChar(EA_bkgrd); + MDTFinalizeWriteTH1FChar(EA_noise); + MDTFinalizeWriteTH1FChar(EC_bkgrd); + MDTFinalizeWriteTH1FChar(EC_noise); + } + + TDirectory* dir_Overview_expert_reco = dir_Overview_expert->GetDirectory("RecoMonitoring"); + if(dir_Overview_expert_reco && dir_Overview_expert) { + dir_Overview_expert_reco->cd(); + // 2D eff histos -- divide and change metadata before writing to new reco dir + EffECap->Divide(EffECap_N); + EffBCap->Divide(EffBCap_N); + mf.setMetaData(dir_Overview_expert_reco, EffECap, EffBCap); + EffECap->Write("",TObject::kOverwrite); + EffBCap->Write("",TObject::kOverwrite); + } + + if(coolmdt_dead){delete coolmdt_dead;} + if(coolmdt_noisy){delete coolmdt_noisy;} + //////////////////////////////////////////////////////////////////////////////////////////////////// + }//While loop over run_XXX directory + + return; + } + + // This function is for grabbing overview hists from raw and doing something to them, rather than going through a chamber-by-chamber loop + void MonitoringFile::MDTChamOcc( std::string inFilename, std::string _title_ ) { + MDTPostProcessor mf( inFilename , "ChamberOcc Calculations"); + if (!mf.IsOpen()) { + std::cerr << "MDTPostProcess(): " + << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + std::cerr << "MDTPostProcess(): " + << "Input file empty \n"; + return; + } + + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + TString run_dir = key_run->GetName(); + if (!run_dir.Contains("run") ) continue; + + TDirectory* dir_Overview = mf.GetDirectory(run_dir + "/Muon/MuonRawDataMonitoring/"+_title_+"/Overview"); + if(!dir_Overview) continue; + TH1F* hNTriggers = 0; mf.get("TotalNumber_of_MDT_hits_per_event_ADCCut",hNTriggers,dir_Overview); + int nTriggers = 1; + if(hNTriggers) { + nTriggers = (int) hNTriggers->GetEntries(); + } + + TString expert_Area = run_dir + "/Muon/MuonRawDataMonitoring/MDT/Overview/Expert"; + TDirectory* dir_Overview_expert = mf.GetDirectory(expert_Area); +// if(dir_Overview_expert && OccECap && OccBCap) { +// mf.cd(expert_Area); +// TH2F* OccBCap = 0; mf.get("NumberOfHitsInBarrelPerChamber_ADCCut",OccBCap,dir_Overview); +// TH2F* OccECap = 0; mf.get("NumberOfHitsInEndCapPerChamber_ADCCut",OccECap,dir_Overview); +// TDirectory* dir_Overview_expert_RawHits = dir_Overview_expert->GetDirectory("RawHitsPerChamber"); +// if(!dir_Overview_expert_RawHits) dir_Overview_expert_RawHits = dir_Overview_expert->mkdir("RawHitsPerChamber"); +// dir_Overview_expert_RawHits->cd(); +// TH2F * OccBCap_norm = 0; +// OccBCap_norm = (TH2F*)OccBCap->Clone(); +// OccBCap_norm->Scale(1.0/(double)nTriggers); +// OccBCap_norm->SetName("HitsPerEventInBarrelPerChamber_ADCCut"); +// OccBCap_norm->SetTitle("Barrel Occupancy normalized to #events"); // these are completely deprecated now +// MDTSet2DRangeZ(OccBCap_norm); +// TH2F * OccECap_norm = 0; +// OccECap_norm = (TH2F*)OccECap->Clone(); +// OccECap_norm->Scale(1.0/(double)nTriggers); +// OccECap_norm->SetName("HitsPerEventInEndCapPerChamber_ADCCut"); +// OccECap_norm->SetTitle("EndCap Occupancy normalized to #events"); // these are completely deprecated now +// MDTSet2DRangeZ(OccECap_norm); +// mf.setMetaData(dir_Overview_expert_RawHits, OccBCap_norm, OccECap_norm); +// OccBCap_norm->Write("",TObject::kOverwrite); +// OccECap_norm->Write("",TObject::kOverwrite); +// } + + TString RecoMonArea = expert_Area+"/RecoMonitoring"; + TDirectory* dir_Overview_expert_reco = mf.GetDirectory(RecoMonArea); + if(dir_Overview_expert_reco && dir_Overview_expert) { + dir_Overview_expert_reco->cd(); + TH2F* OccBCap = 0; mf.get("NumberOfHitsInBarrelPerChamber_onSegm_ADCCut",OccBCap,dir_Overview_expert_reco); + TH2F* OccECap = 0; mf.get("NumberOfHitsInEndCapPerChamber_onSegm_ADCCut",OccECap,dir_Overview_expert_reco); + TH2F* VolumeMapBCap = 0; mf.get("VolumeMapBarrel",VolumeMapBCap,dir_Overview_expert); + TH2F* VolumeMapECap = 0; mf.get("VolumeMapEndcap",VolumeMapECap,dir_Overview_expert); + if( OccECap && OccECap && VolumeMapBCap && VolumeMapECap ){ + TH2F* OccBCap_norm = dynamic_cast<TH2F*> (OccBCap->Clone()); + TH2F* OccECap_norm = dynamic_cast<TH2F*> (OccECap->Clone()); + OccBCap_norm->Scale(1./nTriggers); + OccBCap_norm->Divide(VolumeMapBCap); + OccBCap_norm->SetName("HitsPerEventInBarrelPerChamber_onSegm_ADCCut"); + OccBCap_norm->SetTitle("Avg # hits-on-segm/evt/m^3 Barrel"); + OccECap_norm->Scale(1./nTriggers); + OccECap_norm->Divide(VolumeMapECap); + OccECap_norm->SetName("HitsPerEventInEndCapPerChamber_onSegm_ADCCut"); + OccECap_norm->SetTitle("Avg # hits-on-segm/evt/m^3 Endcap"); + MDTSet2DRangeZ(OccBCap_norm); + MDTSet2DRangeZ(OccECap_norm); + mf.setMetaData(dir_Overview_expert_reco, OccBCap_norm, OccECap_norm); + OccBCap_norm->Write("",TObject::kOverwrite); + OccECap_norm->Write("",TObject::kOverwrite); + } + } + + + }//While loop over run_XXX directory + + return; + } + + void MonitoringFile::MDTTDCSum( std::string inFilename, std::string _title_ ){ + + MDTPostProcessor mf( inFilename, "Sector t0,tmax, & tdrift Calculations"); + + if (!mf.IsOpen()) { + std::cerr << "MDTPostProcess(): " + << "Input file not opened \n"; + return; + } + + if(mf.GetSize()<1000.) { + std::cerr << "MDTPostProcess(): " + << "Input file empty \n"; + return; + } + + + TString run_dir = ""; + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if (tdir_run ==0 ) {delete obj_run; continue; } + TString tdir_run_name( tdir_run->GetName() ); + if (!tdir_run_name.Contains("run") ) continue; + run_dir=tdir_run_name; + + //Compute Summary Hists + TString Overview_Area = run_dir + "/Muon/MuonRawDataMonitoring/"+_title_; + TDirectory* dir_Main = 0; + + if(mf.cd(Overview_Area)) dir_Main = mf.GetDirectory(Overview_Area); + if(!dir_Main) { std::cerr << "No MDT Direcotry! "<< std::endl; mf.error(); return; } + + TIter next_ecap(dir_Main->GetListOfKeys()); + while( TKey* key_ecap = dynamic_cast<TKey*> (next_ecap()) ){//BA,BC,EA,EC + if(strncmp(key_ecap->GetName(),"Overvi",6)==0) continue; + if(strncmp(key_ecap->GetName(),"Summar",6)==0) continue; + TString dir_ecap_str = Overview_Area+"/"+key_ecap->GetName(); + // TDirectory* dir_ecap = dynamic_cast<TDirectory*> (key_ecap->ReadObj()); + TDirectory* dir_ecap = mf.GetDirectory(dir_ecap_str); + if(!dir_ecap) continue; + TString ecap_str = key_ecap->GetName(); + TString ecap_strFull = ecap_str; + if(ecap_str.Length()>4) ecap_str = ecap_str(3,2); + else ecap_str = ecap_str(0,2); + TIter next_Overview(dir_ecap->GetListOfKeys()); + while( TKey* key_Overview = dynamic_cast<TKey*> (next_Overview()) ){ //Overview Chambers + if(strncmp(key_Overview->GetName(),"Chambe",6)==0) continue; + TString sumt0_name = "MDT_t0_"+ecap_str; + TString sumtmax_name = "MDT_tmax_"+ecap_str; + TString sumtdrift_name = "MDT_tdrift_"+ecap_str; + TString dir_Overview_str = dir_ecap_str+"/"+key_Overview->GetName(); + // TDirectory* dir_Overview = dynamic_cast<TDirectory*> (key_Overview->ReadObj()); + TDirectory* dir_Overview = mf.GetDirectory(dir_Overview_str); + if(!dir_Overview) continue; + TH1F* sumt0 = new TH1F(sumt0_name,sumt0_name,1,0,1); + TH1F* sumtmax = new TH1F(sumtmax_name,sumtmax_name,1,0,1); + TH1F* sumtdrift = new TH1F(sumtdrift_name,sumtdrift_name,1,0,1); + mf.setDirectory(sumt0); + sumt0->SetFillColor(42); + sumt0->SetMarkerStyle(20); + sumt0->SetMarkerColor(42); + sumt0->SetAxisRange(400,800,"y"); + mf.setDirectory(sumtmax); + sumtmax->SetFillColor(42); + sumtmax->SetMarkerStyle(20); + sumtmax->SetMarkerColor(42); + sumtmax->SetAxisRange(800,1700,"y"); + mf.setDirectory(sumtdrift); + sumtdrift->SetFillColor(42); + sumtdrift->SetMarkerStyle(20); + sumtdrift->SetMarkerColor(42); + sumtdrift->SetAxisRange(0,1500,"y"); + if(!(sumtdrift && sumt0 && sumtmax)) { + std::cerr << "No Summary Histograms" << std::endl; + mf.error(); + return; + } + sumtmax->Reset(); sumt0->Reset(); sumtdrift->Reset(); + if(dir_Overview){ + if(!dir_Overview->GetDirectory("TDC")) continue; + } + TDirectory* dir_TDC = dir_Overview->GetDirectory("TDC"); //Directory of TDC spectra + TIter next_tdc(dir_TDC->GetListOfKeys()); + int currentbin = 1; + std::vector<TH1F*> hists; + while(TKey* key_TDC = dynamic_cast<TKey*> (next_tdc())){//TDC spectra + if(strncmp(key_TDC->GetName(),"metadata",6)==0) continue; + TH1F* h = 0; mf.get(key_TDC->GetName(),h,dir_TDC); + hists.push_back(h); + } + //TKeys now in alphabetical order after merge, revert to order they were initialized in ESDtoAOD step + std::sort(hists.begin(), hists.end(), tdcSort); + + for(std::vector<TH1F*>::const_iterator hitr = hists.begin(); hitr!=hists.end(); ++hitr){ + TH1F* h = *hitr; + if(!h) continue; + + double t0 = 0; + double t0err = 0; + double tmax = 0; + double tmaxerr = 0; + MDTFitTDC(h, t0, t0err, tmax, tmaxerr); + + TString layer; + if(currentbin<17) layer = "In"; + else if (currentbin<33) layer = "Mid"; + else if (currentbin<49) layer = "Out"; + else layer = "Ext"; + int stPhi = currentbin%16; + if(layer=="Ext" && (ecap_str=="BA"||ecap_str=="BC")) { + stPhi = 2*currentbin%16; + } + if(stPhi==0) stPhi=16; + + TString phi = returnString(stPhi); + + TString sector = ecap_str+"_"+layer+"_"+phi; + if(h->GetEntries()<100) sector+="_OFF"; + else if(t0err>t0) sector+="_ERR"; + sumt0->Fill(sector,t0); + sumt0->SetBinError(currentbin,t0err); + + sector = ecap_str+"_"+layer+"_"+phi; + if(h->GetEntries()<100) sector+="_OFF"; + else if(tmaxerr>tmax) sector+="_ERR"; + sumtmax->Fill(sector,tmax); + sumtmax->SetBinError(currentbin,tmaxerr); + + sector = ecap_str+"_"+layer+"_"+phi; + if(h->GetEntries()<100) sector+="_OFF"; + else if(tmaxerr>tmax || t0err>t0 || tmax-t0 < 0 || tmax-t0 > 2000) sector+="_ERR"; + if(tmax-t0 < 0 || tmax-t0 > 2000) { + sumtdrift->Fill(sector,0); + sumtdrift->SetBinError(currentbin,2000); + } + else { + sumtdrift->Fill(sector,tmax-t0); + sumtdrift->SetBinError(currentbin,sqrt(tmaxerr*tmaxerr + t0err*t0err)); + } + currentbin++;//initialized at 1 for first bin + if(dir_TDC){ + dir_TDC->cd(); + h->SetAxisRange(0,h->GetBinContent(h->GetMaximumBin())*1.05,"y"); + h->Write("",TObject::kOverwrite); + //Seems to help to write to the tfile early and often + // if (currentbin % 10 == 0) mf.Write(); + } + }//TDC Spectra + + if(dir_Overview){ + dir_Overview->cd(); + sumt0->SetAxisRange(300,1000,"y"); + sumtdrift->SetAxisRange(0,1200,"y"); + sumtmax->SetAxisRange(500,2200,"y"); + MDTFinalizeWriteTH1FChar(sumt0); + MDTFinalizeWriteTH1FChar(sumtdrift); + MDTFinalizeWriteTH1FChar(sumtmax); + TH1F* hTDCSummary = 0; mf.get("MDTTDC_Summary_ADCCut_"+ecap_str,hTDCSummary, dir_Overview); + TH1F* hTDCSummary_onsegm = 0; mf.get("MDTTDC_segm_Summary_ADCCut_"+ecap_str,hTDCSummary_onsegm, dir_Overview); + if(hTDCSummary){ +// double t0 = 0; +// double t0err = 0; +// double tmax = 0; +// double tmaxerr = 0; +// MDTFitTDC(hTDCSummary, t0, t0err, tmax, tmaxerr); + hTDCSummary->Write("",TObject::kOverwrite); + } + if(hTDCSummary_onsegm){ + double t0 = 0; + double t0err = 0; + double tmax = 0; + double tmaxerr = 0; + MDTFitTDC(hTDCSummary_onsegm, t0, t0err, tmax, tmaxerr); + hTDCSummary_onsegm->Write("",TObject::kOverwrite); + } + } + }//Overview + } + + TH1F* hTDCSummary = 0; + TH1F* hTDCSummary_onsegm = 0; + mf.get(Overview_Area+"/Overview/Overall_TDC_ADCCut_spectrum",hTDCSummary); + mf.get(Overview_Area+"/Overview/Overall_TDC_onSegm_ADCCut_spectrum",hTDCSummary_onsegm); + if(hTDCSummary){ +// double t0 = 0; +// double t0err = 0; +// double tmax = 0; +// double tmaxerr = 0; +// MDTFitTDC(hTDCSummary, t0, t0err, tmax, tmaxerr); + mf.cd(Overview_Area+"/Overview/"); + hTDCSummary->Write("",TObject::kOverwrite); + } + if(hTDCSummary_onsegm){ + double t0 = 0; + double t0err = 0; + double tmax = 0; + double tmaxerr = 0; + MDTFitTDC(hTDCSummary_onsegm, t0, t0err, tmax, tmaxerr); + mf.cd(Overview_Area+"/Overview/"); + hTDCSummary_onsegm->Write("",TObject::kOverwrite); + } + + }//computing All + + return; + } + + void MonitoringFile::MDTLowStat( std::string inFilename, std::string _title_){ + + MDTPostProcessor mf( inFilename, "MDT LowStat Analysis" ); + + if (!mf.IsOpen()) { + std::cerr << "MDTPostProcess(): " + << "Input file not opened \n"; + return; + } + + if(mf.GetSize()<1000.) { + std::cerr << "MDTPostProcess(): " + << "Input file empty \n"; + return; + } + + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(mf.GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0= dynamic_cast<TDirectory*>(key0->ReadObj()); + /// + + TIter next_run ( dir0->GetListOfKeys() ); + TKey* key_run = 0; + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + TKey* key_lowStat = 0; + + while ((key_lowStat = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + TString lowStat_str = key_lowStat->GetName(); + if(!lowStat_str.Contains("lowStat")) continue; + + TDirectory* lowStat_dir = dir0->GetDirectory(lowStat_str); + if(!lowStat_dir) continue; + TDirectory* dirOverview = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/Overview")); + TDirectory* dirOverviewBA = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTBA/Overview")); + TDirectory* dirOverviewBC = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTBC/Overview")); + TDirectory* dirOverviewEA = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTEA/Overview")); + TDirectory* dirOverviewEC = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTEC/Overview")); + + if( !(dirOverview && dirOverviewBA && dirOverviewBC && dirOverviewEA && dirOverviewEC) ) {//Catch New Directory Name Fix + dirOverview = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/Overview_lowStat")); + dirOverviewBA = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTBA/Overview_lowStat")); + dirOverviewBC = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTBC/Overview_lowStat")); + dirOverviewEA = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTEA/Overview_lowStat")); + dirOverviewEC = lowStat_dir->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTEC/Overview_lowStat")); + } + + if( !(dirOverview && dirOverviewBA && dirOverviewBC && dirOverviewEA && dirOverviewEC) ) continue;//Make sure mdt has lowStat entires before continuing + + TH1F* tdc = 0; mf.get("Overall_TDC_ADCCut_spectrum",tdc,dirOverview); + TH1F* tdcBA = 0; mf.get("MDTTDC_Summary_ADCCut_BA",tdcBA,dirOverviewBA); + TH1F* tdcBC = 0; mf.get("MDTTDC_Summary_ADCCut_BC",tdcBC,dirOverviewBC); + TH1F* tdcEA = 0; mf.get("MDTTDC_Summary_ADCCut_EA",tdcEA,dirOverviewEA); + TH1F* tdcEC = 0; mf.get("MDTTDC_Summary_ADCCut_EC",tdcEC,dirOverviewEC); + TH1F* tdc_onSegm = 0; mf.get("Overall_TDC_onSegm_ADCCut_spectrum",tdc_onSegm,dirOverview); + TH1F* tdcBA_onSegm = 0; mf.get("MDTTDC_segm_Summary_ADCCut_BA",tdcBA_onSegm,dirOverviewBA); + TH1F* tdcBC_onSegm = 0; mf.get("MDTTDC_segm_Summary_ADCCut_BC",tdcBC_onSegm,dirOverviewBC); + TH1F* tdcEA_onSegm = 0; mf.get("MDTTDC_segm_Summary_ADCCut_EA",tdcEA_onSegm,dirOverviewEA); + TH1F* tdcEC_onSegm = 0; mf.get("MDTTDC_segm_Summary_ADCCut_EC",tdcEC_onSegm,dirOverviewEC); + + double t0 = 0; + double t0err = 0; + double tmax = 0; + double tmaxerr = 0; + + if(tdc && dirOverview) { +// MDTFitTDC(tdc,t0,t0err,tmax,tmaxerr); + dirOverview->cd(); + tdc->Write("",TObject::kOverwrite); + } + if(tdcBA && dirOverviewBA) { +// MDTFitTDC(tdcBA,t0,t0err,tmax,tmaxerr); + dirOverviewBA->cd(); + tdcBA->Write("",TObject::kOverwrite); + } + if(tdcBC && dirOverviewBC) { +// MDTFitTDC(tdcBC,t0,t0err,tmax,tmaxerr); + dirOverviewBC->cd(); + tdcBC->Write("",TObject::kOverwrite); + } + if(tdcEA && dirOverviewEA) { +// MDTFitTDC(tdcEA,t0,t0err,tmax,tmaxerr); + dirOverviewEA->cd(); + tdcEA->Write("",TObject::kOverwrite); + } + if(tdcEC && dirOverviewEC) { +// MDTFitTDC(tdcEC,t0,t0err,tmax,tmaxerr); + dirOverviewEC->cd(); + tdcEC->Write("",TObject::kOverwrite); + } + if(tdc_onSegm && dirOverview) { + MDTFitTDC(tdc_onSegm,t0,t0err,tmax,tmaxerr); + dirOverview->cd(); + tdc_onSegm->Write("",TObject::kOverwrite); + } + if(tdcBA_onSegm && dirOverviewBA) { + MDTFitTDC(tdcBA_onSegm,t0,t0err,tmax,tmaxerr); + dirOverviewBA->cd(); + tdcBA_onSegm->Write("",TObject::kOverwrite); + } + if(tdcBC_onSegm && dirOverviewBC) { + MDTFitTDC(tdcBC_onSegm,t0,t0err,tmax,tmaxerr); + dirOverviewBC->cd(); + tdcBC_onSegm->Write("",TObject::kOverwrite); + } + if(tdcEA_onSegm && dirOverviewEA) { + MDTFitTDC(tdcEA_onSegm,t0,t0err,tmax,tmaxerr); + dirOverviewEA->cd(); + tdcEA_onSegm->Write("",TObject::kOverwrite); + } + if(tdcEC_onSegm && dirOverviewEC) { + MDTFitTDC(tdcEC_onSegm,t0,t0err,tmax,tmaxerr); + dirOverviewEC->cd(); + tdcEC_onSegm->Write("",TObject::kOverwrite); + } + }// All LowStat Dirs + }// All Runs + + return; + + } + + bool MonitoringFile::MDTCheckAlign(std::string inFilename, std::string _title_){ + + TFile* f = TFile::Open(inFilename.c_str(),"READ"); + + if (f == 0) { + std::cerr << "MonitoringFile::MDTPostProcess(): " + << "Input file not opened \n"; + return true; + } + if(f->GetSize()<1000.) { + std::cerr << "MonitoringFile::MDTPostProcess(): " + << "Input file empty \n"; + return true; + } + + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + dir0->cd(); + + int keysBA = 0; + int keysBC = 0; + int keysEA = 0; + int keysEC = 0; + TDirectory* dirBA = dir0->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTBA/Chambers")); + if(dirBA) keysBA = dirBA->GetNkeys(); + TDirectory* dirBC = dir0->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTBC/Chambers")); + if(dirBC) keysBC = dirBC->GetNkeys(); + TDirectory* dirEA = dir0->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTEA/Chambers")); + if(dirEA) keysEA = dirEA->GetNkeys(); + TDirectory* dirEC = dir0->GetDirectory(TString("Muon/MuonRawDataMonitoring/"+_title_+"/MDTEC/Chambers")); + if(dirEC) keysEC = dirEC->GetNkeys(); + + bool aligned = (keysBA < 600 && keysBC < 600 && keysEA < 600 && keysEC < 600); + + f->Close(); + delete f; + + return aligned; + } + + bool MonitoringFile::MDTCheck(std::string inFilename){ + + TFile* f = TFile::Open(inFilename.c_str(),"READ"); + + if (f == 0 || ! f->IsOpen()) { + std::cerr << "MonitoringFile::MDTPostProcess(): " + << "Input file not opened \n"; + delete f; + return false; + } + if(f->GetSize()<1000.) { + std::cerr << "MonitoringFile::MDTPostProcess(): " + << "Input file empty \n"; + delete f; + return false; + } + + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0 = 0; + while (key0 != 0 && dir0 == 0) { + dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + key0 = (TKey*)nextcd0(); + } + if (dir0 == 0) { + std::cerr << "MonitoringFile::MDTPostProcess(): " + << "Can't find top level directory \n"; + delete f; + return false; + } + dir0->cd(); + + TDirectory* dir = dir0->GetDirectory("Muon/MuonRawDataMonitoring/MDT"); + bool goodMDTFile = dir!=0; + f->Close(); + delete f; + return goodMDTFile; + } + + void MonitoringFile::MDTTubeEff(const TString & dirName, const TH1F* num, const TH1F* den, TH1F* eff, float &countsML1, float &countsML2, float &entriesML1, float &entriesML2){ + int nBinsNum = num->GetNbinsX(); + int BinsML1 = nBinsNum/2; + if(dirName(0,4)=="BIS8" || dirName(0,2)=="BE") BinsML1=nBinsNum; // only one ML + countsML1 = 0; + countsML2 = 0; + entriesML1 = 0; + entriesML2 = 0; + if(nBinsNum!=den->GetNbinsX()) return; + if(nBinsNum!=eff->GetNbinsX()) return; + eff->Reset(); + for(int ibin = 1; ibin !=nBinsNum+1; ++ibin){ + float entries = den->GetBinContent(ibin); + float counts = num->GetBinContent(ibin); + float efficiency = (counts+1.)/(entries+2.); + float error = sqrt(efficiency*(1-efficiency))/sqrt(entries+3.); + if(ibin<BinsML1 || BinsML1==nBinsNum) {countsML1+=counts; entriesML1+=entries;} + else {countsML2+=counts; entriesML2+=entries;} + eff->SetBinContent(ibin, efficiency); + eff->SetBinError(ibin,error); + } + } + + void MonitoringFile::MDT2DHWName(TString hardware_name, TString &stateta_IMO_c, TString &statphi_IMO_c, TString &stateta_c, TString &statphi_c, + TString &statphi_c2){ + + TString statphi_s = hardware_name(5,2); + TString Barrel = hardware_name(0,1); + TString Side = hardware_name(4,1); + TString hwname = hardware_name(1,1); + + statphi_c = statphi_s+",1"; + statphi_c2 = statphi_s+",2"; + + if(hardware_name(0,3)=="BIR" || hardware_name(0,3)=="BIM") { + statphi_c = statphi_c +","+hardware_name(2,1); + statphi_c2 = statphi_c2 +","+hardware_name(2,1); + } + + TString eta_s = hardware_name(3,1); + stateta_c = hardware_name(0,2); + stateta_c += hardware_name(4,1); + stateta_c+=eta_s; + + stateta_IMO_c = hardware_name(0,1); + stateta_IMO_c += hardware_name(4,1); + stateta_IMO_c += eta_s; + + statphi_IMO_c = hwname+","+statphi_s; + + } + + Double_t MonitoringFile::fittzero(Double_t *x,Double_t *par) + { + Double_t fitvaltzero = par[0] + ( par[3] / ( 1 + ( TMath::Exp((-x[0]+par[1])/par[2]) ) ) ); + return fitvaltzero; + } + + Double_t MonitoringFile::fittmax(Double_t *x,Double_t *par) + { + Double_t fitvaltmax = par[0] + ( par[3] / ( 1 + ( TMath::Exp((x[0]-par[1])/par[2]) ) ) ); + return fitvaltmax; + } + + void MonitoringFile::MDTFitTDC(TH1F* h, double &t0, double &t0err, double &tmax, double &tmaxerr){ + t0 = tmax = 0; + t0err = tmaxerr = 0; + double up = h->GetBinCenter(h->GetMaximumBin()+1); + if( up > 1200 ) up = 1000; + double down = up + 650; + if( up < 300 ) up = 300; + double parESD0 = h->GetBinContent(h->GetMinimumBin()); + double parESD1 = up; + double parESD2 = 20; + double parESD3 = h->GetBinContent(h->GetMaximumBin()) - h->GetBinContent(h->GetMinimumBin()); + TF1 func1("func1", &fittzero,(Double_t)(up-300),(Double_t)(up), 4); + func1.SetParameters(parESD0, parESD1, parESD2, parESD3); + func1.SetLineColor(kBlue+2); + if(h->GetEntries()>100){ + h->Fit("func1","RQ"); + t0 = func1.GetParameter(1) ; + t0err = func1.GetParError(1); + double binAtT0 = (double)h->GetBinContent(h->FindBin(t0)); + if(binAtT0<1) binAtT0 = 1; + t0err += 10.0 * func1.GetChisquare() / (0.01*binAtT0*binAtT0*(double)func1.GetNumberFitPoints()); // to additionally account for bad fits + } + + parESD0 = h->GetBinContent(h->GetMinimumBin()); + parESD1 = down; + parESD2 = 50; + parESD3 = (h->GetBinContent(h->GetMaximumBin())-h->GetBinContent(h->GetMinimumBin()))/10.; + TF1 func2("func2", &fittmax, (Double_t)(down-135), (Double_t)(down+135), 4); + func2.SetParameters(parESD0,parESD1,parESD2,parESD3); + func2.SetLineColor(kRed+1); + if(h->GetEntries()>100){ + func2.SetParLimits(0, parESD0, 2.0*parESD0+1); + func2.SetParLimits(2, 5, 90); + func2.SetParLimits(3, 0.2*parESD3, 7*parESD3); + h->Fit("func2","WWRQ+"); +// std::cout << h->GetName() << std::endl; +// std::cout << " " << func2.GetParameter(0) << " " << func2.GetParameter(1) << " " << func2.GetParameter(2) << " " << func2.GetParameter(3) << std::endl; + tmax = func2.GetParameter(1); + tmaxerr = func2.GetParError(1); + double binAtTmax = (double)h->GetBinContent(h->FindBin(tmax)); + if(binAtTmax<1) binAtTmax = 1; + tmaxerr += 10.0 * func2.GetChisquare() / (0.01*binAtTmax*binAtTmax*(double)func2.GetNumberFitPoints()); // to additionally account for bad fits + } + + h->GetXaxis()->SetTitle("[nsec] t0 = "+returnString(t0)+" +/- "+returnString(t0err)+" tmax = "+returnString(tmax)+" +/- "+returnString(tmaxerr)); + + return; + } + + void MonitoringFile::MDTSetMetaData(TDirectory* targetDir, TH1* h1, TH1* h2, TH1* h3){ + return; + TTree* metadata_overview_tr = 0; + if(!targetDir || !h1) return; + targetDir->GetObject("metadata",metadata_overview_tr); + //Fill Metadata for new objs. + std::string name_; + std::string intervalData_="run"; + std::string chainData_="<none>"; + std::string mergeData_="<default>"; + if(metadata_overview_tr){ + OutputMetadata metadata_overview(metadata_overview_tr); + char name[99]; + char intervalData[99]; + char chainData[99]; + char mergeData[99]; + TBranch* b_name; + TBranch* b_intervalData; + TBranch* b_chainData; + TBranch* b_mergeData; + TTree* tClone = (TTree*) metadata_overview_tr->Clone(); + metadata_overview_tr->SetDirectory(0); + tClone->SetBranchAddress("Name",name,&b_name); + tClone->SetBranchAddress("Interval",intervalData,&b_intervalData); + tClone->SetBranchAddress("TriggerChain",chainData,&b_chainData); + tClone->SetBranchAddress("MergeMethod",mergeData,&b_mergeData); + //Check if Metadata Already Exists + bool isMeta = false; + for(int i = 0; i != tClone->GetEntries(); ++i){ + tClone->GetEntry(i); + intervalData_ = intervalData; + chainData_ = chainData; + mergeData_ = mergeData; + name_ = name; + if(name_ == (std::string) h1->GetName()) isMeta = true; + } + delete tClone; + if(isMeta) { + metadata_overview_tr->SetDirectory(0); + delete metadata_overview_tr; + return; + } + metadata_overview.fill(h1->GetName(), intervalData_.c_str(), chainData_.c_str(), mergeData_.c_str()); + if(h2) metadata_overview.fill(h2->GetName(), intervalData_.c_str(), chainData_.c_str(), mergeData_.c_str()); + if(h3) metadata_overview.fill(h3->GetName(), intervalData_.c_str(), chainData_.c_str(), mergeData_.c_str()); + //set new hists to 0 dir + TDirectory* tempDir = gDirectory; + targetDir->cd(); + metadata_overview_tr->Write("",TObject::kOverwrite); + tempDir->cd(); + } + else { + TTree* metadata_overview_tr = new TTree( "metadata", "Monitoring Metadata" ); + OutputMetadata metadata_overview(metadata_overview_tr); + if(h1) metadata_overview.fill( h1->GetName(), intervalData_.c_str(), chainData_.c_str(), mergeData_.c_str()); + TDirectory* tempDir = gDirectory; + targetDir->cd(); + h1->SetDirectory(0); + metadata_overview_tr->Write("",TObject::kOverwrite); + metadata_overview_tr->SetDirectory(0);//make this safe to delete + delete metadata_overview_tr; + tempDir->cd(); + } + } + + void MonitoringFile::MDTFinalizeWriteTH1FChar(TH1F* h){ + h->LabelsDeflate("x"); + if(h->GetNbinsX()>1) h->LabelsOption("v","x"); + h->Write("",TObject::kOverwrite); + } + + void MonitoringFile::GetTubeLength( double & tubeLength, TString dirName ) { + if( dirName(0,3) == "BEE" ) tubeLength = .9115; + else if( dirName(0,3) == "BIS" && dirName(3,1) != "8" ) tubeLength = 1.6715; + else if( dirName(0,4) == "BIS8" ) tubeLength = .8515; + else if( dirName(0,3) == "BIL" ) tubeLength = 2.6715; + else if( dirName(0,3) == "BIM" ) tubeLength = 1.5365; + else if( dirName(0,3) == "BIR" ) tubeLength = 1.1055; + else if( dirName(0,4) == "BIR1" ) tubeLength = 2.6715; + else if( dirName(0,4) == "BIR2" || dirName(0,4) == "BIR4" || dirName(0,4) == "BIR5" ) tubeLength = 1.5365; + else if( dirName(0,4) == "BIR3" || dirName(0,4) == "BIR6" ) tubeLength = 1.1055; + else if( dirName(0,3) == "BML" ) tubeLength = 3.5515; + else if( dirName(0,3) == "BMS" || dirName(0,3) == "BMF" ) tubeLength = 3.0715; + else if( dirName(0,3) == "BOL" ) tubeLength = 4.9615; + else if( dirName(0,3) == "BOG" ) tubeLength = 3.7715; + else if( dirName(0,3) == "BOS" || dirName(0,3) == "BOF" ) tubeLength = 3.7733; + else if( dirName(0,4) == "EES1" ) tubeLength = 2.1945; + else if( dirName(0,4) == "EES2" ) tubeLength = 2.5905; + else if( dirName(0,4) == "EEL1" && dirName(5,2) == "05" ) tubeLength = 2.6265; + else if( dirName(0,4) == "EEL1" ) tubeLength = 4.2015; + else if( dirName(0,4) == "EEL2" ) tubeLength = 3.6015; + else if( dirName(0,4) == "EIS1" ) tubeLength = 1.0605; + else if( dirName(0,4) == "EIS2" ) tubeLength = 1.4115; + else if( dirName(0,4) == "EIL1" ) tubeLength = 1.5465; + else if( dirName(0,4) == "EIL2" ) tubeLength = 2.0865; + else if( dirName(0,4) == "EIL3" && (dirName(5,2) == "11" || dirName(5,2) == "15") ) tubeLength = 1.7415; + else if( dirName(0,4) == "EIL3" ) tubeLength = 2.0715; + else if( dirName(0,4) == "EIL4" && (dirName(5,2) == "11" || dirName(5,2) == "15") ) tubeLength = 1.5515; + else if( dirName(0,4) == "EIL4" && (dirName(5,2) == "01" || dirName(5,2) == "09") ) tubeLength = 1.5365; + else if( dirName(0,4) == "EIL4" && (dirName(5,2) == "03" || dirName(5,2) == "05" || dirName(5,2) == "13") ) tubeLength = 2.8015; + else if( dirName(0,4) == "EIL4" && (dirName(5,2) == "07") ) tubeLength = 2.0115; + else if( dirName(0,4) == "EIL5" && (dirName(5,2) == "01" || dirName(5,2) == "09") ) tubeLength = 2.8015; + else if( dirName(0,4) == "EML1" ) tubeLength = 1.5465; + else if( dirName(0,4) == "EML2" ) tubeLength = 2.4465; + else if( dirName(0,4) == "EML3" ) tubeLength = 3.4065; + else if( dirName(0,4) == "EML4" ) tubeLength = 4.3665; + else if( dirName(0,4) == "EML5" ) tubeLength = 5.3265; + else if( dirName(0,4) == "EMS1" ) tubeLength = 1.0875; + else if( dirName(0,4) == "EMS2" ) tubeLength = 1.6635; + else if( dirName(0,4) == "EMS3" ) tubeLength = 2.2395; + else if( dirName(0,4) == "EMS4" ) tubeLength = 2.8155; + else if( dirName(0,4) == "EMS5" ) tubeLength = 3.3915; + else if( dirName(0,4) == "EOL1" ) tubeLength = 2.0415; + else if( dirName(0,4) == "EOL2" ) tubeLength = 3.0015; + else if( dirName(0,4) == "EOL3" ) tubeLength = 3.7815; + else if( dirName(0,4) == "EOL4" ) tubeLength = 4.5015; + else if( dirName(0,4) == "EOL5" ) tubeLength = 5.2215; + else if( dirName(0,4) == "EOL6" ) tubeLength = 5.9415; + else if( dirName(0,4) == "EOS1" ) tubeLength = 1.4655; + else if( dirName(0,4) == "EOS2" ) tubeLength = 1.9695; + else if( dirName(0,4) == "EOS3" ) tubeLength = 2.4735; + else if( dirName(0,4) == "EOS4" ) tubeLength = 2.9415; + else if( dirName(0,4) == "EOS5" ) tubeLength = 3.3735; + else if( dirName(0,4) == "EOS6" ) tubeLength = 3.8055; + // else std::cout << "Missing chamb: " << dirName << " " << nTubes << std::endl; + } + + TString MonitoringFile::returnString(int a){ + std::stringstream ss; ss << a; + TString b; ss >> b; + return b; + } + + TString MonitoringFile::returnString(double a){ + std::stringstream ss; ss << a; + TString b; ss >> b; + return b; + } + + /////////dead/noisy/ineff functions + + TString MonitoringFile::ConvertTubeVectorToString( std::vector<int> & v, TH1F* h, TString chamber ) { + TString theList; + if( v.size() > 0 ) theList = TubeID_to_ID_L_ML(v.at(0), chamber, h->GetNbinsX()); + for(unsigned int i=1; i<v.size(); i++) theList += "," + TubeID_to_ID_L_ML(v.at(i), chamber, h->GetNbinsX()); + return theList; + } + + TString MonitoringFile::ConvertLayerVectorToString( std::vector<int> & v, TString chamber ) { + TString theList; + if( v.size() > 0 ) theList = Layer_to_L_ML(v.at(0), chamber); + for(unsigned int i=1; i<v.size(); i++) theList += "," + Layer_to_L_ML(v.at(i), chamber); + return theList; + } + + TString MonitoringFile::ConvertMezzVectorToString( std::vector<int> & v, TH1F* h, TString chamber ) { + TString theList; + if( v.size() > 0 ) theList = Mezz_to_ML_mezz(v.at(0), chamber, h->GetNbinsX()); + for(unsigned int i=1; i<v.size(); i++) theList += "," + Mezz_to_ML_mezz(v.at(i), chamber, h->GetNbinsX()); + return theList; + } + + TString MonitoringFile::ConvertVectorToString( std::vector<int> & v ) { + TString theList; + if( v.size() > 0 ) theList = returnString(v.at(0)); + for(unsigned int i=1; i<v.size(); i++) theList += "," + returnString(v.at(i)); + return theList; + } + + TString MonitoringFile::Mezz_to_ML_mezz(int mezz, const TString & hardware_name, int totalTubes) { + int mezzML = dqutils_mdtdeadnoisy::Get_ML_of_Mezz_degenerate(mezz, hardware_name, totalTubes); + + // Convert to string format + TString mezz_str; + if(mezz<10) mezz_str = "0" + returnString(mezz); + else mezz_str = returnString(mezz); + + return (returnString(mezzML)+mezz_str); + } + + TString MonitoringFile::TubeID_to_ID_L_ML(int & tubeID, const TString & hardware_name, int totalTubes) { + int derived_tube = 1; + int derived_layer = 1; + int derived_ML = 1; + + // Get Number of X + int derived_NumTubePerLayer = 1; + int derived_NumTubePerML = 1; + int derived_NumLayer = 1; + int derived_NumLayerPerML = 1; + int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + derived_NumML = 2; + } + else { + derived_NumLayerPerML = 3; + derived_NumML = 2; + } + + derived_NumLayer = derived_NumLayerPerML * derived_NumML; + derived_NumTubePerML = totalTubes / derived_NumML; + derived_NumTubePerLayer = totalTubes / derived_NumLayer; + + // Corrections for derived_NumTubePerLayer + if( hardware_name(0,4) == "BMS4" || hardware_name(0,4) == "BMS6" ) + derived_NumTubePerLayer = 48; + if((hardware_name(5,2) == "11" || hardware_name(5,2) == "15")) { + if( hardware_name(0,4) == "BIR1" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR2" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR3" ) + derived_NumTubePerLayer = 36; + if( hardware_name(0,4) == "BIR4" ) + derived_NumTubePerLayer = 30; + if( hardware_name(0,4) == "BIR5" ) + derived_NumTubePerLayer = 24; + } +// if( hardware_name(0,4)=="EIL4" && ( hardware_name(5,2)=="09" || hardware_name(5,2)=="01" ) ) // possible MdtIdHelper problem +// derived_NumTubePerLayer = 54; + + // Now get X + derived_ML = (tubeID-1)/derived_NumTubePerML + 1; + derived_layer = (tubeID-1)/derived_NumTubePerLayer + 1; + derived_tube = tubeID - (derived_layer - 1) * derived_NumTubePerLayer; + if(derived_ML==2) derived_layer -= derived_NumLayerPerML; + + // Convert to string format + TString tube_str; + if(derived_tube<10) tube_str = "0" + returnString(derived_tube); + else tube_str = returnString(derived_tube); + + return (returnString(derived_ML)+returnString(derived_layer)+tube_str); + } + + TString MonitoringFile::Layer_to_L_ML(int & layer, const TString & hardware_name) { + int derived_layer = 1; + int derived_ML = 1; + + // Get Number of X + // int derived_NumLayer = 1; + int derived_NumLayerPerML = 1; + // int derived_NumML = 1; + if( hardware_name(0,4) == "BIS8" /*&& hardware_name(5,2) == "12"*/ ) { + derived_NumLayerPerML = 3; + // derived_NumML = 1; + } + else if( /*hardware_name(0,4) == "BIS8" ||*/ hardware_name(0,3) == "BEE" ) { + derived_NumLayerPerML = 4; + // derived_NumML = 1; + } + else if( hardware_name(0,2) == "BI" || hardware_name(0,2) == "EI" ) { + derived_NumLayerPerML = 4; + // derived_NumML = 2; + } + else { + derived_NumLayerPerML = 3; + // derived_NumML = 2; + } + // derived_NumLayer = derived_NumLayerPerML * derived_NumML; + + // Now get X + derived_ML = (layer-1)/derived_NumLayerPerML + 1; + derived_layer = layer; + if(derived_ML==2) derived_layer -= derived_NumLayerPerML; + + // Convert to string format and return + return (returnString(derived_ML)+returnString(derived_layer)); + } + + void MonitoringFile::MDTSet2DRangeZ(TH2F* h) { + double minz = 0.00000001; + double maxz = h->GetMaximum(); + if(h->GetMinimum(minz) > minz) minz = h->GetMinimum(minz); + if( maxz <= minz ) return; + if( maxz/minz < 10.0 ) maxz = 10.0*minz; // always give range >= factor of 10 so that the labels will show in logz (root is stupid) + + h->SetAxisRange(minz,maxz,"z"); + } + + void MonitoringFile::MDTResetContents(TH2F* h) { + // copy all functions of histogram before resetting + TList* h_funcs; + h_funcs = dynamic_cast<TList*> (h->GetListOfFunctions()->Clone()); + h->Reset(); + //now insert these functions back into the hist + TIter iterE(h_funcs); + while ( (iterE()) ){h->GetListOfFunctions()->Add(*iterE);} + delete h_funcs; + // are the functions still valid after list deletion? + //http://root.cern.ch/root/html/TList#TList:_TList should be! + // TIter iterTest(EffBCap->GetListOfFunctions()); + // while( iterTest() ) std::cout << (*iterTest)->GetName() << std::endl; + } + + MonitoringFile::MDTPostProcessor::MDTPostProcessor(std::string inFilename, std::string name) : + TFile( inFilename.c_str(), "UPDATE" ), + m_name(name), + m_error(0) + { +// if(this->IsOpen()) std::cout << "Begin " << m_name << " MonitoringFile: " << this->GetName() << " Size: " << this->GetSize() << std::endl; +// else std::cerr << "ERROR " << m_name << " Could not open MonitoringFile: " << inFilename << std::endl; + if(!this->IsOpen()) std::cerr << "ERROR " << m_name << " Could not open MonitoringFile: " << inFilename << std::endl; + } + + MonitoringFile::MDTPostProcessor::~MDTPostProcessor(){ +// std::cout << "Destructing " << m_name << " Collected " << m_garbage.size() << " Objects to be deleted" << std::endl; + if(!m_error) this->Write(); + else std::cout << "WARNING " << m_name << " Chose Not To Write " << this->GetName() << std::endl; + this->Close(); + for(std::set<TObject*>::const_iterator git = m_garbage.begin(); git != m_garbage.end(); ++git){delete *git;} + // std::cout << "\n"; + } + + void MonitoringFile::MDTPostProcessor::error(){ m_error = true; } + + template <class T> + void MonitoringFile::MDTPostProcessor::get(const char* namecycle, T* &ptr, TDirectory* baseDir, TDirectory* target){ + + if (baseDir) baseDir->GetObject( namecycle, ptr ); // suggested root function + else this->GetObject( namecycle, ptr ); //suggested root function + if(!ptr) return; + TH1* obj = reinterpret_cast<TH1*> (ptr); + + obj->SetDirectory(target); + if( target == 0 ) m_garbage.insert(obj); + } + + void MonitoringFile::MDTPostProcessor::setDirectory( TH1* h, TDirectory* dir ){ + h->SetDirectory(dir); + if ( dir == 0 ) m_garbage.insert(h); + } + + void MonitoringFile::MDTPostProcessor::setDirectory( TH2* h, TDirectory* dir ){ + h->SetDirectory(dir); + if ( dir == 0 ) m_garbage.insert(h); + } + + void MonitoringFile::MDTPostProcessor::setMetaData(TDirectory* targetDir, TH1* h1, TH1* h2, TH1* h3) { + //we will collect the garbage and set the directory to zero + h1->SetDirectory(0); + m_garbage.insert(h1); + if(h2) { h2->SetDirectory(0); m_garbage.insert(h2); } + if(h3) { h3->SetDirectory(0); m_garbage.insert(h3); } + //now call old function being sure not to fill a garbage set + return MonitoringFile::MDTSetMetaData( targetDir, h1, h2, h3); + } + + bool MonitoringFile::tdcSort(const TH1* h1, const TH1* h2){ + TString name1 = h1->GetName(); + TString name2 = h2->GetName(); + + name1.ReplaceAll("MDTTDC_ADCCut_",""); + name2.ReplaceAll("MDTTDC_ADCCut_",""); + name1.ReplaceAll("BA_","") ; name1.ReplaceAll("BC_","") ; name1.ReplaceAll("EA_","") ; name1.ReplaceAll("EC_","") ; + name2.ReplaceAll("BA_","") ; name2.ReplaceAll("BC_","") ; name2.ReplaceAll("EA_","") ; name2.ReplaceAll("EC_","") ; + TString layer1 = name1(0,name1.Index("_")); + TString layer2 = name2(0,name2.Index("_")); + if( layer1 == "Extra" && layer2 != "Extra") return false; + else if (layer2 == "Extra" && layer1 != "Extra") return true; + if(layer1 < layer2) return true; + if(layer1 > layer2) return false; + + name1.ReplaceAll(((TString)layer1+"_StPhi"),"") ; + name2.ReplaceAll(((TString)layer1+"_StPhi"),"") ; + std::stringstream ss1; + std::stringstream ss2; + int phi1; int phi2; + + ss1 << name1; + ss1 >> phi1; + ss2 << name2; + ss2 >> phi2; + + if( phi1 < phi2) return true; + else return false; + } + +}//namespace + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_MDTvsTGCPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_MDTvsTGCPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ddf363e3a486a492250ae1c0b952c0c580274d59 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_MDTvsTGCPostProcess.cxx @@ -0,0 +1,240 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//Methods to Process TGC Histograms after merging. +//Author: Akimasa Ishikawa (akimasa.ishikawa@cern.ch) +//Date: Aug 2009 +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "DataQualityUtils/MonitoringFile.h" +#include "DataQualityUtils/CoolTgc.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TTree.h" +#include "TBranch.h" + +namespace dqutils { + + void + MonitoringFile::MDTvsTGCPostProcess( std::string inFilename, bool /* isIncremental */ ) + { + //start postprocessing + MDTvsTGCEfficiency(inFilename); + } + + void + MonitoringFile::MDTvsTGCEfficiency( std::string inFilename ) + { + PostProcessorFileWrapper mf(inFilename, "MDTvsTGC Efficiency"); + + if(!mf.IsOpen()){ + //std::cerr << "MDTvsTGCEfficiency(): " + // << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.){ + //std::cerr << "MDTvsTGCEfficiency(): " + // << "Input file empty \n"; + return; + } + + std::stringstream ss; + TString sac[2] ={"A","C"}; + TString sws[2] ={"Wire","Strip"}; + TString smethod[3]={"SegmTrack","MidOnly",""}; + + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + TString run_dir = key_run->GetName(); + if (!run_dir.Contains("run") ) continue; + + TString seff; + TString snum; + TString sden; + TString serr; + + TH2F *h2eff(0); + TH2F *h2num(0); + TH2F *h2den(0); + TH2F *h2err(0); + + TString mdtvstgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/MDTvsTGC/"; + + TString mdtvstgc_sub_dir[2] = {mdtvstgc_dir + "TGCEA/", mdtvstgc_dir + "TGCEC/"}; + + if(mf.cd(mdtvstgc_dir)) mf.cd(mdtvstgc_dir); + else { + //std::cerr << "No MDTvsTGC Directory! " << std::endl; mf.error(); + return; + } + + for(int ac=0;ac<2;ac++){ + TString eff_dir = mdtvstgc_sub_dir[ac]; + TDirectory* dir = mf.GetDirectory(eff_dir); + if(!dir){ + //std::cerr<< "TGCHistogramDivision: directory "<<eff_dir<<" not found"<<std::endl; + return; + } + + for(int ws=0;ws<2;ws++){ + // Merge SegmTrack and Midstation-only method results together to make total histograms + bool oktomerge = true; + + TList *nummergelist = new TList(); + for(int imethod=0;imethod<2;imethod++){ + ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "num_" << sac[ac]; + snum = ss.str(); + ss.str(""); + h2num = 0; + mf.get(snum, h2num, dir); + if(!h2num){ + //std::cerr <<"MDTvsTGC PostProcessing: no such histogram!! "<< snum << std::endl; + oktomerge = false; + } + nummergelist->Add(h2num); + } + ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[2] << "num_" << sac[ac]; + snum = ss.str(); + ss.str(""); + h2num = 0; + mf.get(snum, h2num, dir); + if(!h2num){ + //std::cerr <<"MDTvsTGC PostProcessing: no such histogram!! "<< snum << std::endl; + oktomerge = false; + } + + TList *denmergelist = new TList(); + for(int imethod=0;imethod<2;imethod++){ + ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "denom_" << sac[ac]; + sden = ss.str(); + ss.str(""); + h2den = 0; + mf.get(sden, h2den, dir); + if(!h2den){ + //std::cerr <<"MDTvsTGC PostProcessing: no such histogram!! "<< sden << std::endl; + oktomerge = false; + } + denmergelist->Add(h2den); + } + ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[2] << "denom_" << sac[ac]; + sden = ss.str(); + ss.str(""); + h2den = 0; + mf.get(sden, h2den, dir); + if(!h2den){ + //std::cerr <<"MDTvsTGC PostProcessing: no such histogram!! "<< sden << std::endl; + oktomerge = false; + } + + if(oktomerge){ + MDTvsTGCResetContents(h2num); + MDTvsTGCResetContents(h2den); + h2num->Merge(nummergelist); + h2den->Merge(denmergelist); + + dir->cd(); + h2num->Write("",TObject::kOverwrite); + h2den->Write("",TObject::kOverwrite); + } + + // Postprocess all methods + for(int imethod=0;imethod<3;imethod++){ + ss.str(""); + ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "_" << sac[ac]; + seff = ss.str(); + ss.str(""); + ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "num_" << sac[ac]; + snum = ss.str(); + ss.str(""); + ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "denom_" << sac[ac]; + sden = ss.str(); + ss.str(""); + ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "error_" << sac[ac]; + serr = ss.str(); + ss.str(""); + + h2eff = 0; + mf.get(seff, h2eff, dir); + h2num = 0; + mf.get(snum, h2num, dir); + h2den = 0; + mf.get(sden, h2den, dir); + h2err = 0; + mf.get(serr, h2err, dir); + + if( h2eff && h2num && h2den){ + MDTvsTGCResetContents(h2eff); + h2eff->Divide(h2num, h2den, 1., 1., "B"); + + // Make Error Histograms + int nX=h2eff->GetNbinsX();int nY=h2eff->GetNbinsY(); + int beff, bdenom, berror; + float feff, fdenom, ferror; + for(int x=1;x<=nX;x++){ + for(int y=1;y<=nY;y++){ + beff=h2eff->GetBin(x,y); bdenom=h2den->GetBin(x,y); + feff=h2eff->GetBinContent(beff);fdenom=h2den->GetBinContent(bdenom); + ferror=sqrt(feff*(1-feff)/fdenom); + + if(h2err){ + berror=h2err->GetBin(x,y); + h2err->SetBinContent(berror,ferror); + } + h2eff->SetBinError(beff,ferror); + } + } + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + // save histograms + dir->cd(); + h2eff->Write("",TObject::kOverwrite); + if(h2err)h2err->Write("",TObject::kOverwrite); + }// method + }// wirestrip + mf.Write(); + }// ac + }// run_dir + mf.Write(); + } + + void + MonitoringFile::MDTvsTGCResetContents(TH1* h) { + // copy all functions of histogram before resetting + TList* h_funcs; + h_funcs = dynamic_cast<TList*> (h->GetListOfFunctions()->Clone()); + h->Reset(); + //now insert these functions back into the hist + TIter iterE(h_funcs); + while ( (iterE()) ){h->GetListOfFunctions()->Add(*iterE);} + delete h_funcs; + // are the functions still valid after list deletion? + //http://root.cern.ch/root/html/TList#TList:_TList should be! + // TIter iterTest(EffBCap->GetListOfFunctions()); + // while( iterTest() ) std::cout << (*iterTest)->GetName() << std::endl; + } + +} diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_MergeAlgs.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_MergeAlgs.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e3bd36bcc516313683fb7cd7c8d22235509e5312 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_MergeAlgs.cxx @@ -0,0 +1,692 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: MonitoringFile_MergeAlgs.cxx,v 1.4 2009-04-06 13:08:13 ponyisi Exp $ +// ********************************************************************** + +#include "DataQualityUtils/MonitoringFile.h" + +#include <cmath> +#include <iostream> + +#include <TH1.h> +#include <TH2.h> +#include <TList.h> + +namespace { +Bool_t IsBinOverflow(const TH1& hist, Int_t bin) +{ + // Return true if the bin is overflow. + Int_t binx, biny, binz; + hist.GetBinXYZ(bin, binx, biny, binz); + Int_t dim = hist.GetDimension(); + + if ( dim == 1 ) + return binx >= hist.GetNbinsX() + 1; + else if ( dim == 2 ) + return (binx >= hist.GetNbinsX() + 1) || + (biny >= hist.GetNbinsY() + 1); + else if ( dim == 3 ) + return (binx >= hist.GetNbinsX() + 1) || + (biny >= hist.GetNbinsY() + 1) || + (binz >= hist.GetNbinsZ() + 1); + else + return 0; +} + +Bool_t IsBinUnderflow(const TH1& hist, Int_t bin) +{ + + // Return true if the bin is overflow. + Int_t binx, biny, binz; + hist.GetBinXYZ(bin, binx, biny, binz); + Int_t dim = hist.GetDimension(); + + if ( dim == 1 ) + return (binx <= 0); + else if ( dim == 2 ) + return (binx <= 0 || biny <= 0); + else if ( dim == 3 ) + return (binx <= 0 || biny <= 0 || binz <= 0); + else + return 0; +} +} + +namespace dqutils { + +Int_t MonitoringFile::getNumBins( const TH1& hist ) +{ + // Return number of histogram bins in ROOT 1-dim projection scheme + // Allow loops on multi-dim histograms without regard for dimensionality + Int_t dim = hist.GetDimension(); + if (dim == 1) { + return (hist.GetNbinsX()+2); + } + if (dim == 2) { + return (hist.GetNbinsX()+2)*(hist.GetNbinsY()+2); + } + if (dim == 3) { + return (hist.GetNbinsX()+2)*(hist.GetNbinsY()+2)*(hist.GetNbinsZ()+2); + } + return -1; +} + +void MonitoringFile::merge_effAsPerCent( TH2& a, const TH2& b ) +{ + // Auther: Benjamin Trocme + // a and b are efficiency histogramming with percentage stored + // den/num are a number of events + // BinContent = n/d*100 + // BinError = (1/d2) * sqrt( d*n*(d-n) ) + + // First extract the denominator + // It is supposed to be the same for all bins + // Have to do this in two steps to avoid problem + // of empty bins in which the nb of events can not be extracted + float denA = 0.; + float denB = 0.; + for (int ix = 1; ix <= a.GetNbinsX(); ix++){ + for (int iy = 1; iy <= a.GetNbinsY(); iy++){ + // Extract ratio and associated errors + // Warning : these are percentages! + float efficiencyA = a.GetBinContent(ix,iy)/100.; + float efficiencyB = b.GetBinContent(ix,iy)/100.; + float efficiencyErrA = a.GetBinError(ix,iy)/100.; + float efficiencyErrB = b.GetBinError(ix,iy)/100.; + + // Compute denominator ("nb of events") + if (efficiencyErrA != 0 && efficiencyA != 0 && denA == 0) denA = efficiencyA*(1-efficiencyA)/efficiencyErrA/efficiencyErrA; + if (efficiencyErrB != 0 && efficiencyB != 0 && denB == 0) denB = efficiencyB*(1-efficiencyB)/efficiencyErrB/efficiencyErrB; + } + } + + float denTot = denA + denB; + const double nEntries = a.GetEntries() + b.GetEntries(); + + for (int ix = 1; ix <= a.GetNbinsX(); ix++){ + for (int iy = 1; iy <= a.GetNbinsY(); iy++){ + // Extract ratio and associated errors + // Warning : these are percentages! + float efficiencyA = a.GetBinContent(ix,iy)/100.; + float efficiencyB = b.GetBinContent(ix,iy)/100.; + //float efficiencyErrA = a.GetBinError(ix,iy)/100.; + //float efficiencyErrB = b.GetBinError(ix,iy)/100.; + + // Compute numerator ("nb of good events") for each histo + float numA = denA * efficiencyA; + float numB = denB * efficiencyB; + + // Deduce the merged ratio and the associated error + float numTot = numA + numB; + float efficiencyTot = 0.; + float efficiencyErrTot = 0.; + + if (denTot != 0.) efficiencyTot = numTot/denTot*100.; + if (denTot != 0.) efficiencyErrTot = sqrt(numTot*denTot*(denTot-numTot))/denTot/denTot*100.; + + a.SetBinContent(ix,iy,efficiencyTot); + a.SetBinError(ix,iy,efficiencyErrTot); + } + } + a.SetEntries( nEntries ); +} + +void MonitoringFile::merge_perBinEffPerCent(TH1& a, const TH1& b) +{ + // This code assume that the histogram content is the efficiency of a + // given cut or selection in each bin (e.g. the ratio of a distribution + // after cut to the distribution before cut, bin by bin) and that these + // are efficiencies in percent. + // + // It also assumes that the error we calculated in a specific way: + // dEff = sqrt( eff*(1.-eff)/N ) [Eff= efficiency N = number of event in bin before cuts] + // dEff = 1-0.159^(1/N) if Eff = 0 + // dEff = 1-0.159^(1/N) if Eff = 1 + // dEff = 0 means no entries, the bin is ignored + // + + static double OneSigOneSided = 0.159; // 0.5*(1-0.681) where 0.681 means 68%CL + // Verify histogram compatibility + if (a.GetDimension() != b.GetDimension()) { + std::cerr<<"merge_perBinEffPerCent \""<< a.GetName() <<"\": attempt to merge histograms of different dimensionality" << std::endl; + return; + } + + Int_t ncells = getNumBins(a); + + if (ncells != getNumBins(b)) { + std::cerr<<"merge_perBinEffPerCent \""<< a.GetName() <<"\": attempt to merge histograms of different sizes\n"; + return; + } + + const double nEntries = a.GetEntries() + b.GetEntries(); + + for( int bin = 0; bin < ncells; bin++ ) { + if (IsBinUnderflow(a, bin) || IsBinOverflow(a, bin)) continue; + float efficiencyA = a.GetBinContent(bin)/100.; + float efficiencyB = b.GetBinContent(bin)/100.; + float efficiencyErrA = a.GetBinError(bin)/100.; + float efficiencyErrB = b.GetBinError(bin)/100.; + + float efficiencyTot = 0.; + float efficiencyErrTot = 0.; + if ( efficiencyErrA == 0. ) { + efficiencyTot = efficiencyB; + efficiencyErrTot = efficiencyErrB; + } + else { + if ( efficiencyErrB == 0. ) { + efficiencyTot = efficiencyA; + efficiencyErrTot = efficiencyErrA; + } + else { + float denomA = 0.; + if ( efficiencyA == 0. ){ + denomA = std::log(OneSigOneSided)/std::log(1.-efficiencyErrA); + } + else { + if ( efficiencyA > 0.99) { + denomA = std::log(OneSigOneSided)/std::log(1.-efficiencyErrA); + } + else { + denomA = efficiencyA*(1.-efficiencyA)/(efficiencyErrA*efficiencyErrA); + } + } + + float denomB = 0.; + if ( efficiencyB == 0. ){ + denomB = std::log(OneSigOneSided)/std::log(1.-efficiencyErrB); + } + else { + if ( efficiencyB > 0.99) { + denomB = std::log(OneSigOneSided)/std::log(1.-efficiencyErrB); + } + else { + denomB = efficiencyB*(1.-efficiencyB)/(efficiencyErrB*efficiencyErrB); + } + } + + float denom = denomA + denomB; + efficiencyTot = (denomA*efficiencyA + denomB*efficiencyB)/denom; + efficiencyErrTot = std::sqrt(efficiencyTot*(1.-efficiencyTot)/denom); + if ( efficiencyTot == 0. ) efficiencyErrTot = 1.0-std::pow(OneSigOneSided,1.0/denom); + if ( efficiencyTot > 0.99 ) efficiencyErrTot = 1.0-std::pow(OneSigOneSided,1.0/denom); + } + } + a.SetBinContent(bin,efficiencyTot*100.); + a.SetBinError(bin,efficiencyErrTot*100.); + } + a.SetEntries( nEntries ); +} + +void MonitoringFile::merge_effAsPerCentAlt( TH1& a, const TH1& b ) +{ + // Author: Peter Onyisi, d'apres Benjamin Trocme + // Variation of merge_effAsPerCent + // a and b are efficiency histogramming with percentage stored + // den/num are a number of events + // BinContent = n/d*100 + // BinError = (1/d2) * sqrt( d*n*(d-n) ) + + // Verify histogram compatibility + if (a.GetDimension() != b.GetDimension()) { + std::cerr<<"merge_effAsPerCentAlt \"" << a.GetName() <<"\": attempt to merge histograms of different dimensionality\n"; + return; + } + + Int_t ncells = getNumBins(a); + + if (ncells != getNumBins(b)) { + std::cerr<<"merge_effAsPerCentAlt \""<< a.GetName() <<"\": attempt to merge histograms of different bin counts\n"; + return; + } + + // First extract the denominator + // It is supposed to be the same for all bins + // Have to do this in two steps to avoid problem + // of empty bins in which the nb of events can not be extracted + + float denA = 0.; + float denB = 0.; + for( int bin = 0; bin < ncells; bin++ ) { + if (IsBinUnderflow(a, bin) || IsBinOverflow(a, bin)) continue; + // Extract ratio and associated errors + // Warning : these are percentages! + float efficiencyA = a.GetBinContent(bin)/100.; + float efficiencyB = b.GetBinContent(bin)/100.; + float efficiencyErrA = a.GetBinError(bin)/100.; + float efficiencyErrB = b.GetBinError(bin)/100.; + + // Compute denominator ("nb of events") + if (efficiencyErrA != 0 && efficiencyA != 0 && denA == 0) denA = efficiencyA*(1-efficiencyA)/efficiencyErrA/efficiencyErrA; + if (efficiencyErrB != 0 && efficiencyB != 0 && denB == 0) denB = efficiencyB*(1-efficiencyB)/efficiencyErrB/efficiencyErrB; + } + + float denTot = denA + denB; + const double nEntries = a.GetEntries() + b.GetEntries(); + + for( int bin = 0; bin < ncells; bin++ ) { + if (IsBinUnderflow(a, bin) || IsBinOverflow(a, bin)) continue; + // Extract ratio and associated errors + // Warning : these are percentages! + float efficiencyA = a.GetBinContent(bin)/100.; + float efficiencyB = b.GetBinContent(bin)/100.; + //float efficiencyErrA = a.GetBinError(bin)/100.; + //float efficiencyErrB = b.GetBinError(bin)/100.; + + // Compute numerator ("nb of good events") for each histo + float numA = denA * efficiencyA; + float numB = denB * efficiencyB; + + // Deduce the merged ratio and the associated error + float numTot = numA + numB; + float efficiencyTot = 0.; + float efficiencyErrTot = 0.; + + if (denTot != 0.) efficiencyTot = numTot/denTot*100.; + if (denTot != 0.) efficiencyErrTot = sqrt(numTot*denTot*(denTot-numTot))/denTot/denTot*100.; + + a.SetBinContent(bin,efficiencyTot); + a.SetBinError(bin,efficiencyErrTot); + } + a.SetEntries( nEntries ); +} + + +void MonitoringFile::merge_weightedAverage( TH1& a, const TH1& b ) +{ + + // Author: Tobias Golling + + if (a.GetDimension() != b.GetDimension()) { + std::cerr<<"merge_weightedAverage \"" << a.GetName() <<"\": attempt to merge histograms of different dimensionality\n"; + return; + } + + Int_t ncells = getNumBins(a); + + if (ncells != getNumBins(b)) { + std::cerr<<"merge_weightedAverage \"" << a.GetName() <<"\": attempt to merge histograms of different sizes\n"; + return; + } + + double nEntries = a.GetEntries(); + nEntries += b.GetEntries(); + + // if ( !a.InheritsFrom("TH2") ) { + for( int bin = 0; bin < ncells; bin++ ) { + double y1 = a.GetBinContent(bin); + double y2 = b.GetBinContent(bin); + double e1 = a.GetBinError(bin); + double e2 = b.GetBinError(bin); + double w1 = 1., w2 = 1.; + if (e1 > 0) w1 = 1./(e1*e1); + if (e2 > 0) w2 = 1./(e2*e2); + + // case 1: + if (e1 > 0 && e2 > 0){ + a.SetBinContent(bin, (w1*y1 + w2*y2)/(w1 + w2)); + a.SetBinError(bin, 1./sqrt(w1 + w2)); + } + // case 2: + else if (e2 > 0){ + a.SetBinContent(bin, y2); + a.SetBinError(bin, e2); + } + // case 3: + else if (e1 > 0){ + a.SetBinContent(bin, y1); + a.SetBinError(bin, e1); + } + // case 4: + else { + a.SetBinContent(bin, (y1 + y2)/2.); + a.SetBinError(bin, 0.); + } + } + + a.SetEntries( nEntries ); + + /* + } else if ( a.InheritsFrom("TH2") ) { + + try { + + merge_weightedAverage2D( dynamic_cast<TH2&>(a), dynamic_cast<const TH2&>(b) ); + + } catch ( const std::bad_cast& err ) { + // protect against dynamic cast failing + + return; + + } + + } + */ + +} + + +void MonitoringFile::merge_weightedAverage2D( TH2& a, const TH2& b ) +{ + // Author: Frank Berghaus + for( int binx = 0; binx <= a.GetNbinsX()+1; binx++ ) { + for( int biny = 0; biny <= a.GetNbinsY()+1; biny++ ) { + + int bin = a.GetBin(binx,biny); + + double y1 = a.GetBinContent(bin); + double y2 = b.GetBinContent(bin); + double e1 = a.GetBinError(bin); + double e2 = b.GetBinError(bin); + double w1 = 1., w2 = 1.; + if (e1 > 0) w1 = 1./(e1*e1); + if (e2 > 0) w2 = 1./(e2*e2); + + // case 1: + if (e1 > 0 && e2 > 0){ + a.SetBinContent(bin, (w1*y1 + w2*y2)/(w1 + w2)); + a.SetBinError(bin, 1./sqrt(w1 + w2)); + } + // case 2: + else if (e2 > 0){ + a.SetBinContent(bin, y2); + a.SetBinError(bin, e2); + } + // case 3: + else if (e1 > 0){ + a.SetBinContent(bin, y1); + a.SetBinError(bin, e1); + } + // case 4: + else { + a.SetBinContent(bin, (y1 + y2)/2.); + a.SetBinError(bin, 0.); + } + } + } +} + + +void MonitoringFile::merge_weightedEff( TH1& a, const TH1& b ) +{ + // Author: Arely Cortes Gonzalez + // This function adds two 1D efficiency histograms + // weighting them by the number of entries. + // The histograms need to have same binning. + // Also, it can be used to add two normalized histograms, + // keeping the properly weighted normalization. + // The number of entries for the merged histogram + // will be equal to the NumberEntries of 'a' + NumberEntries of 'b' + + + // Getting weights based on number of entries. + double entries_a = a.GetEntries(); + double entries_b = b.GetEntries(); + + double weight_a = 0.0; + double weight_b = 0.0; + + if (a.GetDimension() != b.GetDimension()) { + std::cerr<<"merge_weightedEff \""<< a.GetName()<<"\": attempt to merge histograms of different dimensionality\n"; + return; + } + + // Check whether the sumw2 are present - Added by B.Trocme + bool sumw2 = (a.GetSumw2N() != 0) && (b.GetSumw2N() != 0); + + Int_t ncells = getNumBins(a); + + if (ncells != getNumBins(b)) { + std::cerr<<"merge_weightedEff \""<< a.GetName() << "\": attempt to merge histograms of different sizes\n"; + return; + } + + if (entries_a + entries_b > 0) + { + weight_a = entries_a / (entries_a + entries_b); + weight_b = entries_b / (entries_a + entries_b); + + for( int bin = 0; bin < ncells; bin++ ) { + double binContent_a = a.GetBinContent(bin); + double binContent_b = b.GetBinContent(bin); + + //Error treatment added by Evan Wulf: + double binError_a = a.GetBinError(bin); + double binError_b = b.GetBinError(bin); + + //Filling the histogram with the new weighted values + float weightedEff = binContent_a * weight_a + binContent_b * weight_b; + a.SetBinContent(bin, weightedEff); + + //Set Errors: + float weightedError = sqrt( pow(binError_a * weight_a,2) + pow(binError_b * weight_b,2) ); + a.SetBinError(bin, weightedError); + } + } + // If the original histos did not contain sumw2, delete the sumw2 array created + // by SetBinError. This may look dirty but this is the recommandation by R.Brun: + // http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=1620&p=51674&hilit=sumw2#p51674 + // Added by B.Trocme + if (!sumw2) (a.GetSumw2())->Set(0); + //Resets number of entries of a: + a.SetEntries(entries_a + entries_b); +} + + +void MonitoringFile::merge_Rebinned( TH1& a, TH1& b ) +{ + // Author: Luca Fiorini + // This method provide a correct summation for histograms that have different binning + // e.g. the histograms with TH1::kCanRebin set to true + // The method uses TH1::Merge as explained here: + // http://root.cern.ch/root/html/TH1.html#TH1:Merge + // The axis x may have different number + // of bins and different limits, BUT the largest bin width must be + // a multiple of the smallest bin width and the upper limit must also + // be a multiple of the bin width. + + TList *list = new TList; + list->Add(&b); + a.Merge(list); + + delete list; + +} + + +void MonitoringFile::merge_eventSample( TH2& a, const TH2& b ) +{ + // Author: Peter Faulkner + // Merge histograms containing, for example, event numbers of events + // with particular types of errors. Data is inserted/appended row-wise. + int nbinsx = a.GetNbinsX(); + int nbinsy = a.GetNbinsY(); + if (b.GetNbinsX() != nbinsx || b.GetNbinsY() != nbinsy) return; + double entries = a.GetEntries(); + for( int biny = 1; biny <= nbinsy; biny++ ) { + for( int binx = 1; binx <= nbinsx; binx++ ) { + double bVal = b.GetBinContent(binx, biny); + if (bVal == 0) break; + for( int binxa = 1; binxa <= nbinsx; binxa++ ) { + double aVal = a.GetBinContent(binxa, biny); + if (aVal == 0) { + a.SetBinContent(binxa, biny, bVal); + entries++; + break; + } else if (bVal < aVal) { + for( int bx = nbinsx; bx > binxa; bx-- ) { + double v1 = a.GetBinContent(bx-1, biny); + if (v1 == 0) continue; + double v2 = a.GetBinContent(bx, biny); + if (v2 == 0) entries++; + a.SetBinContent(bx, biny, v1); + } + a.SetBinContent(binxa, biny, bVal); + break; + } else if (aVal == bVal) break; + } + } + } + a.SetEntries(entries); +} + +void MonitoringFile::merge_RMS( TH1& a, const TH1& b ) { + + //Merge histograms where bins are filled with RMS type data: + // Add in quadrature, weighted by the number of events as + // reconstructed from the errors. + + // Author: Evan Wulf + + if (a.GetDimension() != b.GetDimension()) { + std::cerr<<"merge_RMS \""<< a.GetName() <<"\": attempt to merge histograms of different dimensionality\n"; + return; + } + + Int_t ncells = getNumBins(a); + + if (ncells != getNumBins(b)) { + std::cerr<<"merge_RMS \""<< a.GetName() <<"\": attempt to merge histograms of different sizes\n"; + return; + } + + double nEntries = a.GetEntries(); + nEntries += b.GetEntries(); + + for( int bin = 0; bin < ncells; bin++ ) { + double rms1 = a.GetBinContent(bin); + double rms2 = b.GetBinContent(bin); + double e1 = a.GetBinError(bin); + double e2 = b.GetBinError(bin); + + double n1 = 0; + double n2 = 0; + + if( e1 != 0 ) { + n1 = pow( rms1 / e1, 2) / 2; + } + if( e2 != 0 ) { + n2 = pow( rms2 / e2, 2) / 2; + } + + double ntot = n1 + n2; + if( ntot <= 0 ) { + a.SetBinContent( bin, sqrt( (rms1*rms1) + (rms2*rms2) ) ); + a.SetBinError( bin, sqrt( (e1*e1) + (e2*e2) ) ); + } + else { + double rmstot = sqrt( ( (pow(n1 * rms1,2) / (n1 - 1)) + (pow(n2 * rms2, 2) / (n2 - 1)) ) * (ntot - 1) / pow(ntot,2) ); + a.SetBinContent( bin, rmstot ); + a.SetBinError( bin, rmstot / sqrt( 2 * ntot ) ); + } + } + + a.SetEntries(nEntries); +} + +void MonitoringFile::merge_RMSpercentDeviation( TH1& a, const TH1& b ) { + + //Merge histograms where bins are filled with RMS type data which has + // been normalized to a percent deviation by use of a reference, using + // content = 100 * (RMS - reference) / reference = (RMS * 100 / reference) - 100 + // error = RMSerror * 100 / reference. + + // Once constant term (100) is added back in, treatment is the same as with merge_RMS above: + + // Add in quadrature, weighted by the number of events as + // reconstructed from the errors. + + // Author: Evan Wulf + + if (a.GetDimension() != b.GetDimension()) { + std::cerr<<"merge_RMSpercentDeviation \"" << a.GetName() <<"\": attempt to merge histograms of different dimensionality\n"; + return; + } + + Int_t ncells = getNumBins(a); + + if (ncells != getNumBins(b)) { + std::cerr<<"merge_RMSpercentDeviation \"" << a.GetName() <<"\": attempt to merge histograms of different sizes\n"; + return; + } + + double nEntries = a.GetEntries(); + nEntries += b.GetEntries(); + + for( int bin = 0; bin < ncells; bin++ ) { + double y1 = a.GetBinContent(bin) + 100; + double y2 = b.GetBinContent(bin) + 100; + double e1 = a.GetBinError(bin); + double e2 = b.GetBinError(bin); + + double n1 = 0; + double n2 = 0; + + if( e1 != 0 ) { + n1 = pow( y1 / e1, 2) / 2; + } + if( e2 != 0 ) { + n2 = pow( y2 / e2, 2) / 2; + } + + double ntot = n1 + n2; + if( ntot <= 0 ) { + a.SetBinContent( bin, sqrt( (y1*y1) + (y2*y2) ) - 100 ); + a.SetBinError( bin, sqrt( (e1*e1) + (e2*e2) ) ); + } + else { + double ytot = sqrt( ( (pow(n1 * y1,2) / (n1 - 1)) + (pow(n2 * y2, 2) / (n2 - 1)) ) * (ntot - 1) / pow(ntot,2) ); + a.SetBinContent( bin, ytot - 100); + a.SetBinError( bin, ytot / sqrt( 2 * ntot ) ); + } + } + + a.SetEntries(nEntries); +} + +void MonitoringFile::merge_lowerLB( TH1& a, const TH1& b ) { + + // Merge "status" histograms, i.e filled at start of run/LB. + // The histogram title should contain the LB for which the histo was filled + // such that strcmp can extract the histo of lower LB + // Be careful to not format your title with %d but rather %4d. Otherwise, + // strcmp will return : 2>10 + // Example in : LArCalorimeter/LArMonTools/src/LArCoverage.cxx + // Author: B.Trocme + // + + if (a.GetDimension() != b.GetDimension()) { + std::cerr<<"merge_lowerLB \"" << a.GetName() <<"\": attempt to merge histograms of different dimensionality\n"; + return; + } + + Int_t ncells = getNumBins(a); + + if (ncells != getNumBins(b)) { + std::cerr<<"merge_lowerLB \"" << a.GetName() <<"\": attempt to merge histograms of different sizes\n"; + return; + } + + if (strcmp(a.GetTitle(),b.GetTitle())>0){ + // The LB of histo a is greater than the LB of histo b + // a is overwritten by b - Otherwise do nothing + for( int bin = 0; bin < ncells; bin++ ) { + a.SetTitle(b.GetTitle()); + a.SetBinContent(bin,b.GetBinContent(bin)); + a.SetBinError(bin,b.GetBinError(bin)); + } + // If the original histo did not contain sumw2, delete the sumw2 array created + // by SetBinError. This may look dirty but this is the recommandation by R.Brun: + // http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=1620&p=51674&hilit=sumw2#p51674 + if ((b.GetSumw2N()) == 0) (a.GetSumw2())->Set(0); + + a.SetEntries(b.GetEntries()); + } + return; +} + +}//end dqutils namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_MoveVertexMonitoring.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_MoveVertexMonitoring.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2fc71ced8c2bca3f6251d63d1d713b2c3f7c457b --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_MoveVertexMonitoring.cxx @@ -0,0 +1,320 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <ostream> +#include <iomanip> +#include <vector> +#include <stdlib.h> +#include <stdio.h> +#include <TFile.h> +#include <TH1.h> +#include <TKey.h> +#include <TString.h> +#include <string> + +namespace dqutils { + +TFile *source = 0; +TFile *target = 0; +int padding = 0; + +// define helper methods here rather then in this central MonitoringFile.h beast +int updateHists(std::string inFileName, std::string inStem, std::string outFileName = "", std::string outStem = ""); +bool makeDirectories(std::string dirName); +bool makeDir(std::string dirName); +void Copy(std::string inDir, std::string outDir, std::string inHist = "", std::string outHist = ""); +void CopyHist(std::string inDir, std::string outDir, std::string inHist, std::string outHist); + +//main method here +void MonitoringFile::VxMon_move( std::string inFilename, bool isIncremental) +{ + std::string stream_ref = "physics_MinBias"; + int stream_check = -1; + stream_check = inFilename.find(stream_ref); + + if(!isIncremental && stream_check >= 0){ + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + if (f == 0 || ! f->IsOpen()) { + delete f; + return; + } + if(f->GetSize()<1000.) { + delete f; + return; + } + + bool dirExists = false; + TString run_dir; + TString lb_dir; + int writeEOS = 0; + int writeLOCAL = -1; + bool IsFirstTime = true; + std::string AthenaTAG; + + const char *AtlasVersion = getenv("AtlasVersion"); + if (!AtlasVersion){ + delete f; + return; + } + AthenaTAG = AtlasVersion; + std::string out_inStem; + std::string out_EOS; + std::string out_LOCAL; + std::string out_outStem; + + TIter run_keys ( f->GetListOfKeys() ); + TIter lb_keys( f->GetListOfKeys() ); + TKey* key_run(0); + TKey* key_lb(0); + while ((key_run = dynamic_cast<TKey*>( run_keys() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if (tdir_run !=0 ) { + std::string tdir_run_name( tdir_run->GetName() ); + if (tdir_run_name.find("run")!= std::string::npos ) { + run_dir=tdir_run_name; + out_EOS = "root://eosatlas//eos/atlas/atlascerngroupdisk/perf-idtracking/VertexMonitoring/VxMon_"+ run_dir + "_" + AthenaTAG + ".root"; + out_LOCAL = "VxMon_" + run_dir + "_" + AthenaTAG + ".root"; + + lb_keys = tdir_run->GetListOfKeys(); + while ((key_lb = dynamic_cast<TKey*>( lb_keys() )) !=0 ) { + TObject* obj_lb = key_lb->ReadObj(); + TDirectory* tdir_lb = dynamic_cast<TDirectory*>( obj_lb ); + //cout << "tdir_lb " << tdir_lb << endl; + if (tdir_lb !=0 ) { + std::string tdir_lb_name( tdir_lb->GetName() ); + //cout << "tdir_lb_name " << tdir_lb_name << endl; + if (tdir_lb_name.find("lb")!= std::string::npos ) { + lb_dir=tdir_lb_name; + + dirExists = f->GetDirectory(run_dir+"/"+lb_dir+"/InDetGlobal/PrimaryVertexMultiplicity"); + if(dirExists){ + out_inStem = run_dir+"/"+lb_dir+"/InDetGlobal/PrimaryVertexMultiplicity/nVx"; + out_outStem = "nVx_"+lb_dir; + if (writeEOS==0){ + writeEOS = updateHists(inFilename.c_str(),out_inStem,out_EOS,out_outStem); + if(writeEOS!=0 && IsFirstTime) writeLOCAL = updateHists(inFilename.c_str(),out_inStem,out_LOCAL,out_outStem); + } + else{ + writeLOCAL = updateHists(inFilename.c_str(),out_inStem,out_LOCAL,out_outStem); + } + + if(writeEOS != 0 && !IsFirstTime && writeLOCAL != 0){ + delete f; + return; + }; + if(writeEOS != 0 && writeLOCAL != 0){ + delete f; + return; + }; + IsFirstTime = false; + } + } + } + else + { + delete obj_lb; + } + } + + if(writeEOS!=0 && writeLOCAL==0){ + int return_code = system("xrdcp VxMon_" + run_dir + "_" + AthenaTAG + ".root root://eosatlas//eos/atlas/atlascerngroupdisk/perf-idtracking/VertexMonitoring/VxMon_" + run_dir + "_" + AthenaTAG + ".root"); + if(return_code==0)remove(out_LOCAL.c_str()); + else{ + delete f; + return; + } + } + } + } + else + { + delete obj_run; + } + } + + f->Close(); + delete f; + } + return; +} + + //---------------------------------------- + // main macro + //---------------------------------------- + int updateHists(std::string inFileName, std::string inStem, std::string outFileName, std::string outStem) + { + //open original file + source = TFile::Open(inFileName.c_str()); + if (!source) { + //std::cout << "Couldn't open input file, " << inFileName << std::endl; + return 1; + }//else std::cout << "opening input file, " << inFileName << std::endl; + + //find out whether inStem is a histogram or a directory + bool isDir = true; + std::string path = inStem; + std::string hist; + + if (inStem[inStem.size() - 1] != '/') { + std::string::size_type lastSlash = inStem.find_last_of('/'); + hist = inStem.substr(lastSlash + 1, inStem.size() - lastSlash - 1); + path = inStem.substr(0, lastSlash + 1); + isDir = (source->FindObjectAny(hist.c_str()))->InheritsFrom("TDirectory"); + if (isDir) { + path = inStem; + hist.clear(); + } + } + + if (path[path.size() - 1] == '/') + path.resize(path.size() - 1); + if (!source->GetDirectory(path.c_str())) { + //std::cout << "path " << path << " directory doesn't exist in input file" << std::endl; + return 1; + } + + //open target file + std::cout.fill(' '); + if (outFileName.empty()) { + outFileName = std::string(inFileName, 0, inFileName.find(".root")); + outFileName += "_trimmed.root"; + } + + target = TFile::Open(outFileName.c_str(), "update"); + if (!target) { + //std::cout << "coundn't open output file " << outFileName << std::endl; + return 1; + }//else std::cout << "opening output file " << outFileName << std::endl; + + if (outStem.empty()) outStem = inStem; + std::string targetPath = outStem; + std::string targetHist; + if (!isDir) { + std::string::size_type lastSlash = outStem.find_last_of('/'); + targetPath = outStem.substr(0, lastSlash + 1); + targetHist = outStem.substr(lastSlash + 1, outStem.size() - lastSlash - 1); + } + + if (targetPath[targetPath.size() - 1] == '/') + targetPath.resize(targetPath.size() - 1); + + target->cd(); + if (!makeDirectories(targetPath)) { + //std::cout << "couldn't create outStem directories in output" << std::endl; + return 1; + } + //copy relevant objects + if(!target->IsWritable()) return 1; + Copy(path, targetPath, hist, targetHist); + + delete target; + delete source; + return 0; + } + + bool makeDirectories(std::string dirName) + { + bool success = true; + + if (!dirName.empty()) { + + std::string::size_type firstSlash = dirName.find('/'); + if (firstSlash == std::string::npos) { + success = makeDir(dirName); + } else { + std::string subdir(dirName, 0, firstSlash); + if (!subdir.empty()) + success = makeDir(subdir); + + std::string newSubdir(dirName, firstSlash + 1, dirName.size() - firstSlash); + success = makeDirectories(newSubdir); + } + } + return success; + } + + bool makeDir(std::string dirName) + { + padding += 3; + std::cout << std::setw(padding) << " "; + + if (!gDirectory->FindKey(dirName.c_str())) { + gDirectory->mkdir(dirName.c_str()); +// std::cout << "makeDir=" << dirName << std::endl; + } else +// std::cout << "object " << dirName << " already exists in directory " << gDirectory->GetName() << std::endl; + + padding -= 3; + return gDirectory->cd(dirName.c_str()); + } + + void Copy(std::string inDir, std::string outDir, std::string inHist, std::string outHist) + { + padding += 3; + + if (!inHist.empty()) { + CopyHist(inDir, outDir, inHist, outHist); + + } else { + TDirectory *sourceDir = source->GetDirectory(inDir.c_str()); + TDirectory *targetDir = target->GetDirectory(outDir.c_str()); + + TIter nextKey(sourceDir->GetListOfKeys()); + + TKey *key; + while ((key = (TKey*)nextKey())) { + std::string keyName = key->GetName(); + std::string className(key->GetClassName()); + + if (className == "TDirectoryFile") { + std::string newInDir = inDir; + newInDir += '/'; + newInDir += keyName; + + std::string newOutDir = outDir; + newOutDir += '/'; + newOutDir += keyName; + + if (! targetDir->FindKey(keyName.c_str())) { + /* + std::cout << std::setw(padding) << " "; + std::cout << "creating Dir " << newOutDir << std::endl; + */ + targetDir->mkdir(keyName.c_str()); + } + /* + std::cout << std::setw(padding) << " "; + std::cout << "moving to " << newInDir << ", a " << className << std::endl; + */ + Copy(newInDir, newOutDir); + + } else { + CopyHist(inDir, outDir, keyName, keyName); + } + } + } + + padding -= 3; + } + + void CopyHist(std::string inDir, std::string outDir, std::string inHist, std::string outHist) + { + TDirectory *sourceDir = source->GetDirectory(inDir.c_str()); + TDirectory *targetDir = target->GetDirectory(outDir.c_str()); + + targetDir->cd(); + TKey *key = sourceDir->FindKey(inHist.c_str()); + TObject *object = key->ReadObj(); + bool permission = true; + + if (targetDir->FindKey(outHist.c_str())) permission = false; + if (permission) object->Write(outHist.c_str(), TObject::kOverwrite); + + } + +} diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_MuonTrkPhys.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_MuonTrkPhys.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2fdee6c2164f9e6fad119dd9fbcf13540ccbbe10 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_MuonTrkPhys.cxx @@ -0,0 +1,1356 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + + +/////////////////////////////////////////////////////////////////////////////////// +// +//Post processing algorithm for Muon Track Physics Monitoring +// +/////////////////////////////////////////////////////////////////////////////////// + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <stdio.h> +#include <map> +#include <iomanip> +#include <set> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" +#include "TList.h" +#include "TProfile.h" +#include "TMinuit.h" + +void DGausFit(TH1 * Histogram, float * results, float fitWindow/*sigmas*/=3, bool overwrite = true, float th_A=100, float th_B=300); +void SimpleMean(TH1 * Mean, TH1 * Entries, TH1 * Weights, TH1 * Sigma = NULL, bool Eff = false); +void SimpleMean(TH2 * Mean, TH2 * Entries, TH2 * Weights, TH1 * Sigma = NULL, bool Eff = false); + +void DGausFit(TH1 * Histogram, float * results, float fitWindow/*sigmas*/, bool overwrite, float th_A, float th_B){ + + + if (results == NULL) { + // std::cerr << "DGausFit(): " + // << "Uninitialized result pointer was passed. \n"; + return; + } + + if (Histogram == NULL) { + results[0] = 0.0; + results[1] = 0.0; + results[2] = 0.0; + results[3] = 0.0; + // std::cerr << "DGausFit(): " + // << "Uninitialized histogram pointer was passed. \n"; + return; + } + + // minimum hit requirement + if (Histogram->GetEntries() < 50) { + + results[0] = 0.0; + results[1] = FLT_MAX/2; + results[2] = 0.0; + results[3] = FLT_MAX/2;//Error + return; + + } + + //Low Stats - Return MEAN/RMS + if (Histogram->GetEntries() < th_A) { + + results[0] = Histogram->GetMean(); + results[1] = 0.0; + results[2] = fabs(Histogram->GetRMS()); + results[3] = 0.0;//Error + return; + + }else if (Histogram->GetEntries() < th_B) { + + float mean = Histogram->GetMean(); + float width = Histogram->GetRMS(); + float max = Histogram->GetMaximum(); + + float range_high = (mean+fitWindow*width/2 > Histogram->GetXaxis()->GetXmax() ? Histogram->GetXaxis()->GetXmax() : mean+fitWindow*width/2); + float range_low = (mean-fitWindow*width/2 < Histogram->GetXaxis()->GetXmin() ? Histogram->GetXaxis()->GetXmin() : mean-fitWindow*width/2); + + TF1 *gaus = new TF1("f1", "gaus(0)", range_low, range_high); + + gaus->SetParameters(max,mean,width); + + gaus->SetParLimits(0, max*(0.75), max*(1.25)); + gaus->SetParLimits(1, mean-width/4, mean+width/4); + gaus->SetParLimits(2, width*(0.05), width*(1.0)); + + Histogram->Fit(gaus,"QRU"); + + Double_t parameters[3]; + gaus->GetParameters(¶meters[0]); + +// std::cout << Histogram->GetName() << " G " << gMinuit->fCstatu << " " << gaus->GetProb() << " " << gaus->GetChisquare() << std::endl; + + + if(gMinuit->fCstatu == "CONVERGED "){ + float pRelErr[3] = {float(std::fabs(gaus->GetParError(0))/std::fabs(parameters[0])), + float(std::fabs(gaus->GetParError(1))/std::fabs(parameters[1])), + float(std::fabs(gaus->GetParError(2))/std::fabs(parameters[2]))}; + float pAmp = parameters[0]; + float pMean = parameters[1]; + float pSigma = parameters[2]; + + bool Choose = true; + + if (pAmp < 0.25*max) Choose *= false; + if (std::fabs(pSigma) > + std::fabs(width)) Choose *= false; + if (pMean > range_high) Choose *= false; + if (pMean < range_low) Choose *= false; + if (pRelErr[0] > 0.15) Choose *= false; + if (pRelErr[1] > 0.15) Choose *= false; + if (pRelErr[2] > 0.15) Choose *= false; + + + if (Choose) { + results[0] = (float)parameters[1];//Mean + results[1] = (float)fabs(gaus->GetParError(1)); + results[2] = (float)fabs(parameters[2]);//Width + results[3] = (float)fabs(gaus->GetParError(2)); + } + else{ + // Retry with "Low Stats" + DGausFit(Histogram, results, fitWindow/*sigmas*/, overwrite, FLT_MAX, FLT_MAX); + return; + } + + + } + else{ + // Retry with "Low Stats" + DGausFit(Histogram, results, fitWindow/*sigmas*/, overwrite, FLT_MAX, FLT_MAX); + return; + } + + if(overwrite) Histogram->Write("",TObject::kOverwrite); + return; + + }else { + + + + // Same Mean + float mean = Histogram->GetMean(); + + // Sharp Peak + float width = Histogram->GetRMS()*1/5; + float max = Histogram->GetMaximum()*4/5; + + // Wide Peak + float width_2 = Histogram->GetRMS()*4/5; + float max_2 = Histogram->GetMaximum()*1/5; + + //Ranges + float range_high = (mean+fitWindow*width*3 > Histogram->GetXaxis()->GetXmax() ? Histogram->GetXaxis()->GetXmax() : mean+fitWindow*width*3); + float range_low = (mean-fitWindow*width*3 < Histogram->GetXaxis()->GetXmin() ? Histogram->GetXaxis()->GetXmin() : mean-fitWindow*width*3); + + TF1 *doublegaus = new TF1("f1", "gaus(0) + gaus(3)", range_low, range_high); + doublegaus->SetParameters(max,mean,width,max_2,mean,width_2); + + doublegaus->SetParLimits(0, max*(0.7), max*(1.2)); + doublegaus->SetParLimits(1, mean-width/4, mean+width/4); + doublegaus->SetParLimits(2, width*(0.05), width*(.7)); + doublegaus->SetParLimits(0, 0, max*(.7)); + doublegaus->SetParLimits(1, mean-width/2, mean+width/2); + doublegaus->SetParLimits(2, width*(.7), width*(2.0)); + + Histogram->Fit(doublegaus,"QRU"); + + Double_t parameters[6]; + doublegaus->GetParameters(¶meters[0]); + + + //std::cout << Histogram->GetName() << " DG " << gMinuit->fCstatu << " " << doublegaus->GetProb() << " " << doublegaus->GetChisquare() << std::endl; + + if(gMinuit->fCstatu == "CONVERGED "){ + + float pRelErr[2] = {float(std::fabs(doublegaus->GetParError(0))/std::fabs(parameters[0])), + float(std::fabs(doublegaus->GetParError(3))/std::fabs(parameters[3]))}; + float pAmp[2] = {float(parameters[0]),float(parameters[3])}; + float pMean[2] = {float(parameters[1]),float(parameters[4])}; + float pSigma[2] = {float(parameters[2]),float(parameters[5])}; + + bool Choose[2] = {true,true}; + + for (int i = 0; i < 2; i++) { + //Veto Bad Gaussians + if (pAmp[i] < 0.25*max ) Choose[i] *= false; + if (std::fabs(pSigma[i]) > + std::fabs(width)) Choose[i] *= false; + if (pMean[i] > range_high) Choose[i] *= false; + if (pMean[i] < range_low) Choose[i] *= false; + if (pRelErr[i] > 0.15) Choose[i] *= false; + } + + if (Choose[0] && Choose[1]) { + if (std::fabs(pAmp[0]-Histogram->GetEntries()) < + std::fabs(pAmp[1]-Histogram->GetEntries())) { + Choose[1] *= false; + }else { + Choose[0] *= false; + } + } + + if(Choose[0] && !Choose[1]){ + + results[0] = (float)parameters[1];//Mean + results[1] = (float)fabs(doublegaus->GetParError(1)); + results[2] = (float)fabs(parameters[2]);//Width + results[3] = (float)fabs(doublegaus->GetParError(2)); + + } + else if (Choose[1] && !Choose[0]){ + + results[0] = (float)parameters[4];//Mean + results[1] = (float)fabs(doublegaus->GetParError(4)); + results[2] = (float)fabs(parameters[5]);//Width + results[3] = (float)fabs(doublegaus->GetParError(5)); + + } + //If neither are reasonably measured, The one with the greatest amplitude is chosen + else { + // Retry with "Low-er Stats" + DGausFit(Histogram, results, fitWindow/*sigmas*/, overwrite, th_A, FLT_MAX); + return; + } + } + else{ + // Retry with "Low-er Stats" + DGausFit(Histogram, results, fitWindow/*sigmas*/, overwrite, th_A, FLT_MAX); + return; + } + + + if(overwrite) Histogram->Write("",TObject::kOverwrite); + return; + } + + results[0] = 0.0; + results[1] = 0.0; + results[2] = 0.0; + results[3] = 0.0; + return; + +} + +void SimpleMean(TH1 * Mean, TH1 * Weights, TH1 * Entries, TH1 * Sigma, bool Eff ){ + + if (Mean == NULL || Entries == NULL || Weights == NULL) { + return; + } + + float Sigma_val = 0.0; + + if (Sigma) { + Sigma_val = Sigma->GetRMS(1); + } + + + for(int bin_itr = 0; bin_itr < Mean->GetNbinsX(); bin_itr++){ + int i = bin_itr+1; + + Mean->SetBinContent(i,0.0); + Mean->SetBinError(i,0.0); + + if (Entries->GetBinContent(i)) { + + float Mean_val = Weights->GetBinContent(i)/(Entries->GetBinContent(i)); + Mean->SetBinContent(i,Mean_val); + Mean->SetBinError(i,0.0); + + //Change Error to basic statistical approximation + if (Sigma_val) { + Mean->SetBinError(i,Sigma_val/sqrt(Entries->GetBinContent(i))); + } + + //Change Error to binomial function + if(Eff){ + Mean->SetBinError(i,sqrt((1.0-Mean_val)*Mean_val/Entries->GetBinContent(i))); + } + + } + + } + + Mean->Write("",TObject::kOverwrite); + + return; + +} + +void SimpleMean(TH2 * Mean, TH2 * Weights, TH2 * Entries, TH1 * Sigma, bool Eff ){ + + if (Mean == NULL || Entries == NULL || Weights == NULL) { + return; + } + + float Sigma_val = 0.0; + + if (Sigma) { + Sigma_val = Sigma->GetRMS(1); + } + + + for(int bin_itrX = 0; bin_itrX < Mean->GetNbinsX(); bin_itrX++){ + int i = bin_itrX+1; + + for(int bin_itrY = 0; bin_itrY < Mean->GetNbinsY(); bin_itrY++){ + int j = bin_itrY+1; + + Mean->SetBinContent(i,j,0.0); + Mean->SetBinError(i,j,0.0); + + if (Entries->GetBinContent(i,j)) { + + float Mean_val = Weights->GetBinContent(i,j)/(Entries->GetBinContent(i,j)); + Mean->SetBinContent(i,j,Mean_val); + Mean->SetBinError(i,j,0.0); + + //Change Error to basic statistical approximation + if (Sigma_val) { + Mean->SetBinError(i,j,Sigma_val/sqrt(Entries->GetBinContent(i,j))); + } + + //Change Error to binomial function + if(Eff){ + Mean->SetBinError(i,j,sqrt((1.0-Mean_val)*Mean_val/Entries->GetBinContent(i,j))); + } + + } + } + + } + Mean->Write("",TObject::kOverwrite); + + return; + +} + + + +namespace dqutils { + + + void MonitoringFile::MuonTrkPhys( std::string inFilename, bool isIncremental){ + + MonitoringFile::MuonTrkPhys_Zmass( inFilename ); + MonitoringFile::MuonTrkPhys_Tracking( inFilename ); + MonitoringFile::MuonTrkPhys_DetectorSpecific( inFilename ); + MonitoringFile::MuonTrkPhys_BField( inFilename ); + MonitoringFile::MuonTrkPhys_Alignment( inFilename ); + + if (isIncremental) { + + return; + + } + + return; + + } + + void MonitoringFile::MuonTrkPhys_Zmass(std::string inFilename){ + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + if (f == 0) { + std::cerr << "MuonTrkPhys(): " + << "Input file not opened \n"; + return; + } + if(f->GetSize()<1000.) { + std::cerr << "MuonTrkPhys(): " + << "Input file empty \n"; + return; + } + + //Define Constants + std::vector<TString> region_strings; + region_strings.push_back("EC_EC"); + region_strings.push_back("EC_BC"); + region_strings.push_back("EC_BA"); + region_strings.push_back("EC_EA"); + region_strings.push_back("BC_EC"); + region_strings.push_back("BC_BC"); + region_strings.push_back("BC_BA"); + region_strings.push_back("BC_EA"); + region_strings.push_back("BA_EC"); + region_strings.push_back("BA_BC"); + region_strings.push_back("BA_BA"); + region_strings.push_back("BA_EA"); + region_strings.push_back("EA_EC"); + region_strings.push_back("EA_BC"); + region_strings.push_back("EA_BA"); + region_strings.push_back("EA_EA"); + + + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + if (key0 == 0) return; + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + if (dir0 == 0) return; + dir0->cd(); + /// + + TString runNumber = dir0->GetName(); + //std::cout<<"jk: runNumber = "<<runNumber<<endl; + TString mDir = runNumber+"/Muon/MuonTrkPhysMonitoring/NoTrigger/TrackingPerformance/Z_Signal/"; + if (! f->cd(mDir)) return; + //std::cout<<"jk: in directory "<<mDir<<endl; + TIter nextcd1(gDirectory->GetListOfKeys()); + while(TKey* key1 = dynamic_cast<TKey*>(nextcd1())) {//While in Staco/Muid/Third chain + TString recalg_fullStr = mDir+key1->GetName(); + TDirectory* dir1 = f->GetDirectory(recalg_fullStr); + if(!dir1) continue; + dir1->cd(); + + // Divide the efficiency histograms + TH2F* m_Z_EffNumerator = (TH2F*)dir1->Get("m_Z_EffNumerator"); + TH2F* m_Z_EffDenominator = (TH2F*)dir1->Get("m_Z_EffDenominator"); + TH2F* m_Z_Efficiency = (TH2F*)dir1->Get("m_Z_Efficiency"); + + SimpleMean(m_Z_Efficiency,m_Z_EffNumerator,m_Z_EffDenominator,NULL,true); + + + // Divide the efficiency histograms + TH1F* m_Z_EffNumerator_eta = (TH1F*)dir1->Get("m_Z_EffNumerator_eta"); + TH1F* m_Z_EffDenominator_eta = (TH1F*)dir1->Get("m_Z_EffDenominator_eta"); + TH1F* m_Z_Efficiency_eta = (TH1F*)dir1->Get("m_Z_Efficiency_eta"); + + SimpleMean(m_Z_Efficiency_eta,m_Z_EffNumerator_eta,m_Z_EffDenominator_eta,NULL,true); + + + // Fit the Mass histograms to BW + gaussian + TH1F* m_M_Z_Mean = (TH1F*)dir1->Get("m_M_Z_Mean"); + TH1F* m_M_Z_Sigma = (TH1F*)dir1->Get("m_M_Z_Sigma"); + + if(m_M_Z_Mean && m_M_Z_Sigma){ + TH1F* h_M_Z_region = 0; + + for(unsigned int region_it = 0; region_it < region_strings.size(); region_it++){ + //cout<<"jk, processing histogram "<<region_strings.at(region_it)<<endl; + + TString histname = "m_M_Z_"+region_strings.at(region_it); + h_M_Z_region = (TH1F*)dir1->Get(histname); + + if(!h_M_Z_region){ + //std::cout<<"Could not find histogram "<<histname<<endl; + continue; + } + + + //reset + m_M_Z_Mean->SetBinContent(region_it+1,0.0); + m_M_Z_Sigma->SetBinContent(region_it+1,0.0); + m_M_Z_Mean->SetBinError(region_it+1,0.0); + m_M_Z_Sigma->SetBinError(region_it+1,0.0); + + float results[4] = {0.0,0.0,0.0,0.0}; + h_M_Z_region->Rebin(4); + DGausFit(h_M_Z_region,results,7); + + //Get Results + m_M_Z_Mean->SetBinContent(region_it+1, results[0]); + m_M_Z_Sigma->SetBinContent(region_it+1,results[2]); + + m_M_Z_Mean->SetBinError(region_it+1, results[1]); + m_M_Z_Sigma->SetBinError(region_it+1, results[3]); + + } + + m_M_Z_Mean->Write("",TObject::kOverwrite); + m_M_Z_Sigma->Write("",TObject::kOverwrite); + + } + + } //ends staco/muid + + f->Close(); + delete f; + + return; + + } //ends Z-mass function + + + void MonitoringFile::MuonTrkPhys_Tracking( std::string inFilename ){ + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + if (f == 0) { + std::cerr << "MuonTrkPhys(): " + << "Input file not opened \n"; + return; + } + if(f->GetSize()<1000.) { + std::cerr << "MuonTrkPhys(): " + << "Input file empty \n"; + return; + } + + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + if (key0 == 0) return; + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + if (dir0 == 0) return; + dir0->cd(); + /// + + TString runNumber = dir0->GetName(); + TString mDir = runNumber+"/Muon/MuonTrkPhysMonitoring/NoTrigger/TrackingPerformance/General/"; + if (! f->cd(mDir)) return; + //std::cout<<"jk: in directory "<<mDir<<std::endl; + TIter nextcd1(gDirectory->GetListOfKeys()); + while(TKey* key1 = dynamic_cast<TKey*>(nextcd1())) {//While in Staco/Muid/Third chain + TString recalg_fullStr = mDir+key1->GetName(); + TDirectory* dir1 = f->GetDirectory(recalg_fullStr); + if(!dir1) continue; + dir1->cd(); + + //Counting + { + //Hits Per Track + TH2F* m_N_HpT_pLB_CSC = (TH2F*)dir1->Get("m_N_HpT_pLB_CSC"); + TH2F* m_N_HpT_pLB_CSC_Weights = (TH2F*)dir1->Get("m_N_HpT_pLB_CSC_Weights"); + TH2F* m_N_HpT_pLB_CSC_Entries = (TH2F*)dir1->Get("m_N_HpT_pLB_CSC_Entries"); + + SimpleMean(m_N_HpT_pLB_CSC,m_N_HpT_pLB_CSC_Weights,m_N_HpT_pLB_CSC_Entries,NULL,false); + + TH2F* m_N_HpT_pLB_TGC = (TH2F*)dir1->Get("m_N_HpT_pLB_TGC"); + TH2F* m_N_HpT_pLB_TGC_Weights = (TH2F*)dir1->Get("m_N_HpT_pLB_TGC_Weights"); + TH2F* m_N_HpT_pLB_TGC_Entries = (TH2F*)dir1->Get("m_N_HpT_pLB_TGC_Entries"); + + SimpleMean(m_N_HpT_pLB_TGC,m_N_HpT_pLB_TGC_Weights,m_N_HpT_pLB_TGC_Entries,NULL,false); + + TH2F* m_N_HpT_pLB_MDT = (TH2F*)dir1->Get("m_N_HpT_pLB_MDT"); + TH2F* m_N_HpT_pLB_MDT_Weights = (TH2F*)dir1->Get("m_N_HpT_pLB_MDT_Weights"); + TH2F* m_N_HpT_pLB_MDT_Entries = (TH2F*)dir1->Get("m_N_HpT_pLB_MDT_Entries"); + + SimpleMean(m_N_HpT_pLB_MDT,m_N_HpT_pLB_MDT_Weights,m_N_HpT_pLB_MDT_Entries,NULL,false); + + TH2F* m_N_HpT_pLB_RPC = (TH2F*)dir1->Get("m_N_HpT_pLB_RPC"); + TH2F* m_N_HpT_pLB_RPC_Weights = (TH2F*)dir1->Get("m_N_HpT_pLB_RPC_Weights"); + TH2F* m_N_HpT_pLB_RPC_Entries = (TH2F*)dir1->Get("m_N_HpT_pLB_RPC_Entries"); + + SimpleMean(m_N_HpT_pLB_RPC,m_N_HpT_pLB_RPC_Weights,m_N_HpT_pLB_RPC_Entries,NULL,false); + + + //Precision hits + TH1F* m_N_Precision = (TH1F*)dir1->Get("m_N_Precision"); + TH1F* m_N_Precision_entries = (TH1F*)dir1->Get("m_N_Precision_entries"); + TH1F* m_N_Precision_weights = (TH1F*)dir1->Get("m_N_Precision_weights"); + TH1F* m_N_Precision_mean = (TH1F*)dir1->Get("m_N_Precision_mean"); + + SimpleMean(m_N_Precision_mean,m_N_Precision_weights,m_N_Precision_entries,m_N_Precision,false); + + //Phi hits + TH1F* m_N_Phi_Hits = (TH1F*)dir1->Get("m_N_Phi_Hits"); + TH1F* m_N_Phi_Hits_entries = (TH1F*)dir1->Get("m_N_Phi_Hits_entries"); + TH1F* m_N_Phi_Hits_weights = (TH1F*)dir1->Get("m_N_Phi_Hits_weights"); + TH1F* m_N_Phi_Hits_mean = (TH1F*)dir1->Get("m_N_Phi_Hits_mean"); + + SimpleMean(m_N_Phi_Hits_mean,m_N_Phi_Hits_weights,m_N_Phi_Hits_entries,m_N_Phi_Hits,false); + + //Hits on segment + TH1F* m_N_Hits_Segment = (TH1F*)dir1->Get("m_N_Hits_Segment"); + TH1F* m_N_Hits_Segment_entries = (TH1F*)dir1->Get("m_N_Hits_Segment_entries"); + TH1F* m_N_Hits_Segment_weights = (TH1F*)dir1->Get("m_N_Hits_Segment_weights"); + TH1F* m_N_Hits_Segment_mean = (TH1F*)dir1->Get("m_N_Hits_Segment_mean"); + + SimpleMean(m_N_Hits_Segment_mean,m_N_Hits_Segment_weights,m_N_Hits_Segment_entries,m_N_Hits_Segment,false); + + //Segments per track + TH1F* m_N_Segment_Trk = (TH1F*)dir1->Get("m_N_Segment_Trk"); + TH1F* m_N_Segment_Trk_entries = (TH1F*)dir1->Get("m_N_Segment_Trk_entries"); + TH1F* m_N_Segment_Trk_weights = (TH1F*)dir1->Get("m_N_Segment_Trk_weights"); + TH1F* m_N_Segment_Trk_mean = (TH1F*)dir1->Get("m_N_Segment_Trk_mean"); + + SimpleMean(m_N_Segment_Trk_mean,m_N_Segment_Trk_weights,m_N_Segment_Trk_entries,m_N_Segment_Trk,false); + } + + //T0 + { + //t-zero vs. eta & phi + TH1F* m_t0_eta_phi = (TH1F*)dir1->Get("m_t0_eta_phi"); + + TH2F* m_t0_eta_phi_entries = (TH2F*)dir1->Get("m_t0_eta_phi_entries"); + TH2F* m_t0_eta_phi_weights = (TH2F*)dir1->Get("m_t0_eta_phi_weights"); + TH2F* m_t0_eta_phi_mean = (TH2F*)dir1->Get("m_t0_eta_phi_mean"); + + SimpleMean(m_t0_eta_phi_mean,m_t0_eta_phi_weights,m_t0_eta_phi_entries,m_t0_eta_phi,false); + + TH1F* m_t0_eta_phi_i = (TH1F*)dir1->Get("m_t0_eta_phi_i"); + TH2F* m_t0_eta_phi_i_entries = (TH2F*)dir1->Get("m_t0_eta_phi_i_entries"); + TH2F* m_t0_eta_phi_i_weights = (TH2F*)dir1->Get("m_t0_eta_phi_i_weights"); + TH2F* m_t0_eta_phi_i_mean = (TH2F*)dir1->Get("m_t0_eta_phi_i_mean"); + + SimpleMean(m_t0_eta_phi_i_mean,m_t0_eta_phi_i_weights,m_t0_eta_phi_i_entries,m_t0_eta_phi_i,false); + + TH1F* m_t0_eta_phi_m = (TH1F*)dir1->Get("m_t0_eta_phi_m"); + TH2F* m_t0_eta_phi_m_entries = (TH2F*)dir1->Get("m_t0_eta_phi_m_entries"); + TH2F* m_t0_eta_phi_m_weights = (TH2F*)dir1->Get("m_t0_eta_phi_m_weights"); + TH2F* m_t0_eta_phi_m_mean = (TH2F*)dir1->Get("m_t0_eta_phi_m_mean"); + + SimpleMean(m_t0_eta_phi_m_mean,m_t0_eta_phi_m_weights,m_t0_eta_phi_m_entries,m_t0_eta_phi_m,false); + + TH1F* m_t0_eta_phi_o = (TH1F*)dir1->Get("m_t0_eta_phi_o"); + TH2F* m_t0_eta_phi_o_entries = (TH2F*)dir1->Get("m_t0_eta_phi_o_entries"); + TH2F* m_t0_eta_phi_o_weights = (TH2F*)dir1->Get("m_t0_eta_phi_o_weights"); + TH2F* m_t0_eta_phi_o_mean = (TH2F*)dir1->Get("m_t0_eta_phi_o_mean"); + + SimpleMean(m_t0_eta_phi_o_mean,m_t0_eta_phi_o_weights,m_t0_eta_phi_o_entries,m_t0_eta_phi_o,false); + + + //Resolved by Lumi Block and Large Detector Region + + TH1F* m_t0_LB_EA = (TH1F*)dir1->Get("m_Good_t0_EA"); + TH1F* m_t0_LB_EA_entries = (TH1F*)dir1->Get("m_t0_LB_EA_entries"); + TH1F* m_t0_LB_EA_weights = (TH1F*)dir1->Get("m_t0_LB_EA_weights"); + TH1F* m_t0_LB_EA_mean = (TH1F*)dir1->Get("m_t0_LB_EA_mean"); + + SimpleMean(m_t0_LB_EA_mean,m_t0_LB_EA_weights,m_t0_LB_EA_entries,m_t0_LB_EA,false); + + TH1F* m_t0_LB_BA = (TH1F*)dir1->Get("m_Good_t0_BA"); + TH1F* m_t0_LB_BA_entries = (TH1F*)dir1->Get("m_t0_LB_BA_entries"); + TH1F* m_t0_LB_BA_weights = (TH1F*)dir1->Get("m_t0_LB_BA_weights"); + TH1F* m_t0_LB_BA_mean = (TH1F*)dir1->Get("m_t0_LB_BA_mean"); + + SimpleMean(m_t0_LB_BA_mean,m_t0_LB_BA_weights,m_t0_LB_BA_entries,m_t0_LB_BA,false); + + TH1F* m_t0_LB_BC = (TH1F*)dir1->Get("m_Good_t0_BC"); + TH1F* m_t0_LB_BC_entries = (TH1F*)dir1->Get("m_t0_LB_BC_entries"); + TH1F* m_t0_LB_BC_weights = (TH1F*)dir1->Get("m_t0_LB_BC_weights"); + TH1F* m_t0_LB_BC_mean = (TH1F*)dir1->Get("m_t0_LB_BC_mean"); + + SimpleMean(m_t0_LB_BC_mean,m_t0_LB_BC_weights,m_t0_LB_BC_entries,m_t0_LB_BC,false); + + TH1F* m_t0_LB_EC = (TH1F*)dir1->Get("m_Good_t0_EC"); + TH1F* m_t0_LB_EC_entries = (TH1F*)dir1->Get("m_t0_LB_EC_entries"); + TH1F* m_t0_LB_EC_weights = (TH1F*)dir1->Get("m_t0_LB_EC_weights"); + TH1F* m_t0_LB_EC_mean = (TH1F*)dir1->Get("m_t0_LB_EC_mean"); + + SimpleMean(m_t0_LB_EC_mean,m_t0_LB_EC_weights,m_t0_LB_EC_entries,m_t0_LB_EC,false); + } + + // This Needs to be figured out! + //Muons per Run number: make it pretty + /* + TH1F* m_N_Mu_Lumi_Run = (TH1F*)dir1->Get("m_N_Mu_Lumi_Run"); + if (m_N_Mu_Lumi_Run) { + int n_runs = 0; + std::vector<float> mu_vec; + std::vector<TString> runs; + + int firstrun = m_N_Mu_Lumi_Run->GetBinLowEdge(1); + int lastrun = m_N_Mu_Lumi_Run->GetBinLowEdge( m_N_Mu_Lumi_Run->GetNbinsX() + 1 ); + for (int run = firstrun; run != lastrun; run++){ + int bin = m_N_Mu_Lumi_Run->FindBin(run); + float n_mu = m_N_Mu_Lumi_Run->GetBinContent(bin); + if(n_mu != 0){ + n_runs++; + mu_vec.push_back(n_mu); + stringstream runno; + runno << run; + runs.push_back(runno.str()); + } + } + //std::cout<<__FILE__<<":"<<__LINE__<<endl; + if(n_runs != 0){ + TH1F* Muons_per_Run = new TH1F("Muons_per_Run","Muons_per_Run",n_runs,0,n_runs); + for(int j = 0; j < n_runs; j++){ + Muons_per_Run->SetBinContent(j+1,mu_vec.at(j)); + Muons_per_Run->GetXaxis()->SetBinLabel(j+1,runs.at(j)); + } + Muons_per_Run->Write("",TObject::kOverwrite); + } + } + //std::cout<<__FILE__<<":"<<__LINE__<<endl; + */ + + + // Good t0 Fits + { + std::vector<TString> string_vec; + string_vec.clear(); + string_vec.push_back("EC"); + string_vec.push_back("BC"); + string_vec.push_back("BA"); + string_vec.push_back("EA"); + //std::cout<<__FILE__<<":"<<__LINE__<<endl; + TH1F* m_Good_t0 = (TH1F*)dir1->Get("m_Good_t0"); + TH1F* h_t0 = 0; + if(m_Good_t0){ + for(unsigned int st_itr = 0; st_itr < string_vec.size(); st_itr++){ + + h_t0 = (TH1F*)dir1->Get("m_Good_t0_"+string_vec.at(st_itr)); + if (!h_t0) { + continue; + } + + float results[4] = {0.0,0.0,0.0,0.0}; + h_t0->Rebin(5); + DGausFit(h_t0,results,5); + + //Clean Up + m_Good_t0->SetBinContent(st_itr+1,0.0);//Mean + m_Good_t0->SetBinError (st_itr+1,0.0);//Rms + + //Assign Fit Values + m_Good_t0->SetBinContent(st_itr+1,results[0]);//Mean + m_Good_t0->SetBinError (st_itr+1,results[2]/sqrt(h_t0->GetEntries()));//Rms + + m_Good_t0->Write("",TObject::kOverwrite); + } + } + } + + + } + + + f->Close(); + delete f; + + return; + + } //End Tracking general function + + + void MonitoringFile::MuonTrkPhys_DetectorSpecific( std::string inFilename ){ + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + if (f == 0) { + std::cerr << "MuonTrkPhys(): " + << "Input file not opened \n"; + return; + } + if(f->GetSize()<1000.) { + std::cerr << "MuonTrkPhys(): " + << "Input file empty \n"; + return; + } + + //Define Constants + std::vector<TString> phi_vec; + phi_vec.push_back("S01"); + phi_vec.push_back("S02"); + phi_vec.push_back("S03"); + phi_vec.push_back("S04"); + phi_vec.push_back("S05"); + phi_vec.push_back("S06"); + phi_vec.push_back("S07"); + phi_vec.push_back("S08"); + phi_vec.push_back("S09"); + phi_vec.push_back("S10"); + phi_vec.push_back("S11"); + phi_vec.push_back("S12"); + phi_vec.push_back("S13"); + phi_vec.push_back("S14"); + phi_vec.push_back("S15"); + phi_vec.push_back("S16"); + + std::vector<TString> side_vec; + side_vec.push_back("A"); + side_vec.push_back("C"); + + std::vector<TString> string_vec; + string_vec.push_back("EC"); + string_vec.push_back("BC"); + string_vec.push_back("BA"); + string_vec.push_back("EA"); + + + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + if (key0 == 0) return; + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + if (dir0 == 0) return; + dir0->cd(); + /// + + TString runNumber = dir0->GetName(); + TString mDir = runNumber+"/Muon/MuonTrkPhysMonitoring/NoTrigger/Detector_Specific/"; + if (! f->cd(mDir)) return; + //std::cout<<"jk: in directory "<<mDir<<std::endl; + TIter nextcd1(gDirectory->GetListOfKeys()); + while(TKey* key1 = dynamic_cast<TKey*>(nextcd1())) {//While in Staco/Muid/Third chain + TString recalg_fullStr = mDir+key1->GetName(); + TDirectory* dir1 = f->GetDirectory(recalg_fullStr); + if(!dir1) continue; + dir1->cd(); + + + + //MDT HitResiduals: + + //std::cout<<"ab: MDT HitResiduals!\n"; + + TH2F* m_HitRes_Eta_Phi_Mean_I = (TH2F*)dir1->Get("m_HitRes_Eta_Phi_Mean_I"); + TH2F* m_HitRes_Eta_Phi_Mean_M = (TH2F*)dir1->Get("m_HitRes_Eta_Phi_Mean_M"); + TH2F* m_HitRes_Eta_Phi_Mean_O = (TH2F*)dir1->Get("m_HitRes_Eta_Phi_Mean_O"); + TH2F* m_HitRes_Eta_Phi_Width_I = (TH2F*)dir1->Get("m_HitRes_Eta_Phi_Width_I"); + TH2F* m_HitRes_Eta_Phi_Width_M = (TH2F*)dir1->Get("m_HitRes_Eta_Phi_Width_M"); + TH2F* m_HitRes_Eta_Phi_Width_O = (TH2F*)dir1->Get("m_HitRes_Eta_Phi_Width_O"); + + TH1D* HitResProfile = 0; + TH2F* HitResHist = 0; + + for(int phi_itr = 0; phi_itr < m_HitRes_Eta_Phi_Mean_I->GetNbinsY(); phi_itr++){ + int j = phi_itr+1; + + for(int eta_itr = 0; eta_itr < m_HitRes_Eta_Phi_Mean_I->GetNbinsX(); eta_itr++){ + int i = eta_itr+1; + + if (m_HitRes_Eta_Phi_Mean_I && m_HitRes_Eta_Phi_Width_I) { + HitResHist = (TH2F*)dir1->Get("m_HR_Eta_"+phi_vec.at(phi_itr)+"_I"); + if(HitResHist) HitResProfile = HitResHist->ProjectionX("_pfx",eta_itr+1,eta_itr+1); + + m_HitRes_Eta_Phi_Mean_I->SetBinContent(i,j,0.0); + m_HitRes_Eta_Phi_Mean_I->SetBinError (i,j,0.0); + m_HitRes_Eta_Phi_Width_I->SetBinContent(i,j,0.0); + m_HitRes_Eta_Phi_Width_I->SetBinError (i,j,0.0); + + float results[4] = {0.0,0.0,0.0,0.0}; + if(HitResProfile) HitResProfile->Rebin(8); + DGausFit(HitResProfile,results,5,false); + + m_HitRes_Eta_Phi_Mean_I->SetBinContent (i,j,results[0]); + m_HitRes_Eta_Phi_Mean_I->SetBinError (i,j,results[1]); + m_HitRes_Eta_Phi_Width_I->SetBinContent(i,j,results[2]); + m_HitRes_Eta_Phi_Width_I->SetBinError (i,j,results[3]); + + delete HitResProfile; + + } + + //------ + + if (m_HitRes_Eta_Phi_Mean_M && m_HitRes_Eta_Phi_Width_M) { + HitResHist = (TH2F*)dir1->Get("m_HR_Eta_"+phi_vec.at(phi_itr)+"_M"); + if(HitResHist) HitResProfile = HitResHist->ProjectionX("_pfx",eta_itr+1,eta_itr+1); + + m_HitRes_Eta_Phi_Mean_M->SetBinContent(i,j,0.0); + m_HitRes_Eta_Phi_Mean_M->SetBinError (i,j,0.0); + m_HitRes_Eta_Phi_Width_M->SetBinContent(i,j,0.0); + m_HitRes_Eta_Phi_Width_M->SetBinError (i,j,0.0); + + float results[4] = {0.0,0.0,0.0,0.0}; + if(HitResProfile) HitResProfile->Rebin(8); + DGausFit(HitResProfile,results,5,false); + + m_HitRes_Eta_Phi_Mean_M->SetBinContent (i,j,results[0]); + m_HitRes_Eta_Phi_Mean_M->SetBinError (i,j,results[1]); + m_HitRes_Eta_Phi_Width_M->SetBinContent(i,j,results[2]); + m_HitRes_Eta_Phi_Width_M->SetBinError (i,j,results[3]); + + + delete HitResProfile; + } + + //------ + if (m_HitRes_Eta_Phi_Mean_O && m_HitRes_Eta_Phi_Width_O) { + HitResHist = (TH2F*)dir1->Get("m_HR_Eta_"+phi_vec.at(phi_itr)+"_O"); + if(HitResHist) HitResProfile = HitResHist->ProjectionX("_pfx",eta_itr+1,eta_itr+1); + + m_HitRes_Eta_Phi_Mean_O->SetBinContent(i,j,0.0); + m_HitRes_Eta_Phi_Mean_O->SetBinError (i,j,0.0); + m_HitRes_Eta_Phi_Width_O->SetBinContent(i,j,0.0); + m_HitRes_Eta_Phi_Width_O->SetBinError (i,j,0.0); + + float results[4] = {0.0,0.0,0.0,0.0}; + if(HitResProfile) HitResProfile->Rebin(8); + DGausFit(HitResProfile,results,5,false); + + m_HitRes_Eta_Phi_Mean_O->SetBinContent (i,j,results[0]); + m_HitRes_Eta_Phi_Mean_O->SetBinError (i,j,results[1]); + m_HitRes_Eta_Phi_Width_O->SetBinContent(i,j,results[2]); + m_HitRes_Eta_Phi_Width_O->SetBinError (i,j,results[3]); + + + delete HitResProfile; + } + } + } + + if(m_HitRes_Eta_Phi_Mean_I) m_HitRes_Eta_Phi_Mean_I->Write("",TObject::kOverwrite); + if(m_HitRes_Eta_Phi_Mean_M) m_HitRes_Eta_Phi_Mean_M->Write("",TObject::kOverwrite); + if(m_HitRes_Eta_Phi_Mean_O) m_HitRes_Eta_Phi_Mean_O->Write("",TObject::kOverwrite); + if(m_HitRes_Eta_Phi_Width_I) m_HitRes_Eta_Phi_Width_I->Write("",TObject::kOverwrite); + if(m_HitRes_Eta_Phi_Width_M) m_HitRes_Eta_Phi_Width_M->Write("",TObject::kOverwrite); + if(m_HitRes_Eta_Phi_Width_O) m_HitRes_Eta_Phi_Width_O->Write("",TObject::kOverwrite); + + // BEE + //std::cout<<"ab: BEE HitResiduals!\n"; + for (unsigned int side_itr = 0; side_itr < side_vec.size(); side_itr++) { + + TH1F* h_UHitRes = (TH1F*)dir1->Get("m_"+side_vec.at(side_itr)+"_BEE_UHitRes"); + if(!h_UHitRes) continue; + + TH1F* h_residual= 0; + + for(unsigned int phi_itr = 0; phi_itr < phi_vec.size(); phi_itr++){ + + h_residual = (TH1F*)dir1->Get("m_"+side_vec.at(side_itr)+"_BEE_"+phi_vec.at(phi_itr)); + if (!h_residual) continue; + h_residual->Rebin(8); + + if (phi_itr%2 == 0) { + h_UHitRes->SetBinContent (phi_itr+1,0.0);//Mean + h_UHitRes->SetBinError (phi_itr+1,0.0);//Width + continue; + } + + h_UHitRes->SetBinContent(phi_itr+1,0.0); + h_UHitRes->SetBinError (phi_itr+1,0.0); + + float results[4] = {0.0,0.0,0.0,0.0}; + + DGausFit(h_residual,results,4.); + + h_UHitRes->SetBinContent (phi_itr+1,results[0]);//Mean + h_UHitRes->SetBinError (phi_itr+1,results[2]/sqrt(h_residual->GetEntries()));//Width + } + + h_UHitRes->Write("",TObject::kOverwrite); + + } + + //EE + //std::cout<<"ab: EE HitResiduals!\n"; + for (unsigned int side_itr = 0; side_itr < side_vec.size(); side_itr++) { + + TH1F* h_UHitRes = (TH1F*)dir1->Get("m_"+side_vec.at(side_itr)+"_EE_UHitRes"); + if(!h_UHitRes) continue; + + TH1F* h_residual; + + for(unsigned int phi_itr = 0; phi_itr < phi_vec.size(); phi_itr++){ + + h_residual = (TH1F*)dir1->Get("m_"+side_vec.at(side_itr)+"_EE_"+phi_vec.at(phi_itr)); + if (!h_residual) continue; + h_residual->Rebin(8); + + //only 3, 5, 11, 13 installed on A side + if (side_itr == 0 && !(phi_itr == 2 || phi_itr == 4 || phi_itr == 10 || phi_itr == 12) ) + { + h_UHitRes->SetBinContent (phi_itr+1,0.0);//Mean + h_UHitRes->SetBinError (phi_itr+1,0.0);//Width + continue; + } + + h_UHitRes->SetBinContent(phi_itr+1,0.0); + h_UHitRes->SetBinError (phi_itr+1,0.0); + + float results[4] = {0.0,0.0,0.0,0.0}; + + DGausFit(h_residual,results,5./2.); + + h_UHitRes->SetBinContent (phi_itr+1,results[0]);//Mean + h_UHitRes->SetBinError (phi_itr+1,results[2]/sqrt(h_residual->GetEntries()));//Width + } + + h_UHitRes->Write("",TObject::kOverwrite); + } + + //CSC + //std::cout<<"ab: CSC HitResiduals!\n"; + for (unsigned int side_itr = 0; side_itr < side_vec.size(); side_itr++) { + + TH1F* h_UHitRes = (TH1F*)dir1->Get("m_"+side_vec.at(side_itr)+"_CSC_UHitRes"); + if(!h_UHitRes) continue; + + TH1F* h_residual; + + for(unsigned int phi_itr = 0; phi_itr < phi_vec.size(); phi_itr++){ + + h_residual = (TH1F*)dir1->Get("m_"+side_vec.at(side_itr)+"_CSC_UHitRes_"+phi_vec.at(phi_itr)); + if (!h_residual) continue; + h_residual->Rebin(8); + + h_UHitRes->SetBinContent(phi_itr+1,0.0); + h_UHitRes->SetBinError (phi_itr+1,0.0); + + float results[4] = {0.0,0.0,0.0,0.0}; + + DGausFit(h_residual,results,5./2.); + + h_UHitRes->SetBinContent (phi_itr+1,results[0]);//Mean + h_UHitRes->SetBinError (phi_itr+1,results[2]/sqrt(h_residual->GetEntries()));//Width + } + + h_UHitRes->Write("",TObject::kOverwrite); + } + + + //std::cout<<"ab: MDT Track Residuals!\n"; + TH1F* m_MDT_TrackResiduals = (TH1F*)dir1->Get("m_MDT_TrackResiduals"); + TH1F * h_residual = 0; + + if(m_MDT_TrackResiduals){ + for(unsigned int st_itr = 0; st_itr < string_vec.size(); st_itr++){ + + h_residual = (TH1F*)dir1->Get("m_MDT_TR_"+string_vec.at(st_itr)); + if (!h_residual) continue; + h_residual->Rebin(8); + + m_MDT_TrackResiduals->SetBinContent(st_itr+1,0.0); + m_MDT_TrackResiduals->SetBinError (st_itr+1,0.0); + + float results[4] = {0.0,0.0,0.0,0.0}; + + DGausFit(h_residual,results,3.); + + m_MDT_TrackResiduals->SetBinContent (st_itr+1,results[0]);//Mean + m_MDT_TrackResiduals->SetBinError (st_itr+1,results[2]/sqrt(h_residual->GetEntries()));//Width + + } + + m_MDT_TrackResiduals->Write("",TObject::kOverwrite); + } + + + } + + f->Close(); + delete f; + + return; + + } //End Detector-specific function + + + void MonitoringFile::MuonTrkPhys_BField( std::string inFilename ){ + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + if (f == 0) { + std::cerr << "MuonTrkPhys(): " + << "Input file not opened \n"; + return; + } + if(f->GetSize()<1000.) { + std::cerr << "MuonTrkPhys(): " + << "Input file empty \n"; + return; + } + + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + if (key0 == 0) return; + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + if (dir0 == 0) return; + dir0->cd(); + /// + + TString runNumber = dir0->GetName(); + TString mDir = runNumber+"/Muon/MuonTrkPhysMonitoring/NoTrigger/B_Field_Alignment/"; + if (! f->cd(mDir)) return; + //std::cout<<"jk: in directory "<<mDir<<std::endl; + TIter nextcd1(gDirectory->GetListOfKeys()); + while(TKey* key1 = dynamic_cast<TKey*>(nextcd1())) {//While in Staco/Muid/Third chain + TString recalg_fullStr = mDir+key1->GetName(); + TDirectory* dir1 = f->GetDirectory(recalg_fullStr); + if(!dir1) continue; + dir1->cd(); + + TH1F* m_oPt_ms_id_sum = (TH1F*)dir1->Get("m_oPt_ms_id_sum"); + TH1F* m_oPt_ms_id_sum_entries = (TH1F*)dir1->Get("m_oPt_ms_id_sum_entries"); + TH1F* m_oPt_ms_id_sum_weights = (TH1F*)dir1->Get("m_oPt_ms_id_sum_weights"); + TH1F* m_oPt_ms_id_sum_mean = (TH1F*)dir1->Get("m_oPt_ms_id_sum_mean"); + + SimpleMean(m_oPt_ms_id_sum_mean,m_oPt_ms_id_sum_weights,m_oPt_ms_id_sum_entries,m_oPt_ms_id_sum); + + TH1F* m_LSag = (TH1F*)dir1->Get("m_LSag"); + TH1F* m_LSag_entries = (TH1F*)dir1->Get("m_LSag_entries"); + TH1F* m_LSag_weights = (TH1F*)dir1->Get("m_LSag_weights"); + TH1F* m_LSag_mean = (TH1F*)dir1->Get("m_LSag_mean"); + + SimpleMean(m_LSag_mean,m_LSag_weights,m_LSag_entries,m_LSag); + + + TH2F* m_LSag_eta_phi_entries = (TH2F*)dir1->Get("m_LSag_eta_phi_entries"); + TH2F* m_LSag_eta_phi_weights = (TH2F*)dir1->Get("m_LSag_eta_phi_weights"); + TH2F* m_LSag_eta_phi_mean = (TH2F*)dir1->Get("m_LSag_eta_phi_mean"); + + SimpleMean(m_LSag_eta_phi_mean,m_LSag_eta_phi_weights,m_LSag_eta_phi_entries,m_LSag); + + } + + f->Close(); + delete f; + + return; + + } //End B-Field function + + + void MonitoringFile::MuonTrkPhys_Alignment( std::string inFilename ){ + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + + if (f == 0) { + std::cerr << "MuonTrkPhys(): " + << "Input file not opened \n"; + return; + } + if(f->GetSize()<1000.) { + std::cerr << "MuonTrkPhys(): " + << "Input file empty \n"; + return; + } + + //Set Constants + //delta z0 by eta, phi + std::vector<TString> sectors; + sectors.push_back("_S01"); + sectors.push_back("_S02"); + sectors.push_back("_S03"); + sectors.push_back("_S04"); + sectors.push_back("_S05"); + sectors.push_back("_S06"); + sectors.push_back("_S07"); + sectors.push_back("_S08"); + sectors.push_back("_S09"); + sectors.push_back("_S10"); + sectors.push_back("_S11"); + sectors.push_back("_S12"); + sectors.push_back("_S13"); + sectors.push_back("_S14"); + sectors.push_back("_S15"); + sectors.push_back("_S16"); + + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + if (key0 == 0) return; + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + if (dir0 == 0) return; + dir0->cd(); + /// + + TString runNumber = dir0->GetName(); + TString mDir = runNumber+"/Muon/MuonTrkPhysMonitoring/NoTrigger/MS_ID_Alignment/"; + if (! f->cd(mDir)) return; + //std::cout<<"jk: in directory "<<mDir<<std::endl; + TIter nextcd1(gDirectory->GetListOfKeys()); + while(TKey* key1 = dynamic_cast<TKey*>(nextcd1())) {//While in Staco/Muid/Third chain + TString recalg_fullStr = mDir+key1->GetName(); + TDirectory* dir1 = f->GetDirectory(recalg_fullStr); + if(!dir1) continue; + dir1->cd(); + + //Q/pT, positive + TH1F* m_QoPt_ms_id_sum_pos = (TH1F*)dir1->Get("m_QoPt_ms_id_sum_pos"); + TH1F* m_QoPt_ms_id_sum_entries_pos = (TH1F*)dir1->Get("m_QoPt_ms_id_sum_entries_pos"); + TH1F* m_QoPt_ms_id_sum_weights_pos = (TH1F*)dir1->Get("m_QoPt_ms_id_sum_weights_pos"); + TH1F* m_QoPt_ms_id_sum_mean_pos = (TH1F*)dir1->Get("m_QoPt_ms_id_sum_mean_pos"); + + SimpleMean(m_QoPt_ms_id_sum_mean_pos,m_QoPt_ms_id_sum_weights_pos,m_QoPt_ms_id_sum_entries_pos,m_QoPt_ms_id_sum_pos); + + //Q/pT, negative + TH1F* m_QoPt_ms_id_sum_neg = (TH1F*)dir1->Get("m_QoPt_ms_id_sum_neg"); + TH1F* m_QoPt_ms_id_sum_entries_neg = (TH1F*)dir1->Get("m_QoPt_ms_id_sum_entries_neg"); + TH1F* m_QoPt_ms_id_sum_weights_neg = (TH1F*)dir1->Get("m_QoPt_ms_id_sum_weights_neg"); + TH1F* m_QoPt_ms_id_sum_mean_neg = (TH1F*)dir1->Get("m_QoPt_ms_id_sum_mean_neg"); + + SimpleMean(m_QoPt_ms_id_sum_mean_neg,m_QoPt_ms_id_sum_weights_neg,m_QoPt_ms_id_sum_entries_neg,m_QoPt_ms_id_sum_neg); + + + //1/pT, positive + TH1F* m_oPt_sum_pos = (TH1F*)dir1->Get("m_oPt_sum_pos"); + TH1F* m_oPt_sum_entries_pos = (TH1F*)dir1->Get("m_oPt_sum_entries_pos"); + TH1F* m_oPt_sum_weights_pos = (TH1F*)dir1->Get("m_oPt_sum_weights_pos"); + TH1F* m_oPt_sum_mean_pos = (TH1F*)dir1->Get("m_oPt_sum_mean_pos"); + + SimpleMean(m_oPt_sum_mean_pos,m_oPt_sum_weights_pos,m_oPt_sum_entries_pos,m_oPt_sum_pos); + + + //1/pT, negative + TH1F* m_oPt_sum_neg = (TH1F*)dir1->Get("m_oPt_sum_neg"); + TH1F* m_oPt_sum_entries_neg = (TH1F*)dir1->Get("m_oPt_sum_entries_neg"); + TH1F* m_oPt_sum_weights_neg = (TH1F*)dir1->Get("m_oPt_sum_weights_neg"); + TH1F* m_oPt_sum_mean_neg = (TH1F*)dir1->Get("m_oPt_sum_mean_neg"); + + SimpleMean(m_oPt_sum_mean_neg,m_oPt_sum_weights_neg,m_oPt_sum_entries_neg,m_oPt_sum_neg); + + + //Relative p, positive + TH1F* m_rel_p_ms_id_sum_pos = (TH1F*)dir1->Get("m_rel_p_ms_id_sum_pos"); + TH2F* m_rel_p_ms_id_sum_entries_pos = (TH2F*)dir1->Get("m_rel_p_ms_id_sum_entries_pos"); + TH2F* m_rel_p_ms_id_sum_weights_pos = (TH2F*)dir1->Get("m_rel_p_ms_id_sum_weights_pos"); + TH2F* m_rel_p_ms_id_sum_mean_pos = (TH2F*)dir1->Get("m_rel_p_ms_id_sum_mean_pos"); + + SimpleMean(m_rel_p_ms_id_sum_mean_pos,m_rel_p_ms_id_sum_weights_pos,m_rel_p_ms_id_sum_entries_pos,m_rel_p_ms_id_sum_pos); + + + + //Relative p, negative + TH1F* m_rel_p_ms_id_sum_neg = (TH1F*)dir1->Get("m_rel_p_ms_id_sum_neg"); + TH2F* m_rel_p_ms_id_sum_entries_neg = (TH2F*)dir1->Get("m_rel_p_ms_id_sum_entries_neg"); + TH2F* m_rel_p_ms_id_sum_weights_neg = (TH2F*)dir1->Get("m_rel_p_ms_id_sum_weights_neg"); + TH2F* m_rel_p_ms_id_sum_mean_neg = (TH2F*)dir1->Get("m_rel_p_ms_id_sum_mean_neg"); + + SimpleMean(m_rel_p_ms_id_sum_mean_neg,m_rel_p_ms_id_sum_weights_neg,m_rel_p_ms_id_sum_entries_neg,m_rel_p_ms_id_sum_neg); + + + // 1/pT: positive - negative + TH1F* m_oPt_Diff = (TH1F*)dir1->Get("m_oPt_Diff"); + if(m_oPt_Diff){ + + for(int j = 1; j <= m_oPt_Diff->GetNbinsX(); j++){ + m_oPt_Diff->SetBinContent(j, m_oPt_sum_mean_pos->GetBinContent(j) - m_oPt_sum_mean_neg->GetBinContent(j)); + m_oPt_Diff->SetBinError(j, sqrt(m_oPt_sum_mean_pos->GetBinError(j)*m_oPt_sum_mean_pos->GetBinError(j)+ + m_oPt_sum_mean_neg->GetBinError(j)*m_oPt_sum_mean_neg->GetBinError(j))); + } + m_oPt_Diff->Write("",TObject::kOverwrite); + } + + //chi2 per ndof + TH1F* m_chi2ndof_CB = (TH1F*)dir1->Get("m_chi2ndof_CB"); + TH1F* m_chi2ndof_CB_entries = (TH1F*)dir1->Get("m_chi2ndof_CB_entries"); + TH1F* m_chi2ndof_CB_weights = (TH1F*)dir1->Get("m_chi2ndof_CB_weights"); + TH1F* m_chi2ndof_CB_mean = (TH1F*)dir1->Get("m_chi2ndof_CB_mean"); + + SimpleMean(m_chi2ndof_CB_mean,m_chi2ndof_CB_weights,m_chi2ndof_CB_entries,m_chi2ndof_CB); + + + + TH2F* m_deltaZ0_CB_Eta_Phi = (TH2F*)dir1->Get("m_deltaZ0_CB_Eta_Phi"); + TH2F* m_deltaZ0_CB_Eta_Phi_Width = (TH2F*)dir1->Get("m_deltaZ0_CB_Eta_Phi_Width"); + if(m_deltaZ0_CB_Eta_Phi && m_deltaZ0_CB_Eta_Phi_Width){ + for(int isec = 0; isec < m_deltaZ0_CB_Eta_Phi->GetNbinsY(); isec++){ + TH2F* deltaZ0 = (TH2F*)dir1->Get("m_deltaZ0_CB"+sectors.at(isec)); + + TH1D * HitResProfile; + + for(int j = 1; j <= deltaZ0->GetNbinsX(); j++){ + HitResProfile = deltaZ0->ProjectionX("_pfx",j,j); + + float results[4] = {0.0,0.0,0.0,0.0}; + DGausFit(HitResProfile,results,5,false,FLT_MAX,FLT_MAX); + + m_deltaZ0_CB_Eta_Phi->SetBinContent(j, isec+1, results[0]); + m_deltaZ0_CB_Eta_Phi_Width->SetBinContent(j, isec+1, results[2]); + } + + } + + + m_deltaZ0_CB_Eta_Phi->Write("",TObject::kOverwrite); + m_deltaZ0_CB_Eta_Phi_Width->Write("",TObject::kOverwrite); + } + + TH2F* m_deltaZ0_CB = (TH2F*)dir1->Get("m_deltaZ0_CB"); + TH1F* m_deltaZ0_CB_Eta_AllSectors = (TH1F*)dir1->Get("m_deltaZ0_CB_Eta_AllSectors"); + + if(m_deltaZ0_CB && m_deltaZ0_CB_Eta_AllSectors){ + + TH1D * HitResProfile; + + for(int j = 1; j <= m_deltaZ0_CB_Eta_AllSectors->GetNbinsX(); j++){ + HitResProfile = m_deltaZ0_CB->ProjectionX("_pfx",j,j); + + + float results[4] = {0.0,0.0,0.0,0.0}; + DGausFit(HitResProfile,results,5,false,FLT_MAX,FLT_MAX); + + m_deltaZ0_CB_Eta_AllSectors->SetBinContent(j,results[0]); + m_deltaZ0_CB_Eta_AllSectors->SetBinError(j,HitResProfile->GetEntries() ? results[2]/std::sqrt(HitResProfile->GetEntries()) : 0.0); + } + + + m_deltaZ0_CB_Eta_AllSectors->Write("",TObject::kOverwrite); + } + + } + + f->Close(); + delete f; + + } //End MS-ID Alignment + + + Double_t MonitoringFile::MuonTrkPhys_BWgaus(Double_t *x, Double_t *par) + { + //printf("BreitGaus input parameter %f %f %f \n",par[0],par[1],par[2]); + //Fit parameters: + //par[0]=Width (scale) Breit-Wigner + //par[1]=Most Probable (MP, location) Breit mean + //par[2]=Width (sigma) of convoluted Gaussian function + // + // + //In the Landau distribution (represented by the CERNLIB approximation), + //the maximum is located at x=-0.22278298 with the location parameter=0. + //This shift is corrected within this function, so that the actual + //maximum is identical to the MP parameter. + + // Numeric constants + Double_t invsq2pi = 0.3989422804014; // (2 pi)^(-1/2) + //Double_t twoPi = 6.2831853071795;//2Pi + + // Control constants + Double_t np = 100.0; // number of convolution steps + Double_t sc = 5.0; // convolution extends to +-sc Gaussian sigmas + + // Variables + Double_t xx; + Double_t fland; + Double_t sum = 0.0; + Double_t xlow,xupp; + Double_t step; + Double_t i; + + // Range of convolution integral + xlow = x[0] - sc * par[2]; + xupp = x[0] + sc * par[2]; + + step = (xupp-xlow) / np; + + // Convolution integral of Breit and Gaussian by sum + for(i=1.0; i<=np/2; i++) { + xx = xlow + (i-.5) * step; + fland = TMath::BreitWigner(xx,par[1],par[0]); + sum += fland * TMath::Gaus(x[0],xx,par[2]); + + xx = xupp - (i-.5) * step; + fland = TMath::BreitWigner(xx,par[1],par[0]); + sum += fland * TMath::Gaus(x[0],xx,par[2]); + } + return (step * sum * invsq2pi / par[2]); + } + + Double_t MonitoringFile::MuonTrkPhys_fitFunctionS(Double_t *x, Double_t *par) {return par[0]*(MuonTrkPhys_BWgaus(x,&par[1])) + par[4];} + +} //namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_PPFileWrapper.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_PPFileWrapper.cxx new file mode 100644 index 0000000000000000000000000000000000000000..aed3a7cd7d1c4236feda528ec9f1192db786b795 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_PPFileWrapper.cxx @@ -0,0 +1,182 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//File Wrapper class to keep track of histograms and manage memory +//Required due to problems with root's intrinsic memory management +//Author: Matt King (matthew.king@cern.ch) +// Copied from code by Justin Griffiths +//Date: May 2010 +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TTree.h" +#include "TBranch.h" +#include "TGraph.h" + +namespace dqutils { + + MonitoringFile::PostProcessorFileWrapper::PostProcessorFileWrapper(std::string inFilename, std::string name) : + TFile( inFilename.c_str(), "UPDATE" ), + m_name(name), + m_error(0) + { + if(this->IsOpen()){ + //std::cout << "Begin " << m_name << " MonitoringFile: " << this->GetName() << " Size: " << this->GetSize() << std::endl; + }else{ + std::cerr << "ERROR " << m_name << " Could not open MonitoringFile: " << inFilename << std::endl; + } + } + + MonitoringFile::PostProcessorFileWrapper::~PostProcessorFileWrapper(){ + //std::cout << "Destructing " << m_name << " Collected " << m_garbage.size() << " Objects to be deleted" << std::endl; + if(!m_error){ + this->Write(); + }else{ + std::cerr << "ERROR " << m_name << " Chose Not To Write " << this->GetName() << std::endl; + } + this->Close(); + for(std::set<TObject*>::const_iterator git = m_garbage.begin(); git != m_garbage.end(); ++git){ + delete *git; + } + //std::cout << "\n"; + } + + /* + // get() Defined in header file, otherwise it can't use a template. + // If it can't use a template, then it can't pass a reference to an arbitrary object pointer, + // this solution isn't perfect, but it seems to be the best available. + template <class T> + void MonitoringFile::PostProcessorFileWrapper::getOriginal(const char* namecycle, T* &ptr, TDirectory* baseDir, TDirectory* target){ + + if (baseDir) baseDir->GetObject( namecycle, ptr ); // suggested root function + else this->GetObject( namecycle, ptr ); //suggested root function + if(!ptr) return; + + if((T::Class())->InheritsFrom("TH1")){ + TH1 *obj = reinterpret_cast<TH1*> (ptr); + + obj->SetDirectory(target); + if(target == 0) m_garbage.insert(obj); + } + else{ + TObject *obj = reinterpret_cast<TObject*>(ptr); + + if(target == 0) m_garbage.insert(obj); + } + } + */ + + void MonitoringFile::PostProcessorFileWrapper::error(){ m_error = true; } + + void MonitoringFile::PostProcessorFileWrapper::setDirectory( TH1* h, TDirectory* dir ){ + h->SetDirectory(dir); + if ( dir == 0 ){ m_garbage.insert(h);} + } + + void MonitoringFile::PostProcessorFileWrapper::setDirectory( TH2* h, TDirectory* dir ){ + h->SetDirectory(dir); + if ( dir == 0 ){ m_garbage.insert(h);} + } + + void MonitoringFile::PostProcessorFileWrapper::setDirectory( TGraph* g, TDirectory* dir){ + // Cannot set directory for TGraph + if ( dir == 0 ){ m_garbage.insert(g);} + } + + void MonitoringFile::PostProcessorFileWrapper::setMetaData(TDirectory* targetDir, TH1* h1, TH1* h2, TH1* h3) { + //we will collect the garbage and set the directory to zero + h1->SetDirectory(0); + m_garbage.insert(h1); + if(h2) { h2->SetDirectory(0); m_garbage.insert(h2); } + if(h3) { h3->SetDirectory(0); m_garbage.insert(h3); } + //now call old function being sure not to fill a garbage set + return MonitoringFile::TGCSetMetaData( targetDir, h1, h2, h3); + } + + void MonitoringFile::TGCSetMetaData(TDirectory* targetDir, TH1* h1, TH1* h2, TH1* h3){ + TTree* metadata_overview_tr = 0; + if(!targetDir || !h1) return; + targetDir->GetObject("metadata",metadata_overview_tr); + //Fill Metadata for new objs. + std::string name_; + std::string intervalData_="run"; + std::string chainData_="<none>"; + std::string mergeData_="<default>"; + if(metadata_overview_tr){ + OutputMetadata metadata_overview(metadata_overview_tr); + char name[99]; + char intervalData[99]; + char chainData[99]; + char mergeData[99]; + TBranch* b_name; + TBranch* b_intervalData; + TBranch* b_chainData; + TBranch* b_mergeData; + TTree* tClone = (TTree*) metadata_overview_tr->Clone(); + metadata_overview_tr->SetDirectory(0); + tClone->SetBranchAddress("Name",name,&b_name); + tClone->SetBranchAddress("Interval",intervalData,&b_intervalData); + tClone->SetBranchAddress("TriggerChain",chainData,&b_chainData); + tClone->SetBranchAddress("MergeMethod",mergeData,&b_mergeData); + //Check if Metadata Already Exists + bool isMeta = false; + for(int i = 0; i != tClone->GetEntries(); ++i){ + tClone->GetEntry(i); + intervalData_ = intervalData; + chainData_ = chainData; + mergeData_ = mergeData; + name_ = name; + if(name_ == (std::string) h1->GetName()) isMeta = true; + + } + + delete tClone; + if(isMeta) { + metadata_overview_tr->SetDirectory(0); + delete metadata_overview_tr; + return; + } + metadata_overview.fill(h1->GetName(), intervalData_.c_str(), chainData_.c_str(), mergeData_.c_str()); + if(h2) metadata_overview.fill(h2->GetName(), intervalData_.c_str(), chainData_.c_str(), mergeData_.c_str()); + if(h3) metadata_overview.fill(h3->GetName(), intervalData_.c_str(), chainData_.c_str(), mergeData_.c_str()); + //set new hists to 0 dir + TDirectory* tempDir = gDirectory; + targetDir->cd(); + metadata_overview_tr->Write("",TObject::kOverwrite); + tempDir->cd(); + } + else { + TTree* metadata_overview_tr = new TTree( "metadata", "Monitoring Metadata" ); + OutputMetadata metadata_overview(metadata_overview_tr); + if(h1) metadata_overview.fill( h1->GetName(), intervalData_.c_str(), chainData_.c_str(), mergeData_.c_str()); + TDirectory* tempDir = gDirectory; + targetDir->cd(); + h1->SetDirectory(0); + metadata_overview_tr->Write("",TObject::kOverwrite); + metadata_overview_tr->SetDirectory(0);//make this safe to delete + delete metadata_overview_tr; + tempDir->cd(); + } + } +}//namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_RPCPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_RPCPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4d551b4225ddc181fa26c035ccdb2533195ab5a1 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_RPCPostProcess.cxx @@ -0,0 +1,1205 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//************************************************* +// Class for the RPC merge histogram and fill the COOL DB +// author Michele Bianco michele.bianco@le.infn.it, Gabriele Chiodini gabriele.chiodini@le.infn.it +// and Angelo Guida angelo.guida@le.infn.it +// 08/April/2009 +//************************************************ + +#include "DataQualityUtils/MonitoringFile.h" +#include "DataQualityUtils/CoolRpc.h" + +#include <iostream> +#include <iomanip> +#include <fstream> +#include <cmath> +#include <cstdlib> + +#include "TH1F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" + +namespace dqutils { + +void +MonitoringFile::RPCPostProcess( std::string inFilename, bool /* isIncremental */ ) +{ + // std::cout << "Running RPC post processing \n" ; + + TFile* f = TFile::Open(inFilename.c_str(),"UPDATE"); + if (f == 0) { + std::cerr << "MonitoringFile::RPCPostProcess(): " + << "Input file not opened \n"; + return; + } + if(f->GetSize()<1000.) { + std::cerr << "MonitoringFile::RPCPostProcess(): " + << "Input file empty \n"; + return; + } + CoolRpc coolrpc; + + // get run directory name + std::string run_dir; + TIter next_run ( f->GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*>( next_run() )) !=0 ) { + TObject* obj_run = key_run->ReadObj(); + TDirectory* tdir_run = dynamic_cast<TDirectory*>( obj_run ); + if (tdir_run !=0 ) { + std::string tdir_run_name( tdir_run->GetName() ); + if (tdir_run_name.find("run")!= std::string::npos ) { + run_dir=tdir_run_name; + + int run_number; + run_number = atoi( (run_dir.substr(4, run_dir.size()-4 )).c_str() ); + // std::cout << "run_number " << run_number <<std::endl; + + std::string pathRawMon = run_dir + "/Muon/MuonRawDataMonitoring/RPC/" ; + std::string pathTrackMon = run_dir + "/Muon/MuonTrackMonitoring/NoTrigger/RPCStandAloneTrackMon/" ; + //std::string pathTrackMon = run_dir + "/Muon/MuonTrackMonitoring/RPCStandaloneTracksMon/" ; + + std::string dir_ov_raw = pathRawMon + "Overview/" ; + std::string dir_sum_raw = pathRawMon + "Summary/" ; + std::string dir_dqmf_raw = pathRawMon + "Dqmf/" ; + + std::string dir_sideA_track = pathTrackMon + "RPCBA/" ; + std::string dir_sideC_track = pathTrackMon + "RPCBC/" ; + std::string dir_glob_track = pathTrackMon + "GLOBAL/" ; + std::string dir_sum_track = pathTrackMon + "Summary/" ; + std::string dir_dqmf_track = pathTrackMon + "Dqmf/" ; + + double n_hit_f, n_tr_p, panel_eff, panel_err_eff; + double nEta, nPhi, nEtaPhi, gapEff=0.0, gapErrEff=0.0; + double res_mean, res2_mean, res_RMS; + double panel_occ; + double panelCS, panelCS2, panelCS_entries , panelCS_mean, panelCS2_mean, panelCS_RMS; + double Time_mean, Time2_mean, Time_RMS; + double noiseCorr, noiseCorrErr ; + double noiseTot, noiseTotErr ; + double noiseErrNorm ; + + + + // layer efficiency + std::string LyHit_name, LyPrj_name, LyEff_name ; + LyHit_name = dir_glob_track + "Hit_on_Track_Layer" ; + LyPrj_name = dir_glob_track + "Track_Projected_on_Layer" ; + LyEff_name = dir_glob_track + "Layer_Efficiency" ; + + if ( RPCCheckHistogram(f,LyHit_name.c_str()) && RPCCheckHistogram(f,LyPrj_name.c_str()) && RPCCheckHistogram(f,LyEff_name.c_str()) ) { + TH1I* hist_LyHit = (TH1I*)(f->Get( LyHit_name.c_str())); + TH1I* hist_LyPrj = (TH1I*)(f->Get( LyPrj_name.c_str())); + TH1F* hist_LyEff = (TH1F*)(f->Get( LyEff_name.c_str())); + + int nb = hist_LyEff->GetNbinsX() ; + double Ly_eff, Ly_effErr ; + for ( int ib=0; ib!=nb; ib++ ) { + float n_Ly_hitOn = hist_LyHit->GetBinContent(ib+1) ; + float n_Ly_TrPrj = hist_LyPrj->GetBinContent(ib+1) ; + + if ( n_Ly_TrPrj >0 ) { + Ly_eff = float(n_Ly_hitOn)/float(n_Ly_TrPrj); + + Ly_effErr = sqrt( fabs( n_Ly_hitOn) / n_Ly_TrPrj ) * + sqrt( 1. - fabs( n_Ly_hitOn) / n_Ly_TrPrj ) / + sqrt( n_Ly_TrPrj ) ; + hist_LyEff->SetBinContent(ib+1, Ly_eff) ; + hist_LyEff->SetBinError (ib+1, Ly_effErr) ; + } + } + + // write out histogram + TDirectory* dir = f->GetDirectory( dir_glob_track.c_str() ) ; + if ( dir != 0 ) { + dir->cd() ; + //hist_LyEff->Write(); + hist_LyEff->Write("",TObject::kOverwrite); + } + } + + + // layer efficiency Side A + std::string LyHit_SideA_name, LyPrj_SideA_name, LyEff_SideA_name ; + LyHit_SideA_name = dir_sideA_track + "Layer_HitOnTrack_sideA"; + LyPrj_SideA_name = dir_sideA_track + "Layer_TrackProj_sideA" ; + LyEff_SideA_name = dir_sideA_track + "Layer_Efficiency_sideA"; + + if ( RPCCheckHistogram(f,LyHit_SideA_name.c_str()) && RPCCheckHistogram(f,LyPrj_SideA_name.c_str()) && RPCCheckHistogram(f,LyEff_SideA_name.c_str()) ) { + TH1I* hist_LyHit_SideA = (TH1I*)(f->Get( LyHit_SideA_name.c_str())); + TH1I* hist_LyPrj_SideA = (TH1I*)(f->Get( LyPrj_SideA_name.c_str())); + TH1F* hist_LyEff_SideA = (TH1F*)(f->Get( LyEff_SideA_name.c_str())); + + int nb = hist_LyEff_SideA->GetNbinsX() ; + double Ly_eff_SideA, Ly_effErr_SideA ; + for ( int ib=0; ib!=nb; ib++ ) { + float n_Ly_hitOn_SideA = hist_LyHit_SideA->GetBinContent(ib+1) ; + float n_Ly_TrPrj_SideA = hist_LyPrj_SideA->GetBinContent(ib+1) ; + + if ( n_Ly_TrPrj_SideA >0 ) { + Ly_eff_SideA = float(n_Ly_hitOn_SideA)/float(n_Ly_TrPrj_SideA); + + Ly_effErr_SideA = sqrt( fabs( n_Ly_hitOn_SideA) / n_Ly_TrPrj_SideA ) * + sqrt( 1. - fabs( n_Ly_hitOn_SideA) / n_Ly_TrPrj_SideA ) / + sqrt( n_Ly_TrPrj_SideA ) ; + hist_LyEff_SideA->SetBinContent(ib+1, Ly_eff_SideA) ; + hist_LyEff_SideA->SetBinError (ib+1, Ly_effErr_SideA) ; + } + } + + // write out histogram + TDirectory* dir = f->GetDirectory( dir_sideA_track.c_str() ) ; + if ( dir != 0 ) { + dir->cd() ; + //hist_LyEff->Write(); + hist_LyEff_SideA->Write("",TObject::kOverwrite); + } + } + + // layer efficiency Side C + std::string LyHit_SideC_name, LyPrj_SideC_name, LyEff_SideC_name ; + LyHit_SideC_name = dir_sideC_track + "Layer_HitOnTrack_sideC"; + LyPrj_SideC_name = dir_sideC_track + "Layer_TrackProj_sideC" ; + LyEff_SideC_name = dir_sideC_track + "Layer_Efficiency_sideC"; + + if ( RPCCheckHistogram(f,LyHit_SideC_name.c_str()) && RPCCheckHistogram(f,LyPrj_SideC_name.c_str()) && RPCCheckHistogram(f,LyEff_SideC_name.c_str()) ) { + TH1I* hist_LyHit_SideC = (TH1I*)(f->Get( LyHit_SideC_name.c_str())); + TH1I* hist_LyPrj_SideC = (TH1I*)(f->Get( LyPrj_SideC_name.c_str())); + TH1F* hist_LyEff_SideC = (TH1F*)(f->Get( LyEff_SideC_name.c_str())); + + int nb = hist_LyEff_SideC->GetNbinsX() ; + double Ly_eff_SideC, Ly_effErr_SideC ; + for ( int ib=0; ib!=nb; ib++ ) { + float n_Ly_hitOn_SideC = hist_LyHit_SideC->GetBinContent(ib+1) ; + float n_Ly_TrPrj_SideC = hist_LyPrj_SideC->GetBinContent(ib+1) ; + + if ( n_Ly_TrPrj_SideC >0 ) { + Ly_eff_SideC = float(n_Ly_hitOn_SideC)/float(n_Ly_TrPrj_SideC); + + Ly_effErr_SideC = sqrt( fabs( n_Ly_hitOn_SideC) / n_Ly_TrPrj_SideC ) * + sqrt( 1. - fabs( n_Ly_hitOn_SideC) / n_Ly_TrPrj_SideC ) / + sqrt( n_Ly_TrPrj_SideC ) ; + hist_LyEff_SideC->SetBinContent(ib+1, Ly_eff_SideC) ; + hist_LyEff_SideC->SetBinError (ib+1, Ly_effErr_SideC) ; + } + } + // write out histogram + TDirectory* dir = f->GetDirectory( dir_sideC_track.c_str() ) ; + if ( dir != 0 ) { + dir->cd() ; + //hist_LyEff->Write(); + hist_LyEff_SideC->Write("",TObject::kOverwrite); + } + } + + + + int rpc_eventstotal = 0; + if ( RPCCheckHistogram(f,(dir_ov_raw + "Number_of_RPC_hits_per_event").c_str() ) ) { + TH1I* rpc_hits = (TH1I*)(f->Get((dir_ov_raw + "Number_of_RPC_hits_per_event").c_str() ) ) ; + rpc_eventstotal = int(rpc_hits->GetEntries() ); + } + + + // distribution plot all atlas + std::string AverageEff_C_name = dir_sideC_track + "Efficiency_Distribution_sideC" ; + std::string AverageEff_A_name = dir_sideA_track + "Efficiency_Distribution_sideA" ; + std::string AverageGapEff_C_name = dir_sideC_track + "GapEfficiency_Distribution_sideC" ; + std::string AverageGapEff_A_name = dir_sideA_track + "GapEfficiency_Distribution_sideA" ; + std::string AverageNoiseCorr_C_name = dir_sideC_track + "NoiseCorr_Distribution_sideC" ; + std::string AverageNoiseCorr_A_name = dir_sideA_track + "NoiseCorr_Distribution_sideA" ; + std::string AverageNoiseTot_C_name = dir_sideC_track + "NoiseTot_Distribution_sideC" ; + std::string AverageNoiseTot_A_name = dir_sideA_track + "NoiseTot_Distribution_sideA" ; + std::string AverageCS_C_name = dir_sideC_track + "CS_Distribution_sideC" ; + std::string AverageCS_A_name = dir_sideA_track + "CS_Distribution_sideA" ; + std::string AverageRes_CS1_C_name = dir_sideC_track + "Res_CS1_Distribution_sideC" ; + std::string AverageRes_CS1_A_name = dir_sideA_track + "Res_CS1_Distribution_sideA" ; + std::string AverageRes_CS2_C_name = dir_sideC_track + "Res_CS2_Distribution_sideC" ; + std::string AverageRes_CS2_A_name = dir_sideA_track + "Res_CS2_Distribution_sideA" ; + std::string AverageRes_CSmore2_C_name = dir_sideC_track + "Res_CSmore2_Distribution_sideC" ; + std::string AverageRes_CSmore2_A_name = dir_sideA_track + "Res_CSmore2_Distribution_sideA" ; + std::string AverageRes_CS1rms_C_name = dir_sideC_track + "Res_CS1rms_Distribution_sideC" ; + std::string AverageRes_CS1rms_A_name = dir_sideA_track + "Res_CS1rms_Distribution_sideA" ; + std::string AverageRes_CS2rms_C_name = dir_sideC_track + "Res_CS2rms_Distribution_sideC" ; + std::string AverageRes_CS2rms_A_name = dir_sideA_track + "Res_CS2rms_Distribution_sideA" ; + std::string AverageRes_CSmore2rms_C_name= dir_sideC_track + "Res_CSmore2rms_Distribution_sideC" ; + std::string AverageRes_CSmore2rms_A_name= dir_sideA_track + "Res_CSmore2rms_Distribution_sideA" ; + std::string AverageOccupancy_C_name = dir_sideC_track + "Occupancy_Distribution_sideC" ; + std::string AverageOccupancy_A_name = dir_sideA_track + "Occupancy_Distribution_sideA" ; + std::string AverageTime_C_name = dir_sideC_track + "Time_Distribution_sideC" ; + std::string AverageTime_A_name = dir_sideA_track + "Time_Distribution_sideA" ; + + TH1F* h_AverageEff_C = NULL; + TH1F* h_AverageEff_A = NULL; + TH1F* h_AverageGapEff_C = NULL; + TH1F* h_AverageGapEff_A = NULL; + TH1F* h_AverageNoiseCorr_C = NULL; + TH1F* h_AverageNoiseCorr_A = NULL; + TH1F* h_AverageNoiseTot_C = NULL; + TH1F* h_AverageNoiseTot_A = NULL; + TH1F* h_AverageCS_C = NULL; + TH1F* h_AverageCS_A = NULL; + TH1F* h_AverageRes_CS1_C = NULL; + TH1F* h_AverageRes_CS1_A = NULL; + TH1F* h_AverageRes_CS2_C = NULL; + TH1F* h_AverageRes_CS2_A = NULL; + TH1F* h_AverageRes_CSmore2_C = NULL; + TH1F* h_AverageRes_CSmore2_A = NULL; + TH1F* h_AverageRes_CS1rms_C = NULL; + TH1F* h_AverageRes_CS1rms_A = NULL; + TH1F* h_AverageRes_CS2rms_C = NULL; + TH1F* h_AverageRes_CS2rms_A = NULL; + TH1F* h_AverageRes_CSmore2rms_C = NULL; + TH1F* h_AverageRes_CSmore2rms_A = NULL; + TH1F* h_AverageOccupancy_C = NULL; + TH1F* h_AverageOccupancy_A = NULL; + TH1F* h_AverageTime_C = NULL; + TH1F* h_AverageTime_A = NULL; + + + if ( RPCCheckHistogram( f, AverageEff_C_name.c_str() ) ){ h_AverageEff_C = (TH1F*) ( f->Get( AverageEff_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageEff_A_name.c_str() ) ){ h_AverageEff_A = (TH1F*) ( f->Get( AverageEff_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageGapEff_C_name.c_str() ) ){ h_AverageGapEff_C = (TH1F*) ( f->Get( AverageGapEff_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageGapEff_A_name.c_str() ) ){ h_AverageGapEff_A = (TH1F*) ( f->Get( AverageGapEff_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageNoiseCorr_C_name.c_str() ) ){ h_AverageNoiseCorr_C = (TH1F*) ( f->Get( AverageNoiseCorr_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageNoiseCorr_A_name.c_str() ) ){ h_AverageNoiseCorr_A = (TH1F*) ( f->Get( AverageNoiseCorr_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageNoiseTot_C_name.c_str() ) ){ h_AverageNoiseTot_C = (TH1F*) ( f->Get( AverageNoiseTot_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageNoiseTot_A_name.c_str() ) ){ h_AverageNoiseTot_A = (TH1F*) ( f->Get( AverageNoiseTot_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageCS_C_name.c_str() ) ){ h_AverageCS_C = (TH1F*) ( f->Get( AverageCS_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageCS_A_name.c_str() ) ){ h_AverageCS_A = (TH1F*) ( f->Get( AverageCS_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CS1_C_name.c_str() ) ){ h_AverageRes_CS1_C = (TH1F*) ( f->Get( AverageRes_CS1_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CS1_A_name.c_str() ) ){ h_AverageRes_CS1_A = (TH1F*) ( f->Get( AverageRes_CS1_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CS2_C_name.c_str() ) ){ h_AverageRes_CS2_C = (TH1F*) ( f->Get( AverageRes_CS2_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CS2_A_name.c_str() ) ){ h_AverageRes_CS2_A = (TH1F*) ( f->Get( AverageRes_CS2_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CSmore2_C_name.c_str() ) ){ h_AverageRes_CSmore2_C = (TH1F*) ( f->Get( AverageRes_CSmore2_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CSmore2_A_name.c_str() ) ){ h_AverageRes_CSmore2_A = (TH1F*) ( f->Get( AverageRes_CSmore2_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CS1rms_C_name.c_str() ) ){ h_AverageRes_CS1rms_C = (TH1F*) ( f->Get( AverageRes_CS1rms_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CS1rms_A_name.c_str() ) ){ h_AverageRes_CS1rms_A = (TH1F*) ( f->Get( AverageRes_CS1rms_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CS2rms_C_name.c_str() ) ){ h_AverageRes_CS2rms_C = (TH1F*) ( f->Get( AverageRes_CS2rms_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CS2rms_A_name.c_str() ) ){ h_AverageRes_CS2rms_A = (TH1F*) ( f->Get( AverageRes_CS2rms_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CSmore2rms_C_name.c_str() ) ){ h_AverageRes_CSmore2rms_C = (TH1F*) ( f->Get( AverageRes_CSmore2rms_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageRes_CSmore2rms_A_name.c_str() ) ){ h_AverageRes_CSmore2rms_A = (TH1F*) ( f->Get( AverageRes_CSmore2rms_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageOccupancy_C_name.c_str() ) ){ h_AverageOccupancy_C = (TH1F*) ( f->Get( AverageOccupancy_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageOccupancy_A_name.c_str() ) ){ h_AverageOccupancy_A = (TH1F*) ( f->Get( AverageOccupancy_A_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageTime_C_name.c_str() ) ){ h_AverageTime_C = (TH1F*) ( f->Get( AverageTime_C_name.c_str() ) );} + if ( RPCCheckHistogram( f, AverageTime_A_name.c_str() ) ){ h_AverageTime_A = (TH1F*) ( f->Get( AverageTime_A_name.c_str() ) );} + + if ( h_AverageEff_C ) h_AverageEff_C ->Reset() ; + if ( h_AverageEff_A ) h_AverageEff_A ->Reset() ; + if ( h_AverageGapEff_C ) h_AverageGapEff_C ->Reset() ; + if ( h_AverageGapEff_A ) h_AverageGapEff_A ->Reset() ; + if ( h_AverageNoiseCorr_C ) h_AverageNoiseCorr_C ->Reset() ; + if ( h_AverageNoiseCorr_A ) h_AverageNoiseCorr_A ->Reset() ; + if ( h_AverageNoiseTot_C ) h_AverageNoiseTot_C ->Reset() ; + if ( h_AverageNoiseTot_A ) h_AverageNoiseTot_A ->Reset() ; + if ( h_AverageCS_C ) h_AverageCS_C ->Reset() ; + if ( h_AverageCS_A ) h_AverageCS_A ->Reset() ; + if ( h_AverageRes_CS1_C ) h_AverageRes_CS1_C ->Reset() ; + if ( h_AverageRes_CS1_A ) h_AverageRes_CS1_A ->Reset() ; + if ( h_AverageRes_CS2_C ) h_AverageRes_CS2_C ->Reset() ; + if ( h_AverageRes_CS2_A ) h_AverageRes_CS2_A ->Reset() ; + if ( h_AverageRes_CSmore2_C ) h_AverageRes_CSmore2_C ->Reset() ; + if ( h_AverageRes_CSmore2_A ) h_AverageRes_CSmore2_A ->Reset() ; + if ( h_AverageRes_CS1rms_C ) h_AverageRes_CS1rms_C ->Reset() ; + if ( h_AverageRes_CS1rms_A ) h_AverageRes_CS1rms_A ->Reset() ; + if ( h_AverageRes_CS2rms_C ) h_AverageRes_CS2rms_C ->Reset() ; + if ( h_AverageRes_CS2rms_A ) h_AverageRes_CS2rms_A ->Reset() ; + if ( h_AverageRes_CSmore2rms_C ) h_AverageRes_CSmore2rms_C->Reset() ; + if ( h_AverageRes_CSmore2rms_A ) h_AverageRes_CSmore2rms_A->Reset() ; + if ( h_AverageOccupancy_C ) h_AverageOccupancy_C ->Reset() ; + if ( h_AverageOccupancy_A ) h_AverageOccupancy_A ->Reset() ; + if ( h_AverageTime_C ) h_AverageTime_C ->Reset() ; + if ( h_AverageTime_A ) h_AverageTime_A ->Reset() ; + + // summary plots + for (int i_sec=0; i_sec!=15+1; i_sec++) { + char sector_char[100] ; + std::string sector_name ; + sprintf(sector_char,"_Sector%.2d",i_sec+1) ; // sector number with 2 digits + sector_name = sector_char ; + //std::cout << " sector_name "<< sector_name<<std::endl; + + std::string TrackProj_name = dir_sum_track + "SummaryTrackProj" + sector_name ; + std::string HitOnTrack_name = dir_sum_track + "SummaryHitOnTrack" + sector_name ; + std::string HitOnTrackCross_name = dir_sum_track + "SummaryHitOnTrack_withCrossStrip" + sector_name ; + std::string Eff_name = dir_sum_track + "SummaryEfficiency" + sector_name ; + std::string GapEff_name = dir_sum_track + "SummaryGapEfficiency" + sector_name ; + std::string NoiseCorr_name = dir_sum_track + "SummaryNoiseCorr" + sector_name ; + std::string NoiseCorr_s_name = dir_sum_track + "SummaryNoiseCorr_NotNorm" + sector_name ; + std::string NoiseTot_name = dir_sum_track + "SummaryNoiseTot" + sector_name ; + std::string NoiseTot_s_name = dir_sum_track + "SummaryNoiseTot_NotNorm" + sector_name ; + std::string Res_CS1_name = dir_sum_track + "SummaryRes_CS1" + sector_name ; + std::string Res_CS1_s_name = dir_sum_track + "SummaryRes_CS1_NotNorm" + sector_name ; + std::string Res_CS1_square_name = dir_sum_track + "SummaryRes_CS1_square" + sector_name ; + std::string Res_CS1_entries_name = dir_sum_track + "SummaryRes_CS1_entries" + sector_name ; + std::string Res_CS2_name = dir_sum_track + "SummaryRes_CS2" + sector_name ; + std::string Res_CS2_s_name = dir_sum_track + "SummaryRes_CS2_NotNorm" + sector_name ; + std::string Res_CS2_square_name = dir_sum_track + "SummaryRes_CS2_square" + sector_name ; + std::string Res_CS2_entries_name = dir_sum_track + "SummaryRes_CS2_entries" + sector_name ; + std::string Res_CSmore2_name = dir_sum_track + "SummaryRes_CSmore2" + sector_name ; + std::string Res_CSmore2_s_name = dir_sum_track + "SummaryRes_CSmore2_NotNorm" + sector_name ; + std::string Res_CSmore2_square_name = dir_sum_track + "SummaryRes_CSmore2_square" + sector_name ; + std::string Res_CSmore2_entries_name = dir_sum_track + "SummaryRes_CSmore2_entries" + sector_name ; + std::string CS_name = dir_sum_track + "SummaryCS" + sector_name ; + std::string CS_s_name = dir_sum_track + "SummaryCS_NotNorm" + sector_name ; + std::string CS_square_name = dir_sum_track + "SummaryCS_square" + sector_name ; + std::string CS_entries_name = dir_sum_track + "SummaryCS_entries" + sector_name ; + std::string CS1_entries_name = dir_sum_track + "SummaryCS1_entries" + sector_name ; + std::string CS2_entries_name = dir_sum_track + "SummaryCS2_entries" + sector_name ; + std::string Time_name = dir_sum_track + "SummaryTime" + sector_name ; + std::string Time_s_name = dir_sum_track + "SummaryTime_NotNorm" + sector_name ; + std::string Time_square_name = dir_sum_track + "SummaryTime_square" + sector_name ; + std::string Occupancy_name = dir_sum_track + "SummaryOccupancy" + sector_name ; + std::string Occupancy_s_name = dir_sum_track + "SummaryOccupancy_NotNorm" + sector_name ; + std::string PanelId_name = dir_sum_track + "SummaryPanelID" + sector_name ; + + // distribution plot per sector + std::string EffSecDist_name = dir_sum_track + "SummaryEffDistriPerSector" + sector_name ; + std::string GapEffSecDist_name = dir_sum_track + "SummaryGapEffDistriPerSector" + sector_name ; + std::string NoiseCorrSecDist_name = dir_sum_track + "SummaryNoiseCorrDistriPerSector" + sector_name ; + std::string NoiseTotSecDist_name = dir_sum_track + "SummaryNoiseTotDistriPerSector" + sector_name ; + std::string CSSecDist_name = dir_sum_track + "SummaryCSDistriPerSector" + sector_name ; + std::string Res_CS1SecDist_name = dir_sum_track + "SummaryRes_CS1DistriPerSector" + sector_name ; + std::string Res_CS2SecDist_name = dir_sum_track + "SummaryRes_CS2DistriPerSector" + sector_name ; + std::string Res_CSmore2SecDist_name = dir_sum_track + "SummaryRes_CSmore2DistriPerSector" + sector_name ; + std::string Res_CS1_rmsSecDist_name = dir_sum_track + "SummaryRes_CS1rmsDistriPerSector" + sector_name ; + std::string Res_CS2_rmsSecDist_name = dir_sum_track + "SummaryRes_CS2rmsDistriPerSector" + sector_name ; + std::string Res_CSmore2_rmsSecDist_name = dir_sum_track + "SummaryRes_CSmore2rmsDistriPerSector"+ sector_name ; + std::string TimeSecDist_name = dir_sum_track + "SummaryTimeDistriPerSector" + sector_name ; + std::string OccupancySecDist_name = dir_sum_track + "SummaryOccupancyDistriPerSector" + sector_name ; + + TH1F* h_TrackProj = NULL; + TH1F* h_HitOnTrack = NULL; + TH1F* h_HitOnTrackCross = NULL; + TH1F* h_Eff = NULL; + TH1F* h_GapEff = NULL; + TH1F* h_NoiseCorr = NULL; + TH1F* h_NoiseCorr_s = NULL; + TH1F* h_NoiseTot = NULL; + TH1F* h_NoiseTot_s = NULL; + TH1F* h_Res_CS1 = NULL; + TH1F* h_Res_CS1_s = NULL; + TH1F* h_Res_CS1_square = NULL; + TH1F* h_Res_CS1_entries = NULL; + TH1F* h_Res_CS2 = NULL; + TH1F* h_Res_CS2_s = NULL; + TH1F* h_Res_CS2_square = NULL; + TH1F* h_Res_CS2_entries = NULL; + TH1F* h_Res_CSmore2 = NULL; + TH1F* h_Res_CSmore2_s = NULL; + TH1F* h_Res_CSmore2_square = NULL; + TH1F* h_Res_CSmore2_entries = NULL; + TH1F* h_CS = NULL; + TH1F* h_CS_s = NULL; + TH1F* h_CS_square = NULL; + TH1F* h_CS_entries = NULL; + TH1F* h_CS1_entries = NULL; + TH1F* h_CS2_entries = NULL; + TH1F* h_Time = NULL; + TH1F* h_Time_s = NULL; + TH1F* h_Time_square = NULL; + TH1F* h_Occupancy = NULL; + TH1F* h_Occupancy_s = NULL; + TH1I* h_PanelId = NULL; + + TH1F* h_EffSecDist = NULL; + TH1F* h_GapEffSecDist = NULL; + TH1F* h_NoiseCorrSecDist = NULL; + TH1F* h_NoiseTotSecDist = NULL; + TH1F* h_CSSecDist = NULL; + TH1F* h_Res_CS1SecDist = NULL; + TH1F* h_Res_CS2SecDist = NULL; + TH1F* h_Res_CSmore2SecDist = NULL; + TH1F* h_Res_CS1_rmsSecDist = NULL; + TH1F* h_Res_CS2_rmsSecDist = NULL; + TH1F* h_Res_CSmore2_rmsSecDist = NULL; + TH1F* h_TimeSecDist = NULL; + TH1F* h_OccupancySecDist = NULL; + + if ( RPCCheckHistogram( f, TrackProj_name.c_str() ) ){ h_TrackProj = (TH1F*) ( f->Get( TrackProj_name.c_str() ) );} + if ( RPCCheckHistogram( f, HitOnTrack_name.c_str() ) ){ h_HitOnTrack = (TH1F*) ( f->Get( HitOnTrack_name.c_str() ) );} + if ( RPCCheckHistogram( f, HitOnTrackCross_name.c_str() ) ){ h_HitOnTrackCross = (TH1F*) ( f->Get( HitOnTrackCross_name.c_str() ) );} + if ( RPCCheckHistogram( f, Eff_name.c_str() ) ){ h_Eff = (TH1F*) ( f->Get( Eff_name.c_str() ) );} + if ( RPCCheckHistogram( f, GapEff_name.c_str() ) ){ h_GapEff = (TH1F*) ( f->Get( GapEff_name.c_str() ) );} + if ( RPCCheckHistogram( f, NoiseCorr_name.c_str() ) ){ h_NoiseCorr = (TH1F*) ( f->Get( NoiseCorr_name.c_str() ) );} + if ( RPCCheckHistogram( f, NoiseCorr_s_name.c_str() ) ){ h_NoiseCorr_s = (TH1F*) ( f->Get( NoiseCorr_s_name.c_str() ) );} + if ( RPCCheckHistogram( f, NoiseTot_name.c_str() ) ){ h_NoiseTot = (TH1F*) ( f->Get( NoiseTot_name.c_str() ) );} + if ( RPCCheckHistogram( f, NoiseTot_s_name.c_str() ) ){ h_NoiseTot_s = (TH1F*) ( f->Get( NoiseTot_s_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS1_name.c_str() ) ){ h_Res_CS1 = (TH1F*) ( f->Get( Res_CS1_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS1_s_name.c_str() ) ){ h_Res_CS1_s = (TH1F*) ( f->Get( Res_CS1_s_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS1_square_name.c_str() ) ){ h_Res_CS1_square = (TH1F*) ( f->Get( Res_CS1_square_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS1_entries_name.c_str() ) ){ h_Res_CS1_entries = (TH1F*) ( f->Get( Res_CS1_entries_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS2_name.c_str() ) ){ h_Res_CS2 = (TH1F*) ( f->Get( Res_CS2_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS2_s_name.c_str() ) ){ h_Res_CS2_s = (TH1F*) ( f->Get( Res_CS2_s_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS2_square_name .c_str() ) ){ h_Res_CS2_square = (TH1F*) ( f->Get( Res_CS2_square_name .c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS2_entries_name.c_str() ) ){ h_Res_CS2_entries = (TH1F*) ( f->Get( Res_CS2_entries_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CSmore2_name.c_str() ) ){ h_Res_CSmore2 = (TH1F*) ( f->Get( Res_CSmore2_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CSmore2_s_name.c_str() ) ){ h_Res_CSmore2_s = (TH1F*) ( f->Get( Res_CSmore2_s_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CSmore2_square_name.c_str() ) ){ h_Res_CSmore2_square = (TH1F*) ( f->Get( Res_CSmore2_square_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CSmore2_entries_name.c_str() ) ){ h_Res_CSmore2_entries = (TH1F*) ( f->Get( Res_CSmore2_entries_name.c_str() ) );} + if ( RPCCheckHistogram( f, CS_name.c_str() ) ){ h_CS = (TH1F*) ( f->Get( CS_name.c_str() ) );} + if ( RPCCheckHistogram( f, CS_s_name.c_str() ) ){ h_CS_s = (TH1F*) ( f->Get( CS_s_name.c_str() ) );} + if ( RPCCheckHistogram( f, CS_square_name .c_str() ) ){ h_CS_square = (TH1F*) ( f->Get( CS_square_name .c_str() ) );} + if ( RPCCheckHistogram( f, CS_entries_name.c_str() ) ){ h_CS_entries = (TH1F*) ( f->Get( CS_entries_name.c_str() ) );} + if ( RPCCheckHistogram( f, CS1_entries_name.c_str() ) ){ h_CS1_entries = (TH1F*) ( f->Get( CS1_entries_name.c_str() ) );} + if ( RPCCheckHistogram( f, CS2_entries_name.c_str() ) ){ h_CS2_entries = (TH1F*) ( f->Get( CS2_entries_name.c_str() ) );} + if ( RPCCheckHistogram( f, Time_name.c_str() ) ){ h_Time = (TH1F*) ( f->Get( Time_name.c_str() ) );} + if ( RPCCheckHistogram( f, Time_s_name.c_str() ) ){ h_Time_s = (TH1F*) ( f->Get( Time_s_name.c_str() ) );} + if ( RPCCheckHistogram( f, Time_square_name.c_str() ) ){ h_Time_square = (TH1F*) ( f->Get( Time_square_name.c_str() ) );} + if ( RPCCheckHistogram( f, Occupancy_name.c_str() ) ){ h_Occupancy = (TH1F*) ( f->Get( Occupancy_name.c_str() ) );} + if ( RPCCheckHistogram( f, Occupancy_s_name.c_str() ) ){ h_Occupancy_s = (TH1F*) ( f->Get( Occupancy_s_name.c_str() ) );} + if ( RPCCheckHistogram( f, PanelId_name.c_str() ) ){ h_PanelId = (TH1I*) ( f->Get( PanelId_name.c_str() ) );} + + if ( RPCCheckHistogram( f, EffSecDist_name.c_str() ) ){ h_EffSecDist = (TH1F*) ( f->Get( EffSecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, GapEffSecDist_name.c_str() ) ){ h_GapEffSecDist = (TH1F*) ( f->Get( GapEffSecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, NoiseCorrSecDist_name.c_str() ) ){ h_NoiseCorrSecDist = (TH1F*) ( f->Get( NoiseCorrSecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, NoiseTotSecDist_name.c_str() ) ){ h_NoiseTotSecDist = (TH1F*) ( f->Get( NoiseTotSecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, CSSecDist_name.c_str() ) ){ h_CSSecDist = (TH1F*) ( f->Get( CSSecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS1SecDist_name.c_str() ) ){ h_Res_CS1SecDist = (TH1F*) ( f->Get( Res_CS1SecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS2SecDist_name.c_str() ) ){ h_Res_CS2SecDist = (TH1F*) ( f->Get( Res_CS2SecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CSmore2SecDist_name.c_str() ) ){ h_Res_CSmore2SecDist = (TH1F*) ( f->Get( Res_CSmore2SecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS1_rmsSecDist_name.c_str() ) ){ h_Res_CS1_rmsSecDist = (TH1F*) ( f->Get( Res_CS1_rmsSecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CS2_rmsSecDist_name.c_str() ) ){ h_Res_CS2_rmsSecDist = (TH1F*) ( f->Get( Res_CS2_rmsSecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, Res_CSmore2_rmsSecDist_name.c_str()) ){ h_Res_CSmore2_rmsSecDist = (TH1F*) ( f->Get( Res_CSmore2_rmsSecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, TimeSecDist_name.c_str() ) ){ h_TimeSecDist = (TH1F*) ( f->Get( TimeSecDist_name.c_str() ) );} + if ( RPCCheckHistogram( f, OccupancySecDist_name.c_str() ) ){ h_OccupancySecDist = (TH1F*) ( f->Get( OccupancySecDist_name.c_str() ) );} + + if ( h_EffSecDist ) h_EffSecDist ->Reset() ; + if ( h_GapEffSecDist ) h_GapEffSecDist ->Reset() ; + if ( h_NoiseCorrSecDist ) h_NoiseCorrSecDist ->Reset() ; + if ( h_NoiseTotSecDist ) h_NoiseTotSecDist ->Reset() ; + if ( h_CSSecDist ) h_CSSecDist ->Reset() ; + if ( h_Res_CS1SecDist ) h_Res_CS1SecDist ->Reset() ; + if ( h_Res_CS2SecDist ) h_Res_CS2SecDist ->Reset() ; + if ( h_Res_CSmore2SecDist ) h_Res_CSmore2SecDist ->Reset() ; + if ( h_Res_CS1_rmsSecDist ) h_Res_CS1_rmsSecDist ->Reset() ; + if ( h_Res_CS2_rmsSecDist ) h_Res_CS2_rmsSecDist ->Reset() ; + if ( h_Res_CSmore2_rmsSecDist ) h_Res_CSmore2_rmsSecDist->Reset() ; + if ( h_TimeSecDist ) h_TimeSecDist ->Reset() ; + if ( h_OccupancySecDist ) h_OccupancySecDist ->Reset() ; + if ( h_Eff ) h_Eff ->Reset() ; + + // efficiency + if ( h_TrackProj && h_HitOnTrack && h_Eff ) { + for ( int ib = 0; ib != h_TrackProj->GetNbinsX(); ib++ ) { + if ( h_PanelId ) { if ( (h_PanelId->GetBinContent(ib+1) )==0 ) { continue; } } + + n_hit_f = h_HitOnTrack -> GetBinContent(ib+1) ; + n_tr_p = h_TrackProj -> GetBinContent(ib+1) ; + + if ( n_tr_p>50 ) { + if ( n_hit_f!=0) { panel_eff = n_hit_f/n_tr_p ; } + else { panel_eff=0. ; } + if ( n_tr_p!=0 ) { + panel_err_eff = sqrt( fabs(n_hit_f)/n_tr_p ) * + sqrt( 1. - fabs(n_hit_f)/n_tr_p ) / + sqrt( n_tr_p ) ; + } + else { panel_err_eff=0. ; } + h_Eff -> SetBinContent(ib+1, panel_eff) ; + h_Eff -> SetBinError (ib+1, panel_err_eff) ; + if ( h_EffSecDist ) h_EffSecDist->Fill(panel_eff) ; + if ( ib>( h_TrackProj->GetNbinsX()/2 ) ) { if ( h_AverageEff_A ) h_AverageEff_A->Fill(panel_eff) ; } + else { if ( h_AverageEff_C ) h_AverageEff_C->Fill(panel_eff) ; } + } + } + // write out histogram + TDirectory* dir = f->GetDirectory( dir_sum_track.c_str() ) ; + if ( dir != 0 ) { + dir->cd() ; + h_Eff -> Write("",TObject::kOverwrite); + if ( h_EffSecDist ) h_EffSecDist ->Write("",TObject::kOverwrite) ; + } + } + + // gap efficiency + if ( h_TrackProj && h_HitOnTrack && h_HitOnTrackCross && h_GapEff ) { + h_GapEff->Reset(); + nEta=0; nPhi=0; nEtaPhi=0; + int sign=1; + int bmin=0; + bmin = int( h_GapEff->GetXaxis()->GetXmin() ) ; + for ( int ib = 0; ib !=h_TrackProj->GetNbinsX(); ib++ ) { + if ( h_PanelId ) { if ( (h_PanelId->GetBinContent(ib+1) )==0 ) { continue; } } + if ( (bmin + ib )%2 != 0 ) continue; // Phi panel + if ( (bmin + ib )<0 ) { sign=-1; } + else { sign= 1; } + + nEta = h_HitOnTrack ->GetBinContent( ib+1 ) ; + nPhi = h_HitOnTrack ->GetBinContent( ib+1 + sign ) ; + nEtaPhi = h_HitOnTrackCross->GetBinContent( ib+1 ) ; + n_tr_p = h_TrackProj ->GetBinContent( ib+1 ) ; + + if ( n_tr_p>50 ) { + gapEff = (nEta+nPhi-nEtaPhi) / n_tr_p ; + //std::cout << " gapEff " << gapEff <<" nEta "<<nEta<<" nPhi "<<nPhi<< " nEtaPhi "<<nEtaPhi <<" n_tr_p "<<n_tr_p <<std::endl; + + gapErrEff = sqrt( fabs( nEta+nPhi-nEtaPhi)/n_tr_p ) * + sqrt( 1. - fabs( nEta+nPhi-nEtaPhi)/n_tr_p ) / + sqrt( n_tr_p ) ; + //std::cout <<"sqrt( fabs( nEta+nPhi-nEtaPhi -0.5)/n_tr_p )"<<sqrt( fabs( nEta+nPhi-nEtaPhi -0.5)/n_tr_p )<<"sqrt( 1. - fabs( nEta+nPhi-nEtaPhi -0.5)/n_tr_p )"<<sqrt( 1. - fabs( nEta+nPhi-nEtaPhi -0.5)/n_tr_p )<< " gapErrEff " << gapErrEff <<std::endl; + } + //else { + // gapEff = 0.; + // gapErrEff = 0.; + //} + h_GapEff -> SetBinContent(ib+1, gapEff ); + h_GapEff -> SetBinError (ib+1, gapErrEff ); + if ( h_GapEffSecDist ) h_GapEffSecDist->Fill(gapEff); + if ( ib>( h_TrackProj->GetNbinsX()/2 ) ) { if ( h_AverageGapEff_A ) h_AverageGapEff_A->Fill(gapEff); } + else { if ( h_AverageGapEff_C ) h_AverageGapEff_C->Fill(gapEff); } + } + TDirectory* dir = f->GetDirectory( dir_sum_track.c_str() ) ; + if ( dir != 0 ) { + dir->cd() ; + h_GapEff -> Write("",TObject::kOverwrite) ; + if ( h_GapEffSecDist ) h_GapEffSecDist-> Write("",TObject::kOverwrite) ; + } + } + + + //residuals CS = 1 + res_mean=0; res2_mean=0; res_RMS=0; + if ( h_Res_CS1 && h_Res_CS1_s && h_Res_CS1_square && h_Res_CS1_entries ) { + for ( int ib = 0; ib != h_Res_CS1->GetNbinsX(); ib++ ) { + if ( h_PanelId ) { if ( (h_PanelId->GetBinContent(ib+1) )==0 ) { continue; } } + if ( (h_Res_CS1_entries->GetBinContent(ib+1) )!=0 ) { + res_mean = (h_Res_CS1_s->GetBinContent(ib+1) )/ (h_Res_CS1_entries->GetBinContent(ib+1) ) ; + res2_mean = (h_Res_CS1_square->GetBinContent(ib+1) )/ (h_Res_CS1_entries->GetBinContent(ib+1) ); + res_RMS = sqrt( (fabs( res2_mean-res_mean*res_mean ))/( h_Res_CS1_entries->GetBinContent(ib+1) ) ) ; + + h_Res_CS1->SetBinContent(ib+1, res_mean); + h_Res_CS1->SetBinError( ib+1, res_RMS ); + if ( h_Res_CS1SecDist ) h_Res_CS1SecDist ->Fill( res_mean ); + if ( h_Res_CS1_rmsSecDist ) h_Res_CS1_rmsSecDist->Fill( res_RMS ); + if ( ib>( h_Res_CS1->GetNbinsX()/2 ) ) { + if ( h_AverageRes_CS1_A ) h_AverageRes_CS1_A ->Fill( res_mean ); + if ( h_AverageRes_CS1rms_A ) h_AverageRes_CS1rms_A ->Fill( res_RMS ); + } + else { + if ( h_AverageRes_CS1_C ) h_AverageRes_CS1_C ->Fill( res_mean ); + if ( h_AverageRes_CS1rms_C ) h_AverageRes_CS1rms_C->Fill( res_RMS ); + } + } + } // end for bins + TDirectory* dirRes1 = f->GetDirectory( dir_sum_track.c_str() ) ; + if ( dirRes1 != 0 ) { + dirRes1->cd() ; + h_Res_CS1->Write("",TObject::kOverwrite); + if ( h_Res_CS1SecDist ) h_Res_CS1SecDist ->Write("",TObject::kOverwrite); + if ( h_Res_CS1_rmsSecDist ) h_Res_CS1_rmsSecDist->Write("",TObject::kOverwrite); + } + } + + //residuals CS = 2 + res_mean=0; res2_mean=0; res_RMS=0; + if ( h_Res_CS2 && h_Res_CS2_s && h_Res_CS2_square && h_Res_CS2_entries ) { + + for ( int ib = 0; ib != h_Res_CS2->GetNbinsX(); ib++ ) { + if ( h_PanelId ) { if ( (h_PanelId->GetBinContent(ib+1) )==0 ) { continue; } } + if ( (h_Res_CS2_entries->GetBinContent(ib+1) )!=0 ) { + res_mean = (h_Res_CS2_s->GetBinContent(ib+1) )/ (h_Res_CS2_entries->GetBinContent(ib+1) ) ; + res2_mean = (h_Res_CS2_square->GetBinContent(ib+1) )/ (h_Res_CS2_entries->GetBinContent(ib+1) ); + res_RMS = sqrt( fabs ( ( res2_mean-res_mean*res_mean )/( h_Res_CS2_entries->GetBinContent(ib+1) ) ) ) ; + + h_Res_CS2->SetBinContent(ib+1, res_mean); + h_Res_CS2->SetBinError( ib+1, res_RMS ); + if ( h_Res_CS2SecDist ) h_Res_CS2SecDist ->Fill( res_mean ); + if ( h_Res_CS2_rmsSecDist ) h_Res_CS2_rmsSecDist->Fill( res_RMS ); + if ( ib >( h_Res_CS2->GetNbinsX()/2 ) ) { + if ( h_AverageRes_CS2_A ) h_AverageRes_CS2_A ->Fill( res_mean ); + if ( h_AverageRes_CS2rms_A ) h_AverageRes_CS2rms_A ->Fill( res_RMS ); + } + else { + if ( h_AverageRes_CS2_C ) h_AverageRes_CS2_C ->Fill( res_mean ); + if ( h_AverageRes_CS2rms_C ) h_AverageRes_CS2rms_C ->Fill( res_RMS ); + } + } + } + TDirectory* dirRes2 = f->GetDirectory( dir_sum_track.c_str() ) ; + if ( dirRes2 != 0 ) { + dirRes2->cd() ; + h_Res_CS2->Write("",TObject::kOverwrite); + if ( h_Res_CS2SecDist ) h_Res_CS2SecDist ->Write("",TObject::kOverwrite); + if ( h_Res_CS2_rmsSecDist ) h_Res_CS2_rmsSecDist->Write("",TObject::kOverwrite); + } + } + + //residuals CS > 2 + res_mean=0; res2_mean=0; res_RMS=0; + if ( h_Res_CSmore2 && h_Res_CSmore2_s && h_Res_CSmore2_square && h_Res_CSmore2_entries ) { + + for ( int ib = 0; ib != h_Res_CSmore2->GetNbinsX(); ib++ ) { + if ( h_PanelId ) { if ( (h_PanelId->GetBinContent(ib+1) )==0 ) { continue; } } + if ( (h_Res_CSmore2_entries->GetBinContent(ib+1) )!=0 ) { + res_mean = (h_Res_CSmore2_s->GetBinContent(ib+1) )/ (h_Res_CSmore2_entries->GetBinContent(ib+1) ) ; + res2_mean = (h_Res_CSmore2_square->GetBinContent(ib+1) )/ (h_Res_CSmore2_entries->GetBinContent(ib+1) ); + res_RMS = sqrt( fabs( ( res2_mean-res_mean*res_mean )/( h_Res_CSmore2_entries->GetBinContent(ib+1) ) ) ) ; + + h_Res_CSmore2->SetBinContent(ib+1, res_mean); + h_Res_CSmore2->SetBinError( ib+1, res_RMS ); + if ( h_Res_CSmore2SecDist ) h_Res_CSmore2SecDist ->Fill( res_mean ); + if ( h_Res_CSmore2_rmsSecDist ) h_Res_CSmore2_rmsSecDist->Fill( res_RMS ); + if ( ib > (h_Res_CSmore2->GetNbinsX()/2 ) ) { + if ( h_AverageRes_CSmore2_A ) h_AverageRes_CSmore2_A ->Fill( res_mean ); + if ( h_AverageRes_CSmore2rms_A ) h_AverageRes_CSmore2rms_A ->Fill( res_RMS ); + } + else { + if ( h_AverageRes_CSmore2_C ) h_AverageRes_CSmore2_C ->Fill( res_mean ); + if ( h_AverageRes_CSmore2rms_C ) h_AverageRes_CSmore2rms_C ->Fill( res_RMS ); + } + } + } + TDirectory* dirResp2 = f->GetDirectory( dir_sum_track.c_str() ) ; + if ( dirResp2 != 0 ) { + dirResp2->cd() ; + h_Res_CSmore2->Write("",TObject::kOverwrite); + if ( h_Res_CSmore2SecDist ) h_Res_CSmore2SecDist ->Write("",TObject::kOverwrite); + if ( h_Res_CSmore2_rmsSecDist ) h_Res_CSmore2_rmsSecDist->Write("",TObject::kOverwrite); + } + } + + // occupancy + if ( (rpc_eventstotal>0) && h_Occupancy && h_Occupancy_s ) { + for ( int ib = 0; ib != h_Occupancy->GetNbinsX(); ib++ ) { + if ( h_PanelId ) { if ( (h_PanelId->GetBinContent(ib+1) )==0 ) { continue; } } + panel_occ = h_Occupancy_s->GetBinContent(ib+1) ; + panel_occ = panel_occ/float(rpc_eventstotal) ; + + h_Occupancy->SetBinContent(ib+1, panel_occ ) ; + h_Occupancy->SetBinError( ib+1, sqrt(panel_occ) ) ; + + if (panel_occ>0 ) { + panel_occ = log10( panel_occ ) ; + } + else { + panel_occ = -10 ; + } + if ( h_OccupancySecDist ) h_OccupancySecDist->Fill( panel_occ ); + if ( ib>( h_PanelId->GetNbinsX()/2) ) { if ( h_AverageOccupancy_A ) h_AverageOccupancy_A->Fill( panel_occ ); } + else { if ( h_AverageOccupancy_C ) h_AverageOccupancy_C->Fill( panel_occ ); } + } + // write occupancy histograms + TDirectory* dirOcc = f->GetDirectory( dir_sum_track.c_str() ) ; + if ( dirOcc !=0 ) { + dirOcc->cd(); + h_Occupancy ->Write("",TObject::kOverwrite); + h_OccupancySecDist->Write("",TObject::kOverwrite); + } + } + + + // CS + if ( h_CS && h_CS_s && h_CS_square && h_CS_entries ){ + for ( int ib = 0; ib != h_CS->GetNbinsX(); ib++ ) { + if ( h_PanelId ) { if ( (h_PanelId->GetBinContent(ib+1) )==0 ) { continue; } } + panelCS_entries = h_CS_entries->GetBinContent(ib+1); + panelCS = h_CS_s->GetBinContent(ib+1) ; + panelCS2 = h_CS_square->GetBinContent(ib+1) ; + if ( panelCS_entries !=0 ) { + panelCS_mean = panelCS/panelCS_entries ; + panelCS2_mean = panelCS2/panelCS_entries ; + panelCS_RMS = sqrt( fabs( (panelCS2_mean - panelCS_mean*panelCS_mean ) / panelCS_entries ) ) ; + + h_CS->SetBinContent( ib+1, panelCS_mean ) ; + h_CS->SetBinError ( ib+1, panelCS_RMS ) ; + + if ( h_CSSecDist ) h_CSSecDist->Fill( panelCS_mean ); + if ( ib > ( h_CS->GetNbinsX()/2 ) ) { if ( h_AverageCS_A ) h_AverageCS_A->Fill( panelCS_mean ); } + else { if ( h_AverageCS_C ) h_AverageCS_C->Fill( panelCS_mean ); } + } + } + // write CS histograms + TDirectory* dirCS = f->GetDirectory( dir_sum_track.c_str() ) ; + if ( dirCS!=0 ) { + dirCS->cd(); + h_CS->Write("",TObject::kOverwrite) ; + if ( h_CSSecDist ) h_CSSecDist->Write("",TObject::kOverwrite) ; + } + + } + + // time + if ( h_Time && h_Time_s && h_Time_square && h_CS_entries ) { + for ( int ib = 0; ib != h_Time->GetNbinsX(); ib++ ) { + if ( h_PanelId ) { if ( (h_PanelId->GetBinContent(ib+1) )==0 ) { continue; } } + if ( h_CS_entries->GetBinContent(ib+1) !=0 ) { + Time_mean = (h_Time_s->GetBinContent(ib+1) )/ (h_CS_entries->GetBinContent(ib+1) ) ; + Time2_mean = (h_Time_square->GetBinContent(ib+1) )/ (h_CS_entries->GetBinContent(ib+1) ) ; + Time_RMS = sqrt(fabs( ( Time2_mean-Time_mean*Time_mean )/( h_CS_entries->GetBinContent(ib+1) )) ); + + h_Time->SetBinContent(ib+1, Time_mean); + h_Time->SetBinError( ib+1, Time_RMS ); + + if ( h_TimeSecDist ) h_TimeSecDist->Fill( Time_mean ); + if ( ib>( h_Time->GetNbinsX()/2 ) ) { if ( h_AverageTime_A ) h_AverageTime_A->Fill( Time_mean ); } + else { if ( h_AverageTime_C ) h_AverageTime_C->Fill( Time_mean ); } + } + } + // write time histograms + TDirectory* dirTime = f->GetDirectory( dir_sum_track.c_str() ) ; + if ( dirTime != 0 ) { + dirTime->cd(); + h_Time->Write("",TObject::kOverwrite) ; + if ( h_TimeSecDist ) h_TimeSecDist->Write("",TObject::kOverwrite) ; + } + } + // noise + noiseErrNorm = 18257.42 ; + // noiseErr = sqrt( counts ) / ( area * T * events ) + // noiseErr = sqrt(noise_bin * area* 0.2 ) / ( area * time * events ) + // noiseErr = sqrt( noise_bin ) * noiseErrNorm / events + // noiseErrNorm = sqrt(0.2) / sqrt( time * area ) + // assuming average area of RPC panels = 15000 cm2 + // noiseErrNorm = 18257.42 + if ( (rpc_eventstotal>0) && h_NoiseCorr && h_NoiseCorr_s && h_NoiseTot && h_NoiseTot_s && h_CS_entries) { + //std::cout << " Taglio Eventi " << std::endl; + for ( int ib = 0; ib != h_NoiseCorr->GetNbinsX(); ib++ ) { + if ( h_PanelId ) { if ( (h_PanelId->GetBinContent(ib+1) )==0 ) { continue; } } + if ( h_CS_entries->GetBinContent(ib+1) ==0)continue; + noiseCorr = h_NoiseCorr_s->GetBinContent(ib+1) ; + noiseCorrErr = sqrt( noiseCorr ) * noiseErrNorm / float(rpc_eventstotal) ; + noiseCorr = (noiseCorr*1000000)/float(rpc_eventstotal) ; + h_NoiseCorr->SetBinContent(ib+1, noiseCorr); + h_NoiseCorr->SetBinError(ib+1, noiseCorrErr); + if ( h_NoiseCorrSecDist ) h_NoiseCorrSecDist->Fill( noiseCorr ); + + noiseTot = h_NoiseTot_s->GetBinContent(ib+1) ; + noiseTotErr = sqrt( noiseTot ) * noiseErrNorm / float(rpc_eventstotal) ; + noiseTot = (noiseTot*1000000)/float(rpc_eventstotal) ; + h_NoiseTot->SetBinContent(ib+1, noiseTot ) ; + h_NoiseTot->SetBinError(ib+1, noiseTotErr ) ; + + if ( h_NoiseTotSecDist ) h_NoiseTotSecDist->Fill( noiseTot ); + + if ( ib > ( h_NoiseCorr->GetNbinsX()/2 ) ) { + if ( h_AverageNoiseTot_A ) h_AverageNoiseTot_A->Fill ( noiseTot ); + if ( h_AverageNoiseCorr_A ) h_AverageNoiseCorr_A->Fill( noiseCorr ); + } + else { + if ( h_AverageNoiseTot_C ) h_AverageNoiseTot_C ->Fill( noiseTot ); + if ( h_AverageNoiseCorr_C ) h_AverageNoiseCorr_C->Fill( noiseCorr ); + } + } + TDirectory* dirNoise = f->GetDirectory( dir_sum_track.c_str() ) ; + if ( dirNoise!=0 ) { + dirNoise->cd(); + h_NoiseCorr->Write("",TObject::kOverwrite) ; + h_NoiseTot ->Write("",TObject::kOverwrite) ; + + if ( h_NoiseCorrSecDist ) h_NoiseCorrSecDist->Write("",TObject::kOverwrite) ; + if ( h_NoiseTotSecDist ) h_NoiseTotSecDist ->Write("",TObject::kOverwrite) ; + } + } + + + ///create and insert entries in SQLite DB + // bool do_asciiCoolFile1 = true; + float effeta = -9999; float effphi = -9999; char m_effeta [10]; char m_effphi [10]; + float erreffeta = -1; float erreffphi =-1; char m_erreffeta [10]; char m_erreffphi [10]; + float reseta_cs1 = -9999; float resphi_cs1 = -9999; char m_reseta_cs1 [10]; char m_resphi_cs1 [10]; + float errreseta_cs1 = -1; float errresphi_cs1 =-1; char m_errreseta_cs1 [10]; char m_errresphi_cs1 [10]; + float reseta_cs2 = -9999; float resphi_cs2 = -9999; char m_reseta_cs2 [10]; char m_resphi_cs2 [10]; + float errreseta_cs2 = -1; float errresphi_cs2 =-1; char m_errreseta_cs2 [10]; char m_errresphi_cs2 [10]; + float reseta_csother = -9999; float resphi_csother = -9999; char m_reseta_csother [10]; char m_resphi_csother [10]; + float errreseta_csother = -1; float errresphi_csother =-1; char m_errreseta_csother [10]; char m_errresphi_csother [10]; + float timeeta = -9999; float timephi = -9999; char m_timeeta [10]; char m_timephi [10]; + float errtimeeta = -1; float errtimephi =-1; char m_errtimeeta [10]; char m_errtimephi [10]; + float noiseeta = -9999; float noisephi = -9999; char m_noiseeta [10]; char m_noisephi [10]; + float errnoiseeta = -1; float errnoisephi =-1; char m_errnoiseeta [10]; char m_errnoisephi [10]; + float noiseeta_cor = -9999; float noisephi_cor = -9999; char m_noiseeta_cor [10]; char m_noisephi_cor [10]; + float errnoiseeta_cor = -1; float errnoisephi_cor =-1; char m_errnoiseeta_cor [10]; char m_errnoisephi_cor [10]; + float cl_sizeeta = -9999; float cl_sizephi = -9999; char m_cl_sizeeta [10]; char m_cl_sizephi [10]; + float errcl_sizeeta = -1; float errcl_sizephi =-1; char m_errcl_sizeeta [10]; char m_errcl_sizephi [10]; + + + int PannelCode = 0; + int Binposition = 0; + int TableVersion = 1; //Version of Cool Table Formatting according with Andrea Di Simone Table + int n_tr_peta = 0; //Number of eta tracks reconstructed on a gas volume + int n_tr_pphi = 0; //Number of phi tracks reconstructed on a gas volume + int NumberOfInfo = 1; //Number of information for each variable 1= only pannel, >1 depending on tipy of monitoring setting and strip pannel geometry + int StripCluster = 0; //Number of strip that realize de reduction bin and the strip pannel geometry 0=no strip info,if panel has 24 strip: 24=strip info, 3 = cluster of 8 strip, 6 = cluster of 4 strip and so on + + + + coolrpc.coolDbFolder("sqlite://;schema=RPCDQMFOFFLINE.db;dbname=RPC_DQA","/OFFLINE/OFFLINE_DQMF"); + int nbin = 0; + if ( h_Eff ) nbin = h_Eff ->GetNbinsX() ; + for(int ibin=1 ; ibin!=nbin+1 ; ibin++){ + if ( h_PanelId )PannelCode = (int)h_PanelId-> GetBinContent(ibin) ; + if(PannelCode ==0)continue; + if(ibin%2==0){ + + if (h_TrackProj) n_tr_pphi =(int)h_TrackProj -> GetBinContent(ibin) ; + if(n_tr_pphi <1000 ) continue; + + if ( h_Eff )effphi = h_Eff ->GetBinContent(ibin) ; sprintf(m_effphi , "%f ", effphi ) ; m_effphi [5] =0; + if ( h_Eff )erreffphi = h_Eff ->GetBinError (ibin) ; sprintf(m_erreffphi , "%f ", erreffphi ) ; m_erreffphi [5] =0; + if ( h_Res_CS1 )resphi_cs1 = h_Res_CS1 ->GetBinContent(ibin) ; sprintf(m_resphi_cs1 , "%f ", resphi_cs1 ) ; m_resphi_cs1 [5] =0; + if ( h_Res_CS1 )errresphi_cs1 = h_Res_CS1 ->GetBinError (ibin) ; sprintf(m_errresphi_cs1 , "%f ", errresphi_cs1 ) ; m_errresphi_cs1 [5] =0; + if ( h_Res_CS2 )resphi_cs2 = h_Res_CS2 ->GetBinContent(ibin) ; sprintf(m_resphi_cs2 , "%f ", resphi_cs2 ) ; m_resphi_cs2 [5] =0; + if ( h_Res_CS2 )errresphi_cs2 = h_Res_CS2 ->GetBinError (ibin) ; sprintf(m_errresphi_cs2 , "%f ", errresphi_cs2 ) ; m_errresphi_cs2 [5] =0; + if ( h_Res_CSmore2 )resphi_csother = h_Res_CSmore2 ->GetBinContent(ibin) ; sprintf(m_resphi_csother , "%f ", resphi_csother ) ; m_resphi_csother [5] =0; + if ( h_Res_CSmore2 )errresphi_csother = h_Res_CSmore2 ->GetBinError (ibin) ; sprintf(m_errresphi_csother, "%f ", errresphi_csother ) ; m_errresphi_csother[5] =0; + if ( h_Time )timephi = h_Time ->GetBinContent(ibin) ; sprintf(m_timephi , "%f ", timephi ) ; m_timephi [5] =0; + if ( h_Time )errtimephi = h_Time ->GetBinError (ibin) ; sprintf(m_errtimephi , "%f ", errtimephi ) ; m_errtimephi [5] =0; + if ( h_NoiseTot )noisephi = h_NoiseTot ->GetBinContent(ibin) ; sprintf(m_noisephi , "%f ", noisephi ) ; m_noisephi [5] =0; + if ( h_NoiseTot )errnoisephi = h_NoiseTot ->GetBinError (ibin) ; sprintf(m_errnoisephi , "%f ", errnoisephi ) ; m_errnoisephi [5] =0; + if ( h_NoiseCorr )noisephi_cor = h_NoiseCorr ->GetBinContent(ibin) ; sprintf(m_noisephi_cor , "%f ", noisephi_cor ) ; m_noisephi_cor [5] =0; + if ( h_NoiseCorr )errnoisephi_cor = h_NoiseCorr ->GetBinError (ibin) ; sprintf(m_errnoisephi_cor , "%f ", errnoisephi_cor ) ; m_errnoisephi_cor [5] =0; + if ( h_CS )cl_sizephi = h_CS ->GetBinContent(ibin) ; sprintf(m_cl_sizephi , "%f ", cl_sizephi ) ; m_cl_sizephi [5] =0; + if ( h_CS )errcl_sizephi = h_CS ->GetBinError (ibin) ; sprintf(m_errcl_sizephi , "%f ", errcl_sizephi ) ; m_errcl_sizephi [5] =0; + + }else{ + if (h_TrackProj) {n_tr_peta =(int)h_TrackProj -> GetBinContent(ibin) ;} + if(n_tr_peta <1000) continue; + + if ( h_Eff )effeta = h_Eff ->GetBinContent(ibin) ; sprintf(m_effeta , "%f ", effeta ) ; m_effeta [5] =0; + if ( h_Eff )erreffeta = h_Eff ->GetBinError (ibin) ; sprintf(m_erreffeta , "%f ", erreffeta ) ; m_erreffeta [5] =0; + if ( h_Res_CS1 )reseta_cs1 = h_Res_CS1 ->GetBinContent(ibin) ; sprintf(m_reseta_cs1 , "%f ", reseta_cs1 ) ; m_reseta_cs1 [5] =0; + if ( h_Res_CS1 )errreseta_cs1 = h_Res_CS1 ->GetBinError (ibin) ; sprintf(m_errreseta_cs1 , "%f ", errreseta_cs1 ) ; m_errreseta_cs1 [5] =0; + if ( h_Res_CS2 )reseta_cs2 = h_Res_CS2 ->GetBinContent(ibin) ; sprintf(m_reseta_cs2 , "%f ", reseta_cs2 ) ; m_reseta_cs2 [5] =0; + if ( h_Res_CS2 )errreseta_cs2 = h_Res_CS2 ->GetBinError (ibin) ; sprintf(m_errreseta_cs2 , "%f ", errreseta_cs2 ) ; m_errreseta_cs2 [5] =0; + if ( h_Res_CSmore2)reseta_csother = h_Res_CSmore2 ->GetBinContent(ibin) ; sprintf(m_reseta_csother , "%f ", reseta_csother ) ; m_reseta_csother [5] =0; + if ( h_Res_CSmore2)errreseta_csother = h_Res_CSmore2 ->GetBinError (ibin) ; sprintf(m_errreseta_csother, "%f ", errreseta_csother ) ; m_errreseta_csother[5] =0; + if ( h_Time )timeeta = h_Time ->GetBinContent(ibin) ; sprintf(m_timeeta , "%f ", timeeta ) ; m_timeeta [5] =0; + if ( h_Time )errtimeeta = h_Time ->GetBinError (ibin) ; sprintf(m_errtimeeta , "%f ", errtimeeta ) ; m_errtimeeta [5] =0; + if ( h_NoiseTot )noiseeta = h_NoiseTot ->GetBinContent(ibin) ; sprintf(m_noiseeta , "%f ", noiseeta ) ; m_noiseeta [5] =0; + if ( h_NoiseTot )errnoiseeta = h_NoiseTot ->GetBinError (ibin) ; sprintf(m_errnoiseeta , "%f ", errnoiseeta ) ; m_errnoiseeta [5] =0; + if ( h_NoiseCorr )noiseeta_cor = h_NoiseCorr ->GetBinContent(ibin) ; sprintf(m_noiseeta_cor , "%f ", noiseeta_cor ) ; m_noiseeta_cor [5] =0; + if ( h_NoiseCorr )errnoiseeta_cor = h_NoiseCorr ->GetBinError (ibin) ; sprintf(m_errnoiseeta_cor , "%f ", errnoiseeta_cor ) ; m_errnoiseeta_cor [5] =0; + if ( h_CS )cl_sizeeta = h_CS ->GetBinContent(ibin) ; sprintf(m_cl_sizeeta , "%f ", cl_sizeeta ) ; m_cl_sizeeta [5] =0; + if ( h_CS )errcl_sizeeta = h_CS ->GetBinError (ibin) ; sprintf(m_errcl_sizeeta , "%f ", errcl_sizeeta ) ; m_errcl_sizeeta [5] =0; + + + //std::cout<<"PannelCode "<<PannelCode<<" etaprimo "<<"\n"; + + char recEta [4000]; //eff_eta, res_cs1, res_cs2, res_csother, time, mean and rms + char detEta [4000]; //noise, noise_corr, cs, mean and rms + char recPhi1 [4000]; //eff_phi, res_cs1, res_cs2, res_csother, time, only mean + char recPhi2 [4000]; //eff_phi, res_cs1, res_cs2, res_csother, time, only rms + char detPhi1 [4000]; //noise, noise_corr, cs, mean and rms + char detPhi2 [4000]; + sprintf(recEta, "%5d %5d %5d %5d %s %s %s %s %s %s %s %s %s %s ", TableVersion, n_tr_peta, NumberOfInfo, StripCluster, m_effeta, m_erreffeta, m_reseta_cs1, m_errreseta_cs1, m_reseta_cs2, m_errreseta_cs2, m_reseta_csother, m_errreseta_csother, m_timeeta, m_errtimeeta) ; + sprintf(detEta, "%s %s %s %s %s %s ", m_noiseeta, m_errnoiseeta, m_noiseeta_cor, m_errnoiseeta_cor, m_cl_sizeeta, m_errcl_sizeeta) ; + sprintf(recPhi1, "%5d %5d %5d %s %s %s %s %s ", n_tr_pphi, NumberOfInfo, StripCluster, m_effphi, m_resphi_cs1, m_resphi_cs2, m_resphi_csother, m_timephi) ; + sprintf(recPhi2, "%s %s %s %s %s ", m_erreffphi, m_errresphi_cs1, m_errresphi_cs2, m_errresphi_csother, m_errtimephi) ; + sprintf(detPhi1, "%s %s %s %s %s %s ", m_noisephi, m_errnoisephi, m_noisephi_cor, m_errnoisephi_cor, m_cl_sizephi, m_errcl_sizephi) ; + sprintf(detPhi2, "0 ") ; + std::string cool_tag="Reco"; + coolrpc.insert_withTag(run_number,PannelCode,recEta,detEta,recPhi1,recPhi2,detPhi1,detPhi2, cool_tag); + } + } + +//////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////// + + int TableVersionCondDB = 1 ; //RPC conditionDB table versioning + float effeleeta = -9999; char m_effeleeta [10]; + float erreffeleeta = -1; char m_erreffeleeta [10]; + float effelephi = -9999; char m_effelephi [10]; + float erreffelephi = -1; char m_erreffelephi [10]; + float gapeff = -9999; + float errgapeff = -1; + float entriesCSeta = -1; + int entriesCS1eta = -1; + int entriesCS2eta = -1; + float entriesCSphi = -1; + int entriesCS1phi = -1; + int entriesCS2phi = -1; + float rateCS1eta = -1; char m_rateCS1eta [10]; + float rateCS2eta = -1; char m_rateCS2eta [10]; + float rateCSmore2eta = -1; char m_rateCSmore2eta [10]; + float rateCS1phi = -1; char m_rateCS1phi [10]; + float rateCS2phi = -1; char m_rateCS2phi [10]; + float rateCSmore2phi = -1; char m_rateCSmore2phi [10]; + + coolrpc.coolDbFolder("sqlite://;schema=RPCConditionDB.db;dbname=RPC_DQA","/OFFLINE/FINAL"); + std::string dir_cool_raw = run_dir + "/Muon/MuonRawDataMonitoring/RPC/CoolDB/"; + TDirectory* coolFolder = f->GetDirectory( dir_cool_raw.c_str() ) ; + + if ( coolFolder != 0 ) { + + std::vector<std::string> layerList ; + layerList.push_back( "LowPt0" ); + layerList.push_back( "LowPt1" ); + layerList.push_back( "Pivot0" ); + layerList.push_back( "Pivot1" ); + layerList.push_back( "HighPt0" ); + layerList.push_back( "HighPt1" ); + int NumberLayerStrip = 0; + int PanelStripId = 0; + int StripProfileContenent = 0; + + for ( std::vector<std::string>::const_iterator iter=layerList.begin(); iter!=layerList.end(); iter++ ) { + for ( int i_dblPhi=0; i_dblPhi!=2; i_dblPhi++ ) { + char coolName[40]; + sprintf(coolName, "Sector%.2d_%s_dblPhi%d", i_sec+1, (*iter).c_str(), i_dblPhi+1 ); + std::string stripId_name = dir_cool_raw + coolName + "_PanelId" ; + std::string stripProfile_name = dir_cool_raw + coolName + "_Profile" ; + + TH1I* h_stripId = NULL; + TH1F* h_stripProfile = NULL; + + if ( RPCCheckHistogram(f, stripId_name.c_str() ) ) { h_stripId = (TH1I*) ( f->Get(stripId_name.c_str()) );} + if ( RPCCheckHistogram(f, stripProfile_name.c_str() ) ) { h_stripProfile = (TH1F*) ( f->Get(stripProfile_name.c_str()) );} + + if ( h_stripId && h_stripProfile ) { + + int SingleStripsValue = 0; + int StripsOnPanel = 1; //number of strip on panel + char SingleStripsStatus[80] ; + std::string PanelStripsStatus; + + NumberLayerStrip = h_stripProfile->GetNbinsX() ; + for(int Nstrips=1 ; Nstrips!=NumberLayerStrip+1 ; Nstrips++){ + PanelStripId = (int)h_stripId -> GetBinContent(Nstrips) ; + StripProfileContenent = (int)h_stripProfile -> GetBinContent(Nstrips) ; + float StripOccupancy = (float)(StripProfileContenent)/rpc_eventstotal; + if (StripOccupancy==0) SingleStripsValue=0; + if (StripOccupancy>0 && StripOccupancy<0.9) SingleStripsValue=5; + if (StripOccupancy>0.9) SingleStripsValue=9; + + sprintf(SingleStripsStatus, "%d", SingleStripsValue ); + PanelStripsStatus = PanelStripsStatus + SingleStripsStatus; + + + + if((int)h_stripId -> GetBinContent(Nstrips)==(int)h_stripId -> GetBinContent(Nstrips+1))StripsOnPanel++; + if((int)h_stripId -> GetBinContent(Nstrips)!=(int)h_stripId -> GetBinContent(Nstrips+1)){ + + if((int)h_stripId-> GetBinCenter(Nstrips) <0){ + + + // std::cout << " PanelStripsStatus " << PanelStripsStatus <<std::endl; + + std::reverse(PanelStripsStatus.begin(), PanelStripsStatus.end()); + + } + + for(int ibin=1 ; ibin!=nbin+1 ; ibin++){ + if ( h_PanelId )PannelCode = (int)h_PanelId-> GetBinContent(ibin) ; + if(PannelCode !=PanelStripId)continue; + + if(ibin%2!=0){ + if (h_TrackProj) {n_tr_peta =(int)h_TrackProj -> GetBinContent(ibin) ;} + if(n_tr_peta >50){ + + if ( h_GapEff )gapeff = h_GapEff ->GetBinContent(ibin) ; + if ( h_GapEff )errgapeff = h_GapEff ->GetBinError (ibin) ; + if ( h_Eff )effeta = h_Eff ->GetBinContent(ibin) ; + if ( h_Eff )erreffeta = h_Eff ->GetBinError (ibin) ; + if ( h_Res_CS1 )reseta_cs1 = h_Res_CS1 ->GetBinContent(ibin) ; + if ( h_Res_CS1 )errreseta_cs1 = h_Res_CS1 ->GetBinError (ibin) ; + if ( h_Res_CS2 )reseta_cs2 = h_Res_CS2 ->GetBinContent(ibin) ; + if ( h_Res_CS2 )errreseta_cs2 = h_Res_CS2 ->GetBinError (ibin) ; + if ( h_Res_CSmore2)reseta_csother = h_Res_CSmore2 ->GetBinContent(ibin) ; + if ( h_Res_CSmore2)errreseta_csother = h_Res_CSmore2 ->GetBinError (ibin) ; + if ( h_NoiseTot )noiseeta = h_NoiseTot ->GetBinContent(ibin) ; + if ( h_NoiseTot )errnoiseeta = h_NoiseTot ->GetBinError (ibin) ; + if ( h_NoiseCorr )noiseeta_cor = h_NoiseCorr ->GetBinContent(ibin) ; + if ( h_NoiseCorr )errnoiseeta_cor = h_NoiseCorr ->GetBinError (ibin) ; + if ( h_CS )cl_sizeeta = h_CS ->GetBinContent(ibin) ; + if ( h_CS )errcl_sizeeta = h_CS ->GetBinError (ibin) ; + if ( h_CS_entries )entriesCSeta = h_CS_entries ->GetBinContent(ibin) ; + if ( h_CS_entries )entriesCS1eta = h_CS1_entries ->GetBinContent(ibin) ; + if ( h_CS_entries )entriesCS2eta = h_CS2_entries ->GetBinContent(ibin) ; + //std::cout << " entriesCSeta " << entriesCSeta <<std::endl; + if (entriesCSeta>0){ + //std::cout << " entriesCS1eta " << entriesCS1eta <<std::endl; + rateCS1eta =entriesCS1eta/entriesCSeta; + rateCS2eta =entriesCS2eta/entriesCSeta; + rateCSmore2eta =(entriesCSeta-(entriesCS1eta+entriesCS2eta))/entriesCSeta; + } + + if(gapeff!=0 && effeta !=0){ + effeleeta=effeta/gapeff; + erreffeleeta=((erreffeta/effeta)+(errgapeff/gapeff))*effeleeta; + }else{ + effeleeta =0.000; + erreffeleeta =0.000; + } + // std::cout << " effeleeta " << effeleeta <<" erreffeleeta "<<erreffeleeta<<" erreffeta "<<erreffeta << " effeta "<<effeta <<" errgapeff "<<errgapeff << " gapeff "<<gapeff <<" rateCS1eta "<< rateCS1eta << " rateCS2eta " << rateCS2eta <<std::endl; + + sprintf(m_effeta , "%f ", effeta ) ; m_effeta [5] =0; + sprintf(m_erreffeta , "%f ", erreffeta ) ; m_erreffeta [5] =0; + sprintf(m_effeleeta , "%f ", effeleeta ) ; m_effeleeta [5] =0; + sprintf(m_erreffeleeta , "%f ", erreffeleeta ) ; m_erreffeleeta [5] =0; + sprintf(m_reseta_cs1 , "%f ", reseta_cs1 ) ; m_reseta_cs1 [5] =0; + sprintf(m_errreseta_cs1 , "%f ", errreseta_cs1 ) ; m_errreseta_cs1 [5] =0; + sprintf(m_reseta_cs2 , "%f ", reseta_cs2 ) ; m_reseta_cs2 [5] =0; + sprintf(m_errreseta_cs2 , "%f ", errreseta_cs2 ) ; m_errreseta_cs2 [5] =0; + sprintf(m_reseta_csother , "%f ", reseta_csother ) ; m_reseta_csother [5] =0; + sprintf(m_errreseta_csother, "%f ", errreseta_csother ) ; m_errreseta_csother[5] =0; + sprintf(m_noiseeta , "%f ", noiseeta ) ; m_noiseeta [5] =0; + sprintf(m_errnoiseeta , "%f ", errnoiseeta ) ; m_errnoiseeta [5] =0; + sprintf(m_noiseeta_cor , "%f ", noiseeta_cor ) ; m_noiseeta_cor [5] =0; + sprintf(m_errnoiseeta_cor , "%f ", errnoiseeta_cor ) ; m_errnoiseeta_cor [5] =0; + sprintf(m_cl_sizeeta , "%f ", cl_sizeeta ) ; m_cl_sizeeta [5] =0; + sprintf(m_errcl_sizeeta , "%f ", errcl_sizeeta ) ; m_errcl_sizeeta [5] =0; + sprintf(m_rateCS1eta , "%f ", rateCS1eta ) ; m_rateCS1eta [5] =0; + sprintf(m_rateCS2eta , "%f ", rateCS2eta ) ; m_rateCS2eta [5] =0; + sprintf(m_rateCSmore2eta , "%f ", rateCSmore2eta ) ; m_rateCSmore2eta [5] =0; + + char PanelRes [255]; //eff_eta, res_cs1, res_cs2, res_csother, time, mean and rms + char StripStatus [255]; //strips status 0 to 9 for dead noisy strips + + sprintf(PanelRes, "%d %d %d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", TableVersionCondDB, n_tr_peta, StripsOnPanel, m_effeta, m_erreffeta, m_effeleeta, m_erreffeleeta, m_reseta_cs1, m_errreseta_cs1, m_reseta_cs2, m_errreseta_cs2, m_reseta_csother, m_errreseta_csother, m_noiseeta, m_errnoiseeta, m_noiseeta_cor, m_errnoiseeta_cor, m_cl_sizeeta, m_errcl_sizeeta, m_rateCS1eta, m_rateCS2eta, m_rateCSmore2eta) ; + sprintf(StripStatus, "%s", PanelStripsStatus.c_str()) ; + std::string cool_tagCondDB="RecoCondDB"; + coolrpc.insertCondDB_withTag(run_number,PannelCode,PanelRes, StripStatus,cool_tagCondDB); + } + }else{ + if (h_TrackProj) n_tr_pphi =(int)h_TrackProj -> GetBinContent(ibin) ; + if(n_tr_pphi >50 ){ + + if ( h_PanelId )Binposition = (int)h_PanelId-> GetBinCenter(ibin) ; + if(Binposition>0){ + if ( h_GapEff )gapeff = h_GapEff ->GetBinContent(ibin-1) ; + if ( h_GapEff )errgapeff = h_GapEff ->GetBinError (ibin-1) ; + }else{ + if ( h_GapEff )gapeff = h_GapEff ->GetBinContent(ibin+1) ; + if ( h_GapEff )errgapeff = h_GapEff ->GetBinError (ibin+1) ; + } + if ( h_Eff )effphi = h_Eff ->GetBinContent(ibin) ; + if ( h_Eff )erreffphi = h_Eff ->GetBinError (ibin) ; + if ( h_Res_CS1 )resphi_cs1 = h_Res_CS1 ->GetBinContent(ibin) ; + if ( h_Res_CS1 )errresphi_cs1 = h_Res_CS1 ->GetBinError (ibin) ; + if ( h_Res_CS2 )resphi_cs2 = h_Res_CS2 ->GetBinContent(ibin) ; + if ( h_Res_CS2 )errresphi_cs2 = h_Res_CS2 ->GetBinError (ibin) ; + if ( h_Res_CSmore2 )resphi_csother = h_Res_CSmore2 ->GetBinContent(ibin) ; + if ( h_Res_CSmore2 )errresphi_csother = h_Res_CSmore2 ->GetBinError (ibin) ; + if ( h_NoiseTot )noisephi = h_NoiseTot ->GetBinContent(ibin) ; + if ( h_NoiseTot )errnoisephi = h_NoiseTot ->GetBinError (ibin) ; + if ( h_NoiseCorr )noisephi_cor = h_NoiseCorr ->GetBinContent(ibin) ; + if ( h_NoiseCorr )errnoisephi_cor = h_NoiseCorr ->GetBinError (ibin) ; + if ( h_CS )cl_sizephi = h_CS ->GetBinContent(ibin) ; + if ( h_CS )errcl_sizephi = h_CS ->GetBinError (ibin) ; + if ( h_CS_entries )entriesCSphi = h_CS_entries ->GetBinContent(ibin) ; + if ( h_CS_entries )entriesCS1phi = h_CS1_entries ->GetBinContent(ibin) ; + if ( h_CS_entries )entriesCS2phi = h_CS2_entries ->GetBinContent(ibin) ; + if(entriesCSphi>0){ + rateCS1phi =entriesCS1phi/entriesCSphi; + rateCS2phi =entriesCS2phi/entriesCSphi; + rateCSmore2phi =(entriesCSphi-(entriesCS1phi+entriesCS2phi))/entriesCSphi; + } + if(gapeff !=0 && effphi !=0){ + effelephi=effphi/gapeff; + erreffelephi=((erreffphi/effphi)+(errgapeff/gapeff))*effelephi; + }else{ + effelephi = 0.000; + erreffelephi = 0.000; + } + // std::cout << " effelephi " << effelephi <<" erreffelephi "<<erreffelephi<<" erreffphi "<<erreffphi << " effphi "<<effphi <<" errgapeff "<<errgapeff << " gapeff "<<gapeff << " rateCS1phi "<<rateCS1phi<< " rateCS2phi "<<rateCS2phi<<std::endl; + + + sprintf(m_effphi , "%f ", effphi ) ; m_effphi [5] =0; + sprintf(m_erreffphi , "%f ", erreffphi ) ; m_erreffphi [5] =0; + sprintf(m_effelephi , "%f ", effelephi ) ; m_effelephi [5] =0; + sprintf(m_erreffelephi , "%f ", erreffelephi ) ; m_erreffelephi [5] =0; + sprintf(m_resphi_cs1 , "%f ", resphi_cs1 ) ; m_resphi_cs1 [5] =0; + sprintf(m_errresphi_cs1 , "%f ", errresphi_cs1 ) ; m_errresphi_cs1 [5] =0; + sprintf(m_resphi_cs2 , "%f ", resphi_cs2 ) ; m_resphi_cs2 [5] =0; + sprintf(m_errresphi_cs2 , "%f ", errresphi_cs2 ) ; m_errresphi_cs2 [5] =0; + sprintf(m_resphi_csother , "%f ", resphi_csother ) ; m_resphi_csother [5] =0; + sprintf(m_errresphi_csother, "%f ", errresphi_csother ) ; m_errresphi_csother[5] =0; + sprintf(m_noisephi , "%f ", noisephi ) ; m_noisephi [5] =0; + sprintf(m_errnoisephi , "%f ", errnoisephi ) ; m_errnoisephi [5] =0; + sprintf(m_noisephi_cor , "%f ", noisephi_cor ) ; m_noisephi_cor [5] =0; + sprintf(m_errnoisephi_cor , "%f ", errnoisephi_cor ) ; m_errnoisephi_cor [5] =0; + sprintf(m_cl_sizephi , "%f ", cl_sizephi ) ; m_cl_sizephi [5] =0; + sprintf(m_errcl_sizephi , "%f ", errcl_sizephi ) ; m_errcl_sizephi [5] =0; + sprintf(m_rateCS1phi , "%f ", rateCS1phi ) ; m_rateCS1phi [5] =0; + sprintf(m_rateCS2phi , "%f ", rateCS2phi ) ; m_rateCS2phi [5] =0; + sprintf(m_rateCSmore2phi , "%f ", rateCSmore2phi ) ; m_rateCSmore2phi [5] =0; + + char PanelRes [255]; //eff_eta, res_cs1, res_cs2, res_csother, time, mean and rms + char StripStatus [255]; //strips status 0 to 9 for dead noisy strips + sprintf(PanelRes, "%d %d %d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", TableVersionCondDB, n_tr_pphi, StripsOnPanel, m_effphi, m_erreffphi, m_effelephi, m_erreffelephi, m_resphi_cs1, m_errresphi_cs1, m_resphi_cs2, m_errresphi_cs2, m_resphi_csother, m_errresphi_csother, m_noisephi, m_errnoisephi, m_noisephi_cor, m_errnoisephi_cor, m_cl_sizephi, m_errcl_sizephi, m_rateCS1phi, m_rateCS2phi, m_rateCSmore2phi) ; + sprintf(StripStatus, "%s", PanelStripsStatus.c_str()) ; + std::string cool_tag="RecoCondDB"; + coolrpc.insertCondDB_withTag(run_number,PannelCode,PanelRes, StripStatus,cool_tag); + } + } + StripsOnPanel=1; + PanelStripsStatus.clear(); + } + } + } + } + } // end loop on DoubletPhi + } // end loop on layers + }// end Cool Folder + } // end for sectors + + // write distribution plots all ATLAS + TDirectory* dirA = f->GetDirectory( dir_sideA_track.c_str() ) ; + if ( dirA != 0 ) { + dirA->cd(); + if ( h_AverageEff_A ) h_AverageEff_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageGapEff_A ) h_AverageGapEff_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CS1_A ) h_AverageRes_CS1_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CS1rms_A ) h_AverageRes_CS1rms_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CS2_A ) h_AverageRes_CS2_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CS2rms_A ) h_AverageRes_CS2rms_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CSmore2_A ) h_AverageRes_CSmore2_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CSmore2rms_A ) h_AverageRes_CSmore2rms_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageOccupancy_A ) h_AverageOccupancy_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageCS_A ) h_AverageCS_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageTime_A ) h_AverageTime_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageNoiseCorr_A ) h_AverageNoiseCorr_A ->Write("",TObject::kOverwrite) ; + if ( h_AverageNoiseTot_A ) h_AverageNoiseTot_A ->Write("",TObject::kOverwrite) ; + } + TDirectory* dirC = f->GetDirectory( dir_sideC_track.c_str() ) ; + if ( dirC != 0 ) { + dirC->cd(); + if ( h_AverageEff_C ) h_AverageEff_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageGapEff_C ) h_AverageGapEff_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CS1_C ) h_AverageRes_CS1_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CS1rms_C ) h_AverageRes_CS1rms_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CS2_C ) h_AverageRes_CS2_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CS2rms_C ) h_AverageRes_CS2rms_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CSmore2_C ) h_AverageRes_CSmore2_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageRes_CSmore2rms_C ) h_AverageRes_CSmore2rms_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageOccupancy_C ) h_AverageOccupancy_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageCS_C ) h_AverageCS_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageTime_C ) h_AverageTime_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageNoiseCorr_C ) h_AverageNoiseCorr_C ->Write("",TObject::kOverwrite) ; + if ( h_AverageNoiseTot_C ) h_AverageNoiseTot_C ->Write("",TObject::kOverwrite) ; + } + + + } + }else { + delete obj_run; + } // end if tdir_run !=0 + + } + f->Close(); + delete f; + //std::cout << "\n"; + //std::cout << "Finish RPC analysis"<<std::endl; +} + + + + + + +bool +MonitoringFile:: +RPCCheckHistogram(TFile* f,const char* HistoName) + { + if (!(f->Get(HistoName))) { + //std::cerr << "RPC PostProcessing: no such histogram \""<< HistoName << "\"\n"; + return false; + } + else return true; + } + +} diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_SCTPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_SCTPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..65a75b64a00a129b81d5c8fb03dd3f760a1737a1 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_SCTPostProcess.cxx @@ -0,0 +1,203 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +///////////////////////////////////////////////////////////////////// +//Methods to process SCT histograms after merging. +//Author: Masaki ENDO (masaki.endo@cern.ch) +//Date: Aug 2012 +///////////////////////////////////////////////////////////////////// + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TBranch.h" + + +namespace dqutils { + + static const bool rno_debug = false; + + void + MonitoringFile::SCTPostProcess( std::string inFilename, bool /* isIncremental */ ) + { + if (rno_debug) std::cout << "Start SCT post-processing" <<std::endl; + + TFile *infile = TFile::Open(inFilename.c_str(),"UPDATE"); + if(infile==0 || ! infile->IsOpen()){ + std::cerr << "--> SCTPostProcess: Input file not opened" <<std::endl; + return; + } + if(infile->IsZombie()){ + std::cerr << "--> SCTPostProcess: Input file " << inFilename << " cannot be opened" <<std::endl; + return; + } + if(infile->GetSize()<1000){ + std::cerr << "--> SCTPostProcess: Input file empty " <<std::endl; + return; + } + + //start postprocessing + + TIter next_run(infile->GetListOfKeys()); + TKey *key_run(0); + key_run = (TKey*)next_run(); + TDirectory *dir0 = dynamic_cast<TDirectory*> (key_run->ReadObj()); + if (!dir0) return; // should never fail + dir0->cd(); + + TString run_dir; + int times = 1; + while (times--) { // just once + run_dir = dir0->GetName(); + TString rno_dir = run_dir + "/SCT/GENERAL/RatioNoise/"; + + TDirectory *dir = infile->GetDirectory(rno_dir); + if(!dir){ + std::cerr << "--> SCTPostProcess: directory " << rno_dir << " not found " <<std::endl; + return; + } + + TString noSideHitHist = rno_dir + "h_NZ1_vs_modnum"; + TString oneSideHitHist = rno_dir + "h_N11_vs_modnum"; + + TH1F *h_nosidehit = (TH1F*)infile->Get(noSideHitHist); + TH1F *h_onesidehit = (TH1F*)infile->Get(oneSideHitHist); + + if(!h_nosidehit || !h_onesidehit){ + std::cerr << "--> SCTPostProcess: no such histogram " <<std::endl; + return; + } + + + TH1F *hist_all = new TH1F("h_NO","Noise Occupancy for Barrel and Endcaps",500,0.,100.); + TH1F *hist_bar = new TH1F("h_NOb","Noise Occupancy for Barrel",500,0.,100.); + TH1F *hist_end = new TH1F("h_NOEC","Noise Occupancy for Endcaps",500,0.,100.); + TH1F *hist_endc = new TH1F("hist_endcapC","endcap C",500,0.,100.); + TH1F *hist_enda = new TH1F("hist_endcapA","endcap A",500,0.,100.); + + TH1F *hist_bar_layer[4]; + for(int i=0;i<4;i++){ + hist_bar_layer[i] = new TH1F(Form("h_NOb_layer%d",i),Form("Noise Occupancy Barrel Layer %d",i),500,0.,100.); + } + TH1F *hist_endC_disk[9]; + for(int i=0;i<9;i++){ + hist_endC_disk[i] = new TH1F(Form("h_NOECC_disk%d",i),Form("Noise Occupancy Endcap C disk %d",i),500,0.,100.); + } + TH1F *hist_endA_disk[9]; + for(int i=0;i<9;i++){ + hist_endA_disk[i] = new TH1F(Form("h_NOECA_disk%d",i),Form("Noise Occupancy Endcap A disk %d",i),500,0.,100.); + } + TH1F *hist_inner = new TH1F("h_NOEC_Inner","Noise Occupancy Inner Endcap Modules",500,0.,100.); + TH1F *hist_middle = new TH1F("h_NOEC_Middle","Noise Occupancy Middle Endcap Modules",500,0.,100.); + TH1F *hist_outer = new TH1F("h_NOEC_Outer","Noise Occupancy Outer Endcap Modules",500,0.,100.); + TH1F *hist_smiddle = new TH1F("h_NOEC_ShortMiddle","Noise Occupancy Short Middle Endcap Modules",500,0.,100.); + + int nModuleEndCap1[9] = {0, 92, 224, 356, 488, 620, 752, 844, 936}; + int nModuleEndCap2[9] = {92, 224, 356, 488, 620, 752, 844, 936, 988}; + int nModuleBarrel1[4] = {0, 384, 864, 1440}; + int nModuleBarrel2[4] = {384, 864, 1440, 2112}; + + for(int i=0;i<4088;i++){ + int nosidehit = h_nosidehit->GetBinContent(i+1); + int onesidehit = h_onesidehit->GetBinContent(i+1); + if(nosidehit>0){ + double Rval = (double)onesidehit/(double)nosidehit; + double NOval = 1./768.*Rval/(2.+Rval); + if(NOval!=0){ + hist_all->Fill(100000.*NOval); + if(i>=0 && i<988){ + hist_end->Fill(100000.*NOval); + hist_endc->Fill(100000.*NOval); + for(int j=0;j<9;j++){ + if(i>=nModuleEndCap1[j] && i<nModuleEndCap2[j]){ + hist_endC_disk[j]->Fill(100000.*NOval); + if(i-nModuleEndCap1[j]<52){ + hist_outer->Fill(100000.*NOval); + }else if(i-nModuleEndCap1[j]>=52 && i-nModuleEndCap1[j]<92){ + if(i<844){ + hist_middle->Fill(100000.*NOval); + }else if(i>=844){ + hist_smiddle->Fill(100000.*NOval); + } + }else if(i-nModuleEndCap1[j]>=92 && i-nModuleEndCap1[j]<132){ + hist_inner->Fill(100000.*NOval); + } + } + } + }else if(i>=988 && i<3100){ + hist_bar->Fill(100000.*NOval); + for(int j=0;j<4;j++){ + if(i>=nModuleBarrel1[j]+988 && i<nModuleBarrel2[j]+988){ + hist_bar_layer[j]->Fill(100000*NOval); + } + } + }else if(i>=3100 && i<4088){ + hist_end->Fill(100000.*NOval); + hist_enda->Fill(100000.*NOval); + for(int j=0;j<9;j++){ + if(i>=nModuleEndCap1[j]+3100 && i<nModuleEndCap2[j]+3100){ + hist_endA_disk[j]->Fill(100000*NOval); + if(i-nModuleEndCap1[j]-3100<52){ + hist_outer->Fill(100000.*NOval); + }else if(i-nModuleEndCap1[j]-3100>=52 && i-nModuleEndCap1[j]-3100<92){ + if(i-3100<844){ + hist_middle->Fill(100000.*NOval); + }else if(i-3100>=844){ + hist_smiddle->Fill(100000.*NOval); + } + }else if(i-nModuleEndCap1[j]-3100>=92 && i-nModuleEndCap1[j]-3100<132){ + hist_inner->Fill(100000.*NOval); + } + } + } + } + } + } + } + hist_all->SetBinContent(hist_all->GetNbinsX(),hist_all->GetBinContent(hist_all->GetNbinsX() ) + hist_all->GetBinContent(hist_all->GetNbinsX() +1)); + hist_bar->SetBinContent(hist_bar->GetNbinsX(),hist_bar->GetBinContent(hist_bar->GetNbinsX() ) + hist_bar->GetBinContent(hist_bar->GetNbinsX() +1)); + hist_end->SetBinContent(hist_end->GetNbinsX(),hist_end->GetBinContent(hist_end->GetNbinsX() ) + hist_end->GetBinContent(hist_end->GetNbinsX() +1)); + + dir->cd(); + hist_all->Write("", TObject::kOverwrite); + hist_bar->Write("", TObject::kOverwrite); + hist_end->Write("", TObject::kOverwrite); + for(int i=0;i<4;i++){ + hist_bar_layer[i]->Write("", TObject::kOverwrite); + } + for(int i=0;i<9;i++){ + hist_endC_disk[i]->Write("", TObject::kOverwrite); + } + for(int i=0;i<9;i++){ + hist_endA_disk[i]->Write("", TObject::kOverwrite); + } + hist_inner->Write("", TObject::kOverwrite); + hist_middle->Write("", TObject::kOverwrite); + hist_outer->Write("", TObject::kOverwrite); + hist_smiddle->Write("", TObject::kOverwrite); + infile->Write(); + + }//while + } + +}//namespace diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_TGCPostProcess.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_TGCPostProcess.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5045643f1ba040237f046a9690a49f1f8d9397a7 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_TGCPostProcess.cxx @@ -0,0 +1,1077 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//Methods to Process TGC Histograms after merging. +//Author: Akimasa Ishikawa (akimasa.ishikawa@cern.ch) +//Date: Aug 2009 +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "DataQualityUtils/MonitoringFile.h" +#include "DataQualityUtils/CoolTgc.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TTree.h" +#include "TBranch.h" +#include "TGraph.h" + +namespace dqutils { + + static const float TGCChamberLowOccupancyCut = 1.0e-6; + static const float TGCChamberHighOccupancyCut = 0.005; + static const float TGCChannelOccupancyCut = 0.01; + static const float TGCChamberEfficiencyCut = 0.7; + static const float TGCChamberTimingCut = 0.95; + + static const bool tgc_debug = false; + + void + MonitoringFile::TGCPostProcess( std::string inFilename, bool /* isIncremental */ ) + { + //start postprocessing + std::vector< std::pair< std::string, float > > NoisyChambers; + std::vector< std::pair< std::string, float > > DeadChambers; + + std::vector< std::pair< std::string, float > > NoisyChannels; + + std::vector< std::pair< std::string, float > > LowEfficiencyChambers; + + std::vector< std::pair< std::string, float > > ReadoutTimingChambers; + std::vector< std::pair< std::string, float > > TriggerTimingChambers; + + TGCLV1HistogramDivision( inFilename); + TGCRawHistogramDivision( inFilename); + TGCChamberOccupancy( inFilename, NoisyChambers, DeadChambers ); + // TGCChannelOccupancy( inFilename, run_dir, NoisyChannels ); + + TGCChamberEfficiency( inFilename, LowEfficiencyChambers ); + TGCChamberTiming( inFilename, ReadoutTimingChambers, TriggerTimingChambers); + //DQA results to COOL + + return; + }//MonitoringFile::TGCPostProcess + + bool + MonitoringFile::TGCCheckHistogram(TFile *f, TString &hname) + { + if (!(f->Get(hname))) { + //std::cerr << "TGC PostProcessing: no such histogram!! : "<< hname << std::endl; + gDirectory->pwd(); + gDirectory->ls(); + return false; + } + return true; + }//MonitoringFile::TGCCheckHistogram + + void + MonitoringFile::TGCChamberOccupancy(std::string inFilename, + std::vector< std::pair< std::string, float > >& noisychambers, + std::vector< std::pair< std::string, float > >& deadchambers) + { + PostProcessorFileWrapper mf( inFilename , "TGC ChamberOcc Calculations"); + if (!mf.IsOpen()) { + //std::cerr << "TGCPostProcess(): " + // << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + //std::cerr << "TGCPostProcess(): " + // << "Input file empty \n"; + return; + } + /* + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + dir0->cd(); + /// + */ + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + TString run_dir = key_run->GetName(); + if (!run_dir.Contains("run"))continue; + + std::string run_dir2 = run_dir.Data(); + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + TString tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGC/"; + + TString tgc_global_dir = tgc_dir + "Global/"; + + TString tgc_sub_dir[2] = {tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"}; + + TString sac[2]={"_A","_C"}; + TString side[2]={"A","C"}; + TString sws[2]={"Wire_","Strip_"}; + + std::stringstream ss; + + //Summary histograms + TString schambertypesummary[2][4][6];//[ws][station][eta] + TH1F* chambertypesummary[2][4][6];// + + TString schambersummary[2][2];//[ac][ws] + TH1F* chambersummary[2][2];// + + std::string type[17]={"_F_T1", "_E4_T3", "_E3_T6", "_E2_T7", "_E1_T8", + "_F_T2", "_E5_T4", "_E4_T6", "_E3_T7", "_E2_T8","_E1_T9", + "_F_T2", "_E5_T5", "_E4_T6", "_E3_T7", "_E2_T8","_E1_T9" }; + + //get summary histograms + for(int ws=0;ws<2;ws++){ + int ntype=0; + for(int station=0;station<3;station++){ + for(int eta=0;eta<6;eta++){ + if(eta==5 && station==0)continue; + if(eta<2 && station==3)continue; + + ss.str(""); + ss<<"Station"<<station+1<<type[ntype]; + schambertypesummary[ws][station][eta] = tgc_dir + "Global/Summary/" + + "Summary_Of_Log10_" + sws[ws] + "Occupancy_Per_Chamber_Type_" + ss.str(); + if( tgc_debug ) std::cout << schambertypesummary[ws][station][eta] << std::endl; + + chambertypesummary[ws][station][eta] = 0; + mf.get(schambertypesummary[ws][station][eta], chambertypesummary[ws][station][eta]); + if(!chambertypesummary[ws][station][eta]){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambertypesummary[ws][station][eta] << std::endl; + continue; + } + TGCResetContents(chambertypesummary[ws][station][eta]); + + ntype++; + + }//eta + }//station + + for( int ac=0;ac<2;ac++){ + schambersummary[ac][ws] = tgc_sub_dir[ac] + "Summary/" + + "Summary_Of_Log10_" + sws[ws] + "Occupancy_Per_GasGap" + sac[ac]; + if( tgc_debug ) std::cout << schambersummary[ac][ws] << std::endl; + + chambersummary[ac][ws] = 0; + mf.get(schambersummary[ac][ws], chambersummary[ac][ws]); + if(!chambersummary[ac][ws]){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambersummary[ac][ws] << std::endl; + continue; + } + TGCResetContents(chambersummary[ac][ws]); + + }// ac + }// ws + + //get number of events processed + TString sentries = tgc_global_dir + "Event_Counter"; + + TH1F *hentries = 0; + mf.get(sentries, hentries); + if(!hentries){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sentries << std::endl; + continue; + } + + double nentries = hentries->GetEntries(); + + //calculate occupancies + for(int ac=0;ac<2;ac++){ + for(int ws=0;ws<2;ws++){ + double min=1.; + double max=0.; + + TString sprof = tgc_sub_dir[ac] + "Profile/" + sws[ws] + "Profile_Map" + sac[ac]; + TString soccu = tgc_sub_dir[ac] + "Occupancy/" + sws[ws] + "Occupancy_Map" + sac[ac]; + + TH2F *hprof = 0; + mf.get(sprof, hprof); + if(!hprof){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sprof << std::endl; + continue; + } + + TH2F *hoccu = 0; + mf.get(soccu, hoccu); + if(!hoccu){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< soccu << std::endl; + continue; + } + TGCResetContents(hoccu); + + int nbinx = hprof->GetXaxis()->GetNbins(); + int nbiny = hprof->GetYaxis()->GetNbins(); + + for(int binx=1; binx<=nbinx; binx++){ + for(int biny=1; biny<=nbiny; biny++){ + if( ws==1 && binx>=6 && binx<=10 ) continue;//skip strip for layer2 + if( ( binx==5 || binx==10 || binx==15 || + binx==21 || binx==27 || binx==33 || binx>=39 ) && + biny%2 == 0 )continue;// skip phi1,3 for forward region + if( ( binx ==40 || binx==42 ) && + ( biny ==19 || biny==35 || biny==43 ) ) continue;//skip phi9,17,21 for EI + + double num = hprof->GetBinContent(binx,biny); + double den = nentries * nTGCWireStripMap( ws, binx-1, biny ); + double occu = 0.; + double eoccu = 0.; + if(num>0 && nentries>0){ + occu = (double)num/den; + eoccu = sqrt( occu*(1.-occu)/den ); + } + hoccu->SetBinContent(binx,biny,occu); + hoccu->SetBinError(binx,biny,eoccu); + + // to set minimum and maximum + if(occu<min && occu > 1e-8)min=occu; + if(occu>max)max=occu; + + if( occu < 1.e-8 ){ + occu=1.e-8; + eoccu=1.e-8; + } + if(chambersummary[ac][ws]) + chambersummary[ac][ws]->Fill(log10(occu)); + + int station=0; + int eta=-1; + if( binx < 16){ + station=0; + eta=(binx-1)%5; + } else if ( binx < 28 ){ + station=1; + eta=(binx-16)%6; + } else if ( binx < 40 ){ + station=2; + eta=(binx-28)%6; + } else { + station=3; + eta=(binx-40)%2; + } + if(station<3 && eta >=0) + if(chambertypesummary[ws][station][eta]) + chambertypesummary[ws][station][eta]->Fill(log10(occu)); + + //high occupancy chamber + if(occu > TGCChamberHighOccupancyCut){ + ss.str(""); + TString schamber = hprof->GetXaxis()->GetBinLabel(binx); + int sector = (biny-1)/4 + 1; + int phi = (biny-1)%4; + ss<< side[ac]; + if(sector<10)ss<<"0"; + ss<< sector <<"phi"<<phi; + if( tgc_debug ) std::cout<<"TGC noisy channel : " << ss.str() << " " << occu << std::endl; + + std::pair<std::string, float> p(ss.str(),occu); + noisychambers.push_back(p); + }else if( occu < TGCChamberLowOccupancyCut ){//too low occupancy + ss.str(""); + TString schamber = hprof->GetXaxis()->GetBinLabel(binx); + int sector = (biny-1)/4 + 1; + int phi = (biny-1)%4; + ss<< side[ac]; + if(sector<10)ss<<"0"; + ss<< sector <<"phi"<<phi; + if( tgc_debug ) std::cout<<"TGC low occupancy chamber : " << ss.str() << " " << occu << std::endl; + + std::pair<std::string, float> p(ss.str(),occu); + deadchambers.push_back(p); + } + + }//biny + }//binx + + hoccu->SetMinimum(min*0.95); + hoccu->SetMaximum(max*1.05); + + TString occu_dir = tgc_sub_dir[ac] + "Occupancy/" ; + TDirectory* dir = mf.GetDirectory(occu_dir); + + if(dir){ + dir->cd(); + hoccu->Write("",TObject::kOverwrite); + }else{ + //std::cerr<<"TGCChamberOccupancy: directory "<<occu_dir<<" not found"<<std::endl; + } + + }//ws + }//ac + mf.Write(); + + // if directory is found, save the summary histogram + TString sum_dir = tgc_dir + "Global/Summary"; + TDirectory* dir = mf.GetDirectory(sum_dir); + + if(dir){ + dir->cd(); + for(int ws=0;ws<2;ws++){ + for(int station=0;station<3;station++){ + for(int eta=0;eta<6;eta++){ + if(eta==5 && station==0)continue; + if(eta<2 && station==3)continue; + if(chambertypesummary[ws][station][eta]) + chambertypesummary[ws][station][eta]->Write("",TObject::kOverwrite); + + }//eta + }//station + }//ws + }else{ + //std::cerr<<"TGCChamberOccupancy: directory "<<sum_dir<<" not found"<<std::endl; + }//if + mf.Write(); + + for( int ac=0 ;ac<2 ;ac++){ + // if directory is found, save the summary histogram + sum_dir = tgc_sub_dir[ac] + "Summary/"; + dir = mf.GetDirectory(sum_dir); + if(dir){ + dir->cd(); + for(int ws=0;ws<2;ws++){ + if(chambersummary[ac][ws]) + chambersummary[ac][ws]->Write("",TObject::kOverwrite); + }//ws + }else{ + //std::cerr<<"TGCChamberOccupancy: directory "<<sum_dir<<" not found"<<std::endl; + }//if + }//ac + mf.Write(); + + }//while + + mf.Write(); + }//MonitoringFile::TGCChamberOccupancy + + void + MonitoringFile::TGCChamberEfficiency(std::string inFilename, + std::vector< std::pair< std::string, + float > >& loweffchambers) + { + PostProcessorFileWrapper mf( inFilename , "TGC ChamberEff Calculations"); + if (!mf.IsOpen()) { + //std::cerr << "TGCPostProcess(): " + // << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + //std::cerr << "TGCPostProcess(): " + // << "Input file empty \n"; + return; + } + /* + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + dir0->cd(); + /// + */ + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + TString run_dir = key_run->GetName(); + if (!run_dir.Contains("run"))continue; + + std::string run_dir2 = run_dir.Data(); + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + TString tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGC/"; + + TString tgc_sub_dir[2] = {tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"}; + + TString sac[2]={"_A","_C"}; + TString sws[2]={"Wire_","Strip_"}; + + std::stringstream ss; + + //Summary histograms + TString schambertypesummary[2][3][6];//[ws][station][eta] + TH1F* chambertypesummary[2][3][6];// + + TString schambersummary[2][2];//[ac][ws] + TH1F* chambersummary[2][2];// + + std::string type[17]={"_F_T1", "_E4_T3", "_E3_T6", "_E2_T7", "_E1_T8", + "_F_T2", "_E5_T4", "_E4_T6", "_E3_T7", "_E2_T8","_E1_T9", + "_F_T2", "_E5_T5", "_E4_T6", "_E3_T7", "_E2_T8","_E1_T9" }; + + //get summary histograms + for(int ws=0;ws<2;ws++){ + int ntype=0; + for(int station=0;station<3;station++){ + for(int eta=0;eta<6;eta++){ + if(eta==5 && station==0)continue; + if(eta<2 && station==3)continue; + + ss.str(""); + ss<<"Station"<<station+1<<type[ntype]; + schambertypesummary[ws][station][eta] = tgc_dir + "Global/Summary/" + + "Summary_Of_" + sws[ws] + "Efficiency_Per_Chamber_Type_" + ss.str(); + if( tgc_debug ) std::cout << schambertypesummary[ws][station][eta] << std::endl; + + chambertypesummary[ws][station][eta] = 0; + mf.get(schambertypesummary[ws][station][eta], chambertypesummary[ws][station][eta]); + if(!chambertypesummary[ws][station][eta]){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambertypesummary[ws][station][eta] << std::endl; + continue; + } + TGCResetContents(chambertypesummary[ws][station][eta]); + + ntype++; + + }//eta + }//station + + for( int ac=0 ;ac<2 ;ac++){ + schambersummary[ac][ws] = tgc_sub_dir[ac] + "Summary/" + + "Summary_Of_" + sws[ws] + "Efficiency_Per_GasGap" + sac[ac]; + if( tgc_debug ) std::cout << schambersummary[ac][ws] << std::endl; + + chambersummary[ac][ws] = 0; + mf.get(schambersummary[ac][ws], chambersummary[ac][ws]); + if(!chambersummary[ac][ws]){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambersummary[ac][ws] << std::endl; + continue; + } + TGCResetContents(chambersummary[ac][ws]); + + }//ac + }//ws + + for(int ac=0;ac<2;ac++){ + for(int ws=0;ws<2;ws++){ + TString seff = tgc_sub_dir[ac] + "Efficiency/" + sws[ws] + "Efficiency_Map" + sac[ac]; + TString sden = tgc_sub_dir[ac] + "Efficiency/NumDenom/" + sws[ws] + "Efficiency_Map" + sac[ac] + "_Denominator"; + + TH2F *heff = 0; + mf.get(seff, heff); + if(!heff){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< seff << std::endl; + continue; + } + + TH2F *hden = 0; + mf.get(sden, hden); + if(!hden){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sden << std::endl; + } + + int nbinx = heff->GetXaxis()->GetNbins(); + int nbiny = heff->GetYaxis()->GetNbins(); + + for(int binx=1; binx<=nbinx; binx++){ + for(int biny=1; biny<=nbiny; biny++){ + if( ( binx==5 || binx==10 || binx==15 || + binx==21 || binx==27 || binx==33 || binx>=39 ) && + biny%2 == 0 )continue;// skip phi1,3 for forward region + if( ( binx ==40 || binx==42 ) && + ( biny ==18 || biny==34 || biny==42 ) ) continue;//skip phi9,17,21 for EI + + double eff = heff->GetBinContent(binx,biny); + double denom = 1; + if(hden){ + denom = hden->GetBinContent(binx,biny); + } + + if(chambersummary[ac][ws]) + if(denom>0) + chambersummary[ac][ws]->Fill( eff ); + + int station=0; + int eta=-1; + if( binx < 16){ + station=0; + eta=(binx-1)%5; + } else if ( binx < 28 ){ + station=1; + eta=(binx-16)%6; + } else if ( binx < 40 ){ + station=2; + eta=(binx-28)%6; + } else { + station=3; + eta=(binx-40)%2; + } + if(station<3 && eta >=0) + if(chambertypesummary[ws][station][eta]) + if(denom>0) + chambertypesummary[ws][station][eta]->Fill( eff ); + + //low efficiency chambers + if(eff<TGCChamberEfficiencyCut){ + ss.str(""); + TString schamber = heff->GetXaxis()->GetBinLabel(binx); + int sector = (biny-1)/4 + 1; + int phi = (biny-1)%4; + ss<< sac[ac]; + if(sector<10)ss<<"0"; + ss<< sector <<"phi"<<phi; + + if( tgc_debug ) std::cout<<"TGC low efficiency chamber : " << ss.str() << " " << eff << std::endl; + + std::pair<std::string, float> p(ss.str(),eff); + loweffchambers.push_back(p); + } + + }//biny + }//binx + + TString eff_dir = tgc_sub_dir[ac] + "Efficiency/" ; + TDirectory* dir = mf.GetDirectory(eff_dir); + + if(dir){ + dir->cd(); + heff->Write("",TObject::kOverwrite); + }else{ + //std::cerr<<"TGCChamberEfficiency: directory "<<eff_dir<<" not found"<<std::endl; + } + + }//ws + }//ac + + mf.Write(); + // if directory is found, save the summary histogram + TString sum_dir = tgc_dir + "Global/Summary"; + TDirectory* dir = mf.GetDirectory(sum_dir); + + + if(dir){ + dir->cd(); + for(int ws=0;ws<2;ws++){ + for(int station=0;station<3;station++){ + for(int eta=0;eta<6;eta++){ + if(eta==5 && station==0)continue; + if(eta<2 && station==3)continue; + if(chambertypesummary[ws][station][eta]) + chambertypesummary[ws][station][eta]->Write("",TObject::kOverwrite); + + }//eta + }//station + }//ws + }else{ + //std::cerr<<"TGCChamberEfficiency: directory "<<sum_dir<<" not found"<<std::endl; + }//if + mf.Write(); + + for( int ac=0 ;ac<2 ;ac++){ + // if directory is found, save the summary histogram + sum_dir = tgc_sub_dir[ac] + "Summary/"; + dir = mf.GetDirectory(sum_dir); + if(dir){ + dir->cd(); + for( int ws=0; ws<2 ; ws++ ){ + if(chambersummary[ac][ws]) + chambersummary[ac][ws]->Write("",TObject::kOverwrite); + + }//ws + }else{ + //std::cerr<<"TGCChamberEfficiency: directory "<<sum_dir<<" not found"<<std::endl; + }//if + }//ac + mf.Write(); + }//while + mf.Write(); + }//MonitoringFile::TGCChamberEfficiency + + void + MonitoringFile::TGCChamberTiming(std::string inFilename, + std::vector< std::pair< std::string, float > >& badrotimingchambers, + std::vector< std::pair< std::string, float > >& badtrgtimingchambers) + { + PostProcessorFileWrapper mf( inFilename , "TGC Chamber Timing Calculations"); + if (!mf.IsOpen()) { + //std::cerr << "TGCPostProcess(): " + // << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + //std::cerr << "TGCPostProcess(): " + // << "Input file empty \n"; + return; + } + /* + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + dir0->cd(); + /// + */ + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + TString run_dir = key_run->GetName(); + if (!run_dir.Contains("run"))continue; + + std::string run_dir2 = run_dir.Data(); + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + TString tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGCLV1/"; + + TString tgc_sub_dir[2] = {tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"}; + + TString sac[2]={"_A","_C"}; + + TString ssllpt[2]={"SL_Timing","Low_Pt_Timing"}; + + std::stringstream ss; + //Summary histograms + TString schambertypesummary[6];//[station][eta] + TH1F* chambertypesummary[6];// + + std::string type[6]={"_F_T2", "_E5_T5", "_E4_T6", "_E3_T7", "_E2_T8","_E1_T9" }; + + for(int sllpt=0;sllpt<2;sllpt++){//loop over SL/LPT + for(int eta=0;eta<6;eta++){ + //get summary histograms + ss.str(""); + ss<<type[eta]; + schambertypesummary[eta] = tgc_dir + "Global/Summary/" + + "Summary_Of_" + ssllpt[sllpt] + "_Per_Chamber_Type" + ss.str(); + + chambertypesummary[eta] = 0; + mf.get(schambertypesummary[eta], chambertypesummary[eta]); + if(!chambertypesummary[eta]){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambertypesummary[eta] << std::endl; + continue; + } + TGCResetContents(chambertypesummary[eta]); + }//eta + + for(int ac=0;ac<2;ac++){ + //get summary histogram + TString ssum = tgc_sub_dir[ac] + "Summary/Summary_Of_" + ssllpt[sllpt] + sac[ac]; + TString stmap = tgc_sub_dir[ac] + ssllpt[sllpt] + "_Map" + sac[ac]; + TString stfrac = tgc_sub_dir[ac] + ssllpt[sllpt] + "_Fraction_Map" + sac[ac]; + + TH1F *hsum = 0; + mf.get(ssum, hsum); + if(!hsum){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< ssum << std::endl; + continue; + } + + TH2F *htmap = 0; + mf.get(stmap, htmap); + if(!htmap){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< stmap << std::endl; + continue; + } + + TH2F *htfrac = 0; + mf.get(stfrac, htfrac); + if(!htfrac){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< stfrac << std::endl; + continue; + } + + if(!hsum||!htmap||!htfrac)continue; + TGCResetContents(hsum); + TGCResetContents(htfrac); + + int nbinx = htmap->GetXaxis()->GetNbins(); + int nbiny = htmap->GetYaxis()->GetNbins(); + + if( nbinx !=18 || nbiny != 48 ) continue; + + for( int eta = 0 ; eta < 6 ; eta++ ){ + for( int phi48 = 0 ; phi48 < 48 ; phi48++ ){ + if( eta==5 && phi48%2 ==1 )continue;//Forward + + float p = htmap->GetBinContent( eta + 1, phi48 +1); + float c = htmap->GetBinContent( eta + 7, phi48 +1); + float n = htmap->GetBinContent( eta + 13, phi48 +1); + float tot=p+n+c; + + float fp = 0; + float fc = 0; + float fn = 0; + + float efp = 0; + float efc = 0; + float efn = 0; + + if( tot != 0 ){ + fp = p/tot; efp = sqrt( fp * (1. - fp )/tot ); + fc = c/tot; efc = sqrt( fc * (1. - fc )/tot ); + fn = n/tot; efn = sqrt( fn * (1. - fn )/tot ); + } + + htfrac->SetBinContent( eta + 1, phi48 + 1, fp ); + htfrac->SetBinContent( eta + 7, phi48 + 1, fc ); + htfrac->SetBinContent( eta + 13, phi48 + 1, fn ); + htfrac->SetBinError( eta + 1, phi48 + 1, efp ); + htfrac->SetBinError( eta + 7, phi48 + 1, efc ); + htfrac->SetBinError( eta + 13, phi48 + 1, efn ); + + if(chambertypesummary[eta]) + chambertypesummary[eta]->Fill(fc); + hsum->Fill(fc); + + //low current fraction chambers + if(fc < TGCChamberTimingCut){ + ss.str(""); + //std::string chamber = htiming->GetXaxis()->GetBinLabel(bin); + ss<< sac[ac] << "phi" <<phi48+1<<"Eta"<<eta; + + if( tgc_debug ) std::cout<<"TGC "<<ssllpt[sllpt]<<" low current BCID fraction chamber : " << ss.str() << " " << fc << std::endl; + + std::pair<std::string, float> p(ss.str(), fc); + if(sllpt==0){ + badtrgtimingchambers.push_back(p); + }else{ + badrotimingchambers.push_back(p); + } + } + + }//phi48 + }//eta + + //write timing fraction + TString timing_dir = tgc_sub_dir[ac]; + TDirectory* dir = mf.GetDirectory(timing_dir); + + if(dir){ + dir->cd(); + htfrac->Write("",TObject::kOverwrite); + }else{ + //std::cerr<<"TGCChamberTiming : directory "<<timing_dir<<" not found"<<std::endl; + } + + //write summary of timing for each side + TString sum_dir = tgc_sub_dir[ac] + "Summary/"; + dir = mf.GetDirectory(sum_dir); + + if(dir){ + dir->cd(); + hsum->Write("",TObject::kOverwrite); + }else{ + //std::cerr<<"TGCChamberTiming : directory "<<sum_dir<<" not found"<<std::endl; + } + + }//ac + mf.Write(); + + //write summary of timing for each eta + TString sum_dir = tgc_dir + "Global/Summary/"; + TDirectory* dir = mf.GetDirectory(sum_dir); + + if(dir){ + dir->cd(); + for(int eta=0;eta<6;eta++){ + if(chambertypesummary[eta]) + chambertypesummary[eta]->Write("",TObject::kOverwrite); + } + } + else{ + //std::cerr<<"TGCChamberTiming : directory "<<sum_dir<<" not found"<<std::endl; + } + mf.Write(); + + }//sllpt + }//while + mf.Write(); + }//MonitoringFile::TGCChamberTiming + + void + MonitoringFile::TGCChannelOccupancy(std::string inFilename, + std::vector< std::pair< std::string, + float > >& noisychannels) + { + PostProcessorFileWrapper mf( inFilename , "TGC ChannelOcc Calculations"); + if (!mf.IsOpen()) { + //std::cerr << "TGCPostProcess(): " + // << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + //std::cerr << "TGCPostProcess(): " + // << "Input file empty \n"; + return; + } + /* + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + dir0->cd(); + /// + */ + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + while ((key_run = dynamic_cast<TKey*> ( next_run() )) !=0 ) { + if (!key_run->IsFolder()) continue; + TString run_dir = key_run->GetName(); + if (!run_dir.Contains("run"))continue; + + std::string run_dir2 = run_dir.Data(); + int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + run_number=run_number; + + TString tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGC/"; + + TString tgc_global_dir = tgc_dir + "Global/"; + TString tgc_sub_dir[2] = {tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"}; + + TString sac[2]={"_A","_C"}; + TString sws[2]={"Wire_","Strip_"}; + TString slay[7]={"1","2","3","4","5","6","7"}; + std::stringstream ss; + + //get number of events processed + TString sentries = tgc_global_dir + "Event_Counter"; + + TH1F *hentries = 0; + mf.get(sentries, hentries); + if(!hentries){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sentries << std::endl; + continue; + } + + double nentries = hentries->GetEntries(); + + for(int ac=0;ac<2;ac++){ + for(int ws=0;ws<2;ws++){ + for(int lay=0;lay<7;lay++){ + if( ws==1 && lay==1)continue; + for(int subsect=1;subsect<=48;subsect++){ + //get each subsector histogram + int sector, phi4; + TGCsubsect2sectorphi(subsect, sector, phi4); + + ss.str(""); + if(sector<10) ss<<"0"; + ss<<sector<< "_Layer" << slay[lay] << "_Phi" << phi4; + TString sprof = tgc_sub_dir[ac] + "Profile/" + sws[ws] + "Hit_Profile" + sac[ac] + ss.str(); + + TH1F *hprof = 0; + mf.get(sprof, hprof); + if(!hprof){ + //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sprof << std::endl; + continue; + } + + int nbin = hprof->GetXaxis()->GetNbins(); + + for(int bin=1; bin<=nbin; bin++){ + double num = hprof->GetBinContent(bin); + float occu = 0.; + if(nentries>0) + occu = (float)num/nentries; + if(occu > TGCChannelOccupancyCut){ + ss.str(""); + ss<< hprof->GetName() <<" " << bin; + if( tgc_debug ) std::cout<<"TGC noisy channel : " << ss.str() << " " << occu << std::endl; + + std::pair<std::string, float> p(ss.str(),occu); + noisychannels.push_back(p); + } + }//bin + }//subsect + }//lay + }//loop over ws + }//loop over ac + }//while + }//MonitoringFile::TGCChannelOccupancy + + void + MonitoringFile::TGCsubsectbin2stationeta(int subsect, int bin, int& station, int& eta) + { + if(subsect%2 == 1 ){//including forward chamber + if(bin<=15){ + station = 1; + eta = (bin-1)%5; + }else if( bin <=27 ){ + station = 2; + eta = (bin-16)%6; + }else{ + station = 3; + eta = (bin-28)%6; + } + }else{ + if(bin<=12){ + station = 1; + eta = (bin-1)%4 + 1; + }else if( bin <=22 ){ + station = 2; + eta = (bin-13)%5 + 1; + }else{ + station = 3; + eta = (bin-23)%5 + 1; + } + } + + }//MonitoringFile::TGCsubsectbin2stationeta + + void + MonitoringFile::TGCsubsect2sectorphi(int subsect, int& sector, int& phi4) + { + sector = ( subsect+1 ) / 4 + 1; + if( sector >12 ) sector=1; + phi4 = (subsect + 1 ) % 4 ; + + }//MonitoringFile::TGCsubsect2sectorphi + + int + MonitoringFile::nTGCWireStripMap(int ws, int etac, int phi48)//[0:1][0:42][1:48] + { + + int layer=0; + int eta = etac; + int st =0; + if ( etac <= 4 ){ layer = 0; eta = 4 - etac; st = 42;} + else if ( etac <= 9 ){ layer = 1; eta = 9 - etac; st = 42;} + else if ( etac <= 14 ){ layer = 2; eta = 14 - etac; st = 42;} + else if ( etac <= 20 ){ layer = 3; eta = 20 - etac; st = 44;} + else if ( etac <= 26 ){ layer = 4; eta = 26 - etac; st = 44;} + else if ( etac <= 32 ){ layer = 5; eta = 32 - etac; st = 46;} + else if ( etac <= 38 ){ layer = 6; eta = 38 - etac; st = 46;} + else if ( etac <= 40 ){ layer = 7; eta = 40 - etac; st = 48;} + else if ( etac <= 42 ){ layer = 8; eta = 42 - etac; st = 48;} + + if( eta == 0 )st-=1; + + + int nwire = getTGCNumberOfWires( st, layer, eta, phi48 ); + + + //number of strips is always 32 except no chamber region which should be nwire==0. + if(ws==1){ + if(nwire==0) return 0; + return 32; + } + + return nwire; + + } + + int + MonitoringFile::getTGCNumberOfWires( const int istationName, const int layer, const int istationEta, const int istationPhi ) + { + int nWire = 0; + if(istationName==42){ //TGC1 Endcap //41:T1F 42:T1E 43:T2F 44:T2E 45:T3F 46:T3E 47:T3F 48:T4E (T4 means inner small wheel TGCs, EI/FI) + + if(layer==0){ + if(istationEta==1){ // T3 (E4) wire 1ch-91ch (total 91ch) + nWire = 92; + } else if(istationEta==2){ //T6 (E3) 91ch-152ch (62ch) + nWire = 61; + } else if(istationEta==3){ //T7 (E2) 152ch-174ch (23ch) + nWire = 23; + } else if(istationEta==4){ //T8 (E1) 173ch-196ch(24ch) + nWire = 24; + } + }else if( layer ==1 || layer ==2){ + if(istationEta==1){ // T3 (E4) wire 1ch-91ch (total 91ch) + nWire = 91; + } else if(istationEta==2){ //T6 (E3) 91ch-152ch (62ch) + nWire = 62; + } else if(istationEta==3){ //T7 (E2) 152ch-174ch (23ch) + nWire = 23; + } else if(istationEta==4){ //T8 (E1) 173ch-196ch(24ch) + nWire = 24; + } + } + + } else if(istationName==41){ // TGC1 Forward + + if(layer==0 || layer ==2) nWire = 105; + else if(layer==1) nWire = 104; + + } else if(istationName==44){ // TGC2 Endcap + if(istationEta==1){ // T4 (E5) wire 1ch-91ch (total 91ch) + nWire = 110; + } else if(istationEta==2){ //T6 (E4) 109ch-211ch (103ch) + nWire = 103; + } else if(istationEta==3){ //T7 (E3) 211ch-242ch (23ch) + nWire = 32; + } else if(istationEta==4){ //T8 (E2) 241ch-272ch (32ch) + nWire = 32; + } else if(istationEta==5){ //T9 (E1) 271ch-302ch(32ch) + nWire = 32; + } + } else if(istationName==43){ // TGC2 Forward + nWire = 125; + } else if(istationName==46){ // TGC3 Endcap + if(istationEta==1){ // T5 (E5) wire 1ch-110ch (total 110ch) + nWire = 96; + } else if(istationEta==2){ //T6 (E4) 95ch-200ch (106ch) + nWire = 106; + } else if(istationEta==3){ //T7 (E3) 200ch-231ch (32ch) + nWire = 32; + } else if(istationEta==4){ //T8 (E2) 231ch-2 + nWire = 30; + } else if(istationEta==5){ //T9 (E1) 260ch-290ch(31ch) + nWire = 31; + } + } else if(istationName==45){ // TGC3 Forward + nWire = 122; + } else if(istationName==48){ // EI + //stationPhi 1-8 -> 1-8 + // 9-15 -> 10-16 + // 16-18 -> 18-20 + // 19-21 -> 22-24 + if(istationPhi==2 || istationPhi==11 || istationPhi==13 || istationPhi==14 || istationPhi==15 || istationPhi==16 || istationPhi==20|| istationPhi==21 ){ + //short 16 + nWire=16; + }else{ + //long 24 + nWire=24; + } + } else if(istationName==47){ // FI + if(istationPhi == 2 || istationPhi == 5 || istationPhi == 8 || istationPhi == 11 || istationPhi == 14 || istationPhi == 17 || istationPhi == 20 || istationPhi == 23 ){ + //short 30 + nWire=30; + }else{ + //long 32 + nWire=32; + } + } + return nWire; + } + + void + MonitoringFile::TGCResetContents(TH1* h) { + // copy all functions of histogram before resetting + TList* h_funcs; + h_funcs = dynamic_cast<TList*> (h->GetListOfFunctions()->Clone()); + h->Reset(); + //now insert these functions back into the hist + TIter iterE(h_funcs); + while ( (iterE()) ){h->GetListOfFunctions()->Add(*iterE);} + delete h_funcs; + // are the functions still valid after list deletion? + //http://root.cern.ch/root/html/TList#TList:_TList should be! + // TIter iterTest(EffBCap->GetListOfFunctions()); + // while( iterTest() ) std::cout << (*iterTest)->GetName() << std::endl; + } + +}//namespace + diff --git a/DataQuality/DataQualityUtils/src/MonitoringFile_TgcHistogramDivision.cxx b/DataQuality/DataQualityUtils/src/MonitoringFile_TgcHistogramDivision.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d6529bb15fb62196563eb1ce370fa3079885083b --- /dev/null +++ b/DataQuality/DataQualityUtils/src/MonitoringFile_TgcHistogramDivision.cxx @@ -0,0 +1,506 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//Methods to Divide TGC Histograms to calculate efficiency and occupancy after merging. +//Author: Akimasa Ishikawa (akimasa.ishikawa@cern.ch) +//Date: Aug 2009 +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "DataQualityUtils/MonitoringFile.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> +#include <fstream> +#include <cmath> +#include <cstdlib> +#include <sstream> +#include <vector> +#include <utility> +#include <map> +#include <string> + +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TClass.h" +#include "TKey.h" +#include "TMath.h" +#include "TF1.h" +#include "TTree.h" +#include "TCanvas.h" +#include "TBranch.h" +#include "TGraphAsymmErrors.h" + +namespace dqutils { + + void + MonitoringFile::TGCRawHistogramDivision(std::string inFilename) + { + PostProcessorFileWrapper mf( inFilename , "TGC Raw Histogram Division"); + if (!mf.IsOpen()) { + //std::cerr << "TGCPostProcess(): " + // << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + //std::cerr << "TGCPostProcess(): " + // << "Input file empty \n"; + return; + } + + std::stringstream ss; + TString sac[2]={"_A","_C"}; + TString sws[2]={"Wire_","Strip_"}; + + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + + while((key_run=dynamic_cast<TKey*> (next_run()))!=0){ + if (!key_run->IsFolder()) continue; + TString run_dir = key_run->GetName(); + if (!run_dir.Contains("run"))continue; + + std::string run_dir2 = run_dir.Data(); + //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + + TString seff; + TString snum; + TString sden; + + TH1F *h1eff(0); + TH1F *h1num(0); + TH1F *h1den(0); + TH2F *h2eff(0); + TH2F *h2num(0); + TH2F *h2den(0); + + //===TGCRaw + TString tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGC/"; + + TString tgc_global_dir = tgc_dir + "Global/"; + TString tgc_sub_dir[2] = {tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"}; + + for(int ac=0;ac<2;ac++){ + TString eff_dir = tgc_sub_dir[ac] + "Efficiency/"; + TDirectory* dir = mf.GetDirectory(eff_dir); + if(!dir){ + //std::cerr<< "TGCHistogramDivision: directory "<<eff_dir<<" not found"<<std::endl; + return; + } + + ss.str(""); + ss << "Efficiency" << sac[ac]; + seff = eff_dir + ss.str(); + ss.str(""); + ss << "Efficiency" << sac[ac] << "_Numerator"; + snum = eff_dir + "NumDenom/" + ss.str(); + ss.str(""); + ss << "Efficiency" << sac[ac] << "_Denominator"; + sden = eff_dir + "NumDenom/" + ss.str(); + + h1eff = 0; + mf.get(seff, h1eff); + h1num = 0; + mf.get(snum, h1num); + h1den = 0; + mf.get(sden, h1den); + + if( h1eff && h1num && h1den){ + TGCResetContents(h1eff); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + // save the summary histogram + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + + for(int ws=0;ws<2;ws++) { + ss.str(""); + ss << sws[ws] << "Efficiency" << sac[ac]; + seff = eff_dir + ss.str(); + ss.str(""); + ss << sws[ws] << "Efficiency" << sac[ac] << "_Numerator"; + snum = eff_dir + "NumDenom/" + ss.str(); + ss.str(""); + ss << sws[ws] << "Efficiency" << sac[ac] << "_Denominator"; + sden = eff_dir + "NumDenom/" + ss.str(); + + h1eff = 0; + mf.get(seff, h1eff); + h1num = 0; + mf.get(snum, h1num); + h1den = 0; + mf.get(sden, h1den); + + if(h1eff && h1num && h1den){ + TGCResetContents(h1eff); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + // save the summary histogram + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + mf.Write(); + + //efficiency map for current, previous and next. + std::string sbc[3]={"_Previous", "", "_Next" }; + for(int bc=0;bc<3;bc++){ + ss.str(""); + ss << sws[ws] << "Efficiency_Map" << sbc[bc] << sac[ac]; + seff = eff_dir + ss.str(); + ss.str(""); + ss << sws[ws] << "Efficiency_Map" << sbc[bc] << sac[ac] << "_Numerator"; + snum = eff_dir + "NumDenom/" + ss.str(); + ss.str(""); + ss << sws[ws] << "Efficiency_Map" << sac[ac] << "_Denominator"; + sden = eff_dir + "NumDenom/" + ss.str(); + + h2eff = 0; + mf.get(seff, h2eff); + h2num = 0; + mf.get(snum, h2num); + h2den = 0; + mf.get(sden, h2den); + + if(h2eff && h2num && h2den){ + TGCResetContents(h2eff); + h2eff->Divide(h2num, h2den, 1., 1., "B"); + + // save the summary histogram + dir->cd(); + h2eff->Write("",TObject::kOverwrite); + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + + }//bc + }//ws + }//ac + //===End TGCRaw + }// run_dir loop + + mf.Write(); + } + + void + MonitoringFile::TGCLV1HistogramDivision(std::string inFilename) + { + PostProcessorFileWrapper mf( inFilename , "TGC LV1 Histogram Division"); + if (!mf.IsOpen()) { + //std::cerr << "TGCPostProcess(): " + // << "Input file not opened \n"; + return; + } + if(mf.GetSize()<1000.) { + //std::cerr << "TGCPostProcess(): " + // << "Input file empty \n"; + return; + } + /* + // get run directory name + //Seemingly unnecessary lines are necessary + TIter nextcd0(gDirectory->GetListOfKeys()); + TKey *key0 = (TKey*)nextcd0(); + TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj()); + dir0->cd(); + /// + */ + std::stringstream ss; + TString sac[2]={"_A","_C"}; + //TString sws[2]={"Wire_","Strip_"}; + + TIter next_run ( mf.GetListOfKeys() ); + TKey* key_run(0); + while((key_run=dynamic_cast<TKey*> (next_run()))!=0){ + if (!key_run->IsFolder()) continue; + TString run_dir = key_run->GetName(); + if (!run_dir.Contains("run"))continue; + + std::string run_dir2 = run_dir.Data(); + //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() ); + + TString seff; + TString snum; + TString sden; + TString seffg; + + TH1F *h1eff(0); + TH1F *h1num(0); + TH1F *h1den(0); + TH2F *h2eff(0); + TH2F *h2num(0); + TH2F *h2den(0); + TGraphAsymmErrors *geff(0); + + //===TGCLV1 + TString tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGCLV1/"; + + TString tgc_global_dir = tgc_dir + "Global/"; + TString tgc_sub_dir[2] = {tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"}; + + std::string smuid[2] = {"_Muid","_Staco"}; + std::string spna[3] = {"_Posi","_Nega", ""}; + + std::string sbc[3]={"_Previous", "", "_Next" }; + + for(int ac=0;ac<2;ac++){ + TString eff_dir = tgc_sub_dir[ac] + "Eff/"; + TDirectory* dir = mf.GetDirectory(eff_dir); + if(!dir){ + //std::cerr<< "TGCHistogramDivision: directory "<<eff_dir<<" not found"<<std::endl; + return; + } + + for(int pt=1;pt<=6;pt++){ + for(int pna=0;pna<3;pna++){ + for(int muid=0;muid<2;muid++){ + for(int pcn=0;pcn<3;pcn++){ + std::string tempeff, tempnum, tempden; + //Efficiency + ss.str(""); + ss << "Trigger_Efficiency" << spna[pna] << sbc[pcn] << "_PT" << pt << smuid[muid] << sac[ac]; + seff = eff_dir + ss.str(); + tempeff = ss.str(); + ss.str(""); + ss << "Trigger_Efficiency" << spna[pna] << sbc[pcn] << "_PT" << pt << smuid[muid] << sac[ac] << "_Numerator"; + snum = eff_dir + "NumDenom/" + ss.str(); + tempnum = ss.str(); + ss.str(""); + ss << "Trigger_Efficiency" << spna[pna] << "_PT" << pt << smuid[muid] << sac[ac] << "_Denominator"; + sden = eff_dir + "NumDenom/" + ss.str(); + tempden = ss.str(); + + h2eff = 0; + mf.get(seff, h2eff); + h2num = 0; + mf.get(snum, h2num); + h2den = 0; + mf.get(sden, h2den); + if(h2eff && h2num && h2den){ + TGCResetContents(h2eff); + h2eff->Divide(h2num, h2den, 1., 1., "B"); + + // save the summary histogram + dir = mf.GetDirectory(eff_dir); + dir->cd(); + h2eff->Write("",TObject::kOverwrite); + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + mf.Write(); + }//pcn + + //Turn on + ss.str(""); + ss << "Trigger_Turn_On_Curve" << spna[pna] << "_PT" << pt << smuid[muid] << sac[ac]; + seff = eff_dir + ss.str(); + ss << "_Fit"; + seffg = eff_dir + ss.str(); + ss.str(""); + ss << "Trigger_Turn_On_Curve" << spna[pna] << "_PT" << pt << smuid[muid] << sac[ac] << "_Numerator"; + snum = eff_dir + "NumDenom/" + ss.str(); + ss.str(""); + ss << "Trigger_Turn_On_Curve" << spna[pna] << "_PT" << pt << smuid[muid] << sac[ac] << "_Denominator"; + sden = eff_dir + "NumDenom/" + ss.str(); + + h1eff = 0; + mf.get(seff, h1eff); + h1num = 0; + mf.get(snum, h1num); + h1den = 0; + mf.get(sden, h1den); + geff = 0; + mf.get(seffg, geff); + + if(h1eff && h1num && h1den){ + TGCResetContents(h1eff); + h1eff->Divide(h1num, h1den, 1., 1., "B"); + + // save the summary histogram + dir = mf.GetDirectory(eff_dir); + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + + if(geff){ + geff->BayesDivide(h1num, h1den); + + // save the summary histogram + dir = mf.GetDirectory(eff_dir); + dir->cd(); + geff->Write("",TObject::kOverwrite); + } + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + mf.Write(); + }//muid + }//pna + mf.Write(); + + //Rate Ratio + TString grate_dir = tgc_global_dir + "Rate/"; + TString rate_dir = tgc_sub_dir[ac] + "Rate/"; + TString rr_dir = tgc_sub_dir[ac] + "Rate/Ratio/"; + dir = mf.GetDirectory(rr_dir); + if(!dir){ + //std::cerr<< "TGCHistogramDivision: directory "<<rr_dir<<" not found"<<std::endl; + return; + } + + // trigger/10BCID + ss.str(""); + ss << "Number_Of_PT" << pt << "_Triggers_Per_Event_Vs_10BCID" << sac[ac]; + seff = rr_dir + ss.str(); + ss.str(""); + ss << "Number_Of_PT" << pt << "_Triggers_In_10BCID" << sac[ac]; + snum = rate_dir + ss.str(); + ss.str(""); + ss << "Number_Of_Events_In_10BCID"; + sden = grate_dir + ss.str(); + + h1eff = 0; + mf.get(seff, h1eff); + h1num = 0; + mf.get(snum, h1num); + h1den = 0; + mf.get(sden, h1den); + + if( h1eff && h1num && h1den){ + TGCResetContents(h1eff); + h1eff->Divide(h1num, h1den); + + // save the summary histogram + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + + //trigger/2LB + ss.str(""); + ss << "Number_Of_PT" << pt << "_Triggers_Per_Event_Vs_2LB" << sac[ac]; + seff = rr_dir + ss.str(); + ss.str(""); + ss << "Number_Of_PT" << pt << "_Triggers_In_2LB" << sac[ac]; + snum = rate_dir + ss.str(); + ss.str(""); + ss << "Number_Of_Events_In_2LB"; + sden = grate_dir + ss.str(); + + h1eff = 0; + mf.get(seff, h1eff); + h1num = 0; + mf.get(snum, h1num); + h1den = 0; + mf.get(sden, h1den); + + if( h1eff && h1num && h1den){ + TGCResetContents(h1eff); + h1eff->Divide(h1num, h1den); + + // save the summary histogram + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + mf.Write(); + + }//pt + + //Rate Ratio + TString grate_dir = tgc_global_dir + "Rate/"; + TString rate_dir = tgc_sub_dir[ac] + "Rate/"; + TString rr_dir = tgc_sub_dir[ac] + "Rate/Ratio/"; + + // trigger/10BCID + ss.str(""); + ss << "Number_Of_SL_Triggers_Per_Event_Vs_10BCID" << sac[ac]; + seff = rr_dir + ss.str(); + ss.str(""); + ss << "Number_Of_SL_Triggers_In_10BCID" << sac[ac]; + snum = rate_dir + ss.str(); + ss.str(""); + ss << "Number_Of_Events_In_10BCID"; + sden = grate_dir + ss.str(); + + h1eff = 0; + mf.get(seff, h1eff); + h1num = 0; + mf.get(snum, h1num); + h1den = 0; + mf.get(sden, h1den); + + if(h1eff && h1num && h1den){ + TGCResetContents(h1eff); + h1eff->Divide(h1num, h1den); + + // save the summary histogram + dir = mf.GetDirectory(rr_dir); + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + + //trigger/2LB + ss.str(""); + ss << "Number_Of_SL_Triggers_Per_Event_Vs_2LB" << sac[ac]; + seff = rr_dir + ss.str(); + ss.str(""); + ss << "Number_Of_SL_Triggers_In_2LB" << sac[ac]; + snum = rate_dir + ss.str(); + ss.str(""); + ss << "Number_Of_Events_In_2LB"; + sden = grate_dir + ss.str(); + + h1eff = 0; + mf.get(seff, h1eff); + h1num = 0; + mf.get(snum, h1num); + h1den = 0; + mf.get(sden, h1den); + + if(h1eff && h1num && h1den){ + TGCResetContents(h1eff); + h1eff->Divide(h1num, h1den); + + // save the summary histogram + dir->cd(); + h1eff->Write("",TObject::kOverwrite); + } + else{ + //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl; + continue; + } + mf.Write(); + }//ac + //====End TGCLV1 + } + + mf.Write(); + } +}//namespace diff --git a/DataQuality/DataQualityUtils/src/StatusFlagCOOL.cxx b/DataQuality/DataQualityUtils/src/StatusFlagCOOL.cxx new file mode 100644 index 0000000000000000000000000000000000000000..76efc30a14b340597147a438bf793960de8687a0 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/StatusFlagCOOL.cxx @@ -0,0 +1,99 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: StatusFlagCOOL.cxx,v 1.6 2009-02-13 12:32:11 ponyisi Exp $ +// ********************************************************************** + +#include "DataQualityUtils/StatusFlagCOOL.h" + +//CORAL API include files +#include "CoralBase/Attribute.h" + +//COOL API include files (CoolKernel) +#include "CoolKernel/IDatabase.h" +#include "CoolKernel/IFolder.h" +#include "CoolKernel/IObjectIterator.h" +#include "CoolKernel/IObject.h" +#include "CoolKernel/Record.h" +#include "CoolKernel/Exception.h" +#include "CoolKernel/IDatabaseSvc.h" +#include "CoolKernel/StorageType.h" + +ClassImp(dqutils::StatusFlagCOOL) + +namespace dqutils{ + +StatusFlagCOOL:: +StatusFlagCOOL (std::string dbStr, std::string folderStr, int runS, int lumiS, int runU, int lumiU) + : StatusFlagCOOLBase(dbStr, folderStr, runS, lumiS, runU, lumiU) +{ +} + +StatusFlagCOOL:: +StatusFlagCOOL (int runS, int lumiS, int runU, int lumiU) + : StatusFlagCOOLBase(runS, lumiS, runU, lumiU) +{ +} + +StatusFlagCOOL:: +StatusFlagCOOL() + : StatusFlagCOOLBase() +{ +} + +cool::RecordSpecification +StatusFlagCOOL:: +createSpec() { + //std::cout << "Preparing RecordSpecification" << std::endl; + cool::RecordSpecification spec; + spec.extend("Code",cool::StorageType::Int32); + spec.extend("deadFrac",cool::StorageType::Float); + spec.extend("Thrust",cool::StorageType::Float); + if (!(spec==coolFolder->payloadSpecification())) { + std::cout << "ERROR Source and destination folder specifications differ." << std::endl; + } + return spec; +} + +coral::AttributeList +StatusFlagCOOL:: +createPayload(int colourCode, float dfrac, float thrust, const cool::RecordSpecification& spec) { + coral::AttributeList payload = cool::Record( spec ).attributeList(); + payload["Code"].data<cool::Int32>() = colourCode; + payload["deadFrac"].data<cool::Float>() = dfrac; + payload["Thrust"].data<cool::Float>() = thrust; + //std::cout << "Creating payload: "; + //std::cout << "[Code : " << colourCode << "],"; + //std::cout << "[DeadFraction : " << dfrac << "],"; + //std::cout << "[Thrust : " << thrust << "]" << std::endl; + return payload; +} + +void +StatusFlagCOOL:: +insert(cool::ChannelId channelId, int code, float dfrac, float thrust, std::string tag_name) { + try { + cool::RecordSpecification spec = this->createSpec(); + coral::AttributeList payload = this->createPayload(code, dfrac, thrust, spec); + //std::cout << "Trying to store payload [channel " << this->getCoolFolder()->channelName(channelId) <<" ("<< channelId <<")]..."; + insert_helper(channelId, payload, tag_name); + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } +} + +void +StatusFlagCOOL:: +insert(std::string channelName, int code, float dfrac, float thrust, std::string tag_name) { + try { + this->insert(this->getCoolFolder()->channelId(channelName), code, dfrac, thrust, tag_name); + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } +} + +} //namespace dqutils diff --git a/DataQuality/DataQualityUtils/src/StatusFlagCOOLBase.cxx b/DataQuality/DataQualityUtils/src/StatusFlagCOOLBase.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d4c10d71bd864b77e3fc26964cf462de81693340 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/StatusFlagCOOLBase.cxx @@ -0,0 +1,210 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: StatusFlagCOOLBase.cxx,v 1.6 2009-02-13 12:32:11 ponyisi Exp $ +// ********************************************************************** + +#include "DataQualityUtils/StatusFlagCOOLBase.h" + +//CORAL API include files +#include "CoralBase/Attribute.h" + +//COOL API include files (CoolKernel) +#include "CoolKernel/IDatabase.h" +#include "CoolKernel/IFolder.h" +#include "CoolKernel/IObjectIterator.h" +#include "CoolKernel/IObject.h" +#include "CoolKernel/Record.h" +#include "CoolKernel/Exception.h" +#include "CoolKernel/IDatabaseSvc.h" +#include "CoolKernel/StorageType.h" + +ClassImp(dqutils::StatusFlagCOOLBase) + +namespace dqutils{ + +cool::IDatabasePtr +StatusFlagCOOLBase:: +coolDbInstance(std::string dbStr, bool readOnly) { + try { + std::cout << "Opening database '" << dbStr << "'..."; + cool::IDatabaseSvc& dbSvc = this->databaseService(); + std::cout << "done." << std::endl; + return dbSvc.openDatabase(dbStr.c_str(), readOnly); + } + catch (cool::DatabaseDoesNotExist&) { + std::cout << "Error! Database does not exist!" << std::endl; + throw; + } +} + +cool::IFolderPtr +StatusFlagCOOLBase:: +coolFolderInstance(std::string folderStr) { + try { + cool::IFolderPtr folder = coolDb->getFolder(folderStr.c_str()); + std::cout << "Browsing objects of '" << folderStr << "'" << std::endl; + //folder->setupStorageBuffer(); + return folder; + } + catch (cool::FolderNotFound& ) { + std::cout << "Error! Folder '" << folderStr << "' does not exist!" << std::endl; + throw; + } +} + +void +StatusFlagCOOLBase:: +setSince(cool::Int64 run, cool::Int64 lumi) { + since = ((run << 32) + lumi); +} + +void +StatusFlagCOOLBase:: +setUntil(cool::Int64 run, cool::Int64 lumi) { + until = ((run << 32) + lumi); +} + +void +StatusFlagCOOLBase:: +setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU) { + this->setSince(runS, lumiS); + this->setUntil(runU, lumiU); + //this->printIOV(); +} + +void +StatusFlagCOOLBase:: +setIOV(cool::Int64 run) { + this->setSince(run, 0); + this->setUntil(run, cool::UInt32Max); + //this->printIOV(); +} + + +void +StatusFlagCOOLBase:: +printIOV(){ + cool::Int64 runS=since>>32; + cool::Int64 lumiS=since-(runS<<32); + cool::Int64 runU=until>>32; + cool::Int64 lumiU=until-(runU<<32); + std::cout << "Using IOVrange [(" << runS << "," << lumiS << "),(" << runU << "," << lumiU << ")[ " << "[" << since << "," << until << "[" << std::endl; +} + +void +StatusFlagCOOLBase:: +flush() { + //coolFolder->flushStorageBuffer(); +} + +void +StatusFlagCOOLBase:: +Initialize(std::string dbStr, std::string folderStr, int runS, int lumiS, int runU, int lumiU) { + coolDb = this->coolDbInstance(dbStr, false); + coolFolder = this->coolFolderInstance(folderStr); + this->setIOV(runS, lumiS, runU, lumiU); +} + + +StatusFlagCOOLBase:: +StatusFlagCOOLBase (std::string dbStr, std::string folderStr, int runS, int lumiS, int runU, int lumiU) { + Initialize(dbStr, folderStr, runS, lumiS, runU, lumiU); +} + +StatusFlagCOOLBase:: +StatusFlagCOOLBase(int runS, int lumiS, int runU, int lumiU) { + Initialize("COOLOFL_GLOBAL/OFLP200", "/GLOBAL/DETSTATUS/SHIFTOFL", + runS, lumiS, runU, lumiU); +} + +StatusFlagCOOLBase:: +StatusFlagCOOLBase() { + Initialize("COOLOFL_GLOBAL/OFLP200", "/GLOBAL/DETSTATUS/SHIFTOFL", + 0, 0, 0, 0); +} + +StatusFlagCOOLBase:: +~StatusFlagCOOLBase () { + //coolFolder->flushStorageBuffer(); + coolDb->closeDatabase(); + std::cout << "Cleared!" << std::endl; +} + +void +StatusFlagCOOLBase:: +dump(cool::ChannelSelection selection, std::string tag_name) { + try { + cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until-1, selection, tag_name); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + std::cout << element << std::endl;; + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } +} + +std::string +StatusFlagCOOLBase:: +dumpField(cool::ChannelId channelId, std::string field, std::string tag_name) { + std::string result =""; + try { + cool::ChannelSelection selection = cool::ChannelSelection(channelId); + cool::IObjectIteratorPtr objects = coolFolder->browseObjects(since, until-1, selection, tag_name); + while (objects->goToNext()) { + const cool::IObject& element = objects->currentRef(); + result = element.payloadValue(field); + } + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } + return result; +} + +int +StatusFlagCOOLBase:: +dumpCode(std::string channelName, std::string tag_name) { + std::string result = this->dumpField(this->getCoolFolder()->channelId(channelName.c_str()), "Code", tag_name); + if (result == "") { + return INT_MAX; + } else { + return atoi(result.c_str()); + } +} + +void +StatusFlagCOOLBase:: +dumpall(std::string tag_name) { + this->dump(cool::ChannelSelection::all(), tag_name); +} + +void +StatusFlagCOOLBase:: +insert_helper(cool::ChannelId channelId, coral::AttributeList& payload, + std::string& tag_name) { + if (tag_name=="HEAD") { + coolFolder->storeObject(since, until, payload, channelId); + } else { + coolFolder->storeObject(since, until, payload, channelId, tag_name, true); + } +} + +cool::IFolderPtr +StatusFlagCOOLBase:: +getCoolFolder() { + return this->coolFolder; +} + +cool::IDatabasePtr +StatusFlagCOOLBase:: +getCoolDb() { + return this->coolDb; +} + + +} //namespace dqutils diff --git a/DataQuality/DataQualityUtils/src/StatusFlagCommentCOOL.cxx b/DataQuality/DataQualityUtils/src/StatusFlagCommentCOOL.cxx new file mode 100644 index 0000000000000000000000000000000000000000..363cf2a61dc90f2da10e2b5a01b818259e231b2b --- /dev/null +++ b/DataQuality/DataQualityUtils/src/StatusFlagCommentCOOL.cxx @@ -0,0 +1,97 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: StatusFlagCommentCOOL.cxx,v 1.6 2009-02-13 12:32:11 ponyisi Exp $ +// ********************************************************************** + +#include "DataQualityUtils/StatusFlagCommentCOOL.h" + +//CORAL API include files +#include "CoralBase/Attribute.h" + +//COOL API include files (CoolKernel) +#include "CoolKernel/IDatabase.h" +#include "CoolKernel/IFolder.h" +#include "CoolKernel/IObjectIterator.h" +#include "CoolKernel/IObject.h" +#include "CoolKernel/Record.h" +#include "CoolKernel/Exception.h" +#include "CoolKernel/IDatabaseSvc.h" +#include "CoolKernel/StorageType.h" + +ClassImp(dqutils::StatusFlagCommentCOOL) + +namespace dqutils{ + +StatusFlagCommentCOOL:: +StatusFlagCommentCOOL(std::string dbStr, std::string folderStr, int runS, int lumiS, int runU, int lumiU) + : StatusFlagCOOLBase(dbStr, folderStr, runS, lumiS, runU, lumiU) +{ +} + +StatusFlagCommentCOOL:: +StatusFlagCommentCOOL(int runS, int lumiS, int runU, int lumiU) + : StatusFlagCOOLBase(runS, lumiS, runU, lumiU) +{ +} + +StatusFlagCommentCOOL:: +StatusFlagCommentCOOL() + : StatusFlagCOOLBase() +{ +} + +cool::RecordSpecification +StatusFlagCommentCOOL:: +createSpec() { + //std::cout << "Preparing RecordSpecification" << std::endl; + cool::RecordSpecification spec; + spec.extend("Code",cool::StorageType::Int32); + spec.extend("deadFrac",cool::StorageType::Float); + spec.extend("Thrust",cool::StorageType::Float); + spec.extend("Comment",cool::StorageType::String255); + if (!(spec==coolFolder->payloadSpecification())) { + std::cout << "ERROR Source and destination folder specifications differ." << std::endl; + } + return spec; +} + +coral::AttributeList +StatusFlagCommentCOOL:: +createPayload(int colourCode, float dfrac, float thrust, std::string& comment, const cool::RecordSpecification& spec) { + coral::AttributeList payload = cool::Record( spec ).attributeList(); + payload["Code"].data<cool::Int32>() = colourCode; + payload["deadFrac"].data<cool::Float>() = dfrac; + payload["Thrust"].data<cool::Float>() = thrust; + payload["Comment"].data<cool::String255>() = comment; + return payload; +} + + +void +StatusFlagCommentCOOL:: +insert(cool::ChannelId channelId, int code, float dfrac, float thrust, std::string comment, std::string tag_name) { + try { + cool::RecordSpecification spec = this->createSpec(); + coral::AttributeList payload = this->createPayload(code, dfrac, thrust, comment, spec); + insert_helper(channelId, payload, tag_name); + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } +} + +void +StatusFlagCommentCOOL:: +insert(std::string channelName, int code, float dfrac, float thrust, std::string comment, std::string tag_name) { + try { + this->insert(this->getCoolFolder()->channelId(channelName), code, dfrac, thrust, comment, tag_name); + } + catch (cool::Exception& e) { + std::cout << "Unknown exception caught!" << e.what() << std::endl; + } +} + +} //namespace dqutils diff --git a/DataQuality/DataQualityUtils/src/han_results_print.cxx b/DataQuality/DataQualityUtils/src/han_results_print.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a450f3e0d2d8076bbb000c421d803be53426eb31 --- /dev/null +++ b/DataQuality/DataQualityUtils/src/han_results_print.cxx @@ -0,0 +1,80 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * $Id: han_results_print.cxx,v 1.2 2009-02-11 10:42:13 ponyisi Exp $ + */ + +#include <iostream> +#include <string> +#include <cstdlib> + +#include "DataQualityUtils/HanOutputFile.h" + + +namespace { + +void usage( const std::string& command_name, int exit_code ); + +class CmdLineArgs { +public: + CmdLineArgs( int argc, char *argv[] ); + + std::string command; + std::string hresults; +}; + +} // unnamed namespace + + + +int main( int argc, char *argv[] ) +{ + CmdLineArgs arg( argc, argv ); + + std::string resultsName( arg.hresults ); + + dqutils::HanOutputFile of(resultsName); + of.printAllDQAssessments(); + + return 0; +} + + +// ************************************************************ +// Private Functions +// ************************************************************ + +namespace { + +void usage( const std::string& command_name, int exit_code ) +{ + std::string message; + message += "\n"; + message += "This program takes as an argument the name of a \'han\' results\n"; + message += "file and prints the statuses of all assessments to stdout.\n"; + + std::string::size_type s = command_name.size(); + std::string::size_type p = command_name.rfind( '/', s ); + std::string short_name = command_name.substr( p+1, s ); + + std::cout << "\n"; + std::cout << "Usage: " << short_name << " <results_file>\n"; + std::cout << message << "\n"; + exit(exit_code); +} + + +CmdLineArgs:: +CmdLineArgs( int argc, char *argv[] ) +{ + command = argv[0]; + if( argc > 2 ) usage( command, 1 ); + if( argc < 2 ) usage( command, 0 ); + + hresults = argv[1]; +} + +} // unnamed namespace +