Fork me on GitHub

source: git/examples/CaloGrid.cpp@ 92b8d11

Last change on this file since 92b8d11 was 77e9ae1, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

set Standard to Cpp03 in .clang-format

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[96abea4]1//calorimeter grid
[341014c]2#include <algorithm>
3#include <cassert>
4#include <iostream>
[96abea4]5#include <map>
[341014c]6#include <set>
7#include <sstream>
[96abea4]8#include <utility>
9#include <vector>
10
[7d83636]11#include "ExRootAnalysis/ExRootConfReader.h"
[341014c]12#include "classes/DelphesClasses.h"
13#include "display/Delphes3DGeometry.h"
[96abea4]14
15#include "TCanvas.h"
16#include "TH2F.h"
17#include "TLine.h"
[341014c]18#include "TString.h"
19#include "TStyle.h"
20#include "TText.h"
[96abea4]21
22using namespace std;
23
24Bool_t debug = false;
25//Bool_t debug = true;
26
27int main(int argc, char *argv[])
28{
29
[341014c]30 if(argc != 3)
31 {
32 cout << " Usage: ./CaloGrid [detector card] [calo name]" << endl;
33 cout << "Example: ./CaloGrid cards/delphes_card_CMS.tcl ECal" << endl;
34 return 0;
35 }
[96abea4]36
37 TString card(argv[1]);
38
39 ExRootConfReader *confReader = new ExRootConfReader;
40 confReader->ReadFile(card);
[341014c]41
[96abea4]42 std::vector<std::string> calorimeters_;
[77e9ae1]43 std::map<std::string, std::set<std::pair<Double_t, Int_t> > > caloBinning_;
[341014c]44
[96abea4]45 std::string s(argv[2]);
[341014c]46 std::replace(s.begin(), s.end(), ',', ' ');
47 std::istringstream stream(s);
[96abea4]48 std::string word;
[341014c]49 while(stream >> word) calorimeters_.push_back(word);
[96abea4]50
[341014c]51 caloBinning_.clear(); // calo binning
[96abea4]52
[341014c]53 TCanvas c("", "", 1600, 838);
54
55 gPad->SetLeftMargin(0.16);
56 gPad->SetTopMargin(0.16);
57 gPad->SetBottomMargin(0.20);
[96abea4]58 gStyle->SetOptStat(0000000);
[341014c]59
[96abea4]60 gStyle->SetTextFont(132);
[341014c]61
[96abea4]62 TH2F h2("h2", "", 1, -6, 6, 1, 0, 6.28);
63
64 h2.GetXaxis()->SetTitle("#eta");
65 h2.GetYaxis()->SetTitle("#phi");
66
67 h2.GetXaxis()->SetTitleFont(132);
68 h2.GetYaxis()->SetTitleFont(132);
69 h2.GetZaxis()->SetTitleFont(132);
70 h2.GetXaxis()->SetLabelFont(132);
71 h2.GetYaxis()->SetLabelFont(132);
72
[341014c]73 h2.GetXaxis()->SetTitleOffset(1.4);
74 h2.GetYaxis()->SetTitleOffset(1.1);
75 h2.GetXaxis()->SetLabelOffset(0.02);
76 h2.GetYaxis()->SetLabelOffset(0.02);
77 h2.GetXaxis()->SetTitleSize(0.06);
78 h2.GetYaxis()->SetTitleSize(0.06);
79 h2.GetXaxis()->SetLabelSize(0.06);
80 h2.GetYaxis()->SetLabelSize(0.06);
81
82 h2.GetXaxis()->SetTickLength(0.0);
83 h2.GetYaxis()->SetTickLength(0.0);
84
85 h2.Draw();
86
87 // fake loop just keeping it for convenience right now
88 for(std::vector<std::string>::const_iterator calo = calorimeters_.begin(); calo != calorimeters_.end(); ++calo)
89 {
90
[96abea4]91 //first entry is eta bin, second is number of phi bins
[77e9ae1]92 set<pair<Double_t, Int_t> > caloBinning;
[96abea4]93 ExRootConfParam paramEtaBins, paramPhiBins;
[341014c]94 ExRootConfParam param = confReader->GetParam(Form("%s::EtaPhiBins", calo->c_str()));
[96abea4]95 Int_t size = param.GetSize();
[341014c]96
97 for(int i = 0; i < size / 2; ++i)
98 {
99 paramEtaBins = param[i * 2];
100 paramPhiBins = param[i * 2 + 1];
101 assert(paramEtaBins.GetSize() == 1);
102
103 caloBinning.insert(std::make_pair(paramEtaBins[0].GetDouble(), paramPhiBins.GetSize() - 1));
[96abea4]104 }
105 caloBinning_[*calo] = caloBinning;
[341014c]106
107 TLine *liney;
108 TLine *linex;
109
110 //loop over calo binning
[77e9ae1]111 std::set<std::pair<Double_t, Int_t> >::iterator it;
[341014c]112
113 Int_t n = -1;
114 for(it = caloBinning.begin(); it != caloBinning.end(); ++it)
[96abea4]115 {
[341014c]116 n++;
117
118 if(debug) cout << "-----------------------" << endl;
119 if(debug) cout << it->first << "," << it->second << endl;
120 liney = new TLine(it->first, 0, it->first, 6.28);
121 liney->SetLineColor(kRed + 3);
122 liney->Draw();
123
[77e9ae1]124 set<std::pair<Double_t, Int_t> >::iterator it2 = it;
[341014c]125 it2--;
126
127 for(int j = 0; j <= it->second; j++)
128 {
129
130 Double_t yval0 = 0 + 6.28 * j / it->second;
131
132 if(debug) cout << it2->first << "," << yval0 << "," << it->first << "," << yval0 << endl;
133
134 linex = new TLine(it->first, yval0, it2->first, yval0);
135 linex->SetLineColor(kRed + 3);
136 linex->Draw();
137 }
138 }
[96abea4]139 }
140
141 TString text = TString(s);
[341014c]142 TText *th1 = new TText(5.00, 6.45, text);
143 th1->SetTextAlign(31);
144 th1->SetTextFont(132);
[96abea4]145 th1->SetTextSize(0.075);
146 th1->Draw();
147
148 TString output = TString(s);
[341014c]149 c.Print(output + ".png", "png");
150 c.Print(output + ".pdf", "pdf");
[96abea4]151}
Note: See TracBrowser for help on using the repository browser.