diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValBackgroundStudy.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValBackgroundStudy.h new file mode 100644 index 0000000000000000000000000000000000000000..57693c5bccb9f81d85a7f989153e0c53ef4a90f6 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValBackgroundStudy.h @@ -0,0 +1,123 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPVALBACKGROUNDSTUDY_H_ +#define _TTPVALBACKGROUNDSTUDY_H_ + +#include "TTree.h" +#include "TChain.h" +#include "TCanvas.h" +#include "TStyle.h" +#include "TROOT.h" +#include "TFile.h" +#include "TH2.h" +#include "TLegend.h" +#include "TLatex.h" +#include "TPostScript.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +using namespace std; + + +class TTPValBackgroundStudy { + +private: + TString filename; + bool fileDefined; + TChain * chain; + int type; + bool debug, invertL2; + TrigTauFlags::TRIGGERMENU menu; + TrigTauFlags::HLTAUTHOR chainType; + TrigTauSelectionManager::CUTLEVEL cutLevel; + TrigTauMCTauList::OFFLINESELECTION offlineType; + TrigTauSelectionManager::MENUVERSION menuVersion; + bool signal; + int nprong; + float maxVisEta, minLeadingPt; + TrigTauAnalyzer analyzer; + TrigTauSelectionManager selmanager; + vector<TString> hnames; + unsigned int nL1Cuts; + unsigned int nL2CaloCuts; + unsigned int nL2TrkCuts; + unsigned int nEFCuts; + unsigned int nHistos; + unsigned int nNames; + TH1F * hTot[3]; + static const unsigned int nHistograms =96; + TH1F * histograms[nHistograms]; + TH1F * effHistograms[nHistograms]; + unsigned int passedCounter[nHistograms]; + TH2F * testHisto[2]; + unsigned long l1Word[100]; + unsigned long l2CaloWord[100]; + unsigned long l2TrkWord[100]; + unsigned long l2Word[100]; + unsigned long efWord[100]; + TrigTauBugFix bugfix; + TrigTauEvent* event; + int nev, testing; + bool fillHisto[nHistograms]; + int totalPassed; + + void analyzeEvent(int eventNumber); + TH1F * getEffHist(TH1F * hTot1, TH1F * hCut1, TString name); + void createHistograms(TH1F ** histos); + void initialize(bool debug1 = false, bool invertL21 = false); + void createEffHistograms(); + void ATLAS_LABEL(Double_t x,Double_t y,Color_t color=1); + TString getName(TrigTauMCTauList::OFFLINESELECTION offlineType1); + +public: + + TTPValBackgroundStudy(bool invertL21 = false, TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + TTPValBackgroundStudy (TString filename1 , bool invertL21 = false, TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + + void analyze(); + void print(float lum = 0, float xsection = 0); //prints under ntuple.eps + void print(TString name, float lum = 0, float xsectioni = 0); + void save(); + void save(TString name); //saves under trigtau.ntuple.root + void compare(TString reference, TString saveName); + void compare(TString reference1, TString reference2, TString saveName); + void compare(TString reference); //saves under ntuple.eps + void update(TString name); //updates a root file with all histograms + void reset(); + + void setFile( TString filename1 ); + void setDebug(bool newValue) { debug = newValue; }; + void setType ( int newValue) { type = newValue; }; + void setNprong (int newValue) { nprong = newValue; }; + void setMenu (TrigTauFlags::TRIGGERMENU newValue) { menu = newValue; }; + void setOfflineType (TrigTauMCTauList::OFFLINESELECTION newValue) {offlineType = newValue;}; + void setCutLevel ( TrigTauSelectionManager::CUTLEVEL newValue) { cutLevel = newValue; }; + void setMaxVisEta (float newValue ) { maxVisEta = newValue; }; + void setMinLeadingPt (float newValue ) { minLeadingPt = newValue; }; + void setMenuVersion (TrigTauSelectionManager::MENUVERSION newValue ) { menuVersion = newValue;}; + void setSignal (bool newValue) {signal = newValue; }; + void setChainType (TrigTauFlags::HLTAUTHOR newValue) { chainType = newValue; }; + void setInvertL2 (bool newValue) {invertL2 = newValue;}; + + bool getDebug () { return debug; }; + int getType () { return type; }; + int getNprong () { return nprong; }; + TrigTauFlags::TRIGGERMENU getMenu () { return menu; }; + TrigTauMCTauList::OFFLINESELECTION getOfflineType () { return offlineType; }; + TrigTauSelectionManager::CUTLEVEL getCutLevel () { return cutLevel; }; + float getMaxVisEta() { return maxVisEta; }; + float getMinLeadingPt() { return minLeadingPt; }; + TrigTauSelectionManager::MENUVERSION getMenuVersion() { return menuVersion; }; + bool getSignal () {return signal; }; + bool getInvertL2 () {return invertL2;}; + TrigTauFlags::HLTAUTHOR getChainType() { return chainType;}; + + + +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValCosmicPlots.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValCosmicPlots.h new file mode 100644 index 0000000000000000000000000000000000000000..85a4f94386b3b75e956d10dcc3d3a6e1dd17a187 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValCosmicPlots.h @@ -0,0 +1,152 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TTPVALCOSMICPLOTS_H_ +#define TTPVALCOSMICPLOTS_H_ +// +// Class to make lots of plots of lots of trigger variables +// Eric Torrence +// +// Use the PLOTTYPE to instantiate different plot progressions +// DEFAULT: 6 plots showing L1 In, L1 Out, L2Cal Out, L2Trk Out, EF Out, Reco +// RECO_BASED: 4 plots showing Reco, L1 Out, L2 Out, EF Out +// +// See example in macros/makeCosmicPlots.cxx +// +#include "TString.h" +#include "TTree.h" + +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauHistHelper.h" + +#include "TrigTauPerformValidation/TrigTauCounter.h" + +class TTPValCosmicPlots { + public: + + // Selector to choose type of plots to generate + enum PLOTTYPE { + DEFAULT, // Standard plots starting with L1 ROIs + RECO_BASED // Start with reco taus + }; + + TTPValCosmicPlots(TTPValCosmicPlots::PLOTTYPE type = TTPValCosmicPlots::DEFAULT); + virtual ~TTPValCosmicPlots(); + + // Functions to define selectors + void setDefaultVersion(TrigTauSelectionManager::MENUVERSION version); + void setSelector(TrigTauFlags::TRIGGERMENU menu); + + void setHLTAuthorType(TrigTauFlags::HLTAUTHOR type) {_hltAuthorType = type;} + + // Return pointer to selector (useful for making changes) + TrigTauSelectionManager* getSelector() {return _selManager;} + + // Additional selections to help with cosmic samples + void requireMinL2EmEt(float Et); // Energy in MeV + void requireMaxL2EmEt(float Et); // Energy in MeV + + void requireAnyL2Negative(bool val=true) {_requireAnyL2Negative = val;} + void setL2NegativeThreshold(float threshold) {_L2NegThreshold = threshold;} + + // Require offline (m_accept & bitmask) to be non-zero + void requireRecoMask(long bitmask) {_requireRecoMask = bitmask;} + + // Require offline seed type (seed & seedmask) to be non-zero (1-calo, 2-trk) + void requireSeedType(long seedmask) {_requireSeedMask = seedmask;} + + void clear(); // Delete everything and recreate + void reset(); // Sets everything to zero + + void fill(const TString& filename, double wt=1.); + void fill(TTree* tree); + + void draw(const TString& outfile); + void drawEff(const TString& outfile); + + void write(const TString& outfile) {if (hh != 0) hh->writeAll(outfile);} + + // Lower level routines + void setCurrentWeight(double weight) {_currentWeight = weight;} + void defineTH(float tlo, float thi); + void setTHBins(unsigned long bins) {_thbins=bins;} + + // void setTHRange(const TString& filename); + + // Allow access to be able to change plot definitions if desired + TrigTauHistHelper* hh; + + // Set energy ranges and binning for Et plots + void setL1EtBins(unsigned int nBins, float xLo, float xHi); + void setL2EtBins(unsigned int nBins, float xLo, float xHi); + void setEFEtBins(unsigned int nBins, float xLo, float xHi); + // Reco plots use EF binning + + void setEtaBins(unsigned int nBins, float xLo, float xHi); + void setPhiBins(unsigned int nBins, float xLo, float xHi); + + private: + + TTPValCosmicPlots::PLOTTYPE _plotType; + + double _currentWeight; + TrigTauSelectionManager::MENUVERSION _defVersion; + TrigTauSelectionManager* _selManager; + TrigTauCounter _nEvent; + TrigTauBugFix _fix; + + float _minL2EmEt; + float _maxL2EmEt; + + bool _requireAnyL2Negative; + float _L2NegThreshold; + + unsigned long _requireRecoMask; + unsigned long _requireSeedMask; + + // Time History information + unsigned long _thbins; + float _thstart; // Starting time (in hours) + float _thend; // Ending time (in hours) + + // L1 energy plots + unsigned int _nL1E; + float _loL1E; + float _hiL1E; + + // L2 energy plots + unsigned int _nL2E; + float _loL2E; + float _hiL2E; + + // EF energy plots + unsigned int _nEFE; + float _loEFE; + float _hiEFE; + + // Eta/phi binning + unsigned int _nEta; + float _loEta; + float _hiEta; + + unsigned int _nPhi; + float _loPhi; + float _hiPhi; + + TrigTauFlags::HLTAUTHOR _hltAuthorType; + + void fillRoiHist(const TrigTauEvent* ev, + const TrigTauTrigChain& ch, + unsigned int type, + double wt); + + bool passedExtraL2(const TrigTauTrigChain& ch); + + void fillDefault(TTree* tree, TrigTauEvent* event); + void fillReco(TTree* tree, TrigTauEvent* event); +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValCutStudy.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValCutStudy.h new file mode 100644 index 0000000000000000000000000000000000000000..d3e9a623127dc9c8d2fbd22236d6bca42caa0904 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValCutStudy.h @@ -0,0 +1,120 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPVALCUTSTUDY_H_ +#define _TTPVALCUTSTUDY_H_ + +#include "TTree.h" +#include "TChain.h" +#include "TCanvas.h" +#include "TStyle.h" +#include "TROOT.h" +#include "TFile.h" +#include "TH2.h" +#include "TLegend.h" +#include "TLatex.h" +#include "TPostScript.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +using namespace std; + + +class TTPValCutStudy { + +private: + TString filename; + bool fileDefined; + TChain * chain; + int type; + bool debug; + TrigTauFlags::TRIGGERMENU menu; + TrigTauFlags::HLTAUTHOR chainType; + TrigTauSelectionManager::CUTLEVEL cutLevel; + TrigTauMCTauList::OFFLINESELECTION offlineType; + TrigTauSelectionManager::MENUVERSION menuVersion; + bool signal; + int nprong; + float maxVisEta, minLeadingPt; + TrigTauAnalyzer analyzer; + TrigTauSelectionManager selmanager; + vector<TString> hnames; + unsigned int nL1Cuts; + unsigned int nL2CaloCuts; + unsigned int nL2TrkCuts; + unsigned int nEFCuts; + unsigned int nHistos; + unsigned int nNames; + TH1F * hTot[3]; + static const unsigned int nHistograms =96; + TH1F * histograms[nHistograms]; + TH1F * effHistograms[nHistograms]; + TH2F * testHisto[2]; + unsigned long l1Word[100]; + unsigned long l2CaloWord[100]; + unsigned long l2TrkWord[100]; + unsigned long l2Word[100]; + unsigned long efWord[100]; + TrigTauBugFix bugfix; + TrigTauEvent* event; + + void analyzeEvent(int eventNumber); + TH1F * getEffHist(TH1F * hTot1, TH1F * hCut1, TString name); + void createHistograms(TH1F ** histos); + void initialize(bool debug1 = false); + void createEffHistograms(); + void ATLAS_LABEL(Double_t x,Double_t y,Color_t color=1); + TString getName(TrigTauMCTauList::OFFLINESELECTION offlineType1); + +public: + + TTPValCutStudy(TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + TTPValCutStudy (TString filename1 , TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + + void analyze(); + void print(); //prints under ntuple.eps + void print(TString name); + void save(); + void save(TString name); //saves under trigtau.ntuple.root + void compare(TString reference, TString saveName); + void compare(TString reference1, TString reference2, TString saveName); + void compare(TString reference); //saves under ntuple.eps + void update(TString name); //updates a root file with all histograms + void effSequencePlotsUpdate(TString name); //prints L1, L2, EF turn on curves in one plot; former macro effSequencePlot2.cxx + void effSequencePlotsPrintCSC(TPostScript & ps); + void reset(); + + void setFile( TString filename1 ); + void setDebug(bool newValue) { debug = newValue; }; + void setType ( int newValue) { type = newValue; }; + void setNprong (int newValue) { nprong = newValue; }; + void setMenu (TrigTauFlags::TRIGGERMENU newValue) { menu = newValue; }; + void setOfflineType (TrigTauMCTauList::OFFLINESELECTION newValue) {offlineType = newValue;}; + void setCutLevel ( TrigTauSelectionManager::CUTLEVEL newValue) { cutLevel = newValue; }; + void setMaxVisEta (float newValue ) { maxVisEta = newValue; }; + void setMinLeadingPt (float newValue ) { minLeadingPt = newValue; }; + void setMenuVersion (TrigTauSelectionManager::MENUVERSION newValue ) { menuVersion = newValue;}; + void setSignal (bool newValue) {signal = newValue; }; + void setChainType (TrigTauFlags::HLTAUTHOR newValue) { chainType = newValue; }; + + + bool getDebug () { return debug; }; + int getType () { return type; }; + int getNprong () { return nprong; }; + TrigTauFlags::TRIGGERMENU getMenu () { return menu; }; + TrigTauMCTauList::OFFLINESELECTION getOfflineType () { return offlineType; }; + TrigTauSelectionManager::CUTLEVEL getCutLevel () { return cutLevel; }; + float getMaxVisEta() { return maxVisEta; }; + float getMinLeadingPt() { return minLeadingPt; }; + TrigTauSelectionManager::MENUVERSION getMenuVersion() { return menuVersion; }; + bool getSignal () {return signal; }; + TrigTauFlags::HLTAUTHOR getChainType() { return chainType;}; + + + +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValDistribution.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValDistribution.h new file mode 100644 index 0000000000000000000000000000000000000000..98bc9182ceefa5bc14358da8e705dd06e33d297b --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValDistribution.h @@ -0,0 +1,101 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPVALDISTRIBUTION_H_ +#define _TTPVALDISTRIBUTION_H_ + +#include "TTree.h" +#include "TChain.h" +#include "TCanvas.h" +#include "TStyle.h" +#include "TROOT.h" +#include "TFile.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +//#include "TrigTauPerformAnalysis/TrigTauL2TrkFEX.h" +#include <string> +using namespace std; + + +class TTPValDistribution { + +private: + string filename; + bool fileDefined; + bool selected; + bool logScale; + bool plotAllMatchedEvents; + bool ignoreMatching; + TChain * chain; + bool debug; + TrigTauFlags::TRIGGERMENU menu; + TrigTauSelectionManager::CUTLEVEL cutLevel; + TrigTauMCTauList::OFFLINESELECTION offlineType; + TrigTauSelectionManager::MENUVERSION menuVersion; + TrigTauFlags::HLTAUTHOR chainType; + bool signal; + float maxVisEta, minLeadingPt; + TrigTauAnalyzer analyzer[3]; + TrigTauSelectionManager selmanager; + vector<TString> hnames; + static const unsigned int nHistograms =96; + TH1F * histograms[nHistograms]; + TrigTauBugFix bugfix; + TrigTauEvent* event; + unsigned int nL1Cuts; + unsigned int nL2CaloCuts; + unsigned int nL2TrkCuts; + unsigned int nEFCuts; + unsigned int nHistos; + unsigned int nNames; + + void analyzeEvent(int eventNumber); + void createHistograms(TH1F ** histos); + void initialize(bool debug1 = false); + +public: + + TTPValDistribution(TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + TTPValDistribution ( const char * filename1 , TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + + void analyze(int number = 10000000); + void print(); + void save(const char * name = "histo.root"); + void compare(const char * reference, const char * output = "ntuple.eps"); + void compare(const char * reference1, const char* reference2, const char * output); + void update(const char * name); + + void setFile( const char * filename1 ); + void setDebug(bool newValue) { debug = newValue; }; + void setMenu (TrigTauFlags::TRIGGERMENU newValue) { menu = newValue; }; + void setOfflineType (TrigTauMCTauList::OFFLINESELECTION newValue) {offlineType = newValue;}; + void setCutLevel ( TrigTauSelectionManager::CUTLEVEL newValue) { cutLevel = newValue; }; + void setMaxVisEta ( float newValue ) { maxVisEta = newValue; }; + void setMinLeadingPt (float newValue ) { minLeadingPt = newValue; }; + void setSelection ( bool newValue ) { selected = newValue; }; //selected turns on cuts for histograms to not plot extrem values + void setLogScale ( bool newValue) { logScale = newValue; }; + void setMenuVersion (TrigTauSelectionManager::MENUVERSION newValue ) { menuVersion = newValue;}; + void setPlotAllMatchedEvents (bool newValue) { plotAllMatchedEvents = newValue; }; + void setPlotAllEvents (bool newValue); + void setChainType (TrigTauFlags::HLTAUTHOR newValue) { chainType = newValue; }; + + bool getDebug () { return debug; }; + TrigTauFlags::TRIGGERMENU getMenu () { return menu; }; + TrigTauMCTauList::OFFLINESELECTION getOfflineType () { return offlineType; }; + TrigTauSelectionManager::CUTLEVEL getCutLevel () { return cutLevel; }; + float getMaxVisEta() { return maxVisEta; }; + float getMinLeadingPt() { return minLeadingPt; }; + bool getSelection() { return selected; }; + bool getLogScale() { return logScale; }; + TrigTauSelectionManager::MENUVERSION getMenuVersion() { return menuVersion; }; + bool getPlotAllMatchedEvents () { return plotAllMatchedEvents; }; + bool getIgnoreMatching () { return ignoreMatching; }; + TrigTauFlags::HLTAUTHOR getChainType() { return chainType;}; + +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValEffTableMaker.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValEffTableMaker.h new file mode 100644 index 0000000000000000000000000000000000000000..1e6094fa56c89cc4e4ed6f309de8b081d8252762 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValEffTableMaker.h @@ -0,0 +1,85 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPVALEFFTABLEMAKER_H_ +#define _TTPVALEFFTABLEMAKER_H_ + +#include "TTree.h" +#include "TChain.h" +#include "TFile.h" +#include "TCanvas.h" +#include "TROOT.h" +#include "TPostScript.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" + + +class TTPValEffTableMaker { + +private: + + TString filename; + bool filenameSet; + TrigTauSelectionManager selmanager; + TrigTauFlags::TRIGGERMENU menu; + TrigTauFlags::HLTAUTHOR chainType; + TrigTauSelectionManager::CUTLEVEL cutLevel; + TrigTauSelectionManager::MENUVERSION menuVersion; + bool signal, debug; + TChain * tree; + float maxVisEta, minLeadingPt; + int nev; + TrigTauBugFix bugfix; + + // TAU1P3P, TAUREC, EITHERTAU, BOTHTAU //, NONE + TrigTauMCTauList::OFFLINESELECTION offlineType[11]; + + static const unsigned int nMatching = 11; // nMatching: TAU1P3P, TAUREC, EITHERTAU, BOTHTAU, NONE + static const unsigned int nProngType = 3; // nProngType: 1Pr, 3Pr, all + +//counter with index: [matching][prong-type][passed l1, l2Calo, L2trk, EF ,tot] + unsigned int counter[nMatching][nProngType][5]; + TrigTauAnalyzer analyzer[nMatching][nProngType]; + + void initialize (bool debug1 = false); + bool analyzeEvent (TrigTauEvent * event, TrigTauMCTauList::OFFLINESELECTION offlineType, int i, int j); + +public: + + TTPValEffTableMaker( TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + TTPValEffTableMaker( TString filename1, TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + + void analyze(); + void print( int which = 1 ); //0 prints absolute efficiencies, 1 prints relative efficiencies + void printCSC (TPostScript & ps, bool relEff = true); + void update ( TString filename, bool relEff = true); + + void setFile ( TString filename1 ); + void setChain ( TChain * tree1); + void setSignal ( bool signal1 ) { signal = signal1; }; + void setDebug ( bool debug1 ) { debug = debug1; }; + void setMaxVisEta (float eta ) { maxVisEta = eta; } + void setMinLeadingPt (float pt ) { minLeadingPt = pt; }; + void setMenu ( TrigTauFlags::TRIGGERMENU newValue ) {menu = newValue; }; + void setCutLevel (TrigTauSelectionManager::CUTLEVEL newValue ) {cutLevel = newValue; }; + void setMenuVersion (TrigTauSelectionManager::MENUVERSION newValue ) { menuVersion = newValue;}; + void setChainType (TrigTauFlags::HLTAUTHOR newValue) { chainType = newValue; }; + + TString getFile() { return filename; }; + TChain * getChain() { return tree; }; + bool getSignal() { return signal; }; + bool getDebug() { return debug; }; + float getMaxVisEta() { return maxVisEta; }; + float getMinLeadingPt() { return minLeadingPt; }; + TrigTauFlags::TRIGGERMENU getMenu() { return menu; }; + TrigTauSelectionManager::CUTLEVEL getCutLevel() { return cutLevel; }; + TrigTauSelectionManager::MENUVERSION getMenuVersion() { return menuVersion; }; + TrigTauFlags::HLTAUTHOR getChainType() { return chainType;}; +}; + + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValLevelCut.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValLevelCut.h new file mode 100644 index 0000000000000000000000000000000000000000..25e66be27486483cba8ef89945ee07f16f894c5d --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValLevelCut.h @@ -0,0 +1,129 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPVALLEVELCUT_H_ +#define _TTPVALLEVELCUT_H_ + +#include "TTree.h" +#include "TChain.h" +#include "TCanvas.h" +#include "TStyle.h" +#include "TROOT.h" +#include "TFile.h" +#include "TH2.h" +#include "TLegend.h" +#include "TLatex.h" +#include "TPostScript.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +using namespace std; + + +class TTPValLevelCut { + +private: + static const unsigned int nCutLevels = 3; + TString filename; + bool fileDefined; + TChain * chain; + bool debug; + TrigTauFlags::TRIGGERMENU menu; + TrigTauFlags::HLTAUTHOR chainType; + TrigTauSelectionManager::CUTLEVEL theCutLevel[nCutLevels]; + TrigTauMCTauList::OFFLINESELECTION offlineType; + TrigTauSelectionManager::MENUVERSION menuVersion; + bool signal; + int nprong; + float maxVisEta, minLeadingPt; + TrigTauAnalyzer analyzer; + TrigTauSelectionManager selmanager; + TrigTauBugFix bugfix; + TrigTauEvent* event; + unsigned int nTau; + int npt; + float minpt; + float maxpt; + int color[nCutLevels]; + int style[nCutLevels]; + float Threshold; + TString test[nCutLevels]; + TH1F* hMC_InVisPt; + TH1F* hMCVisPt; //MC Pt dist (denominator) + TH1F* hL1VisPt[nCutLevels]; // L1 selected (numerator) + TH1F* hL2VisPt[nCutLevels]; // L2 selected (numerator) + TH1F* hEFVisPt[nCutLevels]; // EF selected (numerator) + TH1F* hL1PtEff[nCutLevels]; // L1 efficiency (result) + TH1F* hL2PtEff[nCutLevels]; // L2 efficiency (result) + TH1F* hEFPtEff[nCutLevels]; // EF efficiency (result) + TH1F* hntrak; + + TH1F* hMC_InVisEta; + TH1F* hMCVisEta; //MC Pt dist (denominator) + TH1F* hL1VisEta[nCutLevels]; // L1 selected (numerator) + TH1F* hL2VisEta[nCutLevels]; // L2 selected (numerator) + TH1F* hEFVisEta[nCutLevels]; // EF selected (numerator) + TH1F* hL1EtaEff[nCutLevels]; // L1 efficiency (result) + TH1F* hL2EtaEff[nCutLevels]; // L2 efficiency (result) + TH1F* hEFEtaEff[nCutLevels]; // EF efficiency (result) + + int nMatch[nCutLevels]; + int nL1passed[nCutLevels]; + int nL2passed[nCutLevels]; + int nEFpassed[nCutLevels]; + int n_OfflineMatchEvent[nCutLevels]; + int n_L1MatchEvent[nCutLevels]; + int n_L2MatchEvent[nCutLevels]; + int n_EFMatchEvent[nCutLevels]; + + int nEvent; + int nTrue; + int nGood; + int nMatched; + + void ATLAS_LABEL(Double_t x,Double_t y,Color_t color=1); + void initialize(bool debug1 = false); + void analyzeEvent(int eventNumber); + + +public: + + TTPValLevelCut(TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + + TTPValLevelCut( TString filename1 , TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + void analyze(); + void print(); + void update(TString name); + void printCSC(TPostScript & ps); + + void setFile( TString filename1 ); + void setDebug(bool newValue) { debug = newValue; }; + void setNprong (int newValue) { nprong = newValue; }; + void setMenu (TrigTauFlags::TRIGGERMENU newValue) { menu = newValue; }; + void setOfflineType (TrigTauMCTauList::OFFLINESELECTION newValue) {offlineType = newValue;}; + //void setCutLevel ( TrigTauSelectionManager::CUTLEVEL newValue) { cutLevel = newValue; }; + void setMaxVisEta (float newValue ) { maxVisEta = newValue; }; + void setMinLeadingPt (float newValue ) { minLeadingPt = newValue; }; + void setMenuVersion (TrigTauSelectionManager::MENUVERSION newValue ) { menuVersion = newValue;}; + void setSignal (bool newValue) {signal = newValue; }; + void setChainType (TrigTauFlags::HLTAUTHOR newValue) { chainType = newValue; }; + + + bool getDebug () { return debug; }; + int getNprong () { return nprong; }; + TrigTauFlags::TRIGGERMENU getMenu () { return menu; }; + TrigTauMCTauList::OFFLINESELECTION getOfflineType () { return offlineType; }; + //TrigTauSelectionManager::CUTLEVEL getCutLevel () { return cutLevel; }; + float getMaxVisEta() { return maxVisEta; }; + float getMinLeadingPt() { return minLeadingPt; }; + TrigTauSelectionManager::MENUVERSION getMenuVersion() { return menuVersion; }; + bool getSignal () {return signal; }; + TrigTauFlags::HLTAUTHOR getChainType() { return chainType;}; + + + +}; +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValMultiPlots.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValMultiPlots.h new file mode 100644 index 0000000000000000000000000000000000000000..862457e447a5ccbe355734e7d2cc8b5ca3ca1345 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValMultiPlots.h @@ -0,0 +1,137 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPVALMULTIPLOTS_H_ +#define _TTPVALMULTIPLOTS_H_ + +#include "TTree.h" +#include "TChain.h" +#include "TCanvas.h" +#include "TStyle.h" +#include "TROOT.h" +#include "TFile.h" +#include "TH2.h" +#include "TLegend.h" +#include "TLatex.h" +#include "TPostScript.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +using namespace std; + + +class TTPValMultiPlots { + +private: + TString filename; + bool fileDefined; + TChain * chain; + bool debug; + TrigTauFlags::TRIGGERMENU menu; + TrigTauFlags::HLTAUTHOR chainType; + TrigTauSelectionManager::CUTLEVEL cutLevel; + TrigTauMCTauList::OFFLINESELECTION offlineType; + TrigTauSelectionManager::MENUVERSION menuVersion; + bool signal; + int nprong; + float maxVisEta, minLeadingPt; + TrigTauAnalyzer analyzer; + TrigTauSelectionManager selmanager; + TrigTauBugFix bugfix; + TrigTauEvent* event; + unsigned int nTau; + int npt; + float minpt; + float maxpt; + static const unsigned int nMenus = 7; + int color[nMenus]; + int style[nMenus]; + TrigTauFlags::TRIGGERMENU theMenu[nMenus]; + float Threshold[nMenus]; + TString test[nMenus]; + TH1F* hMC_InVisPt; + TH1F* hMCVisPt; + TH1F* hL1VisPt[nMenus]; // L1 selected (numerator) + TH1F* hL2VisPt[nMenus]; // L2 selected (numerator) + TH1F* hEFVisPt[nMenus]; // EF selected (numerator) + TH1F* hL1PtEff[nMenus]; + TH1F* hL2PtEff[nMenus]; + TH1F* hEFPtEff[nMenus]; + TH1F* hntrak; + TH1F* hEFnTracks[nMenus]; + + TH1F* hL21PtEff[nMenus]; + TH1F* hEFL2PtEff[nMenus]; + + TH1F* hMC_InVisEta; + TH1F* hMCVisEta; + TH1F* hL1VisEta[nMenus]; + TH1F* hL2VisEta[nMenus]; + TH1F* hEFVisEta[nMenus]; + TH1F* hL1EtaEff[nMenus]; + TH1F* hL2EtaEff[nMenus]; + TH1F* hEFEtaEff[nMenus]; + + TH1F* hL21EtaEff[nMenus]; + TH1F* hEFL2EtaEff[nMenus]; + + int nMatch[nMenus]; + int nL1passed[nMenus]; + int nL2passed[nMenus]; + int nEFpassed[nMenus]; + int n_OfflineMatchEvent[nMenus]; + int n_L1MatchEvent[nMenus]; + int n_L2MatchEvent[nMenus]; + int n_EFMatchEvent[nMenus]; + + int nEvent; + int nTrue; + int nGood; + int nMatched; + + void ATLAS_LABEL(Double_t x,Double_t y,Color_t color=1); + void initialize(bool debug1 = false); + void analyzeEvent(int eventNumber); + + +public: + + TTPValMultiPlots (TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + + TTPValMultiPlots ( TString filename1 , TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + void analyze(); + void print(); + void update(TString name); + void printCSC(TPostScript & ps); + + void setFile( TString filename1 ); + void setDebug(bool newValue) { debug = newValue; }; + void setNprong (int newValue) { nprong = newValue; }; + void setMenu (TrigTauFlags::TRIGGERMENU newValue) { menu = newValue; }; + void setOfflineType (TrigTauMCTauList::OFFLINESELECTION newValue) {offlineType = newValue;}; + void setCutLevel ( TrigTauSelectionManager::CUTLEVEL newValue) { cutLevel = newValue; }; + void setMaxVisEta (float newValue ) { maxVisEta = newValue; }; + void setMinLeadingPt (float newValue ) { minLeadingPt = newValue; }; + void setMenuVersion (TrigTauSelectionManager::MENUVERSION newValue ) { menuVersion = newValue;}; + void setSignal (bool newValue) {signal = newValue; }; + void setChainType (TrigTauFlags::HLTAUTHOR newValue) { chainType = newValue; }; + + + bool getDebug () { return debug; }; + int getNprong () { return nprong; }; + TrigTauFlags::TRIGGERMENU getMenu () { return menu; }; + TrigTauMCTauList::OFFLINESELECTION getOfflineType () { return offlineType; }; + TrigTauSelectionManager::CUTLEVEL getCutLevel () { return cutLevel; }; + float getMaxVisEta() { return maxVisEta; }; + float getMinLeadingPt() { return minLeadingPt; }; + TrigTauSelectionManager::MENUVERSION getMenuVersion() { return menuVersion; }; + bool getSignal () {return signal; }; + TrigTauFlags::HLTAUTHOR getChainType() { return chainType;}; + + + +}; +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValOfflinePlots.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValOfflinePlots.h new file mode 100644 index 0000000000000000000000000000000000000000..98512d0cd2cf199f20305a262467343b21cf4582 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValOfflinePlots.h @@ -0,0 +1,134 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPVALOFFLINEPLOTS_H_ +#define _TTPVALOFFLINEPLOTS_H_ + +#include "TTree.h" +#include "TChain.h" +#include "TCanvas.h" +#include "TStyle.h" +#include "TROOT.h" +#include "TFile.h" +#include "TH2.h" +#include "TLegend.h" +#include "TLatex.h" +#include "TPostScript.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +using namespace std; + + +class TTPValOfflinePlots { + +private: + TString filename; + bool fileDefined; + TChain * chain; + bool debug; + TrigTauFlags::TRIGGERMENU menu; + TrigTauFlags::HLTAUTHOR chainType; + TrigTauSelectionManager::CUTLEVEL cutLevel; + TrigTauSelectionManager::MENUVERSION menuVersion; + bool signal; + float maxVisEta, minLeadingPt; + TrigTauSelectionManager selmanager; + TrigTauBugFix bugfix; + TrigTauEvent* event; + unsigned int nTau; + int npt; + float minpt; + float maxpt; + static const int nOffline = 1; + static const int nNprong =2; + int color[nOffline][nNprong]; + int style[nOffline][nNprong]; + TrigTauMCTauList::OFFLINESELECTION offlineType[nOffline]; + int nprong[nNprong]; + TrigTauAnalyzer analyzer[nOffline][nNprong]; + float threshold; + TString test[nOffline][nNprong]; + TH1F* hMC_InVisPt[nOffline][nNprong]; + TH1F* hMCVisPt[nOffline][nNprong]; + TH1F* hL1VisPt[nOffline][nNprong]; // L1 selected (numerator) + TH1F* hL2VisPt[nOffline][nNprong]; // L2 selected (numerator) + TH1F* hEFVisPt[nOffline][nNprong]; // EF selected (numerator) + TH1F* hL1PtEff[nOffline][nNprong]; + TH1F* hL2PtEff[nOffline][nNprong]; + TH1F* hEFPtEff[nOffline][nNprong]; + TH1F* hntrak; + TH1F* hEFnTracks[nOffline][nNprong]; + + TH1F* hL21PtEff[nOffline][nNprong]; + TH1F* hEFL2PtEff[nOffline][nNprong]; + + TH1F* hMC_InVisEta[nOffline][nNprong]; + TH1F* hMCVisEta[nOffline][nNprong]; + TH1F* hL1VisEta[nOffline][nNprong]; + TH1F* hL2VisEta[nOffline][nNprong]; + TH1F* hEFVisEta[nOffline][nNprong]; + TH1F* hL1EtaEff[nOffline][nNprong]; + TH1F* hL2EtaEff[nOffline][nNprong]; + TH1F* hEFEtaEff[nOffline][nNprong]; + + TH1F* hL21EtaEff[nOffline][nNprong]; + TH1F* hEFL2EtaEff[nOffline][nNprong]; + + int nMatch[nOffline][nNprong]; + int nL1passed[nOffline][nNprong]; + int nL2passed[nOffline][nNprong]; + int nEFpassed[nOffline][nNprong]; + int n_OfflineMatchEvent[nOffline][nNprong]; + int n_L1MatchEvent[nOffline][nNprong]; + int n_L2MatchEvent[nOffline][nNprong]; + int n_EFMatchEvent[nOffline][nNprong]; + + int nEvent; + int nTrue[nOffline][nNprong]; + int nGood[nOffline][nNprong]; + int nMatched[nOffline][nNprong]; + TString getName(TrigTauMCTauList::OFFLINESELECTION selection); + TString getName(int selection); + void ATLAS_LABEL(Double_t x,Double_t y,Color_t color=1); + void initialize(bool debug1 = false); + void analyzeEvent(int eventNumber); + + +public: + + TTPValOfflinePlots (TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + + TTPValOfflinePlots ( TString filename1 , TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + void analyze(); + void print(); + void update(TString name); + void printCSC(TPostScript & ps); + + void setFile( TString filename1 ); + void setDebug(bool newValue) { debug = newValue; }; + void setMenu (TrigTauFlags::TRIGGERMENU newValue) { menu = newValue; }; + void setCutLevel ( TrigTauSelectionManager::CUTLEVEL newValue) { cutLevel = newValue; }; + void setMaxVisEta (float newValue ) { maxVisEta = newValue; }; + void setMinLeadingPt (float newValue ) { minLeadingPt = newValue; }; + void setMenuVersion (TrigTauSelectionManager::MENUVERSION newValue ) { menuVersion = newValue;}; + void setSignal (bool newValue) {signal = newValue; }; + void setChainType (TrigTauFlags::HLTAUTHOR newValue) { chainType = newValue; }; + + + bool getDebug () { return debug; }; + TrigTauFlags::TRIGGERMENU getMenu () { return menu; }; + TrigTauSelectionManager::CUTLEVEL getCutLevel () { return cutLevel; }; + float getMaxVisEta() { return maxVisEta; }; + float getMinLeadingPt() { return minLeadingPt; }; + TrigTauSelectionManager::MENUVERSION getMenuVersion() { return menuVersion; }; + bool getSignal () {return signal; }; + TrigTauFlags::HLTAUTHOR getChainType() { return chainType;}; + + + +}; +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValRateTable.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValRateTable.h new file mode 100644 index 0000000000000000000000000000000000000000..5505cd880a5970ed9ef9d66ffd51e477a34a43ee --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValRateTable.h @@ -0,0 +1,124 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPValRateTable_H_ +#define _TTPValRateTable_H_ + +#include "TTree.h" +#include "TChain.h" +#include "TROOT.h" +#include "TFile.h" +#include "TStyle.h" +#include "TCanvas.h" +#include "TPostScript.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +#include <iostream> +#include <fstream> + +using namespace std; + +class TTPValRateTable { + +private: + long nEvent; + long nev; + long nL1Sel; + long nL2Sel; + long nL2CalSel; + long nEFSel; + + int nDecL1; + int nDecL2; + int nDecEF; + + double nEventWt; + double nL1SelWt; + double nL2SelWt; + double nL2CalSelWt; + double nEFSelWt; + + int nPrintL1; + int nPrintL2; + int nPrintEF; + + bool signal, signalSet; + bool fileDefined; + bool checkOffline; + bool doDetailedPrinting; + bool checkL2Cal, printChain; + TString filename; + TChain * chain; + int type; + bool debug; + TrigTauFlags::TRIGGERMENU menu; + TrigTauFlags::HLTAUTHOR chainType; + TrigTauSelectionManager::CUTLEVEL cutLevel; + TrigTauMCTauList::OFFLINESELECTION offlineType; + TrigTauSelectionManager::MENUVERSION menuVersion; + TrigTauBugFix::TTPVERSION version; + TrigTauBugFix::POOLFILE poolfile; + int nprong; + float maxVisEta, minLeadingPt; + float met; + TrigTauBugFix bugfix; + + + void initialize (bool debug1 = false); + +public: + + TTPValRateTable(TrigTauBugFix::POOLFILE poolfile1 = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version1 = TrigTauBugFix::TTP15, bool debug1 = false); + TTPValRateTable( TString filename1 , TrigTauBugFix::POOLFILE poolfile1 = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version1 = TrigTauBugFix::TTP15, bool debug1 = false); + + void analyze(int nEvents = 10000000); + void print(bool file = true); + void print(TString target, bool file = true); //prints under ntuple.eps + void checkAllMenus(unsigned int nMenu = 9, unsigned int nLevels = 3, double lum = 0, double crosssec = 0); + void print (double lum, double crosssec, TString target, bool file = true); + void print (double lum, double crosssec, bool file = true); + void reset(); + void update( TString filename, double lum = 0.0, double crosssec = 0.0 ); + void printCSC(TPostScript & ps, double lum, double crossec, vector<double> &counter ); + //void print(const char * name); + //void save(); + //void save(const char * name); //saves under trigtau.ntuple.eps + //void compare(const char * reference, const char * saveName); + //void compare(const char * reference); //saves under ntuple.eps + //void reset(); + + void setFile (TString filename1 ); + void setDebug(bool newValue) { debug = newValue; }; + void setType ( int newValue) { type = newValue; }; + void setSignal (bool newValue) { signal = newValue; signalSet = true; }; + void setNprong (int newValue) { nprong = newValue; }; + void setMenu (TrigTauFlags::TRIGGERMENU newValue) { menu = newValue; }; + void setOfflineType (TrigTauMCTauList::OFFLINESELECTION newValue) {offlineType = newValue;}; + void setCutLevel ( TrigTauSelectionManager::CUTLEVEL newValue) { cutLevel = newValue; }; + void setMaxVisEta (float newValue ) { maxVisEta = newValue; }; + void setMinLeadingPt (float newValue ) { minLeadingPt = newValue; }; + void setMenuVersion (TrigTauSelectionManager::MENUVERSION newValue ) { menuVersion = newValue;}; + void setDetailedPrinting( bool newValue) { doDetailedPrinting = newValue;}; + void setChainType (TrigTauFlags::HLTAUTHOR newValue) { chainType = newValue; }; + + bool getDebug () { return debug; }; + int getType () { return type; }; + bool getSignal () {return signal; }; + int getNprong () { return nprong; }; + TrigTauFlags::TRIGGERMENU getMenu () { return menu; }; + TrigTauMCTauList::OFFLINESELECTION getOfflineType () { return offlineType; }; + TrigTauSelectionManager::CUTLEVEL getCutLevel () { return cutLevel; }; + float getMaxVisEta() { return maxVisEta; }; + float getMinLeadingPt() { return minLeadingPt; }; + TrigTauSelectionManager::MENUVERSION getMenuVersion() { return menuVersion; }; + bool getDetailedPrinting() { return doDetailedPrinting; }; + TrigTauFlags::HLTAUTHOR getChainType() { return chainType;} + ofstream outfile; + +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValTrigDump.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValTrigDump.h new file mode 100644 index 0000000000000000000000000000000000000000..e8bbd1859ea00c89e4a9f337b3e7f193dd35dc95 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValTrigDump.h @@ -0,0 +1,33 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TTPVALTRIGDUMP_H_ +#define TTPVALTRIGDUMP_H_ +// +// Class to dump out trigger bits +// +#include "TString.h" +#include "TTree.h" +#include <list> + +class TTPValTrigDump { + public: + TTPValTrigDump(); + virtual ~TTPValTrigDump(); + + void dump(const TString& filename); + void dump(TTree* tree); + + void setNEvents(long nev) {_maxNEvents = nev;} + + // Dump specific events rather than just everything + // Can be called multiple times before calling dump() + void selectEvent(long evNumber); + + private: + long _maxNEvents; + std::list<long> _eventList; +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValTrigPlots.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValTrigPlots.h new file mode 100644 index 0000000000000000000000000000000000000000..ac5f284c99dd402c4d7f4e81f7947dcdd751b944 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValTrigPlots.h @@ -0,0 +1,76 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TTPVALTRIGPLOTS_H_ +#define TTPVALTRIGPLOTS_H_ +// +// Class to make lots of plots of lots of trigger variables +// +#include "TString.h" +#include "TTree.h" + +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauHistHelper.h" + +#include "TrigTauPerformValidation/TrigTauCounter.h" + +class TTPValTrigPlots { + public: + TTPValTrigPlots(); + virtual ~TTPValTrigPlots(); + + // Functions to define selectors + void setDefaultVersion(TrigTauSelectionManager::MENUVERSION version); + void setSelector(TrigTauFlags::TRIGGERMENU menu); + + void setHLTAuthorType(TrigTauFlags::HLTAUTHOR type) {_hltAuthorType = type;} + + // Return pointer to selector (useful for making changes) + TrigTauSelectionManager* getSelector() {return _selManager;} + + void clear(); // Delete everything and recreate + void reset(); // Sets everything to zero + + void fill(const TString& filename, double wt=1.); + void fill(TTree* tree); + + void draw(const TString& outfile); + + void write(const TString& outfile) {hh.writeAll(outfile);} + + // Lower level routines + void setCurrentWeight(double weight) {_currentWeight = weight;} + void defineTH(unsigned long tlo, unsigned long thi); + void setTHBins(unsigned long bins) {_thbins=bins;} + + // void setTHRange(const TString& filename); + + // Allow access to be able to change plot definitions if desired + TrigTauHistHelper hh; + + private: + + double _currentWeight; + TrigTauSelectionManager::MENUVERSION _defVersion; + TrigTauSelectionManager* _selManager; + TrigTauCounter _nEvent; + TrigTauBugFix _fix; + + // Time History information + unsigned long _thbins; + unsigned long _thstart; // Starting time + unsigned long _thend; // Ending time + + TrigTauFlags::HLTAUTHOR _hltAuthorType; + + void fillRoiHist(const TrigTauEvent* ev, + const TrigTauTrigChain& ch, + unsigned int type, + double wt); + +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValTriggerBitChecker.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValTriggerBitChecker.h new file mode 100644 index 0000000000000000000000000000000000000000..964c513b6a6fb7fca73c018e61641e71b75191e3 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValTriggerBitChecker.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPVALTRIGGERBITCHECKER_H_ +#define _TTPVALTRIGGERBITCHECKER_H_ + +// STL headers +#include <map> +#include <list> +#include <string> + +// Root headers +#include "TFile.h" +#include "TTree.h" +#include "TString.h" + +// TTP headers +#include "TrigTauPerformNtuple/TrigTauEvent.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformValidation/TrigTauCounter.h" + +class TTPValTriggerBitChecker { + + public: + + TTPValTriggerBitChecker(); + virtual ~TTPValTriggerBitChecker() {} + + // Functions to define selectors + void setMenuVersion(TrigTauSelectionManager::MENUVERSION version); + void setTauMenu(TrigTauFlags::TRIGGERMENU menu); + + // Access functions for Athena use + void initialize(TrigTauFlags::TRIGGERMENU menu); + void execute(const TrigTauEvent* event); + void finalize(); + + // Run function for standalone use + void processFile(const char* filename, TrigTauFlags::TRIGGERMENU menu); + void processFile(TTree* tree, TrigTauFlags::TRIGGERMENU menu); + + + private: + long m_nevents; + + TrigTauFlags::TRIGGERMENU m_menu; + + TrigTauAnalyzer m_analyzer; + + TrigTauCounter m_L1Cnt; + TrigTauCounter m_L2Cnt; + TrigTauCounter m_EFCnt; + +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValVariables.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..d058f0b7669f610332cecc78e14e7c34e108102d --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TTPValVariables.h @@ -0,0 +1,126 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TTPVALVARIABLES_H_ +#define _TTPVALVARIABLES_H_ + +#include "TTree.h" +#include "TChain.h" +#include "TCanvas.h" +#include "TStyle.h" +#include "TROOT.h" +#include "TFile.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformNtuple/TrigTauTrack.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauAnalyzer.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +//#include "TrigTauPerformAnalysis/TrigTauL2TrkFEX.h" +#include <vector> +using namespace std; + + +class TTPValVariables { + +private: + char * filename; + bool fileDefined; + bool plotAllMatchedEvents; + bool ignoreMatching; + TChain * chain; + bool debug; + unsigned int nProng; + TrigTauFlags::TRIGGERMENU menu; + TrigTauFlags::HLTAUTHOR chainType; + TrigTauSelectionManager::CUTLEVEL cutLevel; + TrigTauMCTauList::OFFLINESELECTION offlineType; + TrigTauSelectionManager::MENUVERSION menuVersion; + bool signal; + float maxVisEta, minLeadingPt; + TrigTauAnalyzer analyzer; + TrigTauSelectionManager selmanager; + TrigTauBugFix bugfix; + TrigTauEvent* event; + unsigned int nL1Cuts; + unsigned int nL2CaloCuts; + unsigned int nL2TrkCuts; + unsigned int nEFCuts; + unsigned int nHistos; + unsigned int nNames; + + void analyzeEvent(int eventNumber, bool chains, bool l1, bool l2 , bool efid, bool ef); + void createHistograms(TH1F ** histos); + void initialize(bool debug1 = false); + + struct less_Et : public binary_function<const TLorentzVector * ,const TLorentzVector * , bool> { + bool operator()(const TLorentzVector * x, const TLorentzVector * y) { return x->Et() < y->Et(); } + }; + // should do this template + struct less_roiWordL1 : public binary_function<const TrigTauL1Object * ,const TrigTauL1Object * , bool> { + bool operator()(const TrigTauL1Object * x, const TrigTauL1Object * y) { return x->m_roiWord < y->m_roiWord; } + }; + struct less_roiWordEFID : public binary_function<const TrigTauTrackCollection * ,const TrigTauTrackCollection * , bool> { + bool operator()(const TrigTauTrackCollection * x, const TrigTauTrackCollection * y) { return x->m_roiWord < y->m_roiWord; } + }; + + struct less_EF : public binary_function<const TrigTauRecEFObject * ,const TrigTauRecEFObject * , bool> { + bool operator()(const TrigTauRecEFObject * x, const TrigTauRecEFObject * y) + { + if( x->m_roiWord != y->m_roiWord ) return x->m_roiWord < y->m_roiWord; + if( x->m_seedType == y->m_seedType ) return x->Et() < y->Et(); + if( x->m_seedType == 3 ) return false; // 3 is bigger + if( y->m_seedType == 3 ) return true; + if( x->m_seedType == 1 ) return false; // y can be only 2 then + if( y->m_seedType == 1 ) return true; + return false; // should never be here + } + }; + + +public: + + TTPValVariables(TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + TTPValVariables ( char * filename1 , TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP15, bool debug1 = false); + + void analyze(int number = 10000000, bool chains=false, bool l1 = true, bool l2 = true, bool efid = true, bool ef = true); + + void setFile( char * filename1 ); + void setDebug(bool newValue) { debug = newValue; }; + void setMenu (TrigTauFlags::TRIGGERMENU newValue) { menu = newValue; }; + void setOfflineType (TrigTauMCTauList::OFFLINESELECTION newValue) {offlineType = newValue;}; + void setCutLevel ( TrigTauSelectionManager::CUTLEVEL newValue) { cutLevel = newValue; }; + void setMaxVisEta ( float newValue ) { maxVisEta = newValue; }; + void setMinLeadingPt (float newValue ) { minLeadingPt = newValue; }; + void setMenuVersion (TrigTauSelectionManager::MENUVERSION newValue ) { menuVersion = newValue;}; + void setPlotAllMatchedEvents (bool newValue) { plotAllMatchedEvents = newValue; }; + void setPlotAllEvents (bool newValue); + void setSignal (bool newValue) {signal = newValue; }; + void setChainType (TrigTauFlags::HLTAUTHOR newValue) { chainType = newValue; }; + + bool getDebug () { return debug; }; + TrigTauFlags::TRIGGERMENU getMenu () { return menu; }; + TrigTauMCTauList::OFFLINESELECTION getOfflineType () { return offlineType; }; + TrigTauSelectionManager::CUTLEVEL getCutLevel () { return cutLevel; }; + float getMaxVisEta() { return maxVisEta; }; + float getMinLeadingPt() { return minLeadingPt; }; + TrigTauSelectionManager::MENUVERSION getMenuVersion() { return menuVersion; }; + bool getPlotAllMatchedEvents () { return plotAllMatchedEvents; }; + bool getIgnoreMatching () { return ignoreMatching; }; + bool getSignal () { return signal; }; + TrigTauFlags::HLTAUTHOR getChainType() { return chainType;}; + + + + int printL1(const TrigTauL1Object * l1object); + int printL2Calo(const TrigTauL2Object * l2object); + int printL2Trk(const TrigTauL2Object * l2object); + int printL2Combined(const TrigTauL2Object * l2object); + int printEF(const TrigTauRecEFObject * efobject); + int printEFID(const TrigTauTrackCollection * object); + +}; + + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauCounter.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauCounter.h new file mode 100644 index 0000000000000000000000000000000000000000..dc6831aa4782543d3a9c472f3375e5bce5eb8192 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauCounter.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TRIGTAUCOUNTER_H +#define _TRIGTAUCOUNTER_H + +#include <vector> +#include <string> + +class TrigTauCounter { + +public: + TrigTauCounter(); + virtual ~TrigTauCounter() {} + + void print() const; // Dump all counter values + void reset(); // Delete everything + void clear(); // Set all counts to zero + + // Accumulate data into counter + void fill(unsigned long entry, double weight=1.); + + // Give the counter a name + void name(unsigned long entry, std::string name); + + // Add contents of another counter + void add(const TrigTauCounter& otherCounter); + + // Get counter values + double getN(unsigned long entry) const; + double getWt(unsigned long entry) const; + double getWt2(unsigned long entry) const; + double getDWt(unsigned long entry) const; + std::string getName(unsigned long entry) const; + + unsigned long getSize() const; + +private: + std::vector<double> _n; + std::vector<double> _wt; + std::vector<double> _wt2; + + std::vector<std::string> _name; +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauEffTool.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauEffTool.h new file mode 100644 index 0000000000000000000000000000000000000000..05812219419bb1e4e6c1b7f750f70ad9798f8e77 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauEffTool.h @@ -0,0 +1,109 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TRIGTAUEFFTOOL_H +#define _TRIGTAUEFFTOOL_H + +#include <map> +#include <list> + +#include "TFile.h" +#include "TTree.h" +#include "TString.h" + +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" +#include "TrigTauPerformValidation/TrigTauCounter.h" + +// Defined below +class TrigTauEffCuts; + +class TrigTauEffTool { + +public: + TrigTauEffTool(); + virtual ~TrigTauEffTool(); + + // Functions to define selectors + void setDefaultVersion(TrigTauSelectionManager::MENUVERSION version); + void defineSelector(TrigTauFlags::TRIGGERMENU menu); + void defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu); + void defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu, + TrigTauSelectionManager::MENUVERSION version); + + // Return pointer to selector by tag (useful for making changes) + TrigTauSelectionManager* getSelector(TString tag); + + // Return pointer to fiducial cuts by tag + TrigTauEffCuts* getCuts(TString tag); + void setPtCut(TString tag, double visPt); // Pt in GeV + + // Functions to define and fill data samples + // Samples now defined automatically when filled + void defineSample(TString tag); + + // One stop shopping + void fillSample(TString tag, TString filename); + + // Lower level routines + void setCurrentSample(TString tag) {_currentSample = tag;} + void fillSample(TTree* tree); + + // Counter access + TrigTauCounter* getCounter(TString selectorTag, TString sampleTag); + + // Dump all counters + void print(); + + // Print total rate vs. selector table + void printSelector(TString selectorTag, bool latexFormat=false); + void printCutFlow(TString selectorTag); + void printSummary(); + void printL1Summary(); + + // Define offline reco match or not (set true by default) + void setRecoMatch(bool match=true) {_recoMatch = match;} + + private: + bool _debug; + bool _recoMatch; + + TString _currentSample; + + TrigTauSelectionManager::MENUVERSION _defVersion; // Default version + + TrigTauBugFix _fix; + + // TString in both cases indexes the selector type + map<TString, TrigTauSelectionManager*> _selectors; + map<TString, TrigTauCounter*> _counters; + map<TString, TrigTauEffCuts*> _cuts; + + list<TString> _samples; + + // Utility to set up new counter + TrigTauCounter* makeNewCounter(); + + // Shortcut for printing one line of rate table + void printRateLine(TrigTauCounter* c, TString& label, bool latexFormat); + void printCutFlowLine(TString seltag, unsigned int c2, + unsigned int c1, unsigned int c0); + +}; + +class TrigTauEffCuts { + +public: + TrigTauEffCuts(); + virtual ~TrigTauEffCuts(); + + void setFiducialCuts(TrigTauMCTauList& truthList); + double maxVisEta; + double minVisPt; + TrigTauMCTau::DECAY decayMode; +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauEvRateTool.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauEvRateTool.h new file mode 100644 index 0000000000000000000000000000000000000000..3bfd7fe75b616d574f8c4f6632c53b82c73bc149 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauEvRateTool.h @@ -0,0 +1,84 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TRIGTAUEVRATETOOL_H +#define _TRIGTAUEVRATETOOL_H + +// +// More simplistic version of TrigTauRateTool +// This applies no selection, but just checks the +// event-level decision bits as produced when the +// TTP ntuple was generated. +// + +#include <map> +#include <list> + +#include "TFile.h" +#include "TTree.h" +#include "TString.h" + +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformValidation/TrigTauCounter.h" + +class TrigTauEvRateTool { + + public: + TrigTauEvRateTool(); + virtual ~TrigTauEvRateTool(); + + // Functions to define selectors + void defineSelector(TrigTauFlags::TRIGGERMENU menu); + void defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu); + + // Utility to do all samples + void defineAllSelectors(); + + // Functions to define and fill data samples + // Samples now defined automatically when filled + void defineSample(TString tag); + + // One stop shopping + void fillSample(TString tag, TString filename, double weight); + + // Lower level routines + void setCurrentSample(TString tag) {_currentSample = tag;} + void setCurrentWeight(double weight) {_currentWeight = weight;} + void fillSample(TTree* tree); + + // Counter access + TrigTauCounter* getCounter(TString selectorTag, TString sampleTag); + + // Function to define summary counters (one will be made for each selector) + // These should be done after filling + void clearSumCounter(TString sumTag); // Also creates if needed + void addSumSample(TString sampleTag, TString sumTag); + TrigTauCounter* getSumCounter(TString selectorTag, TString sumTag); + + // Dump all counters + void print(); + + // Print total rate vs. selector table + void printRateSum(TString sumTag, bool latexFormat=false); + void printSelector(TString selectorTag, bool latexFormat=false); + + private: + bool _debug; + + TString _currentSample; + double _currentWeight; + + // TString in both cases indexes the selector type + std::map<TString, TrigTauFlags::TRIGGERMENU> _selectors; + std::map<TString, TrigTauCounter*> _counters; + std::list<TString> _samples; + + // Utility to set up new counter + TrigTauCounter* makeNewCounter(); + + // Shortcut for printing one line of rate table + void printRateLine(TrigTauCounter* c, TString& label, bool latexFormat); +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauPerformValidationLinkDef.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauPerformValidationLinkDef.h new file mode 100644 index 0000000000000000000000000000000000000000..636c2660895a0182875aafb00d12ce82d2af484d --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauPerformValidationLinkDef.h @@ -0,0 +1,28 @@ +/* + 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++ class TTPValCutStudy; +#pragma link C++ class TTPValEffTableMaker; +#pragma link C++ class TTPValTriggerBitChecker; +#pragma link C++ class TrigTauCounter; +#pragma link C++ class TrigTauRateTool; +#pragma link C++ class TrigTauEvRateTool; +#pragma link C++ class TrigTauEffTool; +#pragma link C++ class TTPValDistribution; +#pragma link C++ class TTPValRateTable; +#pragma link C++ class TTPValVariables; +#pragma link C++ class TTPValTrigPlots; +#pragma link C++ class TTPValTrigDump; +#pragma link C++ class TTPValMultiPlots; +#pragma link C++ class TTPValOfflinePlots; +#pragma link C++ class TTPValLevelCut; +#pragma link C++ class TTPValBackgroundStudy; +#pragma link C++ class TTPValCosmicPlots; +#endif + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauRateTool.h b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauRateTool.h new file mode 100644 index 0000000000000000000000000000000000000000..38525c911867e4b243f4b3d337564f0dd5b91379 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/TrigTauPerformValidation/TrigTauRateTool.h @@ -0,0 +1,91 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef _TRIGTAURATETOOL_H +#define _TRIGTAURATETOOL_H + +#include <map> +#include <list> + +#include "TFile.h" +#include "TTree.h" +#include "TString.h" + +#include "TrigTauPerformNtuple/TrigTauFlags.h" +#include "TrigTauPerformAnalysis/TrigTauSelectionManager.h" +#include "TrigTauPerformAnalysis/TrigTauBugFix.h" + +#include "TrigTauPerformValidation/TrigTauCounter.h" + +class TrigTauRateTool { + + public: + TrigTauRateTool(); + virtual ~TrigTauRateTool(); + + // Functions to define selectors + void setDefaultVersion(TrigTauSelectionManager::MENUVERSION version); + void defineSelector(TrigTauFlags::TRIGGERMENU menu); + void defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu); + void defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu, + TrigTauSelectionManager::MENUVERSION version); + + // Return pointer to selector by tag (useful for making changes) + TrigTauSelectionManager* getSelector(TString tag); + + // Functions to define and fill data samples + // Samples now defined automatically when filled + void defineSample(TString tag); + + // One stop shopping + void fillSample(TString tag, TString filename, double weight); + + // Lower level routines + void setCurrentSample(TString tag) {_currentSample = tag;} + void setCurrentWeight(double weight) {_currentWeight = weight;} + void fillSample(TTree* tree); + + // void fillStdBgd(); // Shortcut to do this using JetManager.h + + // Counter access + TrigTauCounter* getCounter(TString selectorTag, TString sampleTag); + + // Function to define summary counters (one will be made for each selector) + // These should be done after filling + void clearSumCounter(TString sumTag); // Also creates if needed + void addSumSample(TString sampleTag, TString sumTag); + TrigTauCounter* getSumCounter(TString selectorTag, TString sumTag); + + // Dump all counters + void print(); + + // Print total rate vs. selector table + void printRateSum(TString sumTag, bool latexFormat=false); + void printSelector(TString selectorTag, bool latexFormat=false); + + // Used to deal with problems (most notably RDO L1 values) + // Must set this up before use + TrigTauBugFix fix; + + private: + bool _debug; + + TString _currentSample; + double _currentWeight; + + TrigTauSelectionManager::MENUVERSION _defVersion; // Default version + + // TString in both cases indexes the selector type + std::map<TString, TrigTauSelectionManager*> _selectors; + std::map<TString, TrigTauCounter*> _counters; + std::list<TString> _samples; + + // Utility to set up new counter + TrigTauCounter* makeNewCounter(); + + // Shortcut for printing one line of rate table + void printRateLine(TrigTauCounter* c, TString& label, bool latexFormat); +}; + +#endif diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/cmt/Makefile.standalone b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/cmt/Makefile.standalone new file mode 100755 index 0000000000000000000000000000000000000000..b7ebce02f062bbbc99c6f4702733a7d1c76097cc --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/cmt/Makefile.standalone @@ -0,0 +1,122 @@ +# ------------------------------------------------------------- +# This makefile is designed to compile a ROOT library +# independent of the Atlas framework. You only need to +# have ROOTSYS pointing to a valid ROOT installation. +# This has been tested on Linux and OS X, but should work +# for any architecture supported in ROOT Makefile.arch + +# --- External configuration ---------------------------------- +include $(ROOTSYS)/test/Makefile.arch + +MFLAGS = -MM -Wall -W -Woverloaded-virtual + +# ------------------------------------------------------------- + +BASEDIR = .. +WORKDIR = $(BASEDIR)/tmp +LIBDIR = $(BASEDIR) + +# Internal configuration +PACKAGE=TrigTauPerformValidation + +INCDIR=$(BASEDIR)/$(PACKAGE) +OBJDIR=$(WORKDIR) +SRCDIR=$(BASEDIR)/src + +# The following specifies where make looks for prerequisites +# VPATH=$(INCDIR) $(SRCDIR) $(OBJDIR) + +# Better to do it this way? +vpath %.h $(INCDIR) +vpath %.cxx $(SRCDIR) +vpath %.o $(OBJDIR) +vpath %.d $(WORKDIR) + +INCLUDES += -I$(INCDIR) -I$(ROOTSYS)/include + +# Add dependent packages +INCLUDES += -I$(BASEDIR) +INCLUDES += -I$(BASEDIR)/../TrigTauPerformNtuple -I$(BASEDIR)/../TrigTauPerformAnalysis + +ROOTSYS ?= ERROR_RootSysIsNotDefined +HHLIST = $(filter-out $(PACKAGE)LinkDef.h, $(patsubst $(INCDIR)/%h, %h, $(wildcard $(INCDIR)/*.h))) + +CINTFILE = $(PACKAGE)Cint.cxx +CINTOBJ = $(PACKAGE)Cint.o +SHLIBFILE = $(LIBDIR)/lib$(PACKAGE).$(DllSuf) + +# get libraries of ROOT +define ldlinksuffixROOT + $(addsuffix $(LDLINKSUFFIX),$(Lib)) $(shell if [ "$(findstring -Ldlink2,$(OPTIONS))" ]; then echo $(addsuffix _pkgid_$(ROOTVER),$(Lib)); fi) +endef + +default: shlib +#default: testvars + +# List of all source files to build +CCLIST=$(filter-out $(SKIPLIST),$(patsubst $(SRCDIR)/%cxx, %cxx, $(wildcard $(SRCDIR)/*.cxx))) + +# List of all object files to build +OLIST=$(patsubst %.cxx,%.o,$(CCLIST)) + +# List of all dependency file to make +DLIST=$(patsubst %.h,%.d,$(HHLIST)) + +testvars: + @echo $(HHLIST) + @echo $(CCLIST) + @echo $(OLIST) + @echo $(DLIST) + +# Implicit rule making all dependency Makefiles included at the end of this makefile +$(WORKDIR)/%.d: %.cxx $(HHLIST) + @echo "Making $@" + @mkdir -p $(WORKDIR) + @set -e; $(CC) $(MFLAGS) $(CPPFLAGS) $(INCLUDES) $< \ + | sed 's/\($(notdir $*)\)\.o[ :]*/\1.o $(notdir $@) : /g' > $@; \ + [ -s $@ ] || rm -f $@ + +# Implicit rule to compile all classes +%.o : %.cxx + @echo "Compiling $<" + @mkdir -p $(OBJDIR) + $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $(OBJDIR)/$(notdir $@) + +# Rule to make ROOTCINT output file +$(OBJDIR)/$(CINTOBJ): $(HHLIST) $(INCDIR)/$(PACKAGE)LinkDef.h + @mkdir -p $(OBJDIR) + @echo "Running rootcint" + @ROOTSYS=$(ROOTSYS) + @export ROOTSYS + @echo $(ROOTSYS)/bin/rootcint -f $(WORKDIR)/$(CINTFILE) -c $(CXXFLAGS) $(INCLUDES) \ + $(HHLIST) $(PACKAGE)LinkDef.h + $(ROOTSYS)/bin/rootcint -f $(WORKDIR)/$(CINTFILE) -c $(CXXFLAGS) $(INCLUDES) \ + $(HHLIST) $(PACKAGE)LinkDef.h + @echo "Compiling $(CINTFILE)" + @$(CXX) $(CXXFLAGS) $(INCLUDES) -c $(WORKDIR)/$(CINTFILE) -o $(OBJDIR)/$(CINTOBJ) + +# Rule to combine objects into a shared library +$(SHLIBFILE): $(OLIST) $(patsubst %.cxx,%.o,$(CINTFILE)) + @echo "Making $(SHLIBFILE)" + @rm -f $(SHLIBFILE) +ifeq ($(PLATFORM),macosx) + $(LD) $(SOFLAGS) $(addprefix $(OBJDIR)/, $(OLIST)) $(OBJDIR)/$(CINTOBJ) -o $(SHLIBFILE) + cd ..; ln -sf lib$(PACKAGE).$(DllSuf) lib$(PACKAGE).so +else + @cd $(WORKDIR) && $(LD) $(CXXFLAGS) $(INCLUDES) $(SOFLAGS) $(addprefix $(OBJDIR)/, $(OLIST)) $(OBJDIR)/$(CINTOBJ) -o $(SHLIBFILE) +endif + +# Useful build targets +shlib: $(SHLIBFILE) + +clean: + rm -rf $(WORKDIR) + rm -f $(SHLIBFILE) +ifeq ($(PLATFORM),macosx) + rm -f $(patsubst %.$(DllSuf),%.so,$(SHLIBFILE)) +endif + +.PHONY : shlib lib default clean + +-include $(addprefix $(WORKDIR)/,$(DLIST)) + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/cmt/requirements b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/cmt/requirements new file mode 100755 index 0000000000000000000000000000000000000000..a239003084f5ac262c24e1a509eac3316295af95 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/cmt/requirements @@ -0,0 +1,41 @@ +################################################# +package TrigTauPerformValidation + +author Olga Igonkina <Olga.Igonkina@cern.ch> + +use AtlasPolicy AtlasPolicy-* +use AtlasROOT AtlasROOT-* External +use TrigTauPerformNtuple TrigTauPerformNtuple-* Trigger/TrigAnalysis/TrigTauAnalysis +use TrigTauPerformAnalysis TrigTauPerformAnalysis-* Trigger/TrigAnalysis/TrigTauAnalysis + +apply_tag ROOTMathLibs +apply_tag ROOTGraphicsLibs + +apply_pattern installed_library +library TrigTauPerformValidation *.cxx + +private + +macro_append TrigTauPerformValidation_dependencies " TrigTauPerformValidationDict " + +apply_pattern have_root_headers \ + root_headers="TTPValCutStudy.h \ + TTPValEffTableMaker.h \ + TTPValTriggerBitChecker.h \ + TTPValRateTable.h \ + TTPValVariables.h \ + TTPValDistribution.h \ + TTPValMultiPlots.h \ + TTPValOfflinePlots.h \ + TTPValLevelCut.h \ + TrigTauCounter.h \ + TrigTauEffTool.h \ + TrigTauRateTool.h \ + TTPValBackgroundStudy.h \ + TTPValTrigPlots.h \ + TTPValCosmicPlots.h \ + TTPValTrigDump.h \ + TrigTauEvRateTool.h \ + TrigTauPerformValidationLinkDef.h" \ + extra_includes=" ${includes} " \ + headers_lib="TrigTauPerformValidation" diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/howto b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/howto new file mode 100644 index 0000000000000000000000000000000000000000..e42bd96577d3fabf21069bdbf65013105cd1afcc --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/howto @@ -0,0 +1,80 @@ +/* quick start up to run on TTPs created from RDOs. More details and comments are below */ + +gSystem->Load("libHist.so"); +gSystem->Load("libTree.so"); +gSystem->Load("libGpad.so"); +gSystem->Load("libCore.so"); + +gSystem->Load("lib/TrigTauPerformNtuple/libTrigTauPerformNtuple.so"); +gSystem->Load("lib/TrigTauPerformAnalysis/libTrigTauPerformAnalysis.so"); +gSystem->Load("lib/TrigTauPerformValidation/libTrigTauPerformValidation.so"); + +TTPValCutStudy study("ntuples/TTP09/tmp.*"); +study.analyze(); +study.print(); + +TTPValEffTableMaker maker("ntuples/TTP09/tmp.*"); +maker.analyze(); +maker.print(); + + +//------------------------------------------------------------------ + +//Here are two examples of how to use the validation classes: +(the usage of other tools in this package is almost the same, please have a look at the 'manual') + +//========TTPValCutStudy====== +//This class prints out relative and absolute efficiency curves after each cut. This is plotted as function of pt, eta and phi. + +TTPValCutStudy study; //create CutStudy object (this assumes you run on TTPs created from RDOs. to run on TTPs from AODs give 'TrigTauBugFix::AOD' as argument +study.setFile("ntuples/TTP09/tmp.*"); //define which file(s) is/are used +//also possible: TTPValCutStudy study("ntuplest/TTP09/tmp.*"); +//if on TTPs from AODs: TTPValCutStudy study("ntuplest/TTP09/tmp.*", TrigTauBugFix::AOD); + +//The following settings are all optional +study.setType(0); //Type referes to the type of the efficiencies; 0 - absolute and 1- relative; 1 is default +study.setNprong(3); //Only look at 3-prong decays; default is 0 - no selection; +study.setMenu(TrigTauFlags::TAU35I); //defines which menu is used; default is TAU20I +study.setCutLevel(TrigTauSelectionManager::TIGHT); //cutlevel is set to TIGHT; default is LOOSE +study.setOfflineType(TrigTauMCTauList::BOTHTAU); //offline matching set to BOTHTAU; default is EITHERTAU; NONE is currently not implemented; other options: TAUREC and TAU1P3P +study.setChainType(TrigTauFlags::IDSCAN); //default is SITRK; for other values see TrigTauFlags.h +study.setNamingConvention(TrigTauFlags::MENU1560) //default is MENU1600, needs to be set to MENU1560 only for older ntuples (produced before change of default L2 tracking algorithm to SITRK +study.setMaxVisEta(1.); //default is 2.5 +study.setMinLeadingPt(9.0); //default is 6.0 + +//Now, start analyzing and printing the result +study.analyze(); +study.print(); //creates file ntuple.eps with all efficiency histograms +study.save("ntuple.root"); //saves histograms in ntuple.root +study.compare("ntuple.root"); //plots analyzed histograms with the histograms from ntuple.root and prints it in ntuple.eps + + +======TTPValEffTableMaker====== +//This class prints out relative and absolute efficiencies for each trigger level for different offline matching and 1-prong/3-prong/all decay + +TTPValEffTableMaker maker; //give 'TrigTauBugFix::AOD' as argument if you run on TTPs created from AODs +maker.setFile("ntuples/TTP09/tmp.*"); + +//The following settings are all optional +maker.setMenu(TrigTauFlags::TAU35I); //defines which menu is used; default is TAU20I +maker.setCutLevel(TrigTauSelectionManager::TIGHT); //cutlevel is set to TIGHT; default is LOOSE +maker.setMaxVisEta(2.3); //default is 2.5 +maker.setMinLeadingPt(5.0); //default is 6.0 +maker.setChainType(TrigTauFlags::IDSCAN); //default is SITRK; for other values see TrigTauFlags.h + +//Now, start analyzing and printing the result +maker.analyze(); +maker.print(0); //printing absolute efficiencies; without argument: relative efficiencies +maker.print(1); //printing relative efficiencies + + +=====TTPValBackgroundStudy===== +//Prints efficiency with respect of pt, eta, phi. Prints also rates for given luminosity and x-section + +TTPValBackgroundRate brate("../data/ntuples/TTP14/5010/tmp*"); +brate.analyze(); +brate.print(1E31, 1.38E-27); //prints rates for lum=10^31 and x-section 1.38x10^-27 (which is the x-section of 5010) + + + + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/TTP_Monitor.C b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/TTP_Monitor.C new file mode 100644 index 0000000000000000000000000000000000000000..9e3c58bb6a09a2f58adcc4cc3d65f4009c676e94 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/TTP_Monitor.C @@ -0,0 +1,111 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +int TTP_Monitor() +{ + TChain chain("eventTree"); + + TrigTauEvent* event = new TrigTauEvent(); + chain.SetBranchAddress("EventBranch", &event); + chain.SetBranchStatus("*", 1); + chain.Add("*.ttp.root"); + + // Create output file + TFile * out = new TFile("Monitor_histograms_ttp.root","RECREATE"); + + //declare histograms + TH1F* h_NL1=new TH1F("h_NL1","N L1 ",10, 0, 10); + TH1F* h_L1Eta=new TH1F("h_L1Eta","L1 eta",100, -3, 3); + TH1F* h_L1Phi=new TH1F("h_L1Phi","L1 phi",100, -3.5, 3.5); + TH1F* h_L1Et=new TH1F("h_L1Et","L1 et",100, 0, 100); + + TH1F* h_NL2=new TH1F("h_NL2","N L2 ",10, 0, 10); + TH1F* h_L2Eta=new TH1F("h_L2Eta","L2 eta",100, -3, 3); + TH1F* h_L2Phi=new TH1F("h_L2Phi","L2 phi",100, -3.5, 3.5); + TH1F* h_L2Et=new TH1F("h_L2Et","L2 et",100, 0, 100); + TH1F* h_L2EmEn=new TH1F("h_L2EmEn","L2 EM energy",100, 0, 100); + TH1F* h_L2HadEn=new TH1F("h_L2HadEn","L2 Had energy",100, 0, 100); + TH1F* h_L2nStrips=new TH1F("h_L2nStrips","L2 nStrips",2000, 0, 2000); + TH1F* h_L2stripWidth2=new TH1F("h_L2stripWidth2","L2 stripsWidth2",100, 0, 0.3); + TH1F* h_L2EMRadius=new TH1F("h_L2EMRadius","L2 EM Rad",100, 0, 1); + TH1F* h_L2isoFrac=new TH1F("h_L2isoFrac","L2 IsoFrac",100, 0, 1); + + TH1F* h_NEF=new TH1F("h_NEF","N EF ",10, 0, 10); + TH1F* h_EFEta=new TH1F("h_EFEta","EF eta",100, -3, 3); + TH1F* h_EFPhi=new TH1F("h_EFPhi","EF phi",100, -3.5, 3.5); + TH1F* h_EFEt=new TH1F("h_EFEt","EF et",100, 0, 100); + TH1F* h_EFEmEn=new TH1F("h_EFEmEn","EF EM energy",100, 0, 100); + TH1F* h_EFHadEn=new TH1F("h_EFHadEn","EF Had energy",100, 0, 100); + TH1F* h_EFnStrips=new TH1F("h_EFnStrips","EF nStrips",2000, 0, 2000); + TH1F* h_EFstripWidth2=new TH1F("h_EFstripWidth2","EF stripsWidth2",100, 0, 0.3); + TH1F* h_EFEMRadius=new TH1F("h_EFEMRadius","EF EM Rad",100, 0, 1); + TH1F* h_EFisoFrac=new TH1F("h_EFisoFrac","EF IsoFrac",100, 0, 1); + + + //loop over events + int nev = int(chain.GetEntries() ); + + for(int iev = 0; iev<nev; ++iev) + { + event->reset() ; + chain.GetEvent(iev) ; + + //at L1 + int nL1 = event->nTauL1(); + int ntauL1=0; + for(unsigned int iL1 = 0; iL1 < nL1 ; ++iL1) + { + TrigTauL1Object * l1 = &event->tauL1Entry(iL1); + h_L1Eta->Fill( l1->Eta() ); + h_L1Phi->Fill( l1->Phi() ); + h_L1Et->Fill( l1->m_TauEnergy/1000 ); + ntauL1++; + } + h_NL1->Fill(ntauL1); + //at L2 + int nL2 = event->nTauL2(); + int ntauL2=0; + for(unsigned int iL2 = 0; iL2 < nL2 ; ++iL2) + { + TrigTauL2Object * l2 = &event->tauL2Entry(iL2); + h_L2Eta->Fill( l2->Eta() ); + h_L2Phi->Fill( l2->Phi() ); + h_L2Et->Fill( l2->m_EtCalib/1000 ); + h_L2EmEn->Fill( l2->m_EMEnergy/1000 ); + h_L2HadEn->Fill( l2->m_HadEnergy/1000 ); + + h_L2EMRadius->Fill( l2->m_EMRadius ); + h_L2isoFrac->Fill( l2->m_isoFrac ); + h_L2nStrips->Fill( l2->m_nStrips ); + h_L2stripWidth2->Fill( l2->m_stripWidth2 ); + + ntauL2++; + } + h_NL2->Fill(ntauL2); + //at EF + int nEF = event->nTauEF(); + int ntauEF=0; + for(unsigned int iEF = 0; iEF < nEF ; ++iEF) + { + TrigTauRecEFObject * lef = &event->tauEFEntry(iEF); + h_EFEta->Fill( lef->Eta() ); + h_EFPhi->Fill( lef->Phi() ); + h_EFEt->Fill( lef->m_ETcalo/1000 ); + + h_EFEmEn->Fill( lef->m_etEMCalib/1000 ); + h_EFHadEn->Fill( lef->m_etHadCalib/1000 ); + + h_EFEMRadius->Fill( lef->m_EMRadius ); + h_EFisoFrac->Fill( lef->m_isoFrac ); + h_EFnStrips->Fill( lef->m_nStrips ); + h_EFstripWidth2->Fill( lef->m_stripWidth2 ); + + ntauEF++; + } + h_NEF->Fill(ntauEF); + + }//end of loop over entries + out->Write(); out->Close(); + +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/checkTTP.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/checkTTP.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b402f3f405e1136913f0bea74d155262f80d8b47 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/checkTTP.cxx @@ -0,0 +1,70 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +int checkTTP(const char * filename, const char * psname="TTP.eps") +{ + TFile file(filename); + TTree * tree = (TTree*)file.Get("eventTree"); + TCanvas * c1 = (TCanvas*)gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,600); + + // decision + TH1F * hh1 = TrigTauFlags::makeHist("hdec1","L1 decision"); + TH1F * hh2 = TrigTauFlags::makeHist("hdec2","L2 decision"); + TH1F * hh3 = TrigTauFlags::makeHist("hdec3","EF decision"); + hh2->SetLineColor(4); + hh3->SetLineColor(2); + + tree->Draw("EventBranch.decision.fillHist(1,\"hdec1\")"); + tree->Draw("EventBranch.decision.fillHist(2,\"hdec2\")"); + tree->Draw("EventBranch.decision.fillHist(3,\"hdec3\")"); + + + c1->Clear(); + c1->Print(psname+TString("[")); + c1->Divide(2,2); + + c1->cd(1); drawMy(tree, "EventBranch.etMissL1.m_EtMiss","EventBranch.etMissL2.m_EtMiss","EventBranch.etMissEF.m_EtMiss","etmis"); + c1->cd(2); hh1->Draw(); hh2->Draw("same"); hh3->Draw("same"); + + c1->cd(3); drawMy(tree, "EventBranch.tauL1.m_roiWord","EventBranch.tauL2.m_roiWord","EventBranch.tauEF.m_roiWord","roi"); + + c1->cd(4); tree->Draw("EventBranch.tauL1.m_TauEnergy"); + + c1->Print(psname); + + c1->cd(1); tree->Draw("EventBranch.tauL2.Eta()"); + c1->cd(2); tree->Draw("EventBranch.tauL2.m_EMRadius"); + c1->cd(3); tree->Draw("EventBranch.tauL2.m_nCoreTracks"); + :wq +c1->cd(4); tree->Draw("EventBranch.tauL2.nTracks()"); + + c1->Print(psname); + + c1->cd(1); tree->Draw("EventBranch.tauEF.Eta()"); + c1->cd(2); tree->Draw("EventBranch.tauEF.m_EMRadius"); + c1->cd(3); tree->Draw("EventBranch.tauEF.m_EMRadius_1p3p"); + c1->cd(4); tree->Draw("EventBranch.tauEF.nTracks()"); + c1->Print(psname); + + + c1->Print(psname+TString("]")); + +} + +void drawMy(TTree * tree, const char * var1, const char * var2, const char * var3, TString hname) +{ + TString base1 = hname+TString("1"); + TString base2 = hname+TString("2"); + TString base3 = hname+TString("3"); + + tree->Draw(var1+TString(">>"+base1)); + TH1 * h2 = (TH1*)gDirectory->Get(base1)->Clone(base2); + TH1 * h3 = (TH1*)gDirectory->Get(base1)->Clone(base3); + h2->SetLineColor(4); + h3->SetLineColor(2); + tree->Draw(var2+TString(">>"+base2),"","same"); + tree->Draw(var3+TString(">>"+base3),"","same"); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/compareHist.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/compareHist.cxx new file mode 100755 index 0000000000000000000000000000000000000000..e5dd0aa21c7d7bd31d3bc7669a5eb27b9ba46e22 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/compareHist.cxx @@ -0,0 +1,127 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +int compareHist() +{ +TCanvas * c1 = (TCanvas *) gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,1000,500); + + TString plotfile("effic"); + + //int i = 1; + //int i = 0; + int i = 4; + + compareHist("EmEnergy_1_external_eff_a",i); c1->Print(plotfile + ".ps("); + compareHist("TauEnergy_2_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("EmIsol_3_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("HadIsol_4_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("EmCore_5_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("HadCore_6_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("et_1_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("etCalib_2_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("nStrips_3_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("stripWidth_4_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("emrad_5_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("isoFrac_6_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("EmEnWidth_7_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("ntrkExist_1_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("ntrk_2_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("leadPt_3_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("nSlow_4_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("nIso_5_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("nMatched_6_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("Q_7_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("sumPtCore_8_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("Et_trkEM_9_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("etCalibEF_1_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("ntrkMinEF_2_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("ntrkMaxEF_3_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("emradEF_4_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("isoFracEF_5_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("emFracEF_6_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("leadPtEF_7_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("emEtEF_8_external_eff_a",i); c1->Print(plotfile + ".ps"); + compareHist("massEF_9_external_eff_a",i); c1->Print(plotfile + ".ps)"); + + +} + + + +int compareHist(const char * name, int select ) +{ + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + + TFile * file1, * file2, *file3; + if( select == 0 ) { + file1 = new TFile("align/Et_efficiencies_devval_May28_NONE.root"); + file2 = new TFile("align/Et_efficiencies_TTP06_dR03_NONE.root"); + file3 = new TFile("align/Et_efficiencies_TTP07_NONE.root"); + } + elseif ( select == 1 ) { + file1 = new TFile("align/Eta_efficiencies_devval_May28_NONE.root"); + file2 = new TFile("align/Eta_efficiencies_TTP06_dR03_NONE.root"); + file3 = new TFile("align/Eta_efficiencies_TTP07_NONE.root"); + } + elseif ( select == 2 ) { + cout << "Print out Phi histograms" << endl; + file1 = new TFile("align/Phi_efficiencies_devval_May28_NONE.root"); + file2 = new TFile("align/Phi_efficiencies_TTP06_dR03_NONE.root"); + file3 = new TFile("align/Phi_efficiencies_TTP07_NONE.root"); + } + elseif ( select == 3 ) { + file1 = new TFile("align/Eta_efficiencies_devval_May28_NONE.root"); + file2 = new TFile("align/Eta_efficiencies_devval_May28_5862_NONE.root"); + file3 = new TFile("align/Eta_efficiencies_TTP07_NONE.root"); + } + + elseif ( select == 4 ) { + file1 = new TFile("align/Eta_efficiencies_devval_May28_NONE.root"); + file2 = new TFile("align/Eta_efficiencies_devval_May28_5862_NONE.root"); + file3 = new TFile("align/Eta_5107_over40.root"); + } + + + gROOT->cd(); + + TH1* h1 = (TH1*)gROOT->Get("h1"); + if( h1 ) delete h1; + h1 = (TH1*)file1->Get(name)->Clone("h1"); + + TH1* h2 = (TH1*)gROOT->Get("h2"); + if( h2 ) delete h2; + h2 = (TH1*)file2->Get(name)->Clone("h2"); + + TH1* h3 = (TH1*)gROOT->Get("h3"); + if( h3 ) delete h3; + h3 = (TH1*)file3->Get(name)->Clone("h3"); + + if( h1 ){ + h1->SetLineColor(1); + h1->Draw(); + }else cout << "No h1 found \n"; + if( h2 ){ + h2->SetLineColor(2); + h2->Draw("lsame"); + }else cout << "No h2 found \n"; + + if( h3 ){ + h3->SetLineColor(4); + h3->Draw("lsame"); + }else cout << "No h3 found \n"; + + TLatex * text = new TLatex(); + text->DrawTextNDC(0.5,0.3,"black - devval 5107"); + text->SetTextColor(2); + text->DrawTextNDC(0.5,0.5,"red - devval 5862"); + text->SetTextColor(4); + text->DrawTextNDC(0.5,0.4,"blue - devval 5107 Pt>40"); + + delete file1; + delete file2; + +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/cutStudy2.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/cutStudy2.cxx new file mode 100755 index 0000000000000000000000000000000000000000..7ad9d2196ed9084cf2ba525cce215e7dad90e504 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/cutStudy2.cxx @@ -0,0 +1,616 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iomanip> + +void cutStudy2(int select = 2) +{ + gSystem->Load("libHist.so"); + if( select == 1 ){ + //cutStudy("ntuples/sampleA/14.1.0/trigtau.5200.root"); + //cutStudy("ntuples/TTP06_dR03/5107/trig1_misal1_csc11.005107.pythia_Wtauhad.digit.RDO.v12003103.TTP06_dR03.merged.0.root"); + cutStudy("ntuples/TTP07/5107/trig1_misal1_csc11.005107.pythia_Wtauhad.RDO.v12003103.TTP07.merged.0.root"); + //copyHistos("align/Phi_efficiencies_TTP06_dR03_NONE.root"); + //copyHistos("align/Phi_efficiencies_TTP07_NONE.root"); + copyHistos("efficiencies.eta.root"); + } + + else if( select == 2 ){ + cutStudy("~/temp/val/trigtau.5200.root"); + copyHistos("align/Eta_efficiencies_RTT_dev_June01_NONE.root"); + } + + else{ + cutStudy("ntuples/misal1day-5107/trigtau.misal*"); + copyHistos("misal/efficiencies.eta.root"); + } +} + + + + +void cutStudy(const char * ntuppath) +{ + TrigTauFlags::TRIGGERMENU menu = TrigTauFlags::TAU16I; + cout << ntuppath << endl; + TChain * chain = new TChain("eventTree"); + chain->Add(ntuppath); + //chain->Add("ntuples/14.2.0_May28/5107/tmp.*"); + //chain->Add("ntuples/14.2.0_May28/5862/tmp.*"); + //chain->Add("ntuples/14.2.0/5107/tmp.*"); + + doSet(chain, menu, 0); +// doSet(chain, menu, 1); +// doSet(chain, menu, 3); + +// TChain * chain1 = new TChain("eventTree"); +// oSampleTTP04(5009,chain1); +// oSampleTTP04(5010,chain1); +// oSampleTTP04(5011,chain1); +// oSampleTTP04(5012,chain1); + + int nEvent, nL1Sel, nL2Calo, nL2Sel, nEFSel; + //cutStudy(chain1, menu, nEvent, nL1Sel, nL2Calo, nL2Sel, nEFSel, false); + //plotAllEfficiencies(-1,"dijet"); + +} + + + +void doSet(TTree * chain, TrigTauFlags::TRIGGERMENU menu, int nprong) +{ + int nEvent, nL1Sel, nL2Calo, nL2Sel, nEFSel; + TString nprStr = ""; + if( nprong == 1 ) nprStr = ".1pr"; + else if ( nprong == 3 ) nprStr = ".3pr"; + + TString baseName = TString("signal_truth")+nprStr; + cout << baseName<<endl; + cutStudy(chain, menu, nEvent, nL1Sel, nL2Calo, nL2Sel, nEFSel, true, nprong, TrigTauMCTauList::NONE); + //plotAllEfficiencies(2,baseName); + +// baseName = TString("signal_offline")+nprStr; +// cout << baseName<<endl; +// cutStudy(chain, menu, nEvent, nL1Sel, nL2Calo, nL2Sel, nEFSel, true, nprong, TrigTauMCTauList::EITHER); +// plotAllEfficiencies(-1,baseName); + +// baseName = TString("signal_tauRec")+nprStr; +// cout << baseName<<endl; +// cutStudy(chain, menu, nEvent, nL1Sel, nL2Calo, nL2Sel, nEFSel, true, nprong, TrigTauMCTauList::TAUREC); +// plotAllEfficiencies(-1,baseName); + +// baseName = TString("signal_tau1p3p")+nprStr; +// cout << baseName<<endl; +// cutStudy(chain, menu, nEvent, nL1Sel, nL2Calo, nL2Sel, nEFSel, true, nprong, TrigTauMCTauList::TAU1P3P); +// plotAllEfficiencies(-1,baseName ); + +// baseName = TString("signal_bothoffline")+nprStr; +// cout << baseName<<endl; +// cutStudy(chain, menu, nEvent, nL1Sel, nL2Calo, nL2Sel, nEFSel, true, nprong, TrigTauMCTauList::BOTHTAU); +// plotAllEfficiencies(-1,baseName); +} + + +void cutStudy(TTree * tree, + TrigTauFlags::TRIGGERMENU menu1, + int & nEvent , int & nL1Sel, + int & nL2Calo, int & nL2Sel, int & nEFSel, + bool signal=false, bool nprong = 0, + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::NONE) +{ + + TrigTauHistogram::HISTTYPE histType=TrigTauHistogram::EXTERNAL; //PTHIST; + + //==================================================== + + //gROOT->cd(); + // Open file +// TFile* file = new TFile(filename); +// if (!file->IsOpen()) { +// cerr << "Can't open file " << filename << endl; +// return; +// } + + // Initialize tree + // TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + cout << " Usage .x cutStudy(tree, menu)\n"; + return; + } + + //=================================================== + // MC truth + + TrigTauMCTauList truthList; + //truthList.setMaxVisEta(2.5); + truthList.setMinVisPt(menu1); + + if( nprong == 1 ) truthList.select1Prong(); + else if( nprong == 3 ) truthList.select3Prong(); + + truthList.setRecoMatchdR(0.2); + + //=================================================== + + nEvent = 0; + nL1Sel = 0; + nL2Calo = 0; + nL2Sel = 0; + nEFSel = 0; + + + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + tree->SetBranchStatus("mcEvent*", 1); + + // Create our analyzer class + TrigTauAnalyzer analyzer; + + // Also set an L1 MET cut if desired + analyzer.trigMan.setL1MET(0.); + TrigTauSelectionManager trigMan1; + trigMan1.setMenuVersion(TrigTauSelectionManager::MENU1400); + trigMan1.setTauMenu(menu1, TrigTauSelectionManager::LOOSE); + + if( histType == TrigTauHistogram::EXTERNAL ) + { + //TrigTauHistogram::setHistLimits( TrigTauHistogram::EXTERNAL, "external", "true phi",67, -3.35, 3.35); + TrigTauHistogram::setHistLimits( TrigTauHistogram::EXTERNAL, "external", "true eta",60, -3, 3); + //TrigTauHistogram::setHistLimits( TrigTauHistogram::EXTERNAL, "external", "visible true pt, MeV", 60, 0, 120000); + } + trigMan1.l1Sel.setHistDebug(histType); + trigMan1.l2CalSel.setHistDebug(histType); + trigMan1.l2TrkSel.setHistDebug(histType); + trigMan1.efSel.setHistDebug(histType); + + analyzer.chainList.setRoiWordMatching(false); + + TrigTauBugFix bugfix (TrigTauBugFix::TTP7, TrigTauBugFix::RDO); + + //trigMan1.setL2CalOnly(false); + bool checkL2Cal = true; + + // Loop over all events + int nev = int(tree->GetEntries()); + //if (nev > 100) nev=100; + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + + // ============ Select type of events (e.g. signal) ================ + if( signal ) { + truthList.fillPureList(&event->mcEvent); + truthList.fillGoodList(); + truthList.requireRecoMatch(*event, offlineType); + if( truthList.nMCTauGood() ==0 ) continue; + + //================================================================== + } + + nEvent++; + + + // Analyze this event + analyzer.chainList.fillChainList(event); + + bool pass = false; + + float externalVar = 0; + + bugfix.fix(event); + + // Look for L1 pass + unsigned int numCh = analyzer.chainList.nTrigChains(); + for (unsigned int iCh1=0; iCh1 < numCh; ++iCh1) { + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + if( !ch1.L1 ) continue; + + if( signal) // make sure that this is correct RoI + { + bool matchTruth = false; + const TrigTauL1Object* l1 = ch1.L1; + for(unsigned int iTrue = 0; iTrue < truthList.nMCTauGood(); ++iTrue) + { + const TrigTauMCTau * truth = &truthList.mcTauGoodEntry(iTrue); + if( truth->DeltaR(*l1)<0.2 ) { + matchTruth=true; + //externalVar = truth->Pt(); + //externalVar = truth->Phi(); + externalVar = truth->Eta(); + } + } + if( !matchTruth ) continue; + } + + trigMan1.l1Sel.histManager()->setExternal(externalVar); + + if (!trigMan1.passedL1(ch1)){ + continue; + } + pass = true; + if (pass) break; + } + + + if (!pass) continue; + nL1Sel++; + + // Look for L2Calo pass + if( checkL2Cal ){ + pass = false; + for (unsigned int iCh1=0; iCh1 < numCh; iCh1++) { + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + if( !ch1.L2 ) continue; + + if( signal) // make sure that this is correct RoI + { + bool matchTruth = false; + const TrigTauL2Object* l2 = ch1.L2; + for(unsigned int iTrue = 0; iTrue < truthList.nMCTauGood(); ++iTrue) + { + const TrigTauMCTau * truth = &truthList.mcTauGoodEntry(iTrue); + if( truth->DeltaR(*l2)<0.2 ) { + matchTruth=true; + //externalVar = truth->Pt(); + externalVar = truth->Eta(); + //externalVar = truth->Phi(); + } + } + if( !matchTruth ) continue; + } + + trigMan1.l2CalSel.histManager()->setExternal(externalVar); + if (!trigMan1.passedL2Cal(ch1)) continue; + + pass = true; + if (pass) break; + } + + if (!pass) continue; + nL2Calo++; + } + + // continue; + + // Look for L2 pass + pass = false; + for (unsigned int iCh1=0; iCh1 < numCh; iCh1++) { + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + if( !ch1.L2 ) continue; + + if( signal) // make sure that this is correct RoI + { + bool matchTruth = false; + const TrigTauL2Object* l2 = ch1.L2; + for(unsigned int iTrue = 0; iTrue < truthList.nMCTauGood(); ++iTrue) + { + const TrigTauMCTau * truth = &truthList.mcTauGoodEntry(iTrue); + if( truth->DeltaR(*l2)<0.2 ) { + matchTruth=true; + //externalVar = truth->Pt(); + externalVar = truth->Eta(); + //externalVar = truth->Phi(); + } + } + if( !matchTruth ) continue; + } + + trigMan1.l2TrkSel.histManager()->setExternal(externalVar); + if (!trigMan1.passedL2(ch1)) continue; + + pass = true; + if (pass) break; + } + + if (!pass) continue; + nL2Sel++; + + + + // Look for EF pass + pass = false; + for (unsigned int iCh1=0; iCh1 < numCh; iCh1++) { + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + if( !ch1.EF ) continue; + + if( signal) // make sure that this is correct RoI + { + bool matchTruth = false; + const TrigTauRecEFObject* ef = ch1.EF; + for(unsigned int iTrue = 0; iTrue < truthList.nMCTauGood(); ++iTrue) + { + const TrigTauMCTau * truth = &truthList.mcTauGoodEntry(iTrue); + if( truth->DeltaR(*ef)<0.2 ) { + matchTruth=true; + //externalVar = truth->Pt(); + externalVar = truth->Eta(); + //externalVar = truth->Phi(); + } + } + if( !matchTruth ) continue; + } + + trigMan1.efSel.histManager()->setExternal(externalVar); + if (!trigMan1.passedEF(ch1)) continue; + pass = true; + if (pass) break; + } + + if (!pass) continue; + nEFSel++; + + + } // end loop over events + + // trigMan1.print(); + // trigMan2.print(); + //trigMan1.l2CalSel.histManager()->plotAll(); + trigMan1.l1Sel.histManager()->plotAllEfficiencies(-1); + trigMan1.l2CalSel.histManager()->plotAllEfficiencies(-1); + trigMan1.l2TrkSel.histManager()->plotAllEfficiencies(-1); + trigMan1.efSel.histManager()->plotAllEfficiencies(-1); + + + cout << "N event " << nEvent << endl + << " L1 " << nL1Sel << " " << float(nL1Sel)/float(nEvent) << " " << float(nL1Sel)/float(nEvent)<< endl + << " L2Cal " << nL2Calo << " " << float(nL2Calo)/float(nEvent) << " " << float(nL2Calo)/float(nL1Sel)<< endl + << " L2Trk " << nL2Sel << " " << float(nL2Sel)/float(nEvent) << " " << float(nL2Sel)/float(nL2Calo)<< endl + << " EF " << nEFSel << " " << float(nEFSel)/float(nEvent) << " " << float(nEFSel)/float(nL2Sel)<< endl; + +// cout << menu1.menuName(menu1) << " \& "<< nEvent << " & " << setprecision(3) +// << float(nL1Sel)/float(nEvent)<< " & " << setprecision(3) +// << float(nL2Calo)/float(nL1Sel)<< " & "<< setprecision(3) +// << float(nL2Sel)/float(nL2Calo) << " & "<< setprecision(3) +// << float(nEFSel)/float(nL2Sel)<< " \\ \n"; + + + delete event; + //delete tree; + // delete file; + + cout << " Use menu " << menu1.menuName(menu1) << endl; + + + return; +} + + +int plotAllEfficiencies(int select = 3, TString baseFileName = "") +{ + //cout << "Plotting efficiencies..." << endl; + TString name = "_undefined_eff"; + + TString histList[10]; + TString labels[10]; + int index = 0; + + gStyle->SetPadGridY(true); + gStyle->SetPadGridX(true); + + cout << "Selecting Level for plot..." << endl; + + if( select == 0 ) + { + //histList[index] ="EMEnergy_1"; labels[index] = "EMEnergy Cut"; index++; + histList[index] ="TauEnergy_2"; labels[index] = "TauEnergy Cut"; index++; + histList[index] ="EmIsol_3"; labels[index] = "EmIsol Cut"; index++; + //histList[index] ="HadIsol_4"; labels[index] = "HadIsol Cut"; index++; + //histList[index] ="EmCore_5"; labels[index] = "EmCore Cut"; index++; + //histList[index] ="HadCore_6"; labels[index] = "HadCore Cut"; index++; + + } else if( select == 1 ) { + //histList[index] ="et_1"; labels[index] = "Et Cut"; index++; + histList[index] ="etCalib_2"; labels[index] = "EtCalib Cut"; index++; + //histList[index] ="nStrips_3"; labels[index] = "nStrips Cut"; index++; + histList[index] ="stripWidth_4"; labels[index] = "stripWidth Cut"; index++; + histList[index] ="emrad_5"; labels[index] = "EMRad Cut"; index++; + histList[index] ="isoFrac_6"; labels[index] = "IsoFrac Cut"; index++; + //histList[index] ="EmEnWidth_7"; labels[index] = "EmEnWidth Cut"; index++; + + }else if ( select == 2 ) { + + histList[index] ="ntrkExist_1"; labels[index] = "Tracks found"; index++; + histList[index] ="ntrk_2"; labels[index] = "Ntrk Cut"; index++; + histList[index] ="leadPt_3"; labels[index] = "Leading Pt Cut"; index++; + histList[index] ="nSlow_4"; labels[index] = "nSlow Cut"; index++; + histList[index] ="nIso_5"; labels[index] = "nIso Cut"; index++; + histList[index] ="nMatched_6"; labels[index] = "nMatched Cut"; index++; + histList[index] ="Q_7"; labels[index] = "Charge Cut"; index++; + histList[index] ="sumPtCore_8"; labels[index] = "sumPtRatio Cut"; index++; + histList[index] ="Et_trkEM_9"; labels[index] = "Et(trk+EM) Cut"; index++; + + }else if(select == 3 ) { + histList[index] ="etCalibEF_1"; labels[index] = "EtCalib Cut"; index++; + histList[index] ="ntrkMinEF_2"; labels[index] = "ntrkMin Cut"; index++; + histList[index] ="ntrkMaxEF_3"; labels[index] = "ntrkMax Cut"; index++; + histList[index] ="emradEF_4"; labels[index] = "EMRadius Cut"; index++; + histList[index] ="isoFracEF_5"; labels[index] = "isoFraction Cut"; index++; + histList[index] ="emFracEF_6"; labels[index] = "EMFraction Cut"; index++; + histList[index] ="leadPtEF_7"; labels[index] = "Leading pT Cut"; index++; + //histList[index] ="emEtEF_8"; labels[index] = "EM Et Cut"; index++; + + }else if(select == 4 ) { + name = "_pt"; + histList[index] ="baseL1_0"; labels[index] = "After Soft L1"; index++; + histList[index] ="baseL2Cal_0"; labels[index] = "L2Calo input"; index++; + histList[index] ="baseL2Trk_0"; labels[index] = "L2Trk input"; index++; + histList[index] ="baseEF_0"; labels[index] = "EF input"; index++; + histList[index] ="emEtEF_8"; labels[index] = "EF output"; index++; + + } + + else if ( select == -1 ){ + if( baseFileName == "" ) + { + cout << " Please use .x plotAllEfficiencies.cxx(-1, baseFileName)\n"; + return 1; + } + TCanvas * c1 = (TCanvas * )gDirectory->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","Selected",10,10,800,620); + plotAllEfficiencies(0, baseFileName); + c1->Print(baseFileName+name+ ".eps("); + //c1->Print(baseFileName+".l1"+name+".eps"); + plotAllEfficiencies(1, baseFileName); + c1->Print(baseFileName+name+ ".eps"); + //c1->Print(baseFileName+".l2cal"+name+".eps"); + plotAllEfficiencies(2, baseFileName); + c1->Print(baseFileName+name+ ".eps"); + //c1->Print(baseFileName+".l2trk"+name+".eps"); + plotAllEfficiencies(3, baseFileName); + c1->Print(baseFileName+name+ ".eps"); + //c1->Print(baseFileName+".ef"+name+".eps"); + plotAllEfficiencies(4, baseFileName); + c1->Print(baseFileName+name+ ".eps)"); + //c1->Print(baseFileName+".level"+name+".eps"); + return 0; + } + + for(unsigned int i = 0; i < index ; ++i) + { + histList[i].Append(name); + } + + cout << "Setting title..." << endl; + + // set title + TH1 * h1 = (TH1*)gDirectory->Get(histList[0]); + if( h1 == 0 ) {cout << " histogram " << histList[0] << " not found \n"; return 1;} + if( select == 0 ) h1->SetTitle(baseFileName+ " L1 selection"); + else if( select == 1 ) h1->SetTitle(baseFileName+ " L2 Calo selection"); + else if( select == 2 ) h1->SetTitle(baseFileName+ " L2 Trk selection"); + else if( select == 3 ) h1->SetTitle(baseFileName+ " EF selection"); + + + + // draw + cout << "Drawing histograms...." << endl; + TH1F * hist = (TH1F*)gDirectory->Get(histList[0]); + //float xmin = hist->GetXaxis()->GetXmin(); + TLegend *legend = new TLegend(0.5,0.2,0.7,0.5); + + hist->Draw(); legend->AddEntry(hist, labels[0], "l"); + for(unsigned int ihist = 1; ihist < index; ++ihist) + { + hist = (TH1F*)gROOT->Get(histList[ihist]); + hist->Draw("same"); + cout << "Add histogram " << labels[ihist] << endl; + legend->AddEntry(hist, labels[ihist], "l"); + } + legend->Draw(); + return 0; +} + + + + + +void copyHistos(const char * name ) +{ + TFile * fil = new TFile(name,"recreate"); + +TH1 * h1 = (TH1*)gROOT->Get("baseL1_0_external")->Clone("baseL1_0_external_a"); +h1 = (TH1*)gROOT->Get("EmEnergy_1_external")->Clone("EmEnergy_1_external_a"); +h1=(TH1*)gROOT->Get("TauEnergy_2_external")->Clone("TauEnergy_2_external_a"); +h1=(TH1*)gROOT->Get("EmIsol_3_external")->Clone("EmIsol_3_external_a"); +h1=(TH1*)gROOT->Get("HadIsol_4_external")->Clone("HadIsol_4_external_a"); +h1=(TH1*)gROOT->Get("EmCore_5_external")->Clone("EmCore_5_external_a"); +h1=(TH1*)gROOT->Get("HadCore_6_external")->Clone("HadCore_6_external_a"); +h1=(TH1*)gROOT->Get("baseL2Cal_0_external")->Clone("baseL2Cal_0_external_a"); +h1=(TH1*)gROOT->Get("et_1_external")->Clone("et_1_external_a"); +h1=(TH1*)gROOT->Get("etCalib_2_external")->Clone("etCalib_2_external_a"); +h1=(TH1*)gROOT->Get("nStrips_3_external")->Clone("nStrips_3_external_a"); +h1=(TH1*)gROOT->Get("stripWidth_4_external")->Clone("stripWidth_4_external_a"); +h1=(TH1*)gROOT->Get("emrad_5_external")->Clone("emrad_5_external_a"); +h1=(TH1*)gROOT->Get("isoFrac_6_external")->Clone("isoFrac_6_external_a"); +h1=(TH1*)gROOT->Get("EmEnWidth_7_external")->Clone("EmEnWidth_7_external_a"); +h1=(TH1*)gROOT->Get("baseL2Trk_0_external")->Clone("baseL2Trk_0_external_a"); +h1=(TH1*)gROOT->Get("ntrkExist_1_external")->Clone("ntrkExist_1_external_a"); +h1=(TH1*)gROOT->Get("ntrk_2_external")->Clone("ntrk_2_external_a"); +h1=(TH1*)gROOT->Get("leadPt_3_external")->Clone("leadPt_3_external_a"); +h1=(TH1*)gROOT->Get("nSlow_4_external")->Clone("nSlow_4_external_a"); +h1=(TH1*)gROOT->Get("nIso_5_external")->Clone("nIso_5_external_a"); +h1=(TH1*)gROOT->Get("nMatched_6_external")->Clone("nMatched_6_external_a"); +h1=(TH1*)gROOT->Get("Q_7_external")->Clone("Q_7_external_a"); +h1=(TH1*)gROOT->Get("sumPtCore_8_external")->Clone("sumPtCore_8_external_a"); +h1=(TH1*)gROOT->Get("Et_trkEM_9_external")->Clone("Et_trkEM_9_external_a"); +h1=(TH1*)gROOT->Get("baseEF_0_external")->Clone("baseEF_0_external_a"); +h1=(TH1*)gROOT->Get("etCalibEF_1_external")->Clone("etCalibEF_1_external_a"); +h1=(TH1*)gROOT->Get("ntrkMinEF_2_external")->Clone("ntrkMinEF_2_external_a"); +h1=(TH1*)gROOT->Get("ntrkMaxEF_3_external")->Clone("ntrkMaxEF_3_external_a"); +h1=(TH1*)gROOT->Get("emradEF_4_external")->Clone("emradEF_4_external_a"); +h1=(TH1*)gROOT->Get("isoFracEF_5_external")->Clone("isoFracEF_5_external_a"); +h1=(TH1*)gROOT->Get("emFracEF_6_external")->Clone("emFracEF_6_external_a"); +h1=(TH1*)gROOT->Get("leadPtEF_7_external")->Clone("leadPtEF_7_external_a"); +h1=(TH1*)gROOT->Get("emEtEF_8_external")->Clone("emEtEF_8_external_a"); +h1=(TH1*)gROOT->Get("massEF_9_external")->Clone("massEF_9_external_a"); +h1=(TH1*)gROOT->Get("EmEnergy_1_external_eff")->Clone("EmEnergy_1_external_eff_a"); +h1=(TH1*)gROOT->Get("TauEnergy_2_external_eff")->Clone("TauEnergy_2_external_eff_a"); +h1=(TH1*)gROOT->Get("EmIsol_3_external_eff")->Clone("EmIsol_3_external_eff_a"); +h1=(TH1*)gROOT->Get("HadIsol_4_external_eff")->Clone("HadIsol_4_external_eff_a"); +h1=(TH1*)gROOT->Get("EmCore_5_external_eff")->Clone("EmCore_5_external_eff_a"); +h1=(TH1*)gROOT->Get("HadCore_6_external_eff")->Clone("HadCore_6_external_eff_a"); + +h1=(TH1*)gROOT->Get("et_1_external_eff")->Clone("et_1_external_eff_a"); +h1=(TH1*)gROOT->Get("etCalib_2_external_eff")->Clone("etCalib_2_external_eff_a"); +h1=(TH1*)gROOT->Get("nStrips_3_external_eff")->Clone("nStrips_3_external_eff_a"); +h1=(TH1*)gROOT->Get("stripWidth_4_external_eff")->Clone("stripWidth_4_external_eff_a"); +h1=(TH1*)gROOT->Get("emrad_5_external_eff")->Clone("emrad_5_external_eff_a"); +h1=(TH1*)gROOT->Get("isoFrac_6_external_eff")->Clone("isoFrac_6_external_eff_a"); +h1=(TH1*)gROOT->Get("EmEnWidth_7_external_eff")->Clone("EmEnWidth_7_external_eff_a"); + +h1=(TH1*)gROOT->Get("ntrkExist_1_external_eff")->Clone("ntrkExist_1_external_eff_a"); +h1=(TH1*)gROOT->Get("ntrk_2_external_eff")->Clone("ntrk_2_external_eff_a"); +h1=(TH1*)gROOT->Get("leadPt_3_external_eff")->Clone("leadPt_3_external_eff_a"); +h1=(TH1*)gROOT->Get("nSlow_4_external_eff")->Clone("nSlow_4_external_eff_a"); +h1=(TH1*)gROOT->Get("nIso_5_external_eff")->Clone("nIso_5_external_eff_a"); +h1=(TH1*)gROOT->Get("nMatched_6_external_eff")->Clone("nMatched_6_external_eff_a"); +h1=(TH1*)gROOT->Get("Q_7_external_eff")->Clone("Q_7_external_eff_a"); +h1=(TH1*)gROOT->Get("sumPtCore_8_external_eff")->Clone("sumPtCore_8_external_eff_a"); +h1=(TH1*)gROOT->Get("Et_trkEM_9_external_eff")->Clone("Et_trkEM_9_external_eff_a"); + +h1=(TH1*)gROOT->Get("etCalibEF_1_external_eff")->Clone("etCalibEF_1_external_eff_a"); +h1=(TH1*)gROOT->Get("ntrkMinEF_2_external_eff")->Clone("ntrkMinEF_2_external_eff_a"); +h1=(TH1*)gROOT->Get("ntrkMaxEF_3_external_eff")->Clone("ntrkMaxEF_3_external_eff_a"); +h1=(TH1*)gROOT->Get("emradEF_4_external_eff")->Clone("emradEF_4_external_eff_a"); +h1=(TH1*)gROOT->Get("isoFracEF_5_external_eff")->Clone("isoFracEF_5_external_eff_a"); +h1=(TH1*)gROOT->Get("emFracEF_6_external_eff")->Clone("emFracEF_6_external_eff_a"); +h1=(TH1*)gROOT->Get("leadPtEF_7_external_eff")->Clone("leadPtEF_7_external_eff_a"); +h1=(TH1*)gROOT->Get("emEtEF_8_external_eff")->Clone("emEtEF_8_external_eff_a"); +h1=(TH1*)gROOT->Get("massEF_9_external_eff")->Clone("massEF_9_external_eff_a"); + + fil->Write(); + fil->Close(); + delete fil; +} + + +/* + + + + + + + +TChain*chain=newTChain("eventTree") +oSampleTTP04(5107,chain) +oSampleTTP04(5862,chain) +oSampleTTP04(5189,chain) +.xcutStudy.cxx(chain,true) +.xplotAllEfficiencies.cxx(-1) + +TChain*chain=newTChain("eventTree") +oSampleTTP04(5009,chain) +oSampleTTP04(5010,chain) +oSampleTTP04(5011,chain) +oSampleTTP04(5012,chain) +.xcutStudy.cxx(chain) + +*/ + + + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/effMultiPlots.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/effMultiPlots.cxx new file mode 100755 index 0000000000000000000000000000000000000000..59229ec39ae2ffadb322ae5a137a4dcdd2353ec2 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/effMultiPlots.cxx @@ -0,0 +1,463 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//void effMultiPlots(const char* filename="ntuples/trigtau.AOD.root", +// TString mode="all") { +void effMultiPlots(TTree * tree, + TString mode="all") { + + gROOT->cd(); + gROOT->SetStyle("ATLAS"); + gROOT->ForceStyle(); + + /* + // Open file + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + cerr << "Can't open file " << filename << endl; + return; + } + + // Initialize tree + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + cerr << "Can't find eventTree in " << filename << endl; + return; + } + */ + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + + // Create our analyzer class + TrigTauAnalyzer analyzer; + + // We will use our own trigger manager (although we could just use + // the one in TrigTauAnalyzer). + TrigTauSelectionManager trigMan; + + // Pick a menu set (12.0.6 by default) + // trigMan.setMenuVersion(TrigTauSelectionManager:: MENU1206); + // trigMan.setMenuVersion(TrigTauSelectionManager::MENU13020); + //trigMan.setMenuVersion(TrigTauSelectionManager::MENU13030pre); + trigMan.setMenuVersion(TrigTauSelectionManager::MENU1400); + // trigMan.setMenuVersion(TrigTauSelectionManager::MENUJUNE07); + + // Also set an L1 MET cut if desired + trigMan.setL1MET(0.); + + // Set fiducial cuts + analyzer.truthList.setMinVisPt(12.); + analyzer.truthList.setMaxVisEta(2.5); + + // Select a particular tau decay mode (if desired) + // Could also add pi, rho, etc. + TString append; + if (mode == "all") { + } + else if (mode == "1pr") { + append += "_1pr"; + analyzer.truthList.select1Prong(); + } + else if (mode == "3pr") { + append += "_3pr"; + analyzer.truthList.select3Prong(); + } + else { + cout << "Unkown decay mode: " << mode << endl; + delete event; delete tree; delete file; + return; + } + + // Formatting commands + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); + gROOT->cd(); + + // Set up the different menus to plot + const int nMenus = 7; + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::LOOSE; + TrigTauFlags::TRIGGERMENU theMenu[nMenus]; + theMenu[0] = TrigTauFlags::TAU12; + theMenu[1] = TrigTauFlags::TAU16I; + theMenu[2] = TrigTauFlags::TAU20I; + theMenu[3] = TrigTauFlags::TAU29I; + theMenu[4] = TrigTauFlags::TAU38I; + theMenu[5] = TrigTauFlags::TAU50; + theMenu[6] = TrigTauFlags::TAU84; + + float Threshold[nMenus]={15.,20.,25.,35.,45.,60., 100.}; + + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::EITHERTAU; + + TString test[nMenus]; + for(unsigned int im = 0; im < nMenus; ++im ) + test[im] = TrigTauFlags::menuName(theMenu[im]); + + + int npt =50; + float minpt = 0; + float maxpt = 120; + + // Create histograms to hold triggered object counts by pt and eta + TH1F* hMC_InVisPt = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + TH1F* hMCVisPt = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + TH1F* hL1VisPt[nMenus]; // L1 selected (numerator) + TH1F* hL2VisPt[nMenus]; // L2 selected (numerator) + TH1F* hEFVisPt[nMenus]; // EF selected (numerator) + TH1F* hL1PtEff[nMenus]; + TH1F* hL2PtEff[nMenus]; + TH1F* hEFPtEff[nMenus]; + + TH1F* hntrak = new TH1F("","",20,0.,10.); + + TH1F* hEFnTracks[nMenus]; + + TH1F* hL21PtEff[nMenus]; + TH1F* hEFL2PtEff[nMenus]; + + TH1F* hMC_InVisEta = new TH1F("", "", 31, -3.1, 3.1); + TH1F* hMCVisEta = new TH1F("", "", 31, -3.1, 3.1); + TH1F* hL1VisEta[nMenus]; + TH1F* hL2VisEta[nMenus]; + TH1F* hEFVisEta[nMenus]; + TH1F* hL1EtaEff[nMenus]; + TH1F* hL2EtaEff[nMenus]; + TH1F* hEFEtaEff[nMenus]; + + TH1F* hL21EtaEff[nMenus]; + TH1F* hEFL2EtaEff[nMenus]; + + int nMatch[nMenus]; + int nL1passed[nMenus]; + int nL2passed[nMenus]; + int nEFpassed[nMenus]; + int n_OfflineMatchEvent[nMenus]; + int n_L1MatchEvent[nMenus]; + int n_L2MatchEvent[nMenus]; + int n_EFMatchEvent[nMenus]; + + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + nMatch[iMenu]=0; + nL1passed[iMenu]=0; + nL2passed[iMenu]=0; + nEFpassed[iMenu]=0; + n_OfflineMatchEvent[iMenu]=0; + n_L1MatchEvent[iMenu]=0; + n_L2MatchEvent[iMenu]=0; + n_EFMatchEvent[iMenu]=0; + + hEFnTracks[iMenu] = new TH1F(*hntrak); + hL1VisPt[iMenu] = new TH1F(*hMCVisPt); + hL2VisPt[iMenu] = new TH1F(*hMCVisPt); + hEFVisPt[iMenu] = new TH1F(*hMCVisPt); + hL1PtEff[iMenu] = new TH1F(*hMCVisPt); + hL2PtEff[iMenu] = new TH1F(*hMCVisPt); + hEFPtEff[iMenu] = new TH1F(*hMCVisPt); + hL21PtEff[iMenu] = new TH1F(*hMCVisPt); + hEFL2PtEff[iMenu] = new TH1F(*hMCVisPt); + hL1PtEff[iMenu]->Sumw2(); + hL2PtEff[iMenu]->Sumw2(); + hEFPtEff[iMenu]->Sumw2(); + hL21PtEff[iMenu]->Sumw2(); + hEFL2PtEff[iMenu]->Sumw2(); + + hL1VisEta[iMenu] = new TH1F(*hMCVisEta); + hL2VisEta[iMenu] = new TH1F(*hMCVisEta); + hEFVisEta[iMenu] = new TH1F(*hMCVisEta); + hL1EtaEff[iMenu] = new TH1F(*hMCVisEta); + hL2EtaEff[iMenu] = new TH1F(*hMCVisEta); + hEFEtaEff[iMenu] = new TH1F(*hMCVisEta); + hL21EtaEff[iMenu] = new TH1F(*hMCVisEta); + hEFL2EtaEff[iMenu] = new TH1F(*hMCVisEta); + hL1EtaEff[iMenu]->Sumw2(); + hL2EtaEff[iMenu]->Sumw2(); + hEFEtaEff[iMenu]->Sumw2(); + hL21EtaEff[iMenu]->Sumw2(); + hEFL2EtaEff[iMenu]->Sumw2(); + } + + // Counters + int nEvent = 0; + int nTrue = 0; + int nGood = 0; + int nMatched = 0; + + TrigTauBugFix bugfix (TrigTauBugFix::TTP9, TrigTauBugFix::RDO); + + // Loop over all events + int nev = int(tree->GetEntries()); + //nev = 1000; + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + bugfix.fix(event); + + // Analyze this event + analyzer.analyze(event, true, offlineType); + + nEvent++; + nTrue += analyzer.truthList.nMCTauPure(); + nGood += analyzer.truthList.nMCTauGood(); + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + nMatch[iMenu]=0; + nL1passed[iMenu]=0; + nL2passed[iMenu]=0; + nEFpassed[iMenu]=0; + } + // Loop over all good truth taus in this event + unsigned int nTau = analyzer.truthList.nMCTauGood(); + for(unsigned int itau = 0; itau < nTau; ++itau ) { + TrigTauMCTau* tau = &analyzer.truthList.mcTauGoodEntry(itau); + + float visPt = tau->visible().Pt()/1000.; + float visEta = tau->visible().Eta(); + + // Fill denominator with all good taus + hMC_InVisPt->Fill(visPt); + hMC_InVisEta->Fill(visEta); + + nMatched++; + + hMCVisPt->Fill(visPt); + hMCVisEta->Fill(visEta); + + // Now, loop through defined menus, apply selections, and look for + // a matching trigger object within the allowed dR distance. + // Note: The object passing L2 doesn't necessarily need to come + // from the ROI passing L1, but I think that is OK. + for(unsigned int iMenu = 0; iMenu<nMenus; iMenu++) { + + if(visPt> Threshold[iMenu]) nMatch[iMenu]++; + + // Select the new menu + trigMan.setTauMenu(theMenu[iMenu], cutLevel); + + // Refill the selected chain list based on the new menu + analyzer.chainList.fillTriggerList(trigMan); + + // Find a matching L1 object + TrigTauL1Object* l1Tau = analyzer.chainList.getL1Tau(*tau); + if (l1Tau != 0) { + // Found a L1 trigger within dR range, fill numerator histograms + // with MC truth Pt and Eta + hL1VisPt[iMenu]->Fill(visPt); + hL1VisEta[iMenu]->Fill(visEta); + if(visPt> Threshold[iMenu]) nL1passed[iMenu]++; + } + + // Because the dR range might be different between L1 and L2 + // it is possible (if unlikely) to find a L2 match without a L1. + // In reality, this probably never happens... + + // Find a matching L2 object + TrigTauL2Object* l2Tau = analyzer.chainList.getL2Tau(*tau); + if (l2Tau != 0) { + hL2VisPt[iMenu]->Fill(visPt); + hL2VisEta[iMenu]->Fill(visEta); + if(visPt> Threshold[iMenu]) nL2passed[iMenu]++; + } + + // Find a matching EF object + TrigTauRecEFObject* efTau = analyzer.chainList.getEFTau(*tau); + if (efTau != 0) { + hEFVisPt[iMenu]->Fill(visPt); + hEFVisEta[iMenu]->Fill(visEta); + if(visPt> Threshold[iMenu]) nEFpassed[iMenu]++; + if(visPt> Threshold[iMenu]) hEFnTracks[iMenu]->Fill((*efTau)->nTracks()); + } + + } // End of loop over menus + } // End of loop over good taus in the event + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + + if(nMatch[iMenu]>0) n_OfflineMatchEvent[iMenu]++; + if(nL1passed[iMenu]>0) n_L1MatchEvent[iMenu]++; + if(nL2passed[iMenu]>0) n_L2MatchEvent[iMenu]++; + if(nEFpassed[iMenu]>0) n_EFMatchEvent[iMenu]++; + } + + } // end loop over events + + gROOT->cd(); + + // Make ratios + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + hL1PtEff[iMenu]-> Divide(hL1VisPt[iMenu], hMCVisPt, 1., 1., "B"); + hL2PtEff[iMenu]-> Divide(hL2VisPt[iMenu], hMCVisPt, 1., 1., "B"); + hEFPtEff[iMenu]-> Divide(hEFVisPt[iMenu], hMCVisPt, 1., 1., "B"); + + hL21PtEff[iMenu]-> Divide(hL2VisPt[iMenu], hL1VisPt[iMenu], 1., 1., "B"); + hEFL2PtEff[iMenu]-> Divide(hEFVisPt[iMenu], hL2VisPt[iMenu], 1., 1.,"B"); + + hL1EtaEff[iMenu]-> Divide(hL1VisEta[iMenu], hMCVisEta, 1., 1., "B"); + hL2EtaEff[iMenu]-> Divide(hL2VisEta[iMenu], hMCVisEta, 1., 1., "B"); + hEFEtaEff[iMenu]-> Divide(hEFVisEta[iMenu], hMCVisEta, 1., 1., "B"); + + hL21EtaEff[iMenu]->Divide(hL2VisEta[iMenu], hL1VisEta[iMenu], 1., 1., "B"); + hEFL2EtaEff[iMenu]->Divide(hEFVisEta[iMenu], hL2VisEta[iMenu], 1., 1., "B"); + } + + TString plotfile = "effMultiPlots"; + plotfile += append; + + // Titles + for(int i=0; i<nMenus; i++){ + hL1PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[i]->GetYaxis()->SetTitle("L1 efficiency"); + hL2PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[i]->GetYaxis()->SetTitle("L2 efficiency"); + hEFPtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[i]->GetYaxis()->SetTitle("Efficiency"); + } + + hL21PtEff[0]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL21PtEff[0]->GetYaxis()->SetTitle("L2/L1 efficiency"); + hEFL2PtEff[0]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFL2PtEff[0]->GetYaxis()->SetTitle("EF/L2 efficiency"); + + hL1EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hL1EtaEff[0]->GetYaxis()->SetTitle("L1 Efficiency"); + hL2EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hL2EtaEff[0]->GetYaxis()->SetTitle("L2 Efficiency"); + hEFEtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hEFEtaEff[0]->GetYaxis()->SetTitle("Efficiency"); + + hL21EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hL21EtaEff[0]->GetYaxis()->SetTitle("L2/L1 Efficiency"); + hEFL2EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hEFL2EtaEff[0]->GetYaxis()->SetTitle("EF/L2 Efficiency"); + + int color[nMenus]; + color[0] = 51; + color[1] = 8; + color[2] = 60; + color[3] = 96; + color[4] = 66; + color[5] = 100; + color[6] = 84; + int style[nMenus]; + style[0] = 20; + style[1] = 26; + style[2] = 21; + style[3] = 24; + style[4] = 23; + style[5] = 25; + style[6] = 22; + + + //gStyle->SetHistLineWidth(2); + gStyle->SetCanvasColor(0); + + TCanvas * c4 = (TCanvas *) gROOT->Get("c4"); + if( c4 ) delete c4; + c4 = new TCanvas("c4","EF Selected",10,10,800,620); + c4->cd(); + gStyle->SetHistLineColor(1); + TLegend *l = new TLegend(0.75,0.2,0.9,0.5); + l->SetFillStyle(0); + int id = 2; + gStyle->SetHistLineColor(color[id]); + gStyle->SetMarkerStyle(style[id]); + gStyle->SetMarkerColor(color[id]); + gStyle->SetLineColor(color[id]); + gStyle->SetFillColor(0); + hEFPtEff[id]->SetLineColor(color[id]); + hEFPtEff[id]->UseCurrentStyle(); + hEFPtEff[id]->SetMaximum(1.05); + hEFPtEff[id]->Draw("P"); + //l->AddEntry(hEFPtEff[id],test[id],"p"); + + // TLegend *l = new TLegend(0.13,0.65,0.25,0.85); + //l->SetFillStyle(0); + //hEFPtEff[2]->UseCurrentStyle(); + //hEFPtEff[2]->Draw("P"); + //l->AddEntry(hEFPtEff[2],"tau20i","p"); + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + gStyle->SetHistLineColor(color[iMenu]); + //if(iMenu==3 || iMenu==5) continue; + if (iMenu==2) continue; + + gStyle->SetMarkerColor(color[iMenu]); + gStyle->SetMarkerStyle(style[iMenu]); + gStyle->SetLineColor(color[iMenu]); + hEFPtEff[iMenu]->SetLineColor(color[iMenu]); + hEFPtEff[iMenu]->UseCurrentStyle(); + hEFPtEff[iMenu]->Draw("PSAME"); + l->AddEntry(hEFPtEff[iMenu],test[iMenu],"p"); + + //gStyle->SetMarkerStyle(style[iMenu]); + //gStyle->SetMarkerColor(color[iMenu]); + //hEFPtEff[iMenu]->UseCurrentStyle(); + //hEFPtEff[iMenu]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iMenu],test[iMenu],"p"); + } + + l->Draw("SAME"); + + ATLAS_LABEL(0.15,0.85); + + c4->Print(plotfile + ".eps"); + + + + for(unsigned int iMenu = 0; iMenu<nMenus; iMenu++) { + // Select the new menu + cout << endl << "Menu selection " << iMenu << endl << endl; + trigMan.setTauMenu(theMenu[iMenu], cutLevel); + trigMan.print(); + } + + for(unsigned int iMenu = 0; iMenu<nMenus; iMenu++) { + + cout<< "n_L1MatchEvent[iMenu] "<<n_L1MatchEvent[iMenu]<<endl; + cout<< "n_OfflineMatchEvent[iMenu] "<<n_OfflineMatchEvent[iMenu]<<endl; + + cout << " L1 efficiency menu "<<iMenu<<" is "<< ((float)n_L1MatchEvent[iMenu])/((float)n_OfflineMatchEvent[iMenu]) <<endl; + cout << " L2 efficiency menu "<<iMenu<<" is "<< ((float)n_L2MatchEvent[iMenu])/((float)n_OfflineMatchEvent[iMenu]) <<endl; + cout << " EF efficiency menu "<<iMenu<<" is "<< ((float)n_EFMatchEvent[iMenu])/((float)n_OfflineMatchEvent[iMenu]) <<endl; + } + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + cout << "True Taus: " << nTrue << endl; + cout << "Good Taus: " << nGood << endl; + cout << "Matched Taus: " << nMatched << " -> " + << float(nMatched)/nEvent << " Matched/Ev" << endl; + + delete event; + delete tree; + // delete file; + + return; +} + +// double DeltaRad( TrigTauRecObject* t1, TrigTauMCTau* t2){ +// double dEta = t1->Eta() - t2->Eta(); +// double dPhi = t1->Phi() - t2->Phi(); +// if (dPhi > +TMath::Pi()) dPhi -= TMath::TwoPi(); +// if (dPhi < -TMath::Pi()) dPhi += TMath::TwoPi(); +// return float(dEta*dEta + dPhi*dPhi); +// } +// double DeltaRad( TrigTau1p3pObject* t1, TrigTauMCTau* t2){ +// double dEta = t1->Eta() - t2->Eta(); +// double dPhi = t1->Phi() - t2->Phi(); +// if (dPhi > +TMath::Pi()) dPhi -= TMath::TwoPi(); +// if (dPhi < -TMath::Pi()) dPhi += TMath::TwoPi(); +// return float(dEta*dEta + dPhi*dPhi); +// } + +void ATLAS_LABEL(Double_t x,Double_t y,Color_t color=1) { + + TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize); + l.SetNDC(); + l.SetTextFont(72); + l.SetTextColor(color); + l.DrawLatex(x,y,"ATLAS"); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/effSequencePlots.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/effSequencePlots.cxx new file mode 100755 index 0000000000000000000000000000000000000000..e107c4a6474430a71f50645f9b3a6ef3fa02130d --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/effSequencePlots.cxx @@ -0,0 +1,346 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// +// The following picks one macro and plots the efficiency vs. PT +// for L1, L2, and EF on the same plot. +// + +//void effSequencePlots(const char* filename="ntuples/trigtau.AOD.root", +// TString menu="tau25i", TString menuMET="00", +// TString mode="all") { +void effSequencePlots(TTree * tree, + TrigTauFlags::TRIGGERMENU menu, + TString mode="all") { + + gROOT->cd(); + gROOT->SetStyle("ATLAS"); + gROOT->ForceStyle(); + + //mode = "3pr";//;"all"; + + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::EITHERTAU; + + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::LOOSE; + TrigTauBugFix bugfix (TrigTauBugFix::TTP9, TrigTauBugFix::RDO); + + // Create our analyzer class + TrigTauAnalyzer analyzer; + + // Set up selection manager and process selection options + TString append; + + //analyzer.trigMan.setMenuVersion(TrigTauSelectionManager::MENU13030pre); + analyzer.trigMan.setMenuVersion(TrigTauSelectionManager::MENU1400); + + + gStyle->SetPadGridY(true); + gStyle->SetPadGridX(true); + + + + //gROOT->cd(); + + // Open file + /* + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + cerr << "Can't open file " << filename << endl; + return; + } + + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + cerr << "Can't find eventTree in " << filename << endl; + return; + } + */ + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + + append +="_"; + append += TrigTauFlags::menuName(menu); + analyzer.trigMan.setTauMenu(menu, cutLevel); + + + // Set fiducial cuts + analyzer.truthList.setMinVisPt(12.); + analyzer.truthList.setMaxVisEta(2.5); + + // Select a particular tau decay mode (if desired) + // Could also add pi, rho, etc. + if (mode == "all") { + } + else if (mode == "1pr") { + append += "_1pr"; + analyzer.truthList.select1Prong(); + } + else if (mode == "3pr") { + append += "_3pr"; + analyzer.truthList.select3Prong(); + } + else { + cout << "Unkown decay mode: " << mode << endl; + delete event; delete tree; delete file; + return; + } + + + // Formatting commands + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); + //gROOT->cd(); + + int npt =50; + float minpt = 0; + float maxpt = 120; + + + // Create histograms to hold triggered object counts by pt and eta + TH1F* hMCVisPt = new TH1F("hMCVisPt", "", npt, minpt, maxpt); // MC visible (denominator) + TH1F* hOffVisPt = new TH1F("hOffVisPt", "", npt, minpt, maxpt); // MC visible (denominator) + TH1F* hL1VisPt = new TH1F("hL1VisPt", "", npt, minpt, maxpt); + TH1F* hL2VisPt = new TH1F("hL2VisPt", "", npt, minpt, maxpt); + TH1F* hEFVisPt = new TH1F("hEFVisPt", "", npt, minpt, maxpt); + TH1F* hL1PtEff = new TH1F("hL1PtEff", "", npt, minpt, maxpt); + TH1F* hL2PtEff = new TH1F("hL2PtEff", "", npt, minpt, maxpt); + TH1F* hEFPtEff = new TH1F("hEFPtEff", "", npt, minpt, maxpt); + + TH1F* hMCVisEta = new TH1F("hMCVisEta", "", 31, -3.1, 3.1); + TH1F* hOffVisEta = new TH1F("hOffVisEta", "", 31, -3.1, 3.1); + TH1F* hL1VisEta = new TH1F("hL1VisEta", "", 31, -3.1, 3.1); + TH1F* hL2VisEta = new TH1F("hL2VisEta", "", 31, -3.1, 3.1); + TH1F* hEFVisEta = new TH1F("hEFVisEta", "", 31, -3.1, 3.1); + TH1F* hL1EtaEff = new TH1F("hL1EtaEff", "", 31, -3.1, 3.1); + TH1F* hL2EtaEff = new TH1F("hL2EtaEff", "", 31, -3.1, 3.1); + TH1F* hEFEtaEff = new TH1F("hEFEtaEff", "", 31, -3.1, 3.1); + + + hL1PtEff->Sumw2(); + hL2PtEff->Sumw2(); + hEFPtEff->Sumw2(); + + hL1EtaEff->Sumw2(); + hL2EtaEff->Sumw2(); + hEFEtaEff->Sumw2(); + + TH1F* hOffOPt = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + TH1F* hL1OPt = new TH1F(*hOffOPt); // L1 selected (numerator) + TH1F* hL2OPt = new TH1F(*hOffOPt); // L2 selected (numerator) + TH1F* hEFOPt = new TH1F(*hOffOPt); // EF selected (numerator) + TH1F* hL1PtEff_off = new TH1F(*hOffOPt); + TH1F* hL2PtEff_off = new TH1F(*hOffOPt); + TH1F* hEFPtEff_off = new TH1F(*hOffOPt); + + hL1PtEff_off->Sumw2(); + hL2PtEff_off->Sumw2(); + hEFPtEff_off->Sumw2(); + + //TrigTauBugFix bugfix(TrigTauBugFix::TTP5, TrigTauBugFix::RDO); + //bugfix.setTTPVersion(filename); + + + // Counters + int nEvent = 0; + int nTrue = 0; + int nGood = 0; + int nMatched = 0; + + // Loop over all events + int nev = int(tree->GetEntries()); + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + bugfix.fix(event); + + // Analyze this event + analyzer.analyze(event, true, offlineType); + + nEvent++; + nTrue += analyzer.truthList.nMCTauPure(); + nGood += analyzer.truthList.nMCTauGood(); + + // Loop over all good truth taus in this event + unsigned int nTau = analyzer.truthList.nMCTauGood(); + for(unsigned int itau = 0; itau < nTau; ++itau ) { + TrigTauMCTau* tau = &analyzer.truthList.mcTauGoodEntry(itau); + + float visPt = tau->visible().Pt()/1000.; + float visEta = tau->visible().Eta(); + + // Fill denominator with all good taus + hMCVisPt->Fill(visPt); + hMCVisEta->Fill(visEta); + + + float OffPt=0; + + hOffVisPt->Fill(visPt); + hOffVisEta->Fill(visEta); + //hOffOPt->Fill(OffPt); + + // Find a matching L1 object + TrigTauL1Object* l1Tau = analyzer.chainList.getL1Tau(*tau); + if (l1Tau != 0) { + // Found a L1 trigger within dR range, fill numerator histograms + // with MC truth Pt and Eta + hL1VisPt->Fill(visPt); + //hL1OPt->Fill(OffPt); + hL1VisEta->Fill(visEta); + } + + // Because the dR range might be different between L1 and L2 + // it is possible (if unlikely) to find a L2 match without a L1. + // In reality, this probably never happens... + + // Find a matching L2 object + TrigTauL2Object* l2Tau = analyzer.chainList.getL2Tau(*tau); + if (l2Tau != 0) { + hL2VisPt->Fill(visPt); + //hL2OPt->Fill(OffPt); + hL2VisEta->Fill(visEta); + } + + // Find a matching EF object + TrigTauRecEFObject* efTau = analyzer.chainList.getEFTau(*tau); + if (efTau != 0) { + hEFVisPt->Fill(visPt); + //hEFOPt->Fill(OffPt); + hEFVisEta->Fill(visEta); + } + + } // End of loop over good taus in the event + } // end loop over events + + //gROOT->cd(); + + // Make ratios + //hL1PtEff_off->Divide(hL1OPt, hOffOPt, 1., 1., "B"); + //hL2PtEff_off->Divide(hL2OPt, hOffOPt, 1., 1., "B"); + //hEFPtEff_off->Divide(hEFOPt, hOffOPt, 1., 1., "B"); + + hL1PtEff->Divide(hL1VisPt, hOffVisPt, 1., 1., "B"); + hL2PtEff->Divide(hL2VisPt, hOffVisPt, 1., 1., "B"); + hEFPtEff->Divide(hEFVisPt, hOffVisPt, 1., 1., "B"); + + + hL1EtaEff->Divide(hL1VisEta, hOffVisEta, 1., 1., "B"); + hL2EtaEff->Divide(hL2VisEta, hOffVisEta, 1., 1., "B"); + hEFEtaEff->Divide(hEFVisEta, hOffVisEta, 1., 1., "B"); + + + TString plotfile = "effSequencePlots"; + plotfile += append; + + // Titles + hL1PtEff->GetXaxis()->SetTitle("True Visible E_{T} (GeV)"); + hL1PtEff->GetYaxis()->SetTitle("Efficiency"); + hL1PtEff_off->GetXaxis()->SetTitle("Off Visible E_{T} (GeV)"); + hL1PtEff_off->GetYaxis()->SetTitle("Efficiency"); + + hL1EtaEff->GetXaxis()->SetTitle("True visible eta"); + hL1EtaEff->GetYaxis()->SetTitle("Efficiency"); + + + int color[3]; + color[0] = 1;//2; + color[1] = 1;//3; + color[2] = 1;//4; + //gStyle->SetHistLineWidth(2); + + TCanvas * c1 = (TCanvas *) gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","Selected",10,10,800,620); + // c1->Divide(1,2); + + TLegend * legend = new TLegend(0.5,0.2,0.7,0.45); + legend->SetFillStyle(0); + c1->cd(1); + hL1PtEff->SetMaximum(1.05); + gStyle->SetHistLineColor(color[0]); + gStyle->SetMarkerStyle(20); gStyle->SetMarkerColor(color[0]); + hL1PtEff->UseCurrentStyle(); hL1PtEff->Draw(); + legend->AddEntry(hL1PtEff,"L1","p"); + gStyle->SetHistLineColor(color[1]); + gStyle->SetMarkerStyle(26); gStyle->SetMarkerColor(color[1]); + hL2PtEff->UseCurrentStyle(); hL2PtEff->Draw("SAME"); + legend->AddEntry(hL2PtEff,"L2","p"); + gStyle->SetHistLineColor(color[2]); + gStyle->SetMarkerStyle(22); gStyle->SetMarkerColor(color[2]); + hEFPtEff->UseCurrentStyle(); hEFPtEff->Draw("SAME"); + legend->AddEntry(hEFPtEff,"EF","p"); + + legend->Draw("same"); + ATLAS_LABEL(0.55,0.55); + + + TCanvas * c2 = (TCanvas *) gROOT->Get("c2"); + if( c2 ) delete c2; + c2 = new TCanvas("c2","Selected",10,10,800,620); + + c2->cd(1); + + gStyle->SetHistLineColor(color[0]); + gStyle->SetMarkerStyle(20); gStyle->SetMarkerColor(color[0]); + hL1EtaEff->UseCurrentStyle(); hL1EtaEff->Draw(); + gStyle->SetHistLineColor(color[1]); + gStyle->SetMarkerStyle(26); gStyle->SetMarkerColor(color[1]); + hL2EtaEff->UseCurrentStyle(); hL2EtaEff->Draw("SAME"); + gStyle->SetHistLineColor(color[2]); + gStyle->SetMarkerStyle(22); gStyle->SetMarkerColor(color[2]); + hEFEtaEff->UseCurrentStyle(); hEFEtaEff->Draw("SAME"); + // legend->Draw(); + + + + /* + c1->cd(2); + gStyle->SetHistLineColor(color[0]); + hL1PtEff_off->UseCurrentStyle(); hL1PtEff_off->Draw(); + gStyle->SetHistLineColor(color[1]); + hL2PtEff_off->UseCurrentStyle(); hL2PtEff_off->Draw("SAME"); + gStyle->SetHistLineColor(color[2]); + hEFPtEff_off->UseCurrentStyle(); hEFPtEff_off->Draw("SAME"); + */ + + c1->Print(plotfile + ".pt.eps"); + c2->Print(plotfile + ".eta.eps"); + + + analyzer.trigMan.print(); + + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + cout << "True Taus: " << nTrue << endl; + cout << "Good Taus: " << nGood << endl; + cout << "Matched Taus: " << nMatched << " -> " + << float(nMatched)/nEvent << " Match/Ev" << endl; + + delete event; + //delete tree; + + // delete file; + + return; +} + + /* +TChain * chain = new TChain("eventTree") +chain->Add("ntuples/TTP5/5107/user.ElizabethSPtacek.misal1_csc11.005107.pythia_Wtauhad.digit.RDO.v12003103.TTP05.2.root") +chain->Add("ntuples/TTP5/5188/trig1_misal1_mc12.005188.A3_Ztautau_filter.recon.ESD.v13003002_tid016457.0.TTP5.root") +chain->Add("ntuples/TTP5/5188/trig1_misal1_mc12.005188.A3_Ztautau_filter.recon.ESD.v13003002_tid016457.1.TTP5.root") +chain->Add("ntuples/TTP5/5188/trig1_misal1_mc12.005188.A3_Ztautau_filter.recon.ESD.v13003002_tid016457.2.TTP5.root") +chain->Add("ntuples/TTP5/5188/trig1_misal1_mc12.005188.A3_Ztautau_filter.recon.ESD.v13003002_tid016457.3.TTP5.root") + */ +void ATLAS_LABEL(Double_t x,Double_t y,Color_t color=1) { + + TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize); + l.SetNDC(); + l.SetTextFont(72); + l.SetTextColor(color); + l.DrawLatex(x,y,"ATLAS"); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/effSequencePlots2.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/effSequencePlots2.cxx new file mode 100755 index 0000000000000000000000000000000000000000..fb7fc27b994a1c6b5f4b76acde5f71ea924aa49b --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/effSequencePlots2.cxx @@ -0,0 +1,352 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// +// The following picks one macro and plots the efficiency vs. PT +// for L1, L2, and EF on the same plot. +// + +// minEt specifies fiducial cut on MC true Et (in GeV) + +void effSequencePlots2( + //TTree tree, + TrigTauFlags::TRIGGERMENU menu, + float minPt = 0., + TString menuMET="0", + TString mode="all", + bool reco = true) { + + gROOT->cd(); + //gROOT->SetStyle("ATLAS"); + //gROOT->ForceStyle(); + + //mode = "3pr";//;"all"; + bool checkTau1p3p = true;//false;//true;//true; + bool checkTauRec = true;//true; + + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::LOOSE; + + // Create our analyzer class + TrigTauAnalyzer analyzer; + + // Set up selection manager and process selection options + TString append; + + // Pick a menu set (12.0.6 by default) + //analyzer.trigMan.setMenuVersion(TrigTauSelectionManager:: MENU1206); + // analyzer.trigMan.setMenuVersion(TrigTauSelectionManager::MENU13030pre); + analyzer.trigMan.setMenuVersion(TrigTauSelectionManager::MENU1400); + // analyzer.trigMan.setMenuVersion(TrigTauSelectionManager::MENUJUNE06); + + + + gStyle->SetPadGridY(true); + gStyle->SetPadGridX(true); + + //gROOT->cd(); + + // Open file + //TFile* file = new TFile(filename); + //if (!file->IsOpen()) { + //cerr << "Can't open file " << filename << endl; + //return; + //} + + + TChain * tree = new TChain("eventTree"); + tree->Add("../data/TTP12a.142252/5188/tmp.*"); + + //TString filename = new TString("ntuples/TTP07/5107/trig1_misal1_csc11.005107.pythia_Wtauhad.RDO.v12003103.TTP07.merged.0.root"); + //TFile* file =new TFile("ntuples/TTP07/5107/trig1_misal1_csc11.005107.pythia_Wtauhad.RDO.v12003103.TTP07.merged.0.root"); + + //TFile* file =new TFile("ntuples/sampleA/14.1.0/trigtau.5200.root"); + + //TTree* tree = (TTree*)file->Get("eventTree"); + //tree.AddFriend("eventTree","ntuples/TTP07/5188/trig1_misal1_mc12.005188.A3_Ztautau_filter.RDO.v12000605.TTP07.merged.0.root"); + //tree.AddFriend("eventTree","ntuples/TTP07/5862/trig1_misal1_mc12.005862.A10_Atautau_filter.RDO.v12000605..TTP07.merged.0.root"); + //tree.AddFriend("eventTree","ntuples/TTP07/5862/trig1_misal1_mc12.005862.A10_Atautau_filter.RDO.v12000605..TTP07.merged.1.root"); + if (tree == 0) { + cerr << "Can't find eventTree!" << endl; + return; + } + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + + append +="_"; + append += TrigTauFlags::menuName(menu); + analyzer.trigMan.setTauMenu(menu, cutLevel); + + + if (menuMET == "00") { + } + else if (menuMET == "20") { + append += "_met20"; + analyzer.trigMan.setL1MET(20000.); + } + else if (menuMET == "30") { + append += "_met30"; + analyzer.trigMan.setL1MET(30000.); + } + else if (menuMET == "40") { + append += "_met40"; + analyzer.trigMan.setL1MET(40000.); + } + + // Set fiducial cuts + analyzer.truthList.setMinVisPt(minPt); // 12 GeV + analyzer.truthList.setMaxVisEta(2.5); + //analyzer.truthList.setMinLeadingPt(6.0); + + // Select a particular tau decay mode (if desired) + // Could also add pi, rho, etc. + if (mode == "all") { + } + else if (mode == "1pr") { + append += "_1pr"; + analyzer.truthList.select1Prong(); + } + else if (mode == "3pr") { + append += "_3pr"; + analyzer.truthList.select3Prong(); + } + else { + cout << "Unkown decay mode: " << mode << endl; + delete event; delete tree; delete file; + return; + } + + if (reco) append += "_reco"; + if(!reco) append +="_truth"; + + + // Formatting commands + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); + //gROOT->cd(); + + int npt =50; + float minpt = 0; + float maxpt = 120; + + // Create histograms to hold triggered object counts by pt and eta + TH1F* hMCVisPt = new TH1F("hMCVisPt", "", npt, minpt, maxpt); // MC visible (denominator) + + TH1F* hL1VisPt = new TH1F("hL1VisPt", "", npt, minpt, maxpt); + TH1F* hL2VisPt = new TH1F("hL2VisPt", "", npt, minpt, maxpt); + TH1F* hEFVisPt = new TH1F("hEFVisPt", "", npt, minpt, maxpt); + + TH1F* hL1PtEff = new TH1F("hL1PtEff", "", npt, minpt, maxpt); + TH1F* hL2PtEff = new TH1F("hL2PtEff", "", npt, minpt, maxpt); + TH1F* hEFPtEff = new TH1F("hEFPtEff", "", npt, minpt, maxpt); + + TH1F* hMCVisEta = new TH1F("hMCVisEta", "", 31, -3.1, 3.1); + + TH1F* hL1VisEta = new TH1F("hL1VisEta", "", 31, -3.1, 3.1); + TH1F* hL2VisEta = new TH1F("hL2VisEta", "", 31, -3.1, 3.1); + TH1F* hEFVisEta = new TH1F("hEFVisEta", "", 31, -3.1, 3.1); + + TH1F* hL1EtaEff = new TH1F("hL1EtaEff", "", 31, -3.1, 3.1); + TH1F* hL2EtaEff = new TH1F("hL2EtaEff", "", 31, -3.1, 3.1); + TH1F* hEFEtaEff = new TH1F("hEFEtaEff", "", 31, -3.1, 3.1); + + + hL1PtEff->Sumw2(); + hL2PtEff->Sumw2(); + hEFPtEff->Sumw2(); + + hL1EtaEff->Sumw2(); + hL2EtaEff->Sumw2(); + hEFEtaEff->Sumw2(); + + TH1F* hOffOPt = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + TH1F* hL1OPt = new TH1F(*hOffOPt); // L1 selected (numerator) + TH1F* hL2OPt = new TH1F(*hOffOPt); // L2 selected (numerator) + TH1F* hEFOPt = new TH1F(*hOffOPt); // EF selected (numerator) + TH1F* hL1PtEff_off = new TH1F(*hOffOPt); + TH1F* hL2PtEff_off = new TH1F(*hOffOPt); + TH1F* hEFPtEff_off = new TH1F(*hOffOPt); + + hL1PtEff_off->Sumw2(); + hL2PtEff_off->Sumw2(); + hEFPtEff_off->Sumw2(); + + TrigTauBugFix bugfix (TrigTauBugFix::TTP7, TrigTauBugFix::RDO); + //TrigTauBugFix bugfix; + //bugfix.setTTPVersion(filename); + + + // Counters + int nEvent = 0; + int nTrue = 0; + int nGood = 0; + int nMatched = 0; + + analyzer.chainList.setRoiWordMatching(false); + analyzer.chainList.setHLTAuthor(TrigTauFlags::TRTONLY); + + // Loop over all events + int nev = int(tree->GetEntries()); + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + bugfix.fix(event); + + // Analyze this event + analyzer.analyze(event); + + // Only use true taus if an offline tau is nearby + if (reco) analyzer.truthList.requireRecoMatch(*event); + + nEvent++; + nTrue += analyzer.truthList.nMCTauPure(); + nGood += analyzer.truthList.nMCTauGood(); + + // Loop over all good truth taus in this event + unsigned int nTau = analyzer.truthList.nMCTauGood(); + for(unsigned int itau = 0; itau < nTau; ++itau ) { + TrigTauMCTau* tau = &analyzer.truthList.mcTauGoodEntry(itau); + + float visPt = tau->visible().Pt()/1000.; + float visEta = tau->visible().Eta(); + + // Fill denominator with all good taus + hMCVisPt->Fill(visPt); + hMCVisEta->Fill(visEta); + + nMatched++; + + // Find a matching L1 object + TrigTauL1Object* l1Tau = analyzer.chainList.getL1Tau(*tau); + if (l1Tau != 0) { + // Found a L1 trigger within dR range, fill numerator histograms + // with MC truth Pt and Eta + hL1VisPt->Fill(visPt); + hL1VisEta->Fill(visEta); + } + + // Because the dR range might be different between L1 and L2 + // it is possible (if unlikely) to find a L2 match without a L1. + // In reality, this probably never happens... + + // Find a matching L2 object + TrigTauL2Object* l2Tau = analyzer.chainList.getL2Tau(*tau); + if (l2Tau != 0) { + hL2VisPt->Fill(visPt); + hL2VisEta->Fill(visEta); + } + + // Find a matching EF object + TrigTauRecEFObject* efTau = analyzer.chainList.getEFTau(*tau); + if (efTau != 0) { + hEFVisPt->Fill(visPt); + hEFVisEta->Fill(visEta); + } + + } // End of loop over good taus in the event + } // end loop over events + + //gROOT->cd(); + + // Make ratios + + hL1PtEff->Divide(hL1VisPt, hMCVisPt, 1., 1., "B"); + hL2PtEff->Divide(hL2VisPt, hMCVisPt, 1., 1., "B"); + hEFPtEff->Divide(hEFVisPt, hMCVisPt, 1., 1., "B"); + + hL1EtaEff->Divide(hL1VisEta, hMCVisEta, 1., 1., "B"); + hL2EtaEff->Divide(hL2VisEta, hMCVisEta, 1., 1., "B"); + hEFEtaEff->Divide(hEFVisEta, hMCVisEta, 1., 1., "B"); + + + TString plotfile = "effSequencePlots"; + plotfile += append; + + // Titles + hL1PtEff->GetXaxis()->SetTitle("True Visible E_{T} (GeV)"); + hL1PtEff->GetYaxis()->SetTitle("Efficiency"); + + hL1EtaEff->GetXaxis()->SetTitle("True visible eta"); + hL1EtaEff->GetYaxis()->SetTitle("Efficiency"); + + int color[3]; + color[0] = 1;//2; + color[1] = 1;//3; + color[2] = 1;//4; + //gStyle->SetHistLineWidth(2); + + TCanvas * c1 = (TCanvas *) gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","Selected",10,10,800,620); + // c1->Divide(1,2); + + TLegend * legend = new TLegend(0.5,0.2,0.7,0.45); + legend->SetFillStyle(0); + c1->cd(1); + hL1PtEff->SetMaximum(1.05); + gStyle->SetHistLineColor(color[0]); + gStyle->SetMarkerStyle(20); gStyle->SetMarkerColor(color[0]); + hL1PtEff->UseCurrentStyle(); hL1PtEff->Draw(); + legend->AddEntry(hL1PtEff,"L1","p"); + gStyle->SetHistLineColor(color[1]); + gStyle->SetMarkerStyle(26); gStyle->SetMarkerColor(color[1]); + hL2PtEff->UseCurrentStyle(); hL2PtEff->Draw("SAME"); + legend->AddEntry(hL2PtEff,"L2","p"); + gStyle->SetHistLineColor(color[2]); + gStyle->SetMarkerStyle(22); gStyle->SetMarkerColor(color[2]); + hEFPtEff->UseCurrentStyle(); hEFPtEff->Draw("SAME"); + legend->AddEntry(hEFPtEff,"EF","p"); + + legend->Draw("same"); + ATLAS_LABEL(0.55,0.55); + + + TCanvas * c2 = (TCanvas *) gROOT->Get("c2"); + if( c2 ) delete c2; + c2 = new TCanvas("c2","Selected",10,10,800,620); + + c2->cd(1); + + gStyle->SetHistLineColor(color[0]); + gStyle->SetMarkerStyle(20); gStyle->SetMarkerColor(color[0]); + hL1EtaEff->UseCurrentStyle(); hL1EtaEff->Draw(); + gStyle->SetHistLineColor(color[1]); + gStyle->SetMarkerStyle(26); gStyle->SetMarkerColor(color[1]); + hL2EtaEff->UseCurrentStyle(); hL2EtaEff->Draw("SAME"); + gStyle->SetHistLineColor(color[2]); + gStyle->SetMarkerStyle(22); gStyle->SetMarkerColor(color[2]); + hEFEtaEff->UseCurrentStyle(); hEFEtaEff->Draw("SAME"); + // legend->Draw(); + + + c1->Print(plotfile + ".pt.eps"); + c2->Print(plotfile + ".eta.eps"); + + + analyzer.trigMan.print(); + + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + cout << "True Taus: " << nTrue << endl; + cout << "Good Taus: " << nGood << endl; + cout << "Matched Taus: " << nMatched << " -> " + << float(nMatched)/nEvent << " Match/Ev" << endl; + + delete event; + // delete tree; + // delete file; + + return; +} + +void ATLAS_LABEL(Double_t x,Double_t y,Color_t color=1) { + + TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize); + l.SetNDC(); + l.SetTextFont(72); + l.SetTextColor(color); + l.DrawLatex(x,y,"ATLAS"); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/efficiencyTable.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/efficiencyTable.cxx new file mode 100755 index 0000000000000000000000000000000000000000..56cbad412c81a86e5cdf4825a16d32c24c03b729 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/efficiencyTable.cxx @@ -0,0 +1,970 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iomanip> + +void efficiencyTable() +{ + //cout << "\n\n +++++++++++++++ 13.0.30.3 ++++++++++++++++++++\n\n\n"; + //efficiencyTable( TrigTauSelectionManager::MENU13030pre, TrigTauSelectionManager::LOOSE); + cout << "\n\n +++++++++++++++ LOOSE ++++++++++++++++++++\n\n\n"; + efficiencyTable( TrigTauSelectionManager::MENU1400, TrigTauSelectionManager::LOOSE); + cout << "\n\n +++++++++++++++ MEDIUM ++++++++++++++++++++\n\n\n"; + efficiencyTable( TrigTauSelectionManager::MENU1400, TrigTauSelectionManager::MEDIUM); + cout << "\n\n +++++++++++++++ TIGHT ++++++++++++++++++++\n\n\n"; + efficiencyTable( TrigTauSelectionManager::MENU1400, TrigTauSelectionManager::TIGHT); +} + + + +void efficiencyTable(TrigTauSelectionManager::MENUVERSION version , + TrigTauSelectionManager::CUTLEVEL cutLevel) +{ + + cout << "======================== J0 sample ====================\n"; + efficiencyTable(5009,0, version, cutLevel); + TH1F * hJ0 = ((TH1F*)gROOT->Get("hEff"))->Clone("hJ0"); + cout << "======================== J1 sample ====================\n"; + efficiencyTable(5010,0, version, cutLevel); + TH1F * hJ1 = ((TH1F*)gROOT->Get("hEff"))->Clone("hJ1"); + cout << "======================== J2 sample ====================\n"; + efficiencyTable(5011,0, version, cutLevel); + TH1F * hJ2 = ((TH1F*)gROOT->Get("hEff"))->Clone("hJ2"); + cout << "======================== J3 sample ====================\n"; + efficiencyTable(5012,0, version, cutLevel); + TH1F * hJ3 = ((TH1F*)gROOT->Get("hEff"))->Clone("hJ3"); + cout << "======================== W sample ====================\n"; + efficiencyTable(5107,1, version, cutLevel); + TH1F * h5107 = ((TH1F*)gROOT->Get("hEff"))->Clone("h5107"); + cout << "======================== Z sample ====================\n"; +// efficiencyTable(5188,1, version, cutLevel); +// cout << "======================== A(m=800) sample ====================\n"; +// efficiencyTable(5862,1, version, cutLevel); + + cout << "==============================================================\n"; + hJ0->Scale(hJ0->GetBinContent(1)); + hJ1->Scale(hJ1->GetBinContent(1)); + hJ2->Scale(hJ2->GetBinContent(1)); + hJ3->Scale(hJ3->GetBinContent(1)); + int nDec = hJ0->GetNbinsX(); + for(unsigned int itau = 1 ; itau < nDec+1 ; ++itau) + { + if( TString(hDec->GetXaxis()->GetBinLabel(itau)).Length() == 0 ) + { cout << "\\hline \n"; continue;} + float rate = oGetRate(hJ0->GetBinContent(itau),hJ1->GetBinContent(itau), + hJ2->GetBinContent(itau),hJ3->GetBinContent(itau), false); + cout << "\\sig\{" << std::setw(15)<<hJ0->GetXaxis()->GetBinLabel(itau) << "} \& " + << std::setprecision(3)<< rate << endl; + //if( itau == 2 || itau == singleOffset+nTauSingle || + // itau == tautauOffset+nTauTau || itau==taumetOffset+nTauMet || + // itau== taueOffset+nTauE || itau==taumuOffset+nTauMu || itau==tauJetOffset+nTauJet + // ) cout << " \\hline \n"; + } + + + + +} + + +void efficiencyTable(int id, int signal = 0, + TrigTauSelectionManager::MENUVERSION version, + TrigTauSelectionManager::CUTLEVEL cutLevel + )//, TTree * tree) +{ + + bool doDouble = 1; + bool doTauMet = 0; + bool doTauE = 0; + bool doTauMu = 0; + bool doTauJet = 0; + + + + + + int nDec = 1; // 0 bin is all events + + //Tau chains + nDec++; + int singleOffset = nDec; + const unsigned int nTauSingle = 9; + TrigTauFlags::TRIGGERMENU bits[nTauSingle] = { TrigTauFlags::TAU12, + TrigTauFlags::TAU16I, TrigTauFlags::TAU16I, + TrigTauFlags::TAU29I, TrigTauFlags::TAU38, + TrigTauFlags::TAU38I, TrigTauFlags::TAU50, + TrigTauFlags::TAU84, TrigTauFlags::TAU125}; + bool passedSingle[nTauSingle]; + + nDec += nTauSingle; + + // 2taus + nDec++; + int tautauOffset = nDec; + const unsigned int nTauTau = 5; + TString tauTauNames[nTauTau] = { "2tau12", + "2tau20i", + "2tau29i", + "tau12\\_tau29i", + "tau12\\_tau38"}; + nDec +=nTauTau; + + + // TAU+met + nDec++; + int taumetOffset = nDec; + const int nTauMet = 14; + TString tauMetNames[nTauMet] = { "tau12\\_xE20", + "tau16i\\_xE30", + "tau16i\\_EFxE30", + "tau16i\\_EFxE50", + "tau16i\\_xE70", + "tau16i\\_EFxE70", + "tau20i\\_xE30", + "tau29i\\_xE20", + "tau29i\\_xE30", + "tau29i\\_xE40", + "tau29i\\_EFxE40", + "tau38\\_xE20", + "tau38\\_xE40", + "tau38\\_EFxE40" + }; + nDec+=nTauMet; + + // tau+e + nDec++; + int taueOffset = nDec; + const int nTauE = 6; + TString tauENames[nTauE] = { "tau12\\_e10", + "tau16i\\_e10", + "tau16i\\_e15i", + "tau20i\\_e10", + "tau20i\\_e15i", + "tau20i\\_e25i"}; + nDec += nTauE; + + // tau+mu + nDec++; + int taumuOffset = nDec; + const int nTauMu = 5; + TString tauMuNames[nTauMu] = {"tau16i\\_mu6", + "tau16i\\_mu10", + "tau20i\\_mu6", + "tau20i\\_mu10", + "tau20i\\_mu20"}; + nDec += nTauMu; + + // tau+jets + int tauJetOffset = nDec; + const int nTauJet = 6; + TString tauJetNames[nTauJet] = {"tau16i\\_j70", + "tau16i\\_3j23", + "tau16i\\_4j23", + "tau20i\\_4j50", + "tau16i\\_xE30\\_j18", + "tau16i\\_xE30\\_j35"}; + nDec += nTauJet; + + + TH1F * hDec = new TH1F("hDec","Passed trigger",nDec+1, -0.5, nDec+0.5); + hDec->GetXaxis()->SetBinLabel(1,"offline tau"); + for(unsigned int itau = 0; itau < nTauSingle; ++itau ) + { + TString name = TrigTauFlags::menuName(bits[itau]); + hDec->GetXaxis()->SetBinLabel(singleOffset+itau+1,name); + } + for(unsigned int itau = 0; itau < nTauTau; ++itau ) + hDec->GetXaxis()->SetBinLabel(tautauOffset+itau+1, tauTauNames[itau]); + for(unsigned int itau = 0; itau < nTauMet; ++itau ) + hDec->GetXaxis()->SetBinLabel(taumetOffset+itau+1, tauMetNames[itau]); + for(unsigned int itau = 0; itau < nTauE; ++itau ) + hDec->GetXaxis()->SetBinLabel(taueOffset+itau+1, tauENames[itau]); + for(unsigned int itau = 0; itau < nTauMu; ++itau ) + hDec->GetXaxis()->SetBinLabel(taumuOffset+itau+1, tauMuNames[itau]); + for(unsigned int itau = 0; itau < nTauJet; ++itau ) + hDec->GetXaxis()->SetBinLabel(tauJetOffset+itau+1, tauJetNames[itau]); + hDec->LabelsOption("v"); + + TH1F * hMC = hDec->Clone("hMC"); hMC->SetTitle(" passed MC acceptance"); + hMC->LabelsOption("v"); + + + + + //------------------------------------------------------------------------- + //TrigTauSelectionManager::MENUVERSION version = TrigTauSelectionManager::MENU13030pre; + + + TrigTauBugFix bugfix (TrigTauBugFix::TTP9, TrigTauBugFix::RDO); + //bugfix.setTTPVersion(filename); + + //------------------------------------------------------------------------- + // Now work with events + + int nprong = 0; + bool checkOffline = true; + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::EITHERTAU; + + TrigTauAnalyzer analyzer; + analyzer.trigMan.setMenuVersion(version); + analyzer.trigMan.setTauMenu(TrigTauFlags::TAU16I, cutLevel); + + analyzer.truthList.setMaxVisEta(2.5); + analyzer.truthList.setMinVisPt(10.); + if( nprong == 1 ) analyzer.truthList.select1Prong(); + else if( nprong == 3 ) analyzer.truthList.select3Prong(); + analyzer.truthList.setRecoMatchdR(0.2); + + + TChain * tree = new TChain("eventTree"); + bool filter= true; + if( version == TrigTauSelectionManager::MENU13030pre ) + oSampleTTP06(id, tree); + else { + // oSampleTTP06_dR03(id, tree); + oSampleTTP09(id, tree); + filter = false; + } + + if (tree == 0) {cerr << "Can't find eventTree in " << filename << endl; return 0; } + + TrigTauEvent* event = new TrigTauEvent(); + + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + + //=================== loop over events ======================================= + int nEvent = 0; + int nev = int(tree->GetEntries()); + //if( nev > 1000 ) nev = 1000; + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + bugfix.fix(event); + hMC->Fill(0); + + if( !signal && !event->decision.passedL1(TrigTauFlags::TAU12) ) + { + //nEvent++; + //hDec->Fill(0); + continue; + } + + analyzer.analyze(event, signal, offlineType); + + // ============ Select type of events (e.g. signal) ================ + if( signal && analyzer.truthList.nMCTauGood() ==0 ) continue; + nEvent++; + hDec->Fill(0); + + + float leadingTauPt = 0; + if( analyzer.truthList.leadingPtGoodTau() ) + leadingTauPt = analyzer.truthList.leadingPtGoodTau()->visible().Pt(); + float nextTauPt = 0; + if(analyzer.truthList.nextPtGoodTau() ) + nextTauPt = analyzer.truthList.nextPtGoodTau()->visible().Pt(); + //cout << leadingTauPt << endl; + + // now look for leptons + int nMC = event->nMC(); + float leadingEPt = 0; + float leadingMuPt = 0; + for(unsigned int iMC = 0; iMC < nMC; ++iMC) + { + TrigTauTrueParticle * part = &event->MCEntry(iMC); + if( part == 0 ) continue; + int lund = abs(part->pdgId()); + //cout << " lund " << lund << endl; + if(lund != 11 && lund != 13 ) continue; + + // offline match + if( lund == 11 ){ + int nElectron = event->offlineEvent.nElectrons(); + for(unsigned int iElectron = 0; iElectron < nElectron; ++iElectron) + { + TrigTauElectron * elec = &event->offlineEvent.electronEntry(iElectron); + if( part->DeltaR(*elec) > 0.2 ) continue; + // offline match is found! + float pt = elec->Pt(); + if( pt > leadingEPt ) leadingEPt =pt; + } + + } + if( lund == 13 ){ + int nMuon = event->offlineEvent.nMuons(); + for(unsigned int iMuon = 0; iMuon < nMuon; ++iMuon) + { + TrigTauMuon * muon = &event->offlineEvent.muonEntry(iMuon); + if( part->DeltaR(*muon) > 0.2 ) continue; + // offline match is found! + float pt = muon->Pt(); + if( pt > leadingMuPt ) leadingMuPt =pt; + } + } + } + + float jetPt[10]; + for(unsigned int i=0; i<10; ++i) + jetPt[i] = 0; + int nJet = event->offlineEvent.nJets(); + int jetPtfilled = 0; + for(unsigned int iJet = 0; iJet < nJet; ++iJet) + { + TLorentzVector * jet = &event->offlineEvent.jetEntry(iJet); + //remove overlap with leading tau + if( analyzer.truthList.leadingPtGoodTau() && + jet->DeltaR( analyzer.truthList.leadingPtGoodTau()->visible()) < 0.2 ) + continue; + + //match to truth + int ntrueJet = event->mcEvent.nTrueJets(); + bool matched = false; + for(unsigned int itruejet = 0; !matched && itruejet < ntrueJet; ++itruejet) + { + if( jet->DeltaR( event->mcEvent.trueJetsEntry(itruejet)) < 0.2) + matched = true; + } + if( !matched) continue; + + + + if( jetPtfilled < 10 ) + { + jetPt[jetPtfilled] = jet->Pt(); + jetPtfilled++; + }else{ + float pt = jet->Pt(); + mysort(jetPt); + if( jetPt[9] > pt ) jetPt[9] = pt; + } + } //end loop over jets + + mysort(jetPt); + + //================================================================== + // single taus : + for(unsigned int itau1 = 0; itau1 < nTauSingle; ++itau1) + { + passedSingle[itau1] = false; + if( signal && !passedTauPt( leadingTauPt, bits[itau1] ) ) continue; + int ibin = singleOffset+itau1; + hMC->Fill(float(ibin)); + + TrigTauSelectionManager trigMan; + trigMan.setMenuVersion(version); + trigMan.setTauMenu(bits[itau1],cutLevel); + + bool noCandidate = true; + + unsigned int numCh = analyzer.chainList.nTrigChains(); + unsigned int nOther = event->nOtherTrigRoI(); + for (unsigned int iCh1=0; noCandidate && iCh1 < numCh; iCh1++) { + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + //cout << " tries \n"; + if (trigMan.passedEF(ch1))noCandidate = false; + //if( !noCandidate ) cout << " found !!!!!! \n"; + } + + if( !noCandidate ){ hDec->Fill(float(ibin)); passedSingle[itau1] = true; } + } // end single tau + + // 2tau FIRST low PT, then High PT + if( doDouble ) { + checkTauTau(analyzer, event, leadingTauPt, nextTauPt,tautauOffset+0, hMC,hDec, TrigTauFlags::TAU12, TrigTauFlags::TAU12,version, cutLevel,signal, passedSingle[3], passedSingle[3] ); + checkTauTau(analyzer, event, leadingTauPt, nextTauPt,tautauOffset+1, hMC,hDec, TrigTauFlags::TAU20I, TrigTauFlags::TAU20I,version, cutLevel,signal, passedSingle[5], passedSingle[5]); + checkTauTau(analyzer, event, leadingTauPt, nextTauPt,tautauOffset+2, hMC,hDec, TrigTauFlags::TAU29I, TrigTauFlags::TAU29I,version, cutLevel,signal, passedSingle[6], passedSingle[6]); + checkTauTau(analyzer, event, leadingTauPt, nextTauPt,tautauOffset+3, hMC,hDec, TrigTauFlags::TAU10I, TrigTauFlags::TAU38, version, cutLevel,signal, passedSingle[1], passedSingle[7]); + checkTauTau(analyzer, event, leadingTauPt, nextTauPt,tautauOffset+4, hMC,hDec, TrigTauFlags::TAU12, TrigTauFlags::TAU29I,version, cutLevel,signal, passedSingle[3], passedSingle[6]); + checkTauTau(analyzer, event, leadingTauPt, nextTauPt,tautauOffset+5, hMC,hDec, TrigTauFlags::TAU12, TrigTauFlags::TAU38, version, cutLevel,signal, passedSingle[3], passedSingle[7]); + } + // tau+MET + if( doTauMet ) { + int ibintaumet = taumetOffset; + checkTauMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU15, TrigTauFlags::MET20, version, cutLevel,signal, passedSingle[3]); + checkTauMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::MET30, version, cutLevel,signal, passedSingle[4]); + checkTauEFMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::MET30, version, cutLevel,signal, passedSingle[4]); + checkTauEFMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::MET50, version, cutLevel,signal, passedSingle[4]); + checkTauMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::MET70, version, cutLevel,signal, passedSingle[4]); + checkTauEFMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::MET70, version, cutLevel,signal, passedSingle[4]); + + checkTauMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU20I, TrigTauFlags::MET30, version, cutLevel,signal, passedSingle[5]); + checkTauMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU29I, TrigTauFlags::MET20, version, cutLevel,signal, passedSingle[6]); + checkTauMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU29I, TrigTauFlags::MET30, version, cutLevel,signal, passedSingle[6]); + checkTauMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU29I, TrigTauFlags::MET40, version, cutLevel,signal, passedSingle[6]); + checkTauEFMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU29I, TrigTauFlags::MET40, version, cutLevel,signal, passedSingle[6]); + checkTauMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU38, TrigTauFlags::MET20, version, cutLevel,signal, passedSingle[8]); + checkTauMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU38, TrigTauFlags::MET40, version, cutLevel,signal, passedSingle[7]); + checkTauEFMET(analyzer, event, leadingTauPt, ibintaumet++, hMC, hDec, TrigTauFlags::TAU38, TrigTauFlags::MET40, version, cutLevel,signal, passedSingle[7]); + } + + // tau+lep + if( doTauE ) { + checkTauE(analyzer, event, leadingTauPt, leadingEPt,taueOffset+0, hMC, hDec, TrigTauFlags::TAU12, TrigTauFlags::E10,version, cutLevel,signal, passedSingle[3]); + checkTauE(analyzer, event, leadingTauPt, leadingEPt,taueOffset+1, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::E10,version, cutLevel,signal, passedSingle[4]); + checkTauE(analyzer, event, leadingTauPt, leadingEPt,taueOffset+2, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::E15I,version, cutLevel,signal, passedSingle[4]); + checkTauE(analyzer, event, leadingTauPt, leadingEPt,taueOffset+3, hMC, hDec, TrigTauFlags::TAU20I, TrigTauFlags::E10,version, cutLevel,signal, passedSingle[5]); + checkTauE(analyzer, event, leadingTauPt, leadingEPt,taueOffset+4, hMC, hDec, TrigTauFlags::TAU20I, TrigTauFlags::E15I,version, cutLevel,signal, passedSingle[5]); + checkTauE(analyzer, event, leadingTauPt, leadingEPt,taueOffset+5, hMC, hDec, TrigTauFlags::TAU20I, TrigTauFlags::E25I,version, cutLevel,signal, passedSingle[5]); + } + if( doTauMu ) { + checkTauMu(analyzer, event, leadingTauPt, leadingMuPt, taumuOffset+0, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::MU6, version, cutLevel,signal, passedSingle[4]); + checkTauMu(analyzer, event, leadingTauPt, leadingMuPt, taumuOffset+1, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::MU10, version, cutLevel,signal, passedSingle[4]); + checkTauMu(analyzer, event, leadingTauPt, leadingMuPt, taumuOffset+2, hMC, hDec, TrigTauFlags::TAU20I, TrigTauFlags::MU6, version, cutLevel,signal, passedSingle[5]); + checkTauMu(analyzer, event, leadingTauPt, leadingMuPt, taumuOffset+3, hMC, hDec, TrigTauFlags::TAU20I, TrigTauFlags::MU10, version, cutLevel,signal, passedSingle[5]); + checkTauMu(analyzer, event, leadingTauPt, leadingMuPt, taumuOffset+4, hMC, hDec, TrigTauFlags::TAU20I, TrigTauFlags::MU20, version, cutLevel,signal, passedSingle[5]); + } + +// // tau+jet + if( doTauJet ) { + checkTauJet(analyzer, event, leadingTauPt, jetPt, tauJetOffset+0, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::J70, version, cutLevel,signal, passedSingle[4]); + checkTauJet(analyzer, event, leadingTauPt, jetPt, tauJetOffset+1, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::THREEJ18, version, cutLevel,signal, passedSingle[4]); // 23 in reality + checkTauJet(analyzer, event, leadingTauPt, jetPt, tauJetOffset+2, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::FOURJ23, version, cutLevel,signal, passedSingle[4]); + checkTauJet(analyzer, event, leadingTauPt, jetPt, tauJetOffset+3, hMC, hDec, TrigTauFlags::TAU20I, TrigTauFlags::FOURJ50, version, cutLevel,signal, passedSingle[5]); + + checkTauJetEFMET(analyzer, event, leadingTauPt, jetPt, tauJetOffset+4, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::J18, TrigTauFlags::MET30, version, cutLevel,signal, passedSingle[4]); + checkTauJetEFMET(analyzer, event, leadingTauPt, jetPt, tauJetOffset+5, hMC, hDec, TrigTauFlags::TAU16I, TrigTauFlags::J35, TrigTauFlags::MET30, version, cutLevel,signal, passedSingle[4]); + + + } + + } // end loop over events + + delete event; + gROOT->cd(); + TH1F * hEff = (TH1F*)gROOT->Get("hEff"); + if( hEff) delete hEff; + hEff = (TH1F*)hDec->Clone("hEff"); hEff->SetTitle(" Trigger efficiency for good MC events"); + for(unsigned int itau = 1 ; itau < nDec+1 ; ++itau) + { + float eff = 0; float errEff = 0; + if( hMC->GetBinContent(itau) > 0 ) + { + eff = float(hDec->GetBinContent(itau))/float( hMC->GetBinContent(itau)); + errEff = sqrt(eff*(1.-eff)/float( hMC->GetBinContent(itau))); + //eff *= 100.; + //errEff *= 100.; + hEff->SetBinContent(itau, eff); + hEff->SetBinError(itau, errEff); + } + } + + // ------------------- print ---------------------------------------- + if(id == 5188 && signal == 1) + cout << "$Z\\to\\tau\\tau$\n"; + else if(id == 5200 && signal == 1) + cout << "$t\\bar{t}$ \n"; + else if(id == 5402 && signal == 1) + cout << "SU2 \n"; + else if(id == 5403 && signal == 1) + cout << "SU3 \n"; + else if(id == 5107 && signal == 1) + cout << "$W\\to\\tau\\nu$ \n"; + + cout << " Select " << nEvent << " interesting events out of " << nev << " total \n"; + + cout << " Item \& nMC \& trigger efficiency \& Nevents/100 \\ipb \\\\ \n"; + cout << " \\hline \n"; + cout.setf(ios_base::fixed,ios_base::floatfield); + for(unsigned int itau = 1 ; itau < nDec+1 ; ++itau) + { + if( TString(hDec->GetXaxis()->GetBinLabel(itau)).Length() == 0 ) + { cout << "\\hline \n"; continue;} + cout.setf(ios_base::left,ios_base::adjustfield ); + cout << "\\sig\{" << std::setw(15)<<hDec->GetXaxis()->GetBinLabel(itau) << "} \& " ; + + // print number of good MC events + cout << std::setw(7) << int(hMC->GetBinContent(itau)) << " \& "; + + // print trigger efficiency + cout.setf(ios_base::internal,ios_base::adjustfield ); + //if( hEff->GetBinError(itau) > 0.5 ) + //cout << "$" << std::setw(5)<< std::setprecision(0) << hEff->GetBinContent(itau) << " \\pm " + // << std::setw(3)<< std::setprecision(0)<< hEff->GetBinError(itau) << "$" ; + //else + int precision = 8; + cout << "$" << std::setw(5)<< std::setprecision(precision) << hEff->GetBinContent(itau) << " \\pm " + << std::setw(3)<< std::setprecision(precision)<< hEff->GetBinError(itau) << "$" ; + + // print number of events in 100 pb^-1 + float n100pb = getRate( id, hEff->GetBinContent(itau)/100.* hMC->GetBinContent(itau)/nev, filter); + + if( n100pb > 100 ) cout << " \& " << std::setw(6) <<int(n100pb) ; + else cout << " \& " << std::setw(6) <<std::setprecision(2)<< n100pb ; + + + cout << " \\\\ \n"; + //if( itau == 2 || itau == singleOffset+nTauSingle || + // itau == tautauOffset+nTauTau || itau==taumetOffset+nTauMet || + // itau== taueOffset+nTauE || itau==taumuOffset+nTauMu || itau==tauJetOffset+nTauJet + // ) cout << " \\hline \n"; + } + + // --------------------- plot ---------------------------- + gStyle->SetPadBottomMargin(0.4); + + hEff->LabelsOption("v"); + hEff->Draw(); + + return ; + +} + +void checkTauMET(TrigTauAnalyzer& analyzer, + TrigTauEvent * event, float leadingTauPt, + int ibin, TH1F * hMC, TH1F * hDec, + TrigTauFlags::TRIGGERMENU tauItem, + TrigTauFlags::TRIGGERMENU metItem, + TrigTauSelectionManager::MENUVERSION version, + TrigTauSelectionManager::CUTLEVEL cutLevel , bool signal, + bool passedTau) +{ + bool mcGood = false; + bool EFGood = false; + passedMET(event, metItem, mcGood, EFGood); + + + mcGood &= passedTauPt(leadingTauPt, tauItem); + + if( signal && !mcGood ) return; + + hMC->Fill(ibin); + if( EFGood && + //event->decision.passedEF( metItem) && + event->decision.passedL1( metItem)&& passedTau ) + hDec->Fill(ibin); +} + +void checkTauEFMET(TrigTauAnalyzer& analyzer, + TrigTauEvent * event, float leadingTauPt, + int ibin, TH1F * hMC, TH1F * hDec, + TrigTauFlags::TRIGGERMENU tauItem, + TrigTauFlags::TRIGGERMENU metItem, + TrigTauSelectionManager::MENUVERSION version, + TrigTauSelectionManager::CUTLEVEL cutLevel , bool signal, bool passedTau ) +{ + bool mcGood = false; + bool EFGood = false; + passedMET(event, metItem, mcGood, EFGood); + + mcGood &= passedTauPt(leadingTauPt, tauItem); + + if( signal && !mcGood ) return; + + + hMC->Fill(ibin); + if( EFGood && passedTau ) + hDec->Fill(ibin); + +} + + +void checkTauMu(TrigTauAnalyzer& analyzer, + TrigTauEvent * event, float leadingTauPt, float muonPt, + int ibin, TH1F * hMC, TH1F * hDec, + TrigTauFlags::TRIGGERMENU tauItem, + TrigTauFlags::TRIGGERMENU muItem, + TrigTauSelectionManager::MENUVERSION version, + TrigTauSelectionManager::CUTLEVEL cutLevel, bool signal , bool passedTau) +{ + bool mcGood = false; + switch ( muItem ) + { + case TrigTauFlags::MU4 : mcGood = muonPt>4000 ; break; + case TrigTauFlags::MU6 : mcGood = muonPt>6000 ; break; + case TrigTauFlags::MU6L : mcGood = muonPt>6000 ; break; + case TrigTauFlags::MU8 : mcGood = muonPt>8000 ; break; + case TrigTauFlags::MU10 : mcGood = muonPt>10000 ; break; + case TrigTauFlags::MU15 : mcGood = muonPt>15000 ; break; + case TrigTauFlags::MU20 : mcGood = muonPt>20000 ; break; + case TrigTauFlags::TWOMU6 : mcGood = muonPt>6000 ; break; + case TrigTauFlags::TWOMU20 : mcGood = muonPt>20000 ; break; + case TrigTauFlags::THREEMU6 : mcGood = muonPt>6000 ; break; + default : + cout << " ERROR checkTauMu : unknown menu " << TrigTauFlags::menuName(muItem) << endl; + } + + + mcGood &= passedTauPt(leadingTauPt, tauItem); + + if( signal && !mcGood ) return; + + + hMC->Fill(ibin); + + // look now if there is other RoI of proper type + unsigned int nOther = event->nOtherTrigRoI(); + bool noCandidate = true; + for( unsigned int iMuon = 0; noCandidate && iMuon < nOther; ++iMuon) + { + TrigTauRoI * muon = &event->otherTrigRoIEntry(iMuon); + if( !muon->m_tags.passedEF(muItem) ) continue; + noCandidate = false; + } + if( noCandidate ) return; + // now taus + if( !passedTau) return; + + hDec->Fill(ibin); + +} + + + + +void checkTauE(TrigTauAnalyzer& analyzer, + TrigTauEvent * event, float leadingTauPt, float elecPt, + int ibin, TH1F * hMC, TH1F * hDec, + TrigTauFlags::TRIGGERMENU tauItem, + TrigTauFlags::TRIGGERMENU eItem, + TrigTauSelectionManager::MENUVERSION version, + TrigTauSelectionManager::CUTLEVEL cutLevel, bool signal, bool passedTau ) +{ + bool mcGood = false; + switch ( eItem ) + { + case TrigTauFlags::E10 : mcGood = elecPt>10000 ; break; + case TrigTauFlags::E15 : mcGood = elecPt>15000 ; break; + case TrigTauFlags::E15I : mcGood = elecPt>15000 ; break; + case TrigTauFlags::E20 : mcGood = elecPt>20000 ; break; + case TrigTauFlags::E20I : mcGood = elecPt>20000 ; break; + case TrigTauFlags::E25 : mcGood = elecPt>25000 ; break; + case TrigTauFlags::E25I : mcGood = elecPt>25000 ; break; + case TrigTauFlags::E60 : mcGood = elecPt>60000 ; break; + default : + cout << " ERROR checkTauMu : unknown menu " << TrigTauFlags::menuName(muItem) << endl; + } + + mcGood &= passedTauPt(leadingTauPt, tauItem); + if(signal && !mcGood ) return; + + hMC->Fill(ibin); + + if( !passedTau )// || !event->decision.passedEF( eItem) ) + return; + + // now check for overlap + TrigTauSelectionManager trigMan; + trigMan.setMenuVersion(version); + trigMan.setTauMenu(tauItem,cutLevel); + + bool noCandidate = true; + + unsigned int numCh = analyzer.chainList.nTrigChains(); + unsigned int nOther = event->nOtherTrigRoI(); + for (unsigned int iCh1=0; noCandidate && iCh1 < numCh; iCh1++) { + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + + if (!trigMan.passedEF(ch1)) continue; + + for( unsigned int iElec = 0; noCandidate && iElec < nOther; ++iElec) + { + TrigTauRoI * elec = &event->otherTrigRoIEntry(iElec); + if( !elec->m_tags.passedEF(eItem) ) continue; + + if( elec->DeltaR(*ch1.EF) > 0.1 ) + noCandidate = false; // FOUND! + } + + } + + if( noCandidate == false ) hDec->Fill(ibin); + +} + + +void checkTauTau(TrigTauAnalyzer& analyzer, + TrigTauEvent * event, float leadingTauPt, float nextTauPt, + int ibin, TH1F * hMC, TH1F * hDec, + TrigTauFlags::TRIGGERMENU tauLowPtItem, + TrigTauFlags::TRIGGERMENU tauHighPtItem, + TrigTauSelectionManager::MENUVERSION version, + TrigTauSelectionManager::CUTLEVEL cutLevel, bool signal, bool passedLow, bool passedHigh) +{ + bool mcGood = passedTauPt(leadingTauPt, tauHighPtItem) & passedTauPt(nextTauPt, tauLowPtItem); + if( signal && !mcGood ) return; + + hMC->Fill(ibin); + + + if( !passedHigh ) // || !event->decision.passedEF( eItem) ) + return; + + // now check for overlap + TrigTauSelectionManager trigManLow; + trigManLow.setMenuVersion(version); + trigManLow.setTauMenu(tauLowPtItem,cutLevel); + + TrigTauSelectionManager trigManHigh; + trigManHigh.setMenuVersion(version); + trigManHigh.setTauMenu(tauHighPtItem,cutLevel); + + bool noCandidate = true; + + unsigned int numCh = analyzer.chainList.nTrigChains(); + unsigned int nOther = event->nOtherTrigRoI(); + for (unsigned int iCh1=0; noCandidate && iCh1 < numCh; iCh1++) { + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + + if (!trigManLow.passedEF(ch1)) continue; + + for (unsigned int iCh2=iCh1+1; noCandidate && iCh2 < numCh; iCh2++) { + TrigTauTrigChain ch2 = analyzer.chainList.trigChainEntry(iCh2); + if (!trigManHigh.passedEF(ch2)) continue; + noCandidate = false; + } + } + + if( noCandidate == false ) hDec->Fill(ibin); + +} + +bool passedMET(TrigTauEvent * event, TrigTauFlags::TRIGGERMENU metItem, bool & mcGood, bool & EFGood ) +{ + mcGood = false; + float trueMET = event->mcEvent.etMissTrue.m_EtMiss; + float offlineMET = event->offlineEvent.etMissRecFinal.m_EtMiss; + float trigMET = event->etMissEF.m_EtMiss; + + EFGood = false; + switch ( metItem ) + { + case TrigTauFlags::MET15 : mcGood = (trueMET > 15000 && offlineMET > 15000 ); + EFGood = trigMET>15000; break; + case TrigTauFlags::MET20 : mcGood = (trueMET > 20000 && offlineMET > 20000 ); + EFGood = trigMET>20000; break; + case TrigTauFlags::MET25 : mcGood = (trueMET > 25000 && offlineMET > 25000 ); + EFGood = trigMET>25000; break; + case TrigTauFlags::MET30 : mcGood = (trueMET > 30000 && offlineMET > 30000 ); + EFGood = trigMET>30000; break; + case TrigTauFlags::MET40 : mcGood = (trueMET > 40000 && offlineMET > 40000 ); + EFGood = trigMET>40000; break; + case TrigTauFlags::MET50 : mcGood = (trueMET > 50000 && offlineMET > 50000 ); + EFGood = trigMET>50000; break; + case TrigTauFlags::MET70 : mcGood = (trueMET > 70000 && offlineMET > 70000 ); + EFGood = trigMET>70000; break; + case TrigTauFlags::MET80 : mcGood = (trueMET > 80000 && offlineMET > 80000 ); + EFGood = trigMET>80000; break; + default : + cout << " ERROR checkTauMET : unknown menu " << TrigTauFlags::menuName(metItem) << endl; + } + return EFGood; +} + + +bool passedTauPt(float leadingTauPt, TrigTauFlags::TRIGGERMENU tauItem) +{ + leadingTauPt= TrigTauMCTauList::nominalMinVisPt(tauItem)*1000.; + return true; + +} + +float getRate(OTRIGTAU::OSampleTypes type, float eff, bool filter) +{ + + float scaleFactor = 1; + if (filter) + if( type == OTRIGTAU::J0 ) scaleFactor=0.08781; // for TTP06 only! + else if( type == OTRIGTAU::J1 ) scaleFactor=0.4443; // for TTP06 only! + else if( type == 5001 ) scaleFactor=0.034947; + + switch (type) + { + case 5001 : return eff* 670000*scaleFactor; // 0.67e+6 // filtere + case OTRIGTAU::J0 : return eff* 174000*scaleFactor; + case OTRIGTAU::J1 : return eff* 13800*scaleFactor; + case OTRIGTAU::J2 : return eff* 933; + case OTRIGTAU::J3 : return eff* 58.8; + case 5013 : return eff* 3.08; + case 5014 : return eff* 0.125; + case 5015 : return eff* 0.00360; + + case 5107 : return eff * 17.3*0.32*100000.; // 17.3 nb for 100 pb^-1 + case 5188 : return eff * 1.64*0.15*100000.; // nb for 100 pb^-1 + case 5189 : return eff * 1.58*0.29*100000.; // nb for 100 pb^-1 + case 5116 : return eff * 1.58*0.29*100000.; // nb for 100 pb^-1 + case 5200 : return eff * 854*0.54*100 ; // pb for 100 pb^-1 + + case 5401 : return eff *7.43 *100 ; // pb for 100 pb^-1 + case 5402 : return eff *4.86 *100 ; // pb for 100 pb^-1 + case 5403 : return eff *18.59*100 ; // pb for 100 pb^-1 + case 6400 : return eff *262 *100 ; // pb for 100 pb^-1 + case 5404 : return eff *4.48 *100 ; // pb for 100 pb^-1 + case 5862 : return eff *63.3 *0.1 ; // fb for 100 pb^-1 Wolfgang asnwers via tauWG HN + case 5334 : return eff *0.145 *100 ; // pb for 100 pb^-1 https://twiki.cern.ch/twiki/bin/view/Atlas/VBFHTauTau + case 5338 : return eff *0.073 *100 ; // pb for 100 pb^-1 https://twiki.cern.ch/twiki/bin/view/Atlas/VBFHTauTau + + // case 5338 : return eff * 212*0.237*0.1 ; // fb for 100 pb^-1 + + + default : + std::cout << "Do not know how to estimate rate for process " << type << std::endl; + return 1; + } + return 0; +} + +float getRate(float effJ0, float effJ1, float effJ2, float effJ3, bool filter) +{ + float rate = getRate(OTRIGTAU::J0 , effJ0,filter) + getRate(OTRIGTAU::J1 , effJ1,filter) + + getRate(OTRIGTAU::J2 , effJ2,filter) + getRate(OTRIGTAU::J3 , effJ3,filter); + return rate; +} + +void checkTauJet(TrigTauAnalyzer& analyzer, + TrigTauEvent * event, float leadingTauPt, float jetPt[10], + int ibin, TH1F * hMC, TH1F * hDec, + TrigTauFlags::TRIGGERMENU tauItem, + TrigTauFlags::TRIGGERMENU jetItem, + TrigTauSelectionManager::MENUVERSION version, + TrigTauSelectionManager::CUTLEVEL cutLevel, bool signal, bool passedTau) +{ + bool mcGood = false; + int nJet = 0; + float minJet = 0; + switch ( jetItem ) + { + case TrigTauFlags::J35 : mcGood = jetPt[0]>35000 ; + nJet = 1; minJet=35000; break; + case TrigTauFlags::J70 : mcGood = jetPt[0]>70000 ; + nJet = 1; minJet=70000; break; + case TrigTauFlags::THREEJ18 : mcGood = jetPt[2]>23000 ; + nJet = 3; minJet=23000; break; + case TrigTauFlags::FOURJ23 : mcGood = jetPt[3]>23000 ; + nJet = 4; minJet=23000; break; + case TrigTauFlags::FOURJ50 : mcGood = jetPt[3]>50000 ; + nJet = 4; minJet=50000;break; + default : + cout << " ERROR checkTauMu : unknown menu " << TrigTauFlags::menuName(muItem) << endl; + } + + if( signal && !mcGood ) return; + mcGood = passedTauPt(leadingTauPt, tauItem); + if( signal && !mcGood ) return; + + hMC->Fill(ibin); + + if( !passedTau )// || !event->decision.passedEF( eItem) ) + return; + + // now check for overlap + TrigTauSelectionManager trigMan; + trigMan.setMenuVersion(version); + trigMan.setTauMenu(tauItem,cutLevel); + + int nCandidate = 0; + + bool found = 0; + + unsigned int numCh = analyzer.chainList.nTrigChains(); + unsigned int nOther = event->nOtherTrigRoI(); + for (unsigned int iCh1=0; !found&& iCh1 < numCh; iCh1++) { + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + + if (!trigMan.passedEF(ch1)) continue; + + for( unsigned int iJet = 0; iJet < nOther; ++iJet) + { + TrigTauRoI * jet = &event->otherTrigRoIEntry(iJet); + if( !jet->isJet() ) continue; + if( jet->Pt() < minJet ) continue; + if( jet->DeltaR(*ch1.EF) > 0.2 ) + nCandidate++; + } + + if( nCandidate >= nJet ) found = true; + } + + if( found ) hDec->Fill(ibin); + +} + +void checkTauJetEFMET(TrigTauAnalyzer& analyzer, + TrigTauEvent * event, float leadingTauPt, float jetPt[10], + int ibin, TH1F * hMC, TH1F * hDec, + TrigTauFlags::TRIGGERMENU tauItem, + TrigTauFlags::TRIGGERMENU jetItem, + TrigTauFlags::TRIGGERMENU metItem, + TrigTauSelectionManager::MENUVERSION version, + TrigTauSelectionManager::CUTLEVEL cutLevel , bool signal, bool passedTau ) +{ + bool mcGood = false; + bool EFGood = false; + passedMET(event, metItem, mcGood, EFGood); + + mcGood &= passedTauPt(leadingTauPt, tauItem); + if( signal & !mcGood) return ; + int nJet = 0; + float minJet = 0; + switch ( jetItem ) + { + case TrigTauFlags::J18 : mcGood = jetPt[0]>18000 ; + nJet = 1; minJet=18000; break; + case TrigTauFlags::J23 : mcGood = jetPt[0]>23000 ; + nJet = 1; minJet=23000; break; + case TrigTauFlags::J35 : mcGood = jetPt[0]>35000 ; + nJet = 1; minJet=35000; break; + case TrigTauFlags::J70 : mcGood = jetPt[0]>70000 ; + nJet = 1; minJet=70000; break; + case TrigTauFlags::J100 : mcGood = jetPt[0]>100000 ; + nJet = 1; minJet=100000; break; + default : + cout << " ERROR checkTauMetJet : unknown menu " << TrigTauFlags::menuName(jetItem) << endl; + } + + + + if( signal && !mcGood ) return; + + + hMC->Fill(ibin); + if( !EFGood || ! passedTau ) return; + + TrigTauSelectionManager trigMan; + trigMan.setMenuVersion(version); + trigMan.setTauMenu(tauItem,cutLevel); + + int nCandidate = 0; + + bool found = 0; + + unsigned int numCh = analyzer.chainList.nTrigChains(); + unsigned int nOther = event->nOtherTrigRoI(); + for (unsigned int iCh1=0; !found&& iCh1 < numCh; iCh1++) { + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + + if (!trigMan.passedEF(ch1)) continue; + + for( unsigned int iJet = 0; iJet < nOther; ++iJet) + { + TrigTauRoI * jet = &event->otherTrigRoIEntry(iJet); + if( !jet->isJet() ) continue; + if( jet->Pt() < minJet ) continue; + if( jet->DeltaR(*ch1.EF) > 0.2 ) + nCandidate++; + } + + if( nCandidate >= nJet ) found = true; + } + + if( found ) hDec->Fill(ibin); + +} + + + + +void mysort(float jetPt[10]){ + // sort + for (unsigned int x=0; x < 9; x++) + for (unsigned int y=0; y < 9-x; y++) + if (jetPt[y] < jetPt[y+1]) + { + float t=jetPt[y]; + jetPt[y]=jetPt[y+1]; + jetPt[y+1]=t; + } +} + + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/makeCosmicPlots.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/makeCosmicPlots.cxx new file mode 100644 index 0000000000000000000000000000000000000000..bcaaad740080af20a4c152964ca5b98c3257cc56 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/makeCosmicPlots.cxx @@ -0,0 +1,32 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +makeCosmicPlots() { + + // Could be either DEFAULT - normal trigger progression + // or RECO_BASED - starts with offline tau + TTPValCosmicPlots tp(TTPValCosmicPlots::RECO_BASED); + + tp.clear(); + + // Define some menu selection + tp.setDefaultVersion(TrigTauSelectionManager::MENU1560); + tp.setSelector(TrigTauFlags::TAUNOCUT); + + // Data sample, here reading from CAF (only from lxplus) + // For MC data replace "Tau/TrigTau" with "EventBranch" + TChain* chain = new TChain("Tau/TrigTau"); + + // Can add as many directories here as desired + chain->Add("root://castoratlas//castor/cern.ch/atlas/atlascerngroupdisk/trig-daq/tau/TTPCosmic09/data09_cos.00138065.physics_L1Calo.merge.NTUP_TRIG.f163_m226/*"); + + tp.fill(chain); + + // Standard plots + tp.draw("r138065_reco.ps"); + + // Efficiency plots + //tp.drawEff("r138065_eff_reco.ps"); + +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/nTrk.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/nTrk.cxx new file mode 100644 index 0000000000000000000000000000000000000000..20151526faeb6efa277b8ab96fa1a7e4286a3788 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/nTrk.cxx @@ -0,0 +1,146 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +int nTrk(const char * fileName) +{ + TFile *fin=TFile::Open(fileName); + TTree *tree=((TTree*)fin->Get("tauRoI")); + + TH1F *hnTrk=new TH1F("hnTrk","nTrk",7,-0.5,6.5); + TH1F *hnTrkOL=new TH1F("hnTrkOL","nTrk (offline)",7,-0.5,6.5); + TH1F *hnTrkEFID=new TH1F("hnTrkEFID","nTrkEFID",7,-0.5,6.5); + TH1F *hnTrkMy=new TH1F("hnTrkMy","nTrkMy",7,-0.5,6.5); + tree->Project("hnTrk","nTrk"); + tree->Project("hnTrkOL","tr_nTrk"); + tree->Project("hnTrkEFID","nTrkEFID"); + tree->Project("hnTrkMy","nTrkMy"); + hnTrk->Scale(1./hnTrk->GetEntries()); + hnTrkOL->Scale(1./hnTrkOL->GetEntries()); + hnTrkEFID->Scale(1./hnTrkEFID->GetEntries()); + hnTrkMy->Scale(1./hnTrkMy->GetEntries()); + hnTrk->SetLineWidth(2.); + hnTrkOL->SetLineWidth(2.); + hnTrkEFID->SetLineWidth(2.); + hnTrkMy->SetLineWidth(2.); + hnTrk->SetLineColor(2); + hnTrkOL->SetLineColor(6); + hnTrkEFID->SetLineColor(4); + hnTrkMy->SetLineColor(3); + + TH1F *hnTrk1=new TH1F("hnTrk1","nTrk (pi)",7,-0.5,6.5); + TH1F *hnTrkOL1=new TH1F("hnTrkOL1","nTrk (pi)",7,-0.5,6.5); + TH1F *hnTrkEFID1=new TH1F("hnTrkEFID1","nTrkEFID (pi)",7,-0.5,6.5); + TH1F *hnTrkMy1=new TH1F("hnTrkMy1","nTrkMy (pi)",7,-0.5,6.5); + tree->Project("hnTrk1","nTrk","mc_decayType==4"); + tree->Project("hnTrkOL1","tr_nTrk","mc_decayType==4"); + tree->Project("hnTrkEFID1","nTrkEFID","mc_decayType==4"); + tree->Project("hnTrkMy1","nTrkMy","mc_decayType==4"); + hnTrk1->Scale(1./hnTrk1->GetEntries()); + hnTrkOL1->Scale(1./hnTrkOL1->GetEntries()); + hnTrkEFID1->Scale(1./hnTrkEFID1->GetEntries()); + hnTrkMy1->Scale(1./hnTrkMy1->GetEntries()); + hnTrk1->SetLineWidth(2.); + hnTrkOL1->SetLineWidth(2.); + hnTrkEFID1->SetLineWidth(2.); + hnTrkMy1->SetLineWidth(2.); + hnTrk1->SetLineColor(2); + hnTrkOL1->SetLineColor(6); + hnTrkEFID1->SetLineColor(4); + hnTrkMy1->SetLineColor(3); + + TH1F *hnTrk3=new TH1F("hnTrk3","nTrk (3pi)",7,-0.5,6.5); + TH1F *hnTrkOL3=new TH1F("hnTrkOL3","nTrk (3pi)",7,-0.5,6.5); + TH1F *hnTrkEFID3=new TH1F("hnTrkEFID3","nTrkEFID (3pi)",7,-0.5,6.5); + TH1F *hnTrkMy3=new TH1F("hnTrkMy3","nTrkMy (3pi)",7,-0.5,6.5); + tree->Project("hnTrk3","nTrk","mc_decayType==5"); + tree->Project("hnTrkOL3","tr_nTrk","mc_decayType==5"); + tree->Project("hnTrkEFID3","nTrkEFID","mc_decayType==5"); + tree->Project("hnTrkMy3","nTrkMy","mc_decayType==5"); + hnTrk3->Scale(1./hnTrk3->GetEntries()); + hnTrkOL3->Scale(1./hnTrkOL3->GetEntries()); + hnTrkEFID3->Scale(1./hnTrkEFID3->GetEntries()); + hnTrkMy3->Scale(1./hnTrkMy3->GetEntries()); + hnTrk3->SetLineWidth(2.); + hnTrkOL3->SetLineWidth(2.); + hnTrkEFID3->SetLineWidth(2.); + hnTrkMy3->SetLineWidth(2.); + hnTrk3->SetLineColor(2); + hnTrkOL3->SetLineColor(6); + hnTrkEFID3->SetLineColor(4); + hnTrkMy3->SetLineColor(3); + + TCanvas * c1 = (TCanvas *) gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","Canvas 1",10,10,700,700); + c1->Divide(2,2); + + c1->cd(1); + hnTrk->Draw(); + hnTrkOL->Draw("same"); + hnTrkEFID->Draw("same"); + hnTrkMy->Draw("same"); + TLegend* leg = new TLegend(0.5,0.50,0.89,0.69); + leg->AddEntry(hnTrk,"nTrack","l"); + leg->AddEntry(hnTrkOL,"offline::nTrack","l"); + leg->AddEntry(hnTrkEFID,"nTrackEFID","l"); + leg->AddEntry(hnTrkMy,"nTrackMy","l"); + leg->Draw(); + + c1->cd(3); + hnTrk1->Draw(); + hnTrkOL1->Draw("same"); + hnTrkEFID1->Draw("same"); + hnTrkMy1->Draw("same"); + + c1->cd(4); + hnTrkOL3->Draw(); + hnTrkMy3->Draw("same"); + hnTrkEFID3->Draw("same"); + hnTrk3->Draw("same"); + + TH1F *hnTrkS1=new TH1F("hnTrkS1","nTrk (calo)",7,-0.5,6.5); + TH1F *hnTrkEFIDS1=new TH1F("hnTrkEFIDS1","nTrkEFID",7,-0.5,6.5); + tree->Project("hnTrkS1","nTrk","seedType==1"); + tree->Project("hnTrkEFIDS1","nTrkEFID","seedType==1"); + // hnTrkS1->Scale(1./hnTrkS1->GetEntries()); + // hnTrkEFIDS1->Scale(1./hnTrkEFIDS1->GetEntries()); + hnTrkS1->SetLineWidth(2.); + hnTrkEFIDS1->SetLineWidth(2.); + hnTrkS1->SetLineColor(2); + hnTrkEFIDS1->SetLineColor(2); + + TH1F *hnTrkS3=new TH1F("hnTrkS3","nTrk (calo)",7,-0.5,6.5); + TH1F *hnTrkEFIDS3=new TH1F("hnTrkEFIDS3","nTrkEFID",7,-0.5,6.5); + tree->Project("hnTrkS3","nTrk","seedType==3"); + tree->Project("hnTrkEFIDS3","nTrkEFID","seedType==3"); + // hnTrkS3->Scale(1./hnTrkS3->GetEntries()); + // hnTrkEFIDS3->Scale(1./hnTrkEFIDS3->GetEntries()); + hnTrkS3->SetLineWidth(2.); + hnTrkEFIDS3->SetLineWidth(2.); + hnTrkS3->SetLineColor(4); + hnTrkEFIDS3->SetLineColor(4); + + TH2F *hnTrk2d=new TH2F("hnTrk2d","nTrkEFID vs. nTrk;nTrk;nTrkEFID", + 7,-0.5,6.5,7,-0.5,6.5); + tree->Project("hnTrk2d","nTrkEFID:nTrk","seedType==3"); + hnTrk2d->SetFillColor(4); + + TCanvas * c2 = (TCanvas *) gROOT->Get("c2"); + if( c2 ) delete c2; + c2 = new TCanvas("c2","Canvas 2",30,30,700,700); + c2->Divide(2,2); + + c2->cd(1); + hnTrkS3->Draw(); + hnTrkS1->Draw("same"); + c2->cd(2); + hnTrkEFIDS3->Draw(); + hnTrkEFIDS1->Draw("same"); + TLegend* leg2 = new TLegend(0.5,0.55,0.89,0.69); + leg2->AddEntry(hnTrkS1,"seed: calo","l"); + leg2->AddEntry(hnTrkS3,"seed: calo+trk","l"); + leg2->Draw(); + c2->cd(3); + hnTrk2d->Draw("box"); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/plotTauData.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/plotTauData.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b3af6afe9106acbbc0b9dd71a245c4e0971055ae --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/plotTauData.cxx @@ -0,0 +1,357 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +int plotTauData(const char * filename, int select = 0, const char * psfile = 0) +{ + TString l2path, efpath; + + if(select == 1 ) { + l2path = "Histogramming/Top-LVL2-L2-Segment-1-Gatherer/EXPERT/"; + efpath = "Histogramming/Top-EF-EBEF-Segment/EXPERT/"; + }else if( select ==2 ) { + l2path = "Histogramming-L2-Segment-1-1-iss/L2PU-1/Histogramming-L2-Segment-1-1-iss.L2PU-1./EXPERT/"; + efpath = "Histogramming-EF-Segment-1-1-iss/PT-1/Histogramming-EF-Segment-1-1-iss.PT-1./EXPERT/"; + }else if( select ==3 ) { + l2path = ""; + efpath = ""; + }else{ + cout << "Usage : \n"; + cout << " .x plotTauData(const char * filename, int select = 0, const char * psfile = 0)\n"; + cout<< " where select = \n"; + cout<< " 1 for online DATA histograms\n" + << " 2 for offline DATA histograms\n" + << " 3 for MC histograms\n"; + return; + + } + + + + + gStyle->SetOptStat(1111111); + //gStyle->SetPadTopMargin(0.2); + gStyle->SetPadGridY(true); + gStyle->SetPadGridX(true); + gStyle->SetStatY(0.6); + gStyle->SetStatStyle(0) ; + //gStyle->SetTitleY(1); + TFile file(filename); + TCanvas * c1 = (TCanvas*)gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,600); + + c1->SetTitle("L2Calo"); + + TString psname; + if( psfile ) psname.Append(psfile); + else psname.Append("tauslice.eps"); + c1->Print(psname+TString("[")); + plotL2Calo(file, psname, l2path); + plotL2ID(file, psname, l2path); + plotL2Final(file, psname, l2path); + plotEF(file,psname,"TrigTauRecMerged_Tau", efpath ); + plotEF(file,psname,"TrigTauRecMerged_Tau_caloOnly", efpath ); + plotEF(file,psname,"TrigTauRec_Tau", efpath ); + plotDec(file, psname, 2, l2path); + plotDec(file, psname, 3, efpath); + c1->Print(psname+TString("]")); + return 0; + +} + +void plotL2Calo(TFile & file, TString & psname, TString path) +{ + TPaveLabel* pl = new TPaveLabel(0.8,0.95,1,1.,"T2CaloTau_Tau"); + pl->SetBorderSize(0); + pl->SetFillStyle(0); + + c1->Divide(2,2); + pl->Draw(); + c1->cd(1); plotHist(file, path+"T2CaloTau_Tau/EtCalib"); + c1->cd(2); plotHist(file, path+"T2CaloTau_Tau/EtRaw"); + c1->cd(3); plotHist(file, path+"T2CaloTau_Tau/RawEtNar"); + c1->Print(psname); + + + c1->cd(1); plotHist(file,path+"T2CaloTau_Tau/EME"); + c1->cd(2); plotHist(file,path+"T2CaloTau_Tau/HadE"); + c1->cd(3); plotHist(file,path+"T2CaloTau_Tau/EMEtNar"); + c1->cd(4); plotHist(file,path+"T2CaloTau_Tau/EMenergyNar"); + c1->Print(psname); + + c1->cd(1); plotHist(file,path+"T2CaloTau_Tau/IsoFrac"); + c1->cd(2); plotHist(file,path+"T2CaloTau_Tau/StripWidth"); + c1->cd(3); plotHist(file,path+"T2CaloTau_Tau/EMRadius"); + c1->cd(4); plotHist(file,path+"T2CaloTau_Tau/EMenergyWid"); + c1->Print(psname); + + c1->Clear(); c1->Divide(2,3); pl->Draw(); + c1->cd(1); plotHist(file,path+"T2CaloTau_Tau/Phi"); + c1->cd(2); plotHist(file,path+"T2CaloTau_Tau/Eta"); + c1->cd(3); plotHist(file,path+"T2CaloTau_Tau/PhiL1_vs_EtaL1","colz"); + c1->cd(4); plotHist(file,path+"T2CaloTau_Tau/EtaL2vsL1"); + c1->cd(5); plotHist(file,path+"T2CaloTau_Tau/PhiL2vsL1"); + // plotHist(file,path+"T2CaloTau_Tau/"); + c1->Print(psname); +} + +void plotL2ID(TFile & file, TString & psname, TString path) +{ + TPaveLabel* pl = new TPaveLabel(0.8,0.95,1,1.,"T2IDTau_Tau"); + pl->SetBorderSize(0); + pl->SetFillStyle(0); + + c1->SetTitle(TString("T2IDTau_Tau")); + + c1->Clear(); + c1->Divide(2,2);pl->Draw(); + c1->cd(1); plotHist(file, path+"T2IDTau_Tau/NTrk"); + c1->cd(2); plotHist(file, path+"T2IDTau_Tau/NTrkIso"); + c1->cd(3); plotHist(file, path+"T2IDTau_Tau/NTrkSlow"); + c1->cd(3); plotHist(file, path+"T2IDTau_Tau/charge"); + c1->Print(psname); + + c1->cd(1); plotHist(file,path+"T2IDTau_Tau/sumPtRatio"); + c1->cd(2); plotHist(file,path+"T2IDTau_Tau/PtMaxTrk"); + c1->cd(3); plotHist(file,path+"T2IDTau_Tau/PhiL1_vs_EtaL1","colz"); + c1->Print(psname); +} + +void plotL2Final(TFile & file, TString & psname, TString path) +{ + TPaveLabel* pl = new TPaveLabel(0.8,0.95,1,1.,"T2TauFinal_Tau"); + pl->SetBorderSize(0); + pl->SetFillStyle(0); + c1->SetTitle(TString("T2TauFinal_Tau")); + + c1->Clear(); + c1->Divide(2,2); pl->Draw(); + c1->cd(1); plotHist(file, path+"T2TauFinal_Tau/NMatchedTracks"); + c1->cd(2); plotHist(file, path+"T2TauFinal_Tau/EtCalibCluster"); + c1->cd(3); plotHist(file, path+"T2TauFinal_Tau/SimpleEtFlow"); + c1->cd(3); plotHist(file, path+"T2TauFinal_Tau/EtCombined"); + c1->Print(psname); + + c1->Clear(); + c1->Divide(2,3);pl->Draw(); + c1->cd(1); plotHist(file,path+"T2TauFinal_Tau/dEtaTrigTau_cluster"); + c1->cd(2); plotHist(file,path+"T2TauFinal_Tau/DeltaEtaTkClust"); + c1->cd(3); plotHist(file,path+"T2TauFinal_Tau/DeltaPhiTkClust"); + c1->cd(4); plotHist(file,path+"T2TauFinal_Tau/PhiL1_vs_EtaL1","colz"); + c1->cd(5); plotHist(file,path+"T2TauFinal_Tau/dPhiTrigTau_cluster"); + c1->cd(6); plotHist(file,path+"T2TauFinal_Tau/DeltaRTkClust"); + c1->Print(psname); +} + +void plotDec(TFile & file, TString & psname ,int level, TString path) +{ + + TH2F * h2; + + TString dir = path+"TrigSteer_L2/"; + TString tag = "L2"; + if( level == 3 ){ + dir = path+"TrigSteer_EF/"; + tag = "EF"; + } + + TPaveLabel* pl = new TPaveLabel(0.8,0.95,1,1.,"TrigSteer_"+tag); + pl->SetBorderSize(0); + pl->SetFillStyle(0); + + c1->Clear(); + plotSteerHist2(file,dir+"ErrorCodes_vs_Chains_"+tag+"_reason","text");pl->Draw(); + c1->Print(psname); + plotSteerHist1(file,dir+"allTEnumber_"+tag+"_runsummary");pl->Draw(); + c1->Print(psname); + plotSteerHist1(file,dir+"alllvl1TEnumber_"+tag+"_runsummary");pl->Draw(); + c1->Print(psname); + plotSteerHist2(file,dir+"alllvl1TEnumberevent_"+tag+"_runsummary","col,text");pl->Draw(); + c1->Print(psname); + plotSteerHist1(file,dir+"m_etaphi_EM_all","text");pl->Draw(); + c1->Print(psname); + + plotSteerHist1(file,dir+"chainAcceptancePT_"+tag+"_runsummary");pl->Draw(); + c1->Print(psname); + plotSteerHist1(file,dir+"chainAcceptancePS_"+tag+"_runsummary");pl->Draw(); + c1->Print(psname); + plotSteerHist1(file,dir+"chainAcceptance_"+tag+"_runsummary");pl->Draw(); + c1->Print(psname); + plotSteerHist2(file,dir+"signatureAcceptance_"+tag+"_runsummary","col,text");pl->Draw(); + c1->Print(psname); +} + + +void plotEF(TFile & file, TString & psname,const char * algo, TString path) +{ + c1->SetTitle(TString("EF")); + TString tag(algo); + + TPaveLabel* pl = new TPaveLabel(0.8,0.95,1,1.,tag); + pl->SetBorderSize(0); + pl->SetFillStyle(0); + + c1->Clear(); + c1->Divide(2,3);pl->Draw(); + c1->cd(1); plotHist(file,path+""+tag+"/nCand"); + c1->cd(2); plotHist(file,path+""+tag+"/NTools"); + c1->cd(3); plotHist(file,path+""+tag+"/EMFrac"); + c1->cd(4); plotHist(file,path+""+tag+"/EF_TauEMRadius"); + c1->cd(5); plotHist(file,path+""+tag+"/EMCalibEt"); + c1->cd(6); plotHist(file,path+""+tag+"/IsoFrac"); + c1->Print(psname); + + c1->Clear(); + c1->Divide(2,2);pl->Draw(); + c1->cd(1); plotHist(file,path+""+tag+"/NTrk"); + c1->cd(2); plotHist(file,path+""+tag+"/PtMaxTrk"); + c1->cd(3); plotHist(file,path+""+tag+"/nRoI_EFTauTracks"); + c1->cd(4); plotHist(file,path+""+tag+"/nRoI_EFTauCells"); + + c1->Print(psname); + + c1->Clear(); + c1->Divide(2,2);pl->Draw(); + c1->cd(1); plotHist(file,path+""+tag+"/PhiL1_vs_EtaL1","colz"); + c1->cd(2); plotHist(file,path+""+tag+"/dPhiEFTau_RoI"); + c1->cd(3); plotHist(file,path+""+tag+"/dEtaEFTau_RoI"); + c1->Print(psname); + +} + +void plotSteerHist2(TFile & file, const char * histname, const char * opt = "text") +{ + TH1* h1 = ((TH1*)file.Get(histname)); + if( h1 == 0 ) return; + + float bottomPad = gStyle->GetPadBottomMargin(); + int stat = gStyle->GetOptStat(); gStyle->SetOptStat(0); + gPad->SetBottomMargin(0.5); + gPad->SetLeftMargin(0.2); + //gPad->ForceStyle(); + + + TAxis * axis = h1->GetXaxis(); + TAxis * axisY = h1->GetYaxis(); + + std::vector<TString> newLabels; + + int nbins = axis->GetNbins(); + for(unsigned int ibin = 1; ibin <= nbins ; ++ibin) + { + TString label(axis->GetBinLabel(ibin)); + if( label.Contains("HALO")) continue; + if( label.Contains("tau") || label.Contains("Tau") || label.Contains("TAU") || label.Contains("HA") || + label.Contains("trk") || label.Contains("trk")) + { + //if( tag2 == "" || label.Contains(tag2) ) { + //if( tag3 == "" || label.Contains(tag3) ) + newLabels.push_back(label); + // cout << " taken\n";} + //} + } + } + + int nNew = newLabels.size(); + TString newName(h1->GetName()); + + int nY = axisY->GetNbins(); + + newName.Append("_sub"); + TH2F * hNew = (TH2F*)gDirectory->Get(newName); + if( hNew ) delete hNew; + hNew = new TH2F(newName,h1->GetTitle(), nNew, 0, nNew, nY,0, nY); + hNew->GetYaxis()->ImportAttributes(axisY); + //hNew->SetTextSize(0.4); + hNew->SetLabelSize(0.04); + hNew->SetStats(false); + + // name axis + for(unsigned int ibin = 1; ibin <= nY ; ++ibin) + hNew->GetYaxis()->SetBinLabel(ibin,axisY->GetBinLabel(ibin)); + + for(unsigned int ibin = 1; ibin <= nNew ; ++ibin) + { + hNew->GetXaxis()->SetBinLabel(ibin,newLabels[ibin-1]); + for(unsigned int jbin = 0; jbin <= nY+1; ++jbin ) + hNew->SetBinContent(ibin, jbin, + h1->GetBinContent(h1->GetXaxis()->FindBin(newLabels[ibin-1]), jbin)); + + + } + + hNew->LabelsOption("v"); + hNew->Draw(opt); + gStyle->SetOptStat(stat); + gStyle->SetPadBottomMargin(bottomPad); + +} + +void plotSteerHist1(TFile & file, const char * histname, const char * opt = "") +{ + TH1* h1 = ((TH1*)file.Get(histname)); + if( h1 == 0 ) return; + + float bottomPad = gStyle->GetPadBottomMargin(); + int stat = gStyle->GetOptStat(); + gStyle->SetOptStat(0); + gPad->SetBottomMargin(0.5); + //gPad->ForceStyle(); + + + TAxis * axis = h1->GetXaxis(); + TAxis * axisY = h1->GetYaxis(); + + std::vector<TString> newLabels; + + int nbins = axis->GetNbins(); + for(unsigned int ibin = 1; ibin <= nbins ; ++ibin) + { + TString label(axis->GetBinLabel(ibin)); + if( label.Contains("HALO")) continue; + if( label.Contains("tau") || label.Contains("Tau") || label.Contains("TAU") || label.Contains("HA") || + label.Contains("trk") || label.Contains("trk")) + { + //if( tag2 == "" || label.Contains(tag2) ) { + //if( tag3 == "" || label.Contains(tag3) ) + newLabels.push_back(label); + // cout << " taken\n";} + //} + } + } + + int nNew = newLabels.size(); + TString newName(h1->GetName()); + + newName.Append("_sub"); + TH1F * hNew = (TH1F*)gDirectory->Get(newName); + if( hNew ) delete hNew; + hNew = new TH1F(newName,h1->GetTitle(), nNew, 0, nNew); + hNew->GetYaxis()->ImportAttributes(axisY); + hNew->SetLabelSize(0.04); + hNew->SetStats(false); + + for(unsigned int ibin = 1; ibin <= nNew ; ++ibin) + { + hNew->GetXaxis()->SetBinLabel(ibin,newLabels[ibin-1]); + hNew->SetBinContent(ibin,h1->GetBinContent(h1->GetXaxis()->FindBin(newLabels[ibin-1]))); + } + + hNew->LabelsOption("v"); + hNew->SetLineColor(4); hNew->Draw(opt); + gStyle->SetOptStat(stat); + gStyle->SetPadBottomMargin(bottomPad); + +} + + +void plotHist(TFile & file, const char *histname, const char * opt = "") +{ + if( file.Get(histname) == 0 ){ + cout << " Histogram " << histname << " is not found \n"; + return; + } + ((TH1*)file.Get(histname))->SetLineColor(4); + ((TH1*)file.Get(histname))->Draw(opt); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/printCSC.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/printCSC.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ee322e686158f4e625c3be7eeb8f56fe597297b0 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/printCSC.cxx @@ -0,0 +1,190 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +void printCSC( TString outputFile = "csc_plots.eps" ) { + + const int Nbackground = 4; + + //define signal and background samples: + TString signalSample[2]; + TString background[Nbackground]; + +// signalSample[0] = "../data/TTP12.1500/5188/tmp.yjiXu19920.misal1_mc12.005188.A3_Ztautau_filter.digit.RDO.v12000605RDO.013377._00479.pool.root.1.TTP12.1500.root" ; +// signalSample[1] = "../data/TTP12.1500/5107/tmp.ZEjNlX6375.misal1_csc11.005107.pythia_Wtauhad.digit.RDO.v12003103_tid004537._06851.pool.root.1.TTP12.1500.root" ; + +// background[0] = "../data/TTP12.1500/5009/tmp.ZDWMUG1550.misal1_csc11.005009.J0_pythia_jetjet.digit.RDO.v12003103RDO.016351._24844.pool.root.1.TTP12.1500.root" ; +// background[1] = "../data/TTP12.1500/5010/tmp.Yrfzq28506.misal1_csc11.005010.J1_pythia_jetjet.digit.RDO.v12003103_tid003851._01529.pool.root.TTP12.1500.root" ; +// background[2] = "../data/TTP12.1500/5011/tmp.ZCbBCB3815.misal1_csc11.005011.J2_pythia_jetjet.digit.RDO.v12003103RDO.016353._08634.pool.root.1.TTP12.1500.root" ; +// background[3] = "../data/TTP12.1500/5012/tmp.yghkI19797.misal1_csc11.005012.J3_pythia_jetjet.digit.RDO.v12003103RDO.016364._08195.pool.root.1.TTP12.1500.root" ; +// background[4] = "../data/TTP12.1500/5013/tmp.Ycnkq30838.misal1_csc11.005013.J4_pythia_jetjet.digit.RDO.v12003103_tid004016._00061.pool.root.1.TTP12.1500.root" ; +// background[5] = "../data/TTP12.1500/5014/tmp.zGIrnA9890.misal1_csc11.005014.J5_pythia_jetjet.digit.RDO.v12003103RDO.018677._09157.pool.root.1.TTP12.1500.root" ; + + signalSample[0] = "../data/TTP13/5188/tmp.*" ; + signalSample[1] = "../data/TTP12.1500/5107/tmp.*" ; + + background[0] = "../data/TTP13/5009/tmp.*" ; + background[1] = "../data/TTP13/5010/tmp.*" ; + background[2] = "../data/TTP13/5011/tmp.*" ; + background[3] = "../data/TTP13/5012/tmp.*" ; + //background[4] = "../data/TTP12.1500/5013/tmp.*" ; + //background[5] = "../data/TTP12.1500/5014/tmp.*" ; + + double background_xsection[Nbackground]; + background_xsection[0] = 17.6E-27 ; + background_xsection[1] = 1.38E-27 ; + background_xsection[2] = 93.3E-30 ; + background_xsection[3] = 5.88E-30 ; + //background_xsection[4] = 308E-33 ; + //background_xsection[5] = 12.5E-33 ; + + double luminosity = 1E31; + + int type = 1; //1 - relative efficiencies for cutStudy ; 2 - absolute + bool maker_type = 0; + bool debug = false; + bool signal = true; + int nprong = 0; + double maxVisEta = 2.5; + double minLeadingPt = 6.0; + TrigTauFlags::TRIGGERMENU menu = TrigTauFlags::TAU16I; + TrigTauFlags::TRIGGERMENU menu2 = TrigTauFlags::TAU50; + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::LOOSE; + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::EITHERTAU; + TrigTauSelectionManager::MENUVERSION menuVersion = TrigTauSelectionManager::MENU1400; + TrigTauFlags::HLTAUTHOR chainType = TrigTauFlags::IDSCAN; + bool detailedPrinting = false; + + TPostScript ps(outputFile); + + TTPValCutStudy study(signalSample[0]); + study.setDebug(debug); + study.setNprong(nprong); + study.setMenu(menu); + study.setSignal(signal); + study.setType(type); + study.setOfflineType(offlineType); + study.setCutLevel(cutLevel); + study.setMenuVersion(menuVersion); + study.setChainType(chainType); + study.analyze(); + study.effSequencePlotsPrintCSC(ps); + + //effSequence plots for menu2 + TTPValCutStudy study2(signalSample[0]); + study2.setDebug(debug); + study2.setNprong(nprong); + study2.setMenu(menu2); + study2.setSignal(signal); + study2.setType(type); + study2.setOfflineType(offlineType); + study2.setCutLevel(cutLevel); + study2.setMenuVersion(menuVersion); + study2.setChainType(chainType); + study2.analyze(); + study2.effSequencePlotsPrintCSC(ps); + + cout << "Starting TTPValMultiPlots for " << signalSample[0] << endl; + TTPValMultiPlots plots(signalSample[0]); + plots.setDebug(debug); + plots.setNprong(nprong); + plots.setMenu(menu); + plots.setSignal(signal); + plots.setOfflineType(offlineType); + plots.setCutLevel(cutLevel); + plots.setMenuVersion(menuVersion); + plots.setChainType(chainType); + plots.analyze(); + plots.printCSC(ps); + + cout << "Starting TTPValLevelCut for " << signalSample[0] << endl; + TTPValLevelCut cuts(signalSample[0]); + cuts.setDebug(debug); + cuts.setNprong(nprong); + cuts.setMenu(menu); + cuts.setSignal(signal); + cuts.setOfflineType(offlineType); + cuts.setMenuVersion(menuVersion); + cuts.setChainType(chainType); + cuts.analyze(); + cuts.printCSC(ps); + + cout << "Starting TTPValLevelCut for " << signalSample[0] << endl; + TTPValLevelCut cuts(signalSample[0]); + cuts.setDebug(debug); + cuts.setNprong(nprong); + cuts.setMenu(menu2); + cuts.setSignal(signal); + cuts.setOfflineType(offlineType); + cuts.setMenuVersion(menuVersion); + cuts.setChainType(chainType); + cuts.analyze(); + cuts.printCSC(ps); + + cout << "Starting TTPValEffTableMaker for file " << signalSample[0] << endl; + TTPValEffTableMaker maker(signalSample[0]); + maker.setDebug(debug); + maker.setMenu(menu); + maker.setSignal(signal); + maker.setCutLevel(cutLevel); + maker.setMenuVersion(menuVersion); + maker.setChainType(chainType); + maker.analyze(); + maker.printCSC(ps, maker_type); + + vector<double> counter; + counter.push_back(0); + counter.push_back(0); + counter.push_back(0); + counter.push_back(0); + + for (int i =0; i<Nbackground; i++) { + + cout << "Starting TTPValRateTable for file " << background[i] << endl; + TTPValRateTable table((char)background[i]); + table.reset(); + table.setDebug(debug); + table.setNprong(nprong); + table.setMenu(menu); + table.setSignal(false); + table.setOfflineType(offlineType); + table.setCutLevel(cutLevel); + table.setMenuVersion(menuVersion); + table.setChainType(chainType); + table.setDetailedPrinting(detailedPrinting); + table.analyze(); + table.printCSC(ps, luminosity, background_xsection[i], counter); + } + + //print counter; + TH1F * Rates = new TH1F("Total Background Rate", "Total Background Rates", 10, 0, 10); + + Rates->SetBinContent(1, counter[0]); + Rates->GetXaxis()->SetBinLabel(1, "L1 Rate"); + + Rates->SetBinContent(2, counter[1]); + Rates->GetXaxis()->SetBinLabel(2, "L2Cal Rate"); + + Rates->SetBinContent(3, counter[2]); + Rates->GetXaxis()->SetBinLabel(2, "L2Trk Rate"); + + Rates->SetBinContent(4, counter[3]); + Rates->GetXaxis()->SetBinLabel(3, "EF Rate"); + + Rates->LabelsOption("u","X"); + + TCanvas * c1 = (TCanvas *)gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,500); + + ps.On(); + + Rates->Draw(); + c1->Update(); + ps.Close(); + + cout << "Total Rates for L1, L2Calo, L2Trk and EF are " << counter[0] << ", " << counter[1] << ", " << counter[2] << ", " << counter[3] << endl; + + return; + +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/printEffRates.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/printEffRates.cxx new file mode 100644 index 0000000000000000000000000000000000000000..bc7831a992a61ca87dc2234b8510f85a88741ddb --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/printEffRates.cxx @@ -0,0 +1,105 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +void printEffRates( TString outputFile = "RatesEfficiencies.txt" ) { + + const int Nbackground = 7; + const int nMenus = 7; + + //define signal and background samples: + TString signalSample[1]; + TString background[Nbackground]; + TrigTauFlags::TRIGGERMENU theMenu[nMenus]; + + // signalSample[0] = "../data/TTP12.1500/5188/tmp.yjiXu19920.misal1_mc12.005188.A3_Ztautau_filter.digit.RDO.v12000605RDO.013377._00479.pool.root.1.TTP12.1500.root" ; +// signalSample[1] = "../data/TTP12.1500/5107/tmp.ZEjNlX6375.misal1_csc11.005107.pythia_Wtauhad.digit.RDO.v12003103_tid004537._06851.pool.root.1.TTP12.1500.root" ; + +// background[0] = "../data/TTP12.1500/5009/tmp.ZDWMUG1550.misal1_csc11.005009.J0_pythia_jetjet.digit.RDO.v12003103RDO.016351._24844.pool.root.1.TTP12.1500.root" ; +// background[1] = "../data/TTP12.1500/5010/tmp.Yrfzq28506.misal1_csc11.005010.J1_pythia_jetjet.digit.RDO.v12003103_tid003851._01529.pool.root.TTP12.1500.root" ; +// background[2] = "../data/TTP12.1500/5011/tmp.ZCbBCB3815.misal1_csc11.005011.J2_pythia_jetjet.digit.RDO.v12003103RDO.016353._08634.pool.root.1.TTP12.1500.root" ; +// background[3] = "../data/TTP12.1500/5012/tmp.yghkI19797.misal1_csc11.005012.J3_pythia_jetjet.digit.RDO.v12003103RDO.016364._08195.pool.root.1.TTP12.1500.root" ; +// background[4] = "../data/TTP12.1500/5013/tmp.Ycnkq30838.misal1_csc11.005013.J4_pythia_jetjet.digit.RDO.v12003103_tid004016._00061.pool.root.1.TTP12.1500.root" ; + // background[5] = "../data/TTP12.1500/5014/tmp.zGIrnA9890.misal1_csc11.005014.J5_pythia_jetjet.digit.RDO.v12003103RDO.018677._09157.pool.root.1.TTP12.1500.root" ; + + signalSample[0] = "../data/TTP12b.142255/106052/mc*" ; + //signalSample[1] = "../data/TTP12b.142255/5107/tmp.*" ; + + background[0] = "../data/TTP12b.142255/105009/mc*" ; + background[1] = "../data/TTP12b.142255/105010/mc*" ; + background[2] = "../data/TTP12b.142255/105011/mc*" ; + background[3] = "../data/TTP12b.142255/105012/mc*" ; + background[4] = "../data/TTP12b.142255/105013/mc*" ; + background[5] = "../data/TTP12b.142255/105014/mc*" ; + background[6] = "../data/TTP12b.142255/105015/mc*" ; + + double background_xsection[Nbackground]; + background_xsection[0] = 11.7E-27 ; + background_xsection[1] = 0.8668E-27 ; + background_xsection[2] = 56.01E-30 ; + background_xsection[3] = 3.28E-30 ; + background_xsection[4] = 151.6E-33 ; + background_xsection[5] = 5.112E-33 ; + background_xsection[5] = 1.119E-34 ; + + theMenu[0] = TrigTauFlags::TAU12; + theMenu[1] = TrigTauFlags::TAU16I; + theMenu[2] = TrigTauFlags::TAU20I; + theMenu[3] = TrigTauFlags::TAU29I; + theMenu[4] = TrigTauFlags::TAU38I; + theMenu[5] = TrigTauFlags::TAU50; + theMenu[6] = TrigTauFlags::TAU84; + + double luminosity = 1E31; + + int type = 1; //1 - relative efficiencies for cutStudy ; 2 - absolute + bool maker_type = 0; + bool debug = false; + bool signal = true; + int nprong = 0; + double maxVisEta = 2.5; + double minLeadingPt = 6.0; + TrigTauFlags::TRIGGERMENU menu = TrigTauFlags::TAU16I; + TrigTauFlags::TRIGGERMENU menu2 = TrigTauFlags::TAU50; + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::LOOSE; + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::EITHERTAU; + TrigTauSelectionManager::MENUVERSION menuVersion = TrigTauSelectionManager::MENU1400; + TrigTauFlags::HLTAUTHOR chainType = TrigTauFlags::IDSCAN; + bool detailedPrinting = false; + + for (unsigned int j = 0; j<nMenus; ++j) { + + cout << "Starting TTPValRateTable for file " << signalSample[0] << endl; + TTPValRateTable table(signalSample[0]); + table.reset(); + table.setDebug(debug); + table.setNprong(nprong); + table.setMenu(theMenu[j]); + table.setSignal(true); + table.setOfflineType(offlineType); + table.setCutLevel(cutLevel); + table.setMenuVersion(menuVersion); + table.setChainType(chainType); + table.setDetailedPrinting(detailedPrinting); + table.analyze(); + table.print(outputFile, true); + + for (int i =0; i<Nbackground; i++) { + + cout << "Starting TTPValRateTable for file " << background[i] << endl; + TTPValRateTable table((char)background[i]); + table.reset(); + table.setDebug(debug); + table.setNprong(nprong); + table.setMenu(theMenu[j]); + table.setSignal(false); + table.setOfflineType(offlineType); + table.setCutLevel(cutLevel); + table.setMenuVersion(menuVersion); + table.setChainType(chainType); + table.setDetailedPrinting(detailedPrinting); + table.analyze(); + table.print(luminosity, background_xsection[i], outputFile, true); + } + } +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/rateTable2.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/rateTable2.cxx new file mode 100755 index 0000000000000000000000000000000000000000..08c7f9005d0369769833b757f81ce6c90f7c1ff8 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/rateTable2.cxx @@ -0,0 +1,337 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + // Create counters to hold triggered object counts +static long nEvent; +static long nL1Sel; +static long nL2Sel; +static long nL2CalSel; +static long nEFSel; + +static int nDecL1; +static int nDecL2; +static int nDecEF; + +static double nEventWt; +static double nL1SelWt; +static double nL2SelWt; +static double nL2SelCalWt; +static double nEFSelWt; + +void rateTable2EllClear(); +void rateTable2EllPrint(); + + +void rateTable2(const char* fileName) +{ + bool signal = false; + cout << " +++++++++++++++++++++++++ LOOSE ++++++++++++++++++++++ \n"; + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::LOOSE; + rateTable1(fileName, TrigTauFlags::TAU16I, cutLevel, signal); + + cout << " +++++++++++++++++++++++++ MEDIUM ++++++++++++++++++++++ \n"; + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::MEDIUM; + //rateTable1(fileName, TrigTauFlags::TAU15_MEDIUM, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU20I_MEDIUM, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU25I_MEDIUM, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU35I_MEDIUM, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU45_MEDIUM, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU60_MEDIUM, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU100_MEDIUM, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU150_MEDIUM, cutLevel, signal); + + cout << " +++++++++++++++++++++++++ TIGHT ++++++++++++++++++++++ \n"; + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::TIGHT; + //rateTable1(fileName, TrigTauFlags::TAU15_TIGHT, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU20I_TIGHT, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU25I_TIGHT, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU35I_TIGHT, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU45_TIGHT, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU60_TIGHT, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU100_TIGHT, cutLevel, signal); + //rateTable1(fileName, TrigTauFlags::TAU150_TIGHT, cutLevel, signal); + + + +} + +// Menu2 should either be E10, Mu10, or tau +void rateTable1(const char* filename, + TrigTauFlags::TRIGGERMENU menu1, + TrigTauSelectionManager::CUTLEVEL cutLevel, + bool signal ) +{ + + TrigTauSelectionManager::MENUVERSION version = TrigTauSelectionManager::MENU1400; + // TrigTauSelectionManager::MENUVERSION version = TrigTauSelectionManager::MENU13030pre; + //TrigTauSelectionManager::MENUVERSION version = TrigTauSelectionManager::MENU1206; + + float met = 0.; + + //bool signal = true; + int nprong = 0; + bool checkOffline = true; + // TAU1P3P, TAUREC, EITHERTAU, BOTHTAU + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::NONE; + + bool doDetailedPrinting=true; + + //TrigTauBugFix bugfix (TrigTauBugFix::TTP4, TrigTauBugFix::RDO); + TrigTauBugFix bugfix(TrigTauBugFix::TTP7, TrigTauBugFix::RDO); + //bugfix.setTTPVersion(filename); + + // Create our analyzer class + TrigTauAnalyzer analyzer; + + //=================================================== + // MC truth + analyzer.truthList.setMaxVisEta(2.5); + analyzer.truthList.setMinVisPt(menu1); + if( nprong == 1 ) analyzer.truthList.select1Prong(); + else if( nprong == 3 ) analyzer.truthList.select3Prong(); + analyzer.truthList.setRecoMatchdR(0.2); + + rateTable2EllClear(); + gROOT->cd(); + + // Open file + + //commented out; use to use file declared when calling function + + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + cerr << "Can't open file " << filename << endl; + return; + } + + // Initialize tree + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + cerr << "Can't find eventTree in " << filename << endl; + return; + } + + + + //TChain * tree = new TChain("eventTree"); + //tree->Add("ntuples/14.2.0/5107/tmp.*"); + //tree->Add("ntuples/TTP09prelim/tmp.*"); + //tree->Add("~/temp/temp/ChangeEDM.trigtau.5200.root"); + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + //tree->SetBranchStatus("mcEvent*", 0); + + // Also set an L1 MET cut if desired + analyzer.trigMan.setL1MET(met); + analyzer.trigMan.setMenuVersion(version); + analyzer.trigMan.setTauMenu(menu1, cutLevel); + + //TrigTauHistogram::setHistLimits(TrigTauHistogram::PTHIST,30,0,90000); + //analyzer.trigMan.l2CalSel.setHistDebug(); + + + //analyzer.trigMan.setL2CalOnly(false); + bool checkL2Cal = true; + + int nPrintL1 = 0; + int nPrintL2 = 0; + int nPrintEF = 0; + + analyzer.chainList.setRoiWordMatching(false); + + // Loop over all events + int nev = int(tree->GetEntries()); + cout << "Checking a total of " << nev << " events..." << endl; + //if( nev > 15000 ) nev = 15000; + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + bugfix.fix(event); + + analyzer.analyze(event, signal, offlineType); + + // ============ Select type of events (e.g. signal) ================ + if( signal && analyzer.truthList.nMCTauGood() ==0 ) continue; + //================================================================== + nEvent++; + + bool decL1 = event->decision.passedL1(menu1); + bool decL2 = event->decision.passedL2(menu1); + bool decEF = event->decision.passedEF(menu1); + + nDecL1 += int(decL1); + nDecL2 += int(decL2); + nDecEF += int(decEF); + + bool ntL1 = false; + bool ntL2 = false; + bool ntEF = false; + + if( analyzer.chainList.nPassL1Chains() > 0 ) + { + nL1Sel++; + ntL1 = true; + } + + if( checkL2Cal ){ + if( analyzer.chainList.nPassL2CalChains() > 0 ) + nL2CalSel++; + } + + if( analyzer.chainList.nPassL2Chains() > 0 ) { + nL2Sel++; + ntL2 = true; + } + + + if( analyzer.chainList.nPassEFChains() > 0 ) { + nEFSel++; + ntEF=true; + } + + bool printChain=false; + if(doDetailedPrinting && decL1 != ntL1 ) { + cout << "\n============ Event " << event->eventNumber << " L1 decision does not match: NTUPLE " + << ntL1 << " + and HLTcode " << decL1 << endl; + printChain = true; + nPrintL1++; + + } + if( doDetailedPrinting &&decL2 != ntL2 ) { + cout << "\n============ Event " << event->eventNumber << " L2 decision does not match: NTUPLE " + << ntL2 << " + and HLTcode " << decL2 << endl; + printChain = true; + nPrintL2++; + } + if( doDetailedPrinting &&decEF != ntEF ) { + cout << "\n============ Event " << event->eventNumber << " EF decision does not match: NTUPLE " + << ntEF << " + and HLTcode " << decEF << endl; + printChain = true; + nPrintEF++; + } + if( doDetailedPrinting && printChain ) + { + analyzer.chainList.printChainList(); + cout << endl; + analyzer.trigMan.setDebug(true); + int numCh = analyzer.chainList.nTrigChains(); + for (unsigned int iCh1=0; iCh1 < numCh; iCh1++) { + cout << " ==================================\n"; + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + if (!analyzer.trigMan.passedL1(ch1)) continue; + if (!analyzer.trigMan.passedL2(ch1)) continue; + if (!analyzer.trigMan.passedEF(ch1)) continue; + } + analyzer.trigMan.setDebug(false); + cout << endl; + } + //}// end of doDetailedPrinting + + + } // end loop over events + + // analyzer.trigMan.print(); + // trigMan2.print(); + //analyzer.trigMan.l2CalSel.histManager()->plotAll(); + // analyzer.trigMan.l2CalSel.histManager()->plotAllEfficiencies(); + + delete event; + delete tree; + //delete file; + + cout << " Use menu " << menu1.menuName(menu1) << endl; + //analyzer.trigMan.print(); + rateTable2EllPrint() ; + + cout << "Mistmatch found in L1 " << nPrintL1 << " , L2 " << nPrintL2 << ", EF " << nPrintEF << endl; +/* + cout << "Com Eff " << menu1.menuName(menu1) << " \& "<< nEvent << " & " //<< std::setprecision(3) + << float(nL1Sel)/float(nEvent)<< " & " //<< std::setprecision(3) + << float(nL2CalSel)/float(nEvent)<< " & "//<< std::setprecision(3) + << float(nL2Sel)/float(nEvent) << " & "//<< std::setprecision(3) + << float(nEFSel)/float(nEvent)<< " \\ \n"; + cout << "Lev Eff " << menu1.menuName(menu1) << " \& "<< nEvent << " & " //<< std::setprecision(3) + << float(nL1Sel)/float(nEvent)<< " & " //<< std::setprecision(3) + << float(nL2CalSel)/float(nL1Sel)<< " & "//<< std::setprecision(3) + << float(nL2Sel)/float(nL2CalSel) << " & "//<< std::setprecision(3) + << float(nEFSel)/float(nL2Sel)<< " \\ \n"; +*/ + + return; +} + +void rateTable2EllPrint() { + + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + + cout << "L1Sel L2CalSel L2TrkSel EFSel" << endl; + + cout << "Decision : " + << nDecL1 << " " + << nDecL2 << " " + << nDecEF << endl; + + + cout << "Number: " + << nL1Sel << " " + << nL2CalSel << " " + << nL2Sel << " " + << nEFSel << endl; + + //cout << "Rate: " + // << nL1SelWt << " " + // << nL2SelWt << " " + // << nEFSelWt << endl; + + cout << "Cum Eff: " + << 100*float(nL1Sel)/nEvent << " " + << 100*float(nL2CalSel)/nEvent << " " + << 100*float(nL2Sel)/nEvent << " " + << 100*float(nEFSel)/nEvent << endl; + +// cout << "Dif Eff: " +// << 100*float(nL1Sel)/nEvent << " " +// << (nL1Sel > 0 ? 100*float(nL2CalSel)/nL1Sel : 0) << " " +// << (nL2CalSel > 0 ? 100*float(nL2Sel)/nL2CalSel : 0) +// << (nL2Sel > 0 ? 100*float(nEFSel)/nL2Sel : 0) << endl; + +// cout << "Cum Rej: " +// << (nL1Sel > 0 ? nEvent/float(nL1Sel) : 0) << " " +// << (nL2CalSel > 0 ? nEvent/float(nL2CalSel) : 0) << " " +// << (nL2Sel > 0 ? nEvent/float(nL2Sel) : 0) << " " +// << (nEFSel > 0 ? nEvent/float(nEFSel) : 0) << endl; + +// cout << "Dif Rej: " +// << (nL1Sel > 0 ? nEvent/float(nL1Sel) : 0) << " " +// << (nL2CalSel > 0 ? nL1Sel/float(nL2CalSel) : 0) << " " +// << (nL2Sel > 0 ? nL2CalSel/float(nL2Sel) : 0) << " " +// << (nEFSel > 0 ? nL2Sel/float(nEFSel) : 0) << endl; + +} + +void rateTable2EllClear() { + // Create counters to hold triggered object counts + nEvent = 0; + nL1Sel = 0; + nL2CalSel = 0; + nL2Sel = 0; + nEFSel = 0; + nEventWt = 0.; + nL1SelWt = 0.; + nL2SelWt = 0.; + nEFSelWt = 0.; + + nDecL1= 0; + nDecL2= 0; + nDecEF= 0; + +} + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/saveAll.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/saveAll.cxx new file mode 100644 index 0000000000000000000000000000000000000000..166f25ce8c31aad218dee2a1c011514c0f7332a4 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/saveAll.cxx @@ -0,0 +1,139 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +void saveAll( const char * filename = "ntuple/TTP12.1422252/5188/tmp.*", const char * outputFile = "validationAnalysis.root" ) { + + TFile * file = new TFile(outputFile, "recreate"); + file->Close(); + + int type = 1; //1 - relative efficiencies for cutStudy and effTableMaker; 2 - absolute + bool debug = false; + bool signal = true; + int nprong = 0; + double maxVisEta = 2.5; + double minLeadingPt = 6.0; + TrigTauFlags::TRIGGERMENU menu = TrigTauFlags::TAU16I; + TrigTauFlags::TRIGGERMENU menu2 = TrigTauFlags::TAU50; + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::LOOSE; + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::EITHERTAU; + TrigTauSelectionManager::MENUVERSION menuVersion = TrigTauSelectionManager::MENU1400; + TrigTauFlags::HLTAUTHOR chainType = TrigTauFlags::IDSCAN; + bool detailedPrinting = false; + double crossSec = 0; + double luminosity = 1E31; + + + //const char * filename = "ntuple/TTP12.1422252/5188/tmp.*"; + + cout << "Starting TTPValCutStudy. " << endl; + TTPValCutStudy study(filename); + study.setDebug(debug); + study.setNprong(nprong); + study.setMenu(menu); + study.setSignal(signal); + study.setType(type); + study.setOfflineType(offlineType); + study.setCutLevel(cutLevel); + study.setMenuVersion(menuVersion); + study.setChainType(chainType); + study.analyze(); + study.update(outputFile); + study.effSequencePlotsUpdate(outputFile); + + //effSequence plots for NONE offline matching + TTPValCutStudy study2(filename); + study2.setDebug(debug); + study2.setNprong(nprong); + study2.setMenu(menu); + study2.setSignal(signal); + study2.setType(type); + study2.setOfflineType(TrigTauMCTauList::NONE); + study2.setCutLevel(cutLevel); + study2.setMenuVersion(menuVersion); + study2.setChainType(chainType); + study2.analyze(); + study2.effSequencePlotsUpdate(outputFile); + + TTPValCutStudy study3(filename); + study3.setDebug(debug); + study3.setNprong(nprong); + study3.setMenu(menu2); + study3.setSignal(signal); + study3.setType(type); + study3.setOfflineType(offlineType); + study3.setCutLevel(cutLevel); + study3.setMenuVersion(menuVersion); + study3.setChainType(chainType); + study3.analyze(); + study3.update(outputFile); + study3.effSequencePlotsUpdate(outputFile); + + //effSequence plots for NONE offline matching + TTPValCutStudy study4(filename); + study4.setDebug(debug); + study4.setNprong(nprong); + study4.setMenu(menu2); + study4.setSignal(signal); + study4.setType(type); + study4.setOfflineType(TrigTauMCTauList::NONE); + study4.setCutLevel(cutLevel); + study4.setMenuVersion(menuVersion); + study4.setChainType(chainType); + study4.analyze(); + study4.effSequencePlotsUpdate(outputFile); + + cout << "Starting TTPValMultiPlots. " << endl; + TTPValMultiPlots plots(filename); + plots.setDebug(debug); + plots.setNprong(nprong); + plots.setMenu(menu); + plots.setSignal(signal); + plots.setOfflineType(offlineType); + plots.setCutLevel(cutLevel); + plots.setMenuVersion(menuVersion); + plots.setChainType(chainType); + plots.analyze(); + plots.update(outputFile); + + cout << "Starting TTPValDistribution." << endl; + TTPValDistribution dist(filename); + dist.setDebug(debug); + dist.setMenu(menu); + //dist.setSignal(signal); + dist.setOfflineType(offlineType); + dist.setCutLevel(cutLevel); + dist.setMenuVersion(menuVersion); + dist.setChainType(chainType); + dist.analyze(); + dist.update(outputFile); + + cout << "Starting TTPValEffTableMaker." << endl; + TTPValEffTableMaker maker(filename); + maker.setDebug(debug); + maker.setMenu(menu); + maker.setSignal(signal); + //maker.setType(type); + maker.setCutLevel(cutLevel); + maker.setMenuVersion(menuVersion); + maker.setChainType(chainType); + maker.analyze(); + maker.update(outputFile, type); + + cout << "Starting TTPValRateTable." << endl; + TTPValRateTable table(filename); + table.setDebug(debug); + table.setNprong(nprong); + table.setMenu(menu); + table.setSignal(signal); + table.setOfflineType(offlineType); + table.setCutLevel(cutLevel); + table.setMenuVersion(menuVersion); + table.setChainType(chainType); + table.setDetailedPrinting(detailedPrinting); + table.analyze(); + table.update(outputFile, luminosity, crossSec); + + return; + +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/signal_write.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/signal_write.cxx new file mode 100644 index 0000000000000000000000000000000000000000..eaaff607703fd91d64e8757ef3fa875113849886 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/signal_write.cxx @@ -0,0 +1,318 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//#include "Mogens/tauRoI.h"; + +bool signal = true; + +void signal_write( int nevMax=1000000) +{ + tauRoI tauRoI; + + gROOT->cd(); + + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::NONE; + + // Set an L1 MET cut if desired + /* + TrigTauSelectionManager trigMan1; + trigMan1.setMenuVersion(TrigTauSelectionManager::MENU13030pre); + trigMan1.setTauMenu(TrigTauFlags::TAU16I); + trigMan1.l1Sel.print(); + */ + + //const char* filename = "ntuples/TTP09/TTP09_prelim/tmp*root"; + //std::string input = "5107.TTP09_prelim"; + //const char* filename = "ntuples/TTP09/holesAmbSolv/tmp*root"; + //std::string input = "5107.holesAmbSolv"; + // const char* filename = "ntuples/TTP09/largeRoIholesAmbNoBackTrk/5107/tmp*root"; + //std::string input = "5107.largeRoIholesAmbNoBackTrk"; + //const char* filename = "ntuples/TTP09/bigRoI/5107/tmp*root"; + //std::string input = "5107.largeRoIholesAmb"; + //const char* filename = "ntuples/TTP09/oldEFID/5107/tmp*root"; + //std::string input = "5107.KalmanFitter"; + //const char* filename = "ntuples/TTP09/July22/5107/tmp*root"; + //std::string input = "5107.July22"; + //const char* filename = "ntuples/TTP09/July22_tauRecCalo/5107/tmp*root"; + //std::string input = "5107.July22_tauRecCalo"; + const char* filename = "ntuples/TTP06_dR03/5107/user.Eli*root"; + std::string input = "5107.TTP06_dR03"; + + + +// switch ( input ) { +// case 5107: // W->tau +// const char* filename = "/Users/dam/Data/TTP09/5107/*"; +// break; +// case 5188: // Z -> tautau +// const char* filename = "/Users/dam/Data/TTP09/5188/*"; +// break; +// case 5862: // Z -> tautau +// const char* filename = "/Users/dam/Data/TTP09/5862/*"; +// break; +// default: +// cout << "Incorrect choice of input ntuples" << endl; +// return; +// } + + cout << "Opening file(s): " << filename << endl; + + TChain chain("eventTree"); + chain.Reset(); + chain.Add(filename); + + TTree* tree = &chain; + + TrigTauBugFix bugfix(TrigTauBugFix::TTP7, TrigTauBugFix::RDO); + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + + gROOT->cd(); + + std::ostringstream os; + os << "RoI_" << input << ".root"; + TString fileName(os.str()); + TFile *tmvafile = new TFile(fileName,"RECREATE"); + + TTree *tmvatree = new TTree("tauRoI","tauRoI variables"); + tmvatree->Branch("tmva", &tauRoI, + "run/I:event/I:trigChain/I:mc_Pt/F:mc_decayType/I:seedType/I:nTrk/I:nTrkLoose/I:nTrkEFID/I:nTrkMy/I:chrgTot/I:ptTot/F:ptLead/F:Et/F:EtEMCalib/F:EtHadCalib/F:eta/F:phi/F:nStrips/I:EMRadius/F:stripWidth2/F:isoFrac/F:centFrac/F:sumEmCellEt/F:hadRadius/F:sumHadCellEt/F:calRadius/F:trkMass/F:trkMass3/F:trkMass0/F:tr_Et/F:tr_eta/F:tr_phi/F:tr_EtEMCalib/F:tr_EtHadCalib/F:tr_nStrips/I:tr_EMRadius/F:tr_stripWidth2/F:tr_isoFrac/F:tr_Likelihood/F:tr_nTrk/I:tr_charge/I:tr_llh/F:tr_discriCut/F:L2_eta/F:L2_phi/F:L2_nTrk/I:L1_Et/F:L1_EmIsol/F"); + + // Create analyzer class + TrigTauAnalyzer analyzer; + /* + analyzer.truthList.setMaxVisEta(2.5); + analyzer.truthList.setMinVisPt(0.); // in GeV + analyzer.truthList.setMinLeadingPt(0.); // pt of the leading pt of track is + analyzer.truthList.setRecoMatchdR(0.2); + */ + int nEvent; + + // Loop over events + + //Yes, I know. Problem with Navigation. You need to set up : + analyzer.chainList.setRoiWordMatching(false); + //before event loop, then you will not get the problem below. + //Thanks, Olya + + int nnn[10]={0}; + + int nev = int(tree->GetEntries()); + cout << "Number of events in chain: " << nev << endl; + int nLoop = nev; + if ( nevMax<nev) nLoop = nevMax; + for ( int iev = 0; iev<nLoop; ++iev) { + nEvent++; + cout << iev << endl; + if( iev == 466 || iev == 471 || iev == 720 || iev == 1076 ) continue; + if ( nEvent%1000 == 0 ) cout << "Working ... " << nEvent << endl; + + // Get this event + event->reset(); + tree->GetEvent(iev); + bugfix.fix(event); + + // Analyze this event + analyzer.analyze(event, signal, offlineType); + + unsigned int nTau = analyzer.truthList.nMCTauGood(); + unsigned int numCh = analyzer.chainList.nTrigChains(); + unsigned int nTauRec = event->nTauRec(); + + // cout << "nTau= " << nTau << ", numCh= " << numCh + // << ", nTauRec= " << nTauRec << endl; + + for ( unsigned int iTau = 0; iTau < nTau; ++iTau ) { + TrigTauMCTau* tau = &analyzer.truthList.mcTauGoodEntry(iTau); + nnn[0]++; + if ( tau == 0 ) continue; + nnn[1]++; + if ( !tau->hadronicDecay() ) continue; + nnn[2]++; + if ( fabs(tau->visible().Eta()) > 2.5 ) continue; + nnn[3]++; + + if ( tau->visible().Pt() < 15000. ) continue; + nnn[4]++; + + bool match=false; + for (unsigned int iCh=0; iCh < numCh; ++iCh) { + TrigTauTrigChain ch = analyzer.chainList.trigChainEntry(iCh); + TrigTauL1Object* tauL1 = ch.L1; + if ( tauL1 == 0 ) continue; + if ( analyzer.chainList.getL1Tau(*tau) == tauL1 ) { + match = true; + break; + } + } + if ( !match ) continue; + nnn[5]++; + + if ( tauL1->m_TauEnergy < 6001. ) continue; + nnn[6]++; + + const TrigTauRecEFObject* tauEF = ch.EF; + if ( tauEF == 0 ) continue; + nnn[7]++; + + float mass, mass3, mass0; + mass = 0.; + mass0 = 0.; + if ( tauEF->nLooseTracks()==1 ) { + mass = tauEF->looseTrack(0).M(); + } else if ( tauEF->nLooseTracks()>1 ) { + float Px, Py, Pz, E, E0; + Px = Py = Pz = E = E0 = mass3 = 0.; + for ( unsigned int iTrk=0; iTrk<tauEF->nLooseTracks(); ++iTrk ) { + Px += tauEF->looseTrack(iTrk).Px(); + Py += tauEF->looseTrack(iTrk).Py(); + Pz += tauEF->looseTrack(iTrk).Pz(); + E += tauEF->looseTrack(iTrk).E(); + E0 += tauEF->looseTrack(iTrk).P(); + if ( iTrk==2 ) mass3 = sqrt(E*E-Px*Px-Py*Py-Pz*Pz); + } + mass = sqrt(E*E-Px*Px-Py*Py-Pz*Pz); + mass0 = sqrt(E0*E0-Px*Px-Py*Py-Pz*Pz); + } + if ( tauEF->nLooseTracks()<3 ) mass3 = mass; + + float sumCellEt = tauEF->m_sumEmCellEt + tauEF->m_sumHadCellEt; + float calRadius = -999.; + if ( sumCellEt>0. ) + calRadius = (tauEF->m_EMRadius * tauEF->m_sumEmCellEt + + tauEF->m_hadRadius * tauEF->m_sumHadCellEt)/sumCellEt; + + + const TrigTauTrackCollection * trkEFID = + (const TrigTauTrackCollection*) tauEF->r_EFIDtrackCollection.GetObject(); + int nTrkMy = 0; + for ( int jTrk=0; trkEFID && jTrk<trkEFID->nTracks(); ++jTrk ) { + const TrigTauTrack *pTrk = &(trkEFID->track(jTrk)); + double dEta = tauEF->Eta() - pTrk->Eta(); + double dPhi = tauEF->Phi() - pTrk->Phi(); + if (dPhi < -TMath::Pi()) dPhi += TMath::TwoPi(); + if (dPhi > +TMath::Pi()) dPhi -= TMath::TwoPi(); + double dR = sqrt(dEta*dEta+dPhi*dPhi); + if ( dR < 0.3 + && pTrk->Pt() > 1000. + && pTrk->nSiHits() > 6 + && pTrk->nPixBlay() > 0 + && fabs(pTrk->m_a0) < 0.5 + ) nTrkMy++; + } + + // Output variables... + tauRoI.run = event->runNumber; + tauRoI.event = event->eventNumber; + tauRoI.trigChain = iCh; + tauRoI.mc_Pt = tau->visible().Pt(); + tauRoI.mc_decayType = tau->decayType(); + tauRoI.seedType = tauEF->m_seedType; + tauRoI.nTrk = tauEF->nTracks(); + tauRoI.nTrkLoose = tauEF->nLooseTracks(); + if( trkEFID ) tauRoI.nTrkEFID = trkEFID->nTracks(); + else tauRoI.nTrkEFID = 0; + tauRoI.nTrkMy = nTrkMy; + tauRoI.chrgTot = tauEF->chargeTotTracks(); + tauRoI.ptTot = tauEF->ptTotTracks(); + tauRoI.ptLead = ( tauEF->nLooseTracks()>0 ) ? tauEF->looseTrack(0).Pt() : 0.; + tauRoI.Et = tauEF->Et(); + tauRoI.eta = tauEF->Eta(); + tauRoI.phi = tauEF->Phi(); + tauRoI.EtEMCalib = tauEF->m_etEMCalib; + tauRoI.EtHadCalib = tauEF->m_etHadCalib; + tauRoI.nStrips = tauEF->m_nStrips; + tauRoI.EMRadius = tauEF->m_EMRadius; + tauRoI.stripWidth2 = tauEF->m_stripWidth2; + tauRoI.isoFrac = tauEF->m_isoFrac; + tauRoI.centFrac = tauEF->m_centralityFraction; + tauRoI.sumEmCellEt = tauEF->m_sumEmCellEt; + tauRoI.hadRadius = tauEF->m_hadRadius; + tauRoI.sumHadCellEt = tauEF->m_sumHadCellEt; + tauRoI.calRadius = calRadius; + tauRoI.trkMass = mass; + tauRoI.trkMass3 = mass3; + tauRoI.trkMass0 = mass0; + + tauRoI.L1_Et = tauL1->m_TauEnergy; + tauRoI.L1_EmIsol = tauL1->m_EmIsol; + + // tauRec + bool Match = false; + for ( int iTauR=0; iTauR<nTauRec; ++iTauR ) { + const TrigTauRecOfflineObject *tauTR = &(event->tauRecEntry(iTauR)); + double dEta = tauEF->Eta() - tauTR->Eta(); + double dPhi = tauEF->Phi() - tauTR->Phi(); + if (dPhi < -TMath::Pi()) dPhi += TMath::TwoPi(); + if (dPhi > +TMath::Pi()) dPhi -= TMath::TwoPi(); + double dR = sqrt(dEta*dEta+dPhi*dPhi); + if ( dR<0.20 ) { + Match = true; + break; + } + } + + if ( !Match ) { + tauRoI.tr_Et = -999.; + tauToI.tr_eta = -999.; + tauToI.tr_phi = -999.; + tauRoI.tr_EtEMCalib = -999.; + tauRoI.tr_EtHadCalib = -999.; + tauRoI.tr_nStrips = -999; + tauRoI.tr_EMRadius = -999.; + tauRoI.tr_stripWidth2 = -999.; + tauRoI.tr_isoFrac = -999.; + tauRoI.tr_Likelihood = -999.; + tauRoI.tr_nTrk = -1; + tauRoI.tr_charge = -1; + } else { + tauRoI.tr_Et = tauTR->Et(); + tauRoI.tr_eta = tauTR->Eta(); + tauRoI.tr_phi = tauTR->Phi(); + tauRoI.tr_EtEMCalib = tauTR->m_etEMCalib; + tauRoI.tr_EtHadCalib = tauTR->m_etHadCalib; + tauRoI.tr_nStrips = tauTR->m_nStrips; + tauRoI.tr_EMRadius = tauTR->m_EMRadius; + tauRoI.tr_stripWidth2 = tauTR->m_stripWidth2; + tauRoI.tr_isoFrac = tauTR->m_isoFrac; + tauRoI.tr_Likelihood = tauTR->m_Likelihood; + tauRoI.tr_nTrk = tauTR->nTracks(); + tauRoI.tr_charge = tauTR->m_charge; + } + + // L2 + TrigTauL2Object* L2Tau = ch.L2; + if (L2Tau == 0) { + tauRoI.L2_eta = -999.; + tauRoI.L2_phi = -999.; + tauRoI.L2_nTrk = -999; + } else { + tauRoI.L2_eta = L2Tau->Eta(); + tauRoI.L2_phi = L2Tau->Phi(); + tauRoI.L2_nTrk = L2Tau->nTracks(); + } + + tmvatree->Fill(); + + } + } + + cout << "Analysed file(s): " << filename << endl; + cout << "Total of " << nEvent << " events" << endl; + + delete event; + + for ( int i=0; i<10; ++i ) { + printf(" %2d, %6d\n", i, nnn[i] ); + } + + tmvatree->Print(); + tmvatree->Write(); + + delete tmvatree; + delete tmvafile; + return; +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/testTrigTauEvRateTool.cc b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/testTrigTauEvRateTool.cc new file mode 100644 index 0000000000000000000000000000000000000000..3b36333d17d34444f5c2fdc597573b74f9d5b035 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/testTrigTauEvRateTool.cc @@ -0,0 +1,49 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// +// Example of TrigTauEvRateTool usage +// +// Must first define selectors to use (or select all) +// Second, fill as many samples as desired. Unique tags will go into +// separate lines in the composite rate table. +// Third, combine unique tags into a summary (useful for J0-JX addition) +// Fourth, print out the results (or use the counter access and print your own) +// + +testTrigTauEvRateTool() { + + TrigTauEvRateTool tr; + + if (1) { + + // Everything defined in TrigTauFlags + tr.defineAllSelectors(); + + } else { + + // Specific list of triggers + tr.defineSelector( TrigTauFlags::TAU12); + tr.defineSelector( TrigTauFlags::TAU16I); + tr.defineSelector( TrigTauFlags::TAU20I); + tr.defineSelector( TrigTauFlags::TAU29I); + tr.defineSelector( TrigTauFlags::TAU38); + tr.defineSelector( TrigTauFlags::TAU38I); + tr.defineSelector( TrigTauFlags::TAU50); + tr.defineSelector( TrigTauFlags::TAU84); + tr.defineSelector( TrigTauFlags::TAU125); + tr.defineSelector( TrigTauFlags::tau16i_xe30); + + } + + double weight = 1.51; + tr.defineSample("MinBias"); + tr.fillSample("MinBias", "ntuples/EBias/EBias.RDO.v12003103.TTP11.merged.0.root", weight); + + // tr.print(); + // tr.printSelector("tau16i", true); + // tr.printSelector("tau50", true); + + tr.printRateSum("MinBias", true); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/validation3.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/validation3.cxx new file mode 100755 index 0000000000000000000000000000000000000000..955fa17985c873ba505ccb58ad5a17df9d95ed67 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/validation3.cxx @@ -0,0 +1,410 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +void validation3(const char * filename, int type = 2, bool debug = false ) { + + TChain * chain = new TChain("eventTree"); + chain->Add(filename); + //chain->Add("ntuples/14.2.0_May28/5107/tmp.*"); + //chain->Add("ntuples/14.2.0/5107/tmp.*"); + //chain->Add("ntuples/TTP09prelim/tmp.*"); + validation3(chain, type, debug); + +} + + +void validation3(TTree * tree, int type = 2, bool debug = false) +{ + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + TrigTauFlags::TRIGGERMENU menu1 = TrigTauFlags::TAU16I; + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::LOOSE; + bool signal = true; + + int nprong = 3; + // TAU1P3P, TAUREC, EITHERTAU, BOTHTAU, NONE + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::NONE; + + TrigTauBugFix bugfix(TrigTauBugFix::TTP7, TrigTauBugFix::RDO); + + //=================================================== + TrigTauAnalyzer analyzer; + // MC truth + analyzer.truthList.setMaxVisEta(2.5); + analyzer.truthList.setMinVisPt(menu1); // in GeV + analyzer.truthList.setMinLeadingPt(6.); // pt of the leading pt of track is + if( nprong == 1 ) analyzer.truthList.select1Prong(); + else if( nprong == 3 ) analyzer.truthList.select3Prong(); + analyzer.truthList.setRecoMatchdR(0.2); + + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + //tree->SetBranchStatus("mcEvent*", 0); + + // Also set an L1 MET cut if desired + analyzer.trigMan.setL1MET(0.); + analyzer.trigMan.setMenuVersion(TrigTauSelectionManager::MENU1400 ); + analyzer.trigMan.setTauMenu(menu1, cutLevel); + analyzer.chainList.setRoiWordMatching(false); + + TH1F * hTot[3]; + hTot[0] = new TH1F("hptTot","",120,0,120000); + hTot[1] = new TH1F("hphiTot","",64,-3.2,3.2); + hTot[2] = new TH1F("hetaTot","",50,-2.5,2.5); + + //create list of histograms + vector<TString> hnames; + + //Level 1 + hnames.push_back("L1_TauCluster"); + hnames.push_back("L1_EMIsol"); + hnames.push_back("L1_HDIsol"); + hnames.push_back("L1_EMCore"); + hnames.push_back("L1_HDCore"); + hnames.push_back("L1_EMEnergy"); + //Level2 Calo + hnames.push_back("L2Calo_Et"); + hnames.push_back("L2Calo_Et_Calib"); + hnames.push_back("L2Calo_nStrips"); + hnames.push_back("L2Calo_stripWidth"); + hnames.push_back("L2Calo_EMRadius"); + hnames.push_back("L2Calo_IsoFrac"); + hnames.push_back("L2Calo_EMWidth"); + hnames.push_back("L2Calo_Et_Nar"); + //Level2 Track + hnames.push_back("L2Trk_nMinTrk");; + hnames.push_back("L2Trk_nSlow"); + hnames.push_back("L2Trk_nIso"); + hnames.push_back("L2Trk_nMatch"); + hnames.push_back("L2Trk_totCharge"); + hnames.push_back("L2Trk_maxPt"); + hnames.push_back("L2Trk_sumPtRatio"); + hnames.push_back("L2Trk_Et (Trk+EM)"); + //EF + hnames.push_back("EF_min nTrk"); + hnames.push_back("EF_max nTrk"); + hnames.push_back("EF_EMRadius"); + hnames.push_back("EF_IsoFrac"); + hnames.push_back("EF_EMFrac"); + hnames.push_back("EF_Pt_max"); + hnames.push_back("EF_Et"); + hnames.push_back("EF_EM_Et"); + hnames.push_back("EF_Mass"); + + const unsigned int nL1Cuts = 6; + const int nL2CaloCuts = 8; + const int nL2TrkCuts = 8; + const int nEFCuts = 9; + const unsigned int nHistos = hnames.size()*3; + const unsigned int nNames = hnames.size(); + + if ( nL1Cuts+nL2CaloCuts+nL2TrkCuts+nEFCuts != nNames ) { + cout << "ERROR: Number of Cuts for different levels incorrect!!!" << endl; + return; + } + + TH1F * histograms[nHistos]; + createHistograms(hnames, nNames, histograms); + + TrigTauSelectionManager selmanager; + selmanager.setMenuVersion(TrigTauSelectionManager::MENU1400); + selmanager.setTauMenu(menu1, TrigTauSelectionManager::LOOSE); + unsigned long l1Word[100]; + unsigned long l2CaloWord[100]; + unsigned long l2TrkWord[100]; + unsigned long l2Word[100]; + unsigned long efWord[100]; + + + // Loop over all events + int nev = int(tree->GetEntries()); + //if ( nev > 100 ) nev = 100; + for(int iev = 0; iev<nev; ++iev) { + if ( debug ) cout << "============== Checking event " << iev << " ==================" << endl; + event->reset(); + tree->GetEvent(iev); + bugfix.fix(event); + + analyzer.analyze(event, signal, offlineType); + + // ============ Select type of events (e.g. signal) ================ + if( signal ) { + analyzer.truthList.fillPureList(&event->mcEvent); + analyzer.truthList.fillGoodList(); + analyzer.truthList.requireRecoMatch(*event, offlineType); + if ( debug && analyzer.truthList.nMCTauGood() ==0 ) cout << "Event contains no good taus! " << endl; + if( analyzer.truthList.nMCTauGood() ==0 ) continue; + } + + // loop over taus after fiducial cuts + + if ( debug ) cout << "Event contains " << analyzer.truthList.nMCTauGood() << " good tau!" << endl; + for( unsigned int iTrue = 0; iTrue < analyzer.truthList.nMCTauGood(); ++iTrue ) //loop over all true taus + { + const TrigTauMCTau * truth = & analyzer.truthList.mcTauGoodEntry(iTrue); //select tau + float pt = truth->Pt(); + float eta = truth->Eta(); + float phi = truth->Phi(); + hTot[0]->Fill(pt); hTot[1]->Fill(phi); hTot[2]->Fill(eta); + + const unsigned int nTrigChains = analyzer.chainList.nTrigChains() ; + if (debug ) cout << "Value of nTrigChains: " << nTrigChains << endl; + if ( nTrigChains == 0 ) continue; + + unsigned int nl1Word = 0; + //unsigned int nl2CaloWord = 0; + //unsigned int nl2TrkWord = 0; + unsigned int nl2Word = 0; + unsigned int nefWord = 0; + + if ( debug ) cout << " There are " << nTrigChains << " chains to analyze." << endl; + for( unsigned int ichain = 0; ichain < nTrigChains; ++ichain) { + if ( debug ) cout << "Starting chain " << ichain << "!" << endl; + TrigTauTrigChain *ch = &analyzer.chainList.trigChainEntry(ichain); + const TrigTauL1Object* l1object = ch->L1; + const TrigTauL2Object* l2object = ch->L2; + const TrigTauL2Object* l2calobject = ch->L2Cal; + const TrigTauL2Object* l2trkobject = ch->L2Trk; + const TrigTauRecEFObject* efobject = ch->EF; + + //check Level 1 + if (l1object == 0 ) { + if ( debug ) cout << "L1 Object is empty; go to next chain" << endl; + continue; + } + if( truth->DeltaR(*l1object)<0.2 ) { + if ( debug ) cout << "nL1Word is " << nl1Word << endl; + unsigned int currentWord = selmanager.l1Sel.cutWord(*l1object); + l1Word[nl1Word] = currentWord; + if ( debug ) cout << "Found L1 matched chain for number " << nl1Word << " with word :" << l1Word[nl1Word] << endl; + nl1Word++; + if (currentWord != 0 ) continue; + } + else continue; + + //check Level 2 (including Trk and Cal) + if (l2object == 0 ) { + if ( debug ) cout << "L2 object is empty; go to next chain" << endl; + continue; + } + if ( debug ) cout << " L2 DeltaR is :" << ( truth->DeltaR(*l2object) ) << endl; + if( truth->DeltaR(*l2object)<0.2 ) { + l2CaloWord[nl2Word] = selmanager.l2CalSel.cutWord(*l2calobject); + if ( l2CaloWord[nl2Word] !=0 ) { + l2TrkWord[nl2Word] = 255; + nl2Word++; + continue; + } + l2TrkWord[nl2Word] = selmanager.l2TrkSel.cutWord(*l2trkobject); + if ( debug ) cout << "Found L2 matched chain with words :" << l2CaloWord[nl2Word] << " and " << l2TrkWord[nl2Word] << endl; + nl2Word++; + if ( (l2CaloWord[nl2Word-1] !=0 ) || (l2TrkWord[nl2Word-1] !=0 ) ) continue; + } + else continue; + + + //check EF + if (efobject == 0 ) { + if ( debug ) cout << "EF object is empty; go to next chain" << endl; + continue; + } + if ( debug ) cout << " EF DeltaR is :" << (truth->DeltaR(*efobject) ) << endl; + if( truth->DeltaR(*efobject)<0.2 ) { + efWord[nefWord] = selmanager.efSel.cutWord(*efobject); + if ( debug ) cout << "Found EF matched chain with word :" << efWord[nefWord] << endl; + nefWord++; + if ( efWord[nefWord-1] == 0 && debug ) cout << "Tau passed trigger!!!" << endl; + + } + if ( ichain ==0 && debug ) cout << "Word No " << nTrigChains-1 << " is " << l1Word[nTrigChains-1] << endl; + } // end chain loop + + + bool fillHisto[nNames]; + for (int i=0; i!=nNames; ++i) + fillHisto[i] = false; + + for ( int i =0; i!=nl1Word; ++i) { + if ( debug ) cout << "The L1Word for chain " << i << " is " << l1Word[i] << endl; + for (int j=0; j!=nL1Cuts; ++j) { + if ( ((l1Word[i] >> j) & 0x01) ==0 ) fillHisto[j] = true; + else break; + } + } + + + for ( int i =0; i!=nl2Word; ++i) { + //if ( debug ) cout << "The L2Word for chain " << i << " is " << hex << l2Word[i] << endl; + for (int j=0; j!=nL2CaloCuts; ++j) { + if ( ((l2CaloWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts] = true; + else break; + } + for (int j=0; j!=nL2TrkCuts; ++j) { + if ( ((l2TrkWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts+nL2CaloCuts] = true; + else break; + } + } + + for ( int i =0; i!=nefWord; ++i) { + if ( debug ) cout << "The EFWord for chain " << i << " is " << efWord[i] << endl; + for (int j=0; j!=nEFCuts; ++j) { + if ( ((efWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts+nL2CaloCuts+nL2TrkCuts] = true; + else break; + } + } + + if ( debug ) { + cout << "TauCluster found - " << fillHisto[0] << endl; + cout << "L1EMIsol found - " << fillHisto[1] << endl; + cout << "L1HDIsol found - " << fillHisto[2] << endl; + } + + if ( debug ) cout << "First Histogram found; check if it will be filled." << endl; + for ( int j =0; j < nNames; ++j ) { + if ( fillHisto[j] ) { + //if ( debug ) cout << "Filling histogram..." <<endl; + TH1F * h =(TH1F*)histograms[3*j]; + h->Fill(pt); + h = histograms[3*j+1]; + h->Fill(phi); + h = histograms[3*j+2]; + h-> Fill(eta); + } + } + } // end loop over truth + + + } // end loop over events + + TH1F * EffHistograms[nHistos]; + gROOT->cd(); + char word; + switch ( type ) { + + case 1: + createHistograms(hnames, nNames, EffHistograms); + if ( debug ) cout << "Array for Histograms created..." << endl; + for (int j = 0; j != nHistos ; ++j ) { + if ( debug ) cout << "Pointer to histograms created" << endl; + if (!(j%3)) TH1F * effHist =(TH1F*)getEffHist(hTot[0],histograms[j],hnames[j/3]+"_absolut_eff", debug); + else if (!((j-1)%3)) TH1F * effHist =(TH1F*)getEffHist(hTot[1],histograms[j],hnames[(j-1)/3]+"_absolut_eff", debug); + else if (!((j-2)%3)) TH1F * effHist =(TH1F*)getEffHist(hTot[2],histograms[j],hnames[(j-2)/3]+"_absolut_eff", debug); + if ( debug ) cout <<j << " Efficicency Histograms created... " << endl; + EffHistograms[j] = effHist; + } + if (debug ) cout << "Efficiency Histograms filled." << endl; + + break; + + case 2 : + + createHistograms(hnames, nNames, EffHistograms); + if ( debug ) cout << "Array for Histograms created..." << endl; + for (int j = 0; j != nHistos ; ++j ) { + if ( debug ) cout << "Pointer to histograms created" << endl; + if ( j==0 || j==1 || j==2 ) TH1F * effHist = getEffHist(hTot[j],histograms[j],hnames[0]+"_rel_eff", debug); + else TH1F * effHist =(TH1F*)getEffHist(histograms[j-3],histograms[j],hnames[0]+"_rel_eff", debug); + if ( debug ) cout <<j << " Efficicency Histograms created... " << endl; + EffHistograms[j] = effHist; + } + if ( debug ) cout << "Efficiency Histograms filled." << endl; + + break; + + }; + + TCanvas * c1 = (TCanvas *) gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,500); + + if ( debug ) cout << "Draw Efficiency Histograms..." << endl; + for (int j = 0; j < nHistos ; ++j ) { + TH1F * histo = (TH1F*)EffHistograms[j]; + + if ( debug ) cout << "Draw Histogram No. " << j << endl; + if ( histo != 0 ) histo->Draw(); + if ( debug ) cout << "Printing Histogram No " << j << endl; + + if ( j==0 ) c1->Print("ntuple.eps("); + else if ( j+1==nHistos ) c1->Print("ntuple.eps)"); + else c1.Print("ntuple.eps"); + } + + return; +} + + + + + + +TH1F * getEffHist(TH1F * hTot, TH1F * hCut, const char * name, bool debug = false) +{ + if( hTot == 0 || hCut == 0 ) cout << "ERROR: Input to getEffHist is bad!!! " << endl; + + TH1F * hEff = (TH1F*)hTot->Clone(name); + if ( debug ) cout << "Dividing now...." << endl; + if (debug ) cout << "Dividing....done!" << endl; + hEff->GetYaxis()->SetTitle("Efficiency"); + hEff->SetMaximum(1.1); + hEff->SetMinimum(0); + if ( debug ) cout << "Configuration of histogram....done" << endl; + hEff->SetTitle(hCut->GetTitle()); + if ( debug ) cout << "Title set to " << hCut->GetTitle() << endl; + + int nbin = hCut->GetNbinsX(); + if ( debug ) cout << hCut->GetNbinsX() << " bins found..." << endl; + for(unsigned int itau = 1 ; itau < nbin ; ++itau) + { + float eff = 0; float errEff = 0; + if( hTot->GetBinContent(itau) > 0 ) + { + if (debug ) cout << "Bin content of hCut is " << hCut->GetBinContent(itau) << endl; + if ( debug ) cout << "Bin content of hTol is " << hTot->GetBinContent(itau) << endl; + float eff = float(hCut->GetBinContent(itau))/float( hTot->GetBinContent(itau)); + float errEff = sqrt(eff*(1.-eff)/float( hTot->GetBinContent(itau))); + if ( debug ) cout << "Reuting efficiency is " << eff << endl; + //eff *= 100.; + //errEff *= 100.; + hEff->SetBinContent(itau, eff); + hEff->SetBinError(itau, errEff); + } + } + return hEff; +} + +void createHistograms( vector<TString> names, unsigned int nNames, TH1F ** histoList) { + + for (int i = 0; i!=nNames; ++i ) { + TString name(names[i]+"_pt"); + //cout << " b\n"; + histoList[3*i] = new TH1F(name, name, 120, 0, 120000); + //cout << " c\n"; + TH1F * h1 = (TH1F*)histoList[3*i]; + //cout << " d\n"; + h1->GetXaxis()->SetTitle("pt"); + //cout << " e\n"; + + TString name(names[i]+"_phi"); + //cout << " f "<< 3*i+1 << " " << nNames<<"\n"; + histoList[3*i+1] = new TH1F(name, name, 64, -3.2, 3.2); + //cout << " g\n"; + TH1 * h2 = (TH1*)histoList[3*i+1]; + //cout << " h\n"; + h2->GetXaxis()->SetTitle("phi"); + //cout << " i\n"; + + TString name(names[i]+"_eta"); + histoList[3*i+2] = new TH1F(name, name, 50, -2.5, 2.5); + TH1 * h3 = (TH1*)histoList[3*i+2]; + h3->GetXaxis()->SetTitle("eta"); + //cout << " j\n"; + } + + return; + +} + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/validation3_06_dR03.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/validation3_06_dR03.cxx new file mode 100644 index 0000000000000000000000000000000000000000..bc074b38dc86baf8973154376ff80ee08094d3d6 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/macros/validation3_06_dR03.cxx @@ -0,0 +1,417 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +void validation3_06_dR03(const char * filename, int type = 2, bool debug = false ) { + + TChain * chain = new TChain("eventTree"); + chain->Add(filename); + //chain->Add("ntuples/14.2.0_May28/5107/tmp.*"); + //chain->Add("ntuples/14.2.0/5107/tmp.*"); + //chain->Add("ntuples/TTP09prelim/tmp.*"); + validation3_06_dR03(chain, type, debug); + +} + + +void validation3_06_dR03(TTree * tree, int type = 2, bool debug = false) +{ + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + TrigTauFlags::TRIGGERMENU menu1 = TrigTauFlags::TAU16I; + TrigTauSelectionManager::CUTLEVEL cutLevel = TrigTauSelectionManager::LOOSE; + bool signal = true; + + int nprong = 3; + // TAU1P3P, TAUREC, EITHERTAU, BOTHTAU, NONE + TrigTauMCTauList::OFFLINESELECTION offlineType = TrigTauMCTauList::NONE; + + TrigTauBugFix bugfix(TrigTauBugFix::TTP6, TrigTauBugFix::RDO); + + //=================================================== + TrigTauAnalyzer analyzer; + // MC truth + analyzer.truthList.setMaxVisEta(2.5); + analyzer.truthList.setMinVisPt(menu1); // in GeV + analyzer.truthList.setMinLeadingPt(6.); // pt of the leading pt of track is + if( nprong == 1 ) analyzer.truthList.select1Prong(); + else if( nprong == 3 ) analyzer.truthList.select3Prong(); + analyzer.truthList.setRecoMatchdR(0.2); + + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + //tree->SetBranchStatus("mcEvent*", 0); + + // Also set an L1 MET cut if desired + analyzer.trigMan.setL1MET(0.); + analyzer.trigMan.setMenuVersion(TrigTauSelectionManager::MENU1400 ); + analyzer.trigMan.setTauMenu(menu1, cutLevel); + analyzer.chainList.setRoiWordMatching(false); + + TH1F * hTot[3]; + hTot[0] = new TH1F("hptTot","",120,0,120000); + hTot[1] = new TH1F("hphiTot","",64,-3.2,3.2); + hTot[2] = new TH1F("hetaTot","",50,-2.5,2.5); + + //create list of histograms + vector<TString> hnames; + + //Level 1 + hnames.push_back("L1_TauCluster"); + hnames.push_back("L1_EMIsol"); + hnames.push_back("L1_HDIsol"); + hnames.push_back("L1_EMCore"); + hnames.push_back("L1_HDCore"); + hnames.push_back("L1_EMEnergy"); + //Level2 Calo + hnames.push_back("L2Calo_Et"); + hnames.push_back("L2Calo_Et_Calib"); + hnames.push_back("L2Calo_nStrips"); + hnames.push_back("L2Calo_stripWidth"); + hnames.push_back("L2Calo_EMRadius"); + hnames.push_back("L2Calo_IsoFrac"); + hnames.push_back("L2Calo_EMWidth"); + hnames.push_back("L2Calo_Et_Nar"); + //Level2 Track + hnames.push_back("L2Trk_nMinTrk");; + hnames.push_back("L2Trk_nSlow"); + hnames.push_back("L2Trk_nIso"); + hnames.push_back("L2Trk_nMatch"); + hnames.push_back("L2Trk_totCharge"); + hnames.push_back("L2Trk_maxPt"); + hnames.push_back("L2Trk_sumPtRatio"); + hnames.push_back("L2Trk_Et (Trk+EM)"); + //EF + hnames.push_back("EF_min nTrk"); + hnames.push_back("EF_max nTrk"); + hnames.push_back("EF_EMRadius"); + hnames.push_back("EF_IsoFrac"); + hnames.push_back("EF_EMFrac"); + hnames.push_back("EF_Pt_max"); + hnames.push_back("EF_Et"); + hnames.push_back("EF_EM_Et"); + hnames.push_back("EF_Mass"); + + const unsigned int nL1Cuts = 6; + const int nL2CaloCuts = 8; + const int nL2TrkCuts = 8; + const int nEFCuts = 9; + const unsigned int nHistos = hnames.size()*3; + const unsigned int nNames = hnames.size(); + + if ( nL1Cuts+nL2CaloCuts+nL2TrkCuts+nEFCuts != nNames ) { + cout << "ERROR: Number of Cuts for different levels incorrect!!!" << endl; + return; + } + + TH1F * histograms[nHistos]; + createHistograms(hnames, nNames, histograms); + + TrigTauSelectionManager selmanager; + selmanager.setMenuVersion(TrigTauSelectionManager::MENU1400); + selmanager.setTauMenu(menu1, TrigTauSelectionManager::LOOSE); + unsigned long l1Word[100]; + unsigned long l2CaloWord[100]; + unsigned long l2TrkWord[100]; + unsigned long l2Word[100]; + unsigned long efWord[100]; + + if ( debug ) selmanager.l2CalSel.setDebug(true); + // Loop over all events + int nev = int(tree->GetEntries()); + //if ( nev > 100 ) nev = 100; + for(int iev = 0; iev<nev; ++iev) { + if ( debug ) cout << "============== Checking event " << iev << " ==================" << endl; + event->reset(); + if (debug) cout << "Event reset..."<< endl; + tree->GetEvent(iev); + if (debug) cout << "Event choosen..." << endl; + bugfix.fix(event); + + if ( debug ) cout << "Analyze truth..." << endl; + analyzer.analyze(event, signal, offlineType); + + // ============ Select type of events (e.g. signal) ================ + if( signal ) { + analyzer.truthList.fillPureList(&event->mcEvent); + analyzer.truthList.fillGoodList(); + analyzer.truthList.requireRecoMatch(*event, offlineType); + if ( debug && analyzer.truthList.nMCTauGood() ==0 ) cout << "Event contains no good taus! " << endl; + if( analyzer.truthList.nMCTauGood() ==0 ) continue; + } + + // loop over taus after fiducial cuts + + if ( debug ) cout << "Event contains " << analyzer.truthList.nMCTauGood() << " good tau!" << endl; + for( unsigned int iTrue = 0; iTrue < analyzer.truthList.nMCTauGood(); ++iTrue ) //loop over all true taus + { + const TrigTauMCTau * truth = & analyzer.truthList.mcTauGoodEntry(iTrue); //select tau + float pt = truth->Pt(); + float eta = truth->Eta(); + float phi = truth->Phi(); + hTot[0]->Fill(pt); hTot[1]->Fill(phi); hTot[2]->Fill(eta); + + const unsigned int nTrigChains = analyzer.chainList.nTrigChains() ; + if (debug ) cout << "Value of nTrigChains: " << nTrigChains << endl; + if ( nTrigChains == 0 ) continue; + + unsigned int nl1Word = 0; + //unsigned int nl2CaloWord = 0; + //unsigned int nl2TrkWord = 0; + unsigned int nl2Word = 0; + unsigned int nefWord = 0; + + if ( debug ) cout << " There are " << nTrigChains << " chains to analyze." << endl; + for( unsigned int ichain = 0; ichain < nTrigChains; ++ichain) { + if ( debug ) cout << "Starting chain " << ichain << "!" << endl; + TrigTauTrigChain *ch = &analyzer.chainList.trigChainEntry(ichain); + const TrigTauL1Object* l1object = ch->L1; + const TrigTauL2Object* l2object = ch->L2; + const TrigTauL2Object* l2calobject = ch->L2Cal; + const TrigTauL2Object* l2trkobject = ch->L2Trk; + const TrigTauRecEFObject* efobject = ch->EF; + + //check Level 1 + if (l1object == 0 ) { + if ( debug ) cout << "L1 Object is empty; go to next chain" << endl; + continue; + } + if( truth->DeltaR(*l1object)<0.2 ) { + if ( debug ) cout << "nL1Word is " << nl1Word << endl; + if ( debug ) selmanager.l1Sel.setDebug(true); + unsigned int currentWord = selmanager.l1Sel.cutWord(*l1object); + l1Word[nl1Word] = currentWord; + if ( debug ) cout << "Found L1 matched chain for number " << nl1Word << " with word :" << l1Word[nl1Word] << endl; + nl1Word++; + if (currentWord != 0 ) continue; + } + else continue; + + //check Level 2 (including Trk and Cal) + if (l2object == 0 ) { + if ( debug ) cout << "L2 object is empty; go to next chain" << endl; + continue; + } + if ( debug ) cout << " L2 DeltaR is :" << ( truth->DeltaR(*l2object) ) << endl; + if( truth->DeltaR(*l2object)<0.2 ) { + + l2CaloWord[nl2Word] = selmanager.l2CalSel.cutWord(*l2calobject); + if ( l2CaloWord[nl2Word] !=0 ) { + l2TrkWord[nl2Word] = 255; + nl2Word++; + continue; + } + if (debug) selmanager.l2TrkSel.setDebug(true); + l2TrkWord[nl2Word] = selmanager.l2TrkSel.cutWord(*l2trkobject); + if ( debug ) cout << "Found L2 matched chain with words :" << l2CaloWord[nl2Word] << " and " << l2TrkWord[nl2Word] << endl; + nl2Word++; + if ( (l2CaloWord[nl2Word-1] !=0 ) || (l2TrkWord[nl2Word-1] !=0 ) ) continue; + } + else continue; + + + //check EF + if (efobject == 0 ) { + if ( debug ) cout << "EF object is empty; go to next chain" << endl; + continue; + } + if ( debug ) cout << " EF DeltaR is :" << (truth->DeltaR(*efobject) ) << endl; + if( truth->DeltaR(*efobject)<0.2 ) { + if (debug) selmanager.efSel.setDebug(true); + efWord[nefWord] = selmanager.efSel.cutWord(*efobject); + if ( debug ) cout << "Found EF matched chain with word :" << efWord[nefWord] << endl; + nefWord++; + if ( efWord[nefWord-1] == 0 && debug ) cout << "Tau passed trigger!!!" << endl; + + } + if ( ichain ==0 && debug ) cout << "Word No " << nTrigChains-1 << " is " << l1Word[nTrigChains-1] << endl; + } // end chain loop + + + bool fillHisto[nNames]; + for (int i=0; i!=nNames; ++i) + fillHisto[i] = false; + + for ( int i =0; i!=nl1Word; ++i) { + if ( debug ) cout << "The L1Word for chain " << i << " is " << l1Word[i] << endl; + for (int j=0; j!=nL1Cuts; ++j) { + if ( ((l1Word[i] >> j) & 0x01) ==0 ) fillHisto[j] = true; + else break; + } + } + + + for ( int i =0; i!=nl2Word; ++i) { + //if ( debug ) cout << "The L2Word for chain " << i << " is " << hex << l2Word[i] << endl; + for (int j=0; j!=nL2CaloCuts; ++j) { + if ( ((l2CaloWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts] = true; + else break; + } + for (int j=0; j!=nL2TrkCuts; ++j) { + if ( ((l2TrkWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts+nL2CaloCuts] = true; + else break; + } + } + + for ( int i =0; i!=nefWord; ++i) { + if ( debug ) cout << "The EFWord for chain " << i << " is " << efWord[i] << endl; + for (int j=0; j!=nEFCuts; ++j) { + if ( ((efWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts+nL2CaloCuts+nL2TrkCuts] = true; + else break; + } + } + + if ( debug ) { + cout << "TauCluster found - " << fillHisto[0] << endl; + cout << "L1EMIsol found - " << fillHisto[1] << endl; + cout << "L1HDIsol found - " << fillHisto[2] << endl; + } + + if ( debug ) cout << "First Histogram found; check if it will be filled." << endl; + for ( int j =0; j < nNames; ++j ) { + if ( fillHisto[j] ) { + //if ( debug ) cout << "Filling histogram..." <<endl; + TH1F * h =(TH1F*)histograms[3*j]; + h->Fill(pt); + h = histograms[3*j+1]; + h->Fill(phi); + h = histograms[3*j+2]; + h-> Fill(eta); + } + } + } // end loop over truth + + + } // end loop over events + + TH1F * EffHistograms[nHistos]; + gROOT->cd(); + char word; + switch ( type ) { + + case 1: + createHistograms(hnames, nNames, EffHistograms); + if ( debug ) cout << "Array for Histograms created..." << endl; + for (int j = 0; j != nHistos ; ++j ) { + if ( debug ) cout << "Pointer to histograms created" << endl; + if (!(j%3)) TH1F * effHist =(TH1F*)getEffHist(hTot[0],histograms[j],hnames[j/3]+"_absolut_eff", debug); + if (!((j-1)%3)) TH1F * effHist =(TH1F*)getEffHist(hTot[1],histograms[j],hnames[(j-1)/3]+"_absolut_eff", debug); + if (!((j-2)%3)) TH1F * effHist =(TH1F*)getEffHist(hTot[2],histograms[j],hnames[(j-2)/3]+"_absolut_eff", debug); + if ( debug ) cout <<j << " Efficicency Histograms created... " << endl; + EffHistograms[j] = effHist; + } + if (debug ) cout << "Efficiency Histograms filled." << endl; + + break; + + case 2 : + + createHistograms(hnames, nNames, EffHistograms); + if ( debug ) cout << "Array for Histograms created..." << endl; + for (int j = 0; j != nHistos ; ++j ) { + if ( debug ) cout << "Pointer to histograms created" << endl; + if ( j==0 || j==1 || j==2 ) TH1F * effHist = getEffHist(hTot[j],histograms[j],hnames[0]+"_rel_eff", debug); + else TH1F * effHist =(TH1F*)getEffHist(histograms[j-3],histograms[j],hnames[0]+"_rel_eff", debug); + if ( debug ) cout <<j << " Efficicency Histograms created... " << endl; + EffHistograms[j] = effHist; + } + if ( debug ) cout << "Efficiency Histograms filled." << endl; + + break; + + }; + + TCanvas * c1 = (TCanvas *) gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,500); + + if ( debug ) cout << "Draw Efficiency Histograms..." << endl; + for (int j = 0; j < nHistos ; ++j ) { + TH1F * histo = (TH1F*)EffHistograms[j]; + + if ( debug ) cout << "Draw Histogram No. " << j << endl; + if ( histo != 0 ) histo->Draw(); + if ( debug ) cout << "Printing Histogram No " << j << endl; + + if ( j==0 ) c1->Print("ntuple.eps("); + else if ( j+1==nHistos ) c1->Print("ntuple.eps)"); + else c1.Print("ntuple.eps"); + } + + return; +} + + + + + + +TH1F * getEffHist(TH1F * hTot, TH1F * hCut, const char * name, bool debug = false) +{ + if( hTot == 0 || hCut == 0 ) cout << "ERROR: Input to getEffHist is bad!!! " << endl; + + TH1F * hEff = (TH1F*)hTot->Clone(name); + if ( debug ) cout << "Dividing now...." << endl; + if (debug ) cout << "Dividing....done!" << endl; + hEff->GetYaxis()->SetTitle("Efficiency"); + hEff->SetMaximum(1.1); + hEff->SetMinimum(0); + if ( debug ) cout << "Configuration of histogram....done" << endl; + hEff->SetTitle(hCut->GetTitle()); + if ( debug ) cout << "Title set to " << hCut->GetTitle() << endl; + + int nbin = hCut->GetNbinsX(); + if ( debug ) cout << hCut->GetNbinsX() << " bins found..." << endl; + for(unsigned int itau = 1 ; itau < nbin ; ++itau) + { + float eff = 0; float errEff = 0; + if( hTot->GetBinContent(itau) > 0 ) + { + if (debug ) cout << "Bin content of hCut is " << hCut->GetBinContent(itau) << endl; + if ( debug ) cout << "Bin content of hTol is " << hTot->GetBinContent(itau) << endl; + float eff = float(hCut->GetBinContent(itau))/float( hTot->GetBinContent(itau)); + float errEff = sqrt(eff*(1.-eff)/float( hTot->GetBinContent(itau))); + if ( debug ) cout << "Reuting efficiency is " << eff << endl; + //eff *= 100.; + //errEff *= 100.; + hEff->SetBinContent(itau, eff); + hEff->SetBinError(itau, errEff); + } + } + return hEff; +} + +void createHistograms( vector<TString> names, unsigned int nNames, TH1F ** histoList) { + + for (int i = 0; i!=nNames; ++i ) { + TString name(names[i]+"_pt"); + //cout << " b\n"; + histoList[3*i] = new TH1F(name, name, 120, 0, 120000); + //cout << " c\n"; + TH1F * h1 = (TH1F*)histoList[3*i]; + //cout << " d\n"; + h1->GetXaxis()->SetTitle("pt"); + //cout << " e\n"; + + TString name(names[i]+"_phi"); + //cout << " f "<< 3*i+1 << " " << nNames<<"\n"; + histoList[3*i+1] = new TH1F(name, name, 64, -3.2, 3.2); + //cout << " g\n"; + TH1 * h2 = (TH1*)histoList[3*i+1]; + //cout << " h\n"; + h2->GetXaxis()->SetTitle("phi"); + //cout << " i\n"; + + TString name(names[i]+"_eta"); + histoList[3*i+2] = new TH1F(name, name, 50, -2.5, 2.5); + TH1 * h3 = (TH1*)histoList[3*i+2]; + h3->GetXaxis()->SetTitle("eta"); + //cout << " j\n"; + } + + return; + +} + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/manual b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/manual new file mode 100644 index 0000000000000000000000000000000000000000..fac8e0c0409176417c705e0107330813fe890f8a --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/manual @@ -0,0 +1,207 @@ +**This is a general description of the tools in TTPValidation. For examples, please see the 'howto' file!** +the TTPValidation package provides tools for analyzing TTP ntuples and to organize histograms. There are several tools that all follow the same structure: + +1. Create an instance (call constructor) +2. Alter default variables (with setVariable and getVariable) +3. Analyze data (with analyze()) +4. Save histogram in eps or root file, compare to previously produced histograms. (using print for eps file and save for root file) + +If not specified by the individual tools, these are the default values: + +signal: true (for signal: preselect "good" taus; includes truth matching) +nprong: 0 (no requirements for tau decays; 1 - 1-Prong decays; 2 - 3-Prong decays) +maxVisEta: 2.5 +minLeadingPt: 6.0 +menu: TrigTauFlags::TAU16 +cutLevel: TrigTauSelectionManager::LOOSE +Offline Matching: TrigTauMCTauList::TAUCUTSAFEMEDIUM +Type of Chain: IDScan +menuVersion: 15.6.0 (this specifies the version of the cut values) +namingConvention: 16.0.0 (this needs to be set to 15.6.0 for ntuples produced before the change in default L2 tracking algorithm to SiTrk) +Debug: False (if true: prints DEBUG messages to simplify debugging code) +TrigTauBugFix: RDO (needs to be changed by giving 'TrigTauBugFix::AOD' as argument for constructor if you don't run on TTPs created from RDOs) +TrigTauBugFix version: TTP15 + +Filename for saving an eps file: trigtau.ntuple.eps +Filename for saving a root file: histo.root +Filename for saving an eps file after comparison: ntuple.eps + +All variables are set and read with + +setVariable(...); +getVariable(...); + +Here is a list of all individual tools with a short description of their usage and variations of the default behaviour: + + + +1. TTPValCutStudy + +Description: cutStudy plots relative or absolute efficiency after each potential cut (even if the cut is turned off) as a function of visible E_t, eta and phi. Relative means that it plots the efficiency with respect to the previous level, while absolute uses all true "good" taus. + +Constructors: + TTPValCutStudy(TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP9, bool debug1 = false); + TTPValCutStudy ( char * filename1 , TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP9, bool debug1 = false); + +Special variables: + + 'type' + Defines wether relative or absolute efficiencies are plotted. 0 - absolute efficiencies; 1 - relative efficiencies; default is 1. + +Special Functions: + + 'void compare(const char * reference1, const char * reference2, const char * saveName)' + compares output to two reference files and saves it under saveName. + + void effSequencePlotsUpdate(TString name); + This plots the L1, L2 and EF turn-on curves in one diagram. This comes from former macro "effSequencePlot2.cxx" + + + + + +2. TTPValEffTableMaker + +Description: tableMaker prints a list of relative or absolute efficiencies for all different decay types (including ALL) and different offline matching after each level. Relative efficiencies are calculated with respect to the previous level. The printout always includes a summary for EITHERTAU offline matching. + +Constructors: + TTPValEffTableMaker( TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP9, bool debug1 = false); + TTPValEffTableMaker( char * filename1, TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP9, bool debug1 = false); + +Special Variables: + The variables for nProng and offlineMatching are not present, since efficiencies are printed for all settings. + +Special Functions: + + 'void print( int which = 1 );' + prints relative efficiency by default. when using print(0);, absolute efficiencies are printed + + + + +3. TTPValRateTable + +Description: Prints number of passed events for each level for both the real trigger decision (TriggerBit) and from the simulated trigger. This way, one can estimate the accuracy of the trigger simulation. If given cross-section for the used sample and luminosity in the same units, it also returns rates for all levels. + +Constructors: + TTPValRateTable(TrigTauBugFix::POOLFILE poolfile1 = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version1 = TrigTauBugFix::TTP9, bool debug1 = false); + TTPValRateTable( char * filename1 , TrigTauBugFix::POOLFILE poolfile1 = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version1 = TrigTauBugFix::TTP9, bool debug1 = false); + +Special Variables: + + 'doDetailedPrinting' + Default value: false; prints out event information in case the triggerBit and the result from the trigger simulation don't agree. + + +Special Functions: + + 'void analyze(int nEvents = 10000000);' + One can set a number of events to be analyzed; Default value is 10,000,000. + + 'checkAllMenus(unsigned int nMenu = 9, unsigned int nLevels = 3, double lum = 0, double crosssec = 0)' + prints info for the 9 first menus and the 3 first cutLevels. If given luminocity and x-sec, it calculates rates for each of them. + + 'void print (double lum, double crosssec);' + prints info for given menu and given cutLevel. If given luminocity and x-sec, it also calculates rates. + + + + +4. TTPValDistribution + +Description: Plots distribution for all variables that can be cut on. + +Constructors: + TTPValDistribution(TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP7, bool debug1 = false); + TTPValDistribution ( char * filename1 , TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP7, bool debug1 = false); + +Special Variables: + + 'selected' + Default value is TRUE. If True, range of data that can be filled in histogram is preselected. That leads to histograms that don't include dummy variables that are way out of range (like eta=-99) + + 'logScale' + Default: FALSE. If True, histograms have logarithmic scale. + + 'plotAllMatchedEvents = false;' + Default value is FALSE. If true, requires no passing of previous trigger levels. + + 'ignoreMatching' + Default value is FALSE. If true, ignores all matching with offline object. + +Special Functions: + + 'void setSelection ( bool newValue )' + Defines variable: SELECTED (see above) + + 'void setPlotAllEvents (bool newValue)' + Defines ignoreMatching (see above). + + + + +5. TTPValVariables + +Description: Prints value of a set of variables for all Menus for ALL events. Does not require any minimum cuts. + +Constructors: + + TTPValVariables(TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP7, bool debug1 = false); + TTPValVariables ( char * filename1 , TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP7, bool debug1 = false); + +Special Variables: + + Uses only default variabels for menu. All minimum cut variables are set to zero. 'Signal' is False by default. + +Special Functions: + + void analyze(int number = 10000000, bool chains=false, bool l1 = true, bool l2 = true, bool efid = true, bool ef = true); + The function analyze, which prints out the variables, takes in booleans if only selected output is needed. + + + +6. TTPValBackgroundStudy + +Description: This tool is designed to study background rates and the effect of all cuts on the background. It shows efficiency for each cut with respect to pt, eta and phi. Can print rates after each cut. + +Constructors: + + TTPValBackgroundStudy(TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP11, bool debug1 = false); + TTPValBackgroundStudy (TString filename1 , TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP11, bool debug1 = false); + +Special variables: + + By default "signal" is set to false, since this is supposed to run mainly on background. Additionally minLeadingPt is set to zero, since this is used for signal efficiency studies. Offline matching is set to "NONE". + +Special functions: + + void print(float lum = 0, float xsection = 0); + + The print function prints the rates for each cut on the screen, if luminocity and x-section is given in similar units. + + compare(TString reference); + + The compare function compares the output to the given reference file and saves it under ntuple.eps. Optionally, the output file name can be given as a second argument. There is also a compare function that compares the current analysis to two reference files and saves it under a specified filename (so three filenames have to be given as argument). + + effSequencePlotsUpdate(TString name); + + Left-over from previous version. Don't use it. + + + +7. TTPValEfficiencyMultiPlots + +Description: This tool prints turn-on curves for a given level for all menus. + +Constructors: + + TTPValMultiPlots (TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP11, bool debug1 = false); + TTPValMultiPlots ( TString filename1 , TrigTauBugFix::POOLFILE poolfile = TrigTauBugFix::RDO, TrigTauBugFix::TTPVERSION version = TrigTauBugFix::TTP11, bool debug1 = false); + +Special Variables: + + none + +Special Functions: + + none diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValBackgroundStudy.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValBackgroundStudy.cxx new file mode 100644 index 0000000000000000000000000000000000000000..baee961371593c75003e413aceb26660634c5e77 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValBackgroundStudy.cxx @@ -0,0 +1,775 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +using namespace std; +#include "TrigTauPerformValidation/TTPValBackgroundStudy.h" + + + +TTPValBackgroundStudy::TTPValBackgroundStudy ( bool invertL21, TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version, poolfile) { + cout << "WARNING: Filename not specified!! " << endl; + initialize(debug1, invertL21); + fileDefined = false; + return; +} + +TTPValBackgroundStudy::TTPValBackgroundStudy (TString filename1, bool invertL21, TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version, poolfile) { + + if (debug1) cout << " Creating validation4 object..." << endl; + filename = filename1; + chain = new TChain("eventTree"); + chain->Add(filename); + initialize(debug1, invertL21); + fileDefined = true; + return; +} + +void TTPValBackgroundStudy::initialize(bool debug1, bool invertL21) { + + + type = 1; + debug = debug1; + signal = false; + invertL2 = invertL21; + nprong = 0; + maxVisEta = 2.5; + minLeadingPt = 6.0; + totalPassed =0; + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + menu = TrigTauFlags::TAU16; + cutLevel = TrigTauSelectionManager::LOOSE; + offlineType = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + menuVersion = TrigTauSelectionManager::MENU1560; + chainType = TrigTauFlags::SITRK; + + hTot[0] = new TH1F("TTPValBackgroundStudy_hptTot","",50,0,120000); + hTot[1] = new TH1F("TTPValBackgroundStudy_hphiTot","",64,-3.2,3.2); + hTot[2] = new TH1F("TTPValBackgroundStudy_hetaTot","",50,-2.5,2.5); + + testHisto[0] = new TH2F("TTPValBackgroundStudy_EF Calo EtHad", "",64, -3.2, 3.2, 100, 0, 1.5); + testHisto[0]->GetXaxis()->SetTitle("eta"); + testHisto[0]->GetYaxis()->SetTitle("EtHadCalib: EF/Offline"); + + testHisto[1] = new TH2F("TTPValBackgroundStudy_EF Calo EtEM", "",64, -3.2, 3.2, 100, 0, 1.5); + testHisto[1]->GetXaxis()->SetTitle("eta"); + testHisto[1]->GetYaxis()->SetTitle("EtEMCalib: EF/Offline"); + + + //Level 1 + hnames.push_back("L1_TauCluster"); + hnames.push_back("L1_EMIsol"); + hnames.push_back("L1_HDIsol"); + hnames.push_back("L1_EMCore"); + hnames.push_back("L1_HDCore"); + hnames.push_back("L1_EMEnergy"); + + if (invertL2) { + //Level2 Track + hnames.push_back("L2Trk_nTrk");; + hnames.push_back("L2Trk_nSlow"); + hnames.push_back("L2Trk_nIso"); + hnames.push_back("L2Trk_nMatch"); + hnames.push_back("L2Trk_totCharge"); + hnames.push_back("L2Trk_maxPt"); + hnames.push_back("L2Trk_sumPtRatio"); + hnames.push_back("L2Trk_Et (Trk+EM)"); + //Level2 Calo + hnames.push_back("L2Calo_Et"); + hnames.push_back("L2Calo_Et_Calib"); + hnames.push_back("L2Calo_nStrips"); + hnames.push_back("L2Calo_stripWidth"); + hnames.push_back("L2Calo_EMRadius"); + hnames.push_back("L2Calo_IsoFrac"); + hnames.push_back("L2Calo_EMWidth"); + hnames.push_back("L2Calo_Et_Nar"); + } + else { + //Level2 Calo + hnames.push_back("L2Calo_Et"); + hnames.push_back("L2Calo_Et_Calib"); + hnames.push_back("L2Calo_nStrips"); + hnames.push_back("L2Calo_stripWidth"); + hnames.push_back("L2Calo_EMRadius"); + hnames.push_back("L2Calo_IsoFrac"); + hnames.push_back("L2Calo_EMWidth"); + hnames.push_back("L2Calo_Et_Nar"); + //Level2 Track + hnames.push_back("L2Trk_nTrk");; + hnames.push_back("L2Trk_nSlow"); + hnames.push_back("L2Trk_nIso"); + hnames.push_back("L2Trk_nMatch"); + hnames.push_back("L2Trk_totCharge"); + hnames.push_back("L2Trk_maxPt"); + hnames.push_back("L2Trk_sumPtRatio"); + hnames.push_back("L2Trk_Et (Trk+EM)"); + } + //EF + hnames.push_back("EF_min nTrk_EFID"); + hnames.push_back("EF_min nTrk"); + hnames.push_back("EF_max nTrk"); + hnames.push_back("EF_EMRadius"); + hnames.push_back("EF_IsoFrac"); + hnames.push_back("EF_EMFrac"); + hnames.push_back("EF_Pt_max"); + hnames.push_back("EF_Et"); + hnames.push_back("EF_EM_Et"); + hnames.push_back("EF_Mass"); + + nL1Cuts = 6; + nL2CaloCuts = 8; + nL2TrkCuts = 8; + nEFCuts = 10; + nHistos = hnames.size()*3; + nNames = hnames.size(); + + for ( unsigned int j =0; j < nNames; ++j ) + passedCounter[j] =0; + + + //static const unsigned int nHistosConst = nHistos; + //TH1F * histograms[nHistosConst]; + + if ( nL1Cuts+nL2CaloCuts+nL2TrkCuts+nEFCuts != nNames || nNames*3 != nHistograms ) { + cout << "ERROR: Number of Cuts for different levels incorrect!!!" << endl; + return; + } + + if (debug) cout << "Creating Histograms..." << endl; + createHistograms(histograms); + if (debug) cout << "Histograms created! Building selmanager..." << endl; + +} + + +void TTPValBackgroundStudy::setFile( TString filename1) { + filename = filename1; + chain = new TChain("eventTree"); //potential memory leak + chain->Add(filename); + fileDefined = true; + return; +} + + +void TTPValBackgroundStudy::analyze() { + + if (!fileDefined) { + cout << "File was not defined and variables not initialized!!" << endl; + return; + } + + selmanager.setMenuVersion(menuVersion); + selmanager.setTauMenu(menu, cutLevel ); + + // MC truth + analyzer.truthList.setMaxVisEta(maxVisEta); + analyzer.truthList.setMinVisPt(menu); // in GeV + analyzer.truthList.setMinLeadingPt(minLeadingPt); // pt of the leading pt of track is + if( nprong == 1 ) analyzer.truthList.select1Prong(); + else if( nprong == 3 ) analyzer.truthList.select3Prong(); + analyzer.truthList.setRecoMatchdR(0.2); + + event = new TrigTauEvent(); + chain->SetBranchAddress("EventBranch", &event); + chain->SetBranchStatus("*", 1); + + // Also set an L1 MET cut if desired + analyzer.trigMan.setL1MET(0.); + analyzer.trigMan.setMenuVersion(menuVersion); + analyzer.trigMan.setTauMenu(menu, cutLevel); + analyzer.chainList.setRoiWordMatching(false); + analyzer.chainList.setHLTAuthor(chainType); + + testing = 0; + + nev = int(chain->GetEntries()); + //if ( nev > 100 ) nev = 100; + for(int iev = 0; iev<nev; ++iev) { + analyzeEvent( iev ); + } + if (debug) cout << "L1 Had Energy accepted events: " << testing <<endl; + return; +} + + +void TTPValBackgroundStudy::analyzeEvent(int eventNumber) { + + event->reset(); + chain->GetEvent(eventNumber); + bugfix.fix(event); + + analyzer.analyze(event, signal, offlineType); + + // ============ Select type of events (e.g. signal) ================ + if( signal ) { + // analyzer.truthList.fillPureList(&event->mcEvent); +// analyzer.truthList.fillGoodList(); +// analyzer.truthList.requireRecoMatch(*event, offlineType); + if ( debug && analyzer.truthList.nMCTauGood() ==0 ) cout << "Event contains no good taus! " << endl; + if( analyzer.truthList.nMCTauGood() ==0 ) return; + } + + // loop over taus after fiducial cuts + + if ( debug ) cout << "Event contains " << analyzer.truthList.nMCTauGood() << " good tau!" << endl; + + unsigned int nTrigChains = analyzer.chainList.nTrigChains() ; + if ( nTrigChains == 0 ) return; + + unsigned int nl1Word = 0; + //unsigned int nl2CaloWord = 0; + //unsigned int nl2TrkWord = 0; + unsigned int nl2Word = 0; + unsigned int nefWord = 0; + + if ( debug ) cout << " There are " << nTrigChains << " chains to analyze." << endl; + for( unsigned int ichain = 0; ichain < nTrigChains; ++ichain) { + if ( debug ) cout << "Starting chain " << ichain << "!" << endl; + const TrigTauTrigChain *ch = &analyzer.chainList.trigChainEntry(ichain); + const TrigTauL1Object* l1object = ch->L1; + const TrigTauL2Object* l2object = ch->L2; + const TrigTauL2Object* l2calobject = ch->L2Cal; + const TrigTauL2Object* l2trkobject = ch->L2Trk; + const TrigTauRecEFObject* efobject = ch->EF; + const TrigTauRecOfflineObject* offlineobject = ch->tauRec; + + float pt = 0; + float eta = 0; + float phi = 0; + + if (offlineobject != 0) { + pt = offlineobject->Pt(); + eta = offlineobject->Eta(); + phi = offlineobject->Phi(); + } + + bool stop = false; + + //check Level 1 + if (l1object == 0 ) stop = true; + if (!stop) { + unsigned int currentWord = selmanager.l1Sel.cutWord(*l1object); + l1Word[nl1Word] = currentWord; + nl1Word++; + if (currentWord != 0 ) stop = true; + } + + //check Level 2 (including Trk and Cal) + if (invertL2) { + if (l2object == 0 ) stop = true; + if (!stop) { + l2TrkWord[nl2Word] = selmanager.l2TrkSel.cutWord(*l2trkobject); + if ( l2TrkWord[nl2Word] !=0 ) { + l2CaloWord[nl2Word] = 255; + stop = true; + } + + if (!stop) l2CaloWord[nl2Word] = selmanager.l2CalSel.cutWord(*l2calobject); + nl2Word++; + if ( l2CaloWord[nl2Word-1] !=0 ) stop = true; + } + } + else { + if (l2object == 0 ) stop = true; + if (!stop) { + l2CaloWord[nl2Word] = selmanager.l2CalSel.cutWord(*l2calobject); + if ( l2CaloWord[nl2Word] !=0 ) { + l2TrkWord[nl2Word] = 255; + stop = true; + } + + if (!stop) l2TrkWord[nl2Word] = selmanager.l2TrkSel.cutWord(*l2trkobject); + nl2Word++; + if ( l2TrkWord[nl2Word-1] !=0 ) stop = true; + } + } + + //check EF + if (efobject == 0 ) stop = true; + if (!stop) { + efWord[nefWord] = selmanager.efSel.cutWord(*efobject); + nefWord++; + if (offlineobject != 0 && offlineobject->m_etHadCalib != 0 ) testHisto[0]->Fill(efobject->Eta(),efobject->m_etHadCalib/offlineobject->m_etHadCalib); + if (offlineobject != 0 && offlineobject->m_etEMCalib != 0 ) testHisto[1]->Fill(efobject->Eta(),efobject->m_etEMCalib/offlineobject->m_etEMCalib); + } + } + for (unsigned int i=0; i!=nNames; ++i) + fillHisto[i] = false; + + for ( unsigned int i =0; i!=nl1Word; ++i) { + for ( unsigned int j=0; j!=nL1Cuts; ++j) { + if ( ((l1Word[i] >> j) & 0x01) ==0 ) fillHisto[j] = true; + else break; + } + } + + if (invertL2) { + for (unsigned int i =0; i!=nl2Word; ++i) { + for (unsigned int j=0; j!=nL2TrkCuts; ++j) { + if ( ((l2TrkWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts+nL2CaloCuts] = true; + else break; + } + for (unsigned int j=0; j!=nL2CaloCuts; ++j) { + if ( ((l2CaloWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts] = true; + else break; + } + } + } + else { + for (unsigned int i =0; i!=nl2Word; ++i) { + for (unsigned int j=0; j!=nL2CaloCuts; ++j) { + if ( ((l2CaloWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts] = true; + else break; + } + for (unsigned int j=0; j!=nL2TrkCuts; ++j) { + if ( ((l2TrkWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts+nL2CaloCuts] = true; + else break; + } + } + } + + for ( unsigned int i =0; i!=nefWord; ++i) { + for ( unsigned int j=0; j!=nEFCuts; ++j) { + if ( ((efWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts+nL2CaloCuts+nL2TrkCuts] = true; + else break; + } + } + + if ( debug ) { + cout << "TauCluster found - " << fillHisto[0] << endl; + cout << "L1EMIsol found - " << fillHisto[1] << endl; + cout << "L1HDIsol found - " << fillHisto[2] << endl; + } + testing = testing+fillHisto[1]; + if ( debug ) cout << "First Histogram found; check if it will be filled." << endl; + for ( unsigned int j =0; j < nNames; ++j ) { + if ( fillHisto[j] ) { + //if ( debug ) cout << "Filling histogram..." <<endl; + TH1F * h =(TH1F*)histograms[3*j]; + h->Fill(10); + h = histograms[3*j+1]; + h->Fill(0); + h = histograms[3*j+2]; + h-> Fill(0); + } + } + for ( unsigned int j =0; j < nNames; ++j ) + if ( fillHisto[j] ) passedCounter[j]++; + return; +} + +void TTPValBackgroundStudy::print(float lum, float xsection) { + + print("ntuple.background.eps", lum, xsection); + +} + + +void TTPValBackgroundStudy::print(TString name, float lum, float xsection) { + + createEffHistograms(); + + TCanvas * c1 = (TCanvas *)gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,500); + + if ( debug ) cout << "Draw Efficiency Histograms..." << endl; + for (unsigned int j = 0; j < nHistos ; ++j ) { + TH1F * histo = (TH1F*)effHistograms[j]; + + if ( debug ) cout << "Draw Histogram No. " << j << endl; + if ( histo != 0 ) histo->Draw(); + if ( debug ) cout << "Printing Histogram No " << j << endl; + + if ( j==0 ) c1->Print(TString(name)+"("); + //else if ( j+1==nHistos ) c1->Print(TString(name)+")"); + else c1->Print(name); + } + + TH2F * histo2 = (TH2F*)testHisto[0]; + if (histo2 !=0 ) histo2->Draw("BOX"); + c1->Print(TString(name)); + + histo2 = 0; + + histo2 = (TH2F*)testHisto[1]; + if (histo2 !=0 ) histo2->Draw("BOX"); + + c1->Print(TString(name)+")"); + + cout << "Rates after various cuts: " << endl; + + for (unsigned int i = 0; i<hnames.size(); ++i) { + cout << setiosflags(ios::left) << setw(20) << hnames[i] << ": " << lum*xsection*passedCounter[i]/nev << " Hz" << endl; + //cout << " PassedCounter of " << i << " is "<< passedCounter[i] << endl; + } + //cout << "Total Number of Events: " << nev << endl; + return; +} + +void TTPValBackgroundStudy::save() { + + save("histo.background.root"); + +} + + +void TTPValBackgroundStudy::save(TString name) { + + createEffHistograms(); + + TH1F * histo; + TH2F * histo2; + + if (debug) cout << "Starting Save..." << endl; + TFile f(name, "recreate"); + if (debug) cout << "File created..." << endl; + for (unsigned int j = 0; j < nHistos ; ++j ) { + histo = (TH1F*)effHistograms[j]; + if (debug) cout << "Writing histogram " << j << "...." << endl; + histo->Write(); + histo->Draw(); + } + //f->Write(); + + histo2 = (TH2F*)testHisto[0]; + histo2->Write(); + histo2->Draw("BOX"); + + histo2 = (TH2F*)testHisto[1]; + histo2->Write(); + histo2->Draw("BOX"); + + if (debug) cout << "Histograms written..." << endl; + f.Close(); + return; + +} + +void TTPValBackgroundStudy::compare(TString reference) { + + compare(reference, "", "ntuple.eps"); + +} + +void TTPValBackgroundStudy::compare(TString reference, TString saveFile) { + + compare(reference, "", saveFile); + +} + + +void TTPValBackgroundStudy::compare(TString reference1, TString reference2, TString saveFile) { + + createEffHistograms(); + + TCanvas * c2 = (TCanvas *)gROOT->Get("c2"); + if( c2 ) delete c2; + c2 = new TCanvas("c1","",10,10,800,500); + + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + + if (debug) cout << "Opening file..." << endl; + + TFile * file1 = new TFile(reference1); + TFile * file2 = 0; + if (reference2[0] != '\0') file2 = new TFile(reference2); + + for (unsigned int j=0; j!= nHistos; ++j) { + + if (debug) cout << "Processing Histogram " << j << endl; + + TH1* h1 = (TH1*)gROOT->Get("h1"); + if( h1 ) delete h1; + if (debug) cout << " Cloning h1...." << endl; + h1 = (TH1*)effHistograms[j]->Clone("h1"); + + if (debug) cout << " h1 found...." << endl; + + if (debug) cout << "Creating TString..." << endl; + TString histoName("TTPValBackgroundStudy_"); + if (debug) cout << "Initial TString created..." << endl; + histoName+=hnames[j/3]; + if (debug) cout <<"TString 1nd part added..." << endl; + if ( !(j%3) ) histoName+="_pt"; + else if (!((j-1)%3)) histoName+="_eta"; + else if (!((j-2)%3)) histoName+="_phi"; + + TH1* h2 = 0; + //h2 = (TH1*)gROOT->Get("h2"); + //if( h2 ) delete h2; + if (debug) cout << "Accessing histogram: " << histoName << endl; + h2 = (TH1*)file1->Get(histoName)->Clone("h2"); + //if ( !(j%3) ) h2 = (TH1*)file1->Get("TTPValBackgroundStudy_"+hnames[j/3]+"_pt")->Clone("h2"); + //else if (!((j-1)%3)) h2 = (TH1*)file1->Get("TTPValBackgroundStudy_"+hnames[(j-1)/3]+"_eta")->Clone("h2"); + //else if (!((j-2)%3)) h2 = (TH1*)file1->Get("TTPValBackgroundStudy_"+hnames[(j-2)/3]+"_phi")->Clone("h2"); + + if (debug) cout << " h2 found..." << endl; + + + //TH1* h2 = (TH1*)gROOT->Get("h2"); + //if( h2 ) delete h2; + //if ( !(j%3) ) h2 = (TH1*)file1->Get(hnames[j/3]+"_pt")->Clone("h2"); + //else if (!((j-1)%3)) h2 = (TH1*)file1->Get(hnames[(j-1)/3]+"_eta")->Clone("h2"); + //else if (!((j-2)%3)) h2 = (TH1*)file1->Get(hnames[(j-2)/3]+"_phi")->Clone("h2"); + + //if (debug) cout << " h2 found..." << endl; + + TH1* h3 = 0; + if (file2) { + + h3 = (TH1*)gROOT->Get("h3"); + if( h3 ) delete h3; + if ( !(j%3) ) h3 = (TH1*)file2->Get(hnames[j/3]+"_pt")->Clone("h3"); + else if (!((j-1)%3)) h3 = (TH1*)file2->Get(hnames[(j-1)/3]+"_eta")->Clone("h3"); + else if (!((j-2)%3)) h3 = (TH1*)file2->Get(hnames[(j-2)/3]+"_phi")->Clone("h3"); + + } + + if( h1 ){ + h1->SetLineColor(1); + h1->Draw(); + } + else cout << "No h1 found \n"; + + if( h2 ){ + h2->SetLineColor(2); + h2->Draw("lsame"); + } + else cout << "No h2 found \n"; + + if ( h3 ) { + h3->SetLineColor(3); + h3->Draw("lsame"); + } + else cout << "No h3 found \n"; + + if (debug) cout << " Both h1 and h2 not empty..." << endl; + + if ( j==0 ) c2->Print(TString(saveFile)+"("); + else if ( j+1==nHistos ) c2->Print(TString(saveFile)+")"); + else c2->Print(saveFile); + + } +} + + +void TTPValBackgroundStudy::update(TString name) { + + createEffHistograms(); + + TH1F * histo; + TH2F * histo2; + + TString dirName("cutStudy"); + + if (debug) cout << "Starting Save..." << endl; + TFile f(name, "update"); + if (debug) cout << "File created..." << endl; + f.mkdir(dirName); + f.cd(dirName); + for (unsigned int j = 0; j < nHistos ; ++j ) { + histo = (TH1F*)effHistograms[j]; + if (debug) cout << "Writing histogram " << j << "...." << endl; + bool empty = true; + for (int k = 0; k < histo->GetNbinsX(); ++k) { + if (!( 1 - histo->GetBinContent(k) < 1E-5) && histo->GetBinContent(k) > 1E-5) { + empty = false; + break; //end for loop + } + } + if (!empty) histo->Write(); + if (!empty) histo->Draw(); + } + //f->Write(); + + gStyle->SetHistLineColor(1); + gStyle->SetMarkerStyle(20); + gStyle->SetMarkerColor(1); + + histo2 = (TH2F*)testHisto[0]; + histo2->Write(); + histo2->Draw("BOX"); + histo2->UseCurrentStyle(); + + histo2 = (TH2F*)testHisto[1]; + histo2->Write(); + histo2->Draw("BOX"); + histo2->UseCurrentStyle(); + + + if (debug) cout << "Histograms written..." << endl; + f.Close(); + return; + +} + + + + +void TTPValBackgroundStudy::reset() { + + for ( unsigned int i=0; i<nHistograms; ++i) { + histograms[i]=0; + effHistograms[i]=0; + } + hTot[0] = new TH1F("hptTot","",50,0,120000); + hTot[1] = new TH1F("hphiTot","",64,-3.2,3.2); + hTot[2] = new TH1F("hetaTot","",50,-2.5,2.5); //memory leak + + createHistograms(histograms); + +} + +void TTPValBackgroundStudy::createEffHistograms() { + + + TH1F * effHist=0; + switch ( type ) { + + case 0: + createHistograms(effHistograms); + if ( debug ) cout << "Array for Histograms created..." << endl; + for (unsigned int j = 0; j != nHistos ; ++j ) { + if ( debug ) cout << "Pointer to histograms created" << endl; + if ( debug ) cout << histograms[j]->GetNbinsX() << " bins in histograms found..." << endl; + if (!(j%3)) { + if (debug) cout << "pt-Histogram found... j=" << j << endl; + effHist =getEffHist(hTot[0],histograms[j],"TTPValBackgroundStudy_" + hnames[j/3]+"_pt"); + } + else if (!((j-1)%3)) effHist =getEffHist(hTot[1],histograms[j],"TTPValBackgroundStudy_" + hnames[(j-1)/3]+"_eta"); + else if (!((j-2)%3)) effHist =getEffHist(hTot[2],histograms[j],"TTPValBackgroundStudy_" + hnames[(j-2)/3]+"_phi"); + if ( debug ) cout <<j << " Efficicency Histograms created... " << endl; + effHistograms[j] = effHist; + if ( debug ) cout << effHist->GetNbinsX() << " bins in effHist found..." << endl; + } + if (debug ) cout << "Efficiency Histograms filled." << endl; + + break; + + case 1 : + + createHistograms(effHistograms); + if ( debug ) cout << "Array for Histograms created..." << endl; + for (unsigned int j = 0; j != nHistos ; ++j ) { + if ( debug ) cout << "Pointer to histograms created" << endl; + if ( j==0 ) effHist = getEffHist(hTot[j],histograms[j],"TTPValBackgroundStudy_" + hnames[0]+"_pt"); + if ( j==1 ) effHist = getEffHist(hTot[j],histograms[j],"TTPValBackgroundStudy_" + hnames[0]+"_eta"); + if ( j==2 ) effHist = getEffHist(hTot[j],histograms[j],"TTPValBackgroundStudy_" + hnames[0]+"_phi"); + else { + if (!(j%3)) effHist =getEffHist(histograms[j-3],histograms[j],"TTPValBackgroundStudy_" + hnames[j/3]+"_pt"); + else if (!((j-1)%3)) effHist =getEffHist(histograms[j-3],histograms[j],"TTPValBackgroundStudy_" + hnames[(j-1)/3]+"_eta"); + else if (!((j-2)%3)) effHist =getEffHist(histograms[j-3],histograms[j],"TTPValBackgroundStudy_" + hnames[(j-2)/3]+"_phi"); + } + if ( debug ) cout <<j << " Efficicency Histograms created... " << endl; + effHistograms[j] = effHist; + } + if ( debug ) cout << "Efficiency Histograms filled." << endl; + + break; + + }; +} + + + +TH1F * TTPValBackgroundStudy::getEffHist(TH1F * hTot1, TH1F * hCut1, TString name) +{ + if( hTot1 == 0 || hCut1 == 0 ) cout << "ERROR: Input to getEffHist is bad!!! " << endl; + + TH1F * hEff = (TH1F*)hTot1->Clone(name); + + if ( debug ) cout << "Dividing now...." << endl; + if ( debug ) cout << "Dividing....done!" << endl; + hEff->GetYaxis()->SetTitle("Efficiency"); + hEff->SetMaximum(1.1); + hEff->SetMinimum(0); + if ( debug ) cout << "Configuration of histogram....done" << endl; + hEff->SetTitle(hCut1->GetTitle()); + if ( debug ) cout << "Title set to " << hCut1->GetTitle() << endl; + + unsigned int nbin = hCut1->GetNbinsX(); + if ( debug ) cout << hCut1->GetNbinsX() << " bins found..." << endl; + float eff; float errEff; + for(unsigned int itau = 1 ; itau < nbin ; ++itau) + { + eff = 0; errEff = 0; + if( hTot1->GetBinContent(itau) > 0 ) + { + if (debug ) cout << "Bin content of hCut is " << hCut1->GetBinContent(itau) << endl; + if ( debug ) cout << "Bin content of hTol is " << hTot1->GetBinContent(itau) << endl; + eff = float(hCut1->GetBinContent(itau))/float( hTot1->GetBinContent(itau)); + errEff = sqrt(eff*(1.-eff)/float( hTot1->GetBinContent(itau))); + if ( debug ) cout << "Reuting efficiency is " << eff << endl; + //eff *= 100.; + //errEff *= 100.; + hEff->SetBinContent(itau, eff); + hEff->SetBinError(itau, errEff); + } + } + return hEff; +} + +void TTPValBackgroundStudy::createHistograms(TH1F ** histos) { + TString name; + for (unsigned int count = 0; count!=nNames; count++ ) { + if (debug) cout << " Will create " << nNames << " histograms!" << endl; + + if (debug) cout << "Creating Histogram " << count << endl; + name="TTPValBackgroundStudy_" + hnames[count]+"_pt"; + //if (debug ) cout << " b\n"; + histos[3*count]= new TH1F("TTPValBackgroundStudy_" + name, name, 50, 0, 120000); + if (debug) cout << " At step 2 of " << 3*count << ", variable nNames: " << nNames << endl; + //if (debug) cout << " c\n"; + //if (debug) cout << " d\n"; + histos[3*count]->GetXaxis()->SetTitle("pt"); + //if (debug) cout << " e\n"; + if (debug) cout << " After creating histogram " << 3*count << ", variable nNames: " << nNames << endl; + + name = "TTPValBackgroundStudy_" + hnames[count]+"_phi"; + //cout << " f "<< 3*i+1 << " " << nNames<<"\n"; + histos[3*count+1] = new TH1F("TTPValBackgroundStudy_" + name, name, 64, -3.2, 3.2); + //cout << " g\n"; + //cout << " h\n"; + histos[3*count+1]->GetXaxis()->SetTitle("phi"); + //cout << " i\n"; + if (debug) cout << " After creating histogram " << 3*count+1 << ", variable nNames: " << nNames << endl; + + name = "TTPValBackgroundStudy_" + hnames[count]+"_eta"; + histos[3*count+2] = new TH1F("TTPValBackgroundStudy_" + name, name, 50, -2.5, 2.5); + histos[3*count+2]->GetXaxis()->SetTitle("eta"); + //cout << " j\n"; + if (debug) cout << " After creating histogram " << 3*count+2 << ", variable nNames: " << nNames << endl; + } + + return; + +} + +void TTPValBackgroundStudy::ATLAS_LABEL(Double_t x,Double_t y,Color_t color) { + + TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize); + l.SetNDC(); + l.SetTextFont(72); + l.SetTextColor(color); + l.DrawLatex(x,y,"ATLAS"); +} + +TString TTPValBackgroundStudy::getName(TrigTauMCTauList::OFFLINESELECTION offlineType1) { + + TString value; + + if (offlineType1 == TrigTauMCTauList::TAU1P3P) value = "TAU1P3P"; + if (offlineType1 == TrigTauMCTauList::TAUREC) value = "TAUREC"; + if (offlineType1 == TrigTauMCTauList::EITHERTAU) value = "EITERHTAU"; + if (offlineType1 == TrigTauMCTauList::BOTHTAU) value = "BOTHTAU"; + if (offlineType1 == TrigTauMCTauList::NONE) value = "NONE"; + + return value; +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValCosmicPlots.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValCosmicPlots.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d6a00933d8dd1d1f92e97f7f2a3b33fddd04b778 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValCosmicPlots.cxx @@ -0,0 +1,1032 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// Make standard set of selection plots +#include <iostream> +#include <vector> +#include <math.h> + +#include "TROOT.h" // needed for gROOT +#include "TFile.h" + +#include "TrigTauPerformValidation/TTPValCosmicPlots.h" +#include "TrigTauPerformNtuple/TrigTauEvent.h" +#include "TrigTauPerformAnalysis/TrigTauTrigChainList.h" + +TTPValCosmicPlots::TTPValCosmicPlots(TTPValCosmicPlots::PLOTTYPE type) : hh(0), _plotType(type), + _fix(TrigTauBugFix::TTP14, TrigTauBugFix::RDO), + _minL2EmEt(-1000000.), _maxL2EmEt(1000000.), + _requireAnyL2Negative(false), + _L2NegThreshold(0.), + _requireRecoMask(0), + _requireSeedMask(0), + _thbins(100), _thstart(0), + _nL1E(50), _loL1E(0.), _hiL1E(50.), + _nL2E(65), _loL2E(-15.), _hiL2E(50.), + _nEFE(60), _loEFE(-10.), _hiEFE(50.), + _nEta(61), _loEta(-3.05), _hiEta(3.05) +{ + + // Different numbers of histograms produced depending on plot type + switch (_plotType) { + case TTPValCosmicPlots::DEFAULT: + hh = new TrigTauHistHelper(6); + break; + + case TTPValCosmicPlots::RECO_BASED: + hh = new TrigTauHistHelper(4); + break; + + default: + break; + } + + _currentWeight = 1.; + _defVersion = TrigTauSelectionManager::MENU1400; + _selManager = 0; + _hltAuthorType = TrigTauFlags::ANYAUTHOR; + _nEvent.clear(); + setPhiBins(65, -M_PI-M_PI/64., M_PI+M_PI/64.); +} + +TTPValCosmicPlots::~TTPValCosmicPlots() { + if (_selManager != 0) delete _selManager; + if (hh != 0) delete hh; +} + +void +TTPValCosmicPlots::requireMinL2EmEt(float Et) { + _minL2EmEt = Et; +} + +void +TTPValCosmicPlots::requireMaxL2EmEt(float Et) { + _maxL2EmEt = Et; +} + +void +TTPValCosmicPlots::setL1EtBins(unsigned int nBins, float xLo, float xHi) { + _nL1E = nBins; + _loL1E = xLo; + _hiL1E = xHi; +} + +void +TTPValCosmicPlots::setL2EtBins(unsigned int nBins, float xLo, float xHi) { + _nL2E = nBins; + _loL2E = xLo; + _hiL2E = xHi; +} + +void +TTPValCosmicPlots::setEFEtBins(unsigned int nBins, float xLo, float xHi) { + _nEFE = nBins; + _loEFE = xLo; + _hiEFE = xHi; +} + +void +TTPValCosmicPlots::setEtaBins(unsigned int nBins, float xLo, float xHi) { + _nEta = nBins; + _loEta = xLo; + _hiEta = xHi; +} + +void +TTPValCosmicPlots::setPhiBins(unsigned int nBins, float xLo, float xHi) { + _nPhi = nBins; + _loPhi = xLo; + _hiPhi = xHi; +} + +void +TTPValCosmicPlots::setDefaultVersion( + TrigTauSelectionManager::MENUVERSION version) +{ + _defVersion = version; +} + +void +TTPValCosmicPlots::setSelector(TrigTauFlags::TRIGGERMENU menu) { + if (_selManager == 0) _selManager = new TrigTauSelectionManager(); + _selManager->setMenuVersion(_defVersion); + _selManager->setTauMenu(menu); +} + +// Clear plots and define histograms +void +TTPValCosmicPlots::clear() { + + // Delete all histograms + hh->clear(); + + // Define labels before creating histogram families + _nEvent.clear(); + std::vector<TString> ylabel; + + switch (_plotType) { + case TTPValCosmicPlots::DEFAULT: + ylabel.resize(6); + ylabel[0] = "L1 In"; + ylabel[1] = "L1 Out"; + ylabel[2] = "L2Cal Out"; + ylabel[3] = "L2Trk Out"; + ylabel[4] = "EF Out"; + ylabel[5] = "Offline"; + hh->setYAxisLabels(ylabel); + + for (unsigned int i=0; i<6; i++) _nEvent.name(i, ylabel[i].Data()); + + break; + + case TTPValCosmicPlots::RECO_BASED: + ylabel.resize(4); + ylabel[0] = "Reco"; + ylabel[1] = "L1 Out"; + ylabel[2] = "L2 Out"; + ylabel[3] = "EF Out"; + hh->setYAxisLabels(ylabel); + + for (unsigned int i=0; i<4; i++) _nEvent.name(i, ylabel[i].Data()); + + break; + + } + + // Make sure we are in the main ROOT directory + gROOT->cd(); + + hh->create("hNRoi", 10, 0.0, 10., "ROI/ev"); + + // L1 Plots + hh->create("hL1Et", _nL1E, _loL1E, _hiL1E, "L1 Et (GeV)"); + hh->create("hL1EmEt", _nL1E, _loL1E, _hiL1E, "L1 EM Et (1x2) (GeV)"); + hh->setLogY("hL1EmEt"); + hh->create("hL1HdEt", _nL1E, _loL1E, _hiL1E, "L1 Hd Et (2x2) (GeV)"); + hh->create("hL1EmHd", _nL1E, _loL1E, _hiL1E, _nL1E, _loL1E, _hiL1E, "L1 EM Et (GeV)", "L1 Hd Et"); + + hh->create("hL1EmI", _nL1E, _loL1E, _hiL1E, "L1 EmIso (GeV)"); + hh->create("hL1HdI", _nL1E, _loL1E, _hiL1E, "L1 HdIso (GeV)"); + hh->setLogY("hL1HdI"); + hh->create("hL1EmHdI", _nL1E, _loL1E, _hiL1E, _nL1E, _loL1E, _hiL1E, "L1 EmIso Et (GeV)", "L1 HdIso Et"); + + hh->create("hL1Et44", _nL1E, _loL1E, _hiL1E, "L1 Et (4x4) (GeV)"); + + hh->create("hL1Eta", _nEta, _loEta, _hiEta, "L1Eta"); + hh->create("hL1Phi", _nPhi, _loPhi, _hiPhi, "L1Phi"); + + hh->create("hL1EtaPhi", _nEta, _loEta, _hiEta, _nPhi, _loPhi, _hiPhi, "L1Eta", "L1Phi"); + hh->create("hL1EtaEt", _nEta, _loEta, _hiEta, _nL1E, _loL1E, _hiL1E, "L1Eta", "L1 Et (GeV)"); + hh->create("hL1EtaEmEt", _nEta, _loEta, _hiEta, _nL1E, _loL1E, _hiL1E, "L1Eta", "L1 EM Et (1x2) (GeV)"); + hh->create("hL1EtaHdEt", _nEta, _loEta, _hiEta, _nL1E, _loL1E, _hiL1E, "L1Eta", "L1 Hd Et (2x2) (GeV)"); + + // L2Calo Plots + hh->create("hL2EtCalib", _nL2E, _loL2E, _hiL2E, "L2 EtCalib (GeV)"); + hh->create("hL2EtNarrow", _nL2E, _loL2E, _hiL2E, "L2 Et (Narrow) (GeV)"); + hh->setLogY("hL2EtNarrow"); + hh->create("hL2EtMedium", _nL2E, _loL2E, _hiL2E, "L2 Et (Wide) (GeV)"); + hh->setLogY("hL2EtMedium"); + + hh->create("hL2Em", _nL2E, _loL2E, _hiL2E, "L2 EM Et (Narrow) (GeV)"); + hh->setLogY("hL2Em"); + hh->create("hL2Em0", _nL2E, _loL2E, _hiL2E, "L2 EM0 Et (GeV)"); + hh->setLogY("hL2Em0"); + hh->create("hL2Em1", _nL2E, _loL2E, _hiL2E, "L2 EM1 Et (GeV)"); + hh->setLogY("hL2Em1"); + hh->create("hL2Em2", _nL2E, _loL2E, _hiL2E, "L2 EM2 Et (GeV)"); + hh->setLogY("hL2Em2"); + hh->create("hL2Em3", _nL2E, _loL2E, _hiL2E, "L2 EM3 Et (GeV)"); + hh->setLogY("hL2Em3"); + hh->create("hL2EmR", 51, 0.0, 1.02, "L2 EM/Sum (Narrow)"); + hh->create("hL2Em0R", 51, 0.0, 1.02, "L2 EM0/EM"); + hh->create("hL2Em1R", 51, 0.0, 1.02, "L2 EM1/EM"); + hh->create("hL2Em2R", 51, 0.0, 1.02, "L2 EM2/EM"); + hh->create("hL2Em3R", 51, 0.0, 1.02, "L2 EM3/EM"); + + hh->create("hL2Hd", _nL2E, _loL2E, _hiL2E, "L2 HD Et (Narrow) (GeV)"); + hh->setLogY("hL2Hd"); + hh->create("hL2Hd0", _nL2E, _loL2E, _hiL2E, "L2 HD0 Et (GeV)"); + hh->setLogY("hL2Hd0"); + hh->create("hL2Hd1", _nL2E, _loL2E, _hiL2E, "L2 HD1 Et (GeV)"); + hh->setLogY("hL2Hd1"); + hh->create("hL2Hd2", _nL2E, _loL2E, _hiL2E, "L2 HD2 Et (GeV)"); + hh->setLogY("hL2Hd2"); + hh->create("hL2HdR", 51, 0.0, 1.02, "L2 HD/Sum (Narrow)"); + hh->create("hL2Hd0R", 51, 0.0, 1.02, "L2 HD0/HD"); + hh->create("hL2Hd1R", 51, 0.0, 1.02, "L2 HD1/HD"); + hh->create("hL2Hd2R", 51, 0.0, 1.02, "L2 HD2/HD"); + + hh->create("hL2NStrips", 50, 0.0, 50., "L2 NStrips"); + hh->setLogY("hL2NStrips"); + hh->create("hL2StrWid2", 50, 0.0, 0.5, "L2 StrWid2"); + hh->create("hL2EMRad", 50, -0.5, 0.5, "L2 EM Radius"); + hh->create("hL2IsoFrac", 50, 0.0, 2.0, "L2 IsoFrac"); + + hh->create("hL2L1dEt", 50, -25, 25, "L2 Et - L1 Et"); + hh->create("hL2L1Et", _nL1E, _loL1E, _hiL1E, _nL2E, _loL2E, _hiL2E, "L1 Et", "L2 Et"); + hh->create("hL2L1EmEt", _nL1E, _loL1E, _hiL1E, _nL2E, _loL2E, _hiL2E, "L1 EmEt", "L2 EmEt"); + hh->create("hL2L1HdEt", _nL1E, _loL1E, _hiL1E, _nL2E, _loL2E, _hiL2E, "L1 HdEt", "L2 HdEt"); + hh->create("hL2WL1Et", _nL1E, _loL1E, _hiL1E, _nL2E, _loL2E, _hiL2E, "L1 Et", "L2 Et (Wide)"); + hh->create("hL2WL2Et", _nL2E, _loL2E, _hiL2E, _nL2E, _loL2E, _hiL2E, "L2 Et (Narrow)", "L2 Et (Wide)"); + hh->create("hL2EmHdEt", _nL2E, _loL2E, _hiL2E, _nL2E, _loL2E, _hiL2E, "L2 EmEt (Narrow)", "L2 HdEt (Narrow)"); + + hh->create("hL2EtaEt", _nEta, _loEta, _hiEta, _nL2E, _loL2E, _hiL2E, "L2Eta", "L2 Et (Narrow)"); + hh->create("hL2EtaEmEt", _nEta, _loEta, _hiEta, _nL2E, _loL2E, _hiL2E, "L2Eta", "L2 EM Et (Narrow)"); + hh->create("hL2EtaHdEt", _nEta, _loEta, _hiEta, _nL2E, _loL2E, _hiL2E, "L2Eta", "L2 HD Et (Narrow)"); + + // L2Trk Plots + hh->create("hL2NTrk", 10, 0, 10, "L2 Tracks"); + hh->setLogY("hL2NTrk"); + hh->create("hL2NIso", 5, 0, 5, "L2 Iso Tr"); + hh->setLogY("hL2NIso"); + hh->create("hL2NSlow", 10, 0, 10, "L2 Slow Tracks"); + hh->setLogY("hL2NSlow"); + hh->create("hL2PtLead", 50, 0.0, 100., "L2 PtLead (GeV)"); + hh->setLogY("hL2PtLead"); + hh->create("hL2Charge", 7, -3.5, 3.5, "L2 Charge"); + hh->create("hL2IsoR", 20, 0., 1., "L2 Pt Iso/Core"); + hh->setLogY("hL2IsoR"); + hh->create("hL2EtTrkEM", 50, 0.0, 100., "L2 Et Trk+EM (GeV)"); + hh->create("hL2Eta", _nEta, _loEta, _hiEta, "L2Eta"); + hh->create("hL2Phi", _nPhi, _loPhi, _hiPhi, "L2Phi"); + + hh->create("hL2EtaPhi", _nEta, _loEta, _hiEta, _nPhi, _loPhi, _hiPhi, "L2Eta", "L2Phi"); + + hh->create("hL2L1dEta", 50, -0.25, 0.25, "L2-L1 dEta"); + hh->create("hL2L1dPhi", 50, -0.25, 0.25, "L2-L1 dPhi"); + hh->create("hL2L1dEtadPhi", 50, -0.25, 0.25, 50, -0.25, 0.25, "L2-L1 dEta", "dPhi"); + hh->create("hL2L1EtadEta", _nEta, _loEta, _hiEta, 50, -0.25, 0.25, "L2 Eta", "L2-L1 dEta"); + hh->create("hL2L1PhidPhi", _nPhi, _loPhi, _hiPhi, 50, -0.25, 0.25, "L2 Phi", "L2-L1 dPhi"); + + hh->create("hL2L1Eta", _nEta, _loEta, _hiEta, _nEta, _loEta, _hiEta, "L1Eta", "L2Eta"); + hh->create("hL2L1Phi", _nPhi, _loPhi, _hiPhi, _nPhi, _loPhi, _hiPhi, "L1Phi", "L2Phi"); + hh->create("hL2L1CalEta", _nEta, _loEta, _hiEta, _nEta, _loEta, _hiEta, "L1Eta", "L2CaloEta"); + hh->create("hL2L1CalPhi", _nPhi, _loPhi, _hiPhi, _nPhi, _loPhi, _hiPhi, "L1Phi", "L2CaloPhi"); + + // EF Plots + hh->create("hEFNTrk", 10, 0, 10, "EF Tracks"); + hh->setLogY("hEFNTrk"); + hh->create("hEFCharge", 7,-3.5, 3.5, "EF Charge"); + hh->create("hEFPtLead", 50, 0, 100., "EF PtLead (GeV)"); + hh->create("hEFEMRad", 50, -0.5, 0.5, "EF EMRad"); + hh->create("hEFIsoFrac", 100, 0, 2.0, "EF IsoFrac"); + hh->setLogY("hEFIsoFrac"); + hh->create("hEFEt", _nEFE, _loEFE, _hiEFE, "EF Et (GeV)"); + hh->create("hEFMass", 50, 0, 10., "EF Mass (GeV)"); + hh->create("hEFEta", _nEta, _loEta, _hiEta, "EFEta"); + hh->create("hEFPhi", _nPhi, _loPhi, _hiPhi, "EFPhi"); + hh->create("hEFEtaPhi", _nEta, _loEta, _hiEta, _nPhi, _loPhi, _hiPhi, "EFEta", "EFPhi"); + + hh->create("hEFL2dEta", 50, -0.25, 0.25, "EF-L2 dEta"); + hh->create("hEFL2dPhi", 50, -0.25, 0.25, "EF-L2 dPhi"); + hh->create("hEFL1dEtadPhi", 50, -0.25, 0.25, 50, -0.25, 0.25, "EF-L1 dEta", "dPhi"); + hh->create("hEFL2dEtadPhi", 50, -0.25, 0.25, 50, -0.25, 0.25, "EF-L2 dEta", "dPhi"); + hh->create("hEFL1Eta", _nEta, _loEta, _hiEta, _nEta, _loEta, _hiEta, "L1Eta", "EFEta"); + hh->create("hEFL1Phi", _nPhi, _loPhi, _hiPhi, _nPhi, _loPhi, _hiPhi, "L1Phi", "EFPhi"); + hh->create("hEFL2EtadEta", _nEta, _loEta, _hiEta, 50, -0.25, 0.25, "EF Eta", "EF-L2 dEta"); + hh->create("hEFL2PhidPhi", _nPhi, _loPhi, _hiPhi, 50, -0.25, 0.25, "EF Phi", "EF-L2 dPhi"); + + hh->create("hEFL2dEt", 50, -25, 25, "EF Et - L2 Et"); + hh->create("hEFL2Et", _nL2E, _loL2E, _hiL2E, _nEFE, _loEFE, _hiEFE, "L2 Et", "EF Et"); + + hh->create("hEFEtaEt", _nEta, _loEta, _hiEta, _nEFE, _loEFE, _hiEFE, "EF Eta", "EF Et"); + + + // Reco plots + hh->create("hReSeed", 4, 0, 4, "Seed Type"); + hh->setLogY("hReSeed"); + hh->create("hReLike", 50, 0., 20., "Reco Likelihood"); + hh->setLogY("hReLike"); + hh->create("hReDNN", 50, 0, 1., "Reco NN"); + hh->setLogY("hReDNN"); + hh->create("hReBits", 16, 0, 16, "Reco selectors"); + hh->setLogY("hReBits"); + + hh->create("hReEt", _nEFE, _loEFE, _hiEFE, "Reco Et (GeV)"); + + hh->create("hReEMC", _nEFE, _loEFE, _hiEFE, "Reco Et EM Calib"); + hh->create("hReHdC", _nEFE, _loEFE, _hiEFE, "Reco Et Hd Calib"); + hh->create("hReEMHdC", _nEFE, _loEFE, _hiEFE, _nEFE, _loEFE, _hiEFE, "Reco Et EM", "Reco Et Hd"); + hh->create("hReERatio", 50, -0.5, 2.0, "Reco EM Ratio"); + hh->create("hReEMCell", _nEFE, _loEFE, _hiEFE, "Reco Et EM Cell"); + hh->create("hReHdCell", _nEFE, _loEFE, _hiEFE, "Reco Et Hd Cell"); + + hh->create("hReEMR", 20, -0.5, 1.5, "Reco EM Radius"); + hh->create("hReHdR", 20, -0.5, 1.5, "Reco Had Radius"); + hh->create("hReIso", 50, -0.5, 2.0, "Reco IsoFrac"); + hh->create("hReCent", 25, -0.5, 2.0, "Reco CentFrac"); + hh->create("hReWidth", 20, -0.5, 1.5, "Reco StripWidth"); + + + hh->create("hReNTrk", 10, 0, 10, "Reco Tracks"); + hh->create("hReCharge", 7, -3.5, 3.5, "Reco Charge"); + hh->create("hRePtLead", 100, 0, 100., "Reco PtLead (GeV)"); + hh->create("hReLPtLead", 100, 0, 5., "Reco log(PtLead) (GeV)"); + hh->create("hReMass", 50, 0, 10., "Reco Mass (GeV)"); + hh->create("hReRWid", 50, 0, 0.5, "Reco RWidth2"); + + // Tracking plots + hh->create("hReNPix", 16, 0, 16, "Reco Pix Hits"); + hh->create("hReNSCT", 25, 0, 25, "Reco SCT Hits"); + hh->create("hReNSi", 40, 0, 40, "Reco Pix+SCT Hits"); + hh->create("hReBlay", 10, 0, 10, "Reco Blay Hits"); + hh->create("hReNTRT", 50, 0, 50, "Reco TRT Hits"); + hh->create("hReTRTR", 20, 0., 1., "Reco TRT/Straw Hits"); + hh->create("hReChi2", 50, 0., 5., "Reco Chi2"); + hh->create("hReA0", 30, 0., 600., "Reco A0"); + hh->create("hReA0sig", 50, 0., 1000., "Reco A0/dA0"); + hh->create("hReZ0", 25, -1000., 1000., "Reco Z0"); + hh->create("hReZ0A0", 25, -1000., 1000., 30, 0., 600., "Reco Z0", "Reco A0"); + + hh->create("hReEta", _nEta, _loEta, _hiEta, "ReEta"); + hh->create("hRePhi", _nPhi, _loPhi, _hiPhi, "RePhi"); + hh->create("hRePhi2", 12, -M_PI, M_PI, "RePhi"); + hh->create("hReEtaPhi", _nEta, _loEta, _hiEta, _nPhi, _loPhi, _hiPhi, "ReEta", "RePhi"); + hh->create("hReEtaEt", _nEta, _loEta, _hiEta, _nEFE, _loEFE, _hiEFE, "ReEta", "ReEt"); + + hh->create("hReEFdEta", 50, -0.25, 0.25, "Reco-EF dEta"); + hh->create("hReEFdPhi", 50, -0.25, 0.25, "Reco-EF dPhi"); + hh->create("hReL1dEtadPhi", 50, -0.25, 0.25, 50, -0.25, 0.25, "Reco-L1 dEta", "dPhi"); + hh->create("hReL2dEtadPhi", 50, -0.25, 0.25, 50, -0.25, 0.25, "Reco-L2 dEta", "dPhi"); + hh->create("hReEFdEtadPhi", 50, -0.25, 0.25, 50, -0.25, 0.25, "Reco-EF dEta", "dPhi"); + hh->create("hReEFdEt", 50, -25, 25, "Reco Et - EF Et"); + hh->create("hReL1Et", _nL1E, _loL1E, _hiL1E, _nEFE, _loEFE, _hiEFE, "L1 Et", "Reco Et"); + hh->create("hReEFEt", _nEFE, _loEFE, _hiEFE, _nEFE, _loEFE, _hiEFE, "EF Et", "Reco Et"); + + hh->create("hReEFEtadEta", _nEta, _loEta, _hiEta, 50, -0.25, 0.25, "Re Eta", "Re-EF dEta"); + hh->create("hReEFPhidPhi", _nPhi, _loPhi, _hiPhi, 50, -0.25, 0.25, "Re Phi", "Re-EF dPhi"); + hh->create("hReL1EtadEta", _nEta, _loEta, _hiEta, 50, -0.25, 0.25, "Re Eta", "Re-L1 dEta"); + hh->create("hReL1PhidPhi", _nPhi, _loPhi, _hiPhi, 50, -0.25, 0.25, "Re Phi", "Re-L1 dPhi"); + +} + +// define time history plots +void +TTPValCosmicPlots::defineTH(float tlo, float thi) { + + _thstart = tlo; + + // Make sure we are in the main ROOT directory + gROOT->cd(); + + hh->create("thL1Et", _thbins, 0., thi-tlo, _nL1E, _loL1E, _hiL1E, "Timestamp (h)", "L1 Et (GeV)"); + hh->create("thL2EtCalib", _thbins, 0., thi-tlo, _nL2E, _loL2E, _hiL2E, "Timestamp (h)", "L2 EtCalib (GeV)"); + hh->create("thL2EtNarrow", _thbins, 0., thi-tlo, _nL2E, _loL2E, _hiL2E, "Timestamp (h)", "L2 Et (Narrow) (GeV)"); + hh->create("thL2NTrk", _thbins, 0., thi-tlo, 10, 0, 10, "Timestamp (h)", "L2 Tracks"); + hh->create("thEFEt", _thbins, 0., thi-tlo, _nEFE, _loEFE, _hiEFE, "Timestamp (h)", "EF Et (GeV)"); + hh->create("thEFNTrk", _thbins, 0., thi-tlo, 10, 0, 10, "Timestamp (h)", "EF Tracks"); + + hh->create("thL1Eta", _thbins, 0.0, thi-tlo, _nEta, _loEta, _hiEta, "Timestamp (h)", "L1 Eta"); + hh->create("thL2Eta", _thbins, 0.0, thi-tlo, _nEta, _loEta, _hiEta, "Timestamp (h)", "L2 Eta"); + hh->create("thEFEta", _thbins, 0.0, thi-tlo, _nEta, _loEta, _hiEta, "Timestamp (h)", "EF Eta"); +} + +// Zero all histograms +void +TTPValCosmicPlots::reset() { + hh->reset(); + _nEvent.reset(); +} + +// More user friendly way to process file +void +TTPValCosmicPlots::fill(const TString& filename, double wt) { + + // Open file + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + std::cerr << "Can't open file " << filename << std::endl; + return; + } + + // Initialize tree + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + std::cerr << "Can't find eventTree in " << filename << std::endl; + return; + } + + // _fix.setTTPVersion(filename); + + setCurrentWeight(wt); + fill(tree); + + delete tree; + delete file; +} + +// Process file +void +TTPValCosmicPlots::fill(TTree* tree) { + + if (tree == 0) { + std::cerr << "TTPValCosmicPlots::fill - TTree is NULL!" << std::endl; + return; + } + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + tree->SetBranchStatus("mcEvent*", 0); + + int nev = int(tree->GetEntries()); + + // Must do time history plots here (to get time range correct) + float tlo=0.; + float thi=0.; + + event->reset(); + tree->GetEvent(0); + tlo = floor(event->time_stamp/3600.); + + if (nev > 0) { + event->reset(); + tree->GetEvent(nev-1); + thi = ceil(event->time_stamp/3600.); + + defineTH(tlo, thi); + } + + // cout << "Time history lo: " << tlo << " hi: " << thi << endl; + + switch (_plotType) { + case TTPValCosmicPlots::DEFAULT: + fillDefault(tree, event); + break; + + case TTPValCosmicPlots::RECO_BASED: + fillReco(tree, event); + break; + } + + delete event; +} + +void +TTPValCosmicPlots::fillDefault(TTree* tree, TrigTauEvent* event) { + + int nev = int(tree->GetEntries()); + + // Loop over all events + for(int iev = 0; iev<nev; ++iev) { + + event->reset(); + tree->GetEvent(iev); + + // Bugfix + _fix.fix(event); + + // Analyze this event + TrigTauTrigChainList chainList; + chainList.setRoiWordMatching(); + chainList.setHLTAuthor(_hltAuthorType); + chainList.fillChainList(event); + chainList.fillTriggerList(*_selManager); + + long itype; + + unsigned int numCh = chainList.nTrigChains(); + unsigned int numL1 = chainList.nPassL1Chains(); + unsigned int numL2Cal = chainList.nPassL2CalChains(); + unsigned int numL2Trk = chainList.nPassL2Chains(); + unsigned int numEF = chainList.nPassEFChains(); + + // L1 input + itype = 0; + _nEvent.fill(itype, _currentWeight); + hh->fill("hNRoi", itype, numCh, _currentWeight); + if (numCh == 0) continue; + for (unsigned int i=0; i<numCh; i++) { + TrigTauTrigChain ch = chainList.trigChainEntry(i); + fillRoiHist(event, ch, itype, _currentWeight); + } + + // L1 output + itype = 1; + hh->fill("hNRoi", itype, numL1, _currentWeight); + if (numL1 == 0) continue; + _nEvent.fill(itype, _currentWeight); + for (unsigned int i=0; i<numL1; i++) { + TrigTauTrigChain ch = chainList.passL1ChainEntry(i); + fillRoiHist(event, ch, itype, _currentWeight); + } + + // L2Cal output + itype = 2; + hh->fill("hNRoi", itype, numL2Cal, _currentWeight); + if (numL2Cal == 0) continue; + + // Extra check for L2 + bool passed = false; + for (unsigned int i=0; i<numL2Cal; i++) { + TrigTauTrigChain ch = chainList.passL2CalChainEntry(i); + if (!passedExtraL2(ch)) continue; + fillRoiHist(event, ch, itype, _currentWeight); + passed = true; + } + + if (!passed) continue; + _nEvent.fill(itype, _currentWeight); + + // L2Trk output + itype = 3; + hh->fill("hNRoi", itype, numL2Trk, _currentWeight); + if (numL2Trk == 0) continue; + _nEvent.fill(itype, _currentWeight); + for (unsigned int i=0; i<numL2Trk; i++) { + TrigTauTrigChain ch = chainList.passL2ChainEntry(i); + if (!passedExtraL2(ch)) continue; + fillRoiHist(event, ch, itype, _currentWeight); + } + + // EF output + itype = 4; + hh->fill("hNRoi", itype, numEF, _currentWeight); + + unsigned int numReco = 0; + if (numEF == 0) continue; + _nEvent.fill(itype, _currentWeight); + for (unsigned int i=0; i<numEF; i++) { + TrigTauTrigChain ch = chainList.passEFChainEntry(i); + if (!passedExtraL2(ch)) continue; + fillRoiHist(event, ch, 4, _currentWeight); + + // Also add on tauRec selected + const TrigTauRecOfflineObject* tauRec = ch.tauRec; + if (tauRec == 0) continue; + // if (tauRec->m_discriCut < 0.5) continue; + numReco++; + fillRoiHist(event, ch, 5, _currentWeight); + } + hh->fill("hNRoi", 5, numReco, _currentWeight); + + if (numReco > 0) _nEvent.fill(5, _currentWeight); + } + +} + +void +TTPValCosmicPlots::fillReco(TTree* tree, TrigTauEvent* event) { + + int nev = int(tree->GetEntries()); + std::cout << " Found " << nev << " events " << std::endl; + + long nRead = 0; + + // Loop over all events + for(int iev = 0; iev<nev; ++iev) { + + nRead++; + + event->reset(); + tree->GetEvent(iev); + + // Bugfix + _fix.fix(event); + + // Analyze this event + TrigTauTrigChainList chainList; + chainList.setMaxL1dR(0.3); + chainList.setMaxL2dR(0.3); + chainList.setMaxEFdR(0.3); + chainList.setRoiWordMatching(); + chainList.setHLTAuthor(_hltAuthorType); + chainList.fillChainList(event); + chainList.fillTriggerList(*_selManager); + + long itype; + + unsigned int numReco = 0; + unsigned int numL1 = 0; + unsigned int numL2 = 0; + unsigned int numEF = 0; + + // Offline Reco + for (unsigned int i=0; i<event->nTauRec(); i++) { + const TrigTauRecOfflineObject tau = event->tauRecEntry(i); + + // Apply the reconstruction mask + if ((_requireRecoMask != 0) && !(tau.m_accept & _requireRecoMask)) continue; + + // Apply the seed mask + if ((_requireSeedMask != 0) && !(tau.m_seedType & _requireSeedMask)) continue; + + // Must do some gymnastics here to get a chain built properly + // for every offline reco tau found. + + // Try to match chain at EF, then L2, then L1. Attach reco to + // the end of the chain and plot this. + TrigTauTrigChain ch; + const TrigTauTrigChain* trigChain; + + trigChain = chainList.getEFChain(tau); + if (trigChain == 0) trigChain = chainList.getL2Chain(tau); + if (trigChain == 0) trigChain = chainList.getL1Chain(tau); + + // Now we have some chain (empty if no trigger matches) add the reco to the end + if (trigChain != 0) ch = *trigChain; + ch.tauRec = τ + + // Reco + itype = 0; + _nEvent.fill(itype, _currentWeight); + numReco++; + fillRoiHist(event, ch, itype, _currentWeight); + + // L1 output + if (ch.L1 == 0) continue; + numL1++; + itype = 1; + _nEvent.fill(itype, _currentWeight); + fillRoiHist(event, ch, itype, _currentWeight); + + // L2 output + if (ch.L2 == 0) continue; + numL2++; + itype = 2; + _nEvent.fill(itype, _currentWeight); + fillRoiHist(event, ch, itype, _currentWeight); + + // EF output + if (ch.EF == 0) continue; + numEF++; + itype = 3; + _nEvent.fill(itype, _currentWeight); + fillRoiHist(event, ch, itype, _currentWeight); + + } + + hh->fill("hNRoi", 0, numReco, _currentWeight); + hh->fill("hNRoi", 1, numL1, _currentWeight); + hh->fill("hNRoi", 2, numL2, _currentWeight); + hh->fill("hNRoi", 3, numEF, _currentWeight); + } + + std::cout << " Read " << nRead << " events " << std::endl; +} + +bool +TTPValCosmicPlots::passedExtraL2(const TrigTauTrigChain& ch) { + const TrigTauL2Object* L2 = ch.L2; + if (L2 == 0) return false; + + float emEt0 = L2->m_EMEnergyNarrow[0]/TMath::CosH(L2->m_caloEta); + float emEt1 = L2->m_EMEnergyNarrow[1]/TMath::CosH(L2->m_caloEta); + float emEt2 = L2->m_EMEnergyNarrow[2]/TMath::CosH(L2->m_caloEta); + float emEt3 = L2->m_EMEnergyNarrow[3]/TMath::CosH(L2->m_caloEta); + float emEtSum = emEt0+emEt1+emEt2+emEt3; + + if (emEtSum < _minL2EmEt) return false; + if (emEtSum > _maxL2EmEt) return false; + + if (_requireAnyL2Negative) { + for (unsigned int i=0; i<TrigTauL2Object::NEMSAMPLES; i++) + if (L2->m_EMEnergyMedium[i] < _L2NegThreshold) return true; + for (unsigned int i=0; i<TrigTauL2Object::NHADSAMPLES; i++) + if (L2->m_HadEnergyMedium[i] < _L2NegThreshold) return true; + return false; + } + + return true; +} + +void +TTPValCosmicPlots::fillRoiHist(const TrigTauEvent* ev, + const TrigTauTrigChain& ch, + unsigned int type, + double wt) { + + const TrigTauL1Object* L1 = ch.L1; + + if (L1 != 0) { + + hh->fill("hL1Et", type, L1->m_TauEnergy/1000., wt); + hh->fill("hL1EmEt", type, L1->m_EmEnergy/1000., wt); + hh->fill("hL1HdEt", type, L1->m_HdCore/1000., wt); + hh->fill("hL1EmI", type, L1->m_EmIsol/1000., wt); + hh->fill("hL1HdI", type, L1->m_HdIsol/1000., wt); + hh->fill("hL1Et44", type, L1->Et()/1000., wt); + + hh->fill("hL1EmHd", type, L1->m_EmEnergy/1000., L1->m_HdCore/1000., wt); + hh->fill("hL1EmHdI", type, L1->m_EmIsol/1000., L1->m_HdIsol/1000., wt); + + hh->fill("hL1Eta", type, L1->Eta(), wt); + hh->fill("hL1Phi", type, L1->Phi(), wt); + hh->fill("hL1EtaPhi", type, L1->Eta(), L1->Phi(), wt); + + hh->fill("hL1EtaEt", type, L1->Eta(), L1->m_TauEnergy/1000., wt); + hh->fill("hL1EtaEmEt", type, L1->Eta(), L1->m_EmEnergy/1000., wt); + hh->fill("hL1EtaHdEt", type, L1->Eta(), L1->m_HdCore/1000., wt); + + // Time histories + hh->fill("thL1Et", type, ev->time_stamp/3600.-_thstart, L1->m_TauEnergy/1000., wt); + hh->fill("thL1Eta", type, ev->time_stamp/3600.-_thstart, L1->Eta(), wt); + } + + const TrigTauL2Object* L2 = ch.L2; + if (L2 != 0) { + + hh->fill("hL2EtCalib", type, L2->etClusCalib()/1000., wt); + hh->fill("hL2EtNarrow", type, L2->etNarrow()/1000., wt); + + float emEt0 = L2->m_EMEnergyNarrow[0]/1000./TMath::CosH(L2->m_caloEta); + float emEt1 = L2->m_EMEnergyNarrow[1]/1000./TMath::CosH(L2->m_caloEta); + float emEt2 = L2->m_EMEnergyNarrow[2]/1000./TMath::CosH(L2->m_caloEta); + float emEt3 = L2->m_EMEnergyNarrow[3]/1000./TMath::CosH(L2->m_caloEta); + float emEtSum = emEt0+emEt1+emEt2+emEt3; + + hh->fill("hL2Em", type, emEtSum, wt); + hh->fill("hL2EmR", type, (L2->etNarrow() > 0 ? 1000.*emEtSum/L2->etNarrow() : 0), wt); + hh->fill("hL2Em0", type, emEt0, wt); + hh->fill("hL2Em1", type, emEt1, wt); + hh->fill("hL2Em2", type, emEt2, wt); + hh->fill("hL2Em3", type, emEt3, wt); + if (emEtSum>0) { + hh->fill("hL2Em0R", type, emEt0/emEtSum, wt); + hh->fill("hL2Em1R", type, emEt1/emEtSum, wt); + hh->fill("hL2Em2R", type, emEt2/emEtSum, wt); + hh->fill("hL2Em3R", type, emEt3/emEtSum, wt); + } + + float hdEt0 = L2->m_HadEnergyNarrow[0]/1000./TMath::CosH(L2->m_caloEta); + float hdEt1 = L2->m_HadEnergyNarrow[1]/1000./TMath::CosH(L2->m_caloEta); + float hdEt2 = L2->m_HadEnergyNarrow[2]/1000./TMath::CosH(L2->m_caloEta); + float hdEtSum = hdEt0+hdEt1+hdEt2; + + hh->fill("hL2Hd", type, hdEtSum, wt); + hh->fill("hL2HdR", type, (L2->etNarrow() > 0 ? 1000*hdEtSum/L2->etNarrow() : 0), wt); + hh->fill("hL2Hd0", type, hdEt0, wt); + hh->fill("hL2Hd1", type, hdEt1, wt); + hh->fill("hL2Hd2", type, hdEt2, wt); + if (hdEtSum>0) { + hh->fill("hL2Hd0R", type, hdEt0/hdEtSum, wt); + hh->fill("hL2Hd1R", type, hdEt1/hdEtSum, wt); + hh->fill("hL2Hd2R", type, hdEt2/hdEtSum, wt); + } + + hh->fill("hL2NStrips", type, L2->m_nStrips, wt); + hh->fill("hL2StrWid2", type, L2->m_stripWidth2, wt); + hh->fill("hL2EMRad", type, L2->m_EMRadius, wt); + hh->fill("hL2IsoFrac", type, L2->m_isoFrac, wt); + + + // L2 track information now in L2 object correctly + hh->fill("hL2NTrk", type, L2->m_nCoreTracks, wt); + hh->fill("hL2NIso", type, L2->m_nIsoTracks, wt); + hh->fill("hL2NSlow", type, L2->m_nSlowTracks, wt); + hh->fill("hL2PtLead", type, L2->m_leadingTrackPt/1000., wt); + if (L2->m_scalarPtSumCore > 0) { + hh->fill("hL2IsoR", type, L2->m_scalarPtSumIso/L2->m_scalarPtSumCore, wt); + } else { + hh->fill("hL2IsoR", type, 99., wt); + } + + hh->fill("hL2Charge", type, L2->m_charge, wt); + + float emEt = L2->m_EMEnergyWide[0]+L2->m_EMEnergyWide[1]+L2->m_EMEnergyWide[2]; + emEt /= TMath::CosH(L2->m_caloEta); + + TLorentzVector trkEMSum; + trkEMSum.SetPtEtaPhiM(emEt, L2->m_caloEta, L2->m_caloPhi, 0.); + trkEMSum += L2->m_3fastest; + hh->fill("hL2EtTrkEM", type, trkEMSum.Et()/1000., wt); + + hh->fill("hL2Eta", type, L2->Eta(), wt); + hh->fill("hL2Phi", type, L2->Phi(), wt); + hh->fill("hL2EtaPhi", type, L2->Eta(), L2->Phi(), wt); + hh->fill("hL2L1Eta", type, L1->Eta(), L2->Eta(), wt); + hh->fill("hL2L1Phi", type, L1->Phi(), L2->Phi(), wt); + + hh->fill("hL2L1CalEta", type, L1->Eta(), L2->m_caloEta, wt); + hh->fill("hL2L1CalPhi", type, L1->Phi(), L2->m_caloPhi, wt); + + hh->fill("hL2L1dEta", type, L2->Eta()-L1->Eta(), wt); + hh->fill("hL2L1dPhi", type, L2->DeltaPhi(*L1), wt); + hh->fill("hL2L1dEtadPhi", type, L2->Eta()-L1->Eta(), L2->DeltaPhi(*L1), wt); + hh->fill("hL2L1EtadEta", type, L2->Eta(), L2->Eta()-L1->Eta(), wt); + hh->fill("hL2L1PhidPhi", type, L2->Phi(), L2->DeltaPhi(*L1), wt); + + hh->fill("hL2L1dEt", type, L2->etNarrow()/1000. - L1->m_TauEnergy/1000., wt); + hh->fill("hL2L1Et", type, L1->m_TauEnergy/1000., L2->etNarrow()/1000., wt); + hh->fill("hL2L1EmEt", type, L1->m_EmEnergy/1000., emEtSum, wt); + hh->fill("hL2L1HdEt", type, L1->m_HdCore/1000., hdEtSum, wt); + + hh->fill("hL2EtaEt", type, L2->Eta(), L2->etNarrow()/1000., wt); + hh->fill("hL2EtaEmEt", type, L2->Eta(), emEtSum, wt); + hh->fill("hL2EtaHdEt", type, L2->Eta(), hdEtSum, wt); + + + float etMedium = 0.; + for (unsigned int i=0; i<TrigTauL2Object::NEMSAMPLES; i++) + etMedium += L2->m_EMEnergyMedium[i]; + for (unsigned int i=0; i<TrigTauL2Object::NHADSAMPLES; i++) + etMedium += L2->m_HadEnergyMedium[i]; + etMedium /= cosh(L2->m_caloEta); + + hh->fill("hL2WL1Et", type, L1->m_TauEnergy/1000., etMedium/1000., wt); + hh->fill("hL2WL2Et", type, L2->etNarrow()/1000., etMedium/1000., wt); + hh->fill("hL2EmHdEt", type, emEtSum, hdEtSum, wt); + + hh->fill("hL2EtMedium", type, etMedium/1000., wt); + + // Check for weirdness + // float dphi = fabs(L2->DeltaPhi(*L1)); + // if (dphi > 0.25 && dphi < 2.85) { + // cout << ">>>" << ev->runNumber << " " << ev->eventNumber << " has dPhi(L2-L1) " << dphi << " and L2 phi " << L2->Phi() << endl; + // } + + // Time histories + hh->fill("thL2EtCalib", type, ev->time_stamp/3600.-_thstart, L2->etClusCalib()/1000., wt); + hh->fill("thL2EtNarrow", type, ev->time_stamp/3600.-_thstart, L2->etNarrow()/1000., wt); + hh->fill("thL2NTrk", type, ev->time_stamp/3600.-_thstart, L2->m_nCoreTracks, wt); + hh->fill("thL2Eta", type, ev->time_stamp/3600.-_thstart, L2->Eta(), wt); + } + + const TrigTauRecObject* EF = ch.EF; + if (EF != 0) { + + hh->fill("hEFNTrk", type, EF->nTracks(), wt); + hh->fill("hEFCharge", type, EF->charge(), wt); + if (EF->leadingTrack() != 0) + hh->fill("hEFPtLead", type, EF->leadingTrack()->Pt()/1000., wt); + hh->fill("hEFEMRad", type, EF->m_EMRadius, wt); + hh->fill("hEFIsoFrac", type, EF->m_isoFrac, wt); + hh->fill("hEFEt", type, EF->Et()/1000., wt); + // hh->fill("hEFMass", type, EF->Mass()/1000., wt); + hh->fill("hEFEta", type, EF->Eta(), wt); + hh->fill("hEFPhi", type, EF->Phi(), wt); + hh->fill("hEFEtaPhi", type, EF->Eta(), EF->Phi(), wt); + + hh->fill("hEFL2dEta", type, EF->Eta()-L2->Eta(), wt); + hh->fill("hEFL2dPhi", type, EF->DeltaPhi(*L2), wt); + hh->fill("hEFL2dEtadPhi", type, EF->Eta()-L2->Eta(), EF->DeltaPhi(*L2), wt); + hh->fill("hEFL1dEtadPhi", type, EF->Eta()-L1->Eta(), EF->DeltaPhi(*L1), wt); + + hh->fill("hEFL2EtadEta", type, EF->Eta(), EF->Eta()-L2->Eta(), wt); + hh->fill("hEFL2PhidPhi", type, EF->Phi(), EF->DeltaPhi(*L2), wt); + + hh->fill("hEFL1Eta", type, L1->Eta(), EF->Eta(), wt); + hh->fill("hEFL1Phi", type, L1->Phi(), EF->Phi(), wt); + + hh->fill("hEFL2dEt", type, EF->Et()/1000. - L2->etNarrow()/1000., wt); + hh->fill("hEFL2Et", type, L2->etNarrow()/1000., EF->Et()/1000., wt); + + hh->fill("hEFEtaEt", type, EF->Eta(), EF->Et()/1000., wt); + + // Check for weirdness + // dphi = fabs(EF->DeltaPhi(*L1)); + // if (dphi > 0.25 && dphi < 2.85) { + // cout << ">>>" << ev->runNumber << " " << ev->eventNumber << " has dPhi(EF-L1) " << dphi << " and EF phi " << EF->Phi() << endl; + // } + + // Time histories + hh->fill("thEFNTrk", type, ev->time_stamp/3600.-_thstart, EF->nTracks(), wt); + hh->fill("thEFEt", type, ev->time_stamp/3600.-_thstart, EF->Et()/1000., wt); + hh->fill("thEFEta", type, ev->time_stamp/3600.-_thstart, EF->Eta(), wt); + } + + const TrigTauRecOfflineObject* tauRec = ch.tauRec; + if (tauRec == 0) return; + + hh->fill("hReSeed", type, tauRec->m_seedType, wt); + hh->fill("hReEt", type, tauRec->Et()/1000., wt); + + hh->fill("hReNTrk", type, tauRec->nTracks(), wt); + hh->fill("hReCharge", type, tauRec->charge(), wt); + + const TrigTauTrack* tr = tauRec->leadingTrack(); + if (tr != 0) { + hh->fill("hRePtLead", type, tr->Pt()/1000., wt); + hh->fill("hReLPtLead", type, log10(tr->Pt()/1000.), wt); + + // Leading track parameters + hh->fill("hReNPix", type, tr->m_nPixelHits, wt); + hh->fill("hReNSCT", type, tr->m_nSCTHits, wt); + hh->fill("hReNSi", type, tr->nSiHits(), wt); + hh->fill("hReBlay", type, tr->nBlayer(), wt); + hh->fill("hReNTRT", type, tr->m_nTRTHits, wt); + hh->fill("hReTRTR", type, tr->nTRHItsRatio(), wt); + + hh->fill("hReChi2", type, tr->m_chi2, wt); + hh->fill("hReA0", type, tr->m_a0, wt); + + hh->fill("hReA0sig", type, tr->m_a0/tr->m_a0error, wt); + hh->fill("hReZ0", type, tr->m_z0, wt); + + hh->fill("hReZ0A0", type, tr->m_z0, tr->m_a0, wt); + } + + hh->fill("hReMass", type, tauRec->m_MTrk3P/1000., wt); + hh->fill("hReRWid", type, tauRec->m_RWidth2Trk3P, wt); + + hh->fill("hReLike", type, tauRec->m_discriLL, wt); + hh->fill("hReDNN", type, tauRec->m_discriNN, wt); + + // Fill event bits + hh->fill("hReBits", type, 0, wt); + if (tauRec->isTauCutLoose()) hh->fill("hReBits", type, 1, wt); + if (tauRec->isTauCutMedium()) hh->fill("hReBits", type, 2, wt); + if (tauRec->isTauCutTight()) hh->fill("hReBits", type, 3, wt); + if (tauRec->isTauLlhLoose()) hh->fill("hReBits", type, 4, wt); + if (tauRec->isTauLlhMedium()) hh->fill("hReBits", type, 5, wt); + if (tauRec->isTauLlhTight()) hh->fill("hReBits", type, 6, wt); + if (tauRec->isTauCutSafeLoose()) hh->fill("hReBits", type, 7, wt); + if (tauRec->isTauCutSafeMedium()) hh->fill("hReBits", type, 8, wt); + if (tauRec->isTauCutSafeTight()) hh->fill("hReBits", type, 9, wt); + if (tauRec->isTauCutSafeCaloLoose()) hh->fill("hReBits", type, 10, wt); + if (tauRec->isTauCutSafeCaloMedium()) hh->fill("hReBits", type, 11, wt); + if (tauRec->isTauCutSafeCaloTight()) hh->fill("hReBits", type, 12, wt); + if (tauRec->isElectronVetoLoose()) hh->fill("hReBits", type, 13, wt); + if (tauRec->isElectronVetoMedium()) hh->fill("hReBits", type, 14, wt); + if (tauRec->isElectronVetoTight()) hh->fill("hReBits", type, 15, wt); + + hh->fill("hReEMC", type, tauRec->m_etEMCalib/1000., wt); + hh->fill("hReHdC", type, tauRec->m_etHadCalib/1000., wt); + hh->fill("hReEMHdC", type, tauRec->m_etEMCalib/1000., tauRec->m_etHadCalib/1000., wt); + hh->fill("hReEMCell", type, tauRec->m_sumEmCellEt/1000., wt); + hh->fill("hReHdCell", type, tauRec->m_sumHadCellEt/1000., wt); + + hh->fill("hReEMR", type, tauRec->m_EMRadius, wt); + hh->fill("hReHdR", type, tauRec->m_hadRadius, wt); + hh->fill("hReIso", type, tauRec->m_isoFrac, wt); + hh->fill("hReCent", type, tauRec->m_centralityFraction, wt); + hh->fill("hReWidth", type, tauRec->m_stripWidth2, wt); + hh->fill("hReERatio", type, tauRec->m_etEMCalib/(tauRec->m_etEMCalib+tauRec->m_etHadCalib), wt); + + hh->fill("hReEta", type, tauRec->Eta(), wt); + hh->fill("hRePhi", type, tauRec->Phi(), wt); + hh->fill("hRePhi2", type, tauRec->Phi(), wt); + hh->fill("hReEtaPhi", type, tauRec->Eta(), tauRec->Phi(), wt); + hh->fill("hReEtaEt", type, tauRec->Eta(), tauRec->Et()/1000., wt); + + if (L1 == 0) return; + hh->fill("hReL1dEtadPhi", type, tauRec->Eta()-L1->Eta(), tauRec->DeltaPhi(*L1), wt); + hh->fill("hReL1Et", type, L1->m_TauEnergy/1000., tauRec->Et()/1000., wt); + + hh->fill("hReL1EtadEta", type, tauRec->Eta(), tauRec->Eta()-L1->Eta(), wt); + hh->fill("hReL1PhidPhi", type, tauRec->Phi(), tauRec->DeltaPhi(*L1), wt); + + if (L2 == 0) return; + hh->fill("hReL2dEtadPhi", type, tauRec->Eta()-L2->Eta(), tauRec->DeltaPhi(*L2), wt); + + if (EF == 0) return; + hh->fill("hReEFdEta", type, tauRec->Eta()-EF->Eta(), wt); + hh->fill("hReEFdPhi", type, tauRec->DeltaPhi(*EF), wt); + hh->fill("hReEFdEtadPhi", type, tauRec->Eta()-EF->Eta(), tauRec->DeltaPhi(*EF), wt); + + hh->fill("hReEFdEt", type, tauRec->Et()/1000. - EF->Et()/1000., wt); + hh->fill("hReEFEt", type, EF->Et()/1000., tauRec->Et()/1000., wt); + + hh->fill("hReEFEtadEta", type, tauRec->Eta(), tauRec->Eta()-EF->Eta(), wt); + hh->fill("hReEFPhidPhi", type, tauRec->Phi(), tauRec->DeltaPhi(*EF), wt); + + return; +} + +void +TTPValCosmicPlots::draw(const TString& outfile) { + + TCanvas* c1 = new TCanvas("c1", "", 10, 10, 800, 620); + + switch (_plotType) { + case TTPValCosmicPlots::DEFAULT: + c1->Divide(3, 2); + hh->drawAll(outfile, 6, c1); + break; + + case TTPValCosmicPlots::RECO_BASED: + c1->Divide(2,2); + hh->drawAll(outfile, 4, c1); + break; + + } + delete c1; + + _nEvent.print(); +} + +void +TTPValCosmicPlots::drawEff(const TString& outfile) { + + TCanvas* c2 = new TCanvas("c2", "", 10, 10, 800, 620); + + switch (_plotType) { + case TTPValCosmicPlots::DEFAULT: + c2->Divide(3, 2); + hh->drawEffAll(outfile, 6, 0, c2); + break; + + case TTPValCosmicPlots::RECO_BASED: + c2->Divide(2,2); + hh->drawEffAll(outfile, 4, 0, c2); + break; + + } + + delete c2; + + _nEvent.print(); +} + + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValCutStudy.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValCutStudy.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ffa292553e13be00c59549fa1a5e63286a6197c0 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValCutStudy.cxx @@ -0,0 +1,1009 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +using namespace std; +#include "TrigTauPerformValidation/TTPValCutStudy.h" + + + +TTPValCutStudy::TTPValCutStudy (TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version, poolfile) { + cout << "WARNING: Filename not specified!! " << endl; + initialize(debug1); + fileDefined = false; + return; +} + +TTPValCutStudy::TTPValCutStudy (TString filename1, TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version, poolfile) { + + if (debug1) cout << " Creating validation4 object..." << endl; + filename = filename1; + chain = new TChain("eventTree"); + chain->Add(filename); + initialize(debug1); + fileDefined = true; + return; +} + +void TTPValCutStudy::initialize(bool debug1) { + + + type = 1; + debug = debug1; + signal = true; + nprong = 0; + maxVisEta = 2.5; + minLeadingPt = 6.0; + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + menu = TrigTauFlags::TAU16; + cutLevel = TrigTauSelectionManager::LOOSE; + offlineType = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + menuVersion = TrigTauSelectionManager::MENU1560; + chainType = TrigTauFlags::SITRK; + hTot[0] = new TH1F("TTPValCutStudy_hptTot","",50,0,120); + hTot[1] = new TH1F("TTPValCutStudy_hphiTot","",64,-3.2,3.2); + hTot[2] = new TH1F("TTPValCutStudy_hetaTot","",50,-2.5,2.5); + + testHisto[0] = new TH2F("TTPValCutStudy_EF Calo EtHad", "",64, -3.2, 3.2, 100, 0, 1.5); + testHisto[0]->GetXaxis()->SetTitle("eta"); + testHisto[0]->GetYaxis()->SetTitle("EtHadCalib: EF/Offline"); + + testHisto[1] = new TH2F("TTPValCutStudy_EF Calo EtEM", "",64, -3.2, 3.2, 100, 0, 1.5); + testHisto[1]->GetXaxis()->SetTitle("eta"); + testHisto[1]->GetYaxis()->SetTitle("EtEMCalib: EF/Offline"); + + + //Level 1 + hnames.push_back("L1_TauCluster"); + hnames.push_back("L1_EMIsol"); + hnames.push_back("L1_HDIsol"); + hnames.push_back("L1_EMCore"); + hnames.push_back("L1_HDCore"); + hnames.push_back("L1_EMEnergy"); //TEMPRARILY CHANGED, NEEDS TO BE UNDONE _EMEnergy"); + //Level2 Calo + hnames.push_back("L2Calo_Et"); + hnames.push_back("L2Calo_Et_Calib"); + hnames.push_back("L2Calo_nStrips"); + hnames.push_back("L2Calo_stripWidth"); + hnames.push_back("L2Calo_EMRadius"); + hnames.push_back("L2Calo_IsoFrac"); + hnames.push_back("L2Calo_EMWidth"); + hnames.push_back("L2Calo_Et_Nar"); + //Level2 Track + hnames.push_back("L2Trk_nMinTrk");; + hnames.push_back("L2Trk_nSlow"); + hnames.push_back("L2Trk_nIso"); + hnames.push_back("L2Trk_nMatch"); + hnames.push_back("L2Trk_totCharge"); + hnames.push_back("L2Trk_maxPt"); + hnames.push_back("L2Trk_sumPtRatio"); + hnames.push_back("L2Trk_Et (Trk+EM)"); + //EF + hnames.push_back("EF_min nTrk_EFID"); + hnames.push_back("EF_min nTrk"); + hnames.push_back("EF_max nTrk"); + hnames.push_back("EF_EMRadius"); + hnames.push_back("EF_IsoFrac"); + hnames.push_back("EF_EMFrac"); + hnames.push_back("EF_Pt_max"); + hnames.push_back("EF_Et"); + hnames.push_back("EF_EM_Et"); + hnames.push_back("EF_Mass"); //TEMPRARILY CHANGED, NEEDS TO BE UNDONE _Mass"); + + nL1Cuts = 6; + nL2CaloCuts = 8; + nL2TrkCuts = 8; + nEFCuts = 10; + nHistos = hnames.size()*3; + nNames = hnames.size(); + + + //static const unsigned int nHistosConst = nHistos; + //TH1F * histograms[nHistosConst]; + + if ( nL1Cuts+nL2CaloCuts+nL2TrkCuts+nEFCuts != nNames || nNames*3 != nHistograms ) { + cout << "ERROR: Number of Cuts for different levels incorrect!!!" << endl; + return; + } + + if (debug) cout << "Creating Histograms..." << endl; + createHistograms(histograms); + if (debug) cout << "Histograms created! Building selmanager..." << endl; + +} + + +void TTPValCutStudy::setFile( TString filename1) { + filename = filename1; + chain = new TChain("eventTree"); //potential memory leak + chain->Add(filename); + fileDefined = true; + return; +} + + +void TTPValCutStudy::analyze() { + + if (!fileDefined) { + cout << "File was not defined and variables not initialized!!" << endl; + return; + } + + selmanager.setMenuVersion(menuVersion); + selmanager.setTauMenu(menu, cutLevel ); + + // MC truth + analyzer.truthList.setMaxVisEta(maxVisEta); + analyzer.truthList.setMinVisPt(menu); // in GeV + analyzer.truthList.setMinLeadingPt(minLeadingPt); // pt of the leading pt of track is + if( nprong == 1 ) analyzer.truthList.select1Prong(); + else if( nprong == 3 ) analyzer.truthList.select3Prong(); + analyzer.truthList.setRecoMatchdR(0.2); + + event = new TrigTauEvent(); + chain->SetBranchAddress("EventBranch", &event); + chain->SetBranchStatus("*", 1); + + // Also set an L1 MET cut if desired + analyzer.trigMan.setL1MET(0.); + analyzer.trigMan.setMenuVersion(menuVersion); + analyzer.trigMan.setTauMenu(menu, cutLevel); + analyzer.chainList.setRoiWordMatching(false); + analyzer.chainList.setHLTAuthor(chainType); + + int nev = int(chain->GetEntries()); + //if ( nev > 100 ) nev = 100; + for(int iev = 0; iev<nev; ++iev) { + analyzeEvent( iev ); + } +} + + +void TTPValCutStudy::analyzeEvent(int eventNumber) { + + event->reset(); + chain->GetEvent(eventNumber); + bugfix.fix(event); + + if (debug) cout << "\n Starting new event! " << endl; + + analyzer.analyze(event, signal, offlineType); + + // ============ Select type of events (e.g. signal) ================ + if( signal ) { + // analyzer.truthList.fillPureList(&event->mcEvent); +// analyzer.truthList.fillGoodList(); +// analyzer.truthList.requireRecoMatch(*event, offlineType); + if ( debug && analyzer.truthList.nMCTauGood() ==0 ) cout << "Event contains no good taus! " << endl; + if( analyzer.truthList.nMCTauGood() ==0 ) return; + } + + // loop over taus after fiducial cuts + + if ( debug ) cout << "Event contains " << analyzer.truthList.nMCTauGood() << " good tau!" << endl; + for( unsigned int iTrue = 0; iTrue < analyzer.truthList.nMCTauGood(); ++iTrue ) //loop over all true taus + { + const TrigTauMCTau * truth = & analyzer.truthList.mcTauGoodEntry(iTrue); //select tau + float pt = truth->visible().Pt()/1000; + float eta = truth->visible().Eta(); + float phi = truth->visible().Phi(); + hTot[0]->Fill(pt); hTot[1]->Fill(phi); hTot[2]->Fill(eta); + + unsigned int nTrigChains = analyzer.chainList.nTrigChains() ; + if (debug ) cout << "Value of nTrigChains: " << nTrigChains << endl; + if ( nTrigChains == 0 ) continue; + + unsigned int nl1Word = 0; + //unsigned int nl2CaloWord = 0; + //unsigned int nl2TrkWord = 0; + unsigned int nl2Word = 0; + unsigned int nefWord = 0; + + if ( debug ) cout << " There are " << nTrigChains << " chains to analyze." << endl; + for( unsigned int ichain = 0; ichain < nTrigChains; ++ichain) { + if ( debug ) cout << "Starting chain " << ichain << "!" << endl; + const TrigTauTrigChain *ch = &analyzer.chainList.trigChainEntry(ichain); + const TrigTauL1Object* l1object = ch->L1; + const TrigTauL2Object* l2object = ch->L2; + const TrigTauL2Object* l2calobject = ch->L2Cal; + const TrigTauL2Object* l2trkobject = ch->L2Trk; + const TrigTauRecEFObject* efobject = ch->EF; + const TrigTauRecOfflineObject* offlineobject = ch->tauRec; + + //check Level 1 + if (l1object == 0 ) { + if ( debug ) cout << "L1 Object is empty; go to next chain" << endl; + continue; + } + if( truth->DeltaR(*l1object)<0.2 ) { + if ( debug ) cout << "nL1Word is " << nl1Word << endl; + unsigned int currentWord = selmanager.l1Sel.cutWord(*l1object); + l1Word[nl1Word] = currentWord; + if (debug ) cout << "Found L1 matched chain for number " << nl1Word << " with word :" << l1Word[nl1Word] << endl; + if (debug) cout << "The clusterEnergy at L1 is " << l1object->m_TauEnergy << endl; + if (debug) cout << "From nPassL1Chains: " << analyzer.chainList.nPassL1Chains() << endl; + nl1Word++; + if (currentWord != 0 ) continue; + } + else { + if (debug) cout << "No trigger object matched to truth! " << endl; + continue; + } + if (debug) cout << "Passed L1!!" << endl; + //check Level 2 (including Trk and Cal) + if (l2object == 0 ) { + if ( debug ) cout << "L2 object is empty; go to next chain" << endl; + continue; + } + if ( debug ) cout << " L2 DeltaR is :" << ( truth->DeltaR(*l2object) ) << endl; + if( truth->DeltaR(*l2object)<0.2 ) { + l2CaloWord[nl2Word] = selmanager.l2CalSel.cutWord(*l2calobject); + if (debug) cout << "Et Nar at L2 is " << l2object->etNarrow() << endl; + if ( l2CaloWord[nl2Word] !=0 ) { + l2TrkWord[nl2Word] = 255; + nl2Word++; + continue; + } + l2TrkWord[nl2Word] = selmanager.l2TrkSel.cutWord(*l2trkobject); + if (debug) cout << "Found L2 matched chain with words :" << l2CaloWord[nl2Word] << " and " << l2TrkWord[nl2Word] << endl; + nl2Word++; + if ( (l2CaloWord[nl2Word-1] !=0 ) || (l2TrkWord[nl2Word-1] !=0 ) ) continue; + } + else continue; + + + //check EF + if (efobject == 0 ) { + if ( debug ) cout << "EF object is empty; go to next chain" << endl; + continue; + } + if ( debug ) cout << " EF DeltaR is :" << (truth->DeltaR(*efobject) ) << endl; + if( truth->DeltaR(*efobject)<0.2 ) { + efWord[nefWord] = selmanager.efSel.cutWord(*efobject); + if ( debug ) cout << "Found EF matched chain with word :" << efWord[nefWord] << endl; + nefWord++; + if ( efWord[nefWord-1] == 0 && debug ) cout << "Tau passed trigger!!!" << endl; + if (offlineobject != 0 && offlineobject->m_etHadCalib != 0 ) testHisto[0]->Fill(efobject->Eta(),efobject->m_etHadCalib/offlineobject->m_etHadCalib); + if (offlineobject != 0 && offlineobject->m_etEMCalib != 0 ) testHisto[1]->Fill(efobject->Eta(),efobject->m_etEMCalib/offlineobject->m_etEMCalib); + if (debug) cout << "testHistos filled successfully" << endl; + } + if ( ichain ==0 && debug ) cout << "Word No " << nTrigChains-1 << " is " << l1Word[nTrigChains-1] << endl; + } // end chain loop + + + bool fillHisto[nHistograms]; + for (unsigned int i=0; i!=nNames; ++i) + fillHisto[i] = false; + + for ( unsigned int i =0; i!=nl1Word; ++i) { + if ( debug ) cout << "The L1Word for chain " << i << " is " << l1Word[i] << endl; + for ( unsigned int j=0; j!=nL1Cuts; ++j) { + if ( ((l1Word[i] >> j) & 0x01) ==0 ) fillHisto[j] = true; + else break; + } + } + + + for (unsigned int i =0; i!=nl2Word; ++i) { + //if ( debug ) cout << "The L2Word for chain " << i << " is " << hex << l2Word[i] << endl; + for (unsigned int j=0; j!=nL2CaloCuts; ++j) { + if ( ((l2CaloWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts] = true; + else break; + } + for (unsigned int j=0; j!=nL2TrkCuts; ++j) { + if ( ((l2TrkWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts+nL2CaloCuts] = true; + else break; + } + } + + for ( unsigned int i =0; i!=nefWord; ++i) { + if ( debug ) cout << "The EFWord for chain " << i << " is " << efWord[i] << endl; + for ( unsigned int j=0; j!=nEFCuts; ++j) { + if ( ((efWord[i] >> j) & 0x01) ==0 ) fillHisto[j+nL1Cuts+nL2CaloCuts+nL2TrkCuts] = true; + else break; + } + } + + if ( debug ) { + cout << "TauCluster found - " << fillHisto[0] << endl; + cout << "L1EMIsol found - " << fillHisto[1] << endl; + cout << "L1HDIsol found - " << fillHisto[2] << endl; + } + + if ( debug ) cout << "First Histogram found; check if it will be filled." << endl; + for ( unsigned int j =0; j < nNames; ++j ) { + if ( fillHisto[j] ) { + //if ( debug ) cout << "Filling histogram..." <<endl; + TH1F * h =(TH1F*)histograms[3*j]; + h->Fill(pt); + h = histograms[3*j+1]; + h->Fill(phi); + h = histograms[3*j+2]; + h-> Fill(eta); + } + } + } // end loop over truth + + return; +} + +void TTPValCutStudy::print() { + + print("ntuple.eps"); + +} + + +void TTPValCutStudy::print(TString name) { + + createEffHistograms(); + + TCanvas * c1 = (TCanvas *)gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,500); + + if ( debug ) cout << "Draw Efficiency Histograms..." << endl; + for (unsigned int j = 0; j < nHistos ; ++j ) { + TH1F * histo = (TH1F*)effHistograms[j]; + + if ( debug ) cout << "Draw Histogram No. " << j << endl; + if ( histo != 0 ) histo->Draw(); + if ( debug ) cout << "Printing Histogram No " << j << endl; + + if ( j==0 ) c1->Print(TString(name)+"("); + //else if ( j+1==nHistos ) c1->Print(TString(name)+")"); + else c1->Print(name); + } + + TH2F * histo2 = (TH2F*)testHisto[0]; + if (histo2 !=0 ) histo2->Draw("BOX"); + c1->Print(TString(name)); + + histo2 = 0; + + histo2 = (TH2F*)testHisto[1]; + if (histo2 !=0 ) histo2->Draw("BOX"); + + c1->Print(TString(name)+")"); + + return; +} + +void TTPValCutStudy::save() { + + save("histo.root"); + +} + + +void TTPValCutStudy::save(TString name) { + + createEffHistograms(); + + TH1F * histo; + TH2F * histo2; + + if (debug) cout << "Starting Save..." << endl; + TFile f(name, "recreate"); + if (debug) cout << "File created..." << endl; + for (unsigned int j = 0; j < nHistos ; ++j ) { + histo = (TH1F*)effHistograms[j]; + if (debug) cout << "Writing histogram " << j << "...." << endl; + histo->Write(); + histo->Draw(); + } + //f->Write(); + + histo2 = (TH2F*)testHisto[0]; + histo2->Write(); + histo2->Draw("BOX"); + + histo2 = (TH2F*)testHisto[1]; + histo2->Write(); + histo2->Draw("BOX"); + + if (debug) cout << "Histograms written..." << endl; + f.Close(); + return; + +} + +void TTPValCutStudy::compare(TString reference) { + + compare(reference, "", "ntuple.eps"); + +} + +void TTPValCutStudy::compare(TString reference, TString saveFile) { + + compare(reference, "", saveFile); + +} + + +void TTPValCutStudy::compare(TString reference1, TString reference2, TString saveFile) { + + createEffHistograms(); + + TCanvas * c2 = (TCanvas *)gROOT->Get("c2"); + if( c2 ) delete c2; + c2 = new TCanvas("c1","",10,10,800,500); + + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + + if (debug) cout << "Opening file..." << endl; + + TFile * file1 = new TFile(reference1); + TFile * file2 = 0; + if (reference2[0] != '\0') file2 = new TFile(reference2); + + for (unsigned int j=0; j!= nHistos; ++j) { + + if (debug) cout << "Processing Histogram " << j << endl; + + TH1* h1 = (TH1*)gROOT->Get("h1"); + if( h1 ) delete h1; + if (debug) cout << " Cloning h1...." << endl; + h1 = (TH1*)effHistograms[j]->Clone("h1"); + + if (debug) cout << " h1 found...." << endl; + + if (debug) cout << "Creating TString..." << endl; + TString histoName("TTPValCutStudy_"); //TEMPORARILY CHANGED, NEEDS TO BE CHANGED TO TTPValCutStudy_ + if (debug) cout << "Initial TString created..." << endl; + histoName+=hnames[j/3]; + if (debug) cout <<"TString 1nd part added..." << endl; + if ( !(j%3) ) histoName+="_pt"; + else if (!((j-1)%3)) histoName+="_eta"; //TEMPORARY DISABLED, NEEDS TO BE ENABLED + else if (!((j-2)%3)) histoName+="_phi"; + + TH1* h2 = 0; + //h2 = (TH1*)gROOT->Get("h2"); + //if( h2 ) delete h2; + if (debug) cout << "Accessing histogram: " << histoName << endl; + h2 = (TH1*)file1->Get(histoName)->Clone("h2"); + //if ( !(j%3) ) h2 = (TH1*)file1->Get("TTPValCutStudy_"+hnames[j/3]+"_pt")->Clone("h2"); + //else if (!((j-1)%3)) h2 = (TH1*)file1->Get("TTPValCutStudy_"+hnames[(j-1)/3]+"_eta")->Clone("h2"); + //else if (!((j-2)%3)) h2 = (TH1*)file1->Get("TTPValCutStudy_"+hnames[(j-2)/3]+"_phi")->Clone("h2"); + + if (debug) cout << " h2 found..." << endl; + + + //TH1* h2 = (TH1*)gROOT->Get("h2"); + //if( h2 ) delete h2; + //if ( !(j%3) ) h2 = (TH1*)file1->Get(hnames[j/3]+"_pt")->Clone("h2"); + //else if (!((j-1)%3)) h2 = (TH1*)file1->Get(hnames[(j-1)/3]+"_eta")->Clone("h2"); + //else if (!((j-2)%3)) h2 = (TH1*)file1->Get(hnames[(j-2)/3]+"_phi")->Clone("h2"); + + //if (debug) cout << " h2 found..." << endl; + + TH1* h3 = 0; + if (file2) { + + //h3 = (TH1*)gROOT->Get("h3"); + //if( h3 ) delete h3; + h3 = (TH1*)file2->Get(histoName)->Clone("h3"); + //if ( !(j%3) ) h3 = (TH1*)file2->Get(hnames[j/3]+"_pt")->Clone("h3"); + //else if (!((j-1)%3)) h3 = (TH1*)file2->Get(hnames[(j-1)/3]+"_eta")->Clone("h3"); + //else if (!((j-2)%3)) h3 = (TH1*)file2->Get(hnames[(j-2)/3]+"_phi")->Clone("h3"); + + } + + if( h1 ){ + h1->SetLineColor(1); + h1->Draw(); + } + else cout << "No h1 found \n"; + + if( h2 ){ + h2->SetLineColor(2); + h2->Draw("lsame"); + } + else cout << "No h2 found \n"; + + if ( h3 ) { + h3->SetLineColor(3); + h3->Draw("lsame"); + } + else cout << "No h3 found \n"; + + if (debug) cout << " Both h1 and h2 not empty..." << endl; + + if ( j==0 ) c2->Print(TString(saveFile)+"("); + else if ( j+1==nHistos ) c2->Print(TString(saveFile)+")"); + else c2->Print(saveFile); + + } +} + + +void TTPValCutStudy::update(TString name) { + + createEffHistograms(); + + TH1F * histo; + TH2F * histo2; + + TString dirName("cutStudy"); + + if (debug) cout << "Starting Save..." << endl; + TFile f(name, "update"); + if (debug) cout << "File created..." << endl; + f.mkdir(dirName); + f.cd(dirName); + for (unsigned int j = 0; j < nHistos ; ++j ) { + histo = (TH1F*)effHistograms[j]; + if (debug) cout << "Writing histogram " << j << "...." << endl; + bool empty = true; + for (int k = 0; k < histo->GetNbinsX(); ++k) { + if (!( 1 - histo->GetBinContent(k) < 1E-5) && histo->GetBinContent(k) > 1E-5) { + empty = false; + break; //end for loop + } + } + if (!empty) histo->Write(); + if (!empty) histo->Draw(); + } + //f->Write(); + + gStyle->SetHistLineColor(1); + gStyle->SetMarkerStyle(20); + gStyle->SetMarkerColor(1); + + histo2 = (TH2F*)testHisto[0]; + histo2->Write(); + histo2->Draw("BOX"); + histo2->UseCurrentStyle(); + + histo2 = (TH2F*)testHisto[1]; + histo2->Write(); + histo2->Draw("BOX"); + histo2->UseCurrentStyle(); + + + if (debug) cout << "Histograms written..." << endl; + f.Close(); + return; + +} + + + + +void TTPValCutStudy::reset() { + + for ( unsigned int i=0; i<nHistograms; ++i) { + histograms[i]=0; + effHistograms[i]=0; + } + hTot[0] = new TH1F("hptTot","",50,0,120); + hTot[1] = new TH1F("hphiTot","",64,-3.2,3.2); + hTot[2] = new TH1F("hetaTot","",50,-2.5,2.5); //memory leak + + createHistograms(histograms); + +} + +void TTPValCutStudy::effSequencePlotsUpdate(TString name) { + + TrigTauFlags test; + TString dirName("effSequence_"); + dirName +=getName(offlineType); + dirName +="_"; + dirName +=test.menuName(menu); + type = 0; + createEffHistograms(); + + TH1F * histo; + TH1F * histo2; + TH1F * histo3; + + TH1F * histo_eta; + TH1F * histo2_eta; + TH1F * histo3_eta; + + if (debug) cout << "Starting Save..." << endl; + TFile f(name, "update"); + if (debug) cout << "File created..." << endl; + f.cd(); + f.mkdir(dirName); + f.cd(dirName); + histo = (TH1F*)effHistograms[nL1Cuts*3-3]; + histo2= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts-1)*3]; + histo3= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts + nEFCuts - 1)*3]; + + histo->SetName("TTPValEffSequencePlots_L1 efficiency vs pt"); + histo2->SetName("TTPValEffSequencePlots_L2 efficiency vs pt"); + histo3->SetName("TTPValEffSequencePlots_EF efficiency vs pt"); + + + histo_eta = (TH1F*)effHistograms[nL1Cuts*3-1]; + histo2_eta= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts-1)*3-2]; + histo3_eta= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts + nEFCuts - 1)*3-2]; + + histo_eta->SetName("TTPValEffSequencePlots_L1 efficiency vs eta"); + histo2_eta->SetName("TTPValEffSequencePlots_L2 efficiency vs eta"); + histo3_eta->SetName("TTPValEffSequencePlots_EF efficiency vs eta"); + + if (debug) cout << "Histograms defined." << endl; + + if (debug) cout << "Histo defined:" << histo << endl; + if (debug) cout << "Histo2 defined:" << histo2 << endl; + if (debug) cout << "Histo3 defined:" << histo3 << endl; + + + histo->GetXaxis()->SetTitle("True visible P_{T} (GeV)"); + if (debug) cout << "X-axis labelled." << endl; + histo->GetYaxis()->SetTitle("Efficiency"); + if (debug) cout << "Axis labelled." << endl; + + histo_eta->GetXaxis()->SetTitle("True visible eta (GeV)"); + histo_eta->GetYaxis()->SetTitle("Efficiency"); + + int color[3]; + color[0] = 1;//2; + color[1] = 1;//3; + color[2] = 1;//4; + if (debug) cout << "Color defined." << endl; + + gStyle->SetPadGridY(true); + gStyle->SetPadGridX(true); + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); + if (debug) cout << "Style defined." << endl; + + + TLegend * legend = new TLegend(0.5,0.2,0.7,0.45); + legend->SetFillStyle(0); + TLegend * legend_eta = new TLegend(0.5,0.2,0.7,0.45); + legend_eta->SetFillStyle(0); + + if (debug) cout << "Style set for first histo." << endl; + histo->SetMaximum(1.05); + histo_eta->SetMaximum(1.05); + if (debug) cout << "Maximum Y range set for first histo." << endl; + gStyle->SetHistLineColor(color[0]); + gStyle->SetMarkerStyle(20); + gStyle->SetMarkerColor(color[0]); + histo->UseCurrentStyle(); + histo_eta->UseCurrentStyle(); + legend->AddEntry(histo,"L1","p"); + legend_eta->AddEntry(histo_eta,"L1","p"); + gStyle->SetHistLineColor(color[1]); + gStyle->SetMarkerStyle(26); + gStyle->SetMarkerColor(color[1]); + histo2->UseCurrentStyle(); + legend->AddEntry(histo2,"L2","p"); + histo2_eta->UseCurrentStyle(); + legend_eta->AddEntry(histo2_eta,"L2","p"); + gStyle->SetHistLineColor(color[2]); + gStyle->SetMarkerStyle(22); + gStyle->SetMarkerColor(color[2]); + histo3->UseCurrentStyle(); + legend->AddEntry(histo3,"EF","p"); + histo3_eta->UseCurrentStyle(); + legend_eta->AddEntry(histo3_eta,"EF","p"); + + if (debug) cout << "Legend defined!" << endl; + + histo->Write(); + histo->Draw(); + histo2->Write(); + histo2->Draw("SAME"); + histo3->Write(); + histo3->Draw("SAME"); + legend->Draw("SAME"); + ATLAS_LABEL(0.55,0.55); + + //histo_eta->Write(); + //histo_eta->Draw(); + //histo2_eta->Write(); + //histo2_eta->Draw("SAME"); + //histo3_eta->Write(); + //histo3_eta->Draw("SAME"); + //legend_eta->Draw("SAME"); + //ATLAS_LABEL(0.55,0.55); + + //f->Write(); + + if (debug) cout << "Histograms written..." << endl; + f.Close(); + return; +} + +void TTPValCutStudy::effSequencePlotsPrintCSC(TPostScript & ps) { + + TrigTauFlags test; + TString dirName("effSequence_"); + dirName +=getName(offlineType); + dirName +="_"; + dirName +=test.menuName(menu); + type = 0; + createEffHistograms(); + + + TH1F * histo; + TH1F * histo2; + TH1F * histo3; + + TH1F * histo_eta; + TH1F * histo2_eta; + TH1F * histo3_eta; + + TH1F * histo_phi; + TH1F * histo2_phi; + TH1F * histo3_phi; + + histo = (TH1F*)effHistograms[nL1Cuts*3-3]; + histo2= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts-1)*3]; + histo3= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts + nEFCuts - 1)*3]; + + histo->SetName("TTPValEffSequencePlots_L1 efficiency vs pt"); + histo2->SetName("TTPValEffSequencePlots_L2 efficiency vs pt"); + histo3->SetName("TTPValEffSequencePlots_EF efficiency vs pt"); + + histo_eta = (TH1F*)effHistograms[nL1Cuts*3-1]; + histo2_eta= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts-1)*3-2]; + histo3_eta= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts + nEFCuts - 1)*3-2]; + + histo_eta->SetName("TTPValEffSequencePlots_L1 efficiency vs eta"); + histo2_eta->SetName("TTPValEffSequencePlots_L2 efficiency vs eta"); + histo3_eta->SetName("TTPValEffSequencePlots_EF efficiency vs eta"); + + histo_phi = (TH1F*)effHistograms[nL1Cuts*3-2]; + histo2_phi= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts-1)*3-1]; + histo3_phi= (TH1F*)effHistograms[(nL1Cuts + nL2CaloCuts + nL2TrkCuts + nEFCuts - 1)*3-1]; + + histo_phi->SetName("TTPValEffSequencePlots_L1 efficiency vs phi"); + histo2_phi->SetName("TTPValEffSequencePlots_L2 efficiency vs phi"); + histo3_phi->SetName("TTPValEffSequencePlots_EF efficiency vs phi"); + + histo->GetXaxis()->SetTitle("True visible P_{T} [GeV]"); + histo->GetYaxis()->SetTitle("Efficiency"); + + histo_eta->GetXaxis()->SetTitle("True visible eta [GeV]"); + histo_eta->GetYaxis()->SetTitle("Efficiency"); + + histo_phi->GetXaxis()->SetTitle("True visible phi [GeV]"); + histo_phi->GetYaxis()->SetTitle("Efficiency"); + + int color[3]; + color[0] = 1;//2; + color[1] = 1;//3; + color[2] = 1;//4; + if (debug) cout << "Color defined." << endl; + + gStyle->SetPadGridY(true); + gStyle->SetPadGridX(true); + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); + if (debug) cout << "Style defined." << endl; + + TLegend * legend = new TLegend(0.5,0.2,0.7,0.45); + legend->SetFillStyle(0); + TLegend * legend_eta = new TLegend(0.5,0.2,0.7,0.45); + legend_eta->SetFillStyle(0); + TLegend * legend_phi = new TLegend(0.5,0.2,0.7,0.45); + legend_phi->SetFillStyle(0); + + if (debug) cout << "Style set for first histo." << endl; + histo->SetMaximum(1.05); + histo_eta->SetMaximum(1.05); + histo_phi->SetMaximum(1.05); + if (debug) cout << "Maximum Y range set for first histo." << endl; + gStyle->SetHistLineColor(color[0]); + gStyle->SetMarkerStyle(20); + gStyle->SetMarkerColor(color[0]); + histo->UseCurrentStyle(); + histo_eta->UseCurrentStyle(); + histo_phi->UseCurrentStyle(); + legend->AddEntry(histo,"L1","p"); + legend_eta->AddEntry(histo_eta,"L1","p"); + legend_phi->AddEntry(histo_phi, "L1", "p"); + gStyle->SetHistLineColor(color[1]); + gStyle->SetMarkerStyle(26); + gStyle->SetMarkerColor(color[1]); + histo2->UseCurrentStyle(); + legend->AddEntry(histo2,"L2","p"); + histo2_eta->UseCurrentStyle(); + histo2_phi->UseCurrentStyle(); + legend_eta->AddEntry(histo2_eta,"L2","p"); + legend_phi->AddEntry(histo2_phi, "L2", "p"); + gStyle->SetHistLineColor(color[2]); + gStyle->SetMarkerStyle(22); + gStyle->SetMarkerColor(color[2]); + histo3->UseCurrentStyle(); + legend->AddEntry(histo3,"EF","p"); + histo3_eta->UseCurrentStyle(); + legend_eta->AddEntry(histo3_eta,"EF","p"); + histo3_phi->UseCurrentStyle(); + legend_phi->AddEntry(histo3_phi,"EF","p"); + + if (debug) cout << "Legend defined!" << endl; + + TCanvas * c1 = (TCanvas *)gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,500); + + ps.On(); + + histo->Draw(); + histo2->Draw("SAME"); + histo3->Draw("SAME"); + legend->Draw("SAME"); + ATLAS_LABEL(0.55,0.55); + //c1->Print(TString(filename1)+"("); + c1->Update(); + + histo_eta->Draw(); + histo2_eta->Draw("SAME"); + histo3_eta->Draw("SAME"); + legend_eta->Draw("SAME"); + ATLAS_LABEL(0.55,0.55); + //c1->Print(filename1); + c1->Update(); + + histo_phi->Draw(); + histo2_phi->Draw("SAME"); + histo3_phi->Draw("SAME"); + legend_phi->Draw("SAME"); + ATLAS_LABEL(0.55,0.55); + //c1->Print(filename1); + c1->Update(); + ps.Off(); + return; +} + + +void TTPValCutStudy::createEffHistograms() { + + + TH1F * effHist=0; + switch ( type ) { + + case 0: + createHistograms(effHistograms); + if ( debug ) cout << "Array for Histograms created..." << endl; + for (unsigned int j = 0; j != nHistos ; ++j ) { + if ( debug ) cout << "Pointer to histograms created" << endl; + if ( debug ) cout << histograms[j]->GetNbinsX() << " bins in histograms found..." << endl; + if (!(j%3)) { + if (debug) cout << "pt-Histogram found... j=" << j << endl; + effHist =getEffHist(hTot[0],histograms[j],"TTPValCutStudy_" + hnames[j/3]+"_pt"); + } + else if (!((j-1)%3)) effHist =getEffHist(hTot[1],histograms[j],"TTPValCutStudy_" + hnames[(j-1)/3]+"_eta"); + else if (!((j-2)%3)) effHist =getEffHist(hTot[2],histograms[j],"TTPValCutStudy_" + hnames[(j-2)/3]+"_phi"); + if ( debug ) cout <<j << " Efficicency Histograms created... " << endl; + effHistograms[j] = effHist; + if ( debug ) cout << effHist->GetNbinsX() << " bins in effHist found..." << endl; + } + if (debug ) cout << "Efficiency Histograms filled." << endl; + + break; + + case 1 : + + createHistograms(effHistograms); + if ( debug ) cout << "Array for Histograms created..." << endl; + for (unsigned int j = 0; j != nHistos ; ++j ) { + if ( debug ) cout << "Pointer to histograms created" << endl; + if ( j==0 ) effHist = getEffHist(hTot[j],histograms[j],"TTPValCutStudy_" + hnames[0]+"_pt"); + if ( j==1 ) effHist = getEffHist(hTot[j],histograms[j],"TTPValCutStudy_" + hnames[0]+"_eta"); + if ( j==2 ) effHist = getEffHist(hTot[j],histograms[j],"TTPValCutStudy_" + hnames[0]+"_phi"); + else if ( j!=0 && j!=1) { + if (!(j%3)) effHist =getEffHist(histograms[j-3],histograms[j],"TTPValCutStudy_" + hnames[j/3]+"_pt"); + else if (!((j-1)%3)) effHist =getEffHist(histograms[j-3],histograms[j],"TTPValCutStudy_" + hnames[(j-1)/3]+"_eta"); + else if (!((j-2)%3)) effHist =getEffHist(histograms[j-3],histograms[j],"TTPValCutStudy_" + hnames[(j-2)/3]+"_phi"); + } + if ( debug ) cout <<j << " Efficicency Histograms created... " << endl; + effHistograms[j] = effHist; + } + if ( debug ) cout << "Efficiency Histograms filled." << endl; + + break; + + }; +} + + + +TH1F * TTPValCutStudy::getEffHist(TH1F * hTot1, TH1F * hCut1, TString name) +{ + if( hTot1 == 0 || hCut1 == 0 ) cout << "ERROR: Input to getEffHist is bad!!! " << endl; + + TH1F * hEff = (TH1F*)hTot1->Clone(name); + + if ( debug ) cout << "Dividing now...." << endl; + if ( debug ) cout << "Dividing....done!" << endl; + hEff->GetYaxis()->SetTitle("Efficiency"); + hEff->SetMaximum(1.1); + hEff->SetMinimum(0); + if ( debug ) cout << "Configuration of histogram....done" << endl; + hEff->SetTitle(hCut1->GetTitle()); + if ( debug ) cout << "Title set to " << hCut1->GetTitle() << endl; + + unsigned int nbin = hCut1->GetNbinsX(); + if ( debug ) cout << hCut1->GetNbinsX() << " bins found..." << endl; + float eff; float errEff; + for(unsigned int itau = 1 ; itau < nbin ; ++itau) + { + eff = 0; errEff = 0; + if( hTot1->GetBinContent(itau) > 0 ) + { + if (debug ) cout << "Bin content of hCut is " << hCut1->GetBinContent(itau) << endl; + if ( debug ) cout << "Bin content of hTol is " << hTot1->GetBinContent(itau) << endl; + eff = float(hCut1->GetBinContent(itau))/float( hTot1->GetBinContent(itau)); + errEff = sqrt(eff*(1.-eff)/float( hTot1->GetBinContent(itau))); + if ( debug ) cout << "Reuting efficiency is " << eff << endl; + //eff *= 100.; + //errEff *= 100.; + hEff->SetBinContent(itau, eff); + hEff->SetBinError(itau, errEff); + } + } + return hEff; +} + +void TTPValCutStudy::createHistograms(TH1F ** histos) { + TString name; + for (unsigned int count = 0; count!=nNames; count++ ) { + if (debug) cout << " Will create " << nNames << " histograms!" << endl; + + if (debug) cout << "Creating Histogram " << count << endl; + name="TTPValCutStudy_" + hnames[count]+"_pt"; + //if (debug ) cout << " b\n"; + histos[3*count]= new TH1F("TTPValCutStudy_" + name, name, 50, 0, 120); + if (debug) cout << " At step 2 of " << 3*count << ", variable nNames: " << nNames << endl; + //if (debug) cout << " c\n"; + //if (debug) cout << " d\n"; + histos[3*count]->GetXaxis()->SetTitle("pt"); + //if (debug) cout << " e\n"; + if (debug) cout << " After creating histogram " << 3*count << ", variable nNames: " << nNames << endl; + + name = "TTPValCutStudy_" + hnames[count]+"_phi"; + //cout << " f "<< 3*i+1 << " " << nNames<<"\n"; + histos[3*count+1] = new TH1F("TTPValCutStudy_" + name, name, 64, -3.2, 3.2); + //cout << " g\n"; + //cout << " h\n"; + histos[3*count+1]->GetXaxis()->SetTitle("phi"); + //cout << " i\n"; + if (debug) cout << " After creating histogram " << 3*count+1 << ", variable nNames: " << nNames << endl; + + name = "TTPValCutStudy_" + hnames[count]+"_eta"; + histos[3*count+2] = new TH1F("TTPValCutStudy_" + name, name, 50, -2.5, 2.5); + histos[3*count+2]->GetXaxis()->SetTitle("eta"); + //cout << " j\n"; + if (debug) cout << " After creating histogram " << 3*count+2 << ", variable nNames: " << nNames << endl; + } + + return; + +} + +void TTPValCutStudy::ATLAS_LABEL(Double_t x,Double_t y,Color_t color) { + + TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize); + l.SetNDC(); + l.SetTextFont(72); + l.SetTextColor(color); + l.DrawLatex(x,y,"ATLAS"); +} + +TString TTPValCutStudy::getName(TrigTauMCTauList::OFFLINESELECTION offlineType1) { + + TString value; + + if (offlineType1 == TrigTauMCTauList::TAU1P3P) value = "TAU1P3P"; + if (offlineType1 == TrigTauMCTauList::TAUREC) value = "TAUREC"; + if (offlineType1 == TrigTauMCTauList::EITHERTAU) value = "EITERHTAU"; + if (offlineType1 == TrigTauMCTauList::BOTHTAU) value = "BOTHTAU"; + if (offlineType1 == TrigTauMCTauList::NONE) value = "NONE"; + + return value; +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValDistribution.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValDistribution.cxx new file mode 100644 index 0000000000000000000000000000000000000000..23812716aa9b5bbe2789229d68c9bc612c46a3a1 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValDistribution.cxx @@ -0,0 +1,529 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +using namespace std; +#include "TrigTauPerformValidation/TTPValDistribution.h" + + + +TTPValDistribution::TTPValDistribution(TrigTauBugFix::TTPVERSION /*version*/, bool debug1) { + cout << "WARNING: Filename not specified!! " << endl; + initialize(debug1); + fileDefined = false; + return; +} + +TTPValDistribution::TTPValDistribution (const char * filename1, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version, TrigTauBugFix::RDO) { + + if (debug1) cout << " Creating validation4 object..." << endl; + filename = filename1; + chain = new TChain("eventTree"); + chain->Add(filename.c_str()); + initialize(debug1); + fileDefined = true; + +} + +void TTPValDistribution::initialize(bool debug1) { + + + debug = debug1; + signal = true; + maxVisEta = 2.5; + minLeadingPt = 6.0; + selected = true; + logScale = false; + plotAllMatchedEvents = false; + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + menu = TrigTauFlags::TAU20; + cutLevel = TrigTauSelectionManager::LOOSE; + offlineType = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + menuVersion = TrigTauSelectionManager::MENU1560; + chainType = TrigTauFlags::SITRK; + + //Level 1 + hnames.push_back("L1_TauCluster"); + hnames.push_back("L1_EMIsol"); + hnames.push_back("L1_HDIsol"); + hnames.push_back("L1_EMCore"); + hnames.push_back("L1_HDCore"); + hnames.push_back("L1_EMEnergy"); + //Level2 Calo + hnames.push_back("L2Calo_Et"); + hnames.push_back("L2Calo_Et_Calib"); + hnames.push_back("L2Calo_nStrips"); + hnames.push_back("L2Calo_stripWidth"); + hnames.push_back("L2Calo_EMRadius"); + hnames.push_back("L2Calo_IsoFrac"); + hnames.push_back("L2Calo_EMWidth"); + hnames.push_back("L2Calo_Et_Nar"); + //Level2 Track + hnames.push_back("L2Trk_nMinTrk");; + hnames.push_back("L2Trk_nSlow"); + hnames.push_back("L2Trk_nIso"); + hnames.push_back("L2Trk_nMatch"); + hnames.push_back("L2Trk_totCharge"); + hnames.push_back("L2Trk_maxPt"); + hnames.push_back("L2Trk_sumPtRatio"); + hnames.push_back("L2Trk_Et (Trk+EM)"); + //EF + hnames.push_back("EF_min nTrk"); + hnames.push_back("EF_max nTrk"); + hnames.push_back("EF_EMRadius"); + hnames.push_back("EF_IsoFrac"); + hnames.push_back("EF_EMFrac"); + hnames.push_back("EF_Pt_max"); + hnames.push_back("EF_Et"); + hnames.push_back("EF_EM_Et"); + hnames.push_back("EF_Mass"); + + hnames.push_back("ROI_phi"); + + nL1Cuts = 6; + nL2CaloCuts = 8; + nL2TrkCuts = 8; + nEFCuts = 10; + nHistos = hnames.size()*3; + nNames = hnames.size(); + + + if ( nL1Cuts+nL2CaloCuts+nL2TrkCuts+nEFCuts != nNames || nHistos != nHistograms ) { + cout << "ERROR: Number of Cuts for different levels incorrect!!!" << endl; + return; + } + + + +} + + +void TTPValDistribution::setPlotAllEvents (bool newValue) { + + ignoreMatching = newValue; + if (newValue == true) plotAllMatchedEvents = true; + return; +} + + + +void TTPValDistribution::setFile(const char * filename1) { + filename = filename1; + chain = new TChain("eventTree"); //potential memory leak + chain->Add(filename.c_str()); + fileDefined = true; + return; +} + + +void TTPValDistribution::analyze(int number) { + + if (!fileDefined) { + cout << "File was not defined and variables not initialized!!" << endl; + return; + } + + if (debug) cout << "Creating Histograms..." << endl; + createHistograms(histograms); + if (debug) cout << "Histograms created! Building selmanager..." << endl; + selmanager.setMenuVersion(menuVersion); + selmanager.setTauMenu(menu, cutLevel); + if (debug) cout << "Validation object created!!" << endl; + + + // MC truth + for (unsigned int i = 0; i!=3; ++i) { + + analyzer[i].truthList.setMaxVisEta(maxVisEta); + analyzer[i].truthList.setMinVisPt(menu); // in GeV + analyzer[i].truthList.setMinLeadingPt(minLeadingPt); // pt of the leading pt of track is + if ( i == 1 ) analyzer[i].truthList.select1Prong(); + else if ( i == 2 ) analyzer[i].truthList.select3Prong(); + analyzer[i].truthList.setRecoMatchdR(0.2); + analyzer[i].trigMan.setL1MET(0.); + analyzer[i].trigMan.setMenuVersion(menuVersion ); + analyzer[i].trigMan.setTauMenu(menu, cutLevel); + analyzer[i].chainList.setRoiWordMatching(false); + analyzer[i].chainList.setHLTAuthor(chainType); + } + + event = new TrigTauEvent(); + chain->SetBranchAddress("EventBranch", &event); + chain->SetBranchStatus("*", 1); + + // Also set an L1 MET cut if desired + + int nev = int(chain->GetEntries()); + if ( nev > number ) nev = number; + for(int iev = 0; iev<nev; ++iev) { + analyzeEvent( iev ); + } +} + + +void TTPValDistribution::analyzeEvent(int eventNumber) { + + event->reset(); + chain->GetEvent(eventNumber); + bugfix.fix(event); + + for (unsigned int j =0; j!=3; ++j) { + + analyzer[j].analyze(event, signal, offlineType); + + if (j==2 && debug) cout <<"Checking 3-prong decay..." << endl; + + // ============ Select type of events (e.g. signal) ================ + if( signal ) { + // analyzer[j].truthList.fillPureList(&event->mcEvent); +// analyzer[j].truthList.fillGoodList(); +// analyzer[j].truthList.requireRecoMatch(*event, offlineType); + if ( debug && analyzer[j].truthList.nMCTauGood() ==0 ) cout << "Event contains no good taus! " << endl; + if( analyzer[j].truthList.nMCTauGood() ==0 ) return; + } + + if (j==2 && debug) cout << "3-Prong decay found!" << endl; + + // loop over taus after fiducial cuts + + if ( debug ) cout << "Event contains " << analyzer[j].truthList.nMCTauGood() << " good tau!" << endl; + for( unsigned int iTrue = 0; iTrue < analyzer[j].truthList.nMCTauGood(); ++iTrue ) //loop over all true taus + { + const TrigTauMCTau * truth = & analyzer[j].truthList.mcTauGoodEntry(iTrue); //select tau + + unsigned int nTrigChains = analyzer[j].chainList.nTrigChains() ; + if (debug ) cout << "Value of nTrigChains: " << nTrigChains << endl; + if ( nTrigChains == 0 ) continue; + + for( unsigned int ichain = 0; ichain != nTrigChains; ++ichain) { + if ( debug ) cout << "Starting chain " << ichain << "!" << endl; + const TrigTauTrigChain *ch = &analyzer[j].chainList.trigChainEntry(ichain); + const TrigTauL1Object* l1object = ch->L1; + const TrigTauL2Object* l2object = ch->L2; + const TrigTauL2Object* l2calobject = ch->L2Cal; + const TrigTauL2Object* l2trkobject = ch->L2Trk; + const TrigTauRecEFObject* efobject = ch->EF; + + //check Level 1 + if (l1object == 0 && !plotAllMatchedEvents) { + if ( debug ) cout << "L1 Object is empty; go to next chain" << endl; + continue; + } + if (debug) cout << "Checking Level 1..." << endl; + if( !(l1object == 0 ) && (truth->DeltaR(*l1object)<0.2 || ignoreMatching) ) { + if (debug) cout << "Good L1 object found... running cutWord" << endl; + unsigned int currentWord = selmanager.l1Sel.cutWord(*l1object); + //loop over all possible variables to cut on -> fill histograms; Probably can get it from TrigTauL1Object + histograms[0*3+j]->Fill(l1object->m_TauEnergy); + histograms[1*3+j]->Fill(l1object->m_EmIsol); + histograms[2*3+j]->Fill(l1object->m_HdIsol); + histograms[3*3+j]->Fill(l1object->m_EmCore); + histograms[4*3+j]->Fill(l1object->m_HdCore); + histograms[5*3+j]->Fill(l1object->m_EmEnergy); + //histograms[0*3+j]->Fill(l1object->m_EmEnergy); + //histograms[0*3+j]->Fill(l1object->m_EmEnergy); + if (debug) cout << "Histograms filled..." << endl; + + if (!plotAllMatchedEvents && currentWord != 0 ) continue; + if (debug) cout << "L1 done... " << endl; + } + else if (!plotAllMatchedEvents) continue; + + //check Level 2 (including Trk and Cal) + if (l2object == 0 && !plotAllMatchedEvents) { + if ( debug ) cout << "L2 object is empty; go to next chain" << endl; + continue; + } + if ( debug && !l2object == 0 ) cout << " L2 DeltaR is :" << ( truth->DeltaR(*l2object) ) << endl; + if( !(l2object == 0) && (truth->DeltaR(*l2object)<0.2 || ignoreMatching) ) { + + unsigned int currentWord1 = selmanager.l2CalSel.cutWord(*l2calobject); + unsigned int currentWord2 = selmanager.l2TrkSel.cutWord(*l2trkobject); + histograms[6*3+j]->Fill(l2calobject->etClus()); + histograms[7*3+j]->Fill(l2calobject->etClusCalib()); + histograms[8*3+j]->Fill(l2calobject->m_nStrips); + if (!selected || l2calobject->m_stripWidth2 > -90 ) histograms[9*3+j]->Fill(l2calobject->m_stripWidth2); + if (!selected || (l2calobject->m_EMRadius > -0.5 && l2calobject->m_EMRadius < 0.5) ) histograms[10*3+j]->Fill(l2calobject->m_EMRadius); + if (!selected || (l2calobject->m_isoFrac > -2 && l2calobject->m_isoFrac < 2) ) histograms[11*3+j]->Fill(l2calobject->m_isoFrac); + if (!selected || (l2calobject->m_EMEnergyWidth[2] < 100 && l2calobject->m_EMEnergyWidth[2] > -90) ) histograms[12*3+j]->Fill(l2calobject->m_EMEnergyWidth[2]); + histograms[13*3+j]->Fill(l2calobject->etNarrow()); + //TrigTauL2TrkFEX l2FEX(l2object); + //l2FEX.setL2Object(l2object); + //l2FEX.calculate(); + histograms[14*3+j]->Fill(l2object->m_nCoreTracks); + histograms[15*3+j]->Fill(l2object->m_nSlowTracks); + histograms[16*3+j]->Fill(l2object->m_nIsoTracks); + histograms[17*3+j]->Fill(l2object->m_nMatchedTracks); + histograms[18*3+j]->Fill(l2object->m_charge); + histograms[19*3+j]->Fill(l2object->m_leadingTrackPt); + histograms[20*3+j]->Fill(l2object->m_scalarPtSumIso/l2object->m_scalarPtSumCore); + histograms[21*3+j]->Fill(l2object->ptTot()); + + if ( (currentWord1 !=0 || currentWord2 !=0) && !plotAllMatchedEvents ) continue; + } + else if (!plotAllMatchedEvents) continue; + + + //check EF + if (efobject == 0) { + if ( debug ) cout << "EF object is empty; go to next chain" << endl; + continue; + } + if ( debug ) cout << " EF DeltaR is :" << ( truth->DeltaR(*efobject) ) << endl; + if ( truth->DeltaR(*efobject)<0.2 || ignoreMatching ) { + unsigned int currentWord = selmanager.efSel.cutWord(*efobject); + histograms[22*3+j]->Fill(efobject->nTracks()); + histograms[23*3+j]->Fill(efobject->nTracks()); + if (!selected || efobject ->m_EMRadius > -0.2 ) histograms[24*3+j]->Fill(efobject->m_EMRadius); + if (debug) cout << "EMRadius histogram filled." << endl; + if (!selected || efobject->m_isoFrac > -0.2 ) histograms[25*3+j]->Fill(efobject->m_isoFrac); + float emFrac=0; + if (!selected || efobject->m_etEMCalib>0 ) emFrac = efobject->m_etEMCalib/(efobject->m_etEMCalib + efobject->m_etHadCalib); + histograms[26*3+j]->Fill(emFrac); + if (debug) cout << "EMFrac histogram filled. " << endl; + float ptMax = 999999999.; + if (efobject->nTracks() ) { + if (debug) cout << "Non-zero number of tracks found." << endl; + if (efobject->leadingTrack()) ptMax = efobject->leadingTrack()->Pt(); + } + if (debug) cout << "ptMax calculated." << endl; + if (!selected || ptMax < 100000 ) histograms[27*3+j]->Fill(ptMax); + histograms[28*3+j]->Fill(efobject->Et()); + if (debug) cout << "Et histogram filled" << endl; + histograms[29*3+j]->Fill(efobject->m_energy/cosh(efobject->m_caloEta)); + //histograms[30*3+j]->Fill(efobject->mass()); mass is more complicated; will be added later. + histograms[30*3+j]->Fill(j); + histograms[31*3+j]->Fill(efobject->Phi()); + if (debug) cout << "All histograms filled..." << endl; + if ( currentWord == 0 && debug ) cout << "Tau passed trigger!!!" << endl; + + } + if (debug ) cout << "All levels for chain " << ichain << " checked." << endl; + } // end chain loop + } // end loop over truth + } //end loop over different prong decays + return; +} + + +void TTPValDistribution::print() { + + + TCanvas * c1 = (TCanvas *)gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,500); + if (logScale) gPad->SetLogy(1); + /* + //c1->Divide(3,2); + TPad *p1 = new TPad("p1","", 10, 10, 800, 500); + c1->cd(); + p1->Draw(); + p1->cd(); + p1->Divide(3,2); + //c1->Print("ntuple.eps["); + + for (unsigned int j = 0; j<nHistos; j=j+6) { + for (unsigned int k = 0; k!=6; ++k) { + if (j+k < nHistos) { + c1->cd(); + if (debug) cout << "Drawing histo no. " << j+k << endl; + c1->cd(k); + if (debug) cout << "Creating pointer..." << endl; + TH1F * histo = (TH1F*)histograms[j+k]; + if (histo != 0) histo->Draw(); + if (debug) cout << "Histogram created..." << endl; + } + } + c1->Update(); + //c1->Print("ntuple.eps"); + } + + //c1->Print("ntuple.eps]"); + */ + if (debug) cout << "Number of total histograms: " << nHistos << endl; + for (unsigned int j = 0; j < (nHistos) ; j+=3 ) { + TH1F * histo1 = (TH1F*)histograms[j]; + TH1F * histo2 = (TH1F*)histograms[j+1]; + TH1F * histo3 = (TH1F*)histograms[j+2]; + + if ( debug ) cout << "Draw Histogram No. " << j << endl; + if ( histo1 != 0 ) histo1->Draw(); + histo2->SetLineColor(kRed); + if ( histo2 != 0) histo2->Draw("same"); + histo3->SetLineColor(kBlue); + if ( histo3 != 0 )histo3->Draw("same"); + else cout << "Missing 3Pr histogram" << endl; + if ( debug ) cout << "Printing Histogram No " << j << endl; + + if ( j==0 ) c1->Print("trigtau.ntuple.eps("); + else if ( j> nHistos-3 ) c1->Print("trigtau.ntuple.eps)"); + else c1->Print("trigtau.ntuple.eps"); + } + + return; +} + +void TTPValDistribution::save(const char * name) { + + TH1F * histo; + + if (debug) cout << "Starting Save..." << endl; + TFile f(name, "recreate"); + if (debug) cout << "File created..." << endl; + for (unsigned int j = 0; j < nHistos ; ++j ) { + histo = (TH1F*)histograms[j]; + if (debug) cout << "Writing histogram " << j << "...." << endl; + histo->Scale(1/histo->Integral()); + histo->Write(); + histo->Draw(); + } + //f->Write(); + if (debug) cout << "Histograms written..." << endl; + f.Close(); + return; +} + +void TTPValDistribution::compare(const char * reference, const char * output) { + + compare(reference, "", output); + +} + + +void TTPValDistribution::compare(const char * reference1, + const char * reference2, + const char * output) { + + TCanvas * c2 = (TCanvas *)gROOT->Get("c2"); + if( c2 ) delete c2; + c2 = new TCanvas("c1","",10,10,800,500); + if (logScale) gPad->SetLogy(1); + + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + + if (debug) cout << "Opening file..." << endl; + + TFile * file1 = new TFile(reference1); + TFile * file2 = 0; + if (reference2[0] != '\0') file2 = new TFile(reference2); + + for (unsigned int j=0; j!= nHistos; ++j) { + + if (debug) cout << "Processing Histogram " << j << endl; + + TH1* h1 = (TH1*)gROOT->Get("h1"); + if( h1 ) delete h1; + if (debug) cout << " Cloning h1...." << endl; + h1 = (TH1*)histograms[j]->Clone("h1"); + + if (debug) cout << " h1 found...." << endl; + + TH1* h2 = (TH1*)gROOT->Get("h2"); + if( h2 ) delete h2; + if ( !(j%3) ) h2 = (TH1*)file1->Get(hnames[j/3]+"_ALL")->Clone("h2"); + else if (!((j-1)%3)) h2 = (TH1*)file1->Get(hnames[(j-1)/3]+"_1Prong")->Clone("h2"); + else if (!((j-2)%3)) h2 = (TH1*)file1->Get(hnames[(j-2)/3]+"_3Prong")->Clone("h2"); + + if (debug) cout << " h2 found..." << endl; + + TH1 * h3 = 0; + if (file2) { + + h3 = (TH1*)gROOT->Get("h3"); + if( h3 ) delete h3; + if ( !(j%3) ) h3 = (TH1*)file2->Get(hnames[j/3]+"_ALL")->Clone("h3"); + else if (!((j-1)%3)) h3 = (TH1*)file2->Get(hnames[(j-1)/3]+"_1Prong")->Clone("h3"); + else if (!((j-2)%3)) h3 = (TH1*)file2->Get(hnames[(j-2)/3]+"_3Prong")->Clone("h3"); + + if (debug) cout << " h3 found..." << endl; + + } + + + if( h1 ){ + h1->SetLineColor(1); + h1->DrawNormalized("",1); + } + else cout << "No h1 found \n"; + + if( h2 ){ + h2->SetLineColor(2); + h2->DrawNormalized("same", 1); + } + else cout << "No h2 found \n"; + + if (h3) { + h3->SetLineColor(3); + h3->DrawNormalized("same", 1); + } + else cout << "No h3 found \n"; + + + if ( j==0 ) c2->Print(TString(output)+"("); + else if ( j+1==nHistos ) c2->Print(TString(output)+")"); + else c2->Print(output); + + } + +} + + +void TTPValDistribution::update(const char * name) { + + TH1F * histo; + + if (debug) cout << "Starting Save..." << endl; + TFile f(name, "update"); + if (debug) cout << "File created..." << endl; + + f.cd(); + f.mkdir("Distribution"); + f.cd("Distribution"); + + for (unsigned int j = 0; j < nHistos ; ++j ) { + histo = (TH1F*)histograms[j]; + if (debug) cout << "Writing histogram " << j << "...." << endl; + histo->Write(); + histo->Draw(); + } + //f->Write(); + if (debug) cout << "Histograms written..." << endl; + f.Close(); + return; +} + + +void TTPValDistribution::createHistograms(TH1F ** histos) { + + TString name; + for (unsigned int count = 0; count!=nNames; count++ ) { + if (debug) cout << " Will create " << nNames << " histograms!" << endl; + if (debug) cout << "Creating Histogram " << count << endl; + name="TTPValDistribution_" + hnames[count]+"_ALL"; + //if (debug ) cout << " b\n"; + histos[3*count]= new TH1F(name, name, 100, -0.1, 0.1); + histos[3*count]->SetBit(TH1::kCanRebin); + + name = "TTPValDistribution_" + hnames[count]+"_1Prong"; + //cout << " f "<< 3*i+1 << " " << nNames<<"\n"; + histos[3*count+1] = new TH1F(name, name, 100, -0.1, 0.1); + histos[3*count+1]->SetBit(TH1::kCanRebin); + if (debug) cout << " After creating histogram " << 3*count+1 << ", variable nNames: " << nNames << endl; + + name = "TTPValDistribution_" + hnames[count]+"_3Prong"; + histos[3*count+2] = new TH1F(name, name, 100, -0.1, 0.1); + histos[3*count+2]->SetBit(TH1::kCanRebin); + //cout << " j\n"; + if (debug) cout << " After creating histogram " << 3*count+2 << ", variable nNames: " << nNames << endl; + } + + return; + +} + + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValEffTableMaker.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValEffTableMaker.cxx new file mode 100644 index 0000000000000000000000000000000000000000..25b12164e207477d456211822e34a2bc958b5c2b --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValEffTableMaker.cxx @@ -0,0 +1,739 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <fstream> +#include <iomanip> +using namespace std; +#include "TrigTauPerformValidation/TTPValEffTableMaker.h" + +TTPValEffTableMaker::TTPValEffTableMaker (TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version , poolfile) { + + filenameSet = false; + offlineType[0] = TrigTauMCTauList::NONE; + offlineType[1]= TrigTauMCTauList::TAU1P3P; + offlineType[2]= TrigTauMCTauList::TAUREC; + offlineType[3]= TrigTauMCTauList::EITHERTAU; + offlineType[4]= TrigTauMCTauList::BOTHTAU; + offlineType[5] = TrigTauMCTauList::TAUCUTSAFELOOSE; + offlineType[6] = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + offlineType[7] = TrigTauMCTauList::TAUCUTSAFETIGHT; + offlineType[8] = TrigTauMCTauList::TAULLHLOOSE; + offlineType[9] = TrigTauMCTauList::TAULLHMEDIUM; + offlineType[10] = TrigTauMCTauList::TAULLHTIGHT; + + initialize(debug1); + return; +} + +TTPValEffTableMaker::TTPValEffTableMaker (TString filename1, TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version , poolfile) { + + setFile (filename1); + filenameSet = true; + offlineType[0] = TrigTauMCTauList::NONE; + offlineType[1]= TrigTauMCTauList::TAU1P3P; + offlineType[2]= TrigTauMCTauList::TAUREC; + offlineType[3]= TrigTauMCTauList::EITHERTAU; + offlineType[4]= TrigTauMCTauList::BOTHTAU; + offlineType[5] = TrigTauMCTauList::TAUCUTSAFELOOSE; + offlineType[6] = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + offlineType[7] = TrigTauMCTauList::TAUCUTSAFETIGHT; + offlineType[8] = TrigTauMCTauList::TAULLHLOOSE; + offlineType[9] = TrigTauMCTauList::TAULLHMEDIUM; + offlineType[10] = TrigTauMCTauList::TAULLHTIGHT; + initialize(debug1); + return; + +} + + +void TTPValEffTableMaker::setFile ( TString filename1) { + + if (!filenameSet ) { + filename = filename1; + tree = new TChain("eventTree"); + tree->Add(filename); + } + else { + cout << "WARNING: File already defined!! Overwriting old file settings...." << endl; + filename = filename1; + tree = new TChain("eventTree"); //memory leak + tree->Add(filename); + } + filenameSet = true; +} + + +void TTPValEffTableMaker::setChain ( TChain * tree1 ) { + + if ( filenameSet ) { + cout << "WARNING: Tree already defined!! Overwriting tree...." << endl; + tree = tree1; + } + else { + tree = tree1; + if (debug) cout << " Chain is set..." << endl; + } + filenameSet = true; +} + +void TTPValEffTableMaker::initialize ( bool debug1) { + + maxVisEta = 2.5; + minLeadingPt = 6.0; + setDebug(debug1); + setSignal(true); + menu = TrigTauFlags::TAU16; + cutLevel = TrigTauSelectionManager::LOOSE; + menuVersion = TrigTauSelectionManager::MENU1560; + chainType = TrigTauFlags::SITRK; + return; +} + + +void TTPValEffTableMaker::analyze() { + + if (!filenameSet) { + cout << "ERROR: Please set filename! Use TTPValEffTableMaker::setFile(TString filename)." << endl; + return; + } + + //set counter to zero and initialize MCTruth analyzer + for (unsigned int i =0 ; i!=nMatching ; ++i) + for (unsigned int j=0; j!=nProngType; ++j) { + for(unsigned int k=0; k!=5; ++k) + counter[i][j][k] = 0; + analyzer[i][j].truthList.setMaxVisEta(maxVisEta); + analyzer[i][j].truthList.setMinLeadingPt(minLeadingPt); + analyzer[i][j].truthList.setMinVisPt(menu); + if ( j == 0 ) analyzer[i][j].truthList.select1Prong(); + if ( j == 1 ) analyzer[i][j].truthList.select3Prong(); + analyzer[i][j].truthList.setRecoMatchdR(0.2); + //set L1Met cut if desired + analyzer[i][j].trigMan.setL1MET(0.); + analyzer[i][j].trigMan.setMenuVersion(menuVersion ); + analyzer[i][j].trigMan.setTauMenu(menu, cutLevel); + analyzer[i][j].chainList.setRoiWordMatching(false); + analyzer[i][j].chainList.setHLTAuthor(chainType); + } + + selmanager.setMenuVersion(menuVersion); + selmanager.setTauMenu(menu, cutLevel); + + if ( debug ) cout << "Starting Analysis..." << endl; + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + //tree->SetBranchStatus("mcEvent*", 0); + + // Loop over all events + nev = int(tree->GetEntries()); + if ( debug ) cout << "Starting eventloop..." << endl; + //if ( nev > 10 ) nev = 10; + for(int iev = 0; iev<nev; ++iev) { + if ( debug ) cout << "============== Checking event " << iev << " ==================" << endl; + event->reset(); + tree->GetEvent(iev); + bugfix.fix(event); + + if ( debug ) cout << "Starting analysis of event for all matchings and types..." << endl; + + bool goodEvent = true; + for (unsigned int i =0; i!=nMatching; ++i) + for (unsigned int j=0; j!=nProngType; ++j) { + if ( debug && i==2 && j==2 ) cout << "Analyze event " << iev << " with matching type " << i << " and prong type " << j << "." << endl; + goodEvent = analyzeEvent(event, offlineType[i], i, j); + } + } // end loop over events +} + + +bool TTPValEffTableMaker::analyzeEvent (TrigTauEvent * event, TrigTauMCTauList::OFFLINESELECTION offlineType, int i, int j ) { + + if (debug && i==2 && j==2 ) cout << "Starting analyzeEvent...." << endl; + + analyzer[i][j].analyze(event, signal, offlineType); + + // ============ Select type of events (e.g. signal) ================ + if( signal ) { + analyzer[i][j].truthList.fillPureList(&event->mcEvent); + analyzer[i][j].truthList.fillGoodList(); + analyzer[i][j].truthList.requireRecoMatch(*event, offlineType); + if ( debug && i==2 && j==2 && analyzer[i][j].truthList.nMCTauGood() ==0 ) cout << "Event contains no good taus! " << endl; + if( analyzer[i][j].truthList.nMCTauGood() ==0 ) return false; + } + + // loop over taus after fiducial cuts + + if ( debug && i==2 && j==2 ) cout << "Event contains " << analyzer[i][j].truthList.nMCTauGood() << " good tau!" << endl; + for( unsigned int iTrue = 0; iTrue < analyzer[i][j].truthList.nMCTauGood(); ++iTrue ) //loop over all true taus + { + const TrigTauMCTau * truth = & analyzer[i][j].truthList.mcTauGoodEntry(iTrue); //select tau + counter[i][j][4]++; + + //if ( debug && analyzer[i][j].chainList == 0 ) cout << "ERROR: No chain list found!!" << endl; + //if ( debug && i==2 && j==2 ) cout << "L1 chains: " << analyzer[i][j].chainList.nPassL1Chains() << endl; + unsigned int nTrigChains = analyzer[i][j].chainList.nTrigChains() ; + if (debug && i==2 && j==2 ) cout << "Value of nTrigChains: " << nTrigChains << endl; + if ( nTrigChains == 0 ) continue; + + + + for( unsigned int ichain = 0; ichain < nTrigChains; ++ichain) { + if ( debug && i==2 && j==2 ) cout << "Starting chain " << ichain << "!" << endl; + const TrigTauTrigChain *ch = &analyzer[i][j].chainList.trigChainEntry(ichain); + const TrigTauL1Object* l1object = ch->L1; + const TrigTauL2Object* l2object = ch->L2; + const TrigTauL2Object* l2calobject = ch->L2Cal; + const TrigTauL2Object* l2trkobject = ch->L2Trk; + const TrigTauRecEFObject* efobject = ch->EF; + unsigned int currentWord; + if ( l1object == 0 ) continue; + + if( truth->DeltaR(*l1object)<0.2 ) { + currentWord = selmanager.l1Sel.cutWord(*l1object); + if (currentWord != 0 ) continue; + counter[i][j][0]++; + } + else continue; + + //check Level 2 (including Trk and Cal) + if (l2object == 0 ) continue; + + if( truth->DeltaR(*l2object)<0.2 ) { + currentWord = selmanager.l2CalSel.cutWord(*l2calobject); + if ( currentWord !=0 ) { + continue; + } + counter[i][j][1]++; + currentWord = selmanager.l2TrkSel.cutWord(*l2trkobject); + if ( currentWord !=0 ) continue; + counter[i][j][2]++; + } + else continue; + + + //check EF + if (efobject == 0 ) { + if ( debug && i==2 && j==2 ) cout << "EF object is empty; go to next chain" << endl; + continue; + } + if( truth->DeltaR(*efobject)<0.2 ) { + currentWord = selmanager.efSel.cutWord(*efobject); + if (currentWord != 0) continue; + counter[i][j][3]++; + + } + } // end chain loop + } // end loop over truth + return true; +} //end function + + + + +void TTPValEffTableMaker::print (int which) { + + + TrigTauFlags menu1; + + ofstream outfile; + outfile.open("effTable.txt"); + + switch (which) { + + case 0 : + + outfile << "Printing ABSOLUTE Efficiencies: " << endl; + outfile << "Menu " << menu1.menuName(menu) << "\tNumber of total Events: " << nev << endl; + + outfile << "For matching: \n 0 - Tau1P3P \n 1 - TAUREC \n 2 - EITHERTAU \n 3 - BOTHTAU \n 4 - TauCutSafeLoose \n 5 - TauCutSafeMedium \n 6 - TauCutSafeTight \n 7 - TauLlhLoose \n 8 - TauLlhMedium \n 9 - TauLlhTight \n 10 - NONE " << endl; + + + outfile << "\n Number of truth events: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][4]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + outfile << "\n For L1: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][0])/float(counter[i][j][4]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + outfile << "\n For L2Calo: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][1])/float(counter[i][j][4]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + outfile << "\n For L2Trk: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][2])/float(counter[i][j][4]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + + outfile << "\n For EF: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][3])/float(counter[i][j][4]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + outfile << "\nSummary: \"All\" decays and \"TauCutSafeMedium\" offline matching: " << endl; + outfile << "\n\t\t\t\t & Level1 \t\t & L2Calo \t\t & L2Trk \t\t & EF \\\\" << endl; + outfile << "Relative Efficiencies:\t\t & "<< setprecision(3) << float(counter[6][2][0])/float(counter[6][2][4]) + << "\t\t & " << float(counter[6][2][1])/float(counter[6][2][0]) + << "\t\t & " << float(counter[6][2][2])/float(counter[6][2][1]) + << "\t\t & " << float(counter[6][2][3])/float(counter[6][2][2]) << " \\\\" << endl; + outfile << "Absolute Efficiencies: \t\t & "<< setprecision(3) << float(counter[6][2][0])/float(counter[6][2][4]) + << "\t\t & " << float(counter[6][2][1])/float(counter[6][2][4]) + << "\t\t & " << float(counter[6][2][2])/float(counter[6][2][4]) + << "\t\t & " << float(counter[6][2][3])/float(counter[6][2][4]) << " \\\\" << endl; + + + + break; + + + + case 1: + + outfile << "Printing RELATIVE Efficiencies: " << endl; + outfile << "Menu " << menu1.menuName(menu) << "\tNumber of total Events: " << nev << endl; + + outfile << "For matching: \n 0 - Tau1P3P \n 1 - TAUREC \n 2 - EITHERTAU \n 3 - BOTHTAU \n 4 - TauCutSafeLoose \n 5 - TauCutSafeMedium \n 6 - TauCutSafeTight \n 7 - TauLlhLoose \n 8 - TauLlhMedium \n 9 - TauLlhTight \n 10 - NONE " << endl; + + outfile << "\n Number of truth events: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][4]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + outfile << "\n For L1: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][0])/float(counter[i][j][4]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + outfile << "\n For L2Calo: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][1])/float(counter[i][j][0]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + outfile << "\n For L2Trk: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][2])/float(counter[i][j][1]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + + outfile << "\n For EF: " << endl; + outfile << "\t\t & 1Pr \t\t\t & 3Pr \t\t\t & All \\\\" << endl; + for (unsigned int i = 0; i!=nMatching; ++i) { + outfile << offlineType[i]; + + for (unsigned int j = 0; j!=nProngType; ++j) { + if (counter[i][j][4]!=0) outfile << "\t\t & " << setprecision(3) << float(counter[i][j][3])/float(counter[i][j][2]); + else outfile << "\t\t undef."; + } + outfile << " \\\\\n"; + } + + + outfile << "\nSummary: \"All\" decays and \"TauCutSafeMedium\" offline matching: " << endl; + outfile << "\n\t\t\t\t & Level1 \t\t & L2Calo \t\t & L2Trk \t\t & EF \\\\" << endl; + outfile << "Relative Efficiencies:\t\t & "<< setprecision(3) << float(counter[6][2][0])/float(counter[6][2][4]) + << "\t\t & " << float(counter[6][2][1])/float(counter[6][2][0]) + << "\t\t & " << float(counter[6][2][2])/float(counter[6][2][1]) + << "\t\t & " << float(counter[6][2][3])/float(counter[6][2][2]) << " \\\\" << endl; + outfile << "Absolute Efficiencies: \t\t & "<< setprecision(3) << float(counter[6][2][0])/float(counter[6][2][4]) + << "\t\t & " << float(counter[6][2][1])/float(counter[6][2][4]) + << "\t\t & " << float(counter[6][2][2])/float(counter[6][2][4]) + << "\t\t & " << float(counter[6][2][3])/float(counter[6][2][4]) << " \\\\" << endl; + + + break; + } + + return; + +} + +void TTPValEffTableMaker::printCSC(TPostScript & ps, bool relEff) { + + TrigTauFlags menu1; + + TH1F * L1Eff = new TH1F("TTPValEffTableMaker_" + menu1.menuName(menu) + "_L1", "L1 Relative Efficiencies", nMatching*nProngType+1, 0, nMatching*nProngType+1); + TH1F * L2CaloEff = new TH1F("TTPValEffTableMaker_" + menu1.menuName(menu) + "_L2Calo", "L2Calo Relative Efficiencies", nMatching*nProngType+1, 0, nMatching*nProngType+1); + TH1F * L2TrkEff = new TH1F("TTPValEffTableMaker_" + menu1.menuName(menu) + "_L2Trk", "L2Trk Relative Efficiencies", nMatching*nProngType+1, 0, nMatching*nProngType+1); + TH1F * EFEff = new TH1F("TTPValEffTableMaker_" + menu1.menuName(menu) + "_EF", "EF Relative Efficiencies", nMatching*nProngType+1, 0, nMatching*nProngType+1); + + + switch (relEff) { + + case 1: + + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L1_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L1Eff->SetBinContent(i*nProngType+j+1, float(counter[i][j][0])/float(counter[i][j][4])); + L1Eff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L1Eff->LabelsOption("d","X"); + } + } + + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L2Calo_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L2CaloEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][1])/float(counter[i][j][0])); + L2CaloEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L2CaloEff->LabelsOption("d","X"); + } + } + + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L2Trk_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L2TrkEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][1])/float(counter[i][j][1])); + L2TrkEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L2TrkEff->LabelsOption("d","X"); + } + } + + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "EF_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) EFEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][3])/float(counter[i][j][2])); + EFEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + EFEff->LabelsOption("d","X"); + } + } + + break; + + case 0: + + L1Eff->SetName("L1 Absolute Efficiencies"); + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L1_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L1Eff->SetBinContent(i*nProngType+j+1, float(counter[i][j][0])/float(counter[i][j][4])); + L1Eff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L1Eff->LabelsOption("d","X"); + } + } + + L2CaloEff->SetName("L2Calo Absolute Efficiencies"); + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L2Calo_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L2CaloEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][2])/float(counter[i][j][4])); + L2CaloEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L2CaloEff->LabelsOption("d","X"); + } + } + + L2TrkEff->SetName("L2Trk Absolute Efficiencies"); + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L2Trk_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L2TrkEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][1])/float(counter[i][j][4])); + L2TrkEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L2TrkEff->LabelsOption("d","X"); + } + } + + EFEff->SetName("EF Absolute Efficiencies"); + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "EF_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) EFEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][3])/float(counter[i][j][4])); + EFEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + EFEff->LabelsOption("d","X"); + } + } + break; + }; + + TCanvas * c1 = (TCanvas *)gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,500); + ps.On(); + + L1Eff->GetYaxis()->SetTitle("L1 efficiency"); + L1Eff->Draw(); + c1->Update(); + + L2CaloEff->GetYaxis()->SetTitle("L2Calo efficiency"); + L2CaloEff->Draw(); + c1->Update(); + + L2TrkEff->GetYaxis()->SetTitle("L2Trk efficiency"); + L2TrkEff->Draw(); + c1->Update(); + + EFEff->GetYaxis()->SetTitle("EF efficiency"); + EFEff->Draw(); + c1->Update(); + + ps.Off(); +} + +void TTPValEffTableMaker::update(TString filename, bool relEff) { + + TFile f(filename, "update"); + + f.cd(); + f.mkdir("EffTable"); + f.cd("EffTable"); + + + TrigTauFlags menu1; + + TH1F * L1Eff = new TH1F("TTPValEffTableMaker_" + menu1.menuName(menu) + "_L1", "L1 Relative Efficiencies", nMatching*nProngType+1, 0, nMatching*nProngType+1); + TH1F * L2CaloEff = new TH1F("TTPValEffTableMaker_" + menu1.menuName(menu) + "_L2Calo", "L2Calo Relative Efficiencies", nMatching*nProngType+1, 0, nMatching*nProngType+1); + TH1F * L2TrkEff = new TH1F("TTPValEffTableMaker_" + menu1.menuName(menu) + "_L2Trk", "L2Trk Relative Efficiencies", nMatching*nProngType+1, 0, nMatching*nProngType+1); + TH1F * EFEff = new TH1F("TTPValEffTableMaker_" + menu1.menuName(menu) + "_EF", "EF Relative Efficiencies", nMatching*nProngType+1, 0, nMatching*nProngType+1); + + + switch (relEff) { + + case 1: + + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L1_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L1Eff->SetBinContent(i*nProngType+j+1, float(counter[i][j][0])/float(counter[i][j][4])); + L1Eff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L1Eff->LabelsOption("v","X"); + } + } + + + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L2Calo_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L2CaloEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][1])/float(counter[i][j][0])); + L2CaloEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L2CaloEff->LabelsOption("v","X"); + } + } + + + + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L2Trk_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L2TrkEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][1])/float(counter[i][j][1])); + L2TrkEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L2TrkEff->LabelsOption("v","X"); + } + } + + + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "EF_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) EFEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][3])/float(counter[i][j][2])); + EFEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + EFEff->LabelsOption("v","X"); + } + } + + break; + + + case 0: + + L1Eff->SetName("L1 Absolute Efficiencies"); + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L1_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L1Eff->SetBinContent(i*nProngType+j+1, float(counter[i][j][0])/float(counter[i][j][4])); + L1Eff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L1Eff->LabelsOption("v","X"); + } + } + + L2CaloEff->SetName("L2Calo Absolute Efficiencies"); + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L2Calo_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L2CaloEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][2])/float(counter[i][j][4])); + L2CaloEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L2CaloEff->LabelsOption("v","X"); + } + } + + L2TrkEff->SetName("L2Trk Absolute Efficiencies"); + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "L2Trk_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) L2TrkEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][1])/float(counter[i][j][4])); + L2TrkEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + L2TrkEff->LabelsOption("v","X"); + } + } + + EFEff->SetName("EF Absolute Efficiencies"); + for (unsigned int i = 0; i!=nMatching; ++i) { + //outfile << offlineType[i]; + for (unsigned int j = 0; j!=nProngType; ++j) { + TString label = "EF_"; + label += i; + if (j==0) label += "_1Prong"; + if (j==1) label += "_3Prong"; + if (j==2) label += "_AllDecay"; + if (counter[i][j][4]!=0) EFEff->SetBinContent(i*nProngType+j+1, float(counter[i][j][3])/float(counter[i][j][4])); + EFEff->GetXaxis()->SetBinLabel(i*nProngType+j+1, label); + EFEff->LabelsOption("v","X"); + } + } + + + break; + + }; + + L1Eff->Write(); + L2CaloEff->Write(); + L2TrkEff->Write(); + EFEff->Write(); + f.Close(); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValLevelCut.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValLevelCut.cxx new file mode 100644 index 0000000000000000000000000000000000000000..923f49c86a3285da7d5446d05784ea78e45d2084 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValLevelCut.cxx @@ -0,0 +1,555 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +using namespace std; +#include "TrigTauPerformValidation/TTPValLevelCut.h" + + +TTPValLevelCut::TTPValLevelCut ( TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1 ) + : bugfix(version, poolfile) { + + initialize(debug1); + fileDefined = false; + return; +} + +TTPValLevelCut::TTPValLevelCut (TString filename1, TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version, poolfile) { + + filename = filename1; + chain = new TChain("eventTree"); + chain->Add(filename); + initialize(debug1); + fileDefined = true; + return; +} + +void TTPValLevelCut::initialize(bool debug1) { + + debug = debug1; + signal = true; + nprong = 0; + maxVisEta = 2.5; + minLeadingPt = 6.0; + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + menu = TrigTauFlags::TAU16; + //cutLevel = TrigTauSelectionManager::LOOSE; + offlineType = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + menuVersion = TrigTauSelectionManager::MENU1560; + chainType = TrigTauFlags::SITRK; + + nEvent = 0; + nTrue = 0; + nGood = 0; + nMatched = 0; + + npt =50; + minpt = 0; + maxpt = 120; + + color[0] = 51; + color[1] = 8; + color[2] = 60; + + style[0] = 20; + style[1] = 26; + style[2] = 21; + +} + +void TTPValLevelCut::setFile(TString filename1) { + + filename = filename1; + chain = new TChain("eventTree"); //potential memory leak + chain->Add(filename); + if (debug) cout << "file " << filename << " added. " << endl; + fileDefined = true; + return; + +} + +void TTPValLevelCut::analyze() { + + if (!fileDefined) { + cout << "File was not defined and variables not initialized!!" << endl; + return; + } + + selmanager.setMenuVersion(menuVersion); + //selmanager.setTauMenu(menu, cutLevel ); + selmanager.setL1MET(0.); + + // MC truth + analyzer.truthList.setMaxVisEta(maxVisEta); + analyzer.truthList.setMinVisPt(menu); // in GeV + //analyzer.truthList.setMinLeadingPt(minLeadingPt); // pt of the leading pt of track is + if( nprong == 1 ) analyzer.truthList.select1Prong(); + else if( nprong == 3 ) analyzer.truthList.select3Prong(); + //analyzer.truthList.setRecoMatchdR(0.2); + + event = new TrigTauEvent(); + chain->SetBranchAddress("EventBranch", &event); + chain->SetBranchStatus("*", 1); + + // Also set an L1 MET cut if desired + analyzer.trigMan.setL1MET(0.); + analyzer.trigMan.setMenuVersion(menuVersion); + + analyzer.chainList.setRoiWordMatching(false); + analyzer.chainList.setHLTAuthor(chainType); + + gROOT->cd(); + gROOT->SetStyle("ATLAS"); + gROOT->ForceStyle(); + + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); + gROOT->cd(); + + theCutLevel[0] = TrigTauSelectionManager::LOOSE; + theCutLevel[1] = TrigTauSelectionManager::MEDIUM; + theCutLevel[2] = TrigTauSelectionManager::TIGHT; + + test[0] = "LOOSE" ; + test[1] = "MEDIUM" ; + test[2] = "TIGHT" ; + + hMC_InVisPt = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + hMCVisPt = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + + hntrak = new TH1F("","",20,0.,10.); + + hMC_InVisEta = new TH1F("", "", 31, -3.1, 3.1); + hMCVisEta = new TH1F("", "", 31, -3.1, 3.1); + + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + + analyzer.trigMan.setTauMenu(menu, theCutLevel[iCutLevel]); + + nMatch[iCutLevel]=0; + nL1passed[iCutLevel]=0; + nL2passed[iCutLevel]=0; + nEFpassed[iCutLevel]=0; + n_OfflineMatchEvent[iCutLevel]=0; + n_L1MatchEvent[iCutLevel]=0; + n_L2MatchEvent[iCutLevel]=0; + n_EFMatchEvent[iCutLevel]=0; + + //hEFnTracks[iCutLevel] = new TH1F(*hntrak); + hL1VisPt[iCutLevel] = new TH1F(*hMCVisPt); + hL2VisPt[iCutLevel] = new TH1F(*hMCVisPt); + hEFVisPt[iCutLevel] = new TH1F(*hMCVisPt); + hL1PtEff[iCutLevel] = new TH1F(*hMCVisPt); + hL2PtEff[iCutLevel] = new TH1F(*hMCVisPt); + hEFPtEff[iCutLevel] = new TH1F(*hMCVisPt); + hL1PtEff[iCutLevel]->Sumw2(); + hL2PtEff[iCutLevel]->Sumw2(); + hEFPtEff[iCutLevel]->Sumw2(); + + hL1VisEta[iCutLevel] = new TH1F(*hMCVisEta); + hL2VisEta[iCutLevel] = new TH1F(*hMCVisEta); + hEFVisEta[iCutLevel] = new TH1F(*hMCVisEta); + hL1EtaEff[iCutLevel] = new TH1F(*hMCVisEta); + hL2EtaEff[iCutLevel] = new TH1F(*hMCVisEta); + hEFEtaEff[iCutLevel] = new TH1F(*hMCVisEta); + hL1EtaEff[iCutLevel]->Sumw2(); + hL2EtaEff[iCutLevel]->Sumw2(); + hEFEtaEff[iCutLevel]->Sumw2(); + } + + TrigTauBugFix bugfix (TrigTauBugFix::TTP9, TrigTauBugFix::RDO); + if (debug) cout << "Looping over all events" << endl; + int nev = int(chain->GetEntries()); + //if ( nev > 100 ) nev = 100; + for(int iev = 0; iev<nev; ++iev) { + analyzeEvent( iev ); + } +} + +void TTPValLevelCut::analyzeEvent(int eventNumber) { + + event->reset(); + chain->GetEvent(eventNumber); + bugfix.fix(event); + + analyzer.analyze(event, signal, offlineType); + + nEvent++; + nTrue += analyzer.truthList.nMCTauPure(); + nGood += analyzer.truthList.nMCTauGood(); + + nTau = analyzer.truthList.nMCTauGood(); + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + nMatch[iCutLevel]=0; + nL1passed[iCutLevel]=0; + nL2passed[iCutLevel]=0; + nEFpassed[iCutLevel]=0; + } + + for(unsigned int itau = 0; itau < nTau; ++itau ) { + + const TrigTauMCTau* tau = &analyzer.truthList.mcTauGoodEntry(itau); + + float visPt = tau->visible().Pt()/1000.; + float visEta = tau->visible().Eta(); + if (debug) cout << "True visible Pt and Eta found" << endl; + + // Fill denominator with all good taus + hMC_InVisPt->Fill(visPt); + hMC_InVisEta->Fill(visEta); + if (debug) cout << "hMC_InVisPt filled" << endl; + nMatched++; + if (debug) cout << "Now filling hMcVisPt..." << endl; + hMCVisPt->Fill(visPt); + hMCVisEta->Fill(visEta); + + if (debug) cout << "Looping over all CutLevels...." << endl; + for(unsigned int iCutLevel = 0; iCutLevel<nCutLevels; iCutLevel++) { + + // Select the new menu + selmanager.setTauMenu(menu, theCutLevel[iCutLevel]); + + // Refill the selected chain list based on the new menu + analyzer.chainList.fillTriggerList(selmanager); + + // Find a matching L1 object + const TrigTauL1Object* l1Tau = analyzer.chainList.getL1Tau(*tau); + if (l1Tau != 0) { + // Found a L1 trigger within dR range, fill numerator histograms + // with MC truth Pt and Eta + hL1VisPt[iCutLevel]->Fill(visPt); + hL1VisEta[iCutLevel]->Fill(visEta); + } + const TrigTauL2Object* l2Tau = analyzer.chainList.getL2Tau(*tau); + if (l2Tau != 0) { + hL2VisPt[iCutLevel]->Fill(visPt); + hL2VisEta[iCutLevel]->Fill(visEta); + } + + // Find a matching EF object + const TrigTauRecEFObject* efTau = analyzer.chainList.getEFTau(*tau); + if (efTau != 0) { + hEFVisPt[iCutLevel]->Fill(visPt); + hEFVisEta[iCutLevel]->Fill(visEta); + } + + } // End of loop over menus + } // End of loop over good taus in the event + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + + if(nMatch[iCutLevel]>0) n_OfflineMatchEvent[iCutLevel]++; + if(nL1passed[iCutLevel]>0) n_L1MatchEvent[iCutLevel]++; + if(nL2passed[iCutLevel]>0) n_L2MatchEvent[iCutLevel]++; + if(nEFpassed[iCutLevel]>0) n_EFMatchEvent[iCutLevel]++; + } +} + +void TTPValLevelCut::print() { + + gROOT->cd(); + + // Make ratios + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + hL1PtEff[iCutLevel]-> Divide(hL1VisPt[iCutLevel], hMCVisPt, 1., 1., "B"); + hL2PtEff[iCutLevel]-> Divide(hL2VisPt[iCutLevel], hMCVisPt, 1., 1., "B"); + hEFPtEff[iCutLevel]-> Divide(hEFVisPt[iCutLevel], hMCVisPt, 1., 1., "B"); + + hL1EtaEff[iCutLevel]-> Divide(hL1VisEta[iCutLevel], hMCVisEta, 1., 1., "B"); + hL2EtaEff[iCutLevel]-> Divide(hL2VisEta[iCutLevel], hMCVisEta, 1., 1., "B"); + hEFEtaEff[iCutLevel]-> Divide(hEFVisEta[iCutLevel], hMCVisEta, 1., 1., "B"); + + } + TString plotfile = "effMultiPlots"; + //plotfile += append; + + // Titles + for(unsigned int i=0; i<nCutLevels; i++){ + TrigTauFlags test; + hL1PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[i]->GetYaxis()->SetTitle("L1 efficiency_"+ test.menuName(menu)); + hL2PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[i]->GetYaxis()->SetTitle("L2 efficiency_"+ test.menuName(menu)); + hEFPtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[i]->GetYaxis()->SetTitle("EF Efficiency_+ test.menuName(menu)"); + } + + hL1EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hL1EtaEff[0]->GetYaxis()->SetTitle("L1 Efficiency"); + hL2EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hL2EtaEff[0]->GetYaxis()->SetTitle("L2 Efficiency"); + hEFEtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hEFEtaEff[0]->GetYaxis()->SetTitle("Efficiency"); + + //gStyle->SetHistLineWidth(2); + gStyle->SetCanvasColor(0); + + TCanvas * c4 = (TCanvas *) gROOT->Get("c4"); + if( c4 ) delete c4; + c4 = new TCanvas("c4","EF Selected",10,10,800,620); + c4->cd(); + gStyle->SetHistLineColor(1); + TLegend *l = new TLegend(0.75,0.2,0.9,0.5); + l->SetFillStyle(0); + + //commented out, since it's done later for all histos + // int id = 2; +// gStyle->SetHistLineColor(color[id]); +// gStyle->SetMarkerStyle(style[id]); +// gStyle->SetMarkerColor(color[id]); +// gStyle->SetLineColor(color[id]); +// gStyle->SetFillColor(0); +// hEFPtEff[id]->SetLineColor(color[id]); +// hEFPtEff[id]->UseCurrentStyle(); +// hEFPtEff[id]->SetMaximum(1.05); +// hEFPtEff[id]->Draw("P"); + + + + //l->AddEntry(hEFPtEff[id],test[id],"p"); + + // TLegend *l = new TLegend(0.13,0.65,0.25,0.85); + //l->SetFillStyle(0); + //hEFPtEff[2]->UseCurrentStyle(); + //hEFPtEff[2]->Draw("P"); + //l->AddEntry(hEFPtEff[2],"tau20i","p"); + + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + gStyle->SetHistLineColor(color[iCutLevel]); + //if(iCutLevel==3 || iCutLevel==5) continue; + //if (iCutLevel==2) continue; + + gStyle->SetMarkerColor(color[iCutLevel]); + gStyle->SetMarkerStyle(style[iCutLevel]); + gStyle->SetLineColor(color[iCutLevel]); + hEFPtEff[iCutLevel]->SetLineColor(color[iCutLevel]); + hEFPtEff[iCutLevel]->UseCurrentStyle(); + hEFPtEff[iCutLevel]->SetMaximum(1.05); + if (iCutLevel==0) hEFPtEff[iCutLevel]->Draw("P"); + else hEFPtEff[iCutLevel]->Draw("PSAME"); + + l->AddEntry(hEFPtEff[iCutLevel],test[iCutLevel],"p"); + + //gStyle->SetMarkerStyle(style[iCutLevel]); + //gStyle->SetMarkerColor(color[iCutLevel]); + //hEFPtEff[iCutLevel]->UseCurrentStyle(); + //hEFPtEff[iCutLevel]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iCutLevel],test[iCutLevel],"p"); + } + l->Draw("SAME"); + ATLAS_LABEL(0.15,0.85); + + + + + + for(unsigned int iCutLevel = 0; iCutLevel<nCutLevels; iCutLevel++) { + // Select the new menu + cout << endl << "Menu selection " << iCutLevel << endl << endl; + selmanager.setTauMenu(menu, theCutLevel[iCutLevel]); + selmanager.print(); + } + + for(unsigned int iCutLevel = 0; iCutLevel<nCutLevels; iCutLevel++) { + + cout<< "n_L1MatchEvent[iCutLevel] "<<n_L1MatchEvent[iCutLevel]<<endl; + cout<< "n_OfflineMatchEvent[iCutLevel] "<<n_OfflineMatchEvent[iCutLevel]<<endl; + + cout << " L1 efficiency menu "<<iCutLevel<<" is "<< ((float)n_L1MatchEvent[iCutLevel])/((float)n_OfflineMatchEvent[iCutLevel]) <<endl; + cout << " L2 efficiency menu "<<iCutLevel<<" is "<< ((float)n_L2MatchEvent[iCutLevel])/((float)n_OfflineMatchEvent[iCutLevel]) <<endl; + cout << " EF efficiency menu "<<iCutLevel<<" is "<< ((float)n_EFMatchEvent[iCutLevel])/((float)n_OfflineMatchEvent[iCutLevel]) <<endl; + } + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + cout << "True Taus: " << nTrue << endl; + cout << "Good Taus: " << nGood << endl; + cout << "Matched Taus: " << nMatched << " -> " + << float(nMatched)/nEvent << " Matched/Ev" << endl; + +} + +void TTPValLevelCut::printCSC(TPostScript & ps) { + + gROOT->cd(); + + // Make ratios + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + hL1PtEff[iCutLevel]-> Divide(hL1VisPt[iCutLevel], hMCVisPt, 1., 1., "B"); + hL2PtEff[iCutLevel]-> Divide(hL2VisPt[iCutLevel], hMCVisPt, 1., 1., "B"); + hEFPtEff[iCutLevel]-> Divide(hEFVisPt[iCutLevel], hMCVisPt, 1., 1., "B"); + + } + TString plotfile = "effMultiPlots"; + + // Titles + for(unsigned int i=0; i<nCutLevels; i++){ + TrigTauFlags test; + hL1PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[i]->GetYaxis()->SetTitle("L1 efficiency_"+ test.menuName(menu)); + hL2PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[i]->GetYaxis()->SetTitle("L2 efficiency_"+ test.menuName(menu)); + hEFPtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[i]->GetYaxis()->SetTitle("EF Efficiency_"+ test.menuName(menu)); + } + + //gStyle->SetHistLineWidth(2); + gStyle->SetCanvasColor(0); + + TCanvas * c1 = (TCanvas *) gROOT->Get("c4"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","EF Selected",10,10,800,620); + c1->cd(); + gStyle->SetHistLineColor(1); + TLegend *l = new TLegend(0.75,0.2,0.9,0.5); + l->SetFillStyle(0); + + ps.On(); + + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + gStyle->SetHistLineColor(color[iCutLevel]); + gStyle->SetMarkerColor(color[iCutLevel]); + gStyle->SetMarkerStyle(style[iCutLevel]); + gStyle->SetLineColor(color[iCutLevel]); + hL1PtEff[iCutLevel]->SetLineColor(color[iCutLevel]); + hL1PtEff[iCutLevel]->UseCurrentStyle(); + hL1PtEff[iCutLevel]->SetMaximum(1.05); + if (iCutLevel==0) hL1PtEff[iCutLevel]->Draw("P"); + else hL1PtEff[iCutLevel]->Draw("PSAME"); + l->AddEntry(hL1PtEff[iCutLevel],test[iCutLevel],"p"); + } + l->Draw(); + ATLAS_LABEL(0.15,0.85); + c1->Update(); + + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + gStyle->SetHistLineColor(color[iCutLevel]); + gStyle->SetMarkerColor(color[iCutLevel]); + gStyle->SetMarkerStyle(style[iCutLevel]); + gStyle->SetLineColor(color[iCutLevel]); + hL2PtEff[iCutLevel]->SetLineColor(color[iCutLevel]); + hL2PtEff[iCutLevel]->UseCurrentStyle(); + hL2PtEff[iCutLevel]->SetMaximum(1.05); + if (iCutLevel==0) hL2PtEff[iCutLevel]->Draw("P"); + else hL2PtEff[iCutLevel]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iCutLevel],test[iCutLevel],"p"); + } + l->Draw(); + ATLAS_LABEL(0.15,0.85); + c1->Update(); + + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + gStyle->SetHistLineColor(color[iCutLevel]); + gStyle->SetMarkerColor(color[iCutLevel]); + gStyle->SetMarkerStyle(style[iCutLevel]); + gStyle->SetLineColor(color[iCutLevel]); + hEFPtEff[iCutLevel]->SetLineColor(color[iCutLevel]); + hEFPtEff[iCutLevel]->UseCurrentStyle(); + hEFPtEff[iCutLevel]->SetMaximum(1.05); + if (iCutLevel==0) hEFPtEff[iCutLevel]->Draw("P"); + else hEFPtEff[iCutLevel]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iCutLevel],test[iCutLevel],"p"); + } + l->Draw(); + ATLAS_LABEL(0.15,0.85); + c1->Update(); + + for(unsigned int iCutLevel = 0; iCutLevel<nCutLevels; iCutLevel++) { + // Select the new menu + cout << endl << "Menu selection " << iCutLevel << endl << endl; + selmanager.setTauMenu(menu, theCutLevel[iCutLevel]); + selmanager.print(); + } + + for(unsigned int iCutLevel = 0; iCutLevel<nCutLevels; iCutLevel++) { + + cout<< "n_L1MatchEvent[iCutLevel] "<<n_L1MatchEvent[iCutLevel]<<endl; + cout<< "n_OfflineMatchEvent[iCutLevel] "<<n_OfflineMatchEvent[iCutLevel]<<endl; + + cout << " L1 efficiency menu "<<iCutLevel<<" is "<< ((float)n_L1MatchEvent[iCutLevel])/((float)n_OfflineMatchEvent[iCutLevel]) <<endl; + cout << " L2 efficiency menu "<<iCutLevel<<" is "<< ((float)n_L2MatchEvent[iCutLevel])/((float)n_OfflineMatchEvent[iCutLevel]) <<endl; + cout << " EF efficiency menu "<<iCutLevel<<" is "<< ((float)n_EFMatchEvent[iCutLevel])/((float)n_OfflineMatchEvent[iCutLevel]) <<endl; + + ps.Off(); + + } + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + cout << "True Taus: " << nTrue << endl; + cout << "Good Taus: " << nGood << endl; + cout << "Matched Taus: " << nMatched << " -> " + << float(nMatched)/nEvent << " Matched/Ev" << endl; + +} + + +void TTPValLevelCut::update(TString name) { + + TFile f(name, "update"); + + f.cd(); + f.mkdir("MultiPlots"); + f.cd("MultiPlots"); + + + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + hL1PtEff[iCutLevel]-> Divide(hL1VisPt[iCutLevel], hMCVisPt, 1., 1., "B"); + hL2PtEff[iCutLevel]-> Divide(hL2VisPt[iCutLevel], hMCVisPt, 1., 1., "B"); + hEFPtEff[iCutLevel]-> Divide(hEFVisPt[iCutLevel], hMCVisPt, 1., 1., "B"); + } + + // Titles + for(unsigned int i=0; i<nCutLevels; i++){ + TrigTauFlags test; + hL1PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[i]->GetYaxis()->SetTitle("L1 efficiencyI_"+ test.menuName(menu)); + hL2PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[i]->GetYaxis()->SetTitle("L2 efficiency_"+ test.menuName(menu)); + hEFPtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[i]->GetYaxis()->SetTitle("EF Efficiency_"+ test.menuName(menu)); + } + + for (unsigned int iCutLevel=0; iCutLevel<nCutLevels; iCutLevel++) { + + gStyle->SetHistLineColor(color[iCutLevel]); + gStyle->SetMarkerColor(color[iCutLevel]); + gStyle->SetMarkerStyle(style[iCutLevel]); + gStyle->SetLineColor(color[iCutLevel]); + hL1PtEff[iCutLevel]->SetLineColor(color[iCutLevel]); + hL1PtEff[iCutLevel]->UseCurrentStyle(); + hL1PtEff[iCutLevel]->SetMaximum(1.05); + //l->AddEntry(hEFPtEff[iCutLevel],test[iCutLevel],"p"); + + hL2PtEff[iCutLevel]->SetLineColor(color[iCutLevel]); + hL2PtEff[iCutLevel]->UseCurrentStyle(); + hL2PtEff[iCutLevel]->SetMaximum(1.05); + + hEFPtEff[iCutLevel]->SetLineColor(color[iCutLevel]); + hEFPtEff[iCutLevel]->UseCurrentStyle(); + hEFPtEff[iCutLevel]->SetMaximum(1.05); + + + TrigTauFlags test; + hL1PtEff[iCutLevel]->SetName("TTPVAlMultiPlots_" + test.menuName(menu)+"_L1"); //eventually replace menu with cutLevel + hL1PtEff[iCutLevel]->Write(); + hL2PtEff[iCutLevel]->SetName("TTPVAlMultiPlots_" + test.menuName(menu)+"_L2"); + hL2PtEff[iCutLevel]->Write(); + hEFPtEff[iCutLevel]->SetName("TTPVAlMultiPlots_" + test.menuName(menu)+"_EF"); + hEFPtEff[iCutLevel]->Write(); + } + f.Close(); +} + + +void TTPValLevelCut::ATLAS_LABEL(Double_t x,Double_t y,Color_t color) { + + TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize); + l.SetNDC(); + l.SetTextFont(72); + l.SetTextColor(color); + l.DrawLatex(x,y,"ATLAS"); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValMultiPlots.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValMultiPlots.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1f517e0f5a4f489d5da85673ecc708d2dbc52af0 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValMultiPlots.cxx @@ -0,0 +1,596 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +using namespace std; +#include "TrigTauPerformValidation/TTPValMultiPlots.h" + + +TTPValMultiPlots::TTPValMultiPlots ( TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1 ) + : bugfix(version, poolfile) { + + initialize(debug1); + fileDefined = false; + return; +} + +TTPValMultiPlots::TTPValMultiPlots (TString filename1, TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version, poolfile) { + + filename = filename1; + chain = new TChain("eventTree"); + chain->Add(filename); + initialize(debug1); + fileDefined = true; + return; +} + +void TTPValMultiPlots::initialize(bool debug1) { + + debug = debug1; + signal = true; + nprong = 0; + maxVisEta = 2.5; + minLeadingPt = 6.0; + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + menu = TrigTauFlags::TAU16; + cutLevel = TrigTauSelectionManager::LOOSE; + offlineType = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + menuVersion = TrigTauSelectionManager::MENU1560; + chainType = TrigTauFlags::SITRK; + + nEvent = 0; + nTrue = 0; + nGood = 0; + nMatched = 0; + + npt =50; + minpt = 0; + maxpt = 120; + + color[0] = 51; + color[1] = 8; + color[2] = 60; + color[3] = 96; + color[4] = 66; + color[5] = 100; + color[6] = 84; + + style[0] = 20; + style[1] = 26; + style[2] = 21; + style[3] = 24; + style[4] = 23; + style[5] = 25; + style[6] = 22; + + +} + +void TTPValMultiPlots::setFile(TString filename1) { + filename = filename1; + chain = new TChain("eventTree"); //potential memory leak + chain->Add(filename); + if (debug) cout << "file " << filename << " added. " << endl; + fileDefined = true; + return; +} + +void TTPValMultiPlots::analyze() { + + if (!fileDefined) { + cout << "File was not defined and variables not initialized!!" << endl; + return; + } + + selmanager.setMenuVersion(menuVersion); + //selmanager.setTauMenu(menu, cutLevel ); + selmanager.setL1MET(0.); + + // MC truth + analyzer.truthList.setMaxVisEta(maxVisEta); + //analyzer.truthList.setMinVisPt(menu); // in GeV + //analyzer.truthList.setMinLeadingPt(minLeadingPt); // pt of the leading pt of track is + if( nprong == 1 ) analyzer.truthList.select1Prong(); + else if( nprong == 3 ) analyzer.truthList.select3Prong(); + //analyzer.truthList.setRecoMatchdR(0.2); + + event = new TrigTauEvent(); + chain->SetBranchAddress("EventBranch", &event); + chain->SetBranchStatus("*", 1); + + // Also set an L1 MET cut if desired + analyzer.trigMan.setL1MET(0.); + analyzer.trigMan.setMenuVersion(menuVersion); + analyzer.trigMan.setTauMenu(menu, cutLevel); + analyzer.chainList.setRoiWordMatching(false); + analyzer.chainList.setHLTAuthor(chainType); + + gROOT->cd(); + gROOT->SetStyle("ATLAS"); + gROOT->ForceStyle(); + + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); + gROOT->cd(); + + theMenu[0] = TrigTauFlags::TAU12; + theMenu[1] = TrigTauFlags::TAU16; + theMenu[2] = TrigTauFlags::TAU20; + theMenu[3] = TrigTauFlags::TAU29; + theMenu[4] = TrigTauFlags::TAU38; + theMenu[5] = TrigTauFlags::TAU50; + theMenu[6] = TrigTauFlags::TAU84; + //theMenu[3] = TrigTauFlags::TAU125; + + for(unsigned int im = 0; im < nMenus; ++im ) + test[im] = TrigTauFlags::menuName(theMenu[im]); + + + + hMC_InVisPt = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + hMCVisPt = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + + hntrak = new TH1F("","",20,0.,10.); + + hMC_InVisEta = new TH1F("", "", 31, -3.1, 3.1); + hMCVisEta = new TH1F("", "", 31, -3.1, 3.1); + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + nMatch[iMenu]=0; + nL1passed[iMenu]=0; + nL2passed[iMenu]=0; + nEFpassed[iMenu]=0; + n_OfflineMatchEvent[iMenu]=0; + n_L1MatchEvent[iMenu]=0; + n_L2MatchEvent[iMenu]=0; + n_EFMatchEvent[iMenu]=0; + + hEFnTracks[iMenu] = new TH1F(*hntrak); + hL1VisPt[iMenu] = new TH1F(*hMCVisPt); + hL2VisPt[iMenu] = new TH1F(*hMCVisPt); + hEFVisPt[iMenu] = new TH1F(*hMCVisPt); + hL1PtEff[iMenu] = new TH1F(*hMCVisPt); + hL2PtEff[iMenu] = new TH1F(*hMCVisPt); + hEFPtEff[iMenu] = new TH1F(*hMCVisPt); + hL21PtEff[iMenu] = new TH1F(*hMCVisPt); + hEFL2PtEff[iMenu] = new TH1F(*hMCVisPt); + hL1PtEff[iMenu]->Sumw2(); + hL2PtEff[iMenu]->Sumw2(); + hEFPtEff[iMenu]->Sumw2(); + hL21PtEff[iMenu]->Sumw2(); + hEFL2PtEff[iMenu]->Sumw2(); + + hL1VisEta[iMenu] = new TH1F(*hMCVisEta); + hL2VisEta[iMenu] = new TH1F(*hMCVisEta); + hEFVisEta[iMenu] = new TH1F(*hMCVisEta); + hL1EtaEff[iMenu] = new TH1F(*hMCVisEta); + hL2EtaEff[iMenu] = new TH1F(*hMCVisEta); + hEFEtaEff[iMenu] = new TH1F(*hMCVisEta); + hL21EtaEff[iMenu] = new TH1F(*hMCVisEta); + hEFL2EtaEff[iMenu] = new TH1F(*hMCVisEta); + hL1EtaEff[iMenu]->Sumw2(); + hL2EtaEff[iMenu]->Sumw2(); + hEFEtaEff[iMenu]->Sumw2(); + hL21EtaEff[iMenu]->Sumw2(); + hEFL2EtaEff[iMenu]->Sumw2(); + } + + TrigTauBugFix bugfix (TrigTauBugFix::TTP9, TrigTauBugFix::RDO); + if (debug) cout << "Looping over all events" << endl; + int nev = int(chain->GetEntries()); + //if ( nev > 100 ) nev = 100; + for(int iev = 0; iev<nev; ++iev) { + analyzeEvent( iev ); + } +} + +void TTPValMultiPlots::analyzeEvent(int eventNumber) { + + event->reset(); + chain->GetEvent(eventNumber); + bugfix.fix(event); + + analyzer.analyze(event, signal, offlineType); + + nEvent++; + nTrue += analyzer.truthList.nMCTauPure(); + nGood += analyzer.truthList.nMCTauGood(); + + nTau = analyzer.truthList.nMCTauGood(); + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + nMatch[iMenu]=0; + nL1passed[iMenu]=0; + nL2passed[iMenu]=0; + nEFpassed[iMenu]=0; + } + + for(unsigned int itau = 0; itau < nTau; ++itau ) { + + const TrigTauMCTau* tau = &analyzer.truthList.mcTauGoodEntry(itau); + + float visPt = tau->visible().Pt()/1000.; + float visEta = tau->visible().Eta(); + if (debug) cout << "True visible Pt and Eta found" << endl; + + // Fill denominator with all good taus + hMC_InVisPt->Fill(visPt); + hMC_InVisEta->Fill(visEta); + if (debug) cout << "hMC_InVisPt filled" << endl; + nMatched++; + if (debug) cout << "Now filling hMcVisPt..." << endl; + hMCVisPt->Fill(visPt); + hMCVisEta->Fill(visEta); + + if (debug) cout << "Looping over all Menus...." << endl; + for(unsigned int iMenu = 0; iMenu<nMenus; iMenu++) { + + if(visPt> Threshold[iMenu]) nMatch[iMenu]++; + + // Select the new menu + selmanager.setTauMenu(theMenu[iMenu], cutLevel); + + // Refill the selected chain list based on the new menu + analyzer.chainList.fillTriggerList(selmanager); + + // Find a matching L1 object + const TrigTauL1Object* l1Tau = analyzer.chainList.getL1Tau(*tau); + if (l1Tau != 0) { + // Found a L1 trigger within dR range, fill numerator histograms + // with MC truth Pt and Eta + hL1VisPt[iMenu]->Fill(visPt); + hL1VisEta[iMenu]->Fill(visEta); + if(visPt> Threshold[iMenu]) nL1passed[iMenu]++; + } + const TrigTauL2Object* l2Tau = analyzer.chainList.getL2Tau(*tau); + if (l2Tau != 0) { + hL2VisPt[iMenu]->Fill(visPt); + hL2VisEta[iMenu]->Fill(visEta); + if(visPt> Threshold[iMenu]) nL2passed[iMenu]++; + } + + // Find a matching EF object + const TrigTauRecEFObject* efTau = analyzer.chainList.getEFTau(*tau); + if (efTau != 0) { + hEFVisPt[iMenu]->Fill(visPt); + hEFVisEta[iMenu]->Fill(visEta); + if(visPt> Threshold[iMenu]) nEFpassed[iMenu]++; + if(visPt> Threshold[iMenu]) hEFnTracks[iMenu]->Fill(efTau->nTracks()); + } + + } // End of loop over menus + } // End of loop over good taus in the event + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + + if(nMatch[iMenu]>0) n_OfflineMatchEvent[iMenu]++; + if(nL1passed[iMenu]>0) n_L1MatchEvent[iMenu]++; + if(nL2passed[iMenu]>0) n_L2MatchEvent[iMenu]++; + if(nEFpassed[iMenu]>0) n_EFMatchEvent[iMenu]++; + } +} + +void TTPValMultiPlots::print() { + + gROOT->cd(); + + // Make ratios + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + hL1PtEff[iMenu]-> Divide(hL1VisPt[iMenu], hMCVisPt, 1., 1., "B"); + hL2PtEff[iMenu]-> Divide(hL2VisPt[iMenu], hMCVisPt, 1., 1., "B"); + hEFPtEff[iMenu]-> Divide(hEFVisPt[iMenu], hMCVisPt, 1., 1., "B"); + + hL21PtEff[iMenu]-> Divide(hL2VisPt[iMenu], hL1VisPt[iMenu], 1., 1., "B"); + hEFL2PtEff[iMenu]-> Divide(hEFVisPt[iMenu], hL2VisPt[iMenu], 1., 1.,"B"); + + hL1EtaEff[iMenu]-> Divide(hL1VisEta[iMenu], hMCVisEta, 1., 1., "B"); + hL2EtaEff[iMenu]-> Divide(hL2VisEta[iMenu], hMCVisEta, 1., 1., "B"); + hEFEtaEff[iMenu]-> Divide(hEFVisEta[iMenu], hMCVisEta, 1., 1., "B"); + + hL21EtaEff[iMenu]->Divide(hL2VisEta[iMenu], hL1VisEta[iMenu], 1., 1., "B"); + hEFL2EtaEff[iMenu]->Divide(hEFVisEta[iMenu], hL2VisEta[iMenu], 1., 1., "B"); + } + TString plotfile = "effMultiPlots"; + //plotfile += append; + + // Titles + for(unsigned int i=0; i<nMenus; i++){ + hL1PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[i]->GetYaxis()->SetTitle("L1 efficiency"); + hL2PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[i]->GetYaxis()->SetTitle("L2 efficiency"); + hEFPtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[i]->GetYaxis()->SetTitle("Efficiency"); + } + + hL21PtEff[0]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL21PtEff[0]->GetYaxis()->SetTitle("L2/L1 efficiency"); + hEFL2PtEff[0]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFL2PtEff[0]->GetYaxis()->SetTitle("EF/L2 efficiency"); + + hL1EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hL1EtaEff[0]->GetYaxis()->SetTitle("L1 Efficiency"); + hL2EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hL2EtaEff[0]->GetYaxis()->SetTitle("L2 Efficiency"); + hEFEtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hEFEtaEff[0]->GetYaxis()->SetTitle("Efficiency"); + + hL21EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hL21EtaEff[0]->GetYaxis()->SetTitle("L2/L1 Efficiency"); + hEFL2EtaEff[0]->GetXaxis()->SetTitle("True Visible Eta"); + hEFL2EtaEff[0]->GetYaxis()->SetTitle("EF/L2 Efficiency"); + + + + + //gStyle->SetHistLineWidth(2); + gStyle->SetCanvasColor(0); + + TCanvas * c4 = (TCanvas *) gROOT->Get("c4"); + if( c4 ) delete c4; + c4 = new TCanvas("c4","EF Selected",10,10,800,620); + c4->cd(); + gStyle->SetHistLineColor(1); + TLegend *l = new TLegend(0.75,0.2,0.9,0.5); + l->SetFillStyle(0); + + //commented out, since it's done later for all histos + // int id = 2; +// gStyle->SetHistLineColor(color[id]); +// gStyle->SetMarkerStyle(style[id]); +// gStyle->SetMarkerColor(color[id]); +// gStyle->SetLineColor(color[id]); +// gStyle->SetFillColor(0); +// hEFPtEff[id]->SetLineColor(color[id]); +// hEFPtEff[id]->UseCurrentStyle(); +// hEFPtEff[id]->SetMaximum(1.05); +// hEFPtEff[id]->Draw("P"); + + + + //l->AddEntry(hEFPtEff[id],test[id],"p"); + + // TLegend *l = new TLegend(0.13,0.65,0.25,0.85); + //l->SetFillStyle(0); + //hEFPtEff[2]->UseCurrentStyle(); + //hEFPtEff[2]->Draw("P"); + //l->AddEntry(hEFPtEff[2],"tau20i","p"); + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + gStyle->SetHistLineColor(color[iMenu]); + //if(iMenu==3 || iMenu==5) continue; + //if (iMenu==2) continue; + + gStyle->SetMarkerColor(color[iMenu]); + gStyle->SetMarkerStyle(style[iMenu]); + gStyle->SetLineColor(color[iMenu]); + hEFPtEff[iMenu]->SetLineColor(color[iMenu]); + hEFPtEff[iMenu]->UseCurrentStyle(); + hEFPtEff[iMenu]->SetMaximum(1.05); + if (iMenu==0) hEFPtEff[iMenu]->Draw("P"); + else hEFPtEff[iMenu]->Draw("PSAME"); + + l->AddEntry(hEFPtEff[iMenu],test[iMenu],"p"); + + //gStyle->SetMarkerStyle(style[iMenu]); + //gStyle->SetMarkerColor(color[iMenu]); + //hEFPtEff[iMenu]->UseCurrentStyle(); + //hEFPtEff[iMenu]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iMenu],test[iMenu],"p"); + } + l->Draw("SAME"); + ATLAS_LABEL(0.15,0.85); + + + + + + for(unsigned int iMenu = 0; iMenu<nMenus; iMenu++) { + // Select the new menu + cout << endl << "Menu selection " << iMenu << endl << endl; + selmanager.setTauMenu(theMenu[iMenu], cutLevel); + selmanager.print(); + } + + for(unsigned int iMenu = 0; iMenu<nMenus; iMenu++) { + + cout<< "n_L1MatchEvent[iMenu] "<<n_L1MatchEvent[iMenu]<<endl; + cout<< "n_OfflineMatchEvent[iMenu] "<<n_OfflineMatchEvent[iMenu]<<endl; + + cout << " L1 efficiency menu "<<iMenu<<" is "<< ((float)n_L1MatchEvent[iMenu])/((float)n_OfflineMatchEvent[iMenu]) <<endl; + cout << " L2 efficiency menu "<<iMenu<<" is "<< ((float)n_L2MatchEvent[iMenu])/((float)n_OfflineMatchEvent[iMenu]) <<endl; + cout << " EF efficiency menu "<<iMenu<<" is "<< ((float)n_EFMatchEvent[iMenu])/((float)n_OfflineMatchEvent[iMenu]) <<endl; + } + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + cout << "True Taus: " << nTrue << endl; + cout << "Good Taus: " << nGood << endl; + cout << "Matched Taus: " << nMatched << " -> " + << float(nMatched)/nEvent << " Matched/Ev" << endl; + +} + +void TTPValMultiPlots::printCSC(TPostScript & ps) { + + gROOT->cd(); + + // Make ratios + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + hL1PtEff[iMenu]-> Divide(hL1VisPt[iMenu], hMCVisPt, 1., 1., "B"); + hL2PtEff[iMenu]-> Divide(hL2VisPt[iMenu], hMCVisPt, 1., 1., "B"); + hEFPtEff[iMenu]-> Divide(hEFVisPt[iMenu], hMCVisPt, 1., 1., "B"); + + hL21PtEff[iMenu]-> Divide(hL2VisPt[iMenu], hL1VisPt[iMenu], 1., 1., "B"); + hEFL2PtEff[iMenu]-> Divide(hEFVisPt[iMenu], hL2VisPt[iMenu], 1., 1.,"B"); + } + TString plotfile = "effMultiPlots"; + + // Titles + for(unsigned int i=0; i<nMenus; i++){ + hL1PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[i]->GetYaxis()->SetTitle("L1 efficiency"); + hL2PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[i]->GetYaxis()->SetTitle("L2 efficiency"); + hEFPtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[i]->GetYaxis()->SetTitle("EF Efficiency"); + } + + //gStyle->SetHistLineWidth(2); + gStyle->SetCanvasColor(0); + + TCanvas * c1 = (TCanvas *) gROOT->Get("c4"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","EF Selected",10,10,800,620); + c1->cd(); + gStyle->SetHistLineColor(1); + TLegend *l = new TLegend(0.75,0.2,0.9,0.5); + l->SetFillStyle(0); + + ps.On(); + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + gStyle->SetHistLineColor(color[iMenu]); + gStyle->SetMarkerColor(color[iMenu]); + gStyle->SetMarkerStyle(style[iMenu]); + gStyle->SetLineColor(color[iMenu]); + hL1PtEff[iMenu]->SetLineColor(color[iMenu]); + hL1PtEff[iMenu]->UseCurrentStyle(); + hL1PtEff[iMenu]->SetMaximum(1.05); + if (iMenu==0) hL1PtEff[iMenu]->Draw("P"); + else hL1PtEff[iMenu]->Draw("PSAME"); + l->AddEntry(hL1PtEff[iMenu],test[iMenu],"p"); + } + l->Draw(); + ATLAS_LABEL(0.15,0.85); + c1->Update(); + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + gStyle->SetHistLineColor(color[iMenu]); + gStyle->SetMarkerColor(color[iMenu]); + gStyle->SetMarkerStyle(style[iMenu]); + gStyle->SetLineColor(color[iMenu]); + hL2PtEff[iMenu]->SetLineColor(color[iMenu]); + hL2PtEff[iMenu]->UseCurrentStyle(); + hL2PtEff[iMenu]->SetMaximum(1.05); + if (iMenu==0) hL2PtEff[iMenu]->Draw("P"); + else hL2PtEff[iMenu]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iMenu],test[iMenu],"p"); + } + l->Draw(); + ATLAS_LABEL(0.15,0.85); + c1->Update(); + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + gStyle->SetHistLineColor(color[iMenu]); + gStyle->SetMarkerColor(color[iMenu]); + gStyle->SetMarkerStyle(style[iMenu]); + gStyle->SetLineColor(color[iMenu]); + hEFPtEff[iMenu]->SetLineColor(color[iMenu]); + hEFPtEff[iMenu]->UseCurrentStyle(); + hEFPtEff[iMenu]->SetMaximum(1.05); + if (iMenu==0) hEFPtEff[iMenu]->Draw("P"); + else hEFPtEff[iMenu]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iMenu],test[iMenu],"p"); + } + l->Draw(); + ATLAS_LABEL(0.15,0.85); + c1->Update(); + + for(unsigned int iMenu = 0; iMenu<nMenus; iMenu++) { + // Select the new menu + cout << endl << "Menu selection " << iMenu << endl << endl; + selmanager.setTauMenu(theMenu[iMenu], cutLevel); + selmanager.print(); + } + + for(unsigned int iMenu = 0; iMenu<nMenus; iMenu++) { + + cout<< "n_L1MatchEvent[iMenu] "<<n_L1MatchEvent[iMenu]<<endl; + cout<< "n_OfflineMatchEvent[iMenu] "<<n_OfflineMatchEvent[iMenu]<<endl; + + cout << " L1 efficiency menu "<<iMenu<<" is "<< ((float)n_L1MatchEvent[iMenu])/((float)n_OfflineMatchEvent[iMenu]) <<endl; + cout << " L2 efficiency menu "<<iMenu<<" is "<< ((float)n_L2MatchEvent[iMenu])/((float)n_OfflineMatchEvent[iMenu]) <<endl; + cout << " EF efficiency menu "<<iMenu<<" is "<< ((float)n_EFMatchEvent[iMenu])/((float)n_OfflineMatchEvent[iMenu]) <<endl; + + ps.Off(); + + } + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + cout << "True Taus: " << nTrue << endl; + cout << "Good Taus: " << nGood << endl; + cout << "Matched Taus: " << nMatched << " -> " + << float(nMatched)/nEvent << " Matched/Ev" << endl; + +} + + +void TTPValMultiPlots::update(TString name) { + + TFile f(name, "update"); + + f.cd(); + f.mkdir("MultiPlots"); + f.cd("MultiPlots"); + + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + hL1PtEff[iMenu]-> Divide(hL1VisPt[iMenu], hMCVisPt, 1., 1., "B"); + hL2PtEff[iMenu]-> Divide(hL2VisPt[iMenu], hMCVisPt, 1., 1., "B"); + hEFPtEff[iMenu]-> Divide(hEFVisPt[iMenu], hMCVisPt, 1., 1., "B"); + } + + // Titles + for(unsigned int i=0; i<nMenus; i++){ + hL1PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[i]->GetYaxis()->SetTitle("L1 efficiency"); + hL2PtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[i]->GetYaxis()->SetTitle("L2 efficiency"); + hEFPtEff[i]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[i]->GetYaxis()->SetTitle("Efficiency"); + } + + for (unsigned int iMenu=0; iMenu<nMenus; iMenu++) { + + gStyle->SetHistLineColor(color[iMenu]); + gStyle->SetMarkerColor(color[iMenu]); + gStyle->SetMarkerStyle(style[iMenu]); + gStyle->SetLineColor(color[iMenu]); + hL1PtEff[iMenu]->SetLineColor(color[iMenu]); + hL1PtEff[iMenu]->UseCurrentStyle(); + hL1PtEff[iMenu]->SetMaximum(1.05); + //l->AddEntry(hEFPtEff[iMenu],test[iMenu],"p"); + + hL2PtEff[iMenu]->SetLineColor(color[iMenu]); + hL2PtEff[iMenu]->UseCurrentStyle(); + hL2PtEff[iMenu]->SetMaximum(1.05); + + hEFPtEff[iMenu]->SetLineColor(color[iMenu]); + hEFPtEff[iMenu]->UseCurrentStyle(); + hEFPtEff[iMenu]->SetMaximum(1.05); + + + TrigTauFlags test; + hL1PtEff[iMenu]->SetName("TTPVAlMultiPlots_" + test.menuName(theMenu[iMenu])+"_L1"); + hL1PtEff[iMenu]->Write(); + hL2PtEff[iMenu]->SetName("TTPVAlMultiPlots_" + test.menuName(theMenu[iMenu])+"_L2"); + hL2PtEff[iMenu]->Write(); + hEFPtEff[iMenu]->SetName("TTPVAlMultiPlots_" + test.menuName(theMenu[iMenu])+"_EF"); + hEFPtEff[iMenu]->Write(); + } + f.Close(); +} + + +void TTPValMultiPlots::ATLAS_LABEL(Double_t x,Double_t y,Color_t color) { + + TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize); + l.SetNDC(); + l.SetTextFont(72); + l.SetTextColor(color); + l.DrawLatex(x,y,"ATLAS Preliminary"); +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValOfflinePlots.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValOfflinePlots.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5fb7f4e9498b686f94f71c4ceabcbc64408b7612 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValOfflinePlots.cxx @@ -0,0 +1,616 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +using namespace std; +#include "TrigTauPerformValidation/TTPValOfflinePlots.h" + + +TTPValOfflinePlots::TTPValOfflinePlots ( TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1 ) + : bugfix(version, poolfile) { + + initialize(debug1); + fileDefined = false; + return; +} + +TTPValOfflinePlots::TTPValOfflinePlots (TString filename1, TrigTauBugFix::POOLFILE poolfile, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version, poolfile) { + + filename = filename1; + chain = new TChain("eventTree"); + chain->Add(filename); + initialize(debug1); + fileDefined = true; + if (debug) cout << "Finishing constructor..." << endl; + return; +} + +void TTPValOfflinePlots::initialize(bool debug1) { + + debug = debug1; + if (debug) cout << "Initializing variables..." << endl; + signal = true; + maxVisEta = 2.5; + minLeadingPt = 6.0; + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + menu = TrigTauFlags::TAU16; + cutLevel = TrigTauSelectionManager::LOOSE; + menuVersion = TrigTauSelectionManager::MENU1560; + chainType = TrigTauFlags::SITRK; + threshold = 5; + nEvent = 0; + + int i = 0; + + if (debug) cout << "Setting counters to zero..." << endl; + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + nTrue[iOffline][iNprong] = 0; + nGood[iOffline][iNprong] = 0; + nMatched[iOffline][iNprong] = 0; + ++i; + color[iOffline][iNprong] = i; + style[iOffline][iNprong] = 19+i; + } + + if (debug) cout << "Finishing initialization..." << endl; + + npt =40; + minpt = 0; + maxpt = 80; + + //color[0][0] = 1; + //color[0][1] = 2; + //color[1][0] = 60; + //color[1][1] = 96; + //color[2][0] = 66; + //color[2][1] = 100; + //color[6] = 84; + + //style[0][0] = 20; + //style[0][1] = 26; + //style[1][0] = 21; + //style[1][1] = 24; + //style[2][0] = 23; + //style[2][1] = 25; + //style[6] = 22; + + if (debug) cout << "Initialization finished... " << endl; +} + +void TTPValOfflinePlots::setFile(TString filename1) { + filename = filename1; + chain = new TChain("eventTree"); //potential memory leak + chain->Add(filename); + if (debug) cout << "file " << filename << " added. " << endl; + fileDefined = true; + return; +} + +void TTPValOfflinePlots::analyze() { + + if (!fileDefined) { + cout << "File was not defined and variables not initialized!!" << endl; + return; + } + + + selmanager.setMenuVersion(menuVersion); + //selmanager.setTauMenu(menu, cutLevel ); + selmanager.setL1MET(0.); + + event = new TrigTauEvent(); + chain->SetBranchAddress("EventBranch", &event); + chain->SetBranchStatus("*", 1); + + gROOT->cd(); + gROOT->SetStyle("ATLAS"); + gROOT->ForceStyle(); + + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); + gROOT->cd(); + + offlineType[0] = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + //offlineType[1] = TrigTauMCTauList::TAULLHMEDIUM; + //offlineType[2] = TrigTauMCTauList::EITHERTAU; + + nprong[0] = 1; + nprong[1] = 3; + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + + // MC truth + analyzer[iOffline][iNprong].truthList.setMaxVisEta(maxVisEta); + //analyzer[iOffline][iNprong].truthList.setMinVisPt(menu); // in GeV + analyzer[iOffline][iNprong].truthList.setMinLeadingPt(minLeadingPt); // pt of the leading pt of track is + //analyzer.truthList.setRecoMatchdR(0.2); + + // Also set an L1 MET cut if desired + analyzer[iOffline][iNprong].trigMan.setL1MET(0.); + analyzer[iOffline][iNprong].trigMan.setMenuVersion(menuVersion); + analyzer[iOffline][iNprong].trigMan.setTauMenu(menu, cutLevel); + analyzer[iOffline][iNprong].chainList.setRoiWordMatching(false); + analyzer[iOffline][iNprong].chainList.setHLTAuthor(chainType); + + hMC_InVisPt[iOffline][iNprong] = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + hMCVisPt[iOffline][iNprong] = new TH1F("", "", npt, minpt, maxpt); // MC visible (denominator) + + hMC_InVisEta[iOffline][iNprong] = new TH1F("", "", 31, -3.1, 3.1); + hMCVisEta[iOffline][iNprong] = new TH1F("", "", 31, -3.1, 3.1); + + nTrue[iOffline][iNprong]=0; + nGood[iOffline][iNprong]=0; + nMatch[iOffline][iNprong]=0; + nL1passed[iOffline][iNprong]=0; + nL2passed[iOffline][iNprong]=0; + nEFpassed[iOffline][iNprong]=0; + n_OfflineMatchEvent[iOffline][iNprong]=0; + n_L1MatchEvent[iOffline][iNprong]=0; + n_L2MatchEvent[iOffline][iNprong]=0; + n_EFMatchEvent[iOffline][iNprong]=0; + + // hEFnTracks[iOffline][iNprong] = new TH1F(*hntrak[iOffline][iNprong]); + hL1VisPt[iOffline][iNprong] = new TH1F(*hMCVisPt[iOffline][iNprong]); + hL2VisPt[iOffline][iNprong] = new TH1F(*hMCVisPt[iOffline][iNprong]); + hEFVisPt[iOffline][iNprong] = new TH1F(*hMCVisPt[iOffline][iNprong]); + hL1PtEff[iOffline][iNprong] = new TH1F(*hMCVisPt[iOffline][iNprong]); + hL2PtEff[iOffline][iNprong] = new TH1F(*hMCVisPt[iOffline][iNprong]); + hEFPtEff[iOffline][iNprong] = new TH1F(*hMCVisPt[iOffline][iNprong]); + hL21PtEff[iOffline][iNprong] = new TH1F(*hMCVisPt[iOffline][iNprong]); + hEFL2PtEff[iOffline][iNprong] = new TH1F(*hMCVisPt[iOffline][iNprong]); + hL1PtEff[iOffline][iNprong]->Sumw2(); + hL2PtEff[iOffline][iNprong]->Sumw2(); + hEFPtEff[iOffline][iNprong]->Sumw2(); + hL21PtEff[iOffline][iNprong]->Sumw2(); + hEFL2PtEff[iOffline][iNprong]->Sumw2(); + + hL1VisEta[iOffline][iNprong] = new TH1F(*hMCVisEta[iOffline][iNprong]); + hL2VisEta[iOffline][iNprong] = new TH1F(*hMCVisEta[iOffline][iNprong]); + hEFVisEta[iOffline][iNprong] = new TH1F(*hMCVisEta[iOffline][iNprong]); + hL1EtaEff[iOffline][iNprong] = new TH1F(*hMCVisEta[iOffline][iNprong]); + hL2EtaEff[iOffline][iNprong] = new TH1F(*hMCVisEta[iOffline][iNprong]); + hEFEtaEff[iOffline][iNprong] = new TH1F(*hMCVisEta[iOffline][iNprong]); + hL21EtaEff[iOffline][iNprong] = new TH1F(*hMCVisEta[iOffline][iNprong]); + hEFL2EtaEff[iOffline][iNprong] = new TH1F(*hMCVisEta[iOffline][iNprong]); + hL1EtaEff[iOffline][iNprong]->Sumw2(); + hL2EtaEff[iOffline][iNprong]->Sumw2(); + hEFEtaEff[iOffline][iNprong]->Sumw2(); + hL21EtaEff[iOffline][iNprong]->Sumw2(); + hEFL2EtaEff[iOffline][iNprong]->Sumw2(); + } + + TrigTauBugFix bugfix (TrigTauBugFix::TTP14, TrigTauBugFix::RDO); + if (debug) cout << "Looping over all events" << endl; + int nev = int(chain->GetEntries()); + //if ( nev > 100 ) nev = 100; + for(int iev = 0; iev<nev; ++iev) { + if (debug) cout << "Analyzing event number " << iev << endl; + analyzeEvent( iev ); + } +} + +void TTPValOfflinePlots::analyzeEvent(int eventNumber) { + + if (debug) cout << "Starting 'analyzeEvent' " << endl; + event->reset(); + chain->GetEvent(eventNumber); + if (debug) cout << "Chain loaded" << endl; + bugfix.fix(event); + if (debug) cout << "Bugs are fixed.." << endl; + nEvent++; + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + + if (debug) cout << "Starting with combination "<< iOffline << " and " << iNprong << endl; + analyzer[iOffline][iNprong].analyze(event, signal, offlineType[iOffline]); + if( nprong[iNprong] == 1) analyzer[iOffline][iNprong].truthList.select1Prong(); + else if( nprong[iNprong] == 3 ) analyzer[iOffline][iNprong].truthList.select3Prong(); + + nTrue[iOffline][iNprong] += analyzer[iOffline][iNprong].truthList.nMCTauPure(); + nGood[iOffline][iNprong] += analyzer[iOffline][iNprong].truthList.nMCTauGood(); + + nTau = analyzer[iOffline][iNprong].truthList.nMCTauGood(); + + nMatch[iOffline][iNprong]=0; + nL1passed[iOffline][iNprong]=0; + nL2passed[iOffline][iNprong]=0; + nEFpassed[iOffline][iNprong]=0; + + for(unsigned int itau = 0; itau < nTau; ++itau ) { + + const TrigTauMCTau* tau = &analyzer[iOffline][iNprong].truthList.mcTauGoodEntry(itau); + + float visPt = tau->visible().Pt()/1000.; + float visEta = tau->visible().Eta(); + + // Fill denominator with all good taus + hMC_InVisPt[iOffline][iNprong]->Fill(visPt); + hMC_InVisEta[iOffline][iNprong]->Fill(visEta); + if (debug) cout << "hMC_InVisPt filled" << endl; + nMatched[iOffline][iNprong]++; + if (debug) cout << "Now filling hMcVisPt..." << endl; + hMCVisPt[iOffline][iNprong]->Fill(visPt); + hMCVisEta[iOffline][iNprong]->Fill(visEta); + + if(visPt> threshold) nMatch[iOffline][iNprong]++; + + // Find a matching L1 object + const TrigTauL1Object* l1Tau = analyzer[iOffline][iNprong].chainList.getL1Tau(*tau); + if (l1Tau != 0) { + // Found a L1 trigger within dR range, fill numerator histograms + // with MC truth Pt and Eta + hL1VisPt[iOffline][iNprong]->Fill(visPt); + hL1VisEta[iOffline][iNprong]->Fill(visEta); + if(visPt> threshold) nL1passed[iOffline][iNprong]++; + } + const TrigTauL2Object* l2Tau = analyzer[iOffline][iNprong].chainList.getL2Tau(*tau); + if (l2Tau != 0) { + hL2VisPt[iOffline][iNprong]->Fill(visPt); + hL2VisEta[iOffline][iNprong]->Fill(visEta); + if(visPt> threshold) nL2passed[iOffline][iNprong]++; + } + + // Find a matching EF object + const TrigTauRecEFObject* efTau = analyzer[iOffline][iNprong].chainList.getEFTau(*tau); + if (efTau != 0) { + hEFVisPt[iOffline][iNprong]->Fill(visPt); + hEFVisEta[iOffline][iNprong]->Fill(visEta); + if(visPt> threshold) nEFpassed[iOffline][iNprong]++; + //if(visPt> threshold) hEFnTracks[iOffline][iNprong]->Fill(efTau->nTracks()); + } + + } // End of loop over menus + } // End of loop over good taus in the event + if (debug) cout << "End loop over tood taus" << endl; + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + if(nMatch[iOffline][iNprong]>0) n_OfflineMatchEvent[iOffline][iNprong]++; + if(nL1passed[iOffline][iNprong]>0) n_L1MatchEvent[iOffline][iNprong]++; + if(nL2passed[iOffline][iNprong]>0) n_L2MatchEvent[iOffline][iNprong]++; + if(nEFpassed[iOffline][iNprong]>0) n_EFMatchEvent[iOffline][iNprong]++; + } +} + +void TTPValOfflinePlots::print() { + + gROOT->cd(); + + // Make ratios + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + + hL1PtEff[iOffline][iNprong]-> Divide(hL1VisPt[iOffline][iNprong], hMCVisPt[iOffline][iNprong], 1., 1., "B"); + hL2PtEff[iOffline][iNprong]-> Divide(hL2VisPt[iOffline][iNprong], hMCVisPt[iOffline][iNprong], 1., 1., "B"); + hEFPtEff[iOffline][iNprong]-> Divide(hEFVisPt[iOffline][iNprong], hMCVisPt[iOffline][iNprong], 1., 1., "B"); + + hL21PtEff[iOffline][iNprong]-> Divide(hL2VisPt[iOffline][iNprong], hL1VisPt[iOffline][iNprong], 1., 1., "B"); + hEFL2PtEff[iOffline][iNprong]-> Divide(hEFVisPt[iOffline][iNprong], hL2VisPt[iOffline][iNprong], 1., 1.,"B"); + + hL1EtaEff[iOffline][iNprong]-> Divide(hL1VisEta[iOffline][iNprong], hMCVisEta[iOffline][iNprong], 1., 1., "B"); + hL2EtaEff[iOffline][iNprong]-> Divide(hL2VisEta[iOffline][iNprong], hMCVisEta[iOffline][iNprong], 1., 1., "B"); + hEFEtaEff[iOffline][iNprong]-> Divide(hEFVisEta[iOffline][iNprong], hMCVisEta[iOffline][iNprong], 1., 1., "B"); + + hL21EtaEff[iOffline][iNprong]->Divide(hL2VisEta[iOffline][iNprong], hL1VisEta[iOffline][iNprong], 1., 1., "B"); + hEFL2EtaEff[iOffline][iNprong]->Divide(hEFVisEta[iOffline][iNprong], hL2VisEta[iOffline][iNprong], 1., 1., "B"); + } + TString plotfile = "effMultiPlots"; + //plotfile += append; + + // Titles + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + hL1PtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[iOffline][iNprong]->GetYaxis()->SetTitle("L1 efficiency"); + hL2PtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[iOffline][iNprong]->GetYaxis()->SetTitle("L2 efficiency"); + hEFPtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[iOffline][iNprong]->GetYaxis()->SetTitle("Efficiency"); + hL21PtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL21PtEff[iOffline][iNprong]->GetYaxis()->SetTitle("L2/L1 efficiency"); + hEFL2PtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFL2PtEff[iOffline][iNprong]->GetYaxis()->SetTitle("EF/L2 efficiency"); + + hL1EtaEff[iOffline][iNprong]->GetXaxis()->SetTitle("True Visible Eta"); + hL1EtaEff[iOffline][iNprong]->GetYaxis()->SetTitle("L1 Efficiency"); + hL2EtaEff[iOffline][iNprong]->GetXaxis()->SetTitle("True Visible Eta"); + hL2EtaEff[iOffline][iNprong]->GetYaxis()->SetTitle("L2 Efficiency"); + hEFEtaEff[iOffline][iNprong]->GetXaxis()->SetTitle("True Visible Eta"); + hEFEtaEff[iOffline][iNprong]->GetYaxis()->SetTitle("Efficiency"); + + hL21EtaEff[iOffline][iNprong]->GetXaxis()->SetTitle("True Visible Eta"); + hL21EtaEff[iOffline][iNprong]->GetYaxis()->SetTitle("L2/L1 Efficiency"); + hEFL2EtaEff[iOffline][iNprong]->GetXaxis()->SetTitle("True Visible Eta"); + hEFL2EtaEff[iOffline][iNprong]->GetYaxis()->SetTitle("EF/L2 Efficiency"); + + } + + + //gStyle->SetHistLineWidth(2); + gStyle->SetCanvasColor(0); + + TCanvas * c4 = (TCanvas *) gROOT->Get("c4"); + if( c4 ) delete c4; + c4 = new TCanvas("c4","EF Selected",10,10,800,620); + c4->cd(); + gStyle->SetHistLineColor(1); + TLegend *l = new TLegend(0.75,0.1,0.95,0.5); + l->SetFillStyle(0); + //l->SetTextSize(0.9); + + //commented out, since it's done later for all histos + // int id = 2; +// gStyle->SetHistLineColor(color[id]); +// gStyle->SetMarkerStyle(style[id]); +// gStyle->SetMarkerColor(color[id]); +// gStyle->SetLineColor(color[id]); +// gStyle->SetFillColor(0); +// hEFPtEff[id]->SetLineColor(color[id]); +// hEFPtEff[id]->UseCurrentStyle(); +// hEFPtEff[id]->SetMaximum(1.05); +// hEFPtEff[id]->Draw("P"); + + + + //l->AddEntry(hEFPtEff[id],test[id],"p"); + + // TLegend *l = new TLegend(0.13,0.65,0.25,0.85); + //l->SetFillStyle(0); + //hEFPtEff[2]->UseCurrentStyle(); + //hEFPtEff[2]->Draw("P"); + //l->AddEntry(hEFPtEff[2],"tau20i","p"); + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for ( int iNprong = 0; iNprong<nNprong; ++iNprong) { + gStyle->SetHistLineColor(color[iOffline][iNprong]); + //if([iOffline][iNprong]==3 || [iOffline][iNprong]==5) continue; + //if ([iOffline][iNprong]==2) continue; + + gStyle->SetMarkerColor(color[iOffline][iNprong]); + gStyle->SetMarkerStyle(style[iOffline][iNprong]); + gStyle->SetLineColor(color[iOffline][iNprong]); + hEFPtEff[iOffline][iNprong]->SetLineColor(color[iOffline][iNprong]); + hEFPtEff[iOffline][iNprong]->UseCurrentStyle(); + hEFPtEff[iOffline][iNprong]->SetMaximum(1.05); + if (iOffline==0 && iNprong ==0) hEFPtEff[iOffline][iNprong]->Draw("P"); + else hEFPtEff[iOffline][iNprong]->Draw("PSAME"); + + l->AddEntry(hEFPtEff[iOffline][iNprong],getName(offlineType[iOffline]) + ", " + getName(nprong[iNprong]),"p"); + + //gStyle->SetMarkerStyle(style[iOffline][iNprong]); + //gStyle->SetMarkerColor(color[iOffline][iNprong]); + //hEFPtEff[iOffline][iNprong]->UseCurrentStyle(); + //hEFPtEff[iOffline][iNprong]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iOffline][iNprong],test[iOffline][iNprong],"p"); + } + l->Draw("SAME"); + //ATLAS_LABEL(0.15,0.85); + + for( int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + + cout<< "n_L1MatchEvent[iOffline][iNprong] "<<n_L1MatchEvent[iOffline][iNprong]<<endl; + cout<< "n_OfflineMatchEvent[iOffline][iNprong] "<<n_OfflineMatchEvent[iOffline][iNprong]<<endl; + + cout << " L1 efficiency menu "<< menu <<" is "<< ((float)n_L1MatchEvent[iOffline][iNprong])/((float)n_OfflineMatchEvent[iOffline][iNprong]) <<endl; + cout << " L2 efficiency menu "<< menu <<" is "<< ((float)n_L2MatchEvent[iOffline][iNprong])/((float)n_OfflineMatchEvent[iOffline][iNprong]) <<endl; + cout << " EF efficiency menu "<< menu <<" is "<< ((float)n_EFMatchEvent[iOffline][iNprong])/((float)n_OfflineMatchEvent[iOffline][iNprong]) <<endl; + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + cout << "True Taus: " << nTrue[iOffline][iNprong] << endl; + cout << "Good Taus: " << nGood[iOffline][iNprong] << endl; + cout << "Matched Taus: " << nMatched[iOffline][iNprong] << " -> " + << float(nMatched[iOffline][iNprong])/nEvent << " Matched/Ev" << endl; + } +} + +void TTPValOfflinePlots::printCSC(TPostScript & ps) { + + gROOT->cd(); + + // Make ratios + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + + hL1PtEff[iOffline][iNprong]-> Divide(hL1VisPt[iOffline][iNprong], hMCVisPt[iOffline][iNprong], 1., 1., "B"); + hL2PtEff[iOffline][iNprong]-> Divide(hL2VisPt[iOffline][iNprong], hMCVisPt[iOffline][iNprong], 1., 1., "B"); + hEFPtEff[iOffline][iNprong]-> Divide(hEFVisPt[iOffline][iNprong], hMCVisPt[iOffline][iNprong], 1., 1., "B"); + + hL21PtEff[iOffline][iNprong]-> Divide(hL2VisPt[iOffline][iNprong], hL1VisPt[iOffline][iNprong], 1., 1., "B"); + hEFL2PtEff[iOffline][iNprong]-> Divide(hEFVisPt[iOffline][iNprong], hL2VisPt[iOffline][iNprong], 1., 1.,"B"); + } + TString plotfile = "effMultiPlots"; + + // Titles + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + hL1PtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[iOffline][iNprong]->GetYaxis()->SetTitle("L1 efficiency"); + hL2PtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[iOffline][iNprong]->GetYaxis()->SetTitle("L2 efficiency"); + hEFPtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[iOffline][iNprong]->GetYaxis()->SetTitle("EF Efficiency"); + } + + //gStyle->SetHistLineWidth(2); + gStyle->SetCanvasColor(0); + + TCanvas * c1 = (TCanvas *) gROOT->Get("c4"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","EF Selected",10,10,800,620); + c1->cd(); + gStyle->SetHistLineColor(1); + TLegend *l = new TLegend(0.75,0.2,0.9,0.5); + l->SetFillStyle(0); + + ps.On(); + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + gStyle->SetHistLineColor(color[iOffline][iNprong]); + gStyle->SetMarkerColor(color[iOffline][iNprong]); + gStyle->SetMarkerStyle(style[iOffline][iNprong]); + gStyle->SetLineColor(color[iOffline][iNprong]); + hL1PtEff[iOffline][iNprong]->SetLineColor(color[iOffline][iNprong]); + hL1PtEff[iOffline][iNprong]->UseCurrentStyle(); + hL1PtEff[iOffline][iNprong]->SetMaximum(1.05); + if (iOffline==0 && iNprong==0) hL1PtEff[iOffline][iNprong]->Draw("P"); + else hL1PtEff[iOffline][iNprong]->Draw("PSAME"); + l->AddEntry(hL1PtEff[iOffline][iNprong],test[iOffline][iNprong],"p"); + } + l->Draw(); + ATLAS_LABEL(0.15,0.85); + c1->Update(); + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + + gStyle->SetHistLineColor(color[iOffline][iNprong]); + gStyle->SetMarkerColor(color[iOffline][iNprong]); + gStyle->SetMarkerStyle(style[iOffline][iNprong]); + gStyle->SetLineColor(color[iOffline][iNprong]); + hL2PtEff[iOffline][iNprong]->SetLineColor(color[iOffline][iNprong]); + hL2PtEff[iOffline][iNprong]->UseCurrentStyle(); + hL2PtEff[iOffline][iNprong]->SetMaximum(1.05); + if (iOffline == 0 && iNprong == 0) hL2PtEff[iOffline][iNprong]->Draw("P"); + else hL2PtEff[iOffline][iNprong]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iOffline][iNprong],test[iOffline][iNprong],"p"); + } + l->Draw(); + ATLAS_LABEL(0.15,0.85); + c1->Update(); + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + gStyle->SetHistLineColor(color[iOffline][iNprong]); + gStyle->SetMarkerColor(color[iOffline][iNprong]); + gStyle->SetMarkerStyle(style[iOffline][iNprong]); + gStyle->SetLineColor(color[iOffline][iNprong]); + hEFPtEff[iOffline][iNprong]->SetLineColor(color[iOffline][iNprong]); + hEFPtEff[iOffline][iNprong]->UseCurrentStyle(); + hEFPtEff[iOffline][iNprong]->SetMaximum(1.05); + if (iOffline == 0 && iNprong ==0) hEFPtEff[iOffline][iNprong]->Draw("P"); + else hEFPtEff[iOffline][iNprong]->Draw("PSAME"); + //l->AddEntry(hEFPtEff[iOffline][iNprong],test[iOffline][iNprong],"p"); + } + l->Draw(); + ATLAS_LABEL(0.15,0.85); + c1->Update(); + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + + cout<< "n_L1MatchEvent[iOffline][iNprong] "<<n_L1MatchEvent[iOffline][iNprong]<<endl; + cout<< "n_OfflineMatchEvent[iOffline][iNprong] "<<n_OfflineMatchEvent[iOffline][iNprong]<<endl; + + cout << " L1 efficiency menu "<< menu <<" is "<< ((float)n_L1MatchEvent[iOffline][iNprong])/((float)n_OfflineMatchEvent[iOffline][iNprong]) <<endl; + cout << " L2 efficiency menu "<< menu <<" is "<< ((float)n_L2MatchEvent[iOffline][iNprong])/((float)n_OfflineMatchEvent[iOffline][iNprong]) <<endl; + cout << " EF efficiency menu "<< menu <<" is "<< ((float)n_EFMatchEvent[iOffline][iNprong])/((float)n_OfflineMatchEvent[iOffline][iNprong]) <<endl; + + ps.Off(); + + + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + cout << "True Taus: " << nTrue[iOffline][iNprong] << endl; + cout << "Good Taus: " << nGood[iOffline][iNprong] << endl; + cout << "Matched Taus: " << nMatched[iOffline][iNprong] << " -> " + << float(nMatched[iOffline][iNprong])/nEvent << " Matched/Ev" << endl; + } +} + + +void TTPValOfflinePlots::update(TString name) { + + TFile f(name, "update"); + + f.cd(); + f.mkdir("MultiPlots"); + f.cd("MultiPlots"); + + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for ( int iNprong = 0; iNprong<nNprong; ++iNprong) { + hL1PtEff[iOffline][iNprong]-> Divide(hL1VisPt[iOffline][iNprong], hMCVisPt[iOffline][iNprong], 1., 1., "B"); + hL2PtEff[iOffline][iNprong]-> Divide(hL2VisPt[iOffline][iNprong], hMCVisPt[iOffline][iNprong], 1., 1., "B"); + hEFPtEff[iOffline][iNprong]-> Divide(hEFVisPt[iOffline][iNprong], hMCVisPt[iOffline][iNprong], 1., 1., "B"); + } + + // Titles + for(int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + hL1PtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL1PtEff[iOffline][iNprong]->GetYaxis()->SetTitle("L1 efficiency"); + hL2PtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hL2PtEff[iOffline][iNprong]->GetYaxis()->SetTitle("L2 efficiency"); + hEFPtEff[iOffline][iNprong]->GetXaxis()->SetTitle("True visible E_{T} (GeV)"); + hEFPtEff[iOffline][iNprong]->GetYaxis()->SetTitle("Efficiency"); + } + + for( int iOffline = 0; iOffline<nOffline; ++iOffline) + for (int iNprong = 0; iNprong<nNprong; ++iNprong) { + + gStyle->SetHistLineColor(color[iOffline][iNprong]); + gStyle->SetMarkerColor(color[iOffline][iNprong]); + gStyle->SetMarkerStyle(style[iOffline][iNprong]); + gStyle->SetLineColor(color[iOffline][iNprong]); + hL1PtEff[iOffline][iNprong]->SetLineColor(color[iOffline][iNprong]); + hL1PtEff[iOffline][iNprong]->UseCurrentStyle(); + hL1PtEff[iOffline][iNprong]->SetMaximum(1.05); + //l->AddEntry(hEFPtEff[iOffline][iNprong],test[iOffline][iNprong],"p"); + + hL2PtEff[iOffline][iNprong]->SetLineColor(color[iOffline][iNprong]); + hL2PtEff[iOffline][iNprong]->UseCurrentStyle(); + hL2PtEff[iOffline][iNprong]->SetMaximum(1.05); + + hEFPtEff[iOffline][iNprong]->SetLineColor(color[iOffline][iNprong]); + hEFPtEff[iOffline][iNprong]->UseCurrentStyle(); + hEFPtEff[iOffline][iNprong]->SetMaximum(1.05); + + + TrigTauFlags test; + hL1PtEff[iOffline][iNprong]->SetName("TTPVAlMultiPlots_" + TString(iOffline) + "_" + TString(iNprong)+"_L1"); + hL1PtEff[iOffline][iNprong]->Write(); + hL2PtEff[iOffline][iNprong]->SetName("TTPVAlMultiPlots_" + TString(iOffline) + "_" + TString(iNprong)+"_L2"); + hL2PtEff[iOffline][iNprong]->Write(); + hEFPtEff[iOffline][iNprong]->SetName("TTPVAlMultiPlots_" + TString(iOffline) + "_" + TString(iNprong) +"_EF"); + hEFPtEff[iOffline][iNprong]->Write(); + } + f.Close(); +} + + +void TTPValOfflinePlots::ATLAS_LABEL(Double_t x,Double_t y,Color_t color) { + + TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize); + l.SetNDC(); + l.SetTextFont(72); + l.SetTextColor(color); + l.DrawLatex(x,y,"ATLAS Preliminary"); +} + +TString TTPValOfflinePlots::getName(TrigTauMCTauList::OFFLINESELECTION selection) { + + if (selection == TrigTauMCTauList::TAUCUTSAFEMEDIUM) return "TauCutSafeMedium"; + else if (selection == TrigTauMCTauList::TAULLHMEDIUM) return "TauLlhMedium"; + else return "Offline selection not known to printout routine"; + +} + +TString TTPValOfflinePlots::getName(int selection) { + + if (selection == 1) return "1Prong"; + else if (selection == 3) return "3Prong"; + else return "allDecays"; + +} + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValRateTable.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValRateTable.cxx new file mode 100644 index 0000000000000000000000000000000000000000..73e2403f960751e4d769253e3692c7199ec45f86 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValRateTable.cxx @@ -0,0 +1,606 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <fstream> +#include <iomanip> +using namespace std; +#include "TrigTauPerformValidation/TTPValRateTable.h" + + + +TTPValRateTable::TTPValRateTable(TrigTauBugFix::POOLFILE poolfile1, TrigTauBugFix::TTPVERSION version1, bool debug1) + : bugfix(version1, poolfile1) { + + version = version1; + poolfile = poolfile1; + + initialize(debug1); + fileDefined = false; + return; + +} + + + + +TTPValRateTable::TTPValRateTable( TString filename1, TrigTauBugFix::POOLFILE poolfile1, TrigTauBugFix::TTPVERSION version1, bool debug1) + : bugfix (version1, poolfile1) { + + poolfile = poolfile1; + version = version1; + + filename = filename1; + chain = new TChain("eventTree"); + chain->Add(filename); + initialize(debug1); + fileDefined = true; + return; + +} + +void TTPValRateTable::setFile (TString filename1) { + + if (!fileDefined ) { + filename = filename1; + chain = new TChain("eventTree"); + chain->Add(filename); + } + else { + cout << "WARNING: File already defined!! Overwriting old file settings...." << endl; + filename = filename1; + chain = new TChain("eventTree"); //memory leak + chain->Add(filename); + } + fileDefined = true; + + +} + +void TTPValRateTable::initialize ( bool debug1 ) { + + type = 1; + debug = debug1; + nprong = 0; + maxVisEta = 2.5; + minLeadingPt = 6.0; + met = 0.; + nprong = 0; + signalSet = false; + checkOffline = true; + doDetailedPrinting = false; + checkL2Cal = true; printChain=false; + gStyle->SetPadGridX(true); + gStyle->SetPadGridY(true); + menu = TrigTauFlags::TAU16; + cutLevel = TrigTauSelectionManager::LOOSE; + offlineType = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + menuVersion = TrigTauSelectionManager::MENU1560; + chainType = TrigTauFlags::SITRK; +} + + +void TTPValRateTable::checkAllMenus(unsigned int nMenu, unsigned int nLevel, double lum, double crosssec) { + + if (!signalSet) { + + cout << "ERROR: Boolean SIGNAL is not set!" << endl; + return; + + } + + + TrigTauFlags::TRIGGERMENU names[] = {TrigTauFlags::TAU12, TrigTauFlags::TAU16, TrigTauFlags::TAU20, TrigTauFlags::TAU29, TrigTauFlags::TAU38, TrigTauFlags::TAU50, TrigTauFlags::TAU84, TrigTauFlags::TAU100, TrigTauFlags::TAU125}; + TrigTauSelectionManager::CUTLEVEL levels[] = {TrigTauSelectionManager::LOOSE, TrigTauSelectionManager::MEDIUM, TrigTauSelectionManager::TIGHT}; + TTPValRateTable * tables[9][3]; + /* + int j=0; + int i=1; + cout << "Checking number " << j*nMenu+i << " of " << nLevel*nMenu << endl; + tables[i][j] = new TTPValRateTable(filename, poolfile, version, debug); + tables[i][j]->setMenu(names[i]); + tables[i][j]->setCutLevel(levels[j]); + tables[i][j]->analyze(); + + tables[i][j]->print(lum, crosssec); + + i=6; + cout << "Checking number " << j*nMenu+i << " of " << nLevel*nMenu << endl; + tables[i][j] = new TTPValRateTable(filename, poolfile, version, debug); + tables[i][j]->setMenu(names[i]); + tables[i][j]->setCutLevel(levels[j]); + tables[i][j]->analyze(); + + cout << "\n Displaying results for "; + switch (j) { + case 0: cout << "cutLevel: LOOSE" << endl; break; + case 1: cout << "cutLevel: MEDIUM" << endl; break; + case 2: cout << "cutLevel: TIGHT" << endl; break; + } + i=1; + tables[i][j]->print(lum, crosssec); + i=6; + tables[i][j]->print(lum, crosssec); + */ + + + for (unsigned int j =0; j!=nLevel; ++j) { + for (unsigned int i = 0; i!=nMenu; ++i) { + cout << "Checking number " << j*nMenu+i << " of " << nLevel*nMenu << endl; + tables[i][j] = new TTPValRateTable(filename, poolfile, version, debug); + tables[i][j]->setMenu(names[i]); + tables[i][j]->setCutLevel(levels[j]); + tables[i][j]->setSignal(signal); + tables[i][j]->setChainType(chainType); + tables[i][j]->analyze(); + } + } + for (unsigned int j=0; j!=nLevel; ++j) { + outfile << "\n Displaying results for "; + switch (j) { + case 0: outfile << "cutLevel: LOOSE" << endl; break; + case 1: outfile << "cutLevel: MEDIUM" << endl; break; + case 2: outfile << "cutLevel: TIGHT" << endl; break; + } + for (unsigned int i = 0; i!=nMenu; ++i) { + if (lum == 0 || crosssec == 0) tables[i][j]->print(false); + else tables[i][j]->print(lum, crosssec, false); + } + } + +} + + + + +void TTPValRateTable::analyze (int nEvents) { + + if (fileDefined == false) { + cout << "ERROR: Filename is not set. Please set filename with setFile(char*)" << endl; + return; + } + + if (!signalSet) { + + cout << "ERROR: Boolean SIGNAL is not set!" << endl; + return; + + } + + + TrigTauAnalyzer analyzer; + + //=================================================== + // MC truth + analyzer.truthList.setMaxVisEta(maxVisEta); + if (debug) cout << "Analyzer: maxVisEta set." << endl; + analyzer.truthList.setMinVisPt(menu); + if (debug) cout << "Analyzer: minVisPt set." << endl; + if( nprong == 1 ) analyzer.truthList.select1Prong(); + else if( nprong == 3 ) analyzer.truthList.select3Prong(); + analyzer.truthList.setRecoMatchdR(0.2); + if (debug) cout << "Analyzer: RecoMatch set." << endl; + + reset(); + gROOT->cd(); + + + TTree* tree = chain; + if (debug) cout << "Tree created..." << endl; + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + if (debug) cout << "EventBranch connected..." << endl; + tree->SetBranchStatus("*", 1); + //tree->SetBranchStatus("mcEvent*", 0); + if (debug) cout << "Tree configured.." << endl; + + // Also set an L1 MET cut if desired + analyzer.trigMan.setL1MET(met); + analyzer.trigMan.setMenuVersion(menuVersion); + analyzer.trigMan.setTauMenu(menu, cutLevel); + + analyzer.chainList.setRoiWordMatching(false); + analyzer.chainList.setHLTAuthor(chainType); + if (debug) cout << "Analyzer configured.." << endl; + + // Loop over all events + nev = int(tree->GetEntries()); + cout << "Checking a total of " << nev << " events..." << endl; + if (nev > nEvents) nev = nEvents; + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + bugfix.fix(event); + + analyzer.analyze(event, signal, offlineType); + + // ============ Select type of events (e.g. signal) ================ + if( signal && analyzer.truthList.nMCTauGood() ==0 ) continue; + //================================================================== + nEvent++; + + bool decL1 = event->decision.passedL1(analyzer.trigMan.usedTauMenu()); + bool decL2 = event->decision.passedL2(analyzer.trigMan.usedTauMenu()); + bool decEF = event->decision.passedEF(analyzer.trigMan.usedTauMenu()); + + nDecL1 += int(decL1); + nDecL2 += int(decL2); + nDecEF += int(decEF); + + bool ntL1 = false; + bool ntL2 = false; + bool ntEF = false; + + if( analyzer.chainList.nPassL1Chains() > 0 ) { + nL1Sel++; + ntL1 = true; + } + + if( checkL2Cal ) + if( analyzer.chainList.nPassL2CalChains() > 0 ) + nL2CalSel++; + + if( analyzer.chainList.nPassL2Chains() > 0 ) { + nL2Sel++; + ntL2 = true; + } + + if( analyzer.chainList.nPassEFChains() > 0 ) { + nEFSel++; + ntEF=true; + } + + printChain = false; + if(doDetailedPrinting && decL1 != ntL1 ) { + cout << "\n============ Event " << event->eventNumber << " L1 decision does not match: NTUPLE " + << ntL1 << "\n and HLTcode " << decL1 << endl; + printChain = true; + nPrintL1++; + + } + if( doDetailedPrinting && decL2 != ntL2 ) { + cout << "\n============ Event " << event->eventNumber << " L2 decision does not match: NTUPLE " + << ntL2 << "\n and HLTcode " << decL2 << endl; + printChain = true; + nPrintL2++; + } + if( doDetailedPrinting && decEF != ntEF ) { + cout << "\n============ Event " << event->eventNumber << " EF decision does not match: NTUPLE " + << ntEF << "\n and HLTcode " << decEF << endl; + printChain = true; + nPrintEF++; + } + if( doDetailedPrinting && printChain ) + { + analyzer.chainList.printChainList(); + cout << endl; + analyzer.trigMan.setDebug(true); + unsigned int numCh = analyzer.chainList.nTrigChains(); + for (unsigned int iCh1=0; iCh1 < numCh; iCh1++) { + cout << " ==================================\n"; + TrigTauTrigChain ch1 = analyzer.chainList.trigChainEntry(iCh1); + if (!analyzer.trigMan.passedL1(ch1)) continue; + if (!analyzer.trigMan.passedL2(ch1)) continue; + if (!analyzer.trigMan.passedEF(ch1)) continue; + } + analyzer.trigMan.setDebug(false); + cout << endl; + } + // end of doDetailedPrinting + + + } // end loop over events + + delete event; + delete tree; + //delete file; + + + if (doDetailedPrinting) cout << "Out of "<< nEvent << " events: Mistmatch found in L1 " << nPrintL1 << " , L2 " << nPrintL2 << ", EF " << nPrintEF << endl; + return; +} + +void TTPValRateTable::print(double lum, double crosssec, bool file) { + + print(lum, crosssec, "rateTable.txt", file); + +} + +void TTPValRateTable::print(bool file) { + + print("rateTable.txt", file); + +} + + +void TTPValRateTable::print(double lum, double crosssec,TString target, bool file) { + + if (debug) cout << "luminosity is set to " << lum << " and x-sec is set to " << crosssec << endl; + nL1SelWt = lum*crosssec*double(nL1Sel)/double(nEvent); + nL2CalSelWt = lum*crosssec*double(nL2CalSel)/double(nEvent); + nL2SelWt = lum*crosssec*double(nL2Sel)/double(nEvent); + nEFSelWt = lum*crosssec*double(nEFSel)/double(nEvent); + print(target, file); + +} + + +void TTPValRateTable::print(TString target, bool file) { + + outfile.open(target, ios::app); + + if (file==true) { + + TrigTauFlags menu1; + outfile << "For sample: " << filename << endl; + outfile << " Use menu " << menu1.menuName(menu) << endl; + + outfile << "Number of Events in ntuple: " << nev << endl; + + // Print out matching statistics + outfile << "Events: " << nEvent << endl; + + outfile << "L1Sel L2CalSel L2TrkSel EFSel" << endl; + + outfile << "Decision : " + << nDecL1 << " " + << nDecL2 << " " + << nDecEF << endl; + + + outfile << "Number: " + << nL1Sel << " " + << nL2CalSel << " " + << nL2Sel << " " + << nEFSel << endl; + + outfile << "Rate: " + << nL1SelWt << " " + << nL2CalSelWt << " " + << nL2SelWt << " " + << nEFSelWt << endl; + + outfile << "Cum Eff: " + << 100*float(nL1Sel)/nEvent << " " + << 100*float(nL2CalSel)/nEvent << " " + << 100*float(nL2Sel)/nEvent << " " + << 100*float(nEFSel)/nEvent << endl; + + outfile << endl; + outfile << endl; + + + // outfile << "Dif Eff: " + // << 100*float(nL1Sel)/nEvent << " " + // << (nL1Sel > 0 ? 100*float(nL2CalSel)/nL1Sel : 0) << " " + // << (nL2CalSel > 0 ? 100*float(nL2Sel)/nL2CalSel : 0) + // << (nL2Sel > 0 ? 100*float(nEFSel)/nL2Sel : 0) << endl; + + // outfile << "Cum Rej: " + // << (nL1Sel > 0 ? nEvent/float(nL1Sel) : 0) << " " + // << (nL2CalSel > 0 ? nEvent/float(nL2CalSel) : 0) << " " + // << (nL2Sel > 0 ? nEvent/float(nL2Sel) : 0) << " " + // << (nEFSel > 0 ? nEvent/float(nEFSel) : 0) << endl; + + // outfile << "Dif Rej: " + // << (nL1Sel > 0 ? nEvent/float(nL1Sel) : 0) << " " + // << (nL2CalSel > 0 ? nL1Sel/float(nL2CalSel) : 0) << " " + // << (nL2Sel > 0 ? nL2CalSel/float(nL2Sel) : 0) << " " + // << (nEFSel > 0 ? nL2Sel/float(nEFSel) : 0) << endl; + } + else { + + TrigTauFlags menu1; + cout << " Use menu " << menu1.menuName(menu) << endl; + + cout << "Number of Events in ntuple: " << nev << endl; + + // Print out matching statistics + cout << "Events: " << nEvent << endl; + + cout << "L1Sel L2CalSel L2TrkSel EFSel" << endl; + + cout << "Decision : " + << nDecL1 << " " + << nDecL2 << " " + << nDecEF << endl; + + + cout << "Number: " + << nL1Sel << " " + << nL2CalSel << " " + << nL2Sel << " " + << nEFSel << endl; + + cout << "Rate: " + << nL1SelWt << " " + << nL2SelWt << " " + << nEFSelWt << endl; + + cout << "Cum Eff: " + << 100*float(nL1Sel)/nEvent << " " + << 100*float(nL2CalSel)/nEvent << " " + << 100*float(nL2Sel)/nEvent << " " + << 100*float(nEFSel)/nEvent << endl; + + } + + + +} + +void TTPValRateTable::update( TString filename, double lum, double crosssec ) { + + TFile f(filename, "update"); + + f.cd(); + f.mkdir("RateTable"); + f.cd("RateTable"); + + TrigTauFlags menu1; + TH1F *EventNumbers = new TH1F("TTPValRateTable_EventNumbers_"+menu1.menuName(menu), "EventCounter", 20, 0, 20); + EventNumbers->SetBinContent(1, nev); + EventNumbers->GetXaxis()->SetBinLabel(1, "Total Number of Events"); + + EventNumbers->SetBinContent(2, nEvent); + EventNumbers->GetXaxis()->SetBinLabel(2, "# of good Events"); + + EventNumbers->SetBinContent(3, nDecL1); + EventNumbers->GetXaxis()->SetBinLabel(3, "Decision L1"); + + EventNumbers->SetBinContent(4, nL1Sel); + EventNumbers->GetXaxis()->SetBinLabel(4, "Number L1"); + + EventNumbers->SetBinContent(5, nDecL2); + EventNumbers->GetXaxis()->SetBinLabel(5, "Decision L2"); + + EventNumbers->SetBinContent(6, nL2CalSel); + EventNumbers->GetXaxis()->SetBinLabel(6, "Number L2Calo"); + + EventNumbers->SetBinContent(7, nL2Sel); + EventNumbers->GetXaxis()->SetBinLabel(7, "Number L2Trk"); + + EventNumbers->SetBinContent(8, nDecEF); + EventNumbers->GetXaxis()->SetBinLabel(8, "Decision EF"); + + EventNumbers->SetBinContent(9, nEFSel); + EventNumbers->GetXaxis()->SetBinLabel(9, "Number EF"); + + EventNumbers->LabelsOption("u","X"); + + nL1SelWt = lum*crosssec*double(nL1Sel)/double(nEvent); + nL2CalSelWt = lum*crosssec*double(nL2CalSel)/double(nEvent); + nL2SelWt = lum*crosssec*double(nL2Sel)/double(nEvent); + nEFSelWt = lum*crosssec*double(nEFSel)/double(nEvent); + + TH1F *Rates = new TH1F("TTPValRateTable_Rates_"+menu1.menuName(menu), "Rates", 10, 0, 10); + + Rates->SetBinContent(1, nL1SelWt); + Rates->GetXaxis()->SetBinLabel(1, "L1 Rate"); + + Rates->SetBinContent(2, nL2SelWt); + Rates->GetXaxis()->SetBinLabel(2, "L2 Rate"); + + Rates->SetBinContent(3, nEFSelWt); + Rates->GetXaxis()->SetBinLabel(3, "EF Rate"); + + Rates->LabelsOption("u","X"); + + TH1F *Efficiencies = new TH1F("TTPValRateTable_Efficiencies_"+ menu1.menuName(menu), "Cumulated Efficiencies", 10, 0, 10); + + if (nEvent != 0 ) { + Efficiencies->SetBinContent(1, (float)nL1Sel/nEvent); + Efficiencies->GetXaxis()->SetBinLabel(1, "L1 Efficiency"); + + Efficiencies->SetBinContent(2, (float)nL2CalSel/nEvent); + Efficiencies->GetXaxis()->SetBinLabel(2, "L2Calo Efficiency"); + + Efficiencies->SetBinContent(3, (float)nL2Sel/nEvent); + Efficiencies->GetXaxis()->SetBinLabel(3, "L2Trk Efficiency"); + + Efficiencies->SetBinContent(4, (float)nEFSel/nEvent); + Efficiencies->GetXaxis()->SetBinLabel(4, "EF Efficiency"); + + } + else cout << "Due to lack of statistics, all efficiencies set to zero." << endl; + Efficiencies->LabelsOption("u", "X"); + + EventNumbers->Write(); + Rates->Write(); + Efficiencies->Write(); + f.Close(); +} + + + +void TTPValRateTable::printCSC(TPostScript & ps, double lum, double crosssec, vector<double> &counter) { + + TrigTauFlags menu1; + TH1F * Rates = new TH1F("TTPValRateTable_Rates_"+menu1.menuName(menu), "Rates", 10, 0, 10); + + if (debug) cout << "Numbers for calculation of L1 are " << nL1Sel << ", " << nEvent << endl; + + if (nEvent != 0 ) { + nL1SelWt = lum*crosssec*double(nL1Sel)/double(nEvent); + nL2CalSelWt = lum*crosssec*double(nL2CalSel)/double(nEvent); + nL2SelWt = lum*crosssec*double(nL2Sel)/double(nEvent); + nEFSelWt = lum*crosssec*double(nEFSel)/double(nEvent); + } + else { + nL1SelWt=-999999; + nL2CalSelWt=-999999; + nL2SelWt=-999999; + nEFSelWt=-999999; + } + + if (debug) cout << "Numbers to add are " << nEFSelWt << ", " << nL2CalSelWt << ", " << nL2SelWt << ", " << nEFSelWt << endl; + + if (debug) cout << "Before adding, counter has value " << counter[0] << ", " << counter[1] << ", " << counter[2] << ", " << counter[3] << endl; + +// vector<double> counter; + //counter.push_back(counterOld[0] + nL1SelWt); + //counter.push_back(counterOld[1] + nL2CalSelWt); + //counter.push_back(counterOld[2] + nL2SelWt); + //counter.push_back(counterOld[3] + nEFSelWt); + + counter[0] = counter[0] + nL1SelWt; + counter[1] = counter[1] + nL2CalSelWt; + counter[2] += nL2SelWt; + counter[3] += nEFSelWt; + + if (debug) cout << "After adding, counter has value " << counter[0] << ", " << counter[1] << ", " << counter[2] << ", " << counter[3] << endl; + + Rates->SetBinContent(1, nL1SelWt); + Rates->GetXaxis()->SetBinLabel(1, "L1 Rate"); + + Rates->SetBinContent(2, nL2CalSelWt); + Rates->GetXaxis()->SetBinLabel(2, "L2Cal Rate"); + + Rates->SetBinContent(3, nL2SelWt); + Rates->GetXaxis()->SetBinLabel(3, "L2Trk Rate"); + + Rates->SetBinContent(4, nEFSelWt); + Rates->GetXaxis()->SetBinLabel(4, "EF Rate"); + + Rates->LabelsOption("u","X"); + Rates->GetYaxis()->SetTitle("Rates for "+filename); + + + TCanvas * c1 = (TCanvas *)gROOT->Get("c1"); + if( c1 ) delete c1; + c1 = new TCanvas("c1","",10,10,800,500); + c1->cd(); + ps.On(); + + + + Rates->Draw(); + c1->Update(); + ps.Off(); + return; +} + +void TTPValRateTable::reset() { + // Create counters to hold triggered object counts + nEvent = 0; + nL1Sel = 0; + nL2CalSel = 0; + nL2Sel = 0; + nEFSel = 0; + nEventWt = 0.; + nL1SelWt = 0.; + nL2SelWt = 0.; + nEFSelWt = 0.; + + nDecL1= 0; + nDecL2= 0; + nDecEF= 0; + + nPrintL1 = 0; + nPrintL2 = 0; + nPrintEF = 0; + +} + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValTrigDump.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValTrigDump.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f40f2461edf759cf2fa8a887d9ebdd82192bf107 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValTrigDump.cxx @@ -0,0 +1,220 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// Dump out trigger bits +#include <iostream> +#include <iomanip> +#include <vector> +#include <algorithm> + +#include "TFile.h" + +#include "TrigTauPerformValidation/TTPValTrigDump.h" +#include "TrigTauPerformNtuple/TrigTauEvent.h" + +using namespace std; + +TTPValTrigDump::TTPValTrigDump() : _maxNEvents(0) { +} + +TTPValTrigDump::~TTPValTrigDump() { +} + +// Add event numbers to list +void +TTPValTrigDump::selectEvent(long evNumber) { + _eventList.push_back(evNumber); +} + +// More user friendly way to process file +void +TTPValTrigDump::dump(const TString& filename) { + + // Open file + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + std::cerr << "Can't open file " << filename << std::endl; + return; + } + + // Initialize tree + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + std::cerr << "Can't find eventTree in " << filename << std::endl; + return; + } + + dump(tree); + + delete tree; + delete file; +} + +// Process file +void +TTPValTrigDump::dump(TTree* tree) { + + if (tree == 0) { + std::cerr << "TTPValTrigDump::fill - TTree is NULL!" << std::endl; + return; + } + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + tree->SetBranchStatus("mcEvent*", 0); + + // Loop over all events + int nev = int(tree->GetEntries()); + long ndumped = 0; + + for(int iev = 0; iev<nev; ++iev) { + + if (_maxNEvents > 0 && ndumped >= _maxNEvents) break; + + event->reset(); + tree->GetEvent(iev); + + // Check for specific event + if (_eventList.size() > 0 && std::find(_eventList.begin(), _eventList.end(), event->eventNumber) == _eventList.end()) continue; + + ndumped++; + + // Analyze this event + cout << endl << "--------------------- Run: " << event->runNumber + << " Event: " << event->eventNumber + << " ---------------------" << endl; + + cout << " Time Stamp: " << event->time_stamp + << " Lumi Block: " << event->lumi_block + << " BX: " << event->bunch_crossing << endl; + + cout << " --- Triggers Passed ---" << endl; + + event->decision.print(); + + for (unsigned int word=0; word<4; word++) { + for (unsigned int ibit=0; ibit<32; ibit++) { + + unsigned int imenu = 100*word+ibit; + TrigTauFlags::TRIGGERMENU + menu = (TrigTauFlags::TRIGGERMENU) imenu; + + if (event->decision.passedL1(menu)) { + cout << "[" << setw(3) << imenu << "] " + << TrigTauFlags::menuName(menu) << ": L1"; + if (event->decision.passedL2(menu)) cout << " L2"; + if (event->decision.passedEF(menu)) cout << " EF"; + cout << endl; + } + } + } + + cout << " --- L1 ROIs found --- " << endl; + for (unsigned long i=0; i<event->nTauL1(); i++) { + TrigTauL1Object* tau = &event->tauL1Entry(i); + cout << " Et: " << tau->m_TauEnergy + << " eta/phi: " << tau->Eta() << "/" << tau->Phi() + << " EMIso: " << tau->m_EmIsol + << " roiWord: " << std::hex << tau->m_roiWord << std::dec << endl; + } + + cout << " --- L2 ROIs found --- " << endl; + for (unsigned long i=0; i<event->nTauL2(); i++) { + TrigTauL2Object* tau = &event->tauL2Entry(i); + cout << " Et: " << tau->etNarrow() + << " eta/phi: " << tau->Eta() << "/" << tau->Phi() + << " (calo: " << tau->m_caloEta << "/" << tau->m_caloPhi << ")" + << " nTrks: " << tau->nTracks() + << " roiWord: " << std::hex << tau->m_roiWord << std::dec; + + cout << " type: "; + switch (tau->m_seedType) { + case TrigTauTauObject::UNDEFINED: + cout << "undefined"; + break; + case TrigTauTauObject::CALOOBJECT: + cout << "calo"; + break; + case TrigTauTauObject::TRACK: + cout << "track"; + break; + case TrigTauTauObject::BOTH: + cout << "both"; + break; + default: + cout << "unknown!"; + } + cout << endl; + + cout << " Triggers: "; + for (unsigned int word=0; word<4; word++) { + for (unsigned int ibit=0; ibit<32; ibit++) { + + unsigned int imenu = 100*word+ibit; + TrigTauFlags::TRIGGERMENU + menu = (TrigTauFlags::TRIGGERMENU) imenu; + if (tau->m_tags.passedL2(menu)) + cout << "[" << imenu << "] " + << TrigTauFlags::menuName(menu) << " "; + } + } + cout << endl; + // tau->m_tags.print(); + } + + cout << " --- EF ROIs found --- " << endl; + for (unsigned long i=0; i<event->nTauEF(); i++) { + TrigTauRecEFObject* tau = &event->tauEFEntry(i); + cout << " Et: " << tau->Et() + << " eta/phi: " << tau->Eta() << "/" << tau->Phi() + << " (calo: " << tau->m_caloEta << "/" << tau->m_caloPhi << ")" + << " nTrks: " << tau->nTracks() + << " roiWord: " << std::hex << tau->m_roiWord << std::dec + << " type: "; + switch (tau->m_seedType) { + case TrigTauTauObject::UNDEFINED: + cout << "undefined"; + break; + case TrigTauTauObject::CALOOBJECT: + cout << "calo"; + break; + case TrigTauTauObject::TRACK: + cout << "track"; + break; + case TrigTauTauObject::BOTH: + cout << "both"; + break; + default: + cout << "unknown!"; + } + cout << endl; + + cout << " Triggers:"; + for (unsigned int word=0; word<4; word++) { + for (unsigned int ibit=0; ibit<32; ibit++) { + + unsigned int imenu = 100*word+ibit; + TrigTauFlags::TRIGGERMENU + menu = (TrigTauFlags::TRIGGERMENU) imenu; + + if (tau->m_tags.passedEF(menu)) + cout << "[" << imenu << "] " + << TrigTauFlags::menuName(menu) << " "; + } + } + cout << endl; + // tau->m_tags.print(); + + } + + + + + } // End event loop + + delete event; +} + + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValTrigPlots.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValTrigPlots.cxx new file mode 100644 index 0000000000000000000000000000000000000000..763e2a0f14df323362c67bdc8882115d0c7e8784 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValTrigPlots.cxx @@ -0,0 +1,464 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// Make standard set of selection plots +bool debug = false; + +#include <iostream> +#include <vector> +#include <math.h> + +#include "TROOT.h" // needed for gROOT +#include "TFile.h" + +#include "TrigTauPerformValidation/TTPValTrigPlots.h" +#include "TrigTauPerformNtuple/TrigTauEvent.h" +#include "TrigTauPerformAnalysis/TrigTauTrigChainList.h" + +// Histograms managed by HistHelper +// Index means the following: +// 0 - L1 input +// 1 - L1 output +// 2 - L2Cal output +// 3 - L2Trk output +// 4 - EF output +// 5 - Offline reco matched + +TTPValTrigPlots::TTPValTrigPlots() : hh(6), _thbins(100), _thstart(0) +{ + _currentWeight = 1.; + _defVersion = TrigTauSelectionManager::MENU1400; + _selManager = 0; + _hltAuthorType = TrigTauFlags::ANYAUTHOR; + _nEvent.clear(); +} + +TTPValTrigPlots::~TTPValTrigPlots() { + if (_selManager != 0) delete _selManager; +} + +void +TTPValTrigPlots::setDefaultVersion(TrigTauSelectionManager::MENUVERSION version) { + _defVersion = version; +} + +void +TTPValTrigPlots::setSelector(TrigTauFlags::TRIGGERMENU menu) { + if (_selManager == 0) _selManager = new TrigTauSelectionManager(); + _selManager->setMenuVersion(_defVersion); + _selManager->setTauMenu(menu); +} + +// Clear plots and define histograms +void +TTPValTrigPlots::clear() { + + // Delete all histograms + hh.clear(); + + // Define labels before creating histogram families + std::vector<TString> ylabel(7); + ylabel[0] = "L1 In"; + ylabel[1] = "L1 Out"; + ylabel[2] = "L2Cal Out"; + ylabel[3] = "L2Trk Out"; + ylabel[4] = "EF Out"; + ylabel[5] = "Offline"; + hh.setYAxisLabels(ylabel); + + _nEvent.clear(); + for (unsigned int i=0; i<6; i++) _nEvent.name(i, ylabel[i].Data()); + + // Make sure we are in the main ROOT directory + gROOT->cd(); + + hh.create("hNRoi", 10, 0.0, 10., "ROI/ev"); + + // L1 Plots + hh.create("hL1Et", 50, 0.0, 100., "L1 Et (GeV)"); + hh.create("hL1EmEt", 50, 0.0, 100., "L1 EM Et (1x2) (GeV)"); + hh.create("hL1HdEt", 50, 0.0, 50., "L1 Hd Et (2x2) (GeV)"); + hh.create("hL1EmI", 25, 0.0, 25., "L1 EmIso (GeV)"); + hh.setLogY("hL1EmI"); + hh.create("hL1HdI", 25, 0.0, 25., "L1 HdIso (GeV)"); + hh.setLogY("hL1HdI"); + + hh.create("hL1Eta", 61, -3.05, 3.05, "L1Eta"); + hh.create("hL1Phi", 65, -M_PI-M_PI/64., M_PI+M_PI/64., "L1Phi"); + hh.create("hL1EtaPhi", 61, -3.05, 3.05, 65, -M_PI-M_PI/64., M_PI+M_PI/64., + "L1Eta", "L1Phi"); + + // L2Calo Plots + hh.create("hL2EtCalib", 50, 0.0, 100., "L2 EtCalib (GeV)"); + hh.create("hL2NStrips", 50, 0.0, 50., "L2 NStrips"); + hh.create("hL2StrWid2", 50, 0.0, 0.2, "L2 StrWid2"); + hh.create("hL2EMRad", 50, 0.0, 0.1, "L2 EM Radius"); + hh.create("hL2IsoFrac", 50, 0.0, 1.0, "L2 IsoFrac"); + + // L2Trk Plots + hh.create("hL2NTrk", 10, 0, 10, "L2 Tracks"); + hh.create("hL2NIso", 5, 0, 5, "L2 Iso Tr"); + hh.create("hL2NSlow", 10, 0, 10, "L2 Slow Tracks"); + hh.create("hL2PtLead", 50, 0.0, 50., "L2 PtLead (GeV)"); + hh.create("hL2Charge", 7, -3.5, 3.5, "L2 Charge"); + hh.create("hL2IsoR", 20, 0., 1., "L2 Pt Iso/Core"); + hh.setLogY("hL2IsoR"); + hh.create("hL2EtTrkEM", 50, 0.0, 100., "L2 Et Trk+EM (GeV)"); + hh.create("hL2Eta", 31, -3.1, 3.1, "L2Eta"); + hh.create("hL2Phi", 31, -3.1, 3.1, "L2Phi"); + hh.create("hL2EtaPhi", 31, -3.1, 3.1, 31, -3.1, 3.1, "L2Eta", "L2Phi"); + + hh.create("hL2L1dEta", 50, -0.25, 0.25, "L2-L1 dEta"); + hh.create("hL2L1dPhi", 50, -0.25, 0.25, "L2-L1 dPhi"); + hh.create("hL2L1dEtadPhi", 50, -0.25, 0.25, 50, -0.25, 0.25, + "L2-L1 dEta", "dPhi"); + hh.create("hL2L1dEt", 50, -25, 25, "L2 Et - L1 Et"); + hh.create("hL2L1Et", 50, 0.0, 100.0, 50, 0.0, 100.0, "L1 Et", "L2 Et"); + + // EF Plots + hh.create("hEFNTrk", 10, 0, 10, "EF Tracks"); + hh.create("hEFCharge", 7,-3.5, 3.5, "EF Charge"); + hh.create("hEFPtLead", 50, 0, 50., "EF PtLead (GeV)"); + hh.create("hEFEMRad", 40, 0, 0.4, "EF EMRad"); + hh.create("hEFIsoFrac", 50, 0, 0.5, "EF IsoFrac"); + hh.setLogY("hEFIsoFrac"); + hh.create("hEFEt", 50, 0, 100., "EF Et (GeV)"); + hh.create("hEFMass", 50, 0, 10., "EF Mass (GeV)"); + hh.create("hEFEta", 31, -3.1, 3.1, "EFEta"); + hh.create("hEFPhi", 31, -3.1, 3.1, "EFPhi"); + hh.create("hEFEtaPhi", 31, -3.1, 3.1, 31, -3.1, 3.1, "EFEta", "EFPhi"); + + hh.create("hEFL2dEta", 50, -0.25, 0.25, "EF-L2 dEta"); + hh.create("hEFL2dPhi", 50, -0.25, 0.25, "EF-L2 dPhi"); + hh.create("hEFL2dEtadPhi", 50, -0.25, 0.25, 50, -0.25, 0.25, + "EF-L2 dEta", "dPhi"); + hh.create("hEFL2dEt", 50, -25, 25, "EF Et - L2 Et"); + hh.create("hEFL2Et", 50, 0.0, 100.0, 50, 0.0, 100.0, "L2 Et", "EF Et"); + + // Reco plots + hh.create("hReNTrk", 10, 0, 10, "Reco Tracks"); + hh.create("hReCharge", 7, -3.5, 3.5, "Reco Charge"); + hh.create("hRePtLead", 50, 0, 50., "Reco PtLead (GeV)"); + hh.create("hReMass", 50, 0, 10., "Reco Mass (GeV)"); + hh.create("hReRWid", 50, 0, 0.5, "Reco RWidth2"); + hh.create("hReDNN", 50, 0, 1., "Reco NN"); + + hh.create("hReEta", 31, -3.1, 3.1, "ReEta"); + hh.create("hRePhi", 31, -3.1, 3.1, "RePhi"); + hh.create("hReEtaPhi", 31, -3.1, 3.1, 31, -3.1, 3.1, "ReEta", "RePhi"); + + hh.create("hReEFdEta", 50, -0.25, 0.25, "Reco-EF dEta"); + hh.create("hReEFdPhi", 50, -0.25, 0.25, "Reco-EF dPhi"); + hh.create("hReEFdEtadPhi", 50, -0.25, 0.25, 50, -0.25, 0.25, + "Reco-EF dEta", "dPhi"); + hh.create("hReEFdEt", 50, -25, 25, "Reco Et - EF Et"); + hh.create("hReEFEt", 50, 0.0, 100.0, 50, 0.0, 100.0, "EF Et", "Reco Et"); + + +} + +// define time history plots +void +TTPValTrigPlots::defineTH(unsigned long tlo, unsigned long thi) { + + _thstart = tlo; + + // Make sure we are in the main ROOT directory + gROOT->cd(); + + hh.create("thL1Et", _thbins, 0., thi-tlo, 50, 0.0, 100., "Timestamp", "L1 Et (GeV)"); + hh.create("thL2EtCalib", _thbins, 0., thi-tlo, 50, 0.0, 100., "Timestamp", "L2 EtCalib (GeV)"); + hh.create("thL2NTrk", _thbins, 0., thi-tlo, 10, 0, 10, "Timestamp", "L2 Tracks"); + hh.create("thEFEt", _thbins, 0., thi-tlo, 50, 0, 100., "Timestamp", "EF Et (GeV)"); + hh.create("thEFNTrk", _thbins, 0., thi-tlo, 10, 0, 10, "Timestamp", "EF Tracks"); + +} + +// Zero all histograms +void +TTPValTrigPlots::reset() { + hh.reset(); + _nEvent.reset(); +} + +// More user friendly way to process file +void +TTPValTrigPlots::fill(const TString& filename, double wt) { + + // Open file + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + std::cerr << "Can't open file " << filename << std::endl; + return; + } + + // Initialize tree + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + std::cerr << "Can't find eventTree in " << filename << std::endl; + return; + } + + _fix.setTTPVersion(filename); + setCurrentWeight(wt); + fill(tree); + + delete tree; + delete file; +} + +// Process file +void +TTPValTrigPlots::fill(TTree* tree) { + + if (tree == 0) { + std::cerr << "TTPValTrigPlots::fill - TTree is NULL!" << std::endl; + return; + } + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + tree->SetBranchStatus("mcEvent*", 0); + + int nev = int(tree->GetEntries()); + + // Must do time history plots here (to get time range correct) + unsigned long tlo=0; + unsigned long thi=0; + + event->reset(); + tree->GetEvent(0); + tlo = event->time_stamp; + + if (nev > 0) { + event->reset(); + tree->GetEvent(nev-1); + thi = event->time_stamp; + + defineTH(tlo, thi); + } + + // cout << "Time history lo: " << tlo << " hi: " << thi << endl; + + // Loop over all events + for(int iev = 0; iev<nev; ++iev) { + + event->reset(); + tree->GetEvent(iev); + + // Bugfix + _fix.fix(event); + + // Analyze this event + TrigTauTrigChainList chainList; + chainList.setRoiWordMatching(); + chainList.setHLTAuthor(_hltAuthorType); + chainList.fillChainList(event); + chainList.fillTriggerList(*_selManager); + + long itype; + + unsigned int numCh = chainList.nTrigChains(); + unsigned int numL1 = chainList.nPassL1Chains(); + unsigned int numL2Cal = chainList.nPassL2CalChains(); + unsigned int numL2Trk = chainList.nPassL2Chains(); + unsigned int numEF = chainList.nPassEFChains(); + + // L1 input + itype = 0; + _nEvent.fill(itype, _currentWeight); + hh.fill("hNRoi", itype, numCh, _currentWeight); + if (numCh == 0) continue; + for (unsigned int i=0; i<numCh; i++) { + TrigTauTrigChain ch = chainList.trigChainEntry(i); + fillRoiHist(event, ch, itype, _currentWeight); + } + + // L1 output + itype = 1; + _nEvent.fill(itype, _currentWeight); + hh.fill("hNRoi", itype, numL1, _currentWeight); + if (numL1 == 0) continue; + for (unsigned int i=0; i<numL1; i++) { + TrigTauTrigChain ch = chainList.passL1ChainEntry(i); + fillRoiHist(event, ch, itype, _currentWeight); + } + + // L2Cal output + itype = 2; + _nEvent.fill(itype, _currentWeight); + hh.fill("hNRoi", itype, numL2Cal, _currentWeight); + if (numL2Cal == 0) continue; + for (unsigned int i=0; i<numL2Cal; i++) { + TrigTauTrigChain ch = chainList.passL2CalChainEntry(i); + fillRoiHist(event, ch, itype, _currentWeight); + } + + // L2Trk output + itype = 3; + _nEvent.fill(itype, _currentWeight); + hh.fill("hNRoi", itype, numL2Trk, _currentWeight); + if (numL2Trk == 0) continue; + for (unsigned int i=0; i<numL2Trk; i++) { + TrigTauTrigChain ch = chainList.passL2ChainEntry(i); + fillRoiHist(event, ch, itype, _currentWeight); + } + + // EF output + itype = 4; + _nEvent.fill(itype, _currentWeight); + hh.fill("hNRoi", itype, numEF, _currentWeight); + + + unsigned int numReco = 0; + if (numEF == 0) continue; + for (unsigned int i=0; i<numEF; i++) { + TrigTauTrigChain ch = chainList.passEFChainEntry(i); + fillRoiHist(event, ch, 4, _currentWeight); + + // Also add on tauRec selected + const TrigTauRecOfflineObject* tauRec = ch.tauRec; + if (tauRec == 0) continue; + if (tauRec->m_discriCut < 0.5) continue; + numReco++; + fillRoiHist(event, ch, 5, _currentWeight); + } + hh.fill("hNRoi", 5, numReco, _currentWeight); + + } + + delete event; +} + +void +TTPValTrigPlots::fillRoiHist(const TrigTauEvent* ev, + const TrigTauTrigChain& ch, + unsigned int type, + double wt) { + + const TrigTauL1Object* L1 = ch.L1; + if (L1 == 0) return; + + hh.fill("hL1Et", type, L1->m_TauEnergy/1000., wt); + hh.fill("hL1EmEt", type, L1->m_EmEnergy/1000., wt); + hh.fill("hL1HdEt", type, L1->m_HdCore/1000., wt); + hh.fill("hL1EmI", type, L1->m_EmIsol/1000., wt); + hh.fill("hL1HdI", type, L1->m_HdIsol/1000., wt); + hh.fill("hL1Eta", type, L1->Eta(), wt); + hh.fill("hL1Phi", type, L1->Phi(), wt); + hh.fill("hL1EtaPhi", type, L1->Eta(), L1->Phi(), wt); + + // Time histories + hh.fill("thL1Et", type, ev->time_stamp-_thstart, L1->m_TauEnergy/1000., wt); + + const TrigTauL2Object* L2 = ch.L2; + if (L2 == 0) return; + + hh.fill("hL2EtCalib", type, L2->etClusCalib()/1000., wt); + hh.fill("hL2NStrips", type, L2->m_nStrips, wt); + hh.fill("hL2StrWid2", type, L2->m_stripWidth2, wt); + hh.fill("hL2EMRad", type, L2->m_EMRadius, wt); + hh.fill("hL2IsoFrac", type, L2->m_isoFrac, wt); + + + // L2 track information now in L2 object correctly + hh.fill("hL2NTrk", type, L2->m_nCoreTracks, wt); + hh.fill("hL2NIso", type, L2->m_nIsoTracks, wt); + hh.fill("hL2NSlow", type, L2->m_nSlowTracks, wt); + hh.fill("hL2PtLead", type, L2->m_leadingTrackPt/1000., wt); + if (L2->m_scalarPtSumCore > 0) { + hh.fill("hL2IsoR", type, L2->m_scalarPtSumIso/L2->m_scalarPtSumCore, wt); + } else { + hh.fill("hL2IsoR", type, 99., wt); + } + + hh.fill("hL2Charge", type, L2->m_charge, wt); + + float emEt = L2->m_EMEnergyWide[0]+L2->m_EMEnergyWide[1]+L2->m_EMEnergyWide[2]; + emEt /= TMath::CosH(L2->m_caloEta); + + TLorentzVector trkEMSum; + trkEMSum.SetPtEtaPhiM(emEt, L2->m_caloEta, L2->m_caloPhi, 0.); + trkEMSum += L2->m_3fastest; + hh.fill("hL2EtTrkEM", type, trkEMSum.Et()/1000., wt); + + hh.fill("hL2Eta", type, L2->Eta(), wt); + hh.fill("hL2Phi", type, L2->Phi(), wt); + hh.fill("hL2EtaPhi", type, L2->Eta(), L2->Phi(), wt); + + hh.fill("hL2L1dEta", type, L2->Eta()-L1->Eta(), wt); + hh.fill("hL2L1dPhi", type, L2->DeltaPhi(*L1), wt); + hh.fill("hL2L1dEtadPhi", type, L2->Eta()-L1->Eta(), L2->DeltaPhi(*L1), wt); + + hh.fill("hL2L1dEt", type, L2->etClusCalib()/1000. - L1->m_TauEnergy/1000., wt); + hh.fill("hL2L1Et", type, L1->m_TauEnergy/1000., L2->etClusCalib()/1000., wt); + + // Time histories + hh.fill("thL2EtCalib", type, ev->time_stamp-_thstart, L2->etClusCalib()/1000., wt); + hh.fill("thL2NTrk", type, ev->time_stamp-_thstart, L2->m_nCoreTracks, wt); + + const TrigTauRecObject* EF = ch.EF; + if (EF == 0) return; + + hh.fill("hEFNTrk", type, EF->nTracks(), wt); + hh.fill("hEFCharge", type, EF->charge(), wt); + if (EF->leadingTrack() != 0) + hh.fill("hEFPtLead", type, EF->leadingTrack()->Pt()/1000., wt); + hh.fill("hEFEMRad", type, EF->m_EMRadius, wt); + hh.fill("hEFIsoFrac", type, EF->m_isoFrac, wt); + hh.fill("hEFEt", type, EF->Et()/1000., wt); + // hh.fill("hEFMass", type, EF->Mass()/1000., wt); + hh.fill("hEFEta", type, EF->Eta(), wt); + hh.fill("hEFPhi", type, EF->Phi(), wt); + hh.fill("hEFEtaPhi", type, EF->Eta(), EF->Phi(), wt); + + hh.fill("hEFL2dEta", type, EF->Eta()-L2->Eta(), wt); + hh.fill("hEFL2dPhi", type, EF->DeltaPhi(*L2), wt); + hh.fill("hEFL2dEtadPhi", type, EF->Eta()-L2->Eta(), EF->DeltaPhi(*L2), wt); + + hh.fill("hEFL2dEt", type, EF->Et()/1000. - L2->etClusCalib()/1000., wt); + hh.fill("hEFL2Et", type, L2->etClusCalib()/1000., EF->Et()/1000., wt); + + // Time histories + hh.fill("thEFNTrk", type, ev->time_stamp-_thstart, EF->nTracks(), wt); + hh.fill("thEFEt", type, ev->time_stamp-_thstart, EF->Et()/1000., wt); + + const TrigTauRecOfflineObject* tauRec = ch.tauRec; + if (tauRec == 0) return; + + hh.fill("hReNTrk", type, tauRec->nTracks(), wt); + hh.fill("hReCharge", type, tauRec->charge(), wt); + if (tauRec->leadingTrack() != 0) + hh.fill("hRePtLead", type, tauRec->leadingTrack()->Pt()/1000., wt); + hh.fill("hReMass", type, tauRec->m_MTrk3P/1000., wt); + hh.fill("hReRWid", type, tauRec->m_RWidth2Trk3P, wt); + hh.fill("hReDNN", type, tauRec->m_discriNN, wt); + + hh.fill("hReEta", type, tauRec->Eta(), wt); + hh.fill("hRePhi", type, tauRec->Phi(), wt); + hh.fill("hReEtaPhi", type, tauRec->Eta(), tauRec->Phi(), wt); + + hh.fill("hReEFdEta", type, tauRec->Eta()-EF->Eta(), wt); + hh.fill("hReEFdPhi", type, tauRec->DeltaPhi(*EF), wt); + hh.fill("hReEFdEtadPhi", type, tauRec->Eta()-EF->Eta(), + tauRec->DeltaPhi(*EF), wt); + + hh.fill("hReEFdEt", type, tauRec->Et()/1000. - EF->Et()/1000., wt); + hh.fill("hReEFEt", type, EF->Et()/1000., tauRec->Et()/1000., wt); + return; +} + +void +TTPValTrigPlots::draw(const TString& outfile) { + + TCanvas* c1 = new TCanvas("c1", "", 10, 10, 800, 620); + c1->Divide(3, 2); + hh.drawAll(outfile, 6, c1); + delete c1; + + _nEvent.print(); +} + + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValTriggerBitChecker.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValTriggerBitChecker.cxx new file mode 100644 index 0000000000000000000000000000000000000000..027842a851852a68afdaeeb52428a29e1e08ed55 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValTriggerBitChecker.cxx @@ -0,0 +1,154 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include "TrigTauPerformValidation/TTPValTriggerBitChecker.h" + +using namespace std; + +TTPValTriggerBitChecker::TTPValTriggerBitChecker() { +} + +void +TTPValTriggerBitChecker::setMenuVersion(TrigTauSelectionManager::MENUVERSION version) { + m_analyzer.trigMan.setMenuVersion(version); +} + +void +TTPValTriggerBitChecker::setTauMenu(TrigTauFlags::TRIGGERMENU menu) { + m_menu = menu; + m_analyzer.trigMan.setTauMenu(menu); +} + +void +TTPValTriggerBitChecker::initialize(TrigTauFlags::TRIGGERMENU menu) { + + setTauMenu(menu); + + m_nevents = 0; + + m_L1Cnt.reset(); + m_L2Cnt.reset(); + m_EFCnt.reset(); + + m_L1Cnt.name(1, "L1 match"); + m_L1Cnt.name(2, "L1 select"); + m_L1Cnt.name(3, "L1 bits"); + + m_L2Cnt.name(1, "L2 match"); + m_L2Cnt.name(2, "L2 select"); + m_L2Cnt.name(3, "L2 bits"); + + m_EFCnt.name(1, "EF match"); + m_EFCnt.name(2, "EF select"); + m_EFCnt.name(3, "EF bits"); + +} + +void +TTPValTriggerBitChecker::execute(const TrigTauEvent* event) { + + m_nevents++; + + // Analyze this event (false to not fill MC info) + m_analyzer.analyze(event, false); + + long nL1 = m_analyzer.chainList.nPassL1Chains(); + long nL2 = m_analyzer.chainList.nPassL2Chains(); + long nEF = m_analyzer.chainList.nPassEFChains(); + + if ( (nL1 > 0) && event->decision.passedL1(m_menu) ) { + m_L1Cnt.fill(1); + } else if (nL1 > 0) { + m_L1Cnt.fill(2); + } else if (event->decision.passedL1(m_menu)) { + m_L1Cnt.fill(3); + } + + if ( (nL2 > 0) && event->decision.passedL2(m_menu) ) { + m_L2Cnt.fill(1); + } else if (nL2 > 0) { + m_L2Cnt.fill(2); + } else if (event->decision.passedL2(m_menu)) { + m_L2Cnt.fill(3); + } + + if ( (nEF > 0) && event->decision.passedEF(m_menu) ) { + m_EFCnt.fill(1); + } else if (nEF > 0) { + m_EFCnt.fill(2); + } else if (event->decision.passedEF(m_menu)) { + m_EFCnt.fill(3); + } + +} + +void +TTPValTriggerBitChecker::finalize() { + + cout << "TTPValTriggerBitChecker - Checking menu " + << TrigTauFlags::menuName(m_menu) << endl; + + cout << " Events seen: " << m_nevents << endl; + + cout << " L1Sel match: " << long(m_L1Cnt.getN(1)) + << " TTP only: " << long(m_L1Cnt.getN(2)) + << " EvBits only: " << long(m_L1Cnt.getN(3)) << endl; + + cout << " L2Sel match: " << long(m_L2Cnt.getN(1) ) + << " TTP only: " << long(m_L2Cnt.getN(2)) + << " EvBits only: " << long(m_L2Cnt.getN(3)) << endl; + + cout << " EFSel match: " << long(m_EFCnt.getN(1) ) + << " TTP only: " << long(m_EFCnt.getN(2)) + << " EvBits only: " << long(m_EFCnt.getN(3)) << endl; +} + +void +TTPValTriggerBitChecker::processFile(const char* filename, + TrigTauFlags::TRIGGERMENU menu) { + + // Open file + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + cerr << "Can't open file " << filename << endl; + return; + } + + // Initialize tree + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + cerr << "Can't find eventTree in " << filename << endl; + return; + } + + processFile(tree, menu); + + delete tree; + delete file; +} + +void +TTPValTriggerBitChecker::processFile(TTree* tree, + TrigTauFlags::TRIGGERMENU menu) { + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + tree->SetBranchStatus("mcEvent*", 0); + + initialize(menu); + long nev = tree->GetEntries(); + for (long iev = 0; iev < nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + + execute(event); + } + + finalize(); + + delete event; +} + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValVariables.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValVariables.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d73da3d51455b369bda0110db4fb58e339991d59 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TTPValVariables.cxx @@ -0,0 +1,421 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +using namespace std; +#include "TrigTauPerformValidation/TTPValVariables.h" + + + +TTPValVariables::TTPValVariables(TrigTauBugFix::TTPVERSION /*version*/, bool debug1) { + cout << "WARNING: Filename not specified!! " << endl; + initialize(debug1); + fileDefined = false; + return; +} + +TTPValVariables::TTPValVariables ( char * filename1, TrigTauBugFix::TTPVERSION version, bool debug1) + : bugfix(version, TrigTauBugFix::RDO) { + + if (debug1) cout << " Creating validation4 object..." << endl; + filename = filename1; + chain = new TChain("eventTree"); + chain->Add(filename); + initialize(debug1); + fileDefined = true; + +} + +void TTPValVariables::initialize(bool debug1) { + + cout << "INFO: No cuts on events. If cuts are needed, please set them." << endl; + cout << "INFO: Signal set to false by default." << endl; + cout << "INFO: plotAllMatchedEvents set to true by default." << endl; + + debug = debug1; + signal = false; + maxVisEta = 0.0; + minLeadingPt = 0.0; + plotAllMatchedEvents = true; + nProng = 0; + menu = TrigTauFlags::TAU20; + cutLevel = TrigTauSelectionManager::LOOSE; + offlineType = TrigTauMCTauList::TAUCUTSAFEMEDIUM; + menuVersion = TrigTauSelectionManager::MENU1560; + chainType = TrigTauFlags::SITRK; +} + + +void TTPValVariables::setPlotAllEvents (bool newValue) { + + ignoreMatching = newValue; + if (newValue == true) plotAllMatchedEvents = true; + return; +} + + + +void TTPValVariables::setFile( char * filename1) { + filename = filename1; + chain = new TChain("eventTree"); //potential memory leak + chain->Add(filename); + fileDefined = true; + return; +} + + +void TTPValVariables::analyze(int number, bool chains, bool l1, bool l2 , bool efid, bool ef) { + + if (!fileDefined) { + cout << "File was not defined and variables not initialized!!" << endl; + return; + } + + selmanager.setMenuVersion(menuVersion); + selmanager.setTauMenu(menu, cutLevel); + if (debug) cout << "Validation object created!!" << endl; + + + // MC truth + analyzer.truthList.setMaxVisEta(maxVisEta); + //analyzer.truthList.setMinVisPt(menu); // in GeV + analyzer.truthList.setMinLeadingPt(minLeadingPt); // pt of the leading pt of track is + if ( nProng == 1 ) analyzer.truthList.select1Prong(); + else if ( nProng == 2 ) analyzer.truthList.select3Prong(); + analyzer.truthList.setRecoMatchdR(0.2); + analyzer.trigMan.setL1MET(0.); + analyzer.trigMan.setMenuVersion(menuVersion ); + analyzer.trigMan.setTauMenu(menu, cutLevel); + analyzer.chainList.setRoiWordMatching(false); + analyzer.chainList.setHLTAuthor(chainType); + + + event = new TrigTauEvent(); + chain->SetBranchAddress("EventBranch", &event); + chain->SetBranchStatus("*", 1); + + // Also set an L1 MET cut if desired + + int nev = int(chain->GetEntries()); + if ( nev > number ) nev = number; + for(int iev = 0; iev<nev; ++iev) { + analyzeEvent( iev, chains, l1, l2, efid, ef ); + } +} + + +void TTPValVariables::analyzeEvent(int eventNumber, bool chains, bool l1, bool l2 , bool efid, bool ef) { + + event->reset(); + chain->GetEvent(eventNumber); + bugfix.fix(event); + + cout << "\nAnalyzing EVENT NUMBER " << event->eventNumber << endl; + cout << "RUN NUMBER\t" << event->runNumber << endl; + + cout << "Number of Objects:" << "\tL1:\t" << event->tauL1.size() << "\tL2:\t" << event->tauL2.size() << "\tEF:\t" << event->tauEF.size(); + + if( chains ){ +// analyzer.analyze(event, signal, offlineType); + +// // ============ Select type of events (e.g. signal) ================ +// if( signal ) { +// if ( analyzer.truthList.nMCTauGood() ==0 ) cout << "Event contains no good taus! " << endl; +// if( analyzer.truthList.nMCTauGood() ==0 ) return; +// } + +// // loop over taus after fiducial cuts + +// //const TrigTauMCTau * truth = & analyzer.truthList.mcTauGoodEntry(iTrue); //select tau + +// unsigned int nTrigChains = analyzer.chainList.nTrigChains() ; +// cout << "Number of Chains: " << nTrigChains << endl; + //if (nTrigChains == 0) return; + +// vector<TrigTauTrigChain> chainlist; +// for (unsigned int ichain = 0; ichain !=nTrigChains; ++ichain) { +// chainlist.push_back(analyzer.chainList.trigChainEntry(ichain)); +// } + +// //sorting algorithm +// for (int pass=0; pass!=nTrigChains; pass++) { +// int potentialSmallest = pass; // assume this is smallest +// if (debug) cout << "\nPotential Smallest: " << potentialSmallest << " with " << chainlist[potentialSmallest].L1->Phi() << endl; +// //--- Look over remaining elements to find smallest. +// for (int i=pass+1; i<nTrigChains; i++) { +// if (chainlist[i].L1->Phi() < chainlist[potentialSmallest].L1->Phi() ) { +// //--- Remember index for latter swap. +// potentialSmallest = i; +// if (debug) cout << "New Potential Smallest: " << potentialSmallest << " with " << chainlist[potentialSmallest].L1->Phi() << endl; +// } +// } + +// //--- Swap smallest remaining element +// TrigTauTrigChain temp = chainlist[pass]; +// chainlist[pass] = chainlist[potentialSmallest]; +// chainlist[potentialSmallest] = temp; +// } + //starting printing of individual chains +// for( unsigned int ichain = 0; ichain != nTrigChains; ++ichain) { +// cout << "\nStarting chain " << ichain << "!" << endl; +// TrigTauTrigChain *ch = &chainlist[ichain]; +// const TrigTauL1Object* l1object = ch->L1; +// const TrigTauL2Object* l2object = ch->L2; +// const TrigTauL2Object* l2calobject = ch->L2Cal; +// const TrigTauL2Object* l2trkobject = ch->L2Trk; +// const TrigTauRecEFObject* efobject = ch->EF; + + +// //check Level 1 +// if (l1object == 0 && !plotAllMatchedEvents) { +// if ( debug ) cout << "L1 Object is empty; go to next chain" << endl; +// continue; +// } +// if( !l1object == 0 ) { +// unsigned int currentWord = printL1(l1object); +// if (!plotAllMatchedEvents && currentWord != 0 ) continue; +// } +// else if (!plotAllMatchedEvents) continue; + +// //check Level 2 (including Trk and Cal) +// if (l2object == 0 && !plotAllMatchedEvents) { +// if ( debug ) cout << "L2 object is empty; go to next chain" << endl; +// continue; +// } +// if( !(l2object == 0))// && ((truth->DeltaR(*l2object)<0.2) || ignoreMatching) ) +// { + +// unsigned int currentWord1 = printL2Calo(l2caloobject); +// unsigned int currentWord2 = printL2Trk(l2object); +// printL2Combined(l2object); + +// if ( (currentWord1 !=0 || currentWord2 !=0) && !plotAllMatchedEvents ) continue; +// } +// else if (!plotAllMatchedEvents) continue; + + +// //check EF +// if (efobject == 0) { +// if ( debug ) cout << "EF object is empty; go to next chain" << endl; +// continue; +// } +// //if ( truth->DeltaR(*efobject)<0.2 || ignoreMatching ) { +// unsigned int currentWord = printEF(efobject); +// // } //only uncomment with offline matching + + +// if (debug ) cout << "All levels for chain " << ichain << " checked." << endl; +// } // end chain loop + + } + + + + //implement: loop over all tauObjects and see if the are attached to TrigChain + + /*************************************************************************** + DO NOT USE CHAINS AFTER THIS POINT. sorting MODIFIES POINTERS in EVENT + or re-do chains after sorting! + ***************************************************************************/ + if( l1 ){ + sort(event->tauL1.begin(), event->tauL1.end(), less_roiWordL1()); + for(unsigned int iL1 = 0; iL1 < event->nTauL1(); ++iL1) + printL1(&event->tauL1Entry(iL1)); + } + + if( l2 ) { + sort(event->tauL2.begin(), event->tauL2.end(), less_Et()); + for(vector<TrigTauL2Object*>::iterator itau = event->tauL2.begin(); itau != event->tauL2.end(); ++itau) + sort((*itau)->tracks.begin(), (*itau)->tracks.end(), less_Et()); + for(unsigned int iL2 = 0; iL2 < event->tauL2.size(); ++iL2) + { + printL2Combined(event->tauL2[iL2]); + printL2Calo(event->tauL2[iL2]); + printL2Trk(event->tauL2[iL2]); + } + } + + if ( ef ) { + sort(event->tauEF.begin(), event->tauEF.end(), less_EF()); + for(unsigned int iEF = 0; iEF < event->tauEF.size(); ++iEF) + printEF(event->tauEF[iEF]); + + } + + if( efid) { + + // DO NOT sort EF tracks = they are saved in TRefArray, and are pointed to + // IF you use following, do not use EF tracks anymore!! + + // if roiWord is correct : + //sort(event->tracksRoIEF.begin(), event->tracksRoIEF.end(), less_roiWordEFID()); + for(vector<TrigTauTrackCollection*>::iterator itau = event->tracksRoIEF.begin(); + itau != event->tracksRoIEF.end(); ++itau) + sort((*itau)->tracks.begin(), (*itau)->tracks.end(), less_Et()); + + for(unsigned int iEF = 0; iEF < event->tracksRoIEF.size(); ++iEF) + printEFID(event->tracksRoIEF[iEF]); + } + + +return; +} + + + +int TTPValVariables::printL1(const TrigTauL1Object * l1object) +{ + unsigned int currentWord = selmanager.l1Sel.cutWord(*l1object); + cout << "\n==========LEVEL 1 ========= \nWord:\t" << currentWord ; + cout << "\t\tChainPosition: Eta:\t" << l1object->Eta() << "\tPhi:\t" << l1object->Phi() << endl; + cout << "RoIWord:\t" << setprecision(4) << l1object->m_roiWord; + cout << "\tEnergy:\t" << setprecision(4) << l1object->m_TauEnergy; + cout << "\tEmIsol:\t" << setprecision(4) << l1object->m_EmIsol << endl; + //cout << "\tHadIsol:\t" << setprecision(4) << l1object->m_HdIsol; + //cout << "\tEmCore:\t" << setprecision(4) << l1object->m_EmCore; + //cout << "\tHadCore:\t" << setprecision(4) << l1object->m_HdCore; + //cout << "\tEmEnergy:\t" << setprecision(4) << l1object->m_EmEnergy << endl; + //histograms[0*3+j]->Fill(l1object->m_EmEnergy); + //histograms[0*3+j]->Fill(l1object->m_EmEnergy); + return currentWord; +} + +int TTPValVariables::printL2Calo(const TrigTauL2Object * l2calobject) +{ + unsigned int currentWord1 = selmanager.l2CalSel.cutWord(*l2calobject); + cout << "\n\n=========Level 2 Calo ==========\nWord: \t" << currentWord1; + cout << "\t\tChainPosition: Eta:\t" << l2calobject->Eta() << "\tPhi:\t" << l2calobject->Phi(); + cout << "\nEtCluster:\t" << setprecision(4) << l2calobject->etClus(); + cout << "\tEtCalib:\t" << setprecision(4) << l2calobject->etClusCalib(); + cout << "\tnStrips:\t" << setprecision(4) << l2calobject->m_nStrips; + cout << "\tStripWidth:\t" << setprecision(4) << l2calobject->m_stripWidth2; + cout << "\nEmRadius:\t" << setprecision(4) << l2calobject->m_EMRadius; + cout << "\tIsoFrac:\t" << setprecision(4) << l2calobject->m_isoFrac; + cout << "\tEmEnergyWidth:\t" << setprecision(4) << l2calobject->m_EMEnergyWidth[2]; + cout << "\tEtNarrow:\t" << setprecision(4) << l2calobject->etNarrow(); + cout << "\tCaloEta:\t" << setprecision(4) << l2calobject->m_caloEta; + cout << "\nCaloPhi:\t" << setprecision(4) << l2calobject->m_caloPhi; + cout << "\tEmEnergyWide:\t" << setprecision(4) << l2calobject->m_EMEnergyWide[0]+l2calobject->m_EMEnergyWide[1]+l2calobject->m_EMEnergyWide[2]+l2calobject->m_EMEnergyWide[3]; + cout << "\tHadEnergyWide:\t" << setprecision(4) << l2calobject->m_HadEnergyWide[0]+l2calobject->m_HadEnergyWide[1]+l2calobject->m_HadEnergyWide[2]; + return currentWord1; +} + +int TTPValVariables::printL2Trk(const TrigTauL2Object * l2object) +{ + unsigned int currentWord2 = selmanager.l2TrkSel.cutWord(*l2object); + + cout << "\n\n=========Level 2 Track ==========\nWord: \t" << currentWord2; + cout << "\t\tChainPosition: Eta:\t" << l2object->Eta() << "\tPhi:\t" << l2object->Phi(); + cout << "\nnCoreTracks:\t" << setprecision(4) << l2object->m_nCoreTracks; + cout << "\tnSlowTracks:\t" << setprecision(4) << l2object->m_nSlowTracks; + cout << "\tnIsoTracks:\t" << setprecision(4) << l2object->m_nIsoTracks; + cout << "\tnMatchedTracks:\t" << setprecision(4) << l2object->m_nMatchedTracks; + cout << "\tCharge:\t" << setprecision(4) << l2object->m_charge; + cout << "\nPtLeadingTrack:\t" << setprecision(4) << l2object->m_leadingTrackPt; + cout << "\tPtSumRatio:\t" << setprecision(4) << l2object->m_scalarPtSumIso/l2object->m_scalarPtSumCore; + cout << "\tTotal pt:\t" << setprecision(4) << l2object->ptTot(); + + unsigned int ntracks = l2object->nTracks(); + cout << "\n\nLooping over all tracks:\t"<< ntracks<< endl; + const TrigTauTrack * track = 0; + for (unsigned int iTrk = 0; iTrk!=ntracks; ++iTrk) { + track =l2object->tracks[iTrk]; + cout << "Printing Track number " << iTrk << endl; + cout << "Pt:\t" << track->Pt(); + cout << "\tEta:\t" << track->Eta(); + cout << "\tPhi:\t" << track->Phi(); + cout << "\ta0:\t" << track->m_a0 << endl; + } + cout << "\nPtSumCore:\t" <<l2object->m_scalarPtSumCore; + cout << "\tPtSumIsol:\t" <<l2object->m_scalarPtSumIso; + return currentWord2; +} + +int TTPValVariables::printL2Combined(const TrigTauL2Object * l2object) +{ + cout << "\n\n=========Level 2 Combined ==========" << endl;; + //cout << "\nRoIWord:\t" << setprecision(4) << l2object->m_roiWord; + cout << "\tEtaCombined:\t" << l2object->Eta(); + cout << "\tPhiCombined:\t" << l2object->Phi(); + cout << "\nEtCombined:\t" << l2object->m_EtCalib << endl; + cout << "\tm_tags:\t" << endl; l2object->m_tags.print(); + return 0; +} + +int TTPValVariables::printEF(const TrigTauRecEFObject * efobject) +{ + unsigned int currentWord = selmanager.efSel.cutWord(*efobject); + + cout << "\n\n========= Event Filter ==========\nWord: \t" << currentWord; + cout << "\t\tChainPosition: Eta:\t" << efobject->Eta() << "\tPhi:\t" << efobject->Phi(); + cout << "\nEt:\t"<<efobject->Et(); + cout << "\tSeedType:\t" << efobject->m_seedType; + cout << "\nRoIWord:\t" << setprecision(4) << efobject->m_roiWord; + //cout << "\nnTracks:\t" << setprecision(4) << efobject->nTracks(); + cout << "\tEmRadius:\t" << setprecision(4) << efobject->m_EMRadius; + cout << "\tEmRadius1p3p:\t" << setprecision(4) << efobject->m_EMRadius_1p3p; + cout << "\tIsoFrac:\t" << setprecision(4) << efobject->m_isoFrac; + float emFrac=0; + if (efobject->m_etEMCalib>0 ) emFrac = efobject->m_etEMCalib/(efobject->m_etEMCalib + efobject->m_etHadCalib); + cout << "\tEmFrac:\t" << setprecision(4) << emFrac; + float ptMax = 999999999.; + if (efobject->nTracks() ) ptMax = efobject->leadingTrack()->Pt(); + cout << "\tMaxPt:\t" << setprecision(4) << ptMax; + cout << "\nEt\t" << setprecision(4) << efobject->Et(); + cout << "\tEmEt:\t" << setprecision(4) << efobject->m_energy/cosh(efobject->m_caloEta); + //histograms[30*3+j]->Fill(efobject->mass()); mass is more complicated; will be added later. + cout << "\tMass:\t" << "not implemented, yet"; + if (debug) cout << "All histograms filled..." << endl; + if ( currentWord == 0 && debug ) cout << "Tau passed trigger!!!" << endl; + + cout << "\tEmCalib:\t" << efobject->m_etEMCalib; + cout << "\nHadCalib:\t" << efobject->m_etHadCalib; + cout << "\tSumHadCellEt:\t" << efobject->m_sumHadCellEt; + cout << "\tSumEmCellEt:\t" << efobject->m_sumEmCellEt; + cout << "\tHadRadius:\t" << efobject->m_hadRadius; + cout << "\nMTrk3P:\t" << efobject->m_MTrk3P; + cout << "\tEmRadius1P3P:\t" << efobject->m_EMRadius_1p3p; + cout << "\tEfEFlow:\t" << efobject->m_etEFlow; + cout << "\tMVisEFlow:\t" << efobject->m_MvisEflow; + + + cout << "\n\nLooping over all tracks:"; + //unsigned int nTracks = efobject->nTracks(); +// const TrigTauTrack * track = 0; //possible memory leak +// for (unsigned int iTrk = 0; iTrk!=nTracks; ++iTrk) { + +// track = &efobject->track(iTrk); +// cout << "\nPrinting Track number " << iTrk << endl; + +// cout << "Pt:\t" << track->Pt(); +// cout << "\tEta:\t" << track->Eta(); +// cout << "\tPhi:\t" << track->Phi(); +// cout << "\ta0:\t" << track->m_a0 << endl; +// } + cout << "\tm_tags:\t" << endl; efobject->m_tags.print(); + + return currentWord; +} + + +int TTPValVariables::printEFID(const TrigTauTrackCollection * object) +{ + + cout << "\n\n=========Level EF Tracks ==========\n"; + cout << "\nRoIWord:\t" << setprecision(4) << object->m_roiWord; + + unsigned int ntracks = object->nTracks(); + cout << "\n\nLooping over all tracks:\t"<< ntracks<< endl; + const TrigTauTrack * track = 0; + for (unsigned int iTrk = 0; iTrk!=ntracks; ++iTrk) { + track =object->tracks[iTrk]; + cout << "Printing Track number " << iTrk << endl; + cout << "Pt:\t" << track->Pt(); + cout << "\tEta:\t" << track->Eta(); + cout << "\tPhi:\t" << track->Phi(); + cout << "\ta0:\t" << track->m_a0 << endl; + } + return 0; +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauCounter.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauCounter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9a7469d60737065fcd3a3e73a74f3d0d9685bd89 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauCounter.cxx @@ -0,0 +1,117 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "TrigTauPerformValidation/TrigTauCounter.h" + +#include <iostream> +#include <math.h> + +using namespace std; + +TrigTauCounter::TrigTauCounter() : _n(100), _wt(100), _wt2(100), _name(100) +{} + +void +TrigTauCounter::print() const { + vector<string>::const_iterator istr = _name.begin(); + vector<double>::const_iterator in = _n.begin(); + vector<double>::const_iterator iwt = _wt.begin(); + vector<double>::const_iterator iwt2 = _wt2.begin(); + + for (in = _n.begin(); in != _n.end(); in++) { + + if (istr < _name.end()) { + cout << *istr << " "; + } + cout << "N:" << *in << " "; + cout << "Wt: " << *iwt << " +/- "; + cout << sqrt(*iwt2); + cout << endl; + istr++; + iwt++; + iwt2++; + } +} + +void +TrigTauCounter::reset() { + _name.clear(); + clear(); +} + +void +TrigTauCounter::clear() { + _n.clear(); + _wt.clear(); + _wt2.clear(); +} + +void +TrigTauCounter::fill(unsigned long entry, double weight) { + if (entry >= getSize()) { + _n.resize(entry+1); + _wt.resize(entry+1); + _wt2.resize(entry+1); + } + _n[entry]++; + _wt[entry] += weight; + _wt2[entry] += weight*weight; +} + +unsigned long +TrigTauCounter::getSize() const { + return _wt.size(); +} + +void +TrigTauCounter::add(const TrigTauCounter& other) { + + if (getSize() == 0) { + _n.resize(other.getSize()); + _wt.resize(other.getSize()); + _wt2.resize(other.getSize()); + } else if (getSize() != other.getSize()) { + cout << "TrigTauCounter::add() - Size mismatch!" << endl; + return; + } + + for (unsigned long entry = 0; entry < getSize(); entry++) { + _n[entry] += other.getN(entry); + _wt[entry] += other.getWt(entry); + _wt2[entry] += other.getWt2(entry); + } +} + +void +TrigTauCounter::name(unsigned long entry, string name) { + if (entry >= _name.size()) { + _name.resize(entry+1); + } + _name[entry] = name; +} + +double +TrigTauCounter::getN(unsigned long entry) const { + return _n[entry]; +} + +double +TrigTauCounter::getWt(unsigned long entry) const { + return _wt[entry]; +} + +double +TrigTauCounter::getWt2(unsigned long entry) const { + return _wt2[entry]; +} + +double +TrigTauCounter::getDWt(unsigned long entry) const { + return sqrt(_wt2[entry]); +} + +string +TrigTauCounter::getName(unsigned long entry) const { + return _name[entry]; +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauEffTool.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauEffTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9789ef884c1105544574dc5058bc2999dfd166e6 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauEffTool.cxx @@ -0,0 +1,677 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +#include <string> +#include <algorithm> + +using namespace std; + +#include "TrigTauPerformNtuple/TrigTauEvent.h" +#include "TrigTauPerformNtuple/TrigTauMCTauList.h" +#include "TrigTauPerformAnalysis/TrigTauTrigChainList.h" +#include "TrigTauPerformValidation/TrigTauEffTool.h" + +TrigTauEffTool::TrigTauEffTool() { + _debug = true; + _recoMatch = true; + + _currentSample = ""; + + _defVersion = TrigTauSelectionManager::MENU13030pre; + + _selectors.clear(); + _counters.clear(); + _cuts.clear(); + + _samples.clear(); + +} + +TrigTauEffTool::~TrigTauEffTool() { + for (map<TString, TrigTauSelectionManager*>::iterator imap = _selectors.begin(); + imap != _selectors.end(); imap++) { + delete imap->second; + } + + for (map<TString, TrigTauCounter*>::iterator imap = _counters.begin(); + imap != _counters.end(); imap++) { + delete imap->second; + } + + for (map<TString, TrigTauEffCuts*>::iterator imap = _cuts.begin(); + imap != _cuts.end(); imap++) { + delete imap->second; + } +} + +void +TrigTauEffTool::setDefaultVersion(TrigTauSelectionManager::MENUVERSION version) { + _defVersion = version; +} + +void +TrigTauEffTool::defineSelector(TrigTauFlags::TRIGGERMENU menu) { + TrigTauFlags f; + defineSelector(f.menuName(menu), menu, _defVersion); +} + +void +TrigTauEffTool::defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu) { + defineSelector(tag, menu, _defVersion); +} + +void +TrigTauEffTool::defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu, + TrigTauSelectionManager::MENUVERSION version) { + + if (_selectors[tag] != NULL) { + cerr << "TrigTauEffTool::defineSelector - Selector with tag " << tag << + " already defined!" << endl; + return; + } + + TrigTauSelectionManager* sel = new TrigTauSelectionManager(); + sel->setMenuVersion(version); + sel->setTauMenu(menu); + // Enable EF debug (temporary) + // sel->efSel.setDebug(); + + _selectors[tag] = sel; + + // Also define a cuts object for this selector + TrigTauEffCuts* cut = new TrigTauEffCuts(); + cut->minVisPt = TrigTauMCTauList::nominalMinVisPt(menu); + + _cuts[tag] = cut; + + return; +} + +void +TrigTauEffTool::setPtCut(TString tag, double visPt) { + TrigTauEffCuts* cut = getCuts(tag); + if (cut != 0) cut->minVisPt = visPt; +} + +TrigTauSelectionManager* +TrigTauEffTool::getSelector(TString tag) { + if (_selectors[tag] == NULL) + cerr << "TrigTauEffTool::getSelector - No selector with tag " << tag << endl; + return _selectors[tag]; +} + +TrigTauEffCuts* +TrigTauEffTool::getCuts(TString tag) { + if (_cuts[tag] == NULL) + cerr << "TrigTauEffTool::getCuts - No cuts with tag " << tag << endl; + return _cuts[tag]; +} + +TrigTauCounter* +TrigTauEffTool::getCounter(TString selectorTag, TString sampleTag) { + TString tag = selectorTag + TString("_")+sampleTag; + if (_counters[tag] == NULL) { + if (_debug) + cout << "TrigTauEffTool::getCounter - No counter with tag " << tag + << " making new" << endl; + _counters[tag] = makeNewCounter(); + + // Check if the sample tag exists, if not add it here + if (find(_samples.begin(), _samples.end(), sampleTag) == _samples.end()) + defineSample(sampleTag); + + } + + return _counters[tag]; +} + +void +TrigTauEffTool::defineSample(TString tag) { + _samples.push_back(tag); +} + +void +TrigTauEffTool::fillSample(TString tag, TString filename) { + + // Open file + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + cerr << "Can't open file " << filename << endl; + return; + } + + // Initialize tree + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + cerr << "Can't find eventTree in " << filename << endl; + return; + } + + _fix.setTTPVersion(filename); + setCurrentSample(tag); + fillSample(tree); + + delete tree; + delete file; +} + +void +TrigTauEffTool::fillSample(TTree *tree) { + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + + // Loop over all events + int nev = int(tree->GetEntries()); + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + + // Bugfix + _fix.fix(event); + + // Loop over defined selectors + for (map<TString, TrigTauSelectionManager*>::iterator imap = _selectors.begin(); + imap != _selectors.end(); imap++) { + + TString seltag = imap->first; + + // Must apply new fiducial cuts here for different selector tags + // Get fiducial cuts here + TrigTauEffCuts* cuts = getCuts(seltag); + TrigTauMCTauList truthList; + cuts->setFiducialCuts(truthList); + + truthList.fillPureList(&event->mcEvent); + truthList.fillGoodList(); + if (_recoMatch) + truthList.requireRecoMatch(*event); + + // Apply the trigger selection and make chains + TrigTauTrigChainList chainList; + chainList.setRoiWordMatching(); + chainList.fillChainList(event); + + TrigTauSelectionManager* selman = imap->second; + + // Fill trigger chain list for this selection manager + chainList.fillTriggerList(*selman); + + // Get counters + TrigTauCounter* eff = getCounter(seltag, _currentSample); + + // Loop over all found good taus + unsigned int nTau = truthList.nMCTauGood(); + for (unsigned int itau=0; itau<nTau; itau++) { + + const TrigTauMCTau* tau = &truthList.mcTauGoodEntry(itau); + + // All events (denominator) + eff->fill(0); + + const TrigTauTrigChain* chain; + + // Need a generic, non-selected ROI chain... + chain = chainList.getChain(*tau); + + if (chain != 0) { + + // Sequential L1 cuts + unsigned long l1Word = selman->l1Sel.cutWord(*(chain->L1)); + + eff->fill(10); + if ((l1Word & L1CUT_TAUCLUS) == 0) { + eff->fill(11); + if ((l1Word & L1CUT_EMISOL) == 0) eff->fill(12); + } + } + + // Find a matching L1 chain + chain = chainList.getL1Chain(*tau); + if (chain != 0) { + eff->fill(1); + + // Sequential L2Cal cuts + if (chain->L2 != 0) { + eff->fill(20); + + unsigned long l2Word = selman->l2CalSel.cutWord(*(chain->L2)); + + if ((l2Word & L2CUT_STRWID) == 0) { + eff->fill(21); + if ((l2Word & L2CUT_ISOFRAC) == 0) { + eff->fill(22); + if ((l2Word & L2CUT_EMRAD) == 0) { + eff->fill(23); + if ((l2Word & L2CUT_ETCALIB) == 0) { + eff->fill(24); + if ((l2Word & L2CUT_ETNAR) == 0) { + eff->fill(25); + } + } + } + } + } + } + + } + + // Find a matching L2Cal chain + chain = chainList.getL2CalChain(*tau); + if (chain != 0) { + eff->fill(2); + + // Sequential L2Trk cuts + unsigned long l2Word = selman->l2TrkSel.cutWord(*(chain->L2)); + if ((l2Word & L2CUT_LEADPT) == 0) { + eff->fill(31); + if ((l2Word & L2CUT_NSLOW) == 0) { + eff->fill(32); + if ((l2Word & L2CUT_RISO) == 0) { + eff->fill(33); + if ((l2Word & L2CUT_CHARGE) == 0) { + eff->fill(34); + if ((l2Word & L2CUT_NTRK) == 0) { + eff->fill(35); + if ((l2Word & L2CUT_ETTRKEM) == 0) { + eff->fill(36); + if ((l2Word & L2CUT_NMATCHED) == 0) { + eff->fill(37); + } + } + } + } + } + } + } + + } + + // Find a matching L2Cal + L2Trk chain + chain = chainList.getL2Chain(*tau); + if (chain != 0) { + eff->fill(3); + + // Sequential EF cuts + if (chain->EF != 0) { + eff->fill(40); + + unsigned long efWord = selman->efSel.cutWord(*(chain->EF)); + + if ((efWord & EFCUT_EMRAD) == 0) { + eff->fill(41); + if ((efWord & EFCUT_ISOFRAC) == 0) { + eff->fill(42); + if ((efWord & EFCUT_NTRKMIN) == 0 && (efWord & EFCUT_NTRKMAX) == 0) { + eff->fill(43); + if ((efWord & EFCUT_LEADPT) == 0) { + eff->fill(44); + if ((efWord & EFCUT_MASS) == 0) { + eff->fill(45); + if ((efWord & EFCUT_ETCORR) == 0) { + eff->fill(46); + if ((efWord & EFCUT_EMET) == 0) { + eff->fill(47); + } + } + } + } + } + } + } + } + } + + // Find a matching EF chain + chain = chainList.getEFChain(*tau); + if (chain != 0) eff->fill(4); + + } // end loop over taus + + } // end loop over selectors + } // end loop over events + + delete event; +} + +TrigTauCounter* +TrigTauEffTool::makeNewCounter() { + TrigTauCounter* count = new TrigTauCounter(); + count->reset(); + count->name(0, string("L1 In ")); + count->name(1, string("L1 Out")); + count->name(2, string("L2Cal Out")); + count->name(3, string("L2Trk Out")); + count->name(4, string("EF Out")); + return count; +} + +void +TrigTauEffTool::print() { + + for (map<TString, TrigTauCounter*>::iterator imap = _counters.begin(); + imap != _counters.end(); imap++) { + TrigTauCounter* c = imap->second; + cout << imap->first << endl; + c->print(); + } + +} + +void +TrigTauEffTool::printSelector(TString seltag, bool latex) { + + if (latex) cout << "\\hline" << endl; + if (latex) { + cout << "\\multicolumn{4}{c}{{\\tt " << seltag << " }} \\\\" << endl; + } else { + cout << seltag << endl; + } + if (latex) cout << "\\hline" << endl; + + TrigTauCounter* c; + + // Sort sample list (to put Sum at the end) + // _samples.sort(); + + // Loop over defined samples and print out what we have + list<TString>::iterator ilist; + for (ilist = _samples.begin(); ilist != _samples.end(); ilist++) { + c = getCounter(seltag, *ilist); + + // Make sure we got something + if (c == 0) { + cout << "Counter for selector " << seltag << " and sample " << *ilist + << " is NULL!" << endl; + continue; + } + + // Now print + printRateLine(c, *ilist, latex); + } + + if (latex) cout << "\\hline" << endl; + +} + +// Print samples (columns) vs. selector (rows) +void +TrigTauEffTool::printSummary() { + + TrigTauCounter* c; + + cout << "\\hline\\hline" << endl; + + // Print header + list<TString>::iterator ilist; + for (ilist = _samples.begin(); ilist != _samples.end(); ilist++) { + cout << " & " << *ilist; + } + cout << "\\\\" << endl; + cout << "\\hline" << endl; + + // Loop over all selectors + map<TString, TrigTauSelectionManager*>::iterator isel; + for (isel = _selectors.begin(); isel != _selectors.end(); isel++) { + + TString seltag = isel->first; + cout << "\\sig{" << seltag << "} "; + + for (ilist = _samples.begin(); ilist != _samples.end(); ilist++) { + c = getCounter(seltag, *ilist); + + // Make sure we got something + if (c == 0) { + cout << "Counter for selector " << seltag << " and sample " << *ilist + << " is NULL!" << endl; + continue; + } + + cout << setprecision(1); + cout << " & " << 100*c->getWt(4)/c->getWt(0); + } + cout << " \\\\" << endl; + } + cout << "\\hline\\hline" << endl; +} + +// Print samples (columns) vs. selector (rows) +void +TrigTauEffTool::printL1Summary() { + + TrigTauCounter* c; + + cout << "\\hline\\hline" << endl; + + // Print header + list<TString>::iterator ilist; + for (ilist = _samples.begin(); ilist != _samples.end(); ilist++) { + cout << " & " << *ilist; + } + cout << "\\\\" << endl; + cout << "\\hline" << endl; + + // Loop over all selectors + map<TString, TrigTauSelectionManager*>::iterator isel; + for (isel = _selectors.begin(); isel != _selectors.end(); isel++) { + + TString seltag = isel->first; + cout << "\\sig{" << seltag << "} "; + + for (ilist = _samples.begin(); ilist != _samples.end(); ilist++) { + c = getCounter(seltag, *ilist); + + // Make sure we got something + if (c == 0) { + cout << "Counter for selector " << seltag << " and sample " << *ilist + << " is NULL!" << endl; + continue; + } + + cout << setprecision(1); + cout << " & " << 100*c->getWt(1)/c->getWt(0); + } + cout << " \\\\" << endl; + } + cout << "\\hline\\hline" << endl; +} + +// Print samples (columns) vs. individual cuts (rows) +void +TrigTauEffTool::printCutFlow(TString seltag) { + + cout << "\\hline\\hline" << endl; + + // Print header, listing samples + list<TString>::iterator ilist; + for (ilist = _samples.begin(); ilist != _samples.end(); ilist++) { + cout << " & \\multicolumn{3}{c}{" << *ilist << "}"; + } + cout << "\\\\" << endl; + cout << "\\hline" << endl; + + // Write out selector tag + cout << "\\multicolumn{" << 3 * _samples.size()+1 + << "}{c}{\\sig{ " << seltag << " }} \\\\" << endl; + cout << "\\hline" << endl; + + switch(_defVersion) { + + case TrigTauSelectionManager::MENU13030pre: + cout << "L1 ROI "; printCutFlowLine(seltag, 10, 0, 0); + cout << "TauCluster "; printCutFlowLine(seltag, 11, 10, 0); + cout << "EM Isol "; printCutFlowLine(seltag, 12, 11, 0); + cout << "\\hline" << endl; + + cout << "L2 ROI "; printCutFlowLine(seltag, 20, 12, 0); + cout << "L2 Str Wid "; printCutFlowLine(seltag, 21, 20, 0); + cout << "L2 Iso Frac"; printCutFlowLine(seltag, 22, 21, 0); + cout << "L2 EM Rad "; printCutFlowLine(seltag, 23, 22, 0); + cout << "L2 Et "; printCutFlowLine(seltag, 24, 23, 0); + cout << "\\hline" << endl; + + cout << "L2 LeadPt "; printCutFlowLine(seltag, 31, 24, 0); + cout << "L2 NSlow "; printCutFlowLine(seltag, 32, 31, 0); + cout << "L2 RIso "; printCutFlowLine(seltag, 33, 32, 0); + cout << "L2 Charge "; printCutFlowLine(seltag, 34, 33, 0); + cout << "L2 Ntrk "; printCutFlowLine(seltag, 35, 34, 0); + cout << "\\hline" << endl; + + cout << "EF ROI "; printCutFlowLine(seltag, 40, 35, 0); + cout << "EF EM Rad "; printCutFlowLine(seltag, 41, 40, 0); + cout << "EF Iso Frac"; printCutFlowLine(seltag, 42, 41, 0); + cout << "EF Ntrk "; printCutFlowLine(seltag, 43, 42, 0); + cout << "EF LeadPt "; printCutFlowLine(seltag, 44, 43, 0); + cout << "EF EtCorr "; printCutFlowLine(seltag, 46, 44, 0); + cout << "\\hline\\hline" << endl; + break; + + case TrigTauSelectionManager::MENU1400: + cout << "L1 ROI "; printCutFlowLine(seltag, 10, 0, 0); + cout << "TauCluster "; printCutFlowLine(seltag, 11, 10, 0); + cout << "EM Isol "; printCutFlowLine(seltag, 12, 11, 0); + cout << "\\hline" << endl; + + cout << "L2 ROI "; printCutFlowLine(seltag, 20, 12, 0); + cout << "L2 EM Rad "; printCutFlowLine(seltag, 23, 20, 0); + cout << "L2 EtNar "; printCutFlowLine(seltag, 25, 23, 0); + cout << "\\hline" << endl; + + cout << "L2 RIso "; printCutFlowLine(seltag, 33, 25, 0); + cout << "L2 Ntrk "; printCutFlowLine(seltag, 35, 33, 0); + cout << "L2 EtTrkEM "; printCutFlowLine(seltag, 36, 35, 0); + cout << "L2 NMatch "; printCutFlowLine(seltag, 37, 36, 0); + cout << "\\hline" << endl; + + cout << "EF ROI "; printCutFlowLine(seltag, 40, 37, 0); + cout << "EF EM Rad "; printCutFlowLine(seltag, 41, 40, 0); + cout << "EF Ntrk "; printCutFlowLine(seltag, 43, 41, 0); + cout << "EF LeadPt "; printCutFlowLine(seltag, 44, 43, 0); + cout << "EF Mass "; printCutFlowLine(seltag, 45, 44, 0); + cout << "EF EtCorr "; printCutFlowLine(seltag, 46, 45, 0); + cout << "\\hline\\hline" << endl; + break; + + default: + cout << "TrigTauEffTool - Selected menu version not supported!" << endl; + } +} + +void +TrigTauEffTool::printCutFlowLine(TString seltag, unsigned int c2, + unsigned int c1, unsigned int c0) { + + // Loop over all samples + list<TString>::iterator ilist; + for (ilist = _samples.begin(); ilist != _samples.end(); ilist++) { + + TrigTauCounter* c = getCounter(seltag, *ilist); + + // Make sure we got something + if (c == 0) { + cout << "Counter for selector " << seltag << " and sample " << *ilist + << " is NULL!" << endl; + continue; + } + + cout << setprecision(0); + cout << " & " << c->getWt(c2); // Raw count + cout << setprecision(1); + cout << " & " << 100.*c->getWt(c2)/c->getWt(c0); + cout << " & " << 100.*c->getWt(c2)/c->getWt(c1); + } + cout << " \\\\" << endl; +} + +void +TrigTauEffTool::printRateLine(TrigTauCounter* c, TString& label, bool latex) { + + // Make sure we got something + if (c == 0) { + cout << "TrigTauEffTool::printRateLine - TrigTauCounter pointer is NULL!" << endl; + return; + } + + // Now print + TString space; + if (latex) space = " & "; + else space = " "; + + cout << fixed; + if (latex) { + cout << "{\\tt " << label << " }" << space; + } else { + cout << label << space; + } + + // Total events + + cout << setprecision(0); + cout << c->getWt(1) << space; + // cout << setprecision(1); + cout << c->getWt(2) << space; + cout << c->getWt(3) << space; + // cout << setprecision(2); + cout << c->getWt(4) << space; + + if (latex) cout << " \\\\"; + cout << endl; + + // Total efficiency + + cout << setprecision(1); + cout << space; + cout << 100.*c->getWt(1)/c->getWt(0) << space; + cout << 100.*c->getWt(2)/c->getWt(0) << space; + cout << 100.*c->getWt(3)/c->getWt(0) << space; + cout << 100.*c->getWt(4)/c->getWt(0) << space; + /* + if (latex) { + cout << "$" << c->getWt(4) << "\\pm " << c->getDWt(4) << "$"; + } else { + cout << c->getWt(4) << " (" << c->getDWt(4) << ") "; + } + */ + if (latex) cout << " \\\\"; + cout << endl; + + // Differential efficiency + cout << space << space; + cout << 100*c->getWt(2)/c->getWt(1) << space; + cout << 100*c->getWt(3)/c->getWt(2) << space; + cout << 100*c->getWt(4)/c->getWt(3) << space; + /* + if (latex) { + cout << "$" << c->getWt(4) << "\\pm " << c->getDWt(4) << "$"; + } else { + cout << c->getWt(4) << " (" << c->getDWt(4) << ") "; + } + */ + if (latex) cout << " \\\\"; + cout << endl; +} + +//------------------------------------------------------------------- + +TrigTauEffCuts::TrigTauEffCuts() : + maxVisEta(2.5), + minVisPt(0.), + decayMode(TrigTauMCTau::NONE) { +} + +TrigTauEffCuts::~TrigTauEffCuts() { +} + +void +TrigTauEffCuts::setFiducialCuts(TrigTauMCTauList& truthList) { + + truthList.setMaxVisEta(maxVisEta); + truthList.setMinVisPt(minVisPt); + truthList.selectDecayMode(decayMode); + +} + diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauEvRateTool.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauEvRateTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9b03431fcd650419e176cf723675115db9a1a3bd --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauEvRateTool.cxx @@ -0,0 +1,326 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +#include <string> +#include <algorithm> + +using namespace std; + +#include "TrigTauPerformNtuple/TrigTauEvent.h" +#include "TrigTauPerformValidation/TrigTauEvRateTool.h" + +TrigTauEvRateTool::TrigTauEvRateTool() { + _debug = false; + + _currentSample = ""; + _currentWeight = 0.; + + _selectors.clear(); + _counters.clear(); + + _samples.clear(); + +} + +TrigTauEvRateTool::~TrigTauEvRateTool() { + for (map<TString, TrigTauCounter*>::iterator imap = _counters.begin(); + imap != _counters.end(); imap++) { + delete imap->second; + } +} + +void +TrigTauEvRateTool::defineSelector(TrigTauFlags::TRIGGERMENU menu) { + TrigTauFlags f; + defineSelector(f.menuName(menu), menu); +} + +void +TrigTauEvRateTool::defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu) { + + if (_selectors[tag] != 0) { + cerr << "TrigTauEvRateTool::defineSelector - Selector with tag " << tag << + " already defined!" << endl; + return; + } + + _selectors[tag] = menu; + + return; +} + +void +TrigTauEvRateTool::defineAllSelectors() { + + TString menuName; + TrigTauFlags f; + for (unsigned int i = 1; i<400; i++) { + menuName = f.menuName((TrigTauFlags::TRIGGERMENU) i); + if (menuName == "Unknown") continue; + defineSelector((TrigTauFlags::TRIGGERMENU) i); + } + return; +} + +TrigTauCounter* +TrigTauEvRateTool::getCounter(TString selectorTag, TString sampleTag) { + TString tag = selectorTag + TString("_")+sampleTag; + if (_counters[tag] == NULL) { + if (_debug) + cout << "TrigTauEvRateTool::getCounter - No counter with tag " << tag << endl; + _counters[tag] = makeNewCounter(); + + // Check if the sample tag exists, if not add it here + if (find(_samples.begin(), _samples.end(), sampleTag) == _samples.end()) + defineSample(sampleTag); + + } + + return _counters[tag]; +} + +void +TrigTauEvRateTool::clearSumCounter(TString sumTag) { + + // Loop over all defined selectors as we need a summary counter for each + for (map<TString, TrigTauFlags::TRIGGERMENU>::iterator imap = _selectors.begin(); + imap != _selectors.end(); imap++) { + + TString selectorTag = imap->first; + + // Asking for counter will automatically create everything we need + TrigTauCounter* sum = getSumCounter(selectorTag, sumTag); + + // Check we have something + sum->print(); + } +} + +// Add counts from given sampleTag to the summary counter +void +TrigTauEvRateTool::addSumSample(TString sampleTag, TString sumTag) { + + // Loop over all defined selectors as we need a summary counter for each + for (map<TString, TrigTauFlags::TRIGGERMENU>::iterator imap = _selectors.begin(); + imap != _selectors.end(); imap++) { + + TString selectorTag = imap->first; + + // Asking for counter will automatically create everything we need + // in case it doesn't already exist + TrigTauCounter* sum = getSumCounter(selectorTag, sumTag); + if (_debug) { + cout << "Retrieved sum counter " << selectorTag << "_" << sumTag<< endl; + sum->print(); + } + + // Get the sample counter + TrigTauCounter* samp = getCounter(selectorTag, sampleTag); + if (_debug) { + cout << "Retrieved samp counter " << selectorTag << "_" << sampleTag << endl; + samp->print(); + } + + // Add contents + sum->add(*samp); + } +} + +TrigTauCounter* +TrigTauEvRateTool::getSumCounter(TString selectorTag, TString sumTag) { + return getCounter(selectorTag, sumTag); +} + +void +TrigTauEvRateTool::defineSample(TString tag) { + _samples.push_back(tag); +} + +void +TrigTauEvRateTool::fillSample(TString tag, TString filename, double wt) { + + // Open file + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + cerr << "Can't open file " << filename << endl; + return; + } + + // Initialize tree + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + cerr << "Can't find eventTree in " << filename << endl; + return; + } + + setCurrentSample(tag); + setCurrentWeight(wt); + fillSample(tree); + + delete tree; + delete file; +} + +void +TrigTauEvRateTool::fillSample(TTree *tree) { + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + tree->SetBranchStatus("mcEvent*", 0); + + // Loop over all events + int nev = int(tree->GetEntries()); + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + + // Loop over defined selectors + for (map<TString, TrigTauFlags::TRIGGERMENU>::iterator imap = _selectors.begin(); + imap != _selectors.end(); imap++) { + TString seltag = imap->first; + TrigTauFlags::TRIGGERMENU menu = imap->second; + + // Get counters + TrigTauCounter* bgd = getCounter(seltag, _currentSample); + + bgd->fill(0, _currentWeight); + + if (event->decision.passedL1(menu) == 0) continue; + bgd->fill(1, _currentWeight); + + if (event->decision.passedL2(menu) == 0) continue; + bgd->fill(2, _currentWeight); + + if (event->decision.passedEF(menu) == 0) continue; + bgd->fill(3, _currentWeight); + + } // end loop over selectors + } // end loop over events + + delete event; +} + +TrigTauCounter* +TrigTauEvRateTool::makeNewCounter() { + TrigTauCounter* count = new TrigTauCounter(); + count->reset(); + count->name(0, string("L1 In ")); + count->name(1, string("L1 Out")); + count->name(2, string("L2 Out")); + count->name(3, string("EF Out")); + return count; +} + +void +TrigTauEvRateTool::print() { + + for (map<TString, TrigTauCounter*>::iterator imap = _counters.begin(); + imap != _counters.end(); imap++) { + TrigTauCounter* c = imap->second; + cout << imap->first << endl; + c->print(); + } + +} + +void +TrigTauEvRateTool::printRateSum(TString sumTag, bool latex) { + + if (latex) cout << "\\hline" << endl; + + // Loop over defined selectors + map<TString, TrigTauFlags::TRIGGERMENU>::iterator imap; + for (imap = _selectors.begin(); imap != _selectors.end(); imap++) { + TString seltag = imap->first; + TrigTauCounter* c = getSumCounter(seltag, sumTag); + // Make sure we got something + if (c == 0) { + cout << "Sum counter for selector " << seltag << " is NULL!" << endl; + continue; + } + + // Now print + printRateLine(c, seltag, latex); + + } + + if (latex) cout << "\\hline" << endl; +} + +void +TrigTauEvRateTool::printSelector(TString seltag, bool latex) { + + if (latex) cout << "\\hline" << endl; + if (latex) { + cout << "\\multicolumn{4}{c}{{\\tt " << seltag << " }} \\\\" << endl; + } else { + cout << seltag << endl; + } + if (latex) cout << "\\hline" << endl; + + TrigTauCounter* c; + + // Sort sample list (to put Sum at the end) + // No longer necessary... + // _samples.sort(); + + // Loop over defined samples (includes summary) and print out what we have + list<TString>::iterator ilist; + for (ilist = _samples.begin(); ilist != _samples.end(); ilist++) { + c = getCounter(seltag, *ilist); + + // Make sure we got something + if (c == 0) { + cout << "Counter for selector " << seltag << " and sample " << *ilist + << " is NULL!" << endl; + continue; + } + + // Now print + printRateLine(c, *ilist, latex); + } + + if (latex) cout << "\\hline" << endl; + +} + +void +TrigTauEvRateTool::printRateLine(TrigTauCounter* c, TString& label, bool latex) { + + // Make sure we got something + if (c == 0) { + cout << "TrigTauEvRateTool::printRateLine - TrigTauCounter pointer is NULL!" << endl; + return; + } + + // Now print + TString space; + if (latex) space = " & "; + else space = " "; + + cout << fixed; + if (latex) { + cout << "{\\tt " << label << " }" << space; + } else { + cout << label << space; + } + + cout << setprecision(2); + if (latex) { + cout << "$" << c->getWt(1) << "\\pm " << c->getDWt(1) << "$" << space; + cout << "$" << c->getWt(2) << "\\pm " << c->getDWt(2) << "$" << space; + cout << "$" << c->getWt(3) << "\\pm " << c->getDWt(3) << "$"; + } else { + cout << c->getWt(1) << " (" << c->getDWt(1) << ") " << space; + cout << c->getWt(2) << " (" << c->getDWt(2) << ") " << space; + cout << c->getWt(3) << " (" << c->getDWt(3) << ") "; + } + + if (latex) cout << " \\\\"; + cout << endl; + +} diff --git a/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauRateTool.cxx b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauRateTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..65c89072f8261e44346b239bc8ff98806692d964 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigTauAnalysis/TrigTauPerformValidation/src/TrigTauRateTool.cxx @@ -0,0 +1,364 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include <iostream> +#include <iomanip> +#include <string> +#include <algorithm> + +using namespace std; + +#include "TrigTauPerformNtuple/TrigTauEvent.h" +#include "TrigTauPerformAnalysis/TrigTauTrigChainList.h" + +#include "TrigTauPerformValidation/TrigTauRateTool.h" + +TrigTauRateTool::TrigTauRateTool() { + _debug = false; + + _currentSample = ""; + _currentWeight = 0.; + + _defVersion = TrigTauSelectionManager::MENU13030pre; + + _selectors.clear(); + _counters.clear(); + + _samples.clear(); + +} + +TrigTauRateTool::~TrigTauRateTool() { + for (map<TString, TrigTauSelectionManager*>::iterator imap = _selectors.begin(); + imap != _selectors.end(); imap++) { + delete imap->second; + } + + for (map<TString, TrigTauCounter*>::iterator imap = _counters.begin(); + imap != _counters.end(); imap++) { + delete imap->second; + } +} + +void +TrigTauRateTool::setDefaultVersion(TrigTauSelectionManager::MENUVERSION version) { + _defVersion = version; +} + +void +TrigTauRateTool::defineSelector(TrigTauFlags::TRIGGERMENU menu) { + TrigTauFlags f; + defineSelector(f.menuName(menu), menu, _defVersion); +} + +void +TrigTauRateTool::defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu) { + defineSelector(tag, menu, _defVersion); +} + +void +TrigTauRateTool::defineSelector(TString tag, TrigTauFlags::TRIGGERMENU menu, + TrigTauSelectionManager::MENUVERSION version) { + + if (_selectors[tag] != NULL) { + cerr << "TrigTauRateTool::defineSelector - Selector with tag " << tag << + " already defined!" << endl; + return; + } + + TrigTauSelectionManager* sel = new TrigTauSelectionManager(); + sel->setMenuVersion(version); + sel->setTauMenu(menu); + _selectors[tag] = sel; + + return; +} + +TrigTauSelectionManager* +TrigTauRateTool::getSelector(TString tag) { + if (_selectors[tag] == NULL) + cerr << "TrigTauRateTool::getSelector - No selector with tag " << tag << endl; + return _selectors[tag]; +} + +TrigTauCounter* +TrigTauRateTool::getCounter(TString selectorTag, TString sampleTag) { + TString tag = selectorTag + TString("_")+sampleTag; + if (_counters[tag] == NULL) { + if (_debug) + cout << "TrigTauRateTool::getCounter - No counter with tag " << tag << endl; + _counters[tag] = makeNewCounter(); + + // Check if the sample tag exists, if not add it here + if (find(_samples.begin(), _samples.end(), sampleTag) == _samples.end()) + defineSample(sampleTag); + + } + + return _counters[tag]; +} + +void +TrigTauRateTool::clearSumCounter(TString sumTag) { + + // Loop over all defined selectors as we need a summary counter for each + for (map<TString, TrigTauSelectionManager*>::iterator imap = _selectors.begin(); + imap != _selectors.end(); imap++) { + + TString selectorTag = imap->first; + + // Asking for counter will automatically create everything we need + TrigTauCounter* sum = getSumCounter(selectorTag, sumTag); + + // Check we have something + sum->print(); + } +} + +// Add counts from given sampleTag to the summary counter +void +TrigTauRateTool::addSumSample(TString sampleTag, TString sumTag) { + + // Loop over all defined selectors as we need a summary counter for each + for (map<TString, TrigTauSelectionManager*>::iterator imap = _selectors.begin(); + imap != _selectors.end(); imap++) { + + TString selectorTag = imap->first; + + // Asking for counter will automatically create everything we need + // in case it doesn't already exist + TrigTauCounter* sum = getSumCounter(selectorTag, sumTag); + if (_debug) { + cout << "Retrieved sum counter " << selectorTag << "_" << sumTag<< endl; + sum->print(); + } + + // Get the sample counter + TrigTauCounter* samp = getCounter(selectorTag, sampleTag); + if (_debug) { + cout << "Retrieved samp counter " << selectorTag << "_" << sampleTag << endl; + samp->print(); + } + + // Add contents + sum->add(*samp); + } +} + +TrigTauCounter* +TrigTauRateTool::getSumCounter(TString selectorTag, TString sumTag) { + return getCounter(selectorTag, sumTag); +} + +void +TrigTauRateTool::defineSample(TString tag) { + _samples.push_back(tag); +} + +void +TrigTauRateTool::fillSample(TString tag, TString filename, double wt) { + + // Open file + TFile* file = new TFile(filename); + if (!file->IsOpen()) { + cerr << "Can't open file " << filename << endl; + return; + } + + // Initialize tree + TTree* tree = (TTree*)file->Get("eventTree"); + if (tree == 0) { + cerr << "Can't find eventTree in " << filename << endl; + return; + } + + fix.setTTPVersion(filename); + + setCurrentSample(tag); + setCurrentWeight(wt); + fillSample(tree); + + delete tree; + delete file; +} + +void +TrigTauRateTool::fillSample(TTree *tree) { + + TrigTauEvent* event = new TrigTauEvent(); + tree->SetBranchAddress("EventBranch", &event); + tree->SetBranchStatus("*", 1); + tree->SetBranchStatus("mcEvent*", 0); + + // Loop over all events + int nev = int(tree->GetEntries()); + for(int iev = 0; iev<nev; ++iev) { + event->reset(); + tree->GetEvent(iev); + + // Bug fix + fix.fix(event); + + TrigTauTrigChainList chainList; + chainList.setRoiWordMatching(); + chainList.fillChainList(event); + + // Loop over defined selectors + for (map<TString, TrigTauSelectionManager*>::iterator imap = _selectors.begin(); + imap != _selectors.end(); imap++) { + TString seltag = imap->first; + TrigTauSelectionManager* selman = imap->second; + + // Fill trigger chain list for this selection manager + chainList.fillTriggerList(*selman); + + // Get counters + TrigTauCounter* bgd = getCounter(seltag, _currentSample); + + bgd->fill(0, _currentWeight); + + unsigned int numL1 = chainList.nPassL1Chains(); + if (numL1 == 0) continue; + bgd->fill(1, _currentWeight); + + unsigned int numL2Cal = chainList.nPassL2CalChains(); + if (numL2Cal == 0) continue; + bgd->fill(2, _currentWeight); + + unsigned int numL2 = chainList.nPassL2Chains(); + if (numL2 == 0) continue; + bgd->fill(3, _currentWeight); + + unsigned int numEF = chainList.nPassEFChains(); + if (numEF == 0) continue; + bgd->fill(4, _currentWeight); + + } // end loop over selectors + } // end loop over events + + delete event; +} + +TrigTauCounter* +TrigTauRateTool::makeNewCounter() { + TrigTauCounter* count = new TrigTauCounter(); + count->reset(); + count->name(0, string("L1 In ")); + count->name(1, string("L1 Out")); + count->name(2, string("L2Cal Out")); + count->name(3, string("L2Trk Out")); + count->name(4, string("EF Out")); + return count; +} + +void +TrigTauRateTool::print() { + + for (map<TString, TrigTauCounter*>::iterator imap = _counters.begin(); + imap != _counters.end(); imap++) { + TrigTauCounter* c = imap->second; + cout << imap->first << endl; + c->print(); + } + +} + +void +TrigTauRateTool::printRateSum(TString sumTag, bool latex) { + + if (latex) cout << "\\hline" << endl; + + // Loop over defined selectors + map<TString, TrigTauSelectionManager*>::iterator imap; + for (imap = _selectors.begin(); imap != _selectors.end(); imap++) { + TString seltag = imap->first; + TrigTauCounter* c = getSumCounter(seltag, sumTag); + // Make sure we got something + if (c == 0) { + cout << "Sum counter for selector " << seltag << " is NULL!" << endl; + continue; + } + + // Now print + printRateLine(c, seltag, latex); + + } + + if (latex) cout << "\\hline" << endl; +} + +void +TrigTauRateTool::printSelector(TString seltag, bool latex) { + + if (latex) cout << "\\hline" << endl; + if (latex) { + cout << "\\multicolumn{4}{c}{{\\tt " << seltag << " }} \\\\" << endl; + } else { + cout << seltag << endl; + } + if (latex) cout << "\\hline" << endl; + + TrigTauCounter* c; + + // Sort sample list (to put Sum at the end) + // No longer necessary... + // _samples.sort(); + + // Loop over defined samples (includes summary) and print out what we have + list<TString>::iterator ilist; + for (ilist = _samples.begin(); ilist != _samples.end(); ilist++) { + c = getCounter(seltag, *ilist); + + // Make sure we got something + if (c == 0) { + cout << "Counter for selector " << seltag << " and sample " << *ilist + << " is NULL!" << endl; + continue; + } + + // Now print + printRateLine(c, *ilist, latex); + } + + if (latex) cout << "\\hline" << endl; + +} + +void +TrigTauRateTool::printRateLine(TrigTauCounter* c, TString& label, bool latex) { + + // Make sure we got something + if (c == 0) { + cout << "TrigTauRateTool::printRateLine - TrigTauCounter pointer is NULL!" << endl; + return; + } + + // Now print + TString space; + if (latex) space = " & "; + else space = " "; + + cout << fixed; + if (latex) { + cout << "{\\tt " << label << " }" << space; + } else { + cout << label << space; + } + + cout << setprecision(0); + cout << c->getWt(1) << space; + cout << setprecision(1); + cout << c->getWt(2) << space; + cout << c->getWt(3) << space; + cout << setprecision(2); + if (latex) { + cout << "$" << c->getWt(4) << "\\pm " << c->getDWt(4) << "$"; + } else { + cout << c->getWt(4) << " (" << c->getDWt(4) << ") "; + } + + if (latex) cout << " \\\\"; + cout << endl; + +}