NuMu2020_TrimCAFs.C
Go to the documentation of this file.
1 // A macro to trim down a CAF file for use as an input to
2 // something like TMVA.
3 
4 #include "CAFAna/Core/Binning.h"
5 #include "CAFAna/Core/Spectrum.h"
7 
8 #include "CAFAna/Cuts/Cuts.h"
11 #include "CAFAna/Cuts/SpillCuts.h"
12 #include "CAFAna/Cuts/TimingCuts.h"
13 
14 #include "CAFAna/Vars/BPFVars.h"
19 #include "CAFAna/Vars/HistAxes.h"
22 #include "CAFAna/Vars/PngCVNVars.h"
24 #include "CAFAna/Vars/SpillVars.h"
25 #include "CAFAna/Vars/Vars.h"
27 #include "CAFAna/Vars/XsecTunes.h"
28 
29 #include "CAFAna/Analysis/Calcs.h"
30 #include "OscLib/OscCalcPMNSOpt.h"
31 
33 
34 #include "Utilities/rootlogon.C"
35 
36 
37 #include "TTree.h"
38 #include "TString.h"
40 
41 using namespace ana;
42 
43 // -----------------------------------------------------------
44 // -----------------------------------------------------------
45 // --- Add a class to do the CAF cutting.
46 // -----------------------------------------------------------
47 // -----------------------------------------------------------
49 {
50 public:
51  CAFTreeMaker(const std::string& wildcard, std::vector<Cut*> &cuts,
52  std::vector<TTree*> &trees, std::vector<Var*> &vars,
53  std::vector<std::string> varNames)
54  : SpectrumLoader(wildcard, kBeam),
55  fCuts(cuts),
56  fTrees(trees),
57  fVars(vars),
58  fNPassed(0)
59  {
60  // Create branches
61  fLocalVars.clear();
62  fLocalVars.resize(varNames.size(),0.);
63  for ( uint t = 0; t < fTrees.size(); ++t ) {
64  for ( uint v = 0; v < varNames.size(); ++v ) {
65  std::cout << "\tSetting branch address - " << varNames[v].c_str() << std::endl;
66  fTrees[t]->Branch( varNames[v].c_str(), &(fLocalVars[v]) );
67  }
68  }
69  }
70 
72  {
73  }
74 
75  void HandleRecord(caf::SRProxy* sr) override
76  {
77  if(fSpillCut && !(*fSpillCut)(&sr->spill)) return;
78  ++fNPassed;
79  // Fill my local vars.
80  for ( uint v = 0; v < fLocalVars.size(); ++v ) {
81  Var theVar = *(fVars[v]);
82  fLocalVars[v] = double( theVar(sr) );
83  }
84  // If passes cuts then fill trees.
85  for ( uint c = 0; c < fCuts.size(); ++c ) {
86  Cut theCut = *(fCuts[c]);
87  if ( theCut(sr) ) fTrees[c]->Fill();
88  }
89  }
90 
91  int GetNPassed() { return fNPassed; }
92 
93 protected:
94  std::vector<Cut*> fCuts;
95  std::vector<TTree*> fTrees;
96  std::vector<Var*> fVars;
97  std::vector<double> fLocalVars;
98  int fNPassed;
99 };
100 
101 // -----------------------------------------------------------
102 // -----------------------------------------------------------
103 // --- Now for my actual module.
104 // -----------------------------------------------------------
105 // -----------------------------------------------------------
106 void NuMu2020_TrimCAFs( bool IsFHC, bool IsFD, bool IsData=false ) {
107  // -----------------------------------------------------------
108  // --- First off, lets set some global things and make sure we know what we're running over...
109  // -----------------------------------------------------------
110  std::string sFHC_RHC = (IsFHC == true ? "fhc" :"rhc");
111  std::string sIsFD = (IsFD == true ? "FD" :"ND" );
112  std::string sIsData = (IsData == true ? "Data":"MC" );
113 
114  std::string OutName = "FlatTree-"+sFHC_RHC+"-"+sIsFD+"-"+sIsData+".root";
115 
116  // And write them out!
117  std::cout << "\n\nLots of input parameters, so I'm going to write them out now....;"
118  << "\n\t IsFHC " << (IsFHC == true ? "true --> Run in FHC " :"false --> Run in RHC" ) << " ==> sFHC_RHC is " << sFHC_RHC
119  << "\n\t IsFD " << (IsFD == true ? "true --> Run in FD " :"false --> Run in ND " ) << " ==> sIsTrain is " << sIsFD
120  << "\n\t IsData " << (IsData == true ? "true --> Run over Data" :"false --> Run over MC" ) << " ==> sIsData is " << sIsData
121  << "\n\n OutName is therefore " << OutName
122  << "\n\n" << std::endl;
123 
124  // -----------------------------------------------------------
125  // --- Any custom vars?
126  // -----------------------------------------------------------
127  // --- Is this a NuMu CC interaction?
128  const Var kIsNuMuCC([](const caf::SRProxy* sr) {
129  if (sr->mc.nnu == 0) return -5.f;
130  if (abs(sr->mc.nu[0].pdg) == 14 && sr->mc.nu[0].iscc)
131  { return 1.f; }
132  else return 0.f;
133  });
134 
135  // --- Is this a NuMu CC interaction?
136  const Var kOsc2019([](const caf::SRProxy* sr) {
137  if (sr->mc.nnu == 0) return -5.f;
138  // Set my calculator
141  calc.SetdCP ( M_PI*2 );
142  calc.SetDmsq32( 0.00248 );
143  calc.SetTh23 ( asin(sqrt(0.565)) );
144  // What horn am I looking at?
145  int Mu = 14;
146  if (sr->spill.isRHC) Mu= -14;
147  // Calculate weight and return.
148  float oscwgt = calc.P( Mu, Mu, kTrueE(sr) );
149  return oscwgt;
150 
151  });
152 
153  // Loose PTP Presel Quantile Boundaries
154  const Var kWhichQuant_LP([](const caf::SRProxy* sr) {
155  if ( sr->spill.isFHC ) {
156  // ------ FHC ------
157  if ( kNumuMuE2020(sr) < 0.75 ) {
158  if ( kHadEFrac(sr) < 0.118934 ) return 1.f; if ( kHadEFrac(sr) < 0.166448 ) return 2.f; if ( kHadEFrac(sr) < 0.247718 ) return 3.f; return 4.f;
159  }
160  if ( kNumuMuE2020(sr) < 1.0 ) {
161  if ( kHadEFrac(sr) < 0.134239 ) return 1.f; if ( kHadEFrac(sr) < 0.232964 ) return 2.f; if ( kHadEFrac(sr) < 0.334136 ) return 3.f; return 4.f;
162  }
163  if ( kNumuMuE2020(sr) < 1.1 ) {
164  if ( kHadEFrac(sr) < 0.159236 ) return 1.f; if ( kHadEFrac(sr) < 0.267000 ) return 2.f; if ( kHadEFrac(sr) < 0.373284 ) return 3.f; return 4.f;
165  }
166  if ( kNumuMuE2020(sr) < 1.2 ) {
167  if ( kHadEFrac(sr) < 0.158835 ) return 1.f; if ( kHadEFrac(sr) < 0.273729 ) return 2.f; if ( kHadEFrac(sr) < 0.397730 ) return 3.f; return 4.f;
168  }
169  if ( kNumuMuE2020(sr) < 1.3 ) {
170  if ( kHadEFrac(sr) < 0.175534 ) return 1.f; if ( kHadEFrac(sr) < 0.290012 ) return 2.f; if ( kHadEFrac(sr) < 0.417974 ) return 3.f; return 4.f;
171  }
172  if ( kNumuMuE2020(sr) < 1.4 ) {
173  if ( kHadEFrac(sr) < 0.175714 ) return 1.f; if ( kHadEFrac(sr) < 0.297095 ) return 2.f; if ( kHadEFrac(sr) < 0.434264 ) return 3.f; return 4.f;
174  }
175  if ( kNumuMuE2020(sr) < 1.5 ) {
176  if ( kHadEFrac(sr) < 0.173868 ) return 1.f; if ( kHadEFrac(sr) < 0.295911 ) return 2.f; if ( kHadEFrac(sr) < 0.443953 ) return 3.f; return 4.f;
177  }
178  if ( kNumuMuE2020(sr) < 1.6 ) {
179  if ( kHadEFrac(sr) < 0.168174 ) return 1.f; if ( kHadEFrac(sr) < 0.292872 ) return 2.f; if ( kHadEFrac(sr) < 0.454537 ) return 3.f; return 4.f;
180  }
181  if ( kNumuMuE2020(sr) < 1.7 ) {
182  if ( kHadEFrac(sr) < 0.161978 ) return 1.f; if ( kHadEFrac(sr) < 0.283332 ) return 2.f; if ( kHadEFrac(sr) < 0.455999 ) return 3.f; return 4.f;
183  }
184  if ( kNumuMuE2020(sr) < 1.8 ) {
185  if ( kHadEFrac(sr) < 0.158191 ) return 1.f; if ( kHadEFrac(sr) < 0.279510 ) return 2.f; if ( kHadEFrac(sr) < 0.460459 ) return 3.f; return 4.f;
186  }
187  if ( kNumuMuE2020(sr) < 1.9 ) {
188  if ( kHadEFrac(sr) < 0.154199 ) return 1.f; if ( kHadEFrac(sr) < 0.272286 ) return 2.f; if ( kHadEFrac(sr) < 0.460521 ) return 3.f; return 4.f;
189  }
190  if ( kNumuMuE2020(sr) < 2.0 ) {
191  if ( kHadEFrac(sr) < 0.155013 ) return 1.f; if ( kHadEFrac(sr) < 0.270021 ) return 2.f; if ( kHadEFrac(sr) < 0.462871 ) return 3.f; return 4.f;
192  }
193  if ( kNumuMuE2020(sr) < 2.25 ) {
194  if ( kHadEFrac(sr) < 0.152511 ) return 1.f; if ( kHadEFrac(sr) < 0.272472 ) return 2.f; if ( kHadEFrac(sr) < 0.467252 ) return 3.f; return 4.f;
195  }
196  if ( kNumuMuE2020(sr) < 2.50 ) {
197  if ( kHadEFrac(sr) < 0.151469 ) return 1.f; if ( kHadEFrac(sr) < 0.278108 ) return 2.f; if ( kHadEFrac(sr) < 0.467296 ) return 3.f; return 4.f;
198  }
199  if ( kNumuMuE2020(sr) < 2.75 ) {
200  if ( kHadEFrac(sr) < 0.144831 ) return 1.f; if ( kHadEFrac(sr) < 0.274064 ) return 2.f; if ( kHadEFrac(sr) < 0.458401 ) return 3.f; return 4.f;
201  }
202  if ( kNumuMuE2020(sr) < 3.0 ) {
203  if ( kHadEFrac(sr) < 0.139568 ) return 1.f; if ( kHadEFrac(sr) < 0.273579 ) return 2.f; if ( kHadEFrac(sr) < 0.456107 ) return 3.f; return 4.f;
204  }
205  if ( kNumuMuE2020(sr) < 3.5 ) {
206  if ( kHadEFrac(sr) < 0.139661 ) return 1.f; if ( kHadEFrac(sr) < 0.281539 ) return 2.f; if ( kHadEFrac(sr) < 0.458567 ) return 3.f; return 4.f;
207  }
208  if ( kNumuMuE2020(sr) < 4.0 ) {
209  if ( kHadEFrac(sr) < 0.136266 ) return 1.f; if ( kHadEFrac(sr) < 0.282126 ) return 2.f; if ( kHadEFrac(sr) < 0.480083 ) return 3.f; return 4.f;
210  }
211  if ( kNumuMuE2020(sr) < 5.0 ) {
212  if ( kHadEFrac(sr) < 0.139579 ) return 1.f; if ( kHadEFrac(sr) < 0.284188 ) return 2.f; if ( kHadEFrac(sr) < 0.504979 ) return 3.f; return 4.f;
213  }
214  return -5.f;
215  } else {
216  // ------ FHC ------
217  if ( kNumuMuE2020(sr) < 0.75 ) {
218  if ( kHadEFrac(sr) < 0.098619 ) return 1.f; if ( kHadEFrac(sr) < 0.135214 ) return 2.f; if ( kHadEFrac(sr) < 0.192215 ) return 3.f; return 4.f;
219  }
220  if ( kNumuMuE2020(sr) < 1.0 ) {
221  if ( kHadEFrac(sr) < 0.104589 ) return 1.f; if ( kHadEFrac(sr) < 0.172313 ) return 2.f; if ( kHadEFrac(sr) < 0.262349 ) return 3.f; return 4.f;
222  }
223  if ( kNumuMuE2020(sr) < 1.1 ) {
224  if ( kHadEFrac(sr) < 0.113074 ) return 1.f; if ( kHadEFrac(sr) < 0.194818 ) return 2.f; if ( kHadEFrac(sr) < 0.303350 ) return 3.f; return 4.f;
225  }
226  if ( kNumuMuE2020(sr) < 1.2 ) {
227  if ( kHadEFrac(sr) < 0.107167 ) return 1.f; if ( kHadEFrac(sr) < 0.192337 ) return 2.f; if ( kHadEFrac(sr) < 0.308861 ) return 3.f; return 4.f;
228  }
229  if ( kNumuMuE2020(sr) < 1.3 ) {
230  if ( kHadEFrac(sr) < 0.109772 ) return 1.f; if ( kHadEFrac(sr) < 0.196574 ) return 2.f; if ( kHadEFrac(sr) < 0.319727 ) return 3.f; return 4.f;
231  }
232  if ( kNumuMuE2020(sr) < 1.4 ) {
233  if ( kHadEFrac(sr) < 0.104231 ) return 1.f; if ( kHadEFrac(sr) < 0.191203 ) return 2.f; if ( kHadEFrac(sr) < 0.317569 ) return 3.f; return 4.f;
234  }
235  if ( kNumuMuE2020(sr) < 1.5 ) {
236  if ( kHadEFrac(sr) < 0.103482 ) return 1.f; if ( kHadEFrac(sr) < 0.192548 ) return 2.f; if ( kHadEFrac(sr) < 0.327409 ) return 3.f; return 4.f;
237  }
238  if ( kNumuMuE2020(sr) < 1.6 ) {
239  if ( kHadEFrac(sr) < 0.097463 ) return 1.f; if ( kHadEFrac(sr) < 0.184260 ) return 2.f; if ( kHadEFrac(sr) < 0.322252 ) return 3.f; return 4.f;
240  }
241  if ( kNumuMuE2020(sr) < 1.7 ) {
242  if ( kHadEFrac(sr) < 0.092475 ) return 1.f; if ( kHadEFrac(sr) < 0.174988 ) return 2.f; if ( kHadEFrac(sr) < 0.314649 ) return 3.f; return 4.f;
243  }
244  if ( kNumuMuE2020(sr) < 1.8 ) {
245  if ( kHadEFrac(sr) < 0.089280 ) return 1.f; if ( kHadEFrac(sr) < 0.170336 ) return 2.f; if ( kHadEFrac(sr) < 0.310179 ) return 3.f; return 4.f;
246  }
247  if ( kNumuMuE2020(sr) < 1.9 ) {
248  if ( kHadEFrac(sr) < 0.087216 ) return 1.f; if ( kHadEFrac(sr) < 0.168472 ) return 2.f; if ( kHadEFrac(sr) < 0.308919 ) return 3.f; return 4.f;
249  }
250  if ( kNumuMuE2020(sr) < 2.0 ) {
251  if ( kHadEFrac(sr) < 0.086789 ) return 1.f; if ( kHadEFrac(sr) < 0.166271 ) return 2.f; if ( kHadEFrac(sr) < 0.306587 ) return 3.f; return 4.f;
252  }
253  if ( kNumuMuE2020(sr) < 2.25 ) {
254  if ( kHadEFrac(sr) < 0.087671 ) return 1.f; if ( kHadEFrac(sr) < 0.169733 ) return 2.f; if ( kHadEFrac(sr) < 0.317026 ) return 3.f; return 4.f;
255  }
256  if ( kNumuMuE2020(sr) < 2.50 ) {
257  if ( kHadEFrac(sr) < 0.092355 ) return 1.f; if ( kHadEFrac(sr) < 0.180862 ) return 2.f; if ( kHadEFrac(sr) < 0.341470 ) return 3.f; return 4.f;
258  }
259  if ( kNumuMuE2020(sr) < 2.75 ) {
260  if ( kHadEFrac(sr) < 0.095437 ) return 1.f; if ( kHadEFrac(sr) < 0.192014 ) return 2.f; if ( kHadEFrac(sr) < 0.356454 ) return 3.f; return 4.f;
261  }
262  if ( kNumuMuE2020(sr) < 3.0 ) {
263  if ( kHadEFrac(sr) < 0.098152 ) return 1.f; if ( kHadEFrac(sr) < 0.196408 ) return 2.f; if ( kHadEFrac(sr) < 0.363917 ) return 3.f; return 4.f;
264  }
265  if ( kNumuMuE2020(sr) < 3.5 ) {
266  if ( kHadEFrac(sr) < 0.114951 ) return 1.f; if ( kHadEFrac(sr) < 0.226053 ) return 2.f; if ( kHadEFrac(sr) < 0.388776 ) return 3.f; return 4.f;
267  }
268  if ( kNumuMuE2020(sr) < 4.0 ) {
269  if ( kHadEFrac(sr) < 0.119728 ) return 1.f; if ( kHadEFrac(sr) < 0.238313 ) return 2.f; if ( kHadEFrac(sr) < 0.420346 ) return 3.f; return 4.f;
270  }
271  if ( kNumuMuE2020(sr) < 5.0 ) {
272  if ( kHadEFrac(sr) < 0.123770 ) return 1.f; if ( kHadEFrac(sr) < 0.251614 ) return 2.f; if ( kHadEFrac(sr) < 0.481630 ) return 3.f; return 4.f;
273  }
274  return -5.f;
275  }
276  return -5.f;
277  });
278 
279  const Cut kMyLoosePresel([](const caf::SRProxy* sr) {
280  return ( sr->sel.cvnloosepreselptp.numuid > 0.2 );
281  });
282 
283  // -----------------------------------------------------------
284  // --- Now lets get our Quartile cuts
285  // -----------------------------------------------------------
286  /*
287  std::string fdspecfile = (std::string)std::getenv("NUMUDATA_DIR")+"ana2020/Quantiles/quantiles_"+sFHC_RHC+"_full_numu2020.root";
288  TFile* inFile = TFile::Open( fdspecfile.c_str() );
289  // How many quantiles?
290  const int NHadEFracQuantiles = 4; // defines how many divisions of hadEFrac are used
291  // Old Presel Vec...
292  TH2 *FDSpec2D_OP = (TH2*)inFile->FindObjectAny( "FDSpec2D_OldPresel" );
293  TH2 *FDSpec2D_LP = (TH2*)inFile->FindObjectAny( "FDSpec2D_LoosePTP" );
294  std::vector<std::vector<double>> HadEFracQuantCuts_OP = GetQuantileBins(FDSpec2D_OP, kNumuCCOptimisedAxis2020, kHadEFracAxis2020, NHadEFracQuantiles, true);
295  std::vector<std::vector<double>> HadEFracQuantCuts_LP = GetQuantileBins(FDSpec2D_LP, kNumuCCOptimisedAxis2020, kHadEFracAxis2020, NHadEFracQuantiles, true);
296  //*/
297 
298  // -----------------------------------------------------------
299  // --- Create my output file.
300  // -----------------------------------------------------------
301  TFile *outFile = new TFile( OutName.c_str(), "RECREATE" );
302 
303  // -----------------------------------------------------------
304  // --- Lets figure out which definition I want to run over....
305  // -----------------------------------------------------------
306  std::string MyDef = "";
307  if ( IsFD && !IsData ) MyDef = "prod_caf_R19-11-18-prod5reco.f_fd_genie_N1810j0211a_nonswap_"+sFHC_RHC+"_nova_v08_full_v1"; // FD MC
308  else if ( IsFD && IsData ) MyDef = "prod_caf_R19-11-18-prod5reco.i_fd_cosmic_"+sFHC_RHC+"_full_v1_goodruns"; // FD Cosmics
309  else if ( !IsFD && IsFHC && !IsData ) MyDef = "prod_caf_R19-11-18-prod5reco.d_nd_genie_N1810j0211a_nonswap_fhc_nova_v08_full_v1_minus_p9"; // ND FHC MC
310  else if ( !IsFD && !IsFHC && !IsData ) MyDef = "prod_caf_R19-11-18-prod5reco.d_nd_genie_N1810j0211a_nonswap_rhc_nova_v08_full_v1"; // ND RHC MC
311  else if ( !IsFD && IsFHC && IsData ) MyDef = "prod_caf_R19-11-18-prod5reco.d.f_nd_numi_fhc_full_v1_minus_p9_goodruns"; // ND FHC Data
312  else if ( !IsFD && !IsFHC && IsData ) MyDef = "prod_caf_R19-11-18-prod5reco.g_nd_numi_rhc_full_v1_goodruns"; // ND RHC Data
313 
314  // -----------------------------------------------------------
315  // --- What weights do I want to use?
316  // -----------------------------------------------------------
317  Var kXSecWgt = kXSecCVWgt2020;
318  Var kPPFXWgt = kPPFXFluxCVWgt;
319 
320  // -----------------------------------------------------------
321  // --- What cuts do I want to use?
322  // -----------------------------------------------------------
323  Cut kMyBaseCut = kNumuQuality && kMyLoosePresel && kNumuContainFD2020;
324  if (!IsFD) kMyBaseCut = kNumuQuality && kMyLoosePresel && kNumuContainND2020;
325  // If FD Data (cosmics) then apply timing cut.
326  if (IsFD && IsData) kMyBaseCut = kMyBaseCut && kInCosmicTimingWindow;
327  // If MC, then apply the Beam Spill cut to remove out-of-time cosmics.
328  if (!IsData) kMyBaseCut = kMyBaseCut && kInBeamSpill;
329 
330  // -----------------------------------------------------------
331  // --- How many trees do I want to make?
332  // -----------------------------------------------------------
333  TTree *MyTrimTree = new TTree("TrimTree" ,"TrimTree");
334 
335  // -----------------------------------------------------------
336  // --- Push back my trees and cuts --> Need 1 to 1 correspond
337  // -----------------------------------------------------------
338  std::vector<TTree*> MyTrees;
339  std::vector<Cut*> MyCuts;
340  MyTrees.push_back( MyTrimTree ); MyCuts.push_back( &kMyBaseCut );
341 
342  // -----------------------------------------------------------
343  // --- Define variables to include
344  // -----------------------------------------------------------
345  std::vector<Var*> MyVars;
346  std::vector<std::string> MyVarNames;
347  // --- Boring global variables.
348  MyVars.push_back( (Var*)(&kRun ) ); MyVarNames.push_back( "Run" ); // Run number
349  MyVars.push_back( (Var*)(&kEvt ) ); MyVarNames.push_back( "Evt" ); // Event number
350  MyVars.push_back( (Var*)(&kPPFXWgt ) ); MyVarNames.push_back( "PPFXWgt" ); // PPFX Event Weight
351  MyVars.push_back( (Var*)(&kXSecWgt ) ); MyVarNames.push_back( "XSecWgt" ); // XSec Weight.
352  // --- Some truth information...
353  MyVars.push_back( (Var*)(&kTrueE ) ); MyVarNames.push_back( "TrueNuE" ); // True Neutrino energy
354  MyVars.push_back( (Var*)(&kIsNuMuCC ) ); MyVarNames.push_back( "IsNuMuCC" ); // Is it a NuMu CC interaction?
355  MyVars.push_back( (Var*)(&kMode ) ); MyVarNames.push_back( "IntMode" ); // What is the interaction mode?
356 
357  // --- Some oscillation information...
358  MyVars.push_back( (Var*)(&kWOscDumb ) ); MyVarNames.push_back( "DumbOsc" ); // Dumb Oscillations.
359  MyVars.push_back( (Var*)(&kOsc2019 ) ); MyVarNames.push_back( "BestFit2019" ); // 2019 Best Fit Point
360 
361  // --- Some event level information.
362  MyVars.push_back( (Var*)(&kNumuE2018 ) ); MyVarNames.push_back( "RecoNuE2018" ); // What is the reco energy?
363  MyVars.push_back( (Var*)(&kNumuE2020 ) ); MyVarNames.push_back( "RecoNuE" ); // What is the reco energy?
364  MyVars.push_back( (Var*)(&kNumuMuE2020 ) ); MyVarNames.push_back( "RecoMuE" ); // What is the muon energy?
365  MyVars.push_back( (Var*)(&kNumuHadE2020 ) ); MyVarNames.push_back( "RecoHadE" ); // What is the hadronic energy?
366  MyVars.push_back( (Var*)(&kWhichQuant_LP ) ); MyVarNames.push_back( "LooPTPQuant" ); // Which quantile? Loose PTP
367 
368  // --- Want some event id scores.
369  MyVars.push_back( (Var*)(&kCosVeto ) ); MyVarNames.push_back( "CosVeto" ); // CosVeto
370  // CVN
371  MyVars.push_back( (Var*)(&kCVNm_looseptp ) ); MyVarNames.push_back( "CVNMuonLooPTP" ); // Muon Loose PTP
372  MyVars.push_back( (Var*)(&kCVNcos_looseptp ) ); MyVarNames.push_back( "CVNCosmLooPTP" ); // Cosmic Loose PTP
373  // ReMId
374  MyVars.push_back( (Var*)(&kRemID ) ); MyVarNames.push_back( "ReMId" ); // ReMId
375  // Prong CVN
376  MyVars.push_back( (Var*)(&kCVNBestMuonScore) ); MyVarNames.push_back( "CVNProngMuon" ); // Prong CVN Muon Score
377  // Cosmic Rejection
378  MyVars.push_back( (Var*)(&kNumuContPID ) ); MyVarNames.push_back( "CosRej2020" ); // Cosmic Rejection 2020
379 
380 
381  // -----------------------------------------------------------
382  // --- Now that everything is set up, lets make our TTrees!
383  // -----------------------------------------------------------
384  CAFTreeMaker treeMaker( MyDef, MyCuts, MyTrees, MyVars, MyVarNames );
385  treeMaker.SetSpillCut(kStandardSpillCuts);
386  treeMaker.Go();
387 
388  std::cout << "\nFinished looking through my TreeMaker code. I had " << treeMaker.GetNPassed() << " events pass cuts.\n" << std::endl;
389 
390  // -----------------------------------------------------------
391  // --- Finally, write everything to my output file.
392  // -----------------------------------------------------------
393  outFile->cd();
394  for ( uint t = 0; t < MyTrees.size(); ++t ) {
395  MyTrees[t]->Write();
396  }
397  outFile->Close();
398 } // --- DONE! ---
caf::Proxy< caf::SRCVNResult > cvnloosepreselptp
Definition: SRProxy.h:1253
caf::Proxy< caf::SRSpill > spill
Definition: SRProxy.h:2142
const Var kMode([](const caf::SRProxy *sr){return(sr->mc.nnu==0)?-1:int(sr->mc.nu[0].mode);})
Neutrino interaction mode.
Definition: Vars.h:99
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
void ResetOscCalcToDefault(osc::IOscCalcAdjustable *calc)
Reset calculator to default assumptions for all parameters.
Definition: Calcs.cxx:23
std::string sIsFD
CAFTreeMaker(const std::string &wildcard, std::vector< Cut * > &cuts, std::vector< TTree * > &trees, std::vector< Var * > &vars, std::vector< std::string > varNames)
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
const Var kNumuContPID
Definition: NumuVars.cxx:553
bool IsFHC
std::vector< double > fLocalVars
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2125
T sqrt(T number)
Definition: d0nt_math.hpp:156
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:617
const Var kNumuE2018
Definition: NumuEFxs.h:171
void NuMu2020_TrimCAFs(bool IsFHC, bool IsFD, bool IsData=false)
void abs(TH1 *hist)
caf::Proxy< short int > nnu
Definition: SRProxy.h:616
void SetSpillCut(const SpillCut &cut)
virtual double P(int flavBefore, int flavAfter, double E) override
E in GeV; flavors as PDG codes (so, neg==>antinu)
Definition: OscCalcDumb.h:21
osc::OscCalcDumb calc
std::vector< Var * > fVars
#define M_PI
Definition: SbMath.h:34
std::vector< Cut * > fCuts
void HandleRecord(caf::SRProxy *sr) override
const Cut kInCosmicTimingWindow
Is the event far from the start and ends of the spill ? For FD cosmic selection.
Definition: TimingCuts.cxx:165
const Var kNumuE2020
Definition: NumuEFxs.h:217
caf::Proxy< bool > isFHC
Definition: SRProxy.h:1374
const Var kCosVeto
The result of CosVeto.
Definition: Vars.cxx:50
const Var kTrueE([](const caf::SRProxy *sr){assert(sr->mc.nnu==1);return sr->mc.nu[0].E;})
Definition: Vars.cxx:85
TFile * outFile
Definition: PlotXSec.C:135
const Var kEvt
Definition: Vars.cxx:23
if(dump)
const Var kRemID
PID
Definition: Vars.cxx:81
correl_yv Fill(-(dy[iP-1][iC-1]), hyv->GetBinContent(iP, iC))
const Var kHadEFrac
Definition: NumuVars.h:24
std::vector< std::string > wildcard(const std::string &wildcardString)
Definition: convert.C:9
const Cut kNumuContainFD2020
Definition: NumuCuts2020.h:42
Optimized version of OscCalcPMNS.
Definition: StanTypedefs.h:31
caf::StandardRecord * sr
virtual void Go() override
Load all the registered spectra.
const std::map< std::pair< std::string, std::string >, Variable > vars
const Var kCVNm_looseptp
Definition: Vars.cxx:40
const Var kCVNcos_looseptp
Definition: Vars.cxx:47
OStream cout
Definition: OStream.cxx:6
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2137
const Var kWOscDumb([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return 0.f;return float(sr->mc.nu[0].woscdumb);})
Definition: TruthVars.h:10
const Cut kIsNuMuCC
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const Cut kInBeamSpill([](const caf::SRProxy *sr){if(sr->spill.run > util::kLastBadTimingRun) return kInBeamSpill_main(sr);else return kInBeamSpill_main(sr)||kInBeamSpill_shifted(sr);}, [](const caf::SRSpillProxy *spill){if(spill->run > util::kLastBadTimingRun) return kInBeamSpill_main.Livetime(spill);else return kInBeamSpill_main.Livetime(spill)+kInBeamSpill_shifted.Livetime(spill);}, [](const caf::SRSpillProxy *spill) -> double{return spill->spillpot;})
Does the event fall inside the window we call the beam spill?
Definition: TimingCuts.h:8
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
caf::Proxy< bool > isRHC
Definition: SRProxy.h:1375
caf::Proxy< caf::SRIDBranch > sel
Definition: SRProxy.h:2140
const Var kRun
Definition: Vars.cxx:20
const Cut kNumuQuality
Definition: NumuCuts.h:18
const Var kCVNBestMuonScore([](const caf::SRProxy *sr){float muonScore=-5.0;if(kCVNMuonIdx(sr)< 0.0) return muonScore;if(!sr->vtx.elastic.IsValid) return muonScore;muonScore=sr->vtx.elastic.fuzzyk.png[(unsigned int) kCVNMuonIdx(sr)].cvnpart.muonid;if(sr->vtx.elastic.fuzzyk.png[(unsigned int) kCVNMuonIdx(sr)].len > 500.0) muonScore=1.0;return muonScore;})
: Muon score for best muon prong by CVN score & length
Definition: CVNProngVars.h:27
const Cut kNumuContainND2020([](const caf::SRProxy *sr){if(!sr->vtx.elastic.IsValid) return false;for(unsigned int i=0;i< sr->vtx.elastic.fuzzyk.nshwlid;++i){const caf::SRVector3DProxy &start=sr->vtx.elastic.fuzzyk.png[i].shwlid.start;const caf::SRVector3DProxy &stop=sr->vtx.elastic.fuzzyk.png[i].shwlid.stop;if(std::min(start.X(), stop.X())< -180.0) return false;if(std::max(start.X(), stop.X()) > 180.0) return false;if(std::min(start.Y(), stop.Y())< -180.0) return false;if(std::max(start.Y(), stop.Y()) > 180.0) return false;if(std::min(start.Z(), stop.Z())< 40.0) return false;if(std::max(start.Z(), stop.Z()) > 1525.0) return false;}if(sr->trk.kalman.ntracks< 1) return false;for(unsigned int i=0;i< sr->trk.kalman.ntracks;++i){if(i==sr->trk.kalman.idxremid) continue;else if(sr->trk.kalman.tracks[i].start.Z() > 1275||sr->trk.kalman.tracks[i].stop.Z() > 1275) return false;}return(sr->trk.kalman.ntracks > sr->trk.kalman.idxremid &&sr->slc.firstplane > 1 &&sr->slc.lastplane< 212 &&sr->trk.kalman.tracks[0].start.Z()< 1100 &&(sr->trk.kalman.tracks[0].stop.Z()< 1275 ||sr->sel.contain.kalyposattrans< 55) &&sr->sel.contain.kalfwdcellnd > 5 &&sr->sel.contain.kalbakcellnd > 10);})
Definition: NumuCuts2020.h:31
std::vector< TTree * > fTrees
caf::Proxy< float > numuid
Definition: SRProxy.h:906
const Var kNumuMuE2020
Definition: NumuEFxs.h:198
const Var kNumuHadE2020
Definition: NumuEFxs.h:199
T asin(T number)
Definition: d0nt_math.hpp:60
const Var kXSecCVWgt2020
Definition: XsecTunes.h:106
enum BeamMode string
unsigned int uint