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 (const std::string &svar, const std::string &sfx) const
 Return dE/dx mean or norm-reso value for the given time and ring.
 
const 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 (const 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)
inlineexplicit

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()

const 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 ( const 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 82 of file CDCDedxInjectionTime.cc.

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

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

◆ 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 = array.size() + 1;
97 int nbelow = 0;
98
99 while (nabove - nbelow > 1) {
100 int middle = (nabove + nbelow) / 2;
101
102 if (value == array[middle - 1]) return middle - 1;
103 if (value < array[middle - 1]) nabove = middle;
104 else nbelow = middle;
105 }
106
107 return nbelow - 1;
108 }

◆ 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 ( const std::string & svar,
const 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 138 of file CDCDedxInjectionTime.h.


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