MRDiFStudy_RHC_Step1.C
Go to the documentation of this file.
1 
2 //macro to get spectra used to get weights for the reweighting
3 //process in Step 2
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"
17 
19 //#include "MRDiFCutsAndVars.h"
20 
21 #include "CAFAna/Vars/Vars.h"
23 
25 
26 #include <cassert>
27 
28 #include "TFile.h"
29 #include "TCanvas.h"
30 #include "TH2.h"
31 #include "TH1.h"
32 #include "TStyle.h"
33 #include "TLegend.h"
34 #include "TLatex.h"
35 #include "TArrayD.h"
36 #include "TTree.h"
37 #include "TLeaf.h"
38 #include "stdio.h"
39 #include <sstream>
40 #include <string>
41 #include <iostream>
42 #include <fstream>
43 #include <string>
44 
45 
46 using namespace ana;
47 using namespace std;
48 
49 
51 {
52 
53  const std::string filenameCosmicsData = "prod_mrdifcaf_R19-11-18-prod5reco.i_fd_cosmic_rhc_full_v1_goodruns";
54  const std::string filenameCRYMC = "prod_mrdifcaf_R19-11-18-prod5reco.m_fd_cry_rhc_full_v3";
55  const std::string filenameGENIEFluxswap = "prod_caf_R19-11-18-prod5reco.f_fd_genie_N1810j0211a_fluxswap_rhc_nova_v08_full_v1";
56 
57  const Var kShwAngle([](const caf::SRProxy* sr)
58  {
59  double maxe = -99.0;
60  int maxi = 999.0;
61  double cosz = -1.0;
62 
63  if(!sr->vtx.elastic.IsValid) return -99999.0;
64  if(sr->vtx.elastic.fuzzyk.png.size() < 1) return -99999.0;
65 
66  for(unsigned int i=0;i<sr->vtx.elastic.fuzzyk.png.size();i++){
67  if(maxe < sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE){
68  maxe = sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE;
69  maxi = i;
70  cosz = sr->vtx.elastic.fuzzyk.png[i].shwlid.dir.z;
71  }
72  }
73  return cosz;
74  });
75 
76  const Var kShwE( [](const caf::SRProxy* sr)
77  {
78  double maxe = -99.0;
79  int maxi = 999;
80 
81  if(!sr->vtx.elastic.IsValid) return -99999.0;
82  if(sr->vtx.elastic.fuzzyk.png.size() < 1) return -99999.0;
83 
84  for(unsigned int i=0;i<sr->vtx.elastic.fuzzyk.png.size();i++){
85  if(maxe < sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE){
86  maxe = sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE;
87  maxi = i;
88  }
89  }
90  return maxe;
91 
92  });
93 
94 
95  SpectrumLoader loaderCosmicsData(filenameCosmicsData, kCosmic);
96  SpectrumLoader loaderCRYMC(filenameCRYMC, kCosmic);
97  SpectrumLoader loaderGENIEFluxswap(filenameGENIEFluxswap);
98  loaderGENIEFluxswap.SetSpillCut(kStandardSpillCuts);
99 
100 
101  const Binning ShwAnglebin= Binning::Simple(60, 0.0, 1.0);
102  const Binning ShwEbin = Binning::Simple(120, 0, 5.0);
103 
104  //1D spectrums CorePresel Cuts
105  Spectrum sShwAngleCorePreselCosmicsData("Cos(#theta_{Z})", ShwAnglebin,loaderCosmicsData,kShwAngle,kDiFPreselectionCut&&kInCosmicTimingWindow_FD_MR);
106  Spectrum sShwAngleCorePreselCRYMC("Cos(#theta_{Z})", ShwAnglebin,loaderCRYMC,kShwAngle,kDiFPreselectionCut&&kInCosmicTimingWindow_FD_MR);
107  Spectrum sShwAngleCorePreselGENIEFluxswap("Cos(#theta_{Z})", ShwAnglebin,loaderGENIEFluxswap,kShwAngle,kDiFPreselectionCut);
108  /*
109  Spectrum sShwECorePreselCosmicsData("Cos(#theta_{Z})", ShwEbin,loaderCosmicsData,kShwE,kDiFPreselectionCut&&kInCosmicTimingWindow_FD_MR);
110  Spectrum sShwECorePreselCRYMC("Cos(#theta_{Z})", ShwEbin,loaderCRYMC,kShwE,kDiFPreselectionCut&&kInCosmicTimingWindow_FD_MR);
111  Spectrum sShwECorePreselGENIEFluxswap("Cos(#theta_{Z})", ShwEbin,loaderGENIEFluxswap,kShwE,kDiFPreselectionCut);
112  */
113 
114  //1D spectrums Core or Peripheral Cuts
115  Spectrum sShwAngleCoreCosmicsData("Cos(#theta_{Z})", ShwAnglebin,loaderCosmicsData,kShwAngle,kDiFSelectionCut&&kInCosmicTimingWindow_FD_MR);
116  Spectrum sShwAngleCoreCRYMC("Cos(#theta_{Z})", ShwAnglebin,loaderCRYMC,kShwAngle,kDiFSelectionCut&&kInCosmicTimingWindow_FD_MR);
117  Spectrum sShwAngleCoreGENIEFluxswap("Cos(#theta_{Z})", ShwAnglebin,loaderGENIEFluxswap,kShwAngle,kDiFSelectionCut);
118  /*
119  Spectrum sShwECoreCosmicsData("Cos(#theta_{Z})", ShwEbin,loaderCosmicsData,kShwE,kDiFSelectionCut&&kInCosmicTimingWindow_FD_MR);
120  Spectrum sShwECoreCRYMC("Cos(#theta_{Z})", ShwEbin,loaderCRYMC,kShwE,kDiFSelectionCut&&kInCosmicTimingWindow_FD_MR);
121  Spectrum sShwECoreGENIEFluxswap("Cos(#theta_{Z})", ShwEbin,loaderGENIEFluxswap,kShwE,kDiFSelectionCut);
122  */
123 
124 
125  loaderCosmicsData.Go();
126  loaderCRYMC.Go();
127  loaderGENIEFluxswap.Go();
128 
129  TFile *file = new TFile("MRDiF_FD_RHC_Step1.root", "recreate");
130 
131  sShwAngleCorePreselCosmicsData.SaveTo(file, "sShwAngleCorePreselCosmicsData");
132  sShwAngleCorePreselCRYMC.SaveTo(file, "sShwAngleCorePreselCRYMC");
133  sShwAngleCorePreselGENIEFluxswap.SaveTo(file, "sShwAngleCorePreselGENIEFluxswap");
134  /*
135  sShwECorePreselCosmicsData.SaveTo(file, "sShwECorePreselCosmicsData");
136  sShwECorePreselCRYMC.SaveTo(file, "sShwECorePreselCRYMC");
137  sShwECorePreselGENIEFluxswap.SaveTo(file, "sShwECorePreselGENIEFluxswap");
138  */
139  //1D spectrums Core Cuts
140  sShwAngleCoreCosmicsData.SaveTo(file, "sShwAngleCoreCosmicsData");
141  sShwAngleCoreCRYMC.SaveTo(file, "sShwAngleCoreCRYMC");
142  sShwAngleCoreGENIEFluxswap.SaveTo(file, "sShwAngleCoreGENIEFluxswap");
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 SetSpillCut(const SpillCut &cut)
void MRDiFStudy_RHC_Step1()
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