ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_HLTMETAveragePhivsEtaMaps.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
5/* HLTMET Post Processing Method: Peform bin-wise division for each Phi.vs.Eta maps of MET, SumEt, SumE
6 * with Phi.vs.Eta map of N to compute <MET>(eta,phi), <SumEt>(eta,phi)
7 * and <SumE>(eta,phi)
8 * Author : Venkatesh Kaushik <venkat.kaushik@cern.ch>
9 * Date : Feb 2010
10 */
11
13
14#include <iostream>
15#include <iomanip>
16#include <algorithm>
17#include <fstream>
18#include <cmath>
19#include <cstdlib>
20#include <sstream>
21#include <vector>
22#include <utility>
23#include <map>
24#include <string>
25
26#include "TH1F.h"
27#include "TH2F.h"
28#include "TFile.h"
29#include "TClass.h"
30#include "TKey.h"
31#include "TMath.h"
32#include "TF1.h"
33#include "TTree.h"
34#include "TBranch.h"
35
36namespace dqutils {
37 void
38 MonitoringFile::HLTMETAveragePhivsEtaMaps(TFile* f, std::string& run_dir) {
39 //bool dbgLevel = false;
40
41 //if (dbgLevel) std::cout << "--> HLTMETAveragePhivsEtaMaps: <Quantity(eta,phi)> = Quantity(eta,phi)/N(eta,phi) " << std::endl;
42
43 f->cd("/");
44 TIter next_run(f->GetListOfKeys());
45 TKey* key_run(0);
46 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
47 if (!key_run->IsFolder()) continue;
48 run_dir = key_run->GetName();
49 if (run_dir.find("run") == std::string::npos) {
50 continue;
51 }
52
53 // begin HLTMET
54 // note 1: prefix all dirs and hists with '/'
55 // note 2: missing dir => return
56 // note 3: missing hist => continue
57 std::string hlt_top = run_dir + "/HLT"; // toplevel
58 static const std::string met_efdir = "/EFMissingET_Fex"; // EF dir
59
60 std::vector<std::string> met_fexs, hist_numr;
61
62 // expect the following fex dirs
63 met_fexs.push_back("/METMon");
64 //met_fexs.push_back("/METMon_FEB");
65 //met_fexs.push_back("/METMon_allCells");
66
67 // check if fex dirs are in hlt
68 for (std::vector<std::string>::iterator it = met_fexs.begin(); it != met_fexs.end(); ++it) {
69 std::string theHistDir = hlt_top + *it;
70 TDirectory* dir = f->GetDirectory(theHistDir.c_str());
71 if (!dir) {
72 std::cerr << "--> HLTMETAveragePhivsEtaMaps: directory " << theHistDir << " not found" << std::endl;
73 return;
74 }
75 // expect the EF dir inside each fex dir
76 theHistDir += met_efdir;
77 dir = f->GetDirectory(theHistDir.c_str());
78 if (!dir) {
79 std::cerr << "--> HLTMETAveragePhivsEtaMaps: directory " << theHistDir << " not found" << std::endl;
80 return;
81 }
82 }
83
84 // MEt, SumEt, SumE of components (numerator)
85 // compSumEt_lin_EtaPhi_00 etc..
86 hist_numr.push_back("/compEt_lin_");
87 hist_numr.push_back("/compSumEt_lin_");
88 hist_numr.push_back("/compSumE_lin_"); // need to plot SumE on linear scale (todo)
89
90 // components N (denominator)
91 static const std::string hist_denr = "/compN_";
92
93 // type (eta,phi map)
94 static const std::string hist_suffix = "EtaPhi_"; // phi vs. eta map
95
96 // each component a 2d hist. get all components
97 unsigned int comp_num = 25; // 25 components
98
99 // we have all dirs, get the component histograms
100 for (std::vector<std::string>::iterator itFex = met_fexs.begin(); itFex != met_fexs.end(); ++itFex) {
101 for (std::vector<std::string>::iterator itNum = hist_numr.begin(); itNum != hist_numr.end(); ++itNum) {
102 for (unsigned int icomp = 0; icomp < comp_num; icomp++) {
103 TH2F* hnum(0), *hden(0);
104
105 // prepend histogram name with path and append with suffix [_00 .., _24 for each component]
106 std::string thePath = hlt_top + (*itFex) + met_efdir;
107 std::string numHist = (*itNum) + hist_suffix + std::string(Form("%02u", icomp));
108 std::string denHist = hist_denr + hist_suffix + std::string(Form("%02u", icomp));
109 std::string numPath = thePath + numHist;
110 std::string denPath = thePath + denHist;
111
112 // test if histograms are present
113 if (!f->Get(numPath.c_str())) {
114 //if (dbgLevel) std::cerr << "--> HLTMETAveragePhivsEtaMaps: no histogram " << numPath << std::endl;
115 continue;
116 }
117 if (!f->Get(denPath.c_str())) {
118 //if (dbgLevel) std::cerr << "--> HLTMETAveragePhivsEtaMaps: no histogram " << denPath << std::endl;
119 continue;
120 }
121
122 // get histograms
123 hnum = (TH2F*) (f->Get(numPath.c_str()));
124 hden = (TH2F*) (f->Get(denPath.c_str()));
125
126 // get directory of histograms
127 TDirectory* dir = f->GetDirectory(thePath.c_str());
128
129 // these are disabled, because we have to worry about updating metadata
130 // clone numerator histogram in the same directory; prepend with "avg_"
131 // use numerator to do the job
132 //std::string avgHist = std::string("avg_") + (*itNum) + hist_suffix + std::string(Form("%02u",icomp));
133 //havg = (TH2F *) (hnum->Clone(avgHist));
134 //havg->SetDirectory(dir);
135
136 // divide num by den to get average quantity.
137 hnum->Divide(hnum, hden);
138
139 // fix histogram titles
140 TString title = hnum->GetTitle();
141 title.ReplaceAll(": ", ": #LT");
142 title.ReplaceAll("(#eta", "#GT(#eta");
143 hnum->SetTitle(title);
144
145 //title = hden->GetTitle();
147 //title.ReplaceAll(" #phi VS #eta",": N(#eta, #phi)");
148 //hden->SetTitle(title);
149
150 //std::cout << numHist << " div " << denHist << std::endl;
151 //std::cout << hnum->GetZaxis()->GetTitle() << "\t";
152 //std::cout << hden->GetZaxis()->GetTitle() << std::endl;
153 //std::cout << hnum->GetTitle() << "\t";
154 //std::cout << hden->GetTitle() << std::endl;
155 //std::cout << "-------------------------------------------------------------" << std::endl;
156 //getchar();
157 // cd() into that directory and save the avg histogram in file
158 dir->cd();
159 hnum->Write("", TObject::kOverwrite);
160 } // done looping over components
161 } // done looping over quantities
162 } // done looping over directories
163 } // end while loop over all keys
164 } // end method MonitoringFile::HLTMETAveragePhivsEtaMaps
165} // end namespace
static void HLTMETAveragePhivsEtaMaps(TFile *f, std::string &run_dir)