Diana Software
MSideAmplitude.cc
Go to the documentation of this file.
1 #include "MSideAmplitude.hh"
2 #include "QEvent.hh"
3 #include "QEventList.hh"
4 #include "QOFData.hh"
5 #include "QRunDataHandle.hh"
6 #include "QAveragePulseHandle.hh"
8 #include "QBaseType.hh"
9 #include "QVector.hh"
10 #include "QRawEvent.hh"
11 #include "QJitter.hh"
12 #include "QJitterHandle.hh"
13 #include <cmath>
14 
16 
17 using namespace Diana;
18 using std::string;
19 
21 {
22  ev.Require<QPulseInfo>("DAQ","PulseInfo");
23  ev.Require<QHeader>("DAQ","Header");
24  ev.Require<QOFData>("COF","OFData");
25 
26  ev.Add<QDouble>("Amplitude");
27  ev.Add<QDouble>("NSigma");
28  ev.Add<QInt>("MaximumPosition");
29  fSamplesOwner = GetString("SamplesOwner","COF");
30  ev.Require<QVector>(fSamplesOwner,"OF");
31 
32  // get dataset
33  GlobalHandle<QInt> dHandle("Dataset");
34  GlobalData().Get("",&dHandle,"");
35  fDataset = dHandle.Get();
36 }
37 
38 void MSideAmplitude::Do(QEvent& ev, const QEventList& neighbours)
39 {
40 
41  // const QHeader& header = ev.Get<QHeader>("DAQ","Header");
42  const QPulseInfo& pi = ev.Get<QPulseInfo>("DAQ","PulseInfo");
43  const int ch_side = pi.GetChannelId();
44 
45  // const QOFData& ofData = ev.Get<QOFData>(fSamplesOwner.c_str(),"OFData");
46  const QVector& OFSamplesSide = ev.Get<QVector>(fSamplesOwner.c_str(),"OF");
47 
48  ev.Get<QDouble>("Amplitude") = Q_DOUBLE_DEFAULT;
49  ev.Get<QDouble>("NSigma") = Q_DOUBLE_DEFAULT;
50  ev.Get<QInt>("MaximumPosition") = Q_INT_DEFAULT;
51 
52  string InputFilename = GetString("JitterInput","jitter.txt");
53 
54  for(size_t i = 0;i < neighbours.Size();i++){
55  const QPulseInfo& o_pi = neighbours[i].Get<QPulseInfo>("DAQ","PulseInfo");
56  const int ch_main = o_pi.GetChannelId();
57  const QOFData& o_ofData = neighbours[i].Get<QOFData>("COF","OFData");
58 
59  const QHeader& headerMain = neighbours[i].Get<QHeader>("DAQ","Header");
60  QRunDataHandle rHandleMain(headerMain.GetRun());
61  GlobalData().Get("DAQ",&rHandleMain,"");
62  const QRunData& MrunData = rHandleMain.Get();
63 
64  double samplFreq = MrunData.GetChannelRunData(ch_main).fSamplingFrequency;
65  double ADC2mV = MrunData.GetChannelRunData(ch_main).fADC2mV;
66 
67  // double selFreq;
68  // if(samplFreq > LsamplFreq) selFreq = LsamplFreq;
69  // else selFreq = samplFreq;
70 
71  // get OF resolution for the side channel from global quantity COFData
72 
73  QCOFParametersHandle cofHandle;
74  QCOFData cofData;
75 
76  cofHandle.SetDataset(fDataset);
77  cofHandle.SetChannel(ch_side);
78 
79  GlobalData().Get(fSamplesOwner,&cofHandle,"");
80 
81  if(!cofHandle.IsValid()) {
82  Error("Channel %d, has no COFData global quantity: %s",ch_side,cofHandle.GetError().GetDescription().c_str());
83  return;
84  }
85  else {
86  cofData = cofHandle.Get();
87  }
88 
89  double resomV = cofData.fResolutionmV;
90 
91  // get jitter for side and main channel
92  QJitterHandle jHandleS(ch_side,fDataset);
93  QJitter Sjitters;
94 
95  QJitterHandle jHandleM(ch_main,fDataset);
96  QJitter Mjitters;
97 
98  GlobalData().Get("JitterByCoincidence",&jHandleS,InputFilename);
99  GlobalData().Get("JitterByCoincidence",&jHandleM,InputFilename);
100 
101  if(!jHandleS.IsValid()) {
102  if(!fBlackList.count(ch_side)) {
103  fBlackList.insert(ch_side);
104  Error("Channel %d, has no jitter. Cannot be synced: %s",ch_side,jHandleS.GetError().GetDescription().c_str());
105  }
106  return;
107  }
108  else if(!jHandleM.IsValid()) {
109  if(!fBlackList.count(ch_main)) {
110  fBlackList.insert(ch_main);
111  Error("Channel %d, has no jitter. Cannot be synced: %s",ch_main,jHandleM.GetError().GetDescription().c_str());
112  }
113  return;
114  }
115  else {
116  Sjitters = jHandleS.Get();
117  Mjitters = jHandleM.Get();
118  }
119  // calculates jitter between two channels as jitterMain - jitterSide where jitterMain (Side) is the jitter of chMain (Side) from refCh
120 
121  double jitter = Mjitters.fJitter - Sjitters.fJitter;
122 
123  // double MainPos = (o_ofData.GetDelay()/1000.)*samplFreq;
124  // int IntMainPos = (int) MainPos;
125 
126  double NewPos = (o_ofData.GetDelay()/1000.+jitter)*samplFreq;
127  int IntNewPos = lround( NewPos );
128 
129  if(IntNewPos >= 0 && IntNewPos < (int)OFSamplesSide.Size()){
130  double sideampl = OFSamplesSide[IntNewPos]*ADC2mV;
131  double nsig = ( sideampl )/resomV;
132  ev.Get<QDouble>("Amplitude") = sideampl;
133  ev.Get<QDouble>("NSigma") = nsig;
134  ev.Get<QInt>("MaximumPosition") = IntNewPos;
135  }
136  }
137 }
138 
140 {
141 
142 }
143 
#define Q_DOUBLE_DEFAULT
Definition: QDiana.hh:24
#define Q_INT_DEFAULT
Definition: QDiana.hh:26
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
module to calculate amplitude of side pulses starting from the main pulse and the jitter
void Do(Diana::QEvent &ev, const Diana::QEventList &neighbours)
Do method. Declare and implement only one of the two versions.
void Init(Diana::QEvent &ev)
Init method.
void Done()
Done method.
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
general quantities about COF
Definition: QCOFData.hh:15
double fResolutionmV
Definition: QCOFData.hh:24
double fSamplingFrequency
sampling frequency in Hz
double fADC2mV
conversion: mV = ADC * fADC2mV
list of references to const QEvent (s)
Definition: QEventList.hh:21
size_t Size() const
number of QEvent (s)
Definition: QEventList.hh:36
diana event
Definition: QEvent.hh:46
void Require(const std::string &owner, const std::string &name) const
notify the QEvent that we need a QObject, if not found an exception is thrown
Definition: QEvent.hh:232
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
void Add(WriteHandle< Q > &handle)
Add a QObject to the event.
Definition: QEvent.hh:193
Raw event: basic information like run number and time.
Definition: QHeader.hh:16
global handle for jitter by coincidence
jitter by coincidence
Definition: QJitter.hh:17
double fJitter
Definition: QJitter.hh:29
Raw event: bolometer channel, trigger positions and types.
Definition: QPulseInfo.hh:18
const int & GetChannelId() const
Get ChannelId.
Definition: QPulseInfo.hh:22
global handle for QRunData
Basic run based info.
Definition: QRunData.hh:20
const QChannelRunData & GetChannelRunData(const int channel) const
get channel based run data quantities
Definition: QRunData.cc:339
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...