BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
VData.cxx
Go to the documentation of this file.
1/**
2 * @file VData.cxx
3 * @author zhangzeheng (zhangzeheng@ihep.ac.cn)
4 * @brief provides definitions of functions to handle our cached hv info.
5 * @version 0.1
6 * @date 2022-01-19
7 *
8 * @copyright Copyright (c) 2022
9 *
10 */
11
12#include "VData.h"
13#include <algorithm>
14#include <iostream>
15// #include "GaudiKernel/MsgStream.h"
16
17bool VData::isValid( Time_t time ) const {
18 time += time_offset;
19 if ( time > Boundary_time_High || time < Boundary_time_Low ) { return false; }
20 std::vector<Time_t>::const_iterator iter =
21 std::upper_bound( timeVector.begin(), timeVector.end(), time );
22 int index2 = iter - timeVector.begin();
23 Time_t time2 = timeVector[index2], time1 = timeVector[index2 - 1];
24 if ( abs( time - time2 ) > 10 && abs( time - time1 ) > 10 ) { return false; }
25 return true;
26}
27
29 VDataItem voltage;
30 time += time_offset;
31 if ( time > Boundary_time_High || time < Boundary_time_Low )
32 {
33 // MsgStream log(msgSvc(), name());
34 // log << MSG::INFO << "MdcHvDropSvc::initialize()" << endmsg;
35 std::cerr << "Error! time exceeds boundary. up:down" << getUpperBoundaryEventTime() << ":"
36 << getLowerBoundaryEventTime() << std::endl;
37 std::cerr << "this should not happen. check your code that matters with VData"
38 << std::endl;
39 // if (Boundary_time_High==Boundary_time_Low && Boundary_time_Low==0){
40 // std::cerr << "you need to call updateBoundary() after inserting items.";
41 // }
42 // std::cerr << std::endl;
43 return voltage;
44 }
45 std::vector<Time_t>::iterator iter =
46 std::upper_bound( timeVector.begin(), timeVector.end(), time );
47 int index2 = iter - timeVector.begin();
48 Time_t time2 = timeVector[index2], time1 = timeVector[index2 - 1];
49
50 VDataItem &voltage2 = VdataVector[index2], &voltage1 = VdataVector[index2 - 1];
51 for ( size_t i = 0; i < voltage.size(); i++ )
52 {
53 voltage[i] = voltage1[i] + ( (double)( time - time1 ) ) / ( time2 - time1 ) *
54 ( voltage2[i] - voltage1[i] );
55 }
56 return voltage;
57}
59 double a[] = {
60 1871.65, 1988.291667, 2016.875, 2017.791667, 2044.25, 2029.25, 2016.75, 1986.5, 2111,
61 2199, 2187.5, 2226, 2214.75, 2233, 2216, 2222.75, 2199.5, 2217.75,
62 2189.25, 2142.75, 2119.5, 2192.25, 2209.5, 2218, 2201, 2211.25, 2227,
63 2226, 2186.25, 2201.5, 2217, 2211.5, 2177, 2191.25, 2192.25, 2135.75,
64 2133.25, 2200.75, 2218.75, 2204.25, 2137.5, 2139.75, 2059.5,
65 };
66 voltagesStd = VDataItem::fromArray( a );
67 time_offset = 6;
68 Boundary_time_High = 0;
69 Boundary_time_Low = 0;
70}
71
72/**
73 * @brief throw all cached data. next time you might have to prepare cache again..
74 *
75 */
77 Boundary_time_High = 0;
78 Boundary_time_Low = 0;
79 timeVector.clear();
80 VdataVector.clear();
81}
82
84 VDataItem voltTripPerc;
85 VDataItem voltage = getVoltage( time );
86 for ( size_t i = 0; i < voltage.size(); i++ )
87 { voltTripPerc[i] = ( voltagesStd[i] - voltage[i] ) / voltagesStd[i]; }
88 return voltTripPerc;
89}
91 VDataItem voltTripPerc = getDrop( time );
92 double totalDropPerc = 0;
93 for ( size_t i = 0; i < voltTripPerc.size(); i++ ) totalDropPerc += voltTripPerc[i];
94 return totalDropPerc / voltTripPerc.size();
95}
97 VDataItem voltTripPerc = getDrop( time );
98 double totalDropPerc = 0;
99 for ( size_t i = 0; i < 20; i++ ) totalDropPerc += voltTripPerc[i];
100 for ( size_t i = 25 - 1; i < voltTripPerc.size(); i++ ) totalDropPerc += voltTripPerc[i];
101
102 return totalDropPerc / ( voltTripPerc.size() - 4 );
103}
104/**
105 * @brief add a entry to our cache. the entry has to be pushed back in ascending order,
106 * with no gap. inserting a item that is within timeboundary will fail and do nothing.
107 *
108 * @param time_HV_SLOWCTRL a time in database time; not event time
109 * @param data
110 */
111void VData::push_back_sorted( Time_t time_HV_SLOWCTRL, const VDataItem& data ) {
112 if ( time_HV_SLOWCTRL <= Boundary_time_High )
113 { // first check if time is in boundary
114 // std::vector<Time_t>::iterator iter = std::upper_bound(timeVector.begin(),
115 // timeVector.end(), time_HV_SLOWCTRL); if (! (iter == timeVector.end())) {return;} //if
116 // found time in vector
117 return;
118 }
119 timeVector.push_back( time_HV_SLOWCTRL );
120 VdataVector.push_back( data );
122}
123
124VDataItem VDataItem::fromArray( const double* item ) {
125 VDataItem out;
126 for ( size_t i = 0; i < VDataItem::size(); i++ ) { out[i] = item[i]; }
127 return out;
128}
TTree * data
Double_t time
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
class defination for our cached hv info.
long Time_t
Definition VData.h:28
bool isValid(Time_t time) const
Definition VData.cxx:17
double getAvgDrop(Time_t time)
Definition VData.cxx:90
Time_t getUpperBoundaryEventTime()
Definition VData.h:53
void push_back_sorted(Time_t time_HV_SLOWCTRL, const VDataItem &data)
add a entry to our cache. the entry has to be pushed back in ascending order, with no gap....
Definition VData.cxx:111
double getAvgDropButVeryDrop(Time_t time)
Definition VData.cxx:96
VDataItem getVoltage(Time_t time)
Definition VData.cxx:28
Time_t getLowerBoundaryEventTime()
Definition VData.h:54
void clear()
throw all cached data. next time you might have to prepare cache again..
Definition VData.cxx:76
void updateBoundary()
Definition VData.h:45
VDataItem getDrop(Time_t time)
Definition VData.cxx:83
VData()
Definition VData.cxx:58
static VDataItem fromArray(const double *item)
Definition VData.cxx:124
static size_t size()
Definition VData.h:22