Belle II Software development
ScanCDCGeoModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9/**************************************************************************
10 * Test module to get CDC geometry parameters into a .root files *
11 * To run this module use script: cdc/examples/runScanGeo.py *
12 **************************************************************************/
13
14#include <cdc/modules/cdcGeoScan/ScanCDCGeoModule.h>
15#include <geometry/GeometryManager.h>
16#include <framework/gearbox/GearDir.h>
17#include <cdc/geometry/CDCGeometryPar.h>
18#include "TH1F.h"
19#include "TCanvas.h"
20#include "TVectorF.h"
21
22using namespace std;
23using namespace Belle2;
24using namespace CDC;
25
26REG_MODULE(ScanCDCGeo);
27
29{
30 setDescription("This module fills CDC geometry information in histo/tree format to a root file");
31}
32
34{
35
36 bookOutput();
37
38 TH1F* h_nwires = new TH1F("h_nwires", "Number of wires in layer;CDC layer#", 56, 0.5, 56.5);
39 TH1F* h_stereo = new TH1F("h_stereo", "Stereo angle in this layer;CDC layer#", 56, 0.5, 56.5);
40 TH1F* h_swire_posF_phi = new TH1F("h_swire_posF_phi", "#phi of sense wires in forward pos;CDC layer#", 56, 0.5, 56.5);
41 TH1F* h_swire_posF_theta = new TH1F("h_swire_posF_theta", "#theta of sense wires in forward pos;CDC layer#", 56, 0.5, 56.5);
42 TH1F* h_swire_posB_phi = new TH1F("h_swire_posB_phi", "#phi of sense wires in backward pos;CDC layer#", 56, 0.5, 56.5);
43 TH1F* h_swire_posB_theta = new TH1F("h_swire_posB_theta", "#theta of sense wires in backward pos;CDC layer#", 56, 0.5, 56.5);
44 TH1F* h_fwire_iradius = new TH1F("h_fwire_iradius", "inner radius of field wires;CDC layer#", 56, 0.5, 56.5);
45 TH1F* h_fwire_oradius = new TH1F("h_fwire_oradius", "outer radius of field wires;CDC layer#", 56, 0.5, 56.5);
46 TH1F* h_width = new TH1F("h_width", "Cell Width;CDC layer#", 56, 0.5, 56.5);
47 TH1F* h_height = new TH1F("h_height", "Cell Height;CDC layer#", 56, 0.5, 56.5);
48 TH1F* h_length = new TH1F("h_length", "length of the wires;CDC layer#", 56, 0.5, 56.5);
49
50 B2INFO("Creating CDCGeometryPar object");
53
54 // Print some info
55 cout << "------| Summary-1 " << endl;
56 cout << left << "Number of CDC wire layers" << setw(15) << " " << cdcgeo.nWireLayers() << endl;
57 cout << left << "Sense Wire Diameter" << setw(15) << " " << cdcgeo.senseWireDiameter() << endl;
58 cout << left << "Field Wire Diameter" << setw(15) << " " << cdcgeo.fieldWireDiameter() << endl;
59
60 cout << "------| Summary-2 " << endl;
61 cout << left
62 << setw(4) << ""
63 << setw(10) << "Layer"
64 << setw(15) << "nwire"
65 << setw(15) << "radii sense"
66 << setw(15) << "dRdown"
67 << setw(15) << "dRup"
68 << setw(15) << "Delta"
69 << endl;
70
71 for (unsigned int i = 0; i < cdcgeo.nWireLayers(); ++i) {
72
73 fnWires = cdcgeo.nWiresInLayer(i);
74 h_nwires->SetBinContent(i + 1, fnWires);
75
76 // forward position of the input sense wire
77 const B2Vector3D& wirePosF = cdcgeo.wireForwardPosition(i, 0);
78 fswire_posF_phi = wirePosF.Phi();
79 h_swire_posF_phi->SetBinContent(i + 1, fswire_posF_phi);
80 fswire_posF_theta = wirePosF.Theta();
81 h_swire_posF_theta->SetBinContent(i + 1, fswire_posF_theta);
82
83 const B2Vector3D& wirePosB = cdcgeo.wireBackwardPosition(i, 0);
84 fswire_posB_phi = wirePosB.Phi();
85 h_swire_posB_phi->SetBinContent(i + 1, fswire_posB_phi);
86 fswire_posB_theta = wirePosB.Theta();
87 h_swire_posB_theta->SetBinContent(i + 1, fswire_posB_theta);
88
89 const B2Vector3D wireDir = (wirePosF - wirePosB);
90 fstereoAng = wireDir.Theta();
91 if (wirePosF.Phi() < wirePosB.Phi())fstereoAng *= -1;
92 h_stereo->SetBinContent(i + 1, fstereoAng);
93
94 fclength = wirePosF.Perp();
95 h_length->SetBinContent(i + 1, fclength);
96
97 // the width of the cell (trapezoidal)
98 fcwidth = 2 * PI * wirePosF.Perp() / fnWires;
99 h_width->SetBinContent(i + 1, fcwidth);
100
102 h_fwire_iradius->SetBinContent(i + 1, fwire_iradius);
103
105 h_fwire_oradius->SetBinContent(i + 1, fwire_oradius);
106
108 h_height->SetBinContent(i + 1, fcheight);
109
110 //Printing some useful information
111 double inradiusnext = cdcgeo.innerRadiusWireLayer()[i + 1];
112 double delta = -99.0;
113 if (i < cdcgeo.nWireLayers() - 1) {
114 delta = fwire_oradius - inradiusnext;
115 }
116
117 cout << left
118 << setw(4) << ""
119 << setw(10) << i
120 << setw(15) << fnWires
121 << setw(15) << cdcgeo.senseWireR(i)
122 << setw(15) << cdcgeo.senseWireR(i) - cdcgeo.innerRadiusWireLayer()[i]
123 << setw(15) << cdcgeo.outerRadiusWireLayer()[i] - cdcgeo.senseWireR(i)
124 << setw(15) << delta
125 << endl;
126 m_tree->Fill();
127
128 }
129
130 TDirectory* dhistos = m_file->mkdir("histos");
131 dhistos->cd();
132 h_nwires->Write();
133 h_swire_posF_phi->Write();
134 h_swire_posB_phi->Write();
135 h_swire_posF_theta->Write();
136 h_swire_posB_theta->Write();
137 h_stereo->Write();
138 h_fwire_iradius->Write();
139 h_fwire_oradius->Write();
140 h_width->Write();
141 h_height->Write();
142 h_length->Write();
143
144 TDirectory* dvar = m_file->mkdir("vars");
145 dvar->cd();
146
147 TVectorF sWireDia(1);
148 sWireDia[0] = cdcgeo.senseWireDiameter();
149 sWireDia.Write("sWireDia");
150
151 TVectorF fWireDia(1);
152 fWireDia[0] = cdcgeo.fieldWireDiameter();
153 fWireDia.Write("fWireDia");
154
155}
156
158{
159 // register output root file
160 m_file = new TFile("CDCGeometryScan.root", "RECREATE");
161 m_tree = new TTree("tree", "CDC Geometry details");
162 m_tree->SetDirectory(0);
163 m_tree->Branch("lnwires", &fnWires, "lnwires/I");
164 m_tree->Branch("lsteang", &fstereoAng, "lsteang/D");
165 m_tree->Branch("lswire_fpos_phi", &fswire_posF_phi, "lswire_fpos_phi/D");
166 m_tree->Branch("lswire_fpos_theta", &fswire_posF_theta, "lswire_fpos_theta/D");
167 m_tree->Branch("lswire_bpos_phi", &fswire_posB_phi, "lswire_bpos_phi/D");
168 m_tree->Branch("lswire_bpos_theta", &fswire_posB_theta, "lswire_bpos_theta/D");
169 m_tree->Branch("lfwire_inr", &fwire_iradius, "lfwire_inr/D");
170 m_tree->Branch("lfwire_or", &fwire_oradius, "lfwire_or/D");
171 m_tree->Branch("lcwidth", &fcwidth, "lcwidth/D");
172 m_tree->Branch("lclength", &fclength, "lclength/D");
173 m_tree->Branch("lcheight", &fcheight, "lcheight/D");
174}
175
177{
178 m_file->cd();
179 m_tree->Write();
180 m_file->Close();
181}
DataType Phi() const
The azimuth angle.
Definition: B2Vector3.h:151
DataType Theta() const
The polar angle.
Definition: B2Vector3.h:153
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
Definition: B2Vector3.h:200
The Class for CDC Geometry Parameters.
double fieldWireDiameter() const
Returns diameter of the field wire.
const B2Vector3D wireForwardPosition(uint layerId, int cellId, EWirePosition set=c_Base) const
Returns the forward position of the input sense wire.
double senseWireDiameter() const
Returns diameter of the sense wire.
const B2Vector3D wireBackwardPosition(uint layerId, int cellId, EWirePosition set=c_Base) const
Returns the backward position of the input sense wire.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
const double * innerRadiusWireLayer() const
Returns an array of inner radius of wire layers.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
unsigned nWireLayers() const
Returns a number of wire layers.
const double * outerRadiusWireLayer() const
Returns an array of outer radius of wire layers.
double senseWireR(int layerId) const
Returns radius of sense wire in each layer.
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
TTree * m_tree
output ROOT trees
int fnWires
nwire per layer dist
double fswire_posB_phi
sense wire position in backward dir (phi) per layer dist
void bookOutput()
Create the output TFiles and TTrees.
virtual void initialize() override
init
double fstereoAng
stereo angle per layer dist
double fwire_oradius
field wire outer radius per layer dist
double fclength
wire length per layer dist
virtual void terminate() override
terminate and save information
double fcheight
cell height per layer dist
double fcwidth
cell width per layer dist
double fswire_posF_theta
sense wire position in forward dir (theta) per layer dist
double fswire_posB_theta
sense wire position in backward dir (theta) per layer dist
double fwire_iradius
field wire inner radius per layer dist
TFile * m_file
output ROOT files
double fswire_posF_phi
sense wire position in forward dir (phi) per layer dist
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.