1 #include "baseAnalysis.hxx" 3 #include "IgnoreRightECalRuns3and4Correction.hxx" 4 #include "CT4POTCorrection.hxx" 5 #include "DataQualityCorrection.hxx" 7 #include "SIPionSystematics.hxx" 8 #include "SIProtonSystematics.hxx" 9 #include "FluxWeightSystematics.hxx" 11 #include "FlatTreeConverter.hxx" 12 #include "HighlandMiniTreeConverter.hxx" 13 #include "oaAnalysisTreeConverter.hxx" 15 #include "baseToyMaker.hxx" 17 #include "ConfigTreeTools.hxx" 42 versionUtils::prod6_POT =
false;
43 #if VERSION_HAS_OFFICIAL_POT 44 versionUtils::prod6_POT =
true;
49 void baseAnalysis::DefineProductions(){
53 ND::versioning().
AddProduction(ProdId::PROD5E,
"PROD5E",
"v10r11p17",
"v10r11p18");
54 ND::versioning().
AddProduction(ProdId::PROD5F,
"PROD5F",
"v10r11p19",
"v10r11p24");
55 ND::versioning().
AddProduction(ProdId::PROD5G,
"PROD5G",
"v10r11p27",
"v10r11p28");
56 ND::versioning().
AddProduction(ProdId::PROD6PRE,
"PROD6PRE",
"v11r17",
"v11r28");
57 ND::versioning().
AddProduction(ProdId::PROD6A,
"PROD6A",
"v11r29",
"v11r30");
58 ND::versioning().
AddProduction(ProdId::PROD6BC,
"PROD6B/6C",
"v11r31",
"v11r32");
60 ND::versioning().
AddProduction(ProdId::PROD7DEVEL,
"PROD7DEVEL",
"v12",
"v13");
65 void baseAnalysis::DefineInputConverters(){
69 bool readRooTrackerVtxTree = (bool)ND::params().
GetParameterI(
"baseAnalysis.ReadRooTrackerVtxTree");
111 versionUtils::prod6_bunching =
false;
112 versionUtils::prod6_corrections =
false;
113 versionUtils::prod6_systematics =
false;
116 if (ND::versioning().GetProduction(input().GetSoftwareVersion()) >= ProdId::PROD6PRE){
117 versionUtils::prod6_bunching =
true;
118 versionUtils::prod6_corrections =
true;
119 versionUtils::prod6_systematics =
true;
124 if (ND::params().GetParameterI(
"baseAnalysis.Bunching.Production")==6){
125 versionUtils::prod6_bunching =
true;
126 std::cout <<
"WARNING: production has been overwritten by parameter baseAnalysis.Bunching.Production == 6" << std::endl;
128 else if (ND::params().GetParameterI(
"baseAnalysis.Bunching.Production")==5){
129 versionUtils::prod6_bunching =
false;
130 std::cout <<
"WARNING: production has been overwritten by parameter baseAnalysis.Bunching.Production == 5" << std::endl;
134 if (ND::params().GetParameterI(
"baseAnalysis.Corrections.Production")==6){
135 versionUtils::prod6_corrections =
true;
136 std::cout <<
"WARNING: production has been overwritten by parameter baseAnalysis.Corrections.Production == 6" << std::endl;
138 else if (ND::params().GetParameterI(
"baseAnalysis.Corrections.Production")==5){
139 versionUtils::prod6_corrections =
false;
140 std::cout <<
"WARNING: production has been overwritten by parameter baseAnalysis.Corrections.Production == 5" << std::endl;
144 if (ND::params().GetParameterI(
"baseAnalysis.Systematics.Production")==6){
145 versionUtils::prod6_systematics =
true;
146 std::cout <<
"WARNING: production has been overwritten by parameter baseAnalysis.Systematics.Production == 6" << std::endl;
148 else if (ND::params().GetParameterI(
"baseAnalysis.Systematics.Production")==5){
149 versionUtils::prod6_systematics =
false;
150 std::cout <<
"WARNING: production has been overwritten by parameter baseAnalysis.Systematics.Production == 5" << std::endl;
154 versionUtils::DumpProductions();
166 void baseAnalysis::DefineSystematics(){
179 void baseAnalysis::DefineCorrections(){
183 if (ND::params().GetParameterI(
"baseAnalysis.Corrections.DisableAllCorrections")){
196 #if !VERSION_HAS_OFFICIAL_POT 214 if ((
bool)ND::params().GetParameterI(
"baseAnalysis.FluxWeighting.Enable")){
215 _flux =
new FluxWeighting(ND::params().GetParameterS(
"baseAnalysis.FluxWeighting.Folder"),
216 ND::params().GetParameterS(
"baseAnalysis.FluxWeighting.Version"),
217 ND::params().GetParameterS(
"baseAnalysis.FluxWeighting.Tuning"));
221 corr().
SetForceApplyCorrections((
bool)ND::params().GetParameterI(
"baseAnalysis.Corrections.ForceApplyCorrections"));
225 void baseAnalysis::DefineConfigurations(){
230 _enableSingleVariationSystConf = (bool)ND::params().
GetParameterI(
"baseAnalysis.Configurations.EnableSingleVariationSystConfigurations");
231 _enableSingleWeightSystConf = (bool)ND::params().
GetParameterI(
"baseAnalysis.Configurations.EnableSingleWeightSystConfigurations");
232 _enableAllSystConfig = (bool)ND::params().
GetParameterI(
"baseAnalysis.Configurations.EnableAllSystematics");
235 _ntoys = (Int_t)ND::params().
GetParameterI(
"baseAnalysis.Systematics.NumberOfToys");
236 _randomSeed = (Int_t)ND::params().
GetParameterI(
"baseAnalysis.Systematics.RandomSeed");
238 if (_enableSingleWeightSystConf){
239 if (ND::params().GetParameterI(
"baseAnalysis.Weights.EnableSIPion")){
240 AddConfiguration(conf(), sipion_syst, _ntoys, _randomSeed,
new baseToyMaker(_randomSeed));
243 if (ND::params().GetParameterI(
"baseAnalysis.Weights.EnableSIProton")){
244 AddConfiguration(conf(), siproton_syst, _ntoys, _randomSeed,
new baseToyMaker(_randomSeed));
247 if (ND::params().GetParameterI(
"baseAnalysis.Weights.EnableFluxNeutrino")) {
248 AddConfiguration(conf(), nuflux_syst, _ntoys, _randomSeed,
new baseToyMaker(_randomSeed));
251 if (ND::params().GetParameterI(
"baseAnalysis.Weights.EnableFluxAntiNeutrino")) {
252 AddConfiguration(conf(), antinuflux_syst, _ntoys, _randomSeed,
new baseToyMaker(_randomSeed));
258 if (_enableAllSystConfig){
259 AddConfiguration(conf(), all_syst, _ntoys, _randomSeed,
new baseToyMaker(_randomSeed));
266 for (std::vector<ConfigurationBase* >::iterator it= conf().GetConfigurations().begin();it!=conf().
GetConfigurations().end();it++){
267 Int_t index = (*it)->GetIndex();
268 if (index != ConfigurationManager::default_conf && (index != all_syst || !_enableAllSystConfig))
continue;
269 if (ND::params().GetParameterI(
"baseAnalysis.Weights.EnableSIPion")) conf().
EnableEventWeight(SystId::kSIPion , index);
270 if (ND::params().GetParameterI(
"baseAnalysis.Weights.EnableSIProton")) conf().
EnableEventWeight(SystId::kSIProton , index);
271 if (ND::params().GetParameterI(
"baseAnalysis.Weights.EnableFluxNeutrino")) conf().
EnableEventWeight(SystId::kFluxWeightNu , index);
272 if (ND::params().GetParameterI(
"baseAnalysis.Weights.EnableFluxAntiNeutrino")) conf().
EnableEventWeight(SystId::kFluxWeightAntiNu , index);
278 void baseAnalysis::AddZeroVarConfiguration(){
282 if (GetConfigurationIndex(zero_var) < 0)
283 AddConfiguration(conf(), zero_var, 1, 1,
new baseToyMaker(1,
true));
287 if (GetConfigurationIndex(all_syst) > -1){
293 std::cout <<
" \n---- WARNING ----- " << std::endl;
294 std::cout <<
" baseAnalysis::AddZeroVariationConfig: requested zero-variation config but " <<
295 "all_syst is not available --> needed to get the enabled systematics " << std::endl;
296 std::cout <<
" ------------------\n " << std::endl;
302 void baseAnalysis::DefineMicroTrees(
bool addBase){
310 AddVarI(output(), run,
"run number");
311 AddVarI(output(), subrun,
"subrun number ");
312 AddVarI(output(), evt,
"event number ");
313 AddVarI(output(), evt_time,
"event time MCM");
314 AddVarI(output(), bunch,
"bunch number ");
317 AddVarVF(output(), weight,
"global weights (flux, pileup, ...)", NWEIGHTS);
320 AddToyVarI(output(), TruthVertexID,
"The unique ID of the true vertex associated to the selected event");
321 AddToyVarI(output(), RooVtxIndex,
"The index of the associated RooTrackerVtx vertex from its position in the TClonesArray");
322 AddToyVarI(output(), RooVtxEntry,
"The entry of the event in the saved RooTrackerVtx tree");
323 AddVarI(output(), RooVtxEntry2,
"The entry of the event in the saved RooTrackerVtx tree");
324 AddVarI(output(), RooVtxFile,
"The File of the event in the saved RooTrackerVtx tree");
327 AddVarI( output(), nu_pdg,
"neutrino PDG code");
328 AddVarF( output(), nu_trueE,
"true neutrino energy");
329 AddVarI( output(), nu_truereac,
"true netrino reaction code");
330 AddVar3VF(output(), nu_truedir,
"true neutrino direction");
333 AddVarI( output(), selvtx_det,
"detector in which the reconstructed vertex is");
334 AddVar4VF(output(), selvtx_pos,
"reconstructed vertex position");
335 AddVar4VF(output(), selvtx_truepos,
"position of the true vertex associated to the reconstructed vertex");
338 AddToyVarI(output(), true_signal,
"true signal appraisal (filled differently in each analysis package)");
341 if (conf().GetConfiguration(all_syst))
342 output().
AddToyVar(conf().GetConfiguration(all_syst)->GetTreeIndex(), weight_syst_total_noflux,
"weight_syst_total_noflux",
"F",
"Total weight (corr+syst) with no flux systematic");
347 void baseAnalysis::DefineTruthTree(){
352 if (input().GetChain(
"NRooTrackerVtx"))
353 output().
AddTreeWithName(OutputManager::RooTrackerVtx,
"RooTrackerVtx", input().GetChain(
"NRooTrackerVtx"));
354 else if (input().GetChain(
"GRooTrackerVtx"))
355 output().
AddTreeWithName(OutputManager::RooTrackerVtx,
"RooTrackerVtx", input().GetChain(
"GRooTrackerVtx"));
359 AddVarI(output(), evt,
"event number");
360 AddVarI(output(), run,
"run number");
361 AddVarI(output(), subrun,
"subrun number");
364 AddVarI(output(), TruthVertexID,
"The unique ID of the true vertex associated to the selected event");
366 AddVarI(output(), RooVtxIndex,
"The index of the associated RooTrackerVtx vertex from its position in the TClonesArray");
367 AddVarI(output(), RooVtxEntry,
"The entry of the event in the saved RooTrackerVtx tree");
368 AddVarI(output(), RooVtxEntry2,
"The entry of the event in the saved RooTrackerVtx tree");
369 AddVarI(output(), RooVtxFile,
"The File of the event in the saved RooTrackerVtx tree");
372 AddVarI(output(), nu_pdg,
"neutrino pdg code");
373 AddVarF(output(), nu_trueE,
"true neutrino energy");
374 AddVarI(output(), nu_truereac,
"true neutrino reaction type");
375 AddVar3VF(output(), nu_truedir,
"true neutrino direction");
376 AddVar4VF(output(), truevtx_pos,
"true neutrino interaction position");
383 AddVarF( output(), truelepton_mom,
"true lepton momentum");
384 AddVarF( output(), truelepton_costheta,
"true lepton cos(theta) w.r.t. neutrino direction");
385 AddVar3VF(output(), truelepton_dir,
"true lepton direction");
389 AddVarVF(output(), weight,
"global weights (flux, pileup, ...)",NWEIGHTS);
392 AddVarI(output(), true_signal,
"true signal appraisal (filled differently in each analysis package)");
396 bool baseAnalysis::InitializeSpill(){
403 bool baseAnalysis::FinalizeConfiguration(){
409 if (conf().GetCurrentConfigurationIndex() != ConfigurationManager::default_conf)
413 std::vector<AnaTrueVertex*> trueVertices;
414 trueVertices.reserve(NMAXTRUEVERTICES);
415 std::vector<AnaTrueVertex*>::const_iterator iter;
420 else trueVertex =
static_cast<AnaTrueVertex*
>(GetTrueVertex());
422 if (trueVertex) trueVertices.push_back(trueVertex);
428 if (trueVertices.size() == 0){
431 for (std::vector<AnaTrueVertexB*>::iterator it = vertices.begin(); it!=vertices.end(); it++) {
432 if (!(*it))
continue;
438 trueVertices.push_back(vtx);
443 for (iter = trueVertices.begin(); iter != trueVertices.end(); iter++){
449 vtx->
AccumLevel.resize(sel().GetNEnabledSelections());
455 for (std::vector<SelectionBase*>::iterator it = sel().GetSelections().begin(); it != sel().
GetSelections().end(); it++){
457 if (!(*it)->IsEnabled())
continue;
459 Int_t isel = (*it)->GetEnabledIndex();
462 vtx->
AccumLevel[isel].resize((*it)->GetNBranches());
464 for (UInt_t ibranch=0;ibranch<(*it)->GetNBranches();ibranch++)
465 vtx->
AccumLevel[isel][ibranch]=(*it)->GetAccumCutLevel(ibranch);
472 void baseAnalysis::FillMicroTreesBase(
bool addBase){
490 output().
FillVar(evt_time, static_cast<AnaEventInfo*>(
GetSpill().EventInfo)->EventTime);
495 Float_t flux_weight =1;
501 if (GetVertex()->TrueVertex)
507 if (GetVertex()->TrueVertex){
525 output().IncrementCounter(NWEIGHTS);
530 output().IncrementCounter(NWEIGHTS);
534 void baseAnalysis::FillToyVarsInMicroTreesBase(
bool addBase){
539 if (!GetVertex())
return;
555 static Int_t flux_weight_index=-2;
556 if (conf().GetCurrentConfigurationIndex() == all_syst && flux_weight_index!=-1){
557 if (flux_weight_index==-2){
559 flux_weight_index = config.
GetWeightIndex(all_syst, SystId::kFluxWeightNu);
561 if (flux_weight_index!=-1){
562 Float_t flux_corr = output().
GetToyVectorVarValueF(AnalysisAlgorithm::weight_corr,flux_weight_index);
563 Float_t flux_syst = output().
GetToyVectorVarValueF(AnalysisAlgorithm::weight_syst,flux_weight_index);
565 Float_t total_noflux = output().
GetToyVarValueF(AnalysisAlgorithm::weight_syst_total);
566 if (flux_syst!=0) total_noflux = total_noflux*flux_corr/flux_syst;
567 output().
FillToyVar(weight_syst_total_noflux, total_noflux);
600 output().
FillVar( truelepton_costheta, (Float_t)cos(anaUtils::ArrayToTVector3(vtx.
LeptonDir).Angle(anaUtils::ArrayToTVector3(vtx.
NuDir))));
608 output().IncrementCounterForVar(weight);
613 void baseAnalysis::FillTruthTree(){
618 if (!output().HasTree(OutputManager::truth))
return;
624 for (std::vector<AnaTrueVertexB*>::iterator it = vertices.begin(); it!=vertices.end(); it++) {
628 if (!CheckFillTruthTree(vtx))
continue;
631 output().InitializeTree(OutputManager::truth);
650 for (std::vector<SelectionBase*>::iterator itf=sel().GetSelections().begin();itf!=sel().
GetSelections().end();itf++){
651 if (!(*itf)->IsEnabled())
continue;
653 Int_t isel = (*itf)->GetEnabledIndex();
655 for (UInt_t ibranch=0;ibranch<(*itf)->GetNBranches();ibranch++){
659 output().
FillMatrixVar(accum_level, accumLevel, isel, ibranch);
664 if (sel().GetNMaxBranches()>1)
667 output().
FillVar(accum_level, accumLevel);
679 std::map< std::string, TrackCategoryDefinition* >::iterator its;
680 Int_t categ_index = AnalysisAlgorithm::firstCategory;
681 for (its=cat().GetCategories().begin();its!=cat().
GetCategories().end();its++, categ_index++ ){
682 std::string categ_name = its->first;
685 for (
unsigned int i=0;i<categ.
GetNTypes();i++)
686 output().
FillVectorVar(categ_index, (
int)cat().CheckCategoryType(categ_name,i),i);
688 else output().
FillVar(categ_index, cat().GetCode(categ_name));
692 output().
GetTree(OutputManager::truth)->Fill();
696 if (output().HasTree(OutputManager::RooTrackerVtx)){
699 output().
FillTree(OutputManager::RooTrackerVtx);
void DisableAllCorrections()
Disable all corrections in a given configuration (if conf=="" for all confs)
AnaTrueVertexB * TrueVertex
FluxWeighting * _flux
Access to the flux weighting.
Int_t NuPDG
The PDG code of the incoming neutrino.
Float_t GetToyVarValueF(Int_t index)
Get the value of a var already filled (so to be used in another package)
bool IsMultiType()
Is this a multi-type category ? (Can several types coexist?)
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
TTree * GetTree(Int_t index)
Returns the a tree with a given index.
void InitializeGeometry(bool IsMC=true) const
void SetInitializeTrees(bool ini)
Initialize trees at the beginning of each configuration.
Float_t LeptonDir[3]
The direction of the primary outgoing electron/muon.
void AddCorrection(Int_t index, const std::string &name, CorrectionBase *corr)
void AddTreeWithName(Int_t tree_index, const std::string &tree_name, TTree *tree=NULL)
Add a tree provided its index and name.
void AddToyVar(Int_t index, const std::string &name, const std::string &type, const std::string &docstring)
Add a single analysis variable to all trees.
Int_t RooVtxIndex
The index of the associated RooTrackerVtx vertex from its position in the TClonesArray.
void AddPackage(const std::string &name, const std::string &version)
Add a package.
Float_t Position[4]
The identified position of the global vertex.
void FillVectorVar(Int_t index, Float_t var, Int_t indx=-1)
Fill a vector variable.
std::vector< std::vector< Int_t > > AccumLevel
Accumulated cut level for all selections and cut branches. Tell us if a true vertex has been selected...
std::vector< AnaTrueVertexB * > TrueVertices
The true MC vertices used in this spill.
UInt_t GetNEnabledSelections()
Returns the number of enabled selections.
Float_t GetToyVectorVarValueF(Int_t index, Int_t i1)
Get the value of a var already filled (so to be used in another package)
virtual bool Initialize()
[AnalysisAlgorithm_mandatory]
bool _enableZeroVarConfig
SubDetId::SubDetEnum GetDetector(const Float_t *pos)
Return the detector in which the position is.
AnaBunch & GetBunch()
Get a casted AnaBunchBB to AnaBunch from the InputManager (TODO the protection)
void EnableSystematics(const std::vector< Int_t > &systs, Int_t conf=-1)
Enable the systematics registered with the given indices.
std::vector< SelectionBase * > & GetSelections()
Return the map of selections.
Int_t ID
The ID of the trueObj, which corresponds to the ID of the TTruthParticle that created it...
std::string GetSoftwareVersionFromPath(const std::string &path)
Get The software version from the path of the package.
Float_t LeptonMom
The momentum of the primary outgoing electron/muon.
Representation of a true Monte Carlo vertex.
RooTrackerVtxManager * _rooVtxManager
the manager of the RooTrackerVtx
Float_t NuEnergy
The true energy of the incoming neutrino.
Float_t Position[4]
The position the true interaction happened at.
void SetCurrentTree(Int_t index)
Sets the current tree provided the index.
int GetRunPeriod(int run, int subrun=-1)
Returns the run period (sequentially: 0,1,2,3,4,5 ...)
std::map< std::string, TrackCategoryDefinition * > & GetCategories()
Get the map of track categories.
void SetRooVtxEntrySaved(bool saved)
Methods to check whether the current RooTrackerVtxEntry has been already saved.
SubDetEnum
Enumeration of all detector systems and subdetectors.
Creates the appropriate AnaSpillB type. The rest of the work is done by the base converter.
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.
void ResetCurrentCategories()
Reset the properties of the current track.
Float_t GetWeight(AnaTrueVertexB *vertex, int RunPeriod)
bool _saveRooTrackerVtxTree
Save RooTracker tree in output file.
void FillToyVar(Int_t index, Int_t var)
Fill a single analysis variable.
std::vector< ConfigurationBase * > & GetConfigurations()
return the vector of configurations
void IncrementRooVtxEntry()
Increment by one the current entry in the RooTrackerVtx tree.
void AddEventWeight(Int_t index, EventWeightBase *sys)
Add a new Event Weight provided its index in the manager and a pointer to it.
void EnableEventWeight(Int_t syst, Int_t conf=-1)
Enable the systematic registered with the given index.
void SetForceApplyCorrections(bool force)
If set to true corrections applied in the input file are applied again.
void FillVar(Int_t index, Float_t var)
Fill a single variable.
void SetSaveRooTracker(bool save)
Set whether to save the RooTrackerVtx tree or not.
Int_t Bunch
The index of this bunch (0-7).
unsigned int GetNTypes()
Number of types defined for this category.
AnaSpill & GetSpill()
Get a casted AnaSpillC to AnaSpill from the InputManager.
std::vector< AnalysisAlgorithm * > _usedAnalyses
The Vector of used analysis.
Int_t RooVtxEntry
Entry in the RooTrackerVtx tree (not set directly)
baseAnalysis(AnalysisAlgorithm *ana=NULL)
ProdId_h GetProductionIdFromND280AnalysisTools()
Get Production Id from nd280AnalysisTools.
UInt_t GetNMaxBranches()
Returns the maximum number of branches in all selections.
void SetRooVtxManager(RooTrackerVtxManager *man)
Set the RooTrackerVtxManager.
void AddProduction(ProdId_h prodId, const std::string &prodName, const std::string &prodLowVersion, const std::string &prodHighVersion)
Add a production.
Float_t NuDir[3]
The true (unit) direction of the incoming neutrino.
void FillMatrixVar(Int_t index, Float_t var, Int_t indx1, Int_t indx2)
Fill a matrix variable.
void FillVectorVarFromArray(Int_t index, const Double_t var[], UInt_t size)
Fill a vector variable from array.
void SetSaveRooVtxEntry(bool save)
Methods to check whether the current RooTrackerVtxEntry has been already scheduled for saving...
void FillTree(Int_t tree_index)
Fill a specific tree.