Belle II Software development
CDCDedxInjectionTime Class Reference

dE/dx injection time calibration constants More...

#include <CDCDedxInjectionTime.h>

Inheritance diagram for CDCDedxInjectionTime:

Public Member Functions

 CDCDedxInjectionTime ()
 Default constructor.
 
 CDCDedxInjectionTime (const std::vector< std::vector< double > > &vinjcalib)
 Constructor.
 
 ~CDCDedxInjectionTime ()
 Destructor.
 
void printCorrection (std::string svar, std::string sfx) const
 Return dE/dx mean or norm-reso value for the given time and ring.
 
std::vector< std::vector< double > > getConstVector () const
 Return vector of all constant vector of payload.
 
const std::vector< double > & getTimeVector (unsigned int ring) const
 Return time vector.
 
const std::vector< double > & getMeanVector (unsigned int ring) const
 Return dedx mean vector.
 
const std::vector< double > & getResoVector (unsigned int ring) const
 Return dedx reso vector.
 
int getTimeBin (const std::vector< unsigned int > &array, unsigned int value) const
 Return time bin for the given time array.
 
double getCorrection (std::string svar, unsigned int ring, unsigned int time) const
 Return dE/dx mean or norm-reso value for the given time and ring.
 

Private Member Functions

double getSafely (unsigned int iv, int k) const
 Helper: safe access to a vector element.
 
 ClassDef (CDCDedxInjectionTime, 1)
 ClassDef.
 

Private Attributes

std::vector< std::vector< double > > m_injectionvar
 CDC dE/dx injection time payloads for dEdx mean and reso.
 

Detailed Description

dE/dx injection time calibration constants

Definition at line 25 of file CDCDedxInjectionTime.h.

Constructor & Destructor Documentation

◆ CDCDedxInjectionTime() [1/2]

Default constructor.

Definition at line 32 of file CDCDedxInjectionTime.h.

32: m_injectionvar() {};

◆ CDCDedxInjectionTime() [2/2]

CDCDedxInjectionTime ( const std::vector< std::vector< double > > & vinjcalib)
inline

Constructor.

Definition at line 37 of file CDCDedxInjectionTime.h.

37: m_injectionvar(vinjcalib) {};

◆ ~CDCDedxInjectionTime()

~CDCDedxInjectionTime ( )
inline

Destructor.

Definition at line 42 of file CDCDedxInjectionTime.h.

42{};

Member Function Documentation

◆ getConstVector()

std::vector< std::vector< double > > getConstVector ( ) const
inline

Return vector of all constant vector of payload.

Definition at line 55 of file CDCDedxInjectionTime.h.

56 {
57 return m_injectionvar;
58 };

◆ getCorrection()

double getCorrection ( std::string svar,
unsigned int ring,
unsigned int time ) const

Return dE/dx mean or norm-reso value for the given time and ring.

Parameters
svaris option for mean and reso calibration factor
ringis injection ring number (0/1 for LER/HER)
timeis injection time (large 0-20sec range)

Definition at line 83 of file CDCDedxInjectionTime.cc.

84{
85 if (svar != "mean" && svar != "reso") {
86 B2ERROR("wrong var input, choose mean or reso");
87 return 1.0;
88 }
89
90 if (ring > 1) {
91 B2ERROR("wrong ring input, choose 0 or 1");
92 return 1.0;
93 }
94
95 unsigned int iv = ring * 3 + 1 ;
96 if (svar == "reso") iv = ring * 3 + 2 ;
97
98 if (iv >= m_injectionvar.size()) return 1.0;
99
100 int sizev = m_injectionvar[iv].size(); //mean or reso
101 int sizet = m_injectionvar[ring * 3].size(); //time
102 if (sizet < 2 or sizev < 2) {
103 B2ERROR("calibration vectors are empty or have only a single element");
104 return 1.0;
105 }
106
107 std::vector<unsigned int> tedges(sizet); //time edges array
108 std::copy(m_injectionvar[ring * 3].begin(), m_injectionvar[ring * 3].end(), tedges.begin());
109
110 if (time >= 5e6) time = 5e6 - 10;
111
112 int it = getTimeBin(tedges, time);
113 if (it < 0) it = 0;
114
115 double center = 0.5 * (getSafely(ring * 3, it) + getSafely(ring * 3, it + 1));
116
117 //no corr before veto bin (usually one or two starting bin)
118 //intrapolation for entire range except
119 //--extrapolation (for first half and last half of intended bin)
120 int thisbin = it, nextbin = it;
121 if (center != time && it > 0) {
122
123 if (time < center) {
124 thisbin = it - 1;
125 } else {
126 if (it < sizet - 2) nextbin = it + 1;
127 else thisbin = it - 1;
128 }
129
130 if (it <= 2) {
131 double diff = getSafely(iv, 2) - getSafely(iv, 1) ;
132 if (diff < -0.015) { //difference above 1.0%
133 thisbin = it;
134 if (it == 1) nextbin = it;
135 else nextbin = it + 1;
136 } else {
137 if (it == 1) {
138 thisbin = it;
139 nextbin = it + 1;
140 }
141 }
142 }
143 }
144
145 double thisdedx = getSafely(iv, thisbin);
146 double nextdedx = getSafely(iv, nextbin);
147
148 double thistime = 0.5 * (getSafely(ring * 3, thisbin) + getSafely(ring * 3, thisbin + 1));
149 double nexttime = 0.5 * (getSafely(ring * 3, nextbin) + getSafely(ring * 3, nextbin + 1));
150
151 double newdedx = getSafely(iv, it);
152 if (thisbin != nextbin)
153 newdedx = thisdedx + ((nextdedx - thisdedx) / (nexttime - thistime)) * (time - thistime);
154
155 return newdedx;
156}
int getTimeBin(const std::vector< unsigned int > &array, unsigned int value) const
Return time bin for the given time array.
double getSafely(unsigned int iv, int k) const
Helper: safe access to a vector element.
std::vector< std::vector< double > > m_injectionvar
CDC dE/dx injection time payloads for dEdx mean and reso.

◆ getMeanVector()

const std::vector< double > & getMeanVector ( unsigned int ring) const
inline

Return dedx mean vector.

Parameters
ringis injection ring number (0/1 for LER/HER)

Definition at line 73 of file CDCDedxInjectionTime.h.

74 {
75 if (ring > 1) B2ERROR("wrong index for injection ring ");
76 if (ring * 3 + 1 >= m_injectionvar.size()) B2FATAL("CDCDedxInjectionTime: vector-of-vectors too short");
77 return m_injectionvar[ring * 3 + 1];
78 };

◆ getResoVector()

const std::vector< double > & getResoVector ( unsigned int ring) const
inline

Return dedx reso vector.

Parameters
ringis injection ring number (0/1 for LER/HER)

Definition at line 83 of file CDCDedxInjectionTime.h.

84 {
85 if (ring > 1) B2ERROR("wrong index for injection ring ");
86 if (ring * 3 + 2 >= m_injectionvar.size()) B2FATAL("CDCDedxInjectionTime: vector-of-vectors too short");
87 return m_injectionvar[ring * 3 + 2];
88 };

◆ getSafely()

double getSafely ( unsigned int iv,
int k ) const
inlineprivate

Helper: safe access to a vector element.

Parameters
ivvalid index of a vector
kindex of an element
Returns
element value

Definition at line 124 of file CDCDedxInjectionTime.h.

125 {
126 const auto& vector = m_injectionvar[iv]; // assuming iv is valid index and vector not empty
127 int last = vector.size() - 1;
128 if (k < 0) k = 0;
129 else if (k > last) k = last;
130 return vector[k];
131 }

◆ getTimeBin()

int getTimeBin ( const std::vector< unsigned int > & array,
unsigned int value ) const
inline

Return time bin for the given time array.

Parameters
arrayof time
valueof input time

Definition at line 94 of file CDCDedxInjectionTime.h.

95 {
96 int nabove, nbelow, middle;
97 nabove = array.size() + 1;
98 nbelow = 0;
99 while (nabove - nbelow > 1) {
100 middle = (nabove + nbelow) / 2;
101 if (value == array[middle - 1]) return middle - 1;
102 if (value < array[middle - 1]) nabove = middle;
103 else nbelow = middle;
104 }
105 return nbelow - 1;
106 }

◆ getTimeVector()

const std::vector< double > & getTimeVector ( unsigned int ring) const
inline

Return time vector.

Parameters
ringis injection ring number (0/1 for LER/HER)

Definition at line 63 of file CDCDedxInjectionTime.h.

64 {
65 if (ring > 1) B2ERROR("wrong index for injection ring ");
66 if (ring * 3 >= m_injectionvar.size()) B2FATAL("CDCDedxInjectionTime: vector-of-vectors too short");
67 return m_injectionvar[ring * 3];
68 };

◆ printCorrection()

void printCorrection ( std::string svar,
std::string sfx ) const

Return dE/dx mean or norm-reso value for the given time and ring.

Parameters
svaris option for printing mean and reso calibration
sfxto add suffix in file save

Definition at line 16 of file CDCDedxInjectionTime.cc.

17{
18
19 if (svar != "mean" && svar != "reso") {
20 B2WARNING("wrong variable input, choose mean or reso");
21 return;
22 }
23
24 std::string sring[2] = {"ler", "her"};
25 TCanvas* cdraw = new TCanvas("cdraw", "cdraw", 900, 500);
26 cdraw->cd();
27 cdraw->SetGridy(1);
28
29 for (int ir = 0; ir < 2; ir++) {
30
31 unsigned int iv = ir * 3 + 1 ;
32 if (svar == "reso") iv = ir * 3 + 2 ;
33
34 unsigned int sizev = m_injectionvar[iv].size(); //mean or reso
35 unsigned int sizet = m_injectionvar[ir * 3].size(); //time
36 if (sizev == 0 || sizet == 0) {
37 B2ERROR("empty calibration vector");
38 break;
39 }
40
41 std::vector<unsigned int> tedges(sizet); //time edges array
42 std::copy(m_injectionvar[ir * 3].begin(), m_injectionvar[ir * 3].end(), tedges.begin());
43
44 std::string hname = Form("hconst_%s_%s_%s", svar.data(), sring[ir].data(), sfx.data());
45 std::string title = Form("%s corrections;injection-time (#mu-sec);%s", svar.data(), svar.data());
46 TH1F hconst(hname.data(), title.data(), sizet - 1, 0, sizet - 1);
47
48 for (unsigned int ib = 0; ib < sizev; ib++) {
49
50 double corr = m_injectionvar[iv].at(ib);
51 double ledge = tedges[ib];
52 double uedge = tedges[ib + 1];
53
54 std::string label;
55 if (ledge < 2e4)label = Form("%0.01f-%0.01fK", ledge / 1e3, uedge / 1e3);
56 else if (ledge < 1e5)label = Form("%0.00f-%0.00fK", ledge / 1e3, uedge / 1e3);
57 else label = Form("%0.01f-%0.01fM", ledge / 1e6, uedge / 1e6);
58
59 hconst.SetBinContent(ib + 1, corr);
60 hconst.SetBinError(ib + 1, corr * 0.001);
61 hconst.GetXaxis()->SetBinLabel(ib + 1, Form("%s", label.data()));
62 B2INFO("ring: " << sring[ir] << ", time (" << ledge << "-" << uedge << "), mean: " << corr << "");
63 }
64
65 hconst.SetStats(0);
66 hconst.SetMarkerColor(ir + 1);
67 hconst.SetMarkerSize(1.05);
68 hconst.SetMarkerStyle(24);
69 hconst.GetXaxis()->SetLabelOffset(-0.055);
70 hconst.GetYaxis()->SetRangeUser(0.60, 1.10);
71 if (svar == "reso")hconst.GetYaxis()->SetRangeUser(0.01, 0.20);
72
73 if (ir == 0)hconst.DrawCopy("");
74 else hconst.DrawCopy(" same");
75 }
76
77 cdraw->SaveAs(Form("cdcdedx_timeinject_const_%s_%s.pdf", svar.data(), sfx.data()));
78 delete cdraw;
79
80}

Member Data Documentation

◆ m_injectionvar

std::vector<std::vector<double> > m_injectionvar
private

CDC dE/dx injection time payloads for dEdx mean and reso.

different for LER and HER vector to store payload values

Definition at line 137 of file CDCDedxInjectionTime.h.


The documentation for this class was generated from the following files: