demo6.C
Go to the documentation of this file.
1 // setupnova -r S13-12-27 -b maxopt
2 
3 // FD Neutrino Search Analysis macro
4 // bare-bones example
5 
6 #include "CAFAna/Core/Binning.h"
7 #include "CAFAna/Cuts/Cuts.h"
10 #include "CAFAna/Analysis/Plots.h"
11 #include "CAFAna/Core/Spectrum.h"
13 #include "CAFAna/Vars/Vars.h"
14 
16 
17 #include "TCanvas.h"
18 #include "TH2.h"
19 #include "TStyle.h"
20 #include "TLegend.h"
21 #include "TLatex.h"
22 
23 using namespace ana;
24 
25 /// Put NOvA Preliminary on plots
27 {
28  TLatex* prelim = new TLatex(.9, .95, "NO#nuA Preliminary");
29  prelim->SetTextColor(kBlue);
30  prelim->SetNDC();
31  prelim->SetTextSize(2/30.);
32  prelim->SetTextAlign(32);
33  prelim->Draw();
34 }
35 
36 /// legend to depict Data vs. GENIE MC vs. COSMIC MC
37 void legend(TH1* data, TH1* genie, TH1* cosmic){
38 
39  TLegend *leg = new TLegend(.50,.57,.84,.84);
40  leg->AddEntry(data,"Far Detector Data","lpe");
41  leg->AddEntry(genie,"GENIE Simulation","l");
42  leg->AddEntry(cosmic,"Cosmic Simulation","l");
43  leg->SetBorderSize(0); //no border for legend
44  leg->SetFillColor(0); //fill colour is white
45  leg->Draw();
46 
47 }
48 
49 
50 void demo6()
51 {
52  /// Remove statistics from plots
53  gStyle->SetOptStat(0);
54 
55  /// Data, GENIE, Cosmic MC files
56  const std::string fData = "$NOVA_PROD/data/FarDet/S13-10-11/numi/hadd/fardet_r11761*v3a*caf.root";
57  const std::string fGENIE = "$NOVA_PROD/mc/B13-10-23/genie/fd/ImprovedTrans_newMultiplexReadoutSim/fd_r01_s??_*fhc*caf.root";
58  const std::string fCOSMICS = "$NOVA_PROD/mc/B13-10-23/cosmics/fd/ImprovedTrans_newMultiplexReadoutSim/fd_r01_s??_*cosmics*caf.root";
59 
60  //-------------------------------------------------------------------------
61  /// These are just place-holder histograms for ease of use with the TLegend
62  TH1 *hdata = new TH1("hdata", "hdata", 10, 0, 1);
63  TH1 *hgenie = new TH1("hgenie", "hgenie", 10, 0, 1);
64  TH1 *hcosmic = new TH1("hcosmic", "hcosmic", 10, 0, 1);
65 
66  hdata->SetLineWidth(2);
67  hgenie->SetLineWidth(2);
68  hcosmic->SetLineWidth(2);
69 
70  hdata->SetLineColor(kBlack);
71  hgenie->SetLineColor(kRed);
72  hcosmic->SetLineColor(kBlue);
73 
74  hdata->SetMarkerStyle(kFullCircle);
75  //------------------------------------------------------------------------
76 
77 
78  //------------------------------------------------------------------------
79  // Specify variables needed and arbitrary code to extract value from
80  // SRProxy
81  const Var kBoxMinX( [](const caf::SRProxy* sr)
82  {
83  return sr->slc.boxmin.X();
84  });
85  // Don't use this one, but is another example of a Var definition
86  // with the lambda function
87  const Var kNContPlanes([](const caf::SRProxy* sr)
88  {
89  if(sr->slc.ncontplanes == 0) return (unsigned int)0.0;
90  return sr->slc.ncontplanes;
91  });
92 
93  const Var kHitRatio( [](const caf::SRProxy* sr)
94  {
95  if(sr->trk.cosmic.ntracks == 0) return 0.0;
96  return ((sr->trk.cosmic.tracks[0].nhit*1.0)/(1.0*sr->slc.nhit));
97  });
98 
99  // Cut variable on hit ratio
100  const Cut kHitRatioCut([](const caf::SRProxy* sr)
101  {
102  return ((sr->trk.cosmic.tracks[0].nhit*1.0)/(1.0*sr->slc.nhit)) > 0.88;
103  });
104 
105  const Cut kCleanup([](const caf::SRProxy* sr)
106  {
107  return (sr->slc.nhit > 20 &&
108  sr->trk.cosmic.tracks[0].view == 2);
109  });
110 
111  const Cut kNNu([](const caf::SRProxy* sr)
112  {
113  return (sr->mc.nnu > 0);
114  });
115 
116  const Cut k2DBContain( // If we pretend there's no Cosmics, this works well
117  [](const caf::SRProxy* sr)
118  {
119  return (sr->slc.boxmin.X() > -700 &&
120  sr->slc.boxmin.Y() > -700 &&
121  sr->slc.boxmax.X() < 700 &&
122  sr->slc.boxmax.Y() < 660 &&
123  sr->slc.boxmin.Z() > 100 &&
124  sr->slc.boxmax.Z() < 800);
125  });
126 
127  const Var kTrackLen([](const caf::SRProxy* sr)
128  {
129  if(sr->trk.kalman.ntracks == 0) return 0.0f;
130  return sr->trk.kalman.tracks[0].len;
131  });
132 
133  const Var kNHit([](const caf::SRProxy* sr){return sr->slc.nhit;});
134 
135 
136  //SpectrumLoader definitions
137  SpectrumLoader loadData(fData);
138  SpectrumLoader loadGENIE(fGENIE);
139  SpectrumLoader loadCOSMICS(fCOSMICS,kCosmic);
140 
141  //Any particular binning types for spectra
142  const Binning bins = Binning::Simple(100, 0, 1000);
143 
144  const Binning binsX = Binning::Simple(425, -850, 850);
145 
146  //--------------------------------------------------------------------------
147  /// Spectrum to be filled from the loader
148  /// List spectra we'd like to draw along with the cuts we'd like to apply
149  /// Here we're defining cut to be on kCleanup
150  Spectrum boxminxD("Slice Box Min X (cm)", binsX, loadData, kBoxMinX,kCleanup); // DATA
151  Spectrum boxminxG("Slice Box Min X (cm)", binsX, loadGENIE, kBoxMinX, kNNu && kCleanup); // GENIE MC
152  Spectrum boxminxC("Slice Box Min X", binsX, loadCOSMICS, kBoxMinX, kCleanup); // COSMIC MC
153 
154  // Nhits vs Track Length 2D Spectrum
155  Spectrum nhittracklen("Nhits vs Track Length", loadCOSMICS,
156  bins, kTrackLen, bins, kNHit,kCleanup && kNumuContainFD); // COSMIC MC
157 
158  // Do it!
159  loadGENIE.Go();
160  loadData.Go();
161  loadCOSMICS.Go();
162 
163  //Pick data set we'd like to print run/subrun/event information to text file
164  //Cut on genie events with a neutrino that pass kCleanup and k2DBEnter
165  MakeEventListFile(fGENIE,kNNu && kCleanup,"event-list-genie.txt");
166  //Same cuts to a file for Data - obviously can't rely on truth for a neutrino
167  MakeEventListFile(fData,kCleanup,"event-list-data.txt");
168 //Same cuts to a file for Data - obviously can't rely on truth for a neutrino
169  MakeEventListFile(fCOSMICS,kCleanup,"event-list-cosmics.txt");
170 
171  //--------------------------------------------------------------------------
172  //We have histograms
173 
174  // Nhits vs TrackLength
175 
176 
177  TH2* hnht = nhittracklen.ToTH2(nhittracklen.POT());
178  hnht->Draw("colz");
179  Preliminary();
180 
181  // Slice Box Min X
182  TCanvas *minx = new TCanvas();
183  //Make Data vs. MC area normalized
184  DataMCComparisonAreaNormalized(boxminxD,boxminxG);
185  //Add Cosmic MC for comparison
186  TH1* boxminxc = boxminxC.ToTH1(boxminxC.POT());
187  boxminxc->SetLineColor(kBlue);
188  //Scale Cosmic MC appropriately
189  boxminxc->Scale(boxminxD.ToTH1(boxminxD.POT())->Integral()/boxminxc->Integral());
190  boxminxc->Draw("hist same");
191  minx->SetLogy();
192  //Add Preliminary tag and legend
193  Preliminary();
194  legend(hdata,hgenie,hcosmic);
195 
196 }
void legend(TH1 *data, TH1 *genie, TH1 *cosmic)
legend to depict Data vs. GENIE MC vs. COSMIC MC
Definition: demo6.C:37
enum BeamMode kRed
TH2 * ToTH2(double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Spectrum must be 2D to obtain TH2.
Definition: Spectrum.cxx:165
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
caf::Proxy< std::vector< caf::SRTrack > > tracks
Definition: SRProxy.h:1731
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
Definition: Spectrum.cxx:148
caf::Proxy< size_t > ntracks
Definition: SRProxy.h:1778
double Integral(const Spectrum &s, const double pot, int cvnregion)
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
void MakeEventListFile(const std::string &wildcard, const std::vector< Cut > &cuts, const std::vector< std::string > &outputs, bool includeSliceIndex, bool includeSliceTime, bool includeCycleNumber, const SpillCut *spillCut, bool includeBatchNumber)
Make a set of files listing all the events passing cuts One output file is created for each cut in th...
Definition: EventList.cxx:255
caf::Proxy< unsigned int > ncontplanes
Definition: SRProxy.h:1314
const Var kNContPlanes
Definition: NusVars.cxx:13
const Cut kNumuContainFD([](const caf::SRProxy *sr){ std::pair< int, int > planes=calcFirstLastLivePlane(sr->slc.firstplane, std::bitset< 14 >(sr->hdr.dibmask));int planestofront=sr->slc.firstplane-planes.first;int planestoback=planes.second-sr->slc.lastplane;return( sr->slc.ncellsfromedge > 1 &&planestofront > 1 &&planestoback > 1 &&sr->sel.contain.kalfwdcell > 10 &&sr->sel.contain.kalbakcell > 10 &&sr->sel.contain.cosfwdcell > 0 &&sr->sel.contain.cosbakcell > 0);})
Definition: NumuCuts.h:20
caf::Proxy< short int > nnu
Definition: SRProxy.h:617
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
void Preliminary()
Put NOvA Preliminary on plots.
Definition: demo6.C:26
const XML_Char const XML_Char * data
Definition: expat.h:268
void demo6()
Definition: demo6.C:50
caf::Proxy< caf::SRVector3D > boxmin
Definition: SRProxy.h:1291
caf::Proxy< unsigned int > nhit
Definition: SRProxy.h:1315
Sum up livetimes from individual cosmic triggers.
TH1 * DataMCComparisonAreaNormalized(const Spectrum &data, const Spectrum &mc)
Definition: Plots.cxx:74
caf::Proxy< caf::SRTrackBranch > trk
Definition: SRProxy.h:2145
const Var kNHit
Definition: Vars.cxx:71
caf::StandardRecord * sr
virtual void Go() override
Load all the registered spectra.
TLatex * prelim
Definition: Xsec_final.C:133
double POT() const
Definition: Spectrum.h:227
kTrackLen
Definition: demo0.py:15
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2138
const Cut kCleanup([](const caf::SRProxy *sr){return(sr->slc.nhit > 20 && sr->trk.cosmic.tracks[0].view==2);})
2 di-block era cleanup before applying other cuts
Definition: Cuts.h:54
const Binning bins
Definition: NumuCC_CPiBin.h:8
caf::Proxy< caf::SRKalman > kalman
Definition: SRProxy.h:1797
caf::Proxy< caf::SRSlice > slc
Definition: SRProxy.h:2142
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
caf::Proxy< caf::SRTrackBase > cosmic
Definition: SRProxy.h:1795
caf::Proxy< std::vector< caf::SRKalmanTrack > > tracks
Definition: SRProxy.h:1780
enum BeamMode kBlue
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
caf::Proxy< size_t > ntracks
Definition: SRProxy.h:1730
caf::Proxy< caf::SRVector3D > boxmax
Definition: SRProxy.h:1290
enum BeamMode string