1 #include "AnalysisLoop.hxx" 2 #include <TClonesArray.h> 7 #include "Parameters.hxx" 9 #include "DocStringManager.hxx" 12 #include "MultiThread.hxx" 13 #include "VersionManager.hxx" 15 #include "ZeroToyMaker.hxx" 20 const int NENTRIES_TREESAVE=5000;
30 std::string programName = argv[0];
31 std::string paramFile =
"";
42 bool logMemory =
false;
45 int c = getopt(argc, argv,
"crvmn:e:o:p:s:");
66 std::istringstream tmp(optarg);
83 std::istringstream tmp(optarg);
95 std::cerr <<
"ERROR: No output file" << std::endl << std::endl;
100 if (argc <= optind) {
101 std::cerr <<
"ERROR: No input file" << std::endl << std::endl;
103 }
else if (argc != optind + 1) {
104 std::cerr <<
"ERROR: Only one input file may be specified. To process multiple ROOT files, " << std::endl
105 <<
" list them in a text file, and specify that text file as the input." << std::endl << std::endl;
112 if (paramFile !=
"") {
144 std::cout <<
"For runnning in highland2 you must comment out the line #define MULTITHREAD psycheCore/vXrY/srx/MultiThread.hxx and recompile everything !!!" << std::endl;
157 ana().DefineInputConverters();
161 ana().DefineProductions();
182 ana().output().Initialize();
195 ana().DefineSelections();
202 ana().DefineSystematics();
231 ana().output().InitializeEntry();
235 ana().output().InitializeTree(OutputManager::truth);
247 _entry_count += entry1-entry0;
250 if (_entry_count%1000==0 || _entry_count == _entry_nmax)
251 std::cout <<
"entry: " << _entry_count <<
" of " << _entry_nmax <<
" (" << (100*_entry_count/_entry_nmax) <<
"%) --> " <<
_entry << std::endl;
254 if (!spillOK)
return false;
285 ana().InitializeBunch();
294 ana().output().InitializeTree(ana().output().GetCurrentTree(), ana().GetInitializeTrees());
296 if (ana().evar().HasEventVariations()){
302 ana().evar().Initialize(_entry_nmax);
308 if (ana().eweight().HasEventWeights()){
315 anaUtils::CreateArray(_weightSyst, _nWeightSyst);
318 ana().eweight().Initialize(ana().sel(),_entry_nmax);
325 ana().InitializeConfiguration();
344 ana().InitializeToy();
348 void AnalysisLoop::InitializeSelection(
const SelectionBase& selec){
353 ana().InitializeSelection(selec);
372 ana().FinalizeSelection(selec);
395 if (!ana().sel().PreSelectionPassed(*_event))
return false;
413 if (_weightSyst)
delete [] _weightSyst;
430 if (!
_fillTrees || (!_conf_passed && ana().GetFillSuccessOnly()))
return true;
433 if (!ana().CheckAccumLevelToSave())
return false;
440 ana().FillCategories();
457 ana().FinalizeBunch();
470 ana().output().SetFillSingleTree(OutputManager::truth);
475 ana().FillTruthTree();
478 ana().output().SetFillAllTrees();
482 ana().FinalizeSpill();
487 if (
_entry%NENTRIES_TREESAVE == 0){
488 std::vector< TTree* >::iterator it;
489 for (it=ana().output().GetTrees().begin();it!=ana().output().
GetTrees().end();it++){
490 (*it)->AutoSave(
"SaveSelf");
512 std::vector< TTree* >::iterator it;
513 for (it=ana().output().GetTrees().begin();it!=ana().output().
GetTrees().end();it++){
514 (*it)->AutoSave(
"SaveSelf");
533 Int_t tree_index = NMAXSPECIALTREES;
534 for (std::vector<ConfigurationBase* >::iterator it3= ana().conf().GetConfigurations().begin();it3!=ana().conf().
GetConfigurations().end();it3++, tree_index++){
535 if (!(*it3)->IsEnabled())
continue;
538 (*it3)->SetTreeIndex(tree_index);
542 ana().output().
SetNToys(tree_index, (*it3)->GetNToys());
548 ana().output().
AddVar(AnalysisAlgorithm::entry,
"entry",
"I",
"entry number");
551 ana().output().
AddVar(AnalysisAlgorithm::toy_ref,
"toy_ref",
"I",
"Reference toy index");
554 Int_t categ_index = AnalysisAlgorithm::firstCategory;
555 Int_t counter_index = AnalysisAlgorithm::firstCategoryCounter;
556 for (std::map< std::string, TrackCategoryDefinition*>::iterator it=ana().cat().GetCategories().begin();it!=ana().cat().
GetCategories().end();it++, categ_index++){
557 std::string categ_name = it->first;
560 ana().output().
AddVectorVar(categ_index, categ_name,
"I",
"This is a category variable that can be used to split up a MC histogram into a stack. Use the DumpCategory(\"...\") function for more.", counter_index,
"N"+categ_name, categ.
GetNTypes());
564 ana().output().
AddVar(categ_index, categ_name,
"I",
"This is a category variable that can be used to split up a MC histogram into a stack. Use the DumpCategory(\"...\") function for more.");
567 ana().output().
AddToyVar(AnalysisAlgorithm::redo,
"redo",
"I",
"If running multiple toys (for evaluating systematics), whether the selection was re-performed for this toy.");
572 if (ana().sel().GetNEnabledSelections()>1) {
573 if (ana().sel().GetNMaxBranches()>1) {
574 ana().output().
AddToyMatrixVar(AnalysisAlgorithm::accum_level,
"accum_level",
"I",
575 "The number of the first cut that was failed.\n" 576 "highland supports running multiple toys (for evaluating systematics), so the first index in this matrix is the toy index. \n" 577 "the second index is the selection and the third index is the branch.\n" 578 "If you only have one toy (normal), then you can use accum_level[][0][0], etc., where 0 can be replaced with your selection/branch number.",
579 ana().sel().GetNEnabledSelections(), ana().sel().GetNMaxBranches());
582 ana().output().
AddToyVectorVar(AnalysisAlgorithm::accum_level,
"accum_level",
"I",
583 "The number of the first cut that was failed.\n" 584 "highland supports running multiple toys (for evaluating systematics), so the first index in this matrix is the toy index. \n" 585 "The second index is the selection.\n" 586 "If you only have one toy (normal), then you can use accum_level[][0], etc., where 0 can be replaced with your selection number.",
587 ana().sel().GetNEnabledSelections());
591 if (ana().sel().GetNMaxBranches()>1) {
592 ana().output().
AddToyVectorVar(AnalysisAlgorithm::accum_level,
"accum_level",
"I",
593 "The number of the first cut that was failed.\n" 594 "highland supports running multiple toys (for evaluating systematics), so the first index in this matrix is the toy index. The second index is the branch.\n" 595 "If you only have one toy (normal), then you can use accum_level[][0], etc., where 0 can be replaced with your branch number.",
596 ana().sel().GetNMaxBranches());
598 ana().output().
AddToyVar(AnalysisAlgorithm::accum_level,
"accum_level",
"I",
599 "The number of the first cut that was failed.\n" 600 "highland supports running multiple toys (for evaluating systematics), so the index in this vector is the toy index.\n" 601 "If you only have one toy (normal), then you can use accum_level or accum_level[] to access the correct number.");
605 Int_t indx=AnalysisAlgorithm::first_cut;
606 for (
unsigned int i=0;i<ana().sel().
GetNMaxCuts() ;i++, indx++){
607 sprintf(cut,
"cut%d", i);
608 if (ana().sel().GetNEnabledSelections()>1) {
609 if (ana().sel().GetNMaxBranches()>1) {
610 ana().output().
AddToyMatrixVar(indx, cut,
"I",
"Whether this cut was passed or not.\n" 611 "highland supports running multiple toys (for evaluating systematics), so the first index in this matrix is the toy index. \n" 612 "The second index is the selection and third index is the branch in that selection. \n" 613 "If you only have one toy (normal), then you can use cutN[][0][0], etc., where the 0 can be replaced with your selection/branch number \n" 614 "and N is the cut number.",
615 ana().sel().GetNEnabledSelections(), ana().sel().GetNMaxBranches());
618 ana().output().
AddToyVectorVar(indx, cut,
"I",
"Whether this cut was passed or not.\n" 619 "highland supports running multiple toys (for evaluating systematics), so the index in this vector is the toy index.\n" 620 "The second index is the selection. \n" 621 "If you only have one toy (normal), then you can use cutN or cutN[][0] to access the correct number, \n" 622 "where the 0 can be replaced with your selection number and N is the cut number.",
623 ana().sel().GetNEnabledSelections());
627 if (ana().sel().GetNMaxBranches()>1) {
628 ana().output().
AddToyVectorVar(indx, cut,
"I",
"Whether this cut was passed or not.\n" 629 "highland supports running multiple toys (for evaluating systematics), so the first index in this matrix is the toy index. The second index is the branch.\n" 630 "If you only have one toy (normal), then you can use cutN[][0], etc., where 0 can be replaced with your branch number and N is the cut number.",
631 ana().sel().GetNMaxBranches());
633 ana().output().
AddToyVar(indx, cut,
"I",
"Whether this cut was passed or not.\n" 634 "highland supports running multiple toys (for evaluating systematics), so the index in this vector is the toy index.\n" 635 "If you only have one toy (normal), then you can use cutN or cutN[] to access the correct number, where N is the cut number.");
644 There are several variables in the microtree related with systematic error propagation. The correspondence with variables used to compute the covariance matrix
645 is indicated inside the paretheses:
647 - \b NTOYS (\(N_{toys}\)): this the the number of toy experiments. The same for all events.
648 - \b toy_index (t): the toy experiment index (from 0 to NTOYS-1). It has 1 index: toy_index[NTOYS];
649 - \b toy_weight (\(w^t\)): This is the toy experiment weight. It has 1 index: toy_weight[NTOYS].
650 - \b NWEIGHSYST (\(N_s\)): the number of weight systematics.
651 - \b weight_syst (\((W^t)_e^s\)): this is the event weights for each toy and each weight systematic enabled.
652 It has 2 indexes: weight_syst[NTOYS][NWEIGHTSYST].
653 - \b weight_syst_total (\((W^t)_e\)): the product of all weight systematics. It has one index weight_syst_total[NTOYS]
658 for (std::vector<ConfigurationBase* >::iterator it3= ana().conf().GetConfigurations().begin();it3!=ana().conf().
GetConfigurations().end();it3++){
659 if (!(*it3)->IsEnabled())
continue;
671 Int_t tree_index = (*it3)->GetTreeIndex();
675 if ((*it3)->GetIndex() == ConfigurationManager::default_conf){
676 ana().output().
AddVectorVar(tree_index,AnalysisAlgorithm::weight_syst,
"weight_syst",
"F",
"Weight parameters (corr+syst)", ana().eweight().GetNEnabledEventWeights());
677 ana().output().
AddVar(tree_index,AnalysisAlgorithm::weight_syst_total,
"weight_syst_total",
"F",
"Total weight (corr+syst)");
679 ana().output().
AddVectorVar(tree_index,AnalysisAlgorithm::weight_corr,
"weight_corr",
"F",
"Weight parameters (corr only)", ana().eweight().GetNEnabledEventWeights());
680 ana().output().
AddVar(tree_index,AnalysisAlgorithm::weight_corr_total,
"weight_corr_total",
"F",
"Total weight (corr only)");
684 ana().output().
AddToyVectorVar(tree_index,AnalysisAlgorithm::weight_syst,
"weight_syst",
"F",
"Weight parameters (corr+syst)", ana().eweight().GetNEnabledEventWeights());
685 ana().output().
AddToyVar(tree_index,AnalysisAlgorithm::weight_syst_total,
"weight_syst_total",
"F",
"Total weight (corr+syst)");
687 ana().output().
AddToyVectorVar(tree_index,AnalysisAlgorithm::weight_corr,
"weight_corr",
"F",
"Weight parameters (corr only)", ana().eweight().GetNEnabledEventWeights());
688 ana().output().
AddToyVar(tree_index,AnalysisAlgorithm::weight_corr_total,
"weight_corr_total",
"F",
"Total weight (corr only)");
692 ana().output().
AddVar(tree_index,AnalysisAlgorithm::NWEIGHTSYST,
"NWEIGHTSYST",
"I",
"Number of systematic weight parameters");
696 ana().DefineMicroTrees();
706 if (ana().sel().GetNEnabledSelections()>1) {
707 if (ana().sel().GetNMaxBranches()>1) {
708 ana().output().
AddMatrixVar(OutputManager::truth, AnalysisAlgorithm::accum_level,
"accum_level",
"I",
709 "The number of the first cut that was failed for each branch. Unlike the variable with the same name in the standard micro-trees, \n" 710 "this one has a single toy running multiple toys \n" 711 "The first index is the selection and the second index is the branch.\n" 712 "Then you can use accum_level[0][0], etc., where 0 can be replaced with your selection/branch number.",
713 ana().sel().GetNEnabledSelections(), ana().sel().GetNMaxBranches());
716 ana().output().
AddVectorVar(OutputManager::truth, AnalysisAlgorithm::accum_level,
"accum_level",
"I",
717 "The number of the first cut that was failed for each branch. Unlike the variable with the same name in the standard micro-trees, \n" 718 "this one has a single toy running multiple toys \n" 719 "The first index is the selection and the second index is the branch.\n" 720 "Then you can use accum_level[0], etc., where 0 can be replaced with your selection number.",
721 ana().sel().GetNEnabledSelections());
725 if (ana().sel().GetNMaxBranches()>1) {
726 ana().output().
AddVectorVar(OutputManager::truth, AnalysisAlgorithm::accum_level,
"accum_level",
"I",
727 "The number of the first cut that was failed for each branch. Unlike the variable with the same name in the standard micro-trees, \n" 728 "this one has a single toy running multiple toys \n" 729 "The first index is the branch.\n" 730 "Then you can use accum_level[0], etc., where 0 can be replaced with your branch number.",
731 ana().sel().GetNMaxBranches());
734 ana().output().
AddVar(OutputManager::truth, AnalysisAlgorithm::accum_level,
"accum_level",
"I",
735 "The number of the first cut that was failed for each branch. Unlike the variable with the same name in the standard micro-trees, \n" 736 "this one has a single toy running multiple toys \n" 737 "Then you can use accum_level to access the correct number.");
742 ana().output().SetFillSingleTree(OutputManager::truth);
745 Int_t categ_index = AnalysisAlgorithm::firstCategory;
746 Int_t counter_index = AnalysisAlgorithm::firstCategoryCounter;
747 for (std::map< std::string, TrackCategoryDefinition*>::iterator it=ana().cat().GetCategories().begin();it!=ana().cat().
GetCategories().end();it++, categ_index++){
748 std::string categ_name = it->first;
751 ana().output().
AddVectorVar(categ_index, categ_name,
"I",
"This is a category variable that can be used to split up a MC histogram into a stack. Use the DumpCategory(\"...\") function for more.", counter_index,
"N"+categ_name, categ.
GetNTypes());
755 ana().output().
AddVar(categ_index, categ_name,
"I",
"This is a category variable that can be used to split up a MC histogram into a stack. Use the DumpCategory(\"...\") function for more.");
760 ana().DefineTruthTree();
763 ana().output().SetFillAllTrees();
773 ana().output().SetFillSingleTree(OutputManager::config);
776 ana().output().
AddVar(OutputManager::config, AnalysisAlgorithm::CMTPATH,
"CMTPATH",
"C",
"the CMTPATH used to produce the output file");
777 ana().output().
FillVar(AnalysisAlgorithm::CMTPATH, (std::string)getenv(
"CMTPATH") );
780 ana().output().
AddVar(OutputManager::config, AnalysisAlgorithm::HOSTNAME,
"HOSTNAME",
"C",
"the machine used to produce the output file");
781 if (getenv(
"HOSTNAME"))
782 ana().output().
FillVar(AnalysisAlgorithm::HOSTNAME, (std::string)getenv(
"HOSTNAME") );
784 ana().output().
FillVar(AnalysisAlgorithm::HOSTNAME,
"unknown" );
787 ana().output().
AddVar(OutputManager::config, AnalysisAlgorithm::INPUTFILE,
"InputFile",
"C",
"the input file used to produce the output file");
791 ana().output().
AddVar(OutputManager::config, AnalysisAlgorithm::OriginalFile,
"OriginalFile",
"C",
"the original file used to produce the input file");
794 if (!ana().input().InputIsOriginalTree()){
795 TChain* chain =
new TChain(
"config");
797 char OriginalFile[200]=
"unknown";
798 if (chain->FindLeaf(
"OriginalFile")){
799 chain->SetBranchAddress(
"OriginalFile", OriginalFile);
800 Long64_t centry = chain->LoadTree(0);
801 Int_t nb = chain->GetEntry(0);
805 ana().output().
FillVar(AnalysisAlgorithm::OriginalFile, OriginalFile );
811 ana().output().
AddVar(OutputManager::config, AnalysisAlgorithm::MinAccumLevelToSave,
"MinAccumLevelToSave",
"I",
"the minimum accut level to save the event");
812 ana().output().
FillVar(AnalysisAlgorithm::MinAccumLevelToSave, ana().GetMinAccumCutLevelToSave());
816 ND::versioning().WriteClonesArray(*ana().output().GetTree(OutputManager::config));
819 ana().cat().WriteClonesArray(*ana().output().GetTree(OutputManager::config));
826 ana().sel().WriteClonesArray(*ana().output().GetTree(OutputManager::config));
832 ana().doc().WriteClonesArray(*ana().output().GetTree(OutputManager::config));
839 ana().conf().WriteClonesArray(*ana().output().GetTree(OutputManager::config));
846 ana().syst().WriteClonesArray(*ana().output().GetTree(OutputManager::config));
859 ana().corr().WriteClonesArray(*ana().output().GetTree(OutputManager::config));
866 ana().FillConfigTree();
869 ana().output().SetFillAllTrees();
872 ana().output().
GetTree(OutputManager::config)->Fill();
882 Header* headerp = &ana().input().header();
883 ana().output().
GetTree(OutputManager::header)->Branch(
"POTInfo",
"Header",&headerp,32000,0);
885 ana().output().
GetTree(OutputManager::header)->Fill();
899 if (!ana().input().InputIsOriginalTree()){
903 std::cout <<
"ReadCorrections from first file in list: " << firstFile << std::endl;
908 ana().DefineCorrections();
926 ana().DefineConfigurations();
963 Long64_t nentries = ana().input().
GetEntries();
966 std::cout <<
"AnalysisLoop::Loop(). input tree has " << nentries <<
" entries. You cannot start from entry " << imin << std::endl;
971 if (nmax==0 || imin+nmax>nentries) _entry_nmax = nentries-imin;
972 else _entry_nmax = nmax;
975 _entry_imax = _entry_imin+_entry_nmax;
977 if (ana().input().InputIsFlatTree())
978 std::cout <<
"AnalysisLoop::Loop(). input tree has " << nentries <<
" entries for " << ana().input().header().
GetPOT() <<
" good POT" << std::endl;
980 std::cout <<
"AnalysisLoop::Loop(). input tree has " << nentries <<
" entries (POT counted on the fly)" << std::endl;
981 std::cout <<
"AnalysisLoop::Loop(). loop over " << _entry_nmax <<
" entries from entry number "<< _entry_imin << std::endl;
983 double delta_t[20]={0};
987 while (
_entry<_entry_imax) {
991 gettimeofday(&tim, NULL);
992 double t0=tim.tv_sec+(tim.tv_usec/1000000.0);
998 if (anaUtils::breakLoop)
break;
1001 if (!spillOK)
continue;
1003 gettimeofday(&tim, NULL);
1004 double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
1006 delta_t[0] += t1-t0;
1009 for (
unsigned int ibunch=0;ibunch<ana().input().
GetSpill().
Bunches.size();ibunch++){
1010 gettimeofday(&tim, NULL);
1011 double t2=tim.tv_sec+(tim.tv_usec/1000000.0);
1016 gettimeofday(&tim, NULL);
1017 double t3=tim.tv_sec+(tim.tv_usec/1000000.0);
1020 delta_t[1] += t3-t2;
1027 gettimeofday(&tim, NULL);
1028 double t4=tim.tv_sec+(tim.tv_usec/1000000.0);
1030 if (!conf->IsEnabled())
continue;
1035 gettimeofday(&tim, NULL);
1036 double t5=tim.tv_sec+(tim.tv_usec/1000000.0);
1038 delta_t[2] += t5-t4;
1043 for (
int n=0;n<conf->
GetNToys();n++){
1045 gettimeofday(&tim, NULL);
1046 double t6=tim.tv_sec+(tim.tv_usec/1000000.0);
1052 gettimeofday(&tim, NULL);
1053 double t7=tim.tv_sec+(tim.tv_usec/1000000.0);
1055 delta_t[3] += t7-t6;
1058 for (std::vector<SelectionBase*>::iterator sit= ana().sel().
GetSelections().begin();sit!=ana().sel().
GetSelections().end();sit++){
1060 if (!selec.IsEnabled())
continue;
1061 gettimeofday(&tim, NULL);
1062 double t8=tim.tv_sec+(tim.tv_usec/1000000.0);
1064 InitializeSelection(selec);
1066 gettimeofday(&tim, NULL);
1067 double t9=tim.tv_sec+(tim.tv_usec/1000000.0);
1069 delta_t[4] += t9-t8;
1073 gettimeofday(&tim, NULL);
1074 double t10=tim.tv_sec+(tim.tv_usec/1000000.0);
1076 delta_t[5] += t10-t9;
1080 gettimeofday(&tim, NULL);
1081 double t11=tim.tv_sec+(tim.tv_usec/1000000.0);
1084 delta_t[6] += t11-t10;
1085 if (_toy_passed) _conf_passed=
true;
1088 gettimeofday(&tim, NULL);
1089 double t12=tim.tv_sec+(tim.tv_usec/1000000.0);
1093 gettimeofday(&tim, NULL);
1094 double t13=tim.tv_sec+(tim.tv_usec/1000000.0);
1096 delta_t[7] += t13-t12;
1100 gettimeofday(&tim, NULL);
1101 double t14=tim.tv_sec+(tim.tv_usec/1000000.0);
1105 gettimeofday(&tim, NULL);
1106 double t15=tim.tv_sec+(tim.tv_usec/1000000.0);
1108 delta_t[8] += t15-t14;
1110 gettimeofday(&tim, NULL);
1111 double t16=tim.tv_sec+(tim.tv_usec/1000000.0);
1115 gettimeofday(&tim, NULL);
1116 double t17=tim.tv_sec+(tim.tv_usec/1000000.0);
1118 delta_t[9] += t17-t16;
1120 gettimeofday(&tim, NULL);
1121 double t18=tim.tv_sec+(tim.tv_usec/1000000.0);
1123 gettimeofday(&tim, NULL);
1124 double t19=tim.tv_sec+(tim.tv_usec/1000000.0);
1126 delta_t[10] += t19-t18;
1128 delta_t[11] += t19-t0;
1131 for (Int_t i=0;i<11;i++)
1132 delta_t[12] += delta_t[i];
1135 std::cout <<
"time profile --------------" << std::endl;
1136 std::cout <<
"Ini Spill: " << delta_t[0] << std::endl;
1137 std::cout <<
"Ini Bunch: " << delta_t[1] << std::endl;
1138 std::cout <<
"Ini Conf: " << delta_t[2] << std::endl;
1139 std::cout <<
"Ini Toy (v syst): " << delta_t[3] << std::endl;
1140 std::cout <<
"Ini Sel: " << delta_t[4] << std::endl;
1141 std::cout <<
"Selection: " << delta_t[5] << std::endl;
1142 std::cout <<
"End Sel (w syst): " << delta_t[6] << std::endl;
1143 std::cout <<
"End Toy: " << delta_t[7] << std::endl;
1144 std::cout <<
"End Conf: " << delta_t[8] << std::endl;
1145 std::cout <<
"End Bunch: " << delta_t[9] << std::endl;
1146 std::cout <<
"End Spill: " << delta_t[10] << std::endl;
1147 std::cout <<
"Total: " << delta_t[11] << std::endl;
1148 std::cout <<
"Total wo t: " << delta_t[12] << std::endl;
1163 bool ToyPassed = selec.
Apply(*_event, redo);
1167 ana().output().
FillToyVar(AnalysisAlgorithm::redo, (
int)redo);
1177 ana().output().
FillVar(AnalysisAlgorithm::entry, (
int)
_entry);
1180 std::map< std::string, TrackCategoryDefinition* >::iterator it;
1181 Int_t categ_index = AnalysisAlgorithm::firstCategory;
1182 for (it=ana().cat().GetCategories().begin();it!=ana().cat().
GetCategories().end();it++, categ_index++ ){
1183 std::string categ_name = it->first;
1186 for (
unsigned int i=0;i<categ.
GetNTypes();i++)
1187 ana().output().
FillVectorVar(categ_index, (
int)ana().cat().CheckCategoryType(categ_name,i),i);
1189 else ana().output().
FillVar(categ_index, ana().cat().GetCode(categ_name));
1193 ana().output().
FillVar(AnalysisAlgorithm::toy_ref, ana().conf().GetCurrentConfiguration()->GetRefToyIndex());
1197 ana().FillMicroTrees();
1201 ana().output().FillMicroTrees();
1209 ana().output().
FillToyVar(OutputManager::toy_index, ana().conf().GetToyIndex());
1211 if (!_toy_passed && ana().GetFillSuccessOnly())
return;
1212 if (!ana().CheckAccumLevelToSave())
return;
1218 for (std::vector<SelectionBase*>::iterator it=ana().sel().GetSelections().begin();it!=ana().sel().
GetSelections().end();it++){
1219 if (!(*it)->IsEnabled())
continue;
1220 for (UInt_t ibranch=0;ibranch<(*it)->GetNBranches();ibranch++){
1221 Int_t indx=AnalysisAlgorithm::first_cut;
1224 ana().output().
FillToyMatrixVar(AnalysisAlgorithm::accum_level, (*it)->GetAccumCutLevel(ibranch), isel, ibranch);
1225 for (
unsigned int i=0;i<(*it)->GetNCuts(ibranch);i++, indx++){
1226 ana().output().
FillToyMatrixVar(indx, (*it)->GetCutPassed(i, ibranch), isel, ibranch);
1230 ana().output().
FillToyVectorVar(AnalysisAlgorithm::accum_level, (*it)->GetAccumCutLevel(ibranch), isel);
1231 for (
unsigned int i=0;i<(*it)->GetNCuts(ibranch);i++, indx++){
1232 ana().output().
FillToyVectorVar(indx, (*it)->GetCutPassed(i, ibranch), isel);
1238 ana().output().
FillToyVectorVar(AnalysisAlgorithm::accum_level, (*it)->GetAccumCutLevel(ibranch), ibranch);
1239 for (
unsigned int i=0;i<(*it)->GetNCuts(ibranch);i++, indx++){
1240 ana().output().
FillToyVectorVar(indx, (*it)->GetCutPassed(i, ibranch), ibranch);
1244 ana().output().
FillToyVar(AnalysisAlgorithm::accum_level, (*it)->GetAccumCutLevel(ibranch));
1245 for (
unsigned int i=0;i<(*it)->GetNCuts(ibranch);i++, indx++){
1246 ana().output().
FillToyVar(indx, (*it)->GetCutPassed(i, ibranch));
1260 Float_t weight_syst_total = 1.;
1261 Float_t weight_corr_total = 1.;
1263 for (
int j = 0; j < nWeightSyst; ++j){
1264 Float_t weight_syst = 1.;
1265 Float_t weight_corr = 1.;
1266 if (w < nWeightSyst){
1267 weight_syst = _weightSyst[w].Systematic;
1268 weight_corr = _weightSyst[w].Correction;
1270 if (ana().conf().GetCurrentConfigurationIndex() == ConfigurationManager::default_conf){
1271 ana().output().
FillVectorVar(AnalysisAlgorithm::weight_syst, weight_syst, w);
1272 ana().output().
FillVectorVar(AnalysisAlgorithm::weight_corr, weight_corr, w);
1276 ana().output().
FillToyVectorVar(AnalysisAlgorithm::weight_syst, weight_syst, w);
1277 ana().output().
FillToyVectorVar(AnalysisAlgorithm::weight_corr, weight_corr, w);
1280 if(weight_syst < 0.) weight_syst = 0.;
1281 if(weight_syst > 100.) weight_syst = 100.;
1282 if(weight_syst != weight_syst) {
1283 std::cerr <<
"Warning: systematic weight_syst is NaN, setting to 0!" << std::endl;
1286 if(weight_corr < 0.) weight_corr = 0.;
1287 if(weight_corr > 100.) weight_corr = 100.;
1288 if(weight_corr != weight_corr) {
1289 std::cerr <<
"Warning: systematic weight_corr is NaN, setting to 0!" << std::endl;
1293 weight_syst_total *= weight_syst;
1294 weight_corr_total *= weight_corr;
1298 if (ana().conf().GetCurrentConfigurationIndex() == ConfigurationManager::default_conf){
1299 ana().output().
FillVar(AnalysisAlgorithm::weight_syst_total, weight_syst_total);
1300 ana().output().
FillVar(AnalysisAlgorithm::weight_corr_total, weight_corr_total);
1303 ana().output().
FillToyVar(AnalysisAlgorithm::weight_syst_total, weight_syst_total);
1304 ana().output().
FillToyVar(AnalysisAlgorithm::weight_corr_total, weight_corr_total);
1306 ana().output().
FillVar(AnalysisAlgorithm::NWEIGHTSYST, nWeightSyst);
1311 ana().FillToyVarsInMicroTrees();
1317 std::cout <<
"usage: " << programName <<
" [options] [input-file]" << std::endl;
1318 std::cout << std::endl;
1319 std::cout <<
"Options:" << std::endl;
1320 std::cout <<
" -c Run in cosmics mode, putting all tracks in one 'bunch'" << std::endl;
1321 std::cout <<
" -o <file> Set the name of an output file (mandatory)" << std::endl;
1322 std::cout <<
" -n <cnt> Only read <cnt> events" << std::endl;
1323 std::cout <<
" -s <cnt> Skip <cnt> events" << std::endl;
1324 std::cout <<
" -e <file> Set the name of file containing events to skim (format: run subrun event)" << std::endl;
1325 std::cout <<
" -p <file> Set the name of a parameter override file" << std::endl;
1326 std::cout <<
" -v Don't Check version compatibility between nd280AnalysisTools and oaAnalysis file" << std::endl;
1327 std::cout <<
" -r Don't fill any trees and don't create an output file (mainly for speed tests)" << std::endl;
1328 std::cout <<
" -m Dumps on the screen the memory usage" << std::endl;
1335 Loop(_entry_nmax, _entry_imin);
void DefineCorrections()
Define the corrections to be applied.
void DumpConfigurations(SystematicManager *syst=NULL)
Dump summary info about all configurations.
void AddVar(Int_t index, const std::string &name, const std::string &type, const std::string &doc, double ini=-9999)
Add a single variable to all trees.
void AddWeightSystematic(Int_t index, EventWeightBase *sys)
Register an SystematicBase as a weight systematic.
MemoryUsage _memory
Tools for tracking memory usage.
Int_t GetIndex() const
Return the index of this systematic.
void AddConfiguration(Int_t index, const std::string &conf, UInt_t ntoys=1, Int_t randomSeed=-1, ToyMaker *toyMaker=NULL)
Add a new configuration.
bool IsMultiType()
Is this a multi-type category ? (Can several types coexist?)
UInt_t GetNEnabledEventWeights()
Returns the number of enabled EventWeights.
virtual AnaEventC * MakeEvent()=0
[AnalysisAlgorithm_optional]
TTree * GetTree(Int_t index)
Returns the a tree with a given index.
void Loop(int nmax=0, int imin=0)
void CreateToyBoxArray(Int_t nevents)
Create the array of PreviousToyBox for all enabled selections.
AnalysisLoop(AnalysisAlgorithm *ana, int argc, char *argv[])
Constructor which parses and sanity checks the command line options.
ConfigurationBase * GetCurrentConfiguration() const
return the current configuration
void FillHeaderTree()
Fill the "header" tree, which includes POT information etc.
UInt_t GetNEventVariations() const
Returns the number of EventVariations.
bool Process(SelectionBase &selec)
void SetCurrentConfigurationIndex(Int_t conf)
Set the index of the current configuration.
void FinalizeSelection(const SelectionBase &sel)
UInt_t GetNMaxCuts()
Returns the maximum number of cuts in all selections.
void AddTreeWithName(Int_t tree_index, const std::string &tree_name, TTree *tree=NULL)
Add a tree provided its index and name.
std::vector< EventVariationBase * > & GetEventVariations()
Get the vector of EventVariations.
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 GetNToys() const
Get and sets the number of toys.
void FillVectorVar(Int_t index, Float_t var, Int_t indx=-1)
Fill a vector variable.
void DefineMicroTrees()
Define the variables that should be stored in the output micro-trees.
std::vector< AnaBunchC * > Bunches
The reconstructed objects, split into timing bunches.
void FillToyVectorVar(Int_t index, Int_t var, Int_t comp)
Fill a vector analysis variable.
UInt_t GetNEnabledSelections()
Returns the number of enabled selections.
UInt_t GetNEventWeights() const
Returns the number of EventWeights.
const std::vector< Int_t > & GetEnabledEventVariations()
Get the variations enabled for this configuration.
void InitializeEvent(SelectionManager &sel, AnaEventC &event)
Fill the SystBox for the enabled EventWeights.
ToyMaker & GetToyMaker()
Returns the ToyMaker.
const ToyBoxB & GetPreviousToyBox(const AnaEventC &event) const
Get the ToyBox of the last processed toy for a particular event.
std::string _inputFileType
void FinalizeEvent(AnaEventC &event)
Delete the SystBox for all EventWeights.
UInt_t GetNEnabledEventVariations()
Returns the number of enabled EventVariations.
void InitializeConfiguration()
void SetEvent(AnaEventC *event)
Set the current event into the algorithm and all used algorithms.
std::vector< SelectionBase * > & GetSelections()
Return the map of selections.
bool _versionCheck
Check version compatibility between nd280AnalysisTools compilation and oaAnalysis file...
void DisableAllEventVariations()
Disable all eventVariations.
void InitializeEvent(SelectionManager &sel, AnaEventC &event)
Fill the SystBox for the enabled EventVariations.
const std::vector< Int_t > & GetEnabledEventWeights()
Get the weights enabled for this configuration.
void SetToyIndex(int index)
Set and gets the index of the current toy.
Int_t GetTreeIndex() const
Returns the index of the tree associated to this configuration in the TreeManager.
void SetCurrentTree(Int_t index)
Sets the current tree provided the index.
void FillToyVarsInMicroTrees()
Fill the standard configurations only toy-dependent variables.
void FillToyMatrixVar(Int_t index, Int_t var, Int_t comp1, Int_t comp2)
Fill a matrix analysis variable.
std::map< std::string, TrackCategoryDefinition * > & GetCategories()
Get the map of track categories.
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
void SetNToys(Int_t tree_index, int ntoys)
Sets and gets the number of toy experiments for a given configuration.
void ApplyCorrections(AnaSpillC &spill)
Apply all corrections.
std::string _inputFileName
Path to the input file, as defined by the user.
bool UndoEventVariations(AnaEventC &event)
Undo the event variation (Undo the variation, that is, go back to the previous values of modified obs...
void DisableAllEventWeights()
Disable all eventWeights.
void ResetCurrentCategories()
Reset the properties of the current track.
virtual void Finalize()
[AnalysisAlgorithm_optional]
bool Apply(AnaEventC &event, bool &redo)
Apply all steps in the selection.
void PrintUsage(const std::string &programName)
void ReadParamOverrideFile(TString filename)
void FillToyVar(Int_t index, Int_t var)
Fill a single analysis variable.
void DefineTruthTree()
Define the "truth" tree. See FillTruthTree().
void SetForceFillEventSummary(bool force)
std::string _inputSkimFileName
Path to the file with the list of events to skim, as defined by the user.
std::vector< ConfigurationBase * > & GetConfigurations()
return the vector of configurations
void DefineConfigurations()
Define the configurations (micro-trees) and which systematics should be applied in each "configuratio...
void FillVar(Int_t index, Float_t var)
Fill a single variable.
std::string _outputFileName
What to call the output file, as defined by the user.
void FillConfigTree()
Fill the "config" tree, which includes details of the analysis cuts etc.
bool _fillTrees
Whether to fill the trees and create an output file or not.
unsigned int GetNTypes()
Number of types defined for this category.
void ApplyEventVariations(const ToyExperiment &toy, AnaEventC &event)
Apply all EventVariations.
void FinalizeEvent(AnaEventC &event)
Delete the SystBox for all EventVariations.
void SetToyIndex(Int_t index)
Set and gets the index of the current toy experiment.
void EnableEventVariations(const std::vector< Int_t > &systs)
Enable the EventVariations registered with the given indices.
void FillMicroTrees()
Fill the standard configurations trees:
void SetVersionCheck(bool check)
Set version checking.
ToyExperiment * GetToyExperiment(UInt_t index)
Returns the Toy experiment with a given index.
void DumpCorrections()
Dump all corrections.
std::vector< TTree *> & GetTrees()
Returns the map of trees.
bool FinalizeConfiguration()
std::vector< EventWeightBase * > & GetEventWeights()
Get the vector of EventWeights.
void AddMatrixVar(Int_t index, const std::string &name, const std::string &type, const std::string &doc, Int_t counter_index, const std::string &counter_name, int size1=-MAXVECTORSIZE, int size2=-1)
Add a matrix variable to all trees.
void CloseOutputFile()
close the output file
void AddToyMatrixVar(Int_t index, const std::string &name, const std::string &type, const std::string &docstring, int ncomp1, int ncomp2)
Add a matrix analysis variable to all trees.
Int_t GetIndex() const
Returns the configuration index (should match the one in the Configuration Manager) ...
void EnableEventWeights(const std::vector< Int_t > &systs)
Enable the EventWeights registered with the given indices.
UInt_t GetNMaxBranches()
Returns the maximum number of branches in all selections.
bool _enableTruthTree
Whether the "truth" tree should be filled. See FillTruthTree().
void Enable(bool enable=true)
virtual bool GetIsMC() const =0
Return whether this event is from Monte Carlo or not.
void FinalizeEvent(const AnaEventC &event)
Delete the PreviousToyBox pointer for the last toy of the event for all enabled selections.
void EnableSystematics(const std::vector< Int_t > &indices)
Enable the systematic registered with the given name.
void AddVectorVar(Int_t index, const std::string &name, const std::string &type, const std::string &doc, Int_t counter_index, const std::string &counter_name, Int_t size=-MAXVECTORSIZE)
Add a vector variable to all trees.
void AddToyVectorVar(Int_t index, const std::string &name, const std::string &type, const std::string &docstring, int ncomp)
Add a vector analysis variable to all trees.
Weight_h ComputeEventWeights(const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &ToyBox)
Compute all eventWeights. Returns the total event normalization weight.
void FinalizeToyBase()
[AnalysisAlgorithm_mandatory]
void AddVariationSystematic(Int_t index, EventVariationBase *sys)
Register an EventVariationBase as a variation systematic.
void Write()
Write histograms of the memory usage to the output file.
void SetReadParamOverrideFilePointPassed()
Set whether the point in which the overwride parameters file is read is passed or not...
void ReadCorrections(const std::string &file, bool input=false)
Readthe corrections from a file.
Long64_t _entry
Fill the "truth" tree.
virtual const char * GetName() const
Return the name of this systematic. This overrides the TObject::GetName() interface.
void CreateToyExperiments(const SystematicManager &syst)
Create the ToyExperiments using the ToyMaker and the SystematicManager.
bool FinalizeToy()
Called after each toy experiment is complete.
void InitializeEvent(AnaEventC &event)
Initialize the EventBox for all enabled selections.