HighLAND
antiNumuCCAnalysis.cxx
1 #include "antiNumuCCAnalysis.hxx"
2 #include "FiducialVolumeDefinition.hxx"
3 #include "Parameters.hxx"
4 #include "UseGlobalAltMomCorrection.hxx"
5 #include "antiNumuCCSelection.hxx"
6 #include "antiNumuCCMultiTrackSelection.hxx"
7 #include "antiNumuCCFGD2Selection.hxx"
8 #include "antiNumuCCMultiTrackFGD2Selection.hxx"
9 #include "CategoriesUtils.hxx"
10 #include "BasicUtils.hxx"
11 
12 //********************************************************************
13 antiNumuCCAnalysis::antiNumuCCAnalysis(AnalysisAlgorithm* ana) : baseTrackerAnalysis(ana) {
14 //********************************************************************
15 
16  // Add the package version
17  ND::versioning().AddPackage("antiNumuCCAnalysis", anaUtils::GetSoftwareVersionFromPath((std::string)getenv("ANTINUMUCCANALYSISROOT")));
18 
19  // Create a numuCCAnalysis passing this analysis to the constructor. In that way the same managers are used
20  _numuCCAnalysis = new numuCCAnalysis(this);
21 
22  // Use the numuCCAnalysis (in practice that means that the same box and event will be used for the numuCCAnalysis as for this analysis)
23  UseAnalysis(_numuCCAnalysis);
24 }
25 
26 //********************************************************************
28 //********************************************************************
29 
30  // Initialize the baseAnalysis instead of numuCCAnalysis
31  // since we do not want to call and overload numu categories
32  if(!baseTrackerAnalysis::Initialize()) return false;
33 
34  // Minimum accum level to save event into the output tree
35  SetMinAccumCutLevelToSave(ND::params().GetParameterI("antiNumuCCAnalysis.MinAccumLevelToSave"));
36 
37  // which analysis: FGD1, FGD2 or FGDs
38  _whichFGD = ND::params().GetParameterI("antiNumuCCAnalysis.Selections.whichFGD");
39  if (_whichFGD == 3) {
40  std::cout << "----------------------------------------------------" << std::endl;
41  std::cout << "WARNING: only for events with accum_level > 6 the vars in the output microtree will surely refer to the muon candidate in that FGD" << std::endl;
42  std::cout << "----------------------------------------------------" << std::endl;
43  }
44 
45  // CC-inclusive or CC-MultiPi
46  fCCInclusive = ND::params().GetParameterI("antiNumuCCAnalysis.Selections.CCInc");
47 
48  // Define antinu categories (different legend from numuCC)
49  // for FGD2 same categories with prefix "fgd2", i,e, "fgd2reaction" etc.)
52 
53  return true;
54 }
55 
56 //********************************************************************
57 void antiNumuCCAnalysis::DefineSelections(){
58 //********************************************************************
59 
60  // FGD1 antineutrino analysis:
61  if(_whichFGD==1 || _whichFGD==3){
62  // ---- Inclusive CC ----
63  if(fCCInclusive)
64  sel().AddSelection("kTrackerAntiNumuCC", "inclusive antiNumuCC FGD1 selection", new antiNumuCCSelection(false));
65  // ---- CC Multi Pion Samples ----
66  else
67  sel().AddSelection("kTrackerAntiNumuCCMultiTrack", "antiNumu FGD1 CC Multiple Track selection", new antiNumuCCMultiTrackSelection(false));
68  }
69  // FGD2 antineutrino analysis:
70  if (_whichFGD==2 || _whichFGD==3){
71  // ---- CC Inclusive ----
72  if(fCCInclusive)
73  sel().AddSelection("kTrackerAntiNumuCCFGD2", "Inclusive antiNumu FGD2 CC selection", new antiNumuCCFGD2Selection(false));
74  // ---- CC Multi Track Samples ----
75  else
76  sel().AddSelection("kTrackerAntiNumuMultiTrackFGD2", "antiNumu FGD2 CC Multiple Track selection", new antiNumuCCMultiTrackFGD2Selection(false));
77  }
78 }
79 
80 //********************************************************************
81 void antiNumuCCAnalysis::DefineMicroTrees(bool addBase){
82 //********************************************************************
83 
84  // -------- Add variables to the analysis tree ----------------------
85 
86  // Variables from numuCCAnalysis
87  if (addBase) _numuCCAnalysis->DefineMicroTrees(addBase);
88 
89  if (ND::params().GetParameterI("numuCCAnalysis.MicroTrees.AdditionalToyVars")){
90  AddToyVarF(output(), shmp_mom, "second highest momentum positive track reconstructed momentum");
91  }
92  else{
93  AddVarF(output(), shmp_mom, "second highest momentum positive track reconstructed momentum");
94  }
95 
96 }
97 
98 //********************************************************************
99 void antiNumuCCAnalysis::DefineTruthTree(){
100 //********************************************************************
101 
102  // Variables from numuCCAnalysis
103  _numuCCAnalysis->DefineTruthTree();
104 
105 }
106 
107 //********************************************************************
108 void antiNumuCCAnalysis::FillMicroTrees(bool addBase){
109 //********************************************************************
110 
111  // Variables from numuCCAnalysis
112  if (addBase) _numuCCAnalysis->FillMicroTrees(addBase);
113 
114  if (!ND::params().GetParameterI("numuCCAnalysis.MicroTrees.AdditionalToyVars")){
115  if (box().SHMPtrack)
116  output().FillVar(shmp_mom, box().SHMPtrack->Momentum);
117  }
118 
119 }
120 
121 //********************************************************************
122 void antiNumuCCAnalysis::FillToyVarsInMicroTrees(bool addBase){
123 //********************************************************************
124 
125  // Fill all tree variables that vary for each virtual analysis (toy experiment)
126 
127  // Variables from numuCCAnalysis
128  if (addBase) _numuCCAnalysis->FillToyVarsInMicroTrees(addBase);
129 
130  if (ND::params().GetParameterI("numuCCAnalysis.MicroTrees.AdditionalToyVars")){
131  if (box().SHMPtrack){
132  output().FillToyVar(shmp_mom, box().SHMPtrack->Momentum);
133  }
134  }
135 }
136 
137 //********************************************************************
138 bool antiNumuCCAnalysis::CheckFillTruthTree(const AnaTrueVertex& vtx){
139 //********************************************************************
140 
141  // we cannot call the numuCC method here because 1) the setting of _whichFGD would be lost
142  // and 2) the called methods need the IsAntinu paramenter set to true
143 
144  SubDetId::SubDetEnum fgdID;
145  if (_whichFGD == 1) fgdID = SubDetId::kFGD1;
146  if (_whichFGD == 2) fgdID = SubDetId::kFGD2;
147  if (_whichFGD == 3) fgdID = SubDetId::kFGD;
148 
149  bool IsAntinu = true;
150 
151  // GetReactionCC already takes into account the outFV and also
152  // the NuWro reaction code for 2p2h in prod5 (that is 70)
153  bool antiNumuCCinFV = (anaUtils::GetReactionCC(vtx, fgdID, IsAntinu) == 1);
154 
155  // Since our topology definition doesn't consider the reaction code
156  // and since a muon pair can be created in the FSI (likely in DIS)
157  // in principle we might have a non-CC vertex categorized as CCother
158  // (nevertheless I didn't find any)
159  int topo = anaUtils::GetTopology(vtx, fgdID, IsAntinu);
160  bool topoCCinFV = (topo == 0 || topo == 1 || topo == 2);
161 
162  return (antiNumuCCinFV || topoCCinFV);
163 }
164 
165 //********************************************************************
166 void antiNumuCCAnalysis::FillTruthTree(const AnaTrueVertex& vtx){
167 //********************************************************************
168 
169  // Variables from numuCCAnalysis, with antinu categories
170  bool IsAntinu = true;
171  _numuCCAnalysis->FillTruthTreeBase(vtx,IsAntinu);
172 
173 }
174 
175 //********************************************************************
176 void antiNumuCCAnalysis::FillCategories(){
177 //********************************************************************
178 
179  // Fill the track categories for color drawing
180 
181  bool IsAntinu = true;
182 
183  // For the muon candidate
184  anaUtils::FillCategories(&GetEvent(), static_cast<AnaTrack*>(box().MainTrack),"",SubDetId::kFGD1,IsAntinu);
185 
186  // For FGD2, same categories with prefix "fgd2", i,e, "fgd2reaction" etc.
187  // We could directly set which FGD in the usual categories, but this cannot be done for the true vertices
188  anaUtils::FillCategories(&GetEvent(), static_cast<AnaTrack*>(box().MainTrack), "fgd2", SubDetId::kFGD2,IsAntinu);
189 
190 }
191 
void SetMinAccumCutLevelToSave(Int_t level)
Set the minimum accumulated cut level to save an event into the micro-tree.
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
Definition: Parameters.cxx:217
void AddPackage(const std::string &name, const std::string &version)
Add a package.
Int_t GetTopology(const AnaTrueVertex &trueVertex, const SubDetId::SubDetEnum det=SubDetId::kFGD1, bool IsAntinu=false)
Classify reaction topologies.
std::string GetSoftwareVersionFromPath(const std::string &path)
Get The software version from the path of the package.
bool Initialize()
[AnalysisAlgorithm_mandatory]
Representation of a true Monte Carlo vertex.
Definition: DataClasses.hxx:50
virtual const ToyBoxTracker & box(Int_t isel=-1) const
Returns the ToyBoxTracker.
void AddStandardAntiNumuCategories(const std::string &prefix="")
Add the standard categories only, given a prefix for their name.
SubDetEnum
Enumeration of all detector systems and subdetectors.
Definition: SubDetId.hxx:25
void FillCategories(AnaEventB *event, AnaTrack *track, const std::string &prefix, const SubDetId::SubDetEnum det=SubDetId::kFGD1, bool IsAntinu=false, bool useCATSAND=true)
Fill the track categories for color drawing.
AnaEvent & GetEvent()
Get a casted AnaEventC to AnaEvent.
void FillToyVar(Int_t index, Int_t var)
Fill a single analysis variable.
virtual bool Initialize()
[AnalysisAlgorithm_mandatory]
void FillVar(Int_t index, Float_t var)
Fill a single variable.
void AddSelection(const std::string &name, const std::string &title, SelectionBase *sel, Int_t presel=-1)
Add a user selection to the selection manager.