21 using namespace Diana;
26 std::string window = GetString(
"WindowType",
"welch");
29 Warn(
"Window type not defined, using rectangular window");
33 Info(
"Window type: %d (%s)", fWindowType,window.c_str());
36 fCoherentGain = GetInt(
"WindowCoherentGain",2);
37 else fCoherentGain = 2;
38 fUseMainEvent = GetBool(
"UseMainEvent",
false);
39 fValidityKind = GetString(
"ValidityKind",
"dataset",
false);
40 if(fValidityKind !=
"dataset" && fValidityKind !=
"run") {
41 Panic(
"ValidityKind must be set to dataset or run");
46 fSingleChannel = GetBool(
"SingleChannel",
false,
false);
47 fPulseLabel = GetString(
"PulseLabel",
"DAQ@Pulse",
false);
62 if(fUseMainEvent) allchans.
Push(&ev);
63 for(
size_t ch = 0; ch < neighbours.
Size(); ch++) {
64 allchans.
Push(&neighbours[ch]);
66 int run = ev.
Get<
QHeader>(
"DAQ",
"Header").GetRun();
67 if (run != fCurrentRun) {
69 fSRuns.push_back(fCurrentRun);
73 if(fTimeLength == 0) {
75 if(fTimeLength %2 != 0) {
77 Info(
"Window size reduced to %d",fTimeLength);
80 fTransformer->SetWindowType(fWindowType, fCoherentGain);
83 QVectorC TransformedPulseIB(fTimeLength);
84 QVectorC TransformedPulseIF(fTimeLength);
85 QVectorC TransformedPulseJB(fTimeLength);
86 QVectorC TransformedPulseJF(fTimeLength);
87 for(
size_t i = 0; i < allchans.
Size(); i++) {
88 const int chanI = allchans[i].Get<
QPulseInfo>(
"DAQ",
"PulseInfo").GetChannelId();
89 const QVector& samplesIorig = allchans[i].GetByLabel<
QPulse>(fPulseLabel).GetSamples();
92 const QVector& samplesIB = samplesIviewB.
GetVector();
93 int err = Transform(samplesIB, TransformedPulseIB);
95 Error(
"QFFTRealComplex::TransformToFreq: pulse I");
98 TransformedPulseIB[0].SetRe(0);
99 TransformedPulseIB[0].SetIm(0);
102 const QVector& samplesIF = samplesIviewF.
GetVector();
103 err = Transform(samplesIF, TransformedPulseIF);
105 Error(
"QFFTRealComplex::TransformToFreq: pulse I");
108 TransformedPulseIF[0].SetRe(0);
109 TransformedPulseIF[0].SetIm(0);
111 for(
size_t j = i ; j < (fSingleChannel ? i+1: allchans.
Size()); j++) {
112 const int chanJ = allchans[j].Get<
QPulseInfo>(
"DAQ",
"PulseInfo").GetChannelId();
113 const QVector& samplesJorig = allchans[j].GetByLabel<
QPulse>(fPulseLabel).GetSamples();
115 const QVector& samplesJF = samplesJviewF.
GetVector();
116 err = Transform(samplesJF, TransformedPulseJF);
118 Error(
"QFFTRealComplex::TransformToFreq: pulse J");
121 TransformedPulseJF[0].SetRe(0);
122 TransformedPulseJF[0].SetIm(0);
125 const QVector& samplesJB = samplesJviewB.
GetVector();
127 err = Transform(samplesJB, TransformedPulseJB);
129 Error(
"QFFTRealComplex::TransformToFreq: pulse J");
132 TransformedPulseJB[0].SetRe(0);
133 TransformedPulseJB[0].SetIm(0);
140 fChannelList.push_back(chanJ);
144 element = TransformedPulseIF*TransformedPulseJF.
H();
145 phases = TransformedPulseIB*TransformedPulseJB.
H();
147 phases.
Div(magnitudes);
149 element.
Mult(phases);
153 chInfo.
fPower.Resize(fTimeLength);
154 chInfo.
fPower.Initialize(0);
158 chInfo.
fPower += TransformedPulseIF.GetModulusSquare();
159 chInfo.
fCoherence += TransformedPulseIB.Mult(TransformedPulseIF.Conj());
169 if(fTransformer != 0)
delete fTransformer;
170 std::stringstream str;
171 str<<
"Channel List: ";
172 for(
size_t i=0;i<fChannelList.size();i++) {
173 str<<fChannelList[i]<<
" ";
176 Debug(str.str().c_str());
179 std::map<int,std::map<int,ChannelInfo> >::const_iterator iterI = fRosetta.begin();
180 while(iterI != fRosetta.end() ) {
181 std::map<int,ChannelInfo>::const_iterator iterJ = iterI->second.begin();
182 while(iterJ != iterI->second.end() ) {
183 int chI =iterI->first;
184 int chJ =iterJ->first;
187 GlobalHandle<QMatrixC> covHandle(
"CovarianceFreq");
190 if(fValidityKind==
"dataset") {
191 GlobalHandle<QInt> dHandle(
"Dataset");
192 GlobalData().Get(
"",&dHandle,
"");
193 dataset = dHandle.Get();
194 covHandle.SetDataset(dataset);
195 }
else if (fValidityKind==
"run") {
196 if (fSRuns.size()==1){
197 covHandle.SetRun(fSRuns[0]);
199 else Panic(
"ValidityKind set to run is not permitted when reading multiple runs.");
201 else Panic(
"ValidityKind can be set only to run or dataset. Check cfg.");
202 covHandle.SetChannel(chI);
203 covHandle.SetChannel2(chJ);
205 GlobalData().Set(&covHandle,fOutput);
210 GlobalHandle<QVectorC> cohHandle(
"Coherence");
211 cohHandle.SetChannel(chI);
213 if(fValidityKind ==
"run") {
214 nfh.SetRun(fSRuns[0]);
215 cohHandle.SetRun(fSRuns[0]);
217 nfh.SetDataset(dataset);
218 cohHandle.SetDataset(dataset);
220 GlobalData().Set(&nfh, fOutput);
221 GlobalData().Set(&cohHandle,fOutput);
232 const size_t size = samples.Size();
233 QVector zeroMeanPulse(size), meanPulse(size);
234 double mean = samples.Sum(size)/size;
235 meanPulse.Initialize(mean);
236 zeroMeanPulse = samples;
237 zeroMeanPulse -= meanPulse;
238 return fTransformer->TransformToFreq(zeroMeanPulse, out);
#define REGISTER_MODULE(clazz)
Diana::QMatrixC fCovarianceFreq
Diana::QVectorC fCoherence
compute correlation between different frequencies
int Transform(const Diana::QVector &in, Diana::QVectorC &out)
void Init(Diana::QEvent &ev)
Init method.
void Do(Diana::QEvent &ev, const Diana::QEventList &neighbours)
Do method. Declare and implement only one of the two versions.
global handle for average noise power spectra
list of references to const QEvent (s)
void Push(const QEvent *obj)
add a QEvent
size_t Size() const
number of QEvent (s)
const Q & GetByLabel(const QEventLabel &label) const
Get a QObject in read mode by label.
void RequireByLabel(const QEventLabel &label) const
notify the QEvent that we need a QObject, if not found an exception is thrown
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
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
static WindowType StrToWindowType(const std::string &winName)
Convert string to window type.
Interface for complex matrices in Diana analysis.
QMatrix Magnitude() const
return magnitude of each element
const QMatrixC & Mult(const QMatrixC &mat)
Multiply element by element.
const QMatrixC & H()
compute hermitian conjugate
const QMatrixC & Div(const QMatrixC &mat)
Divide element by element.
const QMatrixC & Conjugate()
conjugate this matrix
Raw event: bolometer channel, trigger positions and types.
Raw event: sampled waveform.
Wrapper for a specific QRealComplexFFT algorithm class.
QVectorView for const QVector.
const QVector & GetVector() const
Get subview QVector.
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...