23 int iSample = getSampleIndex(SampleName);
31 std::vector<std::map<std::string,ModeState>> ModeStatus;
34 for (
unsigned iSyst = 0; iSyst < SplineFileParPrefixNames[iSample].size(); iSyst++)
36 auto modes = SplineModeVecs[iSample][iSyst];
37 ModeStatus.emplace_back();
39 for (
auto const & mode : modes)
46 int nOscChannels = nOscChans[iSample];
48 for (
int iOscChan = 0; iOscChan < nOscChannels; iOscChan++)
50 std::cout <<
"Processing:" << OscChanFileNames[iOscChan] << std::endl;
52 TFile *File =
new TFile(OscChanFileNames[iOscChan].c_str(),
"READ");
53 if (!File || File->IsZombie())
55 std::cerr <<
"File " << OscChanFileNames[iOscChan] <<
" not found" << std::endl;
61 TIter Next(File->GetListOfKeys());
64 std::set<std::string> unique_spline_names;
67 while ((Key = (TKey *)Next()))
69 TClass *Class = gROOT->GetClass(Key->GetClassName());
72 if (!Class->InheritsFrom(
"TSpline3")){
continue;}
73 const char* keyName = Key->GetName();
75 char* SplineName =
new char[strlen(keyName) + 1];
76 strcpy(SplineName, keyName);
79 if(unique_spline_names.count(std::string(SplineName)) > 0){
80 if (std::string(SplineName).find(
"unknown") == std::string::npos){
85 unique_spline_names.insert(std::string(SplineName));
93 char *Token = strtok(SplineName,
"_");
94 Token = strtok(NULL,
"_");
98 for (
unsigned iSyst = 0; iSyst < SplineFileParPrefixNames[iSample].size(); iSyst++) {
99 if (strcmp(Syst, SplineFileParPrefixNames[iSample][iSyst].c_str()) == 0) {
111 Mode = strtok(NULL,
"_");
112 for (
unsigned int iMode = 0; iMode < SplineModeVecs[iSample][SystNum].size(); iMode++) {
120 if(ModeStatus[SystNum].count(Mode))
123 if(ModeStatus[SystNum][Mode]!=kInFile)
125 ModeStatus[SystNum][Mode]=kInConfigAndInFile;
134 ModeStatus[SystNum][Mode]=kInFile;
138 TSpline3 *Obj = (TSpline3 *)Key->ReadObj();
139 TSpline3_red *Spline =
new TSpline3_red(Obj);
142 Token = strtok(NULL,
"_");
144 Var1Bin = atoi(strtok(NULL,
"_"));
145 Var2Bin = atoi(strtok(NULL,
"_"));
147 char *Var3Bin_Char = strtok(NULL,
"_");
148 if (Var3Bin_Char == NULL)
154 Var3Bin = atoi(Var3Bin_Char);
157 if (isValidSplineIndex(SampleName, iOscChan, SystNum, ModeNum, Var1Bin, Var2Bin, Var3Bin))
161 int nKnots = Spline->GetNp();
164 for (
int iKnot = 0; iKnot < nKnots; iKnot++)
168 Spline->GetKnot(iKnot, x, y);
170 if (x == -999 || y == -999)
172 std::cerr <<
"Something has gone wrong... knot position is at -999" << std::endl;
173 std::cerr <<
"This error brought you by the folks at : "<<__FILE__<<
" : "<<__LINE__<<std::endl;
177 double Eval = Spline->Eval(x);
178 if (Eval < 0.99999 || Eval > 1.00001)
186 indexvec[iSample][iOscChan][SystNum][ModeNum][Var1Bin][Var2Bin][Var3Bin]=MonolithIndex;
188 coeffindexvec.push_back(CoeffIndex);
192 splinevec_Monolith.push_back(NULL);
196 splinevec_Monolith.push_back(Spline);
197 int np=Spline->GetNp();
198 uniquecoeffindices.push_back(MonolithIndex);
206 std::cout <<
"Got " << nb_splines <<
" total splines with " << unique_spline_names.size() <<
" unique names." << std::endl;
211 for (
unsigned iSyst = 0; iSyst < SplineFileParPrefixNames[iSample].size(); iSyst++)
213 std::vector<std::string> MissedModes;
214 for (
auto const & ModeUsage : ModeStatus[iSyst])
216 if(ModeUsage.second==kInFile)
218 MissedModes.push_back(ModeUsage.first);
222 if(MissedModes.size()!=0)
224 MACH3LOG_INFO(
"Parameter {} has splines for {} modes which have not been read in!", SplineFileParPrefixNames[iSample][iSyst].c_str(), MissedModes.size());
225 std::cout <<
"Modes: ";
226 for (
auto const & Mode : MissedModes)
228 std::cout << Mode <<
" ";
230 std::cout << std::endl;
238std::vector< std::vector<int> >
splinesDUNE::GetEventSplines(std::string SampleName,
int iOscChan,
int EventMode,
double Var1Val,
double Var2Val,
double Var3Val)
241 std::vector<std::vector<int>> ReturnVec;
242 int SampleIndex = -1;
243 for (
unsigned int iSample = 0; iSample < SampleNames.size(); iSample++) {
244 if (SampleName == SampleNames[iSample]) {
245 SampleIndex = iSample;
249 if (SampleIndex == -1)
251 MACH3LOG_ERROR(
"Sample not found: {}", SampleName);
252 throw MaCh3Exception(__FILE__, __LINE__);
255 int nSplineSysts = (int)indexvec[SampleIndex][iOscChan].size();
260 int Var1Bin = SplineBinning[SampleIndex][iOscChan][0]->FindBin(Var1Val)-1;
261 if (Var1Bin < 0 || Var1Bin >= SplineBinning[SampleIndex][iOscChan][0]->GetNbins()){
263 ReturnVec.push_back(std::vector<int>());
267 int Var2Bin = SplineBinning[SampleIndex][iOscChan][1]->FindBin(Var2Val)-1;
268 if (Var2Bin < 0 || Var2Bin >= SplineBinning[SampleIndex][iOscChan][1]->GetNbins()){
270 ReturnVec.push_back(std::vector<int>());
274 int Var3Bin = SplineBinning[SampleIndex][iOscChan][2]->FindBin(Var3Val)-1;
276 if (Var3Bin < 0 || Var3Bin >= SplineBinning[SampleIndex][iOscChan][2]->GetNbins()){
278 ReturnVec.push_back(std::vector<int>());
282 for(
int iSyst=0; iSyst<nSplineSysts; iSyst++){
283 std::vector<int> spline_modes = SplineModeVecs[SampleIndex][iSyst];
284 int nSampleModes = (int)spline_modes.size();
287 for(
int iMode = 0; iMode<nSampleModes ; iMode++){
288 if(Mode == spline_modes[iMode]){
289 std::vector<int> event_vec(7);
290 event_vec[0]=SampleIndex;
291 event_vec[1]=iOscChan;
294 event_vec[4]=Var1Bin;
295 event_vec[5]=Var2Bin;
296 event_vec[6]=Var3Bin;
297 int splineID=indexvec[SampleIndex][iOscChan][iSyst][iMode][Var1Bin][Var2Bin][Var3Bin];
298 if(!isflatarray[splineID]){
299 ReturnVec.push_back(event_vec);
313 int InputVectorSize = InputVector.size();
314 std::vector< std::vector<int> > ReturnVec(InputVectorSize);
317 for (
int iVec=0;iVec<InputVectorSize;iVec++) {
318 std::vector<int> TmpVec;
321 for (
unsigned int iMode = 0 ; iMode < InputVector[iVec].size() ; iMode++){
324 bool IncludeMode =
true;
327 for(
unsigned int entry_i = 0 ; entry_i < TmpVec.size() ; entry_i++){
329 if(iSplineMode == TmpVec[entry_i]){
336 TmpVec.push_back(iSplineMode);
341 ReturnVec[iVec] = TmpVec;