MRDiFStudy_FHC_Step1.C
Go to the documentation of this file.
1 //This macro gets the spectra needed to make the weights used in the reweighting process
2 //done in Step 2
3 
4 
5 #include "CAFAna/Core/Binning.h"
6 #include "CAFAna/Core/Spectrum.h"
8 #include "CAFAna/Core/Var.h"
9 #include "CAFAna/Core/MultiVar.h"
10 
11 #include "CAFAna/Cuts/Cuts.h"
13 #include "CAFAna/Cuts/TimingCuts.h"
14 #include "CAFAna/Cuts/SpillCuts.h"
16 #include "CAFAna/Cuts/TruthCuts.h"
18 
19 #include "CAFAna/Vars/Vars.h"
21 
23 
24 #include <cassert>
25 
26 #include "TFile.h"
27 #include "TCanvas.h"
28 #include "TH2.h"
29 #include "TH1.h"
30 #include "TStyle.h"
31 #include "TLegend.h"
32 #include "TLatex.h"
33 #include "TArrayD.h"
34 #include "TTree.h"
35 #include "TLeaf.h"
36 #include "stdio.h"
37 #include <sstream>
38 #include <string>
39 #include <iostream>
40 #include <fstream>
41 #include <string>
42 
43 
44 using namespace ana;
45 using namespace std;
46 
47 
49 {
50 
51  const std::string filenameCosmicsData = "prod_mrdifcaf_R19-11-18-prod5reco.i_fd_cosmic_fhc_full_v1_goodruns";
52  const std::string filenameCRYMC = "prod_mrdifcaf_R19-11-18-prod5reco.m_fd_cry_fhc_full_v3";
53  const std::string filenameGENIEFluxswap = "prod_caf_R19-11-18-prod5reco.f_fd_genie_N1810j0211a_fluxswap_fhc_nova_v08_full_v1";
54 
55  const Var kShwAngle([](const caf::SRProxy* sr)
56  {
57  double maxe = -99.0;
58  int maxi = 999.0;
59  double cosz = -1.0;
60 
61  if(!sr->vtx.elastic.IsValid) return -99999.0;
62  if(sr->vtx.elastic.fuzzyk.png.size() < 1) return -99999.0;
63 
64  for(unsigned int i=0;i<sr->vtx.elastic.fuzzyk.png.size();i++){
65  if(maxe < sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE){
66  maxe = sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE;
67  maxi = i;
68  cosz = sr->vtx.elastic.fuzzyk.png[i].shwlid.dir.z;
69  }
70  }
71  return cosz;
72  });
73 
74  const Var kShwE( [](const caf::SRProxy* sr)
75  {
76  double maxe = -99.0;
77  int maxi = 999;
78 
79  if(!sr->vtx.elastic.IsValid) return -99999.0;
80  if(sr->vtx.elastic.fuzzyk.png.size() < 1) return -99999.0;
81 
82  for(unsigned int i=0;i<sr->vtx.elastic.fuzzyk.png.size();i++){
83  if(maxe < sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE){
84  maxe = sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE;
85  maxi = i;
86  }
87  }
88  return maxe;
89 
90  });
91 
92 
93  SpectrumLoader loaderCosmicsData(filenameCosmicsData, kCosmic);
94  SpectrumLoader loaderCRYMC(filenameCRYMC, kCosmic);
95  SpectrumLoader loaderGENIEFluxswap(filenameGENIEFluxswap);
96  loaderGENIEFluxswap.SetSpillCut(kStandardSpillCuts);
97 
98 
99  const Binning ShwAnglebin= Binning::Simple(60, 0.0, 1.0);
100  // const Binning ShwEbin = Binning::Simple(120, 0, 5.0);
101 
102  //1D spectrums CorePresel Cuts
103  Spectrum sShwAngleCorePreselCosmicsData("Cos(#theta_{Z})", ShwAnglebin,loaderCosmicsData,kShwAngle,kDiFPreselectionCut&&kInCosmicTimingWindow_FD_MR);
104  Spectrum sShwAngleCorePreselCRYMC("Cos(#theta_{Z})", ShwAnglebin,loaderCRYMC,kShwAngle,kDiFPreselectionCut&&kInCosmicTimingWindow_FD_MR);
105  Spectrum sShwAngleCorePreselGENIEFluxswap("Cos(#theta_{Z})", ShwAnglebin,loaderGENIEFluxswap,kShwAngle,kDiFPreselectionCut);
106  /*
107  Spectrum sShwECorePreselCosmicsData("Cos(#theta_{Z})", ShwEbin,loaderCosmicsData,kShwE,kDiFPreselectionCut&&kInCosmicTimingWindow_FD_MR);
108  Spectrum sShwECorePreselCRYMC("Cos(#theta_{Z})", ShwEbin,loaderCRYMC,kShwE,kDiFPreselectionCut&&kInCosmicTimingWindow_FD_MR);
109  Spectrum sShwECorePreselGENIEFluxswap("Cos(#theta_{Z})", ShwEbin,loaderGENIEFluxswap,kShwE,kDiFPreselectionCut);
110  */
111 
112  //1D spectrums Core or Peripheral Cuts
113  Spectrum sShwAngleCoreCosmicsData("Cos(#theta_{Z})", ShwAnglebin,loaderCosmicsData,kShwAngle,kDiFSelectionCut&&kInCosmicTimingWindow_FD_MR);
114  Spectrum sShwAngleCoreCRYMC("Cos(#theta_{Z})", ShwAnglebin,loaderCRYMC,kShwAngle,kDiFSelectionCut&&kInCosmicTimingWindow_FD_MR);
115  Spectrum sShwAngleCoreGENIEFluxswap("Cos(#theta_{Z})", ShwAnglebin,loaderGENIEFluxswap,kShwAngle,kDiFSelectionCut);
116  /*
117  Spectrum sShwECoreCosmicsData("Cos(#theta_{Z})", ShwEbin,loaderCosmicsData,kShwE,kDiFSelectionCut&&kInCosmicTimingWindow_FD_MR);
118  Spectrum sShwECoreCRYMC("Cos(#theta_{Z})", ShwEbin,loaderCRYMC,kShwE,kDiFSelectionCut&&kInCosmicTimingWindow_FD_MR);
119  Spectrum sShwECoreGENIEFluxswap("Cos(#theta_{Z})", ShwEbin,loaderGENIEFluxswap,kShwE,kDiFSelectionCut);
120 */
121 
122 
123  loaderCosmicsData.Go();
124  loaderCRYMC.Go();
125  loaderGENIEFluxswap.Go();
126 
127  TFile *file = new TFile("MRDiF_FD_FHC_Step1_test.root", "recreate");
128 
129  sShwAngleCorePreselCosmicsData.SaveTo(file, "sShwAngleCorePreselCosmicsData");
130  sShwAngleCorePreselCRYMC.SaveTo(file, "sShwAngleCorePreselCRYMC");
131  sShwAngleCorePreselGENIEFluxswap.SaveTo(file, "sShwAngleCorePreselGENIEFluxswap");
132  /*
133  sShwECorePreselCosmicsData.SaveTo(file, "sShwECorePreselCosmicsData");
134  sShwECorePreselCRYMC.SaveTo(file, "sShwECorePreselCRYMC");
135  sShwECorePreselGENIEFluxswap.SaveTo(file, "sShwECorePreselGENIEFluxswap");
136  */
137 
138  //1D spectrums Core Cuts
139  sShwAngleCoreCosmicsData.SaveTo(file, "sShwAngleCoreCosmicsData");
140  sShwAngleCoreCRYMC.SaveTo(file, "sShwAngleCoreCRYMC");
141  sShwAngleCoreGENIEFluxswap.SaveTo(file, "sShwAngleCoreGENIEFluxswap");
142 
143  /*
144  sShwECoreCosmicsData.SaveTo(file, "sShwECoreCosmicsData");
145  sShwECoreCRYMC.SaveTo(file, "sShwECoreCRYMC");
146  sShwECoreGENIEFluxswap.SaveTo(file, "sShwECoreGENIEFluxswap");
147  */
148  file->Close();
149  return;
150 
151 }
const Var kShwE([](const caf::SRProxy *sr){double maxe=-99.0;if(!sr->vtx.elastic.IsValid) return-99999.0;if(sr->vtx.elastic.fuzzyk.npng< 1) return-99999.0;for(unsigned int i=0;i< sr->vtx.elastic.fuzzyk.npng;i++){if(maxe< sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE){maxe=sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE;}}return maxe;})
Definition: MRVars.h:9
caf::Proxy< caf::SRFuzzyK > fuzzyk
Definition: SRProxy.h:2059
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
void MRDiFStudy_FHC_Step1()
void SetSpillCut(const SpillCut &cut)
const Cut kDiFPreselectionCut
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
caf::Proxy< caf::SRElastic > elastic
Definition: SRProxy.h:2118
Double_t maxi
Definition: plot.C:28
caf::Proxy< std::vector< caf::SRFuzzyKProng > > png
Definition: SRProxy.h:2043
const Cut kDiFSelectionCut
caf::StandardRecord * sr
virtual void Go() override
Load all the registered spectra.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
caf::Proxy< bool > IsValid
Definition: SRProxy.h:2058
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
TFile * file
Definition: cellShifts.C:17
const Cut kInCosmicTimingWindow_FD_MR
Definition: TimingCuts.cxx:170
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
const Var kShwAngle([](const caf::SRProxy *sr){double maxe=-99.0;double cosz=-1.0;if(!sr->vtx.elastic.IsValid) return-99999.0;if(sr->vtx.elastic.fuzzyk.npng< 1) return-99999.0;for(unsigned int i=0;i< sr->vtx.elastic.fuzzyk.npng;i++){if(maxe< sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE){maxe=sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE;cosz=sr->vtx.elastic.fuzzyk.png[i].shwlid.dir.z;}}return cosz;})
Definition: MRVars.h:8
caf::Proxy< caf::SRVertexBranch > vtx
Definition: SRProxy.h:2146
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
enum BeamMode string