JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwCorrelator.cc
Go to the documentation of this file.
1/*!
2 * \file QwCorrelator.cc
3 * \brief Implementation of correlator data handler using LinRegBlue algorithms
4 * \author Michael Vallee
5 * \date 2018-08-01
6 */
7
8#include "QwCorrelator.h"
9
10// System includes
11#include <utility>
12
13// ROOT headers
14#include "TFile.h"
15#include "TH2D.h"
16
17// Qweak headers
18#include "QwOptions.h"
19#include "QwHelicityPattern.h"
20#include "VQwDataElement.h"
21#include "QwVQWK_Channel.h"
22#include "QwParameterFile.h"
23#include "QwRootFile.h"
24
25// Register this handler with the factory
27
28// Static members
30
31QwCorrelator::QwCorrelator(const TString& name)
32: VQwDataHandler(name),
33 fBlock(-1),
34 fDisableHistos(true),
35 fAlphaOutputFileBase("blueR"),
36 fAlphaOutputFileSuff("new.slope.root"),
39 fTree(0),
40 fAliasOutputFileBase("regalias_"),
43 fNameNoSpaces(name),
44 nP(0),nY(0),
46{
47 fNameNoSpaces.ReplaceAll(" ","_");
48 // Set default tree name and descriptions (in VQwDataHandler)
49 fTreeName = "lrb";
50 fTreeComment = "Correlations";
51 // Parsing separator
52 ParseSeparator = "_";
53
54 // Clear all data
56}
57
59: VQwDataHandler(source),
60 fBlock(source.fBlock),
66 fTree(0),
70 nP(source.nP),nY(source.nY),
72{
73 QwWarning << "QwCorrelator copy constructor required but untested" << QwLog::endl;
74
75 // Clear all data
77}
78
80{
81 // Close alpha and alias file
84}
85
87{
88 options.AddOptions()("print-correlations",
89 po::value<bool>(&fPrintCorrelations)->default_bool_value(false),
90 "print correlations after determining them");
91}
92
96
98{
100 file.PopValue("slope-file-base", fAlphaOutputFileBase);
101 file.PopValue("slope-file-suff", fAlphaOutputFileSuff);
102 file.PopValue("slope-path", fAlphaOutputPath);
103 file.PopValue("alias-file-base", fAliasOutputFileBase);
104 file.PopValue("alias-file-suff", fAliasOutputFileSuff);
105 file.PopValue("alias-path", fAliasOutputPath);
106 file.PopValue("disable-histos", fDisableHistos);
107 file.PopValue("block", fBlock);
108 if (fBlock >= 4)
109 QwWarning << "QwCorrelator: expect 0 <= block <= 3 but block = "
110 << fBlock << QwLog::endl;
111}
112
114{
115 // Add to total count
116 fTotalCount++;
117
118 // Start as good event
119 fGoodEvent = 0;
120
121 // Event error flag
123 if ( GetEventcutErrorFlag() != 0) fErrCounts_EF++;
124 // Dependent variable error codes
125 for (size_t i = 0; i < fDependentVar.size(); ++i) {
126 fGoodEvent |= fDependentVar.at(i)->GetErrorCode();
127 fDependentValues.at(i) = (fDependentVar[i]->GetValue(fBlock+1));
128 if (fDependentVar.at(i)->GetErrorCode() !=0) (fErrCounts_DV.at(i))++;
129 }
130 // Independent variable error codes
131 for (size_t i = 0; i < fIndependentVar.size(); ++i) {
132 fGoodEvent |= fIndependentVar.at(i)->GetErrorCode();
133 fIndependentValues.at(i) = (fIndependentVar[i]->GetValue(fBlock+1));
134 if (fIndependentVar.at(i)->GetErrorCode() !=0) (fErrCounts_IV.at(i))++;
135 }
136
137 // If good, process event
138 if (fGoodEvent == 0) {
139 fGoodCount++;
140
141 TVectorD P(fIndependentValues.size(), fIndependentValues.data());
142 TVectorD Y(fDependentValues.size(), fDependentValues.data());
143 linReg += std::make_pair(P, Y);
144 }
145}
146
148{
149 // Clear error counters
150 fErrCounts_EF = 0;
151 std::fill(fErrCounts_DV.begin(), fErrCounts_DV.end(), 0);
152 std::fill(fErrCounts_IV.begin(), fErrCounts_IV.end(), 0);
153
154 // Clear event counts
155 fTotalCount = 0;
156 fGoodCount = 0;
157 fGoodEvent = -1;
158
159 // Clear regression
160 linReg.clear();
161}
162
163void QwCorrelator::AccumulateRunningSum(VQwDataHandler &value, Int_t count, Int_t ErrorMask)
164{
165 QwCorrelator* correlator = dynamic_cast<QwCorrelator*>(&value);
166 if (correlator) {
167 linReg += correlator->linReg;
168 } else {
169 QwWarning << "QwCorrelator::AccumulateRunningSum "
170 << "can only accept other QwCorrelator objects."
171 << QwLog::endl;
172 }
173}
174
176{
177 // Check if any channels are active
178 if (nP == 0 || nY == 0) {
179 return;
180 }
181
182 QwMessage << "QwCorrelator::CalcCorrelations(): name=" << GetName() << QwLog::endl;
183
184 // Print entry summary
185 QwVerbose << "QwCorrelator: "
186 << "total entries: " << fTotalCount << ", "
187 << "good entries: " << fGoodCount
188 << QwLog::endl;
189 // and warn if zero
190 if (fTotalCount > 100 && fGoodCount == 0) {
191 QwWarning << "QwCorrelator: "
192 << "< 1% good events, "
193 << fGoodCount << " of " << fTotalCount
194 << QwLog::endl;
195 }
196
197 // Event error flag
198 if (fErrCounts_EF > 0) {
199 QwVerbose << " Entries failed due to error flag: "
201 }
202 // Dependent variable error codes
203 for (size_t i = 0; i < fDependentVar.size(); ++i) {
204 if (fErrCounts_DV.at(i) > 0) {
205 QwVerbose << " Entries failed due to " << fDependentVar.at(i)->GetElementName()
206 << ": " << fErrCounts_DV.at(i) << QwLog::endl;
207 }
208 }
209 // Independent variable error codes
210 for (size_t i = 0; i < fIndependentVar.size(); ++i) {
211 if (fErrCounts_IV.at(i) > 0) {
212 QwVerbose << " Entries failed due to " << fIndependentVar.at(i)->GetElementName()
213 << ": " << fErrCounts_IV.at(i) << QwLog::endl;
214 }
215 }
216
217 if (! linReg.failed()) {
218
219 if (fPrintCorrelations) {
220 linReg.printSummaryP();
221 linReg.printSummaryY();
222 }
223
224 linReg.solve();
225
226 if (fPrintCorrelations) {
227 linReg.printSummaryAlphas();
228 linReg.printSummaryMeansWithUnc();
229 linReg.printSummaryMeansWithUncCorrected();
230 }
231 }
232
233 // Fill tree
234 if (fTree) fTree->Fill();
235 else QwWarning << "No tree" << QwLog::endl;
236
237 // Write alpha and alias file
240}
241
242
243/** Load the channel map
244 *
245 * @param mapfile Filename of map file
246 * @return Zero when success
247 */
248Int_t QwCorrelator::LoadChannelMap(const std::string& mapfile)
249{
250 // Open the file
251 QwParameterFile map(mapfile);
252
253 // Read the sections of dependent variables
254 std::pair<EQwHandleType,std::string> type_name;
255
256 // Add independent variables and sensitivities
257 while (map.ReadNextLine()) {
258 // Throw away comments, whitespace, empty lines
259 map.TrimComment();
260 map.TrimWhitespace();
261 if (map.LineIsEmpty()) continue;
262 // Get first token: label (dv or iv), second token is the name like "asym_blah"
263 string primary_token = map.GetNextToken(" ");
264 string current_token = map.GetNextToken(" ");
265 // Parse current token into independent variable type and name
266 type_name = ParseHandledVariable(current_token);
267
268 if (primary_token == "iv") {
269 fIndependentType.push_back(type_name.first);
270 fIndependentName.push_back(type_name.second);
271 fIndependentFull.push_back(current_token);
272 }
273 else if (primary_token == "dv") {
274 fDependentType.push_back(type_name.first);
275 fDependentName.push_back(type_name.second);
276 fDependentFull.push_back(current_token);
277 }
278 else if (primary_token == "treetype") {
279 QwMessage << "Tree Type read, ignoring." << QwLog::endl;
280 }
281 else {
282 QwError << "LoadChannelMap in QwCorrelator read invalid primary_token " << primary_token << QwLog::endl;
283 }
284 }
285
286 return 0;
287}
288
289
291{
293
294 // Return if correlator is not enabled
295
296 /// Fill vector of pointers to the relevant data elements
297 for (size_t dv = 0; dv < fDependentName.size(); dv++) {
298 // Get the dependent variables
299
300 const VQwHardwareChannel* dv_ptr = 0;
301
302 if (fDependentType.at(dv)==kHandleTypeMps){
303 // Quietly ignore the MPS type when we're connecting the asym & diff
304 continue;
305 }else{
306 dv_ptr = this->RequestExternalPointer(fDependentFull.at(dv));
307 if (dv_ptr==NULL){
308 switch (fDependentType.at(dv)) {
309 case kHandleTypeAsym:
310 dv_ptr = asym.RequestExternalPointer(fDependentName.at(dv));
311 break;
312 case kHandleTypeDiff:
313 dv_ptr = diff.RequestExternalPointer(fDependentName.at(dv));
314 break;
315 default:
316 QwWarning << "QwCorrelator::ConnectChannels(QwSubsystemArrayParity& asym, QwSubsystemArrayParity& diff): "
317 << "Dependent variable, " << fDependentName.at(dv)
318 << ", for asym/diff correlator does not have proper type, type=="
319 << fDependentType.at(dv) << "." << QwLog::endl;
320 break;
321 }
322 }
323 if (dv_ptr == NULL){
324 QwWarning << "QwCombiner::ConnectChannels(QwSubsystemArrayParity& asym, QwSubsystemArrayParity& diff): Dependent variable, "
325 << fDependentName.at(dv)
326 << ", was not found (fullname=="
327 << fDependentFull.at(dv)<< ")." << QwLog::endl;
328 continue;
329 }
330 }
331
332 // pair creation
333 if(dv_ptr != NULL){
334 // fDependentVarType.push_back(fDependentType.at(dv));
335 fDependentVar.push_back(dv_ptr);
336 }
337
338 }
339
340 // Add independent variables
341 for (size_t iv = 0; iv < fIndependentName.size(); iv++) {
342 // Get the independent variables
343 const VQwHardwareChannel* iv_ptr = 0;
344 iv_ptr = this->RequestExternalPointer(fIndependentFull.at(iv));
345 if (iv_ptr==NULL){
346 switch (fIndependentType.at(iv)) {
347 case kHandleTypeAsym:
348 iv_ptr = asym.RequestExternalPointer(fIndependentName.at(iv));
349 break;
350 case kHandleTypeDiff:
351 iv_ptr = diff.RequestExternalPointer(fIndependentName.at(iv));
352 break;
353 default:
354 QwWarning << "Independent variable for correlator has unknown type."
355 << QwLog::endl;
356 break;
357 }
358 }
359 if (iv_ptr) {
360 fIndependentVar.push_back(iv_ptr);
361 } else {
362 QwWarning << "Independent variable " << fIndependentName.at(iv) << " for correlator could not be found."
363 << QwLog::endl;
364 }
365
366 }
367 fIndependentValues.resize(fIndependentVar.size());
368 fDependentValues.resize(fDependentVar.size());
369
370 nP = fIndependentName.size();
371 nY = fDependentName.size();
372
373 linReg.setDims(nP, nY);
374 linReg.init();
375
376 fErrCounts_IV.resize(fIndependentVar.size(),0);
377 fErrCounts_DV.resize(fDependentVar.size(),0);
378
379 return 0;
380}
381
382
384 QwRootFile *treerootfile,
385 const std::string& treeprefix,
386 const std::string& branchprefix)
387{
388 // Check if any channels are active
389 if (nP == 0 || nY == 0) {
390 return;
391 }
392
393 // Check if tree name is specified
394 if (fTreeName == "") {
395 QwWarning << "QwCorrelator: no tree name specified, use 'tree-name = value'" << QwLog::endl;
396 return;
397 }
398
399 // Create alpha and alias files before trying to create the tree
400 OpenAlphaFile(treeprefix);
401 OpenAliasFile(treeprefix);
402
403 // Construct tree name and create new tree
404 const std::string name = treeprefix + fTreeName;
405 treerootfile->NewTree(name, fTreeComment.c_str());
406 fTree = treerootfile->GetTree(name);
407 // Check to make sure the tree was created successfully
408 if (fTree == NULL) return;
409
410 // Set up branches
411 fTree->Branch(TString(branchprefix + "total_count"), &fTotalCount);
412 fTree->Branch(TString(branchprefix + "good_count"), &fGoodCount);
413
414 fTree->Branch(TString(branchprefix + "n"), &(linReg.fGoodEventNumber));
415 fTree->Branch(TString(branchprefix + "ErrorFlag"), &(linReg.fErrorFlag));
416
417 auto bn = [&](const TString& n) {
418 return TString(branchprefix + n);
419 };
420 auto pm = [](TMatrixD& m) {
421 return m.GetMatrixArray();
422 };
423 auto lm = [](TMatrixD& m, const TString& n) {
424 return Form("%s[%d][%d]/D", n.Data(), m.GetNrows(), m.GetNcols());
425 };
426 auto branchm = [&](TTree* tree, TMatrixD& m, const TString& n) {
427 tree->Branch(bn(n),pm(m),lm(m,n));
428 };
429 auto pv = [](TVectorD& v) {
430 return v.GetMatrixArray();
431 };
432 auto lv = [](TVectorD& v, const TString& n) {
433 return Form("%s[%d]/D", n.Data(), v.GetNrows());
434 };
435 auto branchv = [&](TTree* tree, TVectorD& v, const TString& n) {
436 tree->Branch(bn(n),pv(v),lv(v,n));
437 };
438
439 branchm(fTree,linReg.Axy, "A");
440 branchm(fTree,linReg.dAxy, "dA");
441
442 branchm(fTree,linReg.mVPP, "VPP");
443 branchm(fTree,linReg.mVPY, "VPY");
444 branchm(fTree,linReg.mVYP, "VYP");
445 branchm(fTree,linReg.mVYY, "VYY");
446 branchm(fTree,linReg.mVYYp, "VYYp");
447
448 branchm(fTree,linReg.mSPP, "SPP");
449 branchm(fTree,linReg.mSPY, "SPY");
450 branchm(fTree,linReg.mSYP, "SYP");
451 branchm(fTree,linReg.mSYY, "SYY");
452 branchm(fTree,linReg.mSYYp, "SYYp");
453
454 branchm(fTree,linReg.mRPP, "RPP");
455 branchm(fTree,linReg.mRPY, "RPY");
456 branchm(fTree,linReg.mRYP, "RYP");
457 branchm(fTree,linReg.mRYY, "RYY");
458 branchm(fTree,linReg.mRYYp, "RYYp");
459
460 branchv(fTree,linReg.mMP, "MP"); // Parameter mean
461 branchv(fTree,linReg.mMY, "MY"); // Uncorrected mean
462 branchv(fTree,linReg.mMYp, "MYp"); // Corrected mean
463
464 branchv(fTree,linReg.mSP, "dMP"); // Parameter mean error
465 branchv(fTree,linReg.mSY, "dMY"); // Uncorrected mean error
466 branchv(fTree,linReg.mSYp, "dMYp"); // Corrected mean error
467
468}
469
470/// \brief Construct the histograms in a folder with a prefix
471void QwCorrelator::ConstructHistograms(TDirectory *folder, TString &prefix)
472{
473 // Skip if disabled
474 if (fDisableHistos) return;
475
476 // Check if any channels are active
477 if (nP == 0 || nY == 0) {
478 return;
479 }
480
481 // Go to directory
482 TString name(fName);
483 name.ReplaceAll(" ","_");
484 folder->mkdir(name)->cd();
485
486 //..... 1D, iv
487 fH1iv.resize(nP);
488 for (int i = 0; i < nP; i++) {
489 fH1iv[i] = TH1D(
490 Form("P%d",i),
491 Form("iv P%d=%s, pass=%s ;iv=%s (ppm)",i,fIndependentName[i].c_str(),fName.Data(),fIndependentName[i].c_str()),
492 128,0.,0.);
493 fH1iv[i].GetXaxis()->SetNdivisions(4);
494 }
495
496 //..... 2D, iv correlations
497 Double_t x1 = 0;
498 fH2iv.resize(nP);
499 for (int i = 0; i < nP; i++) {
500 fH2iv[i].resize(nP);
501 for (int j = i+1; j < nP; j++) { // not all are used
502 fH2iv[i][j] = TH2D(
503 Form("P%d_P%d",i,j),
504 Form("iv correlation P%d_P%d, pass=%s ;P%d=%s (ppm);P%d=%s (ppm) ",
505 i,j,fName.Data(),i,fIndependentName[i].c_str(),j,fIndependentName[j].c_str()),
506 64,-x1,x1,
507 64,-x1,x1);
508 fH2iv[i][j].GetXaxis()->SetTitleColor(kBlue);
509 fH2iv[i][j].GetYaxis()->SetTitleColor(kBlue);
510 fH2iv[i][j].GetXaxis()->SetNdivisions(4);
511 fH2iv[i][j].GetYaxis()->SetNdivisions(4);
512 }
513 }
514
515 //..... 1D, dv
516 fH1dv.resize(nY);
517 for (int i = 0; i < nY; i++) {
518 fH1dv[i] = TH1D(
519 Form("Y%d",i),
520 Form("dv Y%d=%s, pass=%s ;dv=%s (ppm)",i,fDependentName[i].c_str(),fName.Data(),fDependentName[i].c_str()),
521 128,0.,0.);
522 fH1dv[i].GetXaxis()->SetNdivisions(4);
523 }
524
525 //..... 2D, dv-iv correlations
526 Double_t y1 = 0;
527 fH2dv.resize(nP);
528 for (int i = 0; i < nP; i++) {
529 fH2dv[i].resize(nY);
530 for (int j = 0; j < nY; j++) {
531 fH2dv[i][j] = TH2D(
532 Form("P%d_Y%d",i,j),
533 Form("iv-dv correlation P%d_Y%d, pass=%s ;P%d=%s (ppm);Y%d=%s (ppm) ",
534 i,j,fName.Data(),i,fIndependentName[i].c_str(),j,fDependentName[j].c_str()),
535 64,-x1,x1,
536 64,-y1,y1);
537 fH2dv[i][j].GetXaxis()->SetTitleColor(kBlue);
538 fH2dv[i][j].GetYaxis()->SetTitleColor(kBlue);
539 fH2dv[i][j].GetXaxis()->SetNdivisions(4);
540 fH2dv[i][j].GetYaxis()->SetNdivisions(4);
541 }
542 }
543
544 // store list of names to be archived
545 fHnames.resize(2);
546 fHnames[0] = TH1D("NamesIV",Form("IV name list nIV=%d",nP),nP,0,1);
547 for (int i = 0; i < nP; i++)
548 fHnames[0].Fill(fIndependentName[i].c_str(),1.*i);
549 fHnames[1] = TH1D("NamesDV",Form("DV name list nIV=%d",nY),nY,0,1);
550 for (int i = 0; i < nY; i++)
551 fHnames[1].Fill(fDependentName[i].c_str(),i*1.);
552}
553
554/// \brief Fill the histograms
556{
557 // Skip if disabled
558 if (fDisableHistos) return;
559
560 // Check if any channels are active
561 if (nP == 0 || nY == 0) {
562 return;
563 }
564
565 // Skip if bad event
566 if (fGoodEvent != 0) return;
567
568 // Fill histograms
569 for (size_t i = 0; i < fIndependentValues.size(); i++) {
570 fH1iv[i].Fill(fIndependentValues[i]);
571 for (size_t j = i+1; j < fIndependentValues.size(); j++)
573 }
574 for (size_t j = 0; j < fDependentValues.size(); j++) {
575 fH1dv[j].Fill(fDependentValues[j]);
576 for (size_t i = 0; i < fIndependentValues.size(); i++)
577 fH2dv[i][j].Fill(fIndependentValues[i], fDependentValues[j]);
578 }
579}
580
582{
583 // Ensure in output file
585
586 // Write objects
587 linReg.Axy.Write("slopes");
588 linReg.dAxy.Write("sigSlopes");
589
590 linReg.mRPP.Write("IV_IV_correlation");
591 linReg.mRPY.Write("IV_DV_correlation");
592 linReg.mRYY.Write("DV_DV_correlation");
593 linReg.mRYYp.Write("DV_DV_correlation_prime");
594
595 linReg.mMP.Write("IV_mean");
596 linReg.mMY.Write("DV_mean");
597 linReg.mMYp.Write("DV_mean_prime");
598
599 // number of events
600 TMatrixD Mstat(1,1);
601 Mstat(0,0)=linReg.getUsedEve();
602 Mstat.Write("MyStat");
603
604 //... IVs
605 TH1D hiv("IVname","names of IVs",nP,-0.5,nP-0.5);
606 for (int i=0;i<nP;i++) hiv.Fill(fIndependentFull[i].c_str(),i);
607 hiv.Write();
608
609 //... DVs
610 TH1D hdv("DVname","names of IVs",nY,-0.5,nY-0.5);
611 for (int i=0;i<nY;i++) hdv.Fill(fDependentFull[i].c_str(),i);
612 hdv.Write();
613
614 // sigmas
615 linReg.mSP.Write("IV_sigma");
616 linReg.mSY.Write("DV_sigma");
617 linReg.mSYp.Write("DV_sigma_prime");
618
619 // raw covariances
620 linReg.mVPP.Write("IV_IV_rawVariance");
621 linReg.mVPY.Write("IV_DV_rawVariance");
622 linReg.mVYY.Write("DV_DV_rawVariance");
623 linReg.mVYYp.Write("DV_DV_rawVariance_prime");
624 TVectorD mVY2(TMatrixDDiag(linReg.mVYY));
625 mVY2.Write("DV_rawVariance");
626 TVectorD mVP2(TMatrixDDiag(linReg.mVPP));
627 mVP2.Write("IV_rawVariance");
628 TVectorD mVY2prime(TMatrixDDiag(linReg.mVYYp));
629 mVY2prime.Write("DV_rawVariance_prime");
630
631 // normalized covariances
632 linReg.mSPP.Write("IV_IV_normVariance");
633 linReg.mSPY.Write("IV_DV_normVariance");
634 linReg.mSYY.Write("DV_DV_normVariance");
635 linReg.mSYYp.Write("DV_DV_normVariance_prime");
636 TVectorD sigY2(TMatrixDDiag(linReg.mSYY));
637 sigY2.Write("DV_normVariance");
638 TVectorD sigX2(TMatrixDDiag(linReg.mSPP));
639 sigX2.Write("IV_normVariance");
640 TVectorD sigY2prime(TMatrixDDiag(linReg.mSYYp));
641 sigY2prime.Write("DV_normVariance_prime");
642
643 linReg.Axy.Write("A_xy");
644 linReg.Ayx.Write("A_yx");
645}
646
647void QwCorrelator::OpenAlphaFile(const std::string& prefix)
648{
649 // Create old-style blueR ROOT file
650 std::string name = prefix + fAlphaOutputFileBase + run_label.Data() + fAlphaOutputFileSuff;
651 std::string path = fAlphaOutputPath + "/";
652 std::string file = path + name;
653 fAlphaOutputFile = new TFile(TString(file), "RECREATE", "correlation coefficients");
654 if (! fAlphaOutputFile->IsWritable()) {
655 QwError << "QwCorrelator could not create output file " << file << QwLog::endl;
656 delete fAlphaOutputFile;
658 }
659}
660
661void QwCorrelator::OpenAliasFile(const std::string& prefix)
662{
663 // Turn "." into "_" in run_label (no "." allowed in function name, and must
664 // agree with the filename)
665 std::string label(run_label);
666 std::replace(label.begin(), label.end(), '.', '_');
667 // Create old-style regalias script
668 std::string name = prefix + fAliasOutputFileBase + label + fAliasOutputFileSuff;
669 std::string path = fAliasOutputPath + "/";
670 std::string file = path + name + ".C"; // add extension outside of file suffix
671 fAliasOutputFile.open(file, std::ofstream::out);
672 if (fAliasOutputFile.good()) {
673 fAliasOutputFile << Form("void %s(int i = 0) {", name.c_str()) << std::endl;
674 } else {
675 QwWarning << "QwCorrelator: Could not write to alias output file " << QwLog::endl;
676 }
677}
678
680{
681 // Close slopes output file
682 if (fAlphaOutputFile) {
683 fAlphaOutputFile->Write();
684 fAlphaOutputFile->Close();
685 }
686}
687
689{
690 // Close alias output file
691 if (fAliasOutputFile.good()) {
692 fAliasOutputFile << "}" << std::endl << std::endl;
693 fAliasOutputFile.close();
694 } else {
695 QwWarning << "QwCorrelator: Unable to close alias output file." << QwLog::endl;
696 }
697}
698
700{
701 // Ensure output file is open
702 if (fAliasOutputFile.bad()) {
703 QwWarning << "QwCorrelator: Could not write to alias output file " << QwLog::endl;
704 return;
705 }
706
707 fAliasOutputFile << " if (i == " << fCycleCounter << ") {" << std::endl;
708 fAliasOutputFile << Form(" TTree* tree = (TTree*) gDirectory->Get(\"mul\");") << std::endl;
709 for (int i = 0; i < nY; i++) {
710 fAliasOutputFile << Form(" tree->SetAlias(\"reg_%s\",",fDependentFull[i].c_str()) << std::endl;
711 fAliasOutputFile << Form(" \"%s",fDependentFull[i].c_str());
712 for (int j = 0; j < nP; j++) {
713 fAliasOutputFile << Form("%+.4e*%s", -linReg.Axy(j,i), fIndependentFull[j].c_str());
714 }
715 fAliasOutputFile << "\");" << std::endl;
716 }
717 fAliasOutputFile << " }" << std::endl;
718
719 // Increment call counter
721}
722
An options class which parses command line, config file and environment.
#define QwVerbose
Predefined log drain for verbose messages.
Definition QwLog.h:54
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
#define QwWarning
Predefined log drain for warnings.
Definition QwLog.h:44
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
ROOT file and tree management wrapper classes.
Parameter file parsing and management.
Definition of the pure virtual base class of all data elements.
Decoding and management for VQWK ADC channels (6x32-bit datawords)
#define REGISTER_DATA_HANDLER_FACTORY(A)
Definition QwFactory.h:263
Correlator data handler using LinRegBlue algorithms.
Helicity pattern analysis and management.
const VQwHardwareChannel * RequestExternalPointer(const TString &name) const
const VQwHardwareChannel * RequestExternalPointer(const TString &name) const
Retrieve a direct pointer to an external variable Searches for the named variable in external subsyst...
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Command-line and configuration file options processor.
Definition QwOptions.h:141
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Definition QwOptions.h:170
Configuration file parser with flexible tokenization and search capabilities.
Bool_t PopValue(const std::string keyname, T &retvalue)
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
void TrimComment(const char commentchar)
std::string GetNextToken(const std::string &separatorchars)
Get next token as a string.
A wrapper class for a ROOT file or memory mapped file.
Definition QwRootFile.h:827
void NewTree(const std::string &name, const std::string &desc)
Create a new tree with name and description.
Definition QwRootFile.h:912
TTree * GetTree(const std::string &name)
Get the tree with name.
Definition QwRootFile.h:943
Abstract base for concrete hardware channels implementing dual-operator pattern.
Data handler computing correlations and linear-regression coefficients.
std::vector< std::string > fIndependentName
void OpenAliasFile(const std::string &prefix)
unsigned int fGoodEvent
void WriteAlphaFile()
std::string fAlphaOutputPath
void CloseAliasFile()
void ClearEventData() override
std::string fAliasOutputFileBase
void OpenAlphaFile(const std::string &prefix)
void ProcessData() override
QwCorrelator(const TString &name)
Constructor with name.
std::vector< std::vector< TH2D > > fH2iv
void CalcCorrelations()
~QwCorrelator() override
std::vector< Double_t > fIndependentValues
std::string fAlphaOutputFileBase
std::vector< EQwHandleType > fIndependentType
std::string fAliasOutputPath
std::ofstream fAliasOutputFile
Int_t ConnectChannels(QwSubsystemArrayParity &asym, QwSubsystemArrayParity &diff) override
Connect to Channels (asymmetry/difference only)
TString fNameNoSpaces
TFile * fAlphaOutputFile
void ConstructTreeBranches(QwRootFile *treerootfile, const std::string &treeprefix="", const std::string &branchprefix="") override
Construct the tree branches.
void ParseConfigFile(QwParameterFile &file) override
void CloseAlphaFile()
Int_t fCycleCounter
static bool fPrintCorrelations
void WriteAliasFile()
LinRegBevPeb linReg
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms in a folder with a prefix.
std::vector< std::string > fIndependentFull
std::vector< const VQwHardwareChannel * > fIndependentVar
std::string fAlphaOutputFileSuff
std::vector< TH1D > fHnames
std::vector< TH1D > fH1dv
std::string fAliasOutputFileSuff
std::vector< std::vector< TH2D > > fH2dv
std::vector< TH1D > fH1iv
void ProcessOptions(QwOptions &options)
std::vector< int > fErrCounts_DV
void FillHistograms() override
Fill the histograms.
bool fDisableHistos
std::vector< int > fErrCounts_IV
static void DefineOptions(QwOptions &options)
Subsystem array container specialized for parity analysis with asymmetry calculations.
const UInt_t * GetEventcutErrorFlagPointer() const
std::vector< std::string > fDependentFull
void AccumulateRunningSum()
void SetEventcutErrorFlagPointer(const UInt_t *errorflagptr)
TString GetName()
std::vector< Double_t > fDependentValues
virtual void ParseConfigFile(QwParameterFile &file)
std::vector< const VQwHardwareChannel * > fDependentVar
UInt_t GetEventcutErrorFlag() const
VQwDataHandler(const TString &name)
std::string ParseSeparator
std::string fTreeComment
std::string fTreeName
std::pair< EQwHandleType, std::string > ParseHandledVariable(const std::string &variable)
std::vector< EQwHandleType > fDependentType
std::vector< std::string > fDependentName