|
1 | 1 | #include "BinnedSplinesTutorial.h" |
2 | | -#include "manager/MaCh3Modes.h" |
3 | | -#include "samplePDF/StructsTutorial.h" |
4 | | - |
5 | | - |
6 | | -//MaCh3 core includes |
7 | | -#include <samplePDF/Structs.h> |
8 | | -#include <manager/MaCh3Logger.h> |
9 | | -//**************************************** |
10 | | - |
11 | | -_MaCh3_Safe_Include_Start_ //{ |
12 | | -//ROOT include |
13 | | -#include "TKey.h" |
14 | | -#include "TROOT.h" |
15 | | -_MaCh3_Safe_Include_End_ //} |
16 | 2 |
|
17 | 3 | BinnedSplineTutorial::BinnedSplineTutorial(covarianceXsec *xsec_cov, MaCh3Modes* Modes_) : splineFDBase(xsec_cov, Modes_) { |
18 | 4 | } |
19 | 5 |
|
20 | 6 | BinnedSplineTutorial::~BinnedSplineTutorial() { |
21 | 7 | } |
22 | 8 |
|
23 | | -/*! ETA - moved this into experiment specific code since it relies on experimental MC format and also the experiment spline name mapping |
24 | | - * Performs two jobs |
25 | | - * 1. Fills indexing/each sample |
26 | | - * 2. Creates the big spline vector |
27 | | - */ |
28 | | -void BinnedSplineTutorial::FillSampleArray(std::string SampleName, std::vector<std::string> OscChanFileNames) |
29 | | -{ |
30 | | - int iSample = getSampleIndex(SampleName); |
31 | | - |
32 | | - int nOscChannels = nOscChans[iSample]; |
| 9 | +std::vector<std::string> BinnedSplineTutorial::GetTokensFromSplineName(std::string FullSplineName) { |
| 10 | + std::vector<std::string> ReturnVec(TokenOrdering::kNTokens); |
| 11 | + |
| 12 | + TObjArray *tokens = TString(FullSplineName).Tokenize("."); |
| 13 | + /* |
| 14 | + A little hacky but lets us grab both old + new splines |
| 15 | + */ |
| 16 | + if(tokens->GetEntries()!=7){ |
| 17 | + delete tokens; |
| 18 | + tokens = TString(FullSplineName).Tokenize("_"); |
| 19 | + } |
33 | 20 |
|
34 | | - for (int iOscChan = 0; iOscChan < nOscChannels; iOscChan++) { |
35 | | - MACH3LOG_INFO("Processing: {}", OscChanFileNames[iOscChan]); |
36 | | - TSpline3* mySpline = nullptr; |
37 | | - TSpline3_red* Spline = nullptr; |
38 | | - TString Syst, Mode; |
39 | | - int nKnots, SystNum, ModeNum, Var1Bin, Var2Bin, Var3Bin = M3::_BAD_INT_; |
40 | | - double x,y, Eval = M3::_BAD_DOUBLE_; |
41 | | - bool isFlat = true; |
42 | | - |
43 | | - auto File = std::unique_ptr<TFile>(TFile::Open(OscChanFileNames[iOscChan].c_str())); |
44 | | - |
45 | | - if (!File || File->IsZombie()) { |
46 | | - MACH3LOG_ERROR("File {} not found", OscChanFileNames[iOscChan]); |
47 | | - throw MaCh3Exception(__FILE__, __LINE__); |
48 | | - } |
49 | | - |
50 | | - //This is the MC specific part of the code |
51 | | - //i.e. we always assume that the splines are just store in single TDirectory and they're all in there as single objects |
52 | | - for (auto k : *File->GetListOfKeys()) { |
53 | | - auto Key = static_cast<TKey*>(k); |
54 | | - TClass *Class = gROOT->GetClass(Key->GetClassName(), false); |
55 | | - if(!Class->InheritsFrom("TSpline3")) { |
56 | | - continue; |
57 | | - } |
58 | | - |
59 | | - TString FullSplineName = static_cast<TString>(Key->GetName()); |
60 | | - MACH3LOG_DEBUG("FillSplineName is {}", FullSplineName); |
61 | | - // First We split into binning and spline name |
62 | | - TObjArray *tokens = FullSplineName.Tokenize("."); |
63 | | - MACH3LOG_DEBUG("Number of tokens is {}", tokens->GetEntries()); |
64 | | - /* |
65 | | - A little hacky but lets us grab both old + new splines |
66 | | - */ |
67 | | - if(tokens->GetEntries()!=7){ |
68 | | - delete tokens; |
69 | | - tokens = FullSplineName.Tokenize("_"); |
70 | | - } |
71 | | - |
72 | | - Syst = static_cast<TObjString*>(tokens->At(1))->GetString(); |
73 | | - Mode = static_cast<TObjString*>(tokens->At(2))->GetString(); |
74 | | - // Skip 3 because it's "sp" |
75 | | - Var1Bin = static_cast<TObjString*>(tokens->At(4))->GetString().Atoi(); |
76 | | - Var2Bin = static_cast<TObjString*>(tokens->At(5))->GetString().Atoi(); |
77 | | - Var3Bin = 0; |
78 | | - |
79 | | - if (tokens->GetEntries() == 7) |
80 | | - { |
81 | | - Var3Bin = static_cast<TObjString*>(tokens->At(6))->GetString().Atoi(); |
82 | | - } |
83 | | - |
84 | | - SystNum = -1; |
85 | | - for (unsigned iSyst = 0; iSyst < SplineFileParPrefixNames[iSample].size(); iSyst++) { |
86 | | - if (strcmp(Syst, SplineFileParPrefixNames[iSample][iSyst].c_str()) == 0) { |
87 | | - SystNum = iSyst; |
88 | | - break; |
89 | | - } |
90 | | - } |
91 | | - |
92 | | - // If the syst doesn't match any of the spline names then skip it |
93 | | - if (SystNum == -1){ |
94 | | - MACH3LOG_WARN("Couldn't match!!"); |
95 | | - MACH3LOG_DEBUG("Couldn't Match any systematic name in xsec yaml with spline name: {}" , FullSplineName.Data()); |
96 | | - continue; |
97 | | - } |
98 | | - |
99 | | - ModeNum = -1; |
100 | | - for (unsigned int iMode = 0; iMode < SplineModeVecs[iSample][SystNum].size(); iMode++) { |
101 | | - if (strcmp(Mode, Modes->GetSplineSuffixFromMaCh3Mode(SplineModeVecs[iSample][SystNum][iMode]).c_str()) == 0) { |
102 | | - ModeNum = iMode; |
103 | | - break; |
104 | | - } |
105 | | - } |
106 | | - |
107 | | - if (ModeNum == -1) { |
108 | | - MACH3LOG_ERROR("Couldn't find mode for {} in {}. Problem Spline is : {} ", Mode, Syst, FullSplineName); |
109 | | - throw; |
110 | | - } |
111 | | - |
112 | | - |
113 | | - mySpline = Key->ReadObject<TSpline3>(); |
114 | | - |
115 | | - if (isValidSplineIndex(SampleName, iOscChan, SystNum, ModeNum, Var1Bin, Var2Bin, Var3Bin)) |
116 | | - { // loop over all the spline knots and check their value |
117 | | - MACH3LOG_DEBUG("Pushed back monolith for spline {}", FullSplineName); |
118 | | - // if the value is 1 then set the flat bool to false |
119 | | - nKnots = mySpline->GetNp(); |
120 | | - isFlat = true; |
121 | | - for (int iKnot = 0; iKnot < nKnots; iKnot++) |
122 | | - { |
123 | | - mySpline->GetKnot(iKnot, x, y); |
124 | | - |
125 | | - Eval = mySpline->Eval(x); |
126 | | - if (Eval < 0.99999 || Eval > 1.00001) |
127 | | - { |
128 | | - isFlat = false; |
129 | | - break; |
130 | | - } |
131 | | - } |
132 | | - |
133 | | - //Rather than keeping a mega vector of splines then converting, this should just keep everything nice in memory! |
134 | | - indexvec[iSample][iOscChan][SystNum][ModeNum][Var1Bin][Var2Bin][Var3Bin]=MonolithIndex; |
135 | | - coeffindexvec.push_back(CoeffIndex); |
136 | | - // Should save memory rather saving [x_i_0 ,... x_i_maxknots] for every spline! |
137 | | - if (isFlat) { |
138 | | - splinevec_Monolith.push_back(nullptr); |
139 | | - delete mySpline; |
140 | | - } else { |
141 | | - Spline = new TSpline3_red(mySpline, SplineInterpolationTypes[iSample][SystNum]); |
142 | | - delete mySpline; |
143 | | - |
144 | | - splinevec_Monolith.push_back(Spline); |
145 | | - uniquecoeffindices.push_back(MonolithIndex); //So we can get the unique coefficients and skip flat splines later on! |
146 | | - CoeffIndex+=nKnots; |
147 | | - } |
148 | | - //Incrementing MonolithIndex to keep track of number of valid spline indices |
149 | | - MonolithIndex+=1; |
150 | | - } else { |
151 | | - //Potentially you are not a valid spline index |
152 | | - delete mySpline; |
153 | | - } |
154 | | - }//End of loop over all TKeys in file |
| 21 | + ReturnVec[TokenOrdering::kSystToken] = (static_cast<TObjString*>(tokens->At(1)))->GetString(); |
| 22 | + ReturnVec[TokenOrdering::kModeToken] = (static_cast<TObjString*>(tokens->At(2)))->GetString(); |
| 23 | + // Skip 3 because it's "sp" |
| 24 | + ReturnVec[TokenOrdering::kVar1BinToken] = (static_cast<TObjString*>(tokens->At(4)))->GetString(); |
| 25 | + ReturnVec[TokenOrdering::kVar2BinToken] = (static_cast<TObjString*>(tokens->At(5)))->GetString(); |
| 26 | + ReturnVec[TokenOrdering::kVar3BinToken] = "0"; |
| 27 | + |
| 28 | + if (tokens->GetEntries() == 7) { |
| 29 | + ReturnVec[TokenOrdering::kVar3BinToken] = (static_cast<TObjString*>(tokens->At(6)))->GetString(); |
| 30 | + } |
155 | 31 |
|
156 | | - //A bit of clean up |
157 | | - File->Delete("*"); |
158 | | - File->Close(); |
159 | | - } //End of oscillation channel loop |
| 32 | + return ReturnVec; |
160 | 33 | } |
0 commit comments