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 29 of file CDCDedxInjectionTime.h.

Constructor & Destructor Documentation

◆ CDCDedxInjectionTime() [1/2]

Default constructor.

Definition at line 36 of file CDCDedxInjectionTime.h.

36: m_injectionvar() {};
std::vector< std::vector< double > > m_injectionvar
CDC dE/dx injection time payloads for dEdx mean and reso.

◆ CDCDedxInjectionTime() [2/2]

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

Constructor.

Definition at line 41 of file CDCDedxInjectionTime.h.

41: m_injectionvar(vinjcalib) {};

◆ ~CDCDedxInjectionTime()

~CDCDedxInjectionTime ( )
inline

Destructor.

Definition at line 46 of file CDCDedxInjectionTime.h.

46{};

Member Function Documentation

◆ getConstVector()

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

Return vector of all constant vector of payload.

Definition at line 59 of file CDCDedxInjectionTime.h.

60 {
61 return m_injectionvar;
62 };

◆ 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 80 of file CDCDedxInjectionTime.cc.

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

◆ 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 77 of file CDCDedxInjectionTime.h.

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

◆ 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 87 of file CDCDedxInjectionTime.h.

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

◆ 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 128 of file CDCDedxInjectionTime.h.

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

◆ 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 98 of file CDCDedxInjectionTime.h.

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

◆ 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 67 of file CDCDedxInjectionTime.h.

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

◆ 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 13 of file CDCDedxInjectionTime.cc.

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

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 141 of file CDCDedxInjectionTime.h.


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