Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
momentumDistributions.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file momentumDistributions.C
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include "TFile.h"
10 #include "TH1F.h"
11 #include "TH2F.h"
12 #include "TProfile.h"
13 #include "TROOT.h"
14 #include "TTree.h"
15 
16 // This root script creates different momentum distributions with the inFile
17 // created from the ExtrapolationTest.
18 // To plot two momentum distributions of this kind in one canvas the root
19 // script "compareDistributions.C" can be used.
20 
22  std::string outFile, int nBins, float r, float zMin,
23  float zMax, float etaMin, float etaMax,
24  float thetaMin = 0., float thetaMax = M_PI) {
25  std::cout << "Opening file: " << inFile << std::endl;
26  TFile inputFile(inFile.c_str());
27  std::cout << "Reading tree: " << treeName << std::endl;
28  TTree* tree = (TTree*)inputFile.Get(treeName.c_str());
29 
30  int nHits;
31  float eta;
32 
33  std::vector<float>* x = new std::vector<float>;
34  std::vector<float>* y = new std::vector<float>;
35  std::vector<float>* z = new std::vector<float>;
36 
37  tree->SetBranchAddress("nHits", &nHits);
38  tree->SetBranchAddress("Eta", &eta);
39  tree->SetBranchAddress("StepX", &x);
40  tree->SetBranchAddress("StepY", &y);
41  tree->SetBranchAddress("StepZ", &z);
42 
43  Int_t entries = tree->GetEntries();
44  std::cout << "Creating new output file: " << outFile
45  << " and writing "
46  "material maps"
47  << std::endl;
48  TFile outputFile(outFile.c_str(), "recreate");
49 
50  // distributions of the number of hits versus momentum coordinates
51  TProfile* nHits_eta = new TProfile("nHits_eta", "Hits in sensitive Material",
52  nBins, etaMin, etaMax);
53  nHits_eta->GetXaxis()->SetTitle("#eta");
54  nHits_eta->GetYaxis()->SetTitle("#hits");
55  TProfile* nHits_theta = new TProfile(
56  "nHits_theta", "Hits in sensitive Material", nBins, thetaMin, thetaMax);
57  nHits_theta->GetXaxis()->SetTitle("#theta [rad]");
58  nHits_theta->GetYaxis()->SetTitle("#hits");
59  TProfile* nHits_z =
60  new TProfile("nHits_z", "Hits in sensitive Material", nBins, zMin, zMax);
61  nHits_z->GetXaxis()->SetTitle("z coordinate of momentum [mm]");
62  nHits_z->GetYaxis()->SetTitle("#hits");
63 
64  // distributions of the momentum coordinates
65  TH1F* Eta = new TH1F("eta", "Distribution of #eta", nBins, etaMin, etaMax);
66  Eta->GetXaxis()->SetTitle("#eta");
67  Eta->GetYaxis()->SetTitle("#events");
68  // distributions of the momentum coordinates calculated from eta - since in
69  // the extrapolation test eta is flat randomly generated and theta and z are
70  // calculated from eta.
71  TH1F* Theta =
72  new TH1F("theta", "Distribution of #theta", nBins, thetaMin, thetaMax);
73  Theta->GetXaxis()->SetTitle("#theta [rad]");
74  Theta->GetYaxis()->SetTitle("#events");
75  TH1F* Z = new TH1F("z", "Distribution of z coordinate of the momentum", nBins,
76  zMin, zMax);
77  Z->GetXaxis()->SetTitle("z coordinate of momentum [mm]");
78  Z->GetYaxis()->SetTitle("#events");
79 
80  // hit distributions
81  TH1F* hitsEta =
82  new TH1F("hitsEta", "Sensitive Hit Distribution", nBins, etaMin, etaMax);
83  hitsEta->GetXaxis()->SetTitle("#eta");
84  hitsEta->GetYaxis()->SetTitle("#hits");
85  TH1F* hitsTheta = new TH1F("hitsTheta", "Sensitive Hit Distribution", nBins,
86  thetaMin, thetaMax);
87  hitsTheta->GetXaxis()->SetTitle("#theta");
88  hitsTheta->GetYaxis()->SetTitle("#hits");
89  TH1F* hitsZ =
90  new TH1F("hitsZ", "Sensitive Hit Distribution", nBins, zMin, zMax);
91  hitsZ->GetXaxis()->SetTitle("z [mm]");
92  hitsZ->GetYaxis()->SetTitle("#hits");
93 
94  for (int i = 0; i < entries; i++) {
95  tree->GetEvent(i);
96  double theta = 2. * atan(exp(-eta));
97  double zDir = r / tan(theta);
98 
99  nHits_eta->Fill(eta, nHits);
100  nHits_theta->Fill(theta, nHits);
101  nHits_z->Fill(zDir, nHits);
102 
103  Eta->Fill(eta, 1);
104  Theta->Fill(theta);
105  Z->Fill(zDir, 1);
106 
107  for (int j = 0; j < x->size(); j++) {
108  float hitTheta = std::atan2(std::hypot(x->at(j), y->at(j)), z->at(j));
109  hitsEta->Fill(-log(tan(hitTheta * 0.5)));
110  hitsTheta->Fill(hitTheta);
111  hitsZ->Fill(z->at(j));
112  }
113  }
114  inputFile.Close();
115 
116  nHits_eta->Write();
117  nHits_theta->Write();
118  nHits_z->Write();
119 
120  Eta->Write();
121  Theta->Write();
122  Z->Write();
123 
124  hitsEta->Write();
125  hitsTheta->Write();
126  hitsZ->Write();
127 
128  delete nHits_eta;
129  delete nHits_theta;
130  delete nHits_z;
131 
132  delete Eta;
133  delete Theta;
134  delete Z;
135 
136  delete hitsEta;
137  delete hitsTheta;
138  delete hitsZ;
139 
140  delete x;
141  delete y;
142  delete z;
143 
144  outputFile.Close();
145 }