Functions | Variables
gRwghtNCorrelatedParams.cxx File Reference
#include <TArrayD.h>
#include <TFile.h>
#include <TKey.h>
#include <TList.h>
#include <TMath.h>
#include <TMatrixD.h>
#include <TTree.h>
#include <TRandom.h>
#include "Conventions/Constants.h"
#include "Conventions/Controls.h"
#include "EVGCore/EventRecord.h"
#include "Ntuple/NtpMCFormat.h"
#include "Ntuple/NtpMCTreeHeader.h"
#include "Ntuple/NtpMCEventRecord.h"
#include "Numerical/RandomGen.h"
#include "Messenger/Messenger.h"
#include "ReWeight/GReWeight.h"
#include "ReWeight/GReWeightI.h"
#include "ReWeight/GReWeightAGKY.h"
#include "ReWeight/GReWeightDISNuclMod.h"
#include "ReWeight/GReWeightFGM.h"
#include "ReWeight/GReWeightFZone.h"
#include "ReWeight/GReWeightINuke.h"
#include "ReWeight/GReWeightNonResonanceBkg.h"
#include "ReWeight/GReWeightNuXSecCCQE.h"
#include "ReWeight/GReWeightNuXSecCCQEvec.h"
#include "ReWeight/GReWeightNuXSecCCRES.h"
#include "ReWeight/GReWeightNuXSecNCRES.h"
#include "ReWeight/GReWeightNuXSecDIS.h"
#include "ReWeight/GReWeightNuXSecCOH.h"
#include "ReWeight/GReWeightResonanceDecay.h"
#include "ReWeight/GSystSet.h"
#include "ReWeight/GSystUncertainty.h"
#include "Utils/CmdLnArgParser.h"
#include "Utils/MathUtils.h"
#include "Utils/StringUtils.h"

Go to the source code of this file.

Functions

void PrintSyntax ()
 
void GetEventRange (Long64_t nev_in_file, Long64_t &nfirst, Long64_t &nlast)
 
void GetCommandLineArgs (int argc, char **argv)
 
void GetCorrelationMatrix (string fname, TMatrixD *&cmat)
 
void AdoptWeightCalcs (vector< GSyst_t > lsyst, GReWeight &rw)
 
bool FindIncompatibleSystematics (vector< GSyst_t > lsyst)
 
int main (int argc, char **argv)
 

Variables

vector< GSyst_tgOptVSyst
 
vector< double > gOptVCentVal
 
string gOptInpFilename
 
string gOptInpCovariance
 
string gOptOutFilename
 
Long64_t gOptNEvt1
 
Long64_t gOptNEvt2
 
int gOptRunKey = 0
 
int gOptNSyst = 0
 
int gOptNTwk = 0
 
TRandom * tRnd = new TRandom()
 

Function Documentation

void AdoptWeightCalcs ( vector< GSyst_t lsyst,
GReWeight rw 
)

Definition at line 762 of file gRwghtNCorrelatedParams.cxx.

763 {
764  //
765  // Sets of systematics can be incompatible because they request different
766  // reweighting modes. If one of these systematics is requested, adopt a
767  // reweighting calculator and set it to the appropriate mode.
768  //
770  for(it=lsyst.begin();it != lsyst.end();it++)
771  {
772  switch(*it){
773  // CC QE
774  case kXSecTwkDial_MaCCQE:
777  if ( ! rw.WghtCalc("xsec_ccqe") ){
778  LOG("grwghtnp", pNOTICE) << "Adopting xsec_ccqe weight calc";
779  rw.AdoptWghtCalc( "xsec_ccqe", new GReWeightNuXSecCCQE );
780  GReWeightNuXSecCCQE * rwccqe =
781  dynamic_cast<GReWeightNuXSecCCQE *> (rw.WghtCalc("xsec_ccqe"));
782  if (*it == kXSecTwkDial_MaCCQE) {
783  rwccqe->SetMode(GReWeightNuXSecCCQE::kModeMa); }
784  else { rwccqe->SetMode(GReWeightNuXSecCCQE::kModeNormAndMaShape); }
785  }
786  break;
792  if ( ! rw.WghtCalc("xsec_ccqe") ){
793  LOG("grwghtnp", pNOTICE) << "Adopting xsec_ccqe weight calc";
794  rw.AdoptWghtCalc( "xsec_ccqe", new GReWeightNuXSecCCQE );
795  GReWeightNuXSecCCQE * rwccqe =
796  dynamic_cast<GReWeightNuXSecCCQE *> (rw.WghtCalc("xsec_ccqe"));
797  rwccqe->SetMode(GReWeightNuXSecCCQE::kModeZExp);
798  }
799  break;
800  // CC Res
803  if ( ! rw.WghtCalc("xsec_ccres") ){
804  LOG("grwghtnp", pNOTICE) << "Adopting xsec_ccres weight calc";
805  rw.AdoptWghtCalc( "xsec_ccres", new GReWeightNuXSecCCRES );
806  GReWeightNuXSecCCRES * rwccres =
807  dynamic_cast<GReWeightNuXSecCCRES *> (rw.WghtCalc("xsec_ccres"));
808  rwccres->SetMode(GReWeightNuXSecCCRES::kModeMaMv);
809  }
810  break;
814  if ( ! rw.WghtCalc("xsec_ccres") ){
815  LOG("grwghtnp", pNOTICE) << "Adopting xsec_ccres weight calc";
816  rw.AdoptWghtCalc( "xsec_ccres", new GReWeightNuXSecCCQE );
817  GReWeightNuXSecCCQE * rwccres =
818  dynamic_cast<GReWeightNuXSecCCQE *> (rw.WghtCalc("xsec_ccres"));
819  rwccres->SetMode(GReWeightNuXSecCCRES::kModeNormAndMaMvShape);
820  }
821  break;
822  // DIS
827  if ( ! rw.WghtCalc("xsec_dis") ){
828  LOG("grwghtnp", pNOTICE) << "Adopting xsec_dis weight calc";
829  rw.AdoptWghtCalc( "xsec_dis", new GReWeightNuXSecDIS );
830  GReWeightNuXSecDIS * rwdis =
831  dynamic_cast<GReWeightNuXSecDIS *> (rw.WghtCalc("xsec_dis"));
832  rwdis->SetMode(GReWeightNuXSecDIS::kModeABCV12uShape);
833  }
834  break;
835  case kXSecTwkDial_AhtBY:
836  case kXSecTwkDial_BhtBY:
837  case kXSecTwkDial_CV1uBY:
838  case kXSecTwkDial_CV2uBY:
839  if ( ! rw.WghtCalc("xsec_dis") ){
840  LOG("grwghtnp", pNOTICE) << "Adopting xsec_dis weight calc";
841  rw.AdoptWghtCalc( "xsec_dis", new GReWeightNuXSecDIS );
842  GReWeightNuXSecDIS * rwdis =
843  dynamic_cast<GReWeightNuXSecDIS *> (rw.WghtCalc("xsec_dis"));
844  rwdis->SetMode(GReWeightNuXSecDIS::kModeABCV12u);
845  }
846  break;
847  // NC Res
850  if ( ! rw.WghtCalc("xsec_ncres") ){
851  LOG("grwghtnp", pNOTICE) << "Adopting xsec_ncres weight calc";
852  rw.AdoptWghtCalc( "xsec_ncres", new GReWeightNuXSecNCRES );
853  GReWeightNuXSecNCRES * rwncres =
854  dynamic_cast<GReWeightNuXSecNCRES *> (rw.WghtCalc("xsec_ncres"));
855  rwncres->SetMode(GReWeightNuXSecNCRES::kModeMaMv);
856  }
857  break;
861  if ( ! rw.WghtCalc("xsec_ncres") ){
862  LOG("grwghtnp", pNOTICE) << "Adopting xsec_ncres weight calc";
863  rw.AdoptWghtCalc( "xsec_ncres", new GReWeightNuXSecNCRES );
864  GReWeightNuXSecNCRES * rwncres =
865  dynamic_cast<GReWeightNuXSecNCRES *> (rw.WghtCalc("xsec_ncres"));
866  rwncres->SetMode(GReWeightNuXSecNCRES::kModeNormAndMaMvShape);
867  }
868  break;
869  default: // no fine-tuning needed
870  break;
871  }
872  }
873 }
Reweighting GENIE DIS neutrino-nucleus cross sections.
tweak Mv CCRES, affects d2sigma(CCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:59
tweak Z-expansion coefficient 1, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:157
tweak Mv CCRES, affects d2sigma(CCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:57
intermediate_table::iterator iterator
Reweighting CCQE GENIE neutrino cross sections.
tweak CCQE normalization (energy independent)
Definition: GSyst.h:49
tweak the Bodek-Yang model parameter B_{ht} - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:91
Reweight GENIE NC resonance neutrino-production cross section. Basically a clone of the corresponding...
GReWeightI * WghtCalc(string name)
access a weight calculator by name
Definition: GReWeight.cxx:61
tweak Z-expansion coefficient 4, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:160
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87
tweak Z-expansion coefficient 3, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:159
tweak the Bodek-Yang model parameter CV2u - incl. both shape and normalization effect ...
Definition: GSyst.h:89
tweak Z-expansion coefficient 2, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:158
tweak Z-expansion CCQE normalization (energy independent)
Definition: GSyst.h:156
void AdoptWghtCalc(string name, GReWeightI *wcalc)
add concrete weight calculator, transfers ownership
Definition: GReWeight.cxx:54
tweak CCRES normalization
Definition: GSyst.h:55
tweak Mv NCRES, affects d2sigma(NCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:64
tweak the Bodek-Yang model parameter A_{ht} - incl. both shape and normalization effect ...
Definition: GSyst.h:86
tweak the Bodek-Yang model parameter A_{ht} - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:90
tweak Ma CCRES, affects d2sigma(CCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:58
tweak NCRES normalization
Definition: GSyst.h:60
tweak Ma CCQE, affects dsigma(CCQE)/dQ2 both in shape and normalization
Definition: GSyst.h:52
tweak the Bodek-Yang model parameter CV1u - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:92
tweak Ma CCRES, affects d2sigma(CCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:56
tweak the Bodek-Yang model parameter CV1u - incl. both shape and normalization effect ...
Definition: GSyst.h:88
Reweight GENIE CC resonance neutrino-production.
#define pNOTICE
Definition: Messenger.h:52
tweak Ma NCRES, affects d2sigma(NCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:61
tweak Mv NCRES, affects d2sigma(NCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:62
tweak the Bodek-Yang model parameter CV2u - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:93
tweak Ma CCQE, affects dsigma(CCQE)/dQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:51
tweak the Bodek-Yang model parameter B_{ht} - incl. both shape and normalization effect ...
Definition: GSyst.h:87
tweak Ma NCRES, affects d2sigma(NCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:63
bool FindIncompatibleSystematics ( vector< GSyst_t lsyst)

Definition at line 641 of file gRwghtNCorrelatedParams.cxx.

642 {
643  //
644  // returns false if there are incompatible systematics
645  //
648  // CC QE
649  GSyst_t ccqe_ma_shp[1]
650  = { kXSecTwkDial_MaCCQE };
651  GSyst_t ccqe_ma_shp_norm[2]
653  GSyst_t ccqe_z_shp[5]
657  // CC Res
658  GSyst_t ccres_shp[2]
660  GSyst_t ccres_shp_norm[3]
663  // DIS
664  GSyst_t dis_shp_norm[4]
667  GSyst_t dis_shp[4]
670  // NC Res
671  GSyst_t ncres_shp[2]
673  GSyst_t ncres_shp_norm[3]
676 
677  //
678  // Sort systematics by mode (it0)
679  // Get the list of systematics for that systematic
680  // Look through the rest of systematics the list for others with similar modes (it1)
681  // If it1 conflicts with the group for it0, reject whole list
682  //
683  for(it0=lsyst.begin();it0 != lsyst.end();it0++)
684  {
685  switch(*it0){
686  // CC QE
687  case kXSecTwkDial_MaCCQE:
688  for(it1=it0;it1 != lsyst.end();it1++){
689  for(int i=0;i<2;i++){ if(ccqe_ma_shp_norm[i] == *it1) return false; }
690  for(int i=0;i<5;i++){ if(ccqe_z_shp[i] == *it1) return false; }
691  }
693  case kXSecTwkDial_MaCCQEshape:
694  for(it1=it0;it1 != lsyst.end();it1++){
695  for(int i=0;i<1;i++){ if(ccqe_ma_shp[i] == *it1) return false; }
696  for(int i=0;i<5;i++){ if(ccqe_z_shp[i] == *it1) return false; }
697  }
698  break;
703  case kXSecTwkDial_ZExpA4CCQE:
704  for(it1=it0;it1 != lsyst.end();it1++){
705  for(int i=0;i<1;i++){ if(ccqe_ma_shp[i] == *it1) return false; }
706  for(int i=0;i<2;i++){ if(ccqe_ma_shp_norm[i] == *it1) return false; }
707  }
708  break;
709  // CC RES
711  case kXSecTwkDial_MvCCRES:
712  for(it1=it0;it1 != lsyst.end();it1++){
713  for(int i=0;i<3;i++){ if(ccres_shp_norm[i] == *it1) return false; }
714  }
715  break;
718  case kXSecTwkDial_MvCCRESshape:
719  for(it1=it0;it1 != lsyst.end();it1++){
720  for(int i=0;i<2;i++){ if(ccres_shp[i] == *it1) return false; }
721  }
722  break;
723  // DIS
727  case kXSecTwkDial_CV2uBYshape:
728  for(it1=it0;it1 != lsyst.end();it1++){
729  for(int i=0;i<4;i++){ if(dis_shp_norm[i] == *it1) return false; }
730  }
731  break;
732  case kXSecTwkDial_AhtBY:
733  case kXSecTwkDial_BhtBY:
734  case kXSecTwkDial_CV1uBY:
735  case kXSecTwkDial_CV2uBY:
736  for(it1=it0;it1 != lsyst.end();it1++){
737  for(int i=0;i<4;i++){ if(dis_shp[i] == *it1) return false; }
738  }
739  break;
740  // NC RES
742  case kXSecTwkDial_MvNCRES:
743  for(it1=it0;it1 != lsyst.end();it1++){
744  for(int i=0;i<3;i++){ if(ncres_shp_norm[i] == *it1) return false; }
745  }
746  break;
749  case kXSecTwkDial_MvNCRESshape:
750  for(it1=it0;it1 != lsyst.end();it1++){
751  for(int i=0;i<2;i++){ if(ncres_shp[i] == *it1) return false; }
752  }
753  break;
754  default: // no conflicts
755  break;
756  }
757  }
758  return true;
759 
760 }
tweak Mv CCRES, affects d2sigma(CCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:59
tweak Z-expansion coefficient 1, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:157
tweak Mv CCRES, affects d2sigma(CCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:57
intermediate_table::iterator iterator
tweak CCQE normalization (energy independent)
Definition: GSyst.h:49
tweak the Bodek-Yang model parameter B_{ht} - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:91
tweak Z-expansion coefficient 4, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:160
tweak Z-expansion coefficient 3, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:159
tweak the Bodek-Yang model parameter CV2u - incl. both shape and normalization effect ...
Definition: GSyst.h:89
tweak Z-expansion coefficient 2, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:158
tweak Z-expansion CCQE normalization (energy independent)
Definition: GSyst.h:156
An enumeration of systematic parameters.
tweak CCRES normalization
Definition: GSyst.h:55
tweak Mv NCRES, affects d2sigma(NCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:64
tweak the Bodek-Yang model parameter A_{ht} - incl. both shape and normalization effect ...
Definition: GSyst.h:86
tweak the Bodek-Yang model parameter A_{ht} - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:90
tweak Ma CCRES, affects d2sigma(CCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:58
tweak NCRES normalization
Definition: GSyst.h:60
tweak Ma CCQE, affects dsigma(CCQE)/dQ2 both in shape and normalization
Definition: GSyst.h:52
tweak the Bodek-Yang model parameter CV1u - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:92
tweak Ma CCRES, affects d2sigma(CCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:56
tweak the Bodek-Yang model parameter CV1u - incl. both shape and normalization effect ...
Definition: GSyst.h:88
tweak Ma NCRES, affects d2sigma(NCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:61
tweak Mv NCRES, affects d2sigma(NCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:62
tweak the Bodek-Yang model parameter CV2u - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:93
tweak Ma CCQE, affects dsigma(CCQE)/dQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:51
tweak the Bodek-Yang model parameter B_{ht} - incl. both shape and normalization effect ...
Definition: GSyst.h:87
tweak Ma NCRES, affects d2sigma(NCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:63
void GetCommandLineArgs ( int  argc,
char **  argv 
)

Definition at line 399 of file gRwghtNCorrelatedParams.cxx.

400 {
401  LOG("grwghtnp", pINFO) << "*** Parsing command line arguments";
402 
403  CmdLnArgParser parser(argc,argv);
404 
405  // get GENIE event sample
406  if( parser.OptionExists('f') ) {
407  LOG("grwghtnp", pINFO) << "Reading event sample filename";
408  gOptInpFilename = parser.ArgAsString('f');
409  } else {
410  LOG("grwghtnp", pFATAL)
411  << "Unspecified input filename - Exiting";
412  PrintSyntax();
413  exit(1);
414  }
415 
416  // get ROOT covariance matrix binary file
417  if( parser.OptionExists('c') ) {
418  LOG("grwghtnp", pINFO) << "Reading covariance matrix filename";
419  gOptInpCovariance = parser.ArgAsString('c');
420  } else {
421  LOG("grwghtnp", pFATAL)
422  << "Unspecified covariance filename - Exiting";
423  PrintSyntax();
424  exit(1);
425  }
426 
427  // output weight file
428  if(parser.OptionExists('o')) {
429  LOG("grwghtnp", pINFO) << "Reading requested output filename";
430  gOptOutFilename = parser.ArgAsString('o');
431  } else {
432  LOG("grwghtnp", pINFO) << "Setting default output filename";
433  gOptOutFilename = "rwt_cov.root";
434  }
435 
436  if ( parser.OptionExists('n') ) {
437  //
438  LOG("grwghtnp", pINFO) << "Reading number of events to analyze";
439  string nev = parser.ArgAsString('n');
440  if (nev.find(",") != string::npos) {
441  vector<long> vecn = parser.ArgAsLongTokens('n',",");
442  if(vecn.size()!=2) {
443  LOG("grwghtnp", pFATAL) << "Invalid syntax";
444  gAbortingInErr = true;
445  PrintSyntax();
446  exit(1);
447  }
448  // User specified a comma-separated set of values n1,n2.
449  // Use [n1,n2] as the event range to process.
450  gOptNEvt1 = vecn[0];
451  gOptNEvt2 = vecn[1];
452  } else {
453  // User specified a single number n.
454  // Use [0,n] as the event range to process.
455  gOptNEvt1 = -1;
456  gOptNEvt2 = parser.ArgAsLong('n');
457  }
458  } else {
459  LOG("grwghtnp", pINFO)
460  << "Unspecified number of events to analyze - Use all";
461  gOptNEvt1 = -1;
462  gOptNEvt2 = -1;
463  }
464  LOG("grwghtnp", pDEBUG)
465  << "Input event range: " << gOptNEvt1 << ", " << gOptNEvt2;
466 
467  // systematics:
468  if( parser.OptionExists('s') ) {
469  LOG("grwghtnp", pINFO) << "Reading systematics";
470  string insyst = parser.ArgAsString('s');
471  vector<string> lsyst = utils::str::Split(insyst, ",");
473  int ik = 0;
474  for(it=lsyst.begin();it != lsyst.end();it++,ik++)
475  {
476  gOptVSyst.push_back(GSyst::FromString(*it));
477  LOG("grwghtnp",pINFO)<<"Read systematic "<<ik+1<<" : "<< lsyst[ik];
478  }
479  // split into strings of systematics
480  gOptNSyst = gOptVSyst.size();
481  LOG("grwghtnp", pINFO) << "Number of systematics : " << gOptNSyst;
482  } else {
483  LOG("rwghtcov", pFATAL)
484  << "Unspecified systematics - Exiting";
485  PrintSyntax();
486  exit(1);
487  }
488 
489  // systematic central values:
490  if( parser.OptionExists('v') ) {
491  LOG("grwghtnp", pINFO) << "Reading parameter central values";
492  gOptVCentVal = parser.ArgAsDoubleTokens('v',",");
493  // check size
494  if (gOptNSyst != (int)gOptVCentVal.size()) {
495  LOG("rwghtcov", pFATAL)
496  << "Number of systematic central values does not match number of systematics- Exiting";
497  PrintSyntax();
498  exit(1);
499  }
500  } else {
501  LOG("rwghtcov", pFATAL)
502  << "Unspecified systematic central values - Exiting";
503  PrintSyntax();
504  exit(1);
505  }
506 
507  // number of tweaks:
508  if( parser.OptionExists('t') ) {
509  LOG("grwghtnp", pINFO) << "Reading number of tweaks";
510  gOptNTwk = parser.ArgAsInt('t');
511 
512  if( gOptNTwk < 1 )
513  {
514  LOG("grwghtnp", pFATAL) << "Must have at least 1 tweak - Exiting";
515  PrintSyntax();
516  exit(1);
517  }
518  LOG("grwghtnp",pINFO)<<"Number of tweaks : "<< gOptNTwk;
519  } else {
520  LOG("grwghtnp", pFATAL)
521  << "Unspecified tweaks for parameters - Exiting";
522  PrintSyntax();
523  exit(1);
524  }
525 
526  // run key:
527  if( parser.OptionExists('r') ) {
528  LOG("grwghtnp", pINFO) << "Reading run key";
529  gOptRunKey = parser.ArgAsInt('r');
530 
531  LOG("grwghtnp", pINFO)
532  << "Run key set to " <<gOptRunKey;
533  }
534 
535 }
Long64_t gOptNEvt2
Resonance_t FromString(const char *res)
string -> resonance id
vector< GSyst_t > gOptVSyst
string gOptOutFilename
intermediate_table::iterator iterator
string gOptInpFilename
#define pFATAL
Definition: Messenger.h:47
Long64_t gOptNEvt1
vector< double > gOptVCentVal
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87
#define pINFO
Definition: Messenger.h:53
string gOptInpCovariance
void PrintSyntax()
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:42
Command line argument parser.
bool gAbortingInErr
Definition: Messenger.cxx:56
#define pDEBUG
Definition: Messenger.h:54
void GetCorrelationMatrix ( string  fname,
TMatrixD *&  cmat 
)

Definition at line 567 of file gRwghtNCorrelatedParams.cxx.

568 {
569  //
570  // Loads a ROOT file containing only a TMatrixD
571  // Reads a covariance/correlation matrix and returns correlation matrix
572  //
573 
574  // Load covariance matrix diagonal into uncertainties
575  GSystUncertainty * unc = GSystUncertainty::Instance();
578 
579  // open file and prepare for loading
580  TFile * fin = new TFile(fname.c_str(),"READ");
581  TKey * fkey;
582  TMatrixD * inmat = new TMatrixD();
583  if(cmat) { delete cmat; }
584 
585  // read covariance into cmat and return
586  TIter next(fin->GetListOfKeys());
587  fkey = (TKey *)next();
588  fkey->Read(inmat);
589 
590  // checks
591  fin->Close();
592  if (!inmat) {
593  LOG("grwghtnp", pFATAL) << "Error reading covariance matrix - Exiting";
594  gAbortingInErr = true;
595  exit(1);
596  }
597  if (inmat->GetNrows() != inmat->GetNcols()) {
598  LOG("grwghtnp", pFATAL) << "Covariance matrix not square - Exiting";
599  gAbortingInErr = true;
600  exit(1);
601  }
602  if (inmat->GetNrows() != gOptNSyst ){
603  LOG("grwghtnp", pFATAL) << "Number of systematics does not match covariance matrix size- Exiting";
604  gAbortingInErr = true;
605  exit(1);
606  }
607 
608  // Convert covariance to correlation
609  TMatrixD tmpmat = TMatrixD(*inmat);
610 
611  // Diag = Diag(Cov)
612  // set off-diagonals to zero and take 1/square root of diagonals
613  // is there an easier way?
614  int i=0;
615  itd = gOptVCentVal.begin();
616  for (it = gOptVSyst.begin();it != gOptVSyst.end(); it++, itd++, i++) {
617  for(int j=0;j<tmpmat.GetNcols();j++){
618  if(i!=j) { tmpmat(i,j) = 0.; }
619  else {
620  // convert diagonal entries to uncertainty
621  //LOG("grwghtnp", pINFO) <<"Setting uncertainty "<<i<<" to : "<<
622  // TMath::Sqrt(tmpmat(i,i))/(*itd);
623  unc->SetUncertainty(*it,TMath::Sqrt(tmpmat(i,i))/(*itd),
624  TMath::Sqrt(tmpmat(i,i))/(*itd));
625  tmpmat(i,i) = 1./TMath::Sqrt(tmpmat(i,i));
626  }
627  }
628  }
629  //LOG("grwghtnp", pWARN) <<"diagonal scaling matrix:";
630  //tmpmat.Print();
631 
632  // Cor = Diag^(-1/2).Cov.Diag^(-1/2)
633  TMatrixD sigmat = TMatrixD(tmpmat);
634  tmpmat = TMatrixD(*inmat,TMatrixD::kMult,sigmat);
635  cmat = new TMatrixD(sigmat,TMatrixD::kMult,tmpmat);
636 
637  delete inmat;
638  return;
639 }
vector< GSyst_t > gOptVSyst
intermediate_table::iterator iterator
#define pFATAL
Definition: Messenger.h:47
vector< double > gOptVCentVal
void SetUncertainty(GSyst_t syst, double plus_err, double minus_err)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87
bool gAbortingInErr
Definition: Messenger.cxx:56
void GetEventRange ( Long64_t  nev_in_file,
Long64_t &  nfirst,
Long64_t &  nlast 
)

Definition at line 537 of file gRwghtNCorrelatedParams.cxx.

538 {
539  nfirst = 0;
540  nlast = 0;
541 
542  if(gOptNEvt1>=0 && gOptNEvt2>=0) {
543  // Input was `-n N1,N2'.
544  // Process events [N1,N2].
545  // Note: Incuding N1 and N2.
546  nfirst = gOptNEvt1;
547  nlast = TMath::Min(nev_in_file-1, gOptNEvt2);
548  }
549  else
550  if(gOptNEvt1<0 && gOptNEvt2>=0) {
551  // Input was `-n N'.
552  // Process first N events [0,N).
553  // Note: Event N is not included.
554  nfirst = 0;
555  nlast = TMath::Min(nev_in_file-1, gOptNEvt2-1);
556  }
557  else
558  if(gOptNEvt1<0 && gOptNEvt2<0) {
559  // No input. Process all events.
560  nfirst = 0;
561  nlast = nev_in_file-1;
562  }
563 
564  assert(nfirst <= nlast && nfirst >= 0 && nlast <= nev_in_file-1);
565 }
Long64_t gOptNEvt2
Long64_t gOptNEvt1
int main ( int  argc,
char **  argv 
)

Definition at line 135 of file gRwghtNCorrelatedParams.cxx.

136 {
137  GetCommandLineArgs (argc, argv);
138 
139  // open the ROOT file and get the TTree & its header
140  TTree * tree = 0;
141  NtpMCTreeHeader * thdr = 0;
142  TFile file(gOptInpFilename.c_str(),"READ");
143  tree = dynamic_cast <TTree *> ( file.Get("gtree") );
144  thdr = dynamic_cast <NtpMCTreeHeader *> ( file.Get("header") );
145  if(!tree){
146  LOG("grwghtnp", pFATAL)
147  << "Can't find a GHEP tree in input file: "<< file.GetName();
148  gAbortingInErr = true;
149  PrintSyntax();
150  exit(1);
151  }
152  LOG("grwghtnp", pNOTICE) << "Input tree header: " << *thdr;
154  {
155  LOG("grwghtnp", pFATAL) << "Error: conflicting systematics";
156  gAbortingInErr = true;
157  exit(1);
158  }
159 
160  //
161  // Preparation for finding correlated vectors
162  //
163  // Solutions are subject to constraint of an error ellipse with equation:
164  // 1 = x^T.Cor^-1.x
165  // x is a vector of tweaks to apply to the systematics
166  // Cholesky Decomposition solves for U in equation:
167  // Cor^-1 = U^T.U
168  // LU decomposition used to solve for x:
169  // L.U.x = b
170  // where L=I and b is a vector of random numbers with b^T.b = 1
171  //
172 
173  TMatrixD *cmat = NULL;
174  // Gets Cor, which is needed in decompositions
175  // Assumed errors from covariance are stored in one sigma errors for parameters
177  TMatrixD lTri = CholeskyDecomposition(*cmat);
178 
179  //LOG("grwghtnp", pNOTICE) << "Correlation matrix:";
180  //cmat->Print();
181  //LOG("grwghtnp", pNOTICE) << "Lower triangular matrix:";
182  //lTri.Print();
183 
184  NtpMCEventRecord * mcrec = 0;
185  tree->SetBranchAddress("gmcrec", &mcrec);
186 
187  Long64_t nev_in_file = tree->GetEntries();
188  Long64_t nfirst = 0;
189  Long64_t nlast = 0;
190  GetEventRange(nev_in_file, nfirst, nlast);
191  int nev = int(nlast - nfirst + 1);
192 
193  LOG("grwghtnp", pNOTICE) << "Will process " << nev << " events";
194 
195  //
196  // Create a GReWeight object and add to it a set of
197  // weight calculators
198  //
199  // If seg-faulting here, probably need to change
200  // models in UserPhysicsOptions.xml and other config files
201  //
202 
203  GReWeight rw;
205 
206  //
207  // Create a list of systematic params (more to be found at GSyst.h)
208  // set non-default values and re-configure.
209  // Weight calculators included above must be able to handle the tweaked params.
210  // Each tweaking dial t modifies a physics parameter p as:
211  // p_{tweaked} = p_{default} ( 1 + t * dp/p )
212  // So setting a tweaking dial to +/-1 modifies a physics quantity
213  // by +/- 1sigma.
214  // Default fractional errors are defined in GSystUncertainty
215  // and can be overriden.
216  //
217 
218  GSystSet & syst = rw.Systematics();
219 
220  // Declare the weights, twkvals
221  const int n_params = (const int) gOptNSyst;
222  const int n_tweaks = (const int) gOptNTwk;
223  TVectorD twkvals(n_params);
224 
225  // Initialize
226  for (int ipr = 0; ipr < n_params; ipr++) { twkvals(ipr) = 0.; }
227 
228  // objects to pass elements into tree
229  int branch_eventnum = 0;
230  double branch_weight = 0.;
231 
232  // objects used in processing
234  stringstream twk_dial_brnch_name;
235  stringstream tmpName;
236  int ip;
237 
238  //
239  // REWEIGHTING LOOP
240  // -- do all of reweighting, save to temporary files
241  //
242  TFile * wght_file = NULL;
243  TTree * wght_tree = NULL;
244  for (int itk = 0; itk < gOptNTwk; itk++) {
245  // Make temporary output trees for saving the weights.
246  // This step is necessary because ROOT trees cannot be edited once filled
247  // Later consolidate the trees into a single tree with the requested filename
248  tmpName.str("");
249  tmpName << "_temporary_rwght." <<itk <<"." <<gOptRunKey <<".root";
250  LOG("grwghtnp", pINFO) <<"temporary file: " <<tmpName.str();
251  wght_file = new TFile(tmpName.str().c_str(),"RECREATE");
252  wght_tree = new TTree("covrwt","GENIE weights tree");
253 
254  // Create tree branches
255  wght_tree->Branch("eventnum", &branch_eventnum);
256  wght_tree->Branch("weights", &branch_weight);
257 
258  // Construct multiple branches to streamline loading later
259  // Load tweaks into reweighting
261  // scale the size of the vector to avg length 1
262  //twkvals *= 1./(TMath::Sqrt((double)gOptNSyst));
263  ip = 0;
264  for (it = gOptVSyst.begin();it != gOptVSyst.end(); it++, ip++) {
265  twk_dial_brnch_name.str("");
266  twk_dial_brnch_name << "twk_" << GSyst::AsString(*it);
267  // each array element individually
268  wght_tree->Branch(twk_dial_brnch_name.str().c_str(), &twkvals(ip));
269  //LOG("grwghtnp", pINFO) << "Setting systematic : "
270  // <<GSyst::AsString(*it) <<", " <<twkvals(ip);
271  syst.Set(*it,twkvals(ip));
272  }
273  rw.Reconfigure();
274 
275  stringstream str_wght;
276  str_wght.str("");
277  str_wght << ", parameter tweaks : ";
278  for (int ipr=0; ipr < n_params; ipr++) {
279  if (ipr > 0) str_wght << ", ";
280  str_wght << ipr << " -> " << twkvals(ipr);
281  }
282 
283  for(int iev = nfirst; iev <= nlast; iev++) {
284  branch_eventnum = iev;
285  tree->GetEntry(iev);
286 
287  EventRecord & event = *(mcrec->event);
288  LOG("rwghtzexpaxff", pNOTICE) << "Event_num => " << iev;
289  //LOG("rwghtzexpaxff", pNOTICE) << event;
290 
291  branch_weight = rw.CalcWeight(event);
292  mcrec->Clear();
293  wght_tree->Fill();
294 
295  } // event loop
296 
297  // close out temporary file
298  wght_file->cd();
299  wght_tree->Write();
300  wght_file->Close();
301  //delete wght_tree; // segfault when deleted
302  wght_tree = 0;
303  delete wght_file;
304  } // tweak loop
305 
306  // Close event file
307  file.Close();
308 
309  // open temporary trees for consolidation
310  LOG("rwghtzexpaxff", pNOTICE)
311  << "Consolidating temporary files into ROOT file " << gOptOutFilename;
312  wght_file = new TFile(gOptOutFilename.c_str(),"RECREATE"); // new file
313  wght_tree = new TTree("covrwt","GENIE covariant reweighting tree");
314  wght_tree->Branch("n_tweaks", &gOptNTwk);
315  wght_tree->Branch("eventnum", &branch_eventnum);
316  TFile * file_list[n_tweaks];
317  TTree * wght_list[n_tweaks];
318  for (int itk=0; itk < n_tweaks; itk++) {
319  tmpName.str("");
320  tmpName << "_temporary_rwght." <<itk <<"." <<gOptRunKey <<".root";
321  file_list[itk] = new TFile(tmpName.str().c_str(),"READ");
322  wght_list[itk] = (TTree*)file_list[itk]->Get("covrwt");
323  }
324 
325  // objects to load data into and fill new tree with
326  TArrayD branch_weights_array(gOptNTwk);
327  double * branch_weights_ptr = branch_weights_array.GetArray();
328  TArrayD * branch_twkdials_array[n_params];
329  double * branch_twkdials_ptr [n_params];
330 
331  // set up streamlined weight loading
332  wght_tree->Branch("weights", &branch_weights_array);
333  for (int itk = 0; itk < gOptNTwk; itk++) {
334  wght_list[itk]->SetBranchAddress("weights",&branch_weights_ptr[itk]);
335  }
336 
337  ip = 0;
338  for (it = gOptVSyst.begin();it != gOptVSyst.end(); it++, ip++) {
339  twk_dial_brnch_name.str("");
340  twk_dial_brnch_name << "twk_" << GSyst::AsString(*it);
341 
342  // access TArrayD memory directly
343  branch_twkdials_array[ip] = new TArrayD(gOptNTwk);
344  branch_twkdials_ptr[ip] = branch_twkdials_array[ip]->GetArray();
345 
346  // create branch
347  wght_tree->Branch(twk_dial_brnch_name.str().c_str(), branch_twkdials_array[ip]);
348  LOG("grwghtnp", pINFO) << "Creating tweak branch : " << twk_dial_brnch_name.str();
349 
350  // set up loading directly into TArrayD
351  for (int i=0; i < n_tweaks; i++) {
352  wght_list[i]->SetBranchAddress(twk_dial_brnch_name.str().c_str(),&branch_twkdials_ptr[ip][i]);
353  //LOG("grwghtnp", pINFO) << "Loading tweak value : "<<branch_twkdials_array[ip]->fArray[i];
354  }
355  }
356 
357  //
358  // CONSOLIDATION LOOP
359  // -- combine all data from reweighting into single file
360  //
361  wght_file->cd();
362  for(int iev = nfirst; iev <= nlast; iev++) {
363  branch_eventnum = iev;
364  for (int itk = 0; itk < n_tweaks; itk++) {
365  wght_list[itk]->GetEntry(iev);
366  } // tweak loop
367  wght_tree->Fill();
368  } // event loop
369  wght_file->cd();
370  wght_tree->Write();
371 
372  //
373  // CLEANUP LOOP
374  //
375 
376  // delete temporary files
377  for (int itk = 0; itk < gOptNTwk; itk++) {
378  tmpName.str("");
379  tmpName << "_temporary_rwght." <<itk <<"." <<gOptRunKey <<".root";
380  if( remove(tmpName.str().c_str()) != 0 )
381  { LOG("grwghtnp", pWARN) << "Could not delete temporary file : " << tmpName.str(); }
382  //else
383  //{ LOG("grwghtnp", pINFO) << "Deleted temporary file : " << tmpName.str(); }
384  }
385 
386  // free memory
387  wght_file->Close();
388  //delete wght_tree;
389  wght_tree = 0;
390  delete wght_file;
391  for (int ipr = 0; ipr < n_params; ipr++) {
392  delete branch_twkdials_array[ipr];
393  }
394 
395  LOG("grwghtnp", pNOTICE) << "Done!";
396  return 0;
397 }
vector< GSyst_t > gOptVSyst
string gOptOutFilename
intermediate_table::iterator iterator
MINOS-style ntuple record. Each such ntuple record holds a generated EventRecord object. Ntuples of this type are intended for feeding GENIE events into other applications (for example the GEANT4 based MC generation framework of an experiment) if no direct interface exists.
string gOptInpFilename
#define pFATAL
Definition: Messenger.h:47
std::string AsString(TrkPoint_t trkpt)
void Reconfigure(void)
reconfigure weight calculators with new params
Definition: GReWeight.cxx:74
TMatrixD CholeskyDecomposition(const TMatrixD &cov)
Definition: MathUtils.cxx:27
void Set(GSyst_t syst, double current_value)
Definition: GSystSet.cxx:89
void GetEventRange(Long64_t nev_in_file, Long64_t &nfirst, Long64_t &nlast)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87
MINOS-style Ntuple Class to hold an output MC Tree Header.
#define pINFO
Definition: Messenger.h:53
#define pWARN
Definition: Messenger.h:51
string gOptInpCovariance
void PrintSyntax()
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
bool FindIncompatibleSystematics(vector< GSyst_t > lsyst)
void GetCorrelationMatrix(string fname, TMatrixD *&cmat)
double CalcWeight(const genie::EventRecord &event)
calculate weight for input event
Definition: GReWeight.cxx:99
TVectorD CholeskyGenerateCorrelatedParamVariations(const TMatrixD &Lch)
Definition: MathUtils.cxx:172
#define pNOTICE
Definition: Messenger.h:52
GSystSet & Systematics(void)
set of enabled systematic params & values
Definition: GReWeight.cxx:69
void Clear(Option_t *opt="")
bool gAbortingInErr
Definition: Messenger.cxx:56
Set of systematics to be considered by the reweighting package.
Definition: GSystSet.h:37
Interface to the GENIE event reweighting engines.
Definition: GReWeight.h:40
EventRecord * event
event
Event finding and building.
void AdoptWeightCalcs(vector< GSyst_t > lsyst, GReWeight &rw)
void GetCommandLineArgs(int argc, char **argv)
void PrintSyntax ( void  )

Definition at line 875 of file gRwghtNCorrelatedParams.cxx.

876 {
877  LOG("grwghtnp", pFATAL)
878  << "\n\n"
879  << "grwghtnp \n"
880  << " -f input_event_file \n"
881  << " -c input_covariance_file\n"
882  << " -t num_twk \n"
883  << " -s syst1[,syst2[,...]] \n"
884  << " -v cval1[,cval2[,...]] \n"
885  << " [-n n1[,n2]] \n"
886  << " [-r run_key] \n"
887  << " [-o output_weights_file]";
888 }
#define pFATAL
Definition: Messenger.h:47
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87

Variable Documentation

string gOptInpCovariance

Definition at line 125 of file gRwghtNCorrelatedParams.cxx.

string gOptInpFilename

Definition at line 124 of file gRwghtNCorrelatedParams.cxx.

Long64_t gOptNEvt1

Definition at line 127 of file gRwghtNCorrelatedParams.cxx.

Long64_t gOptNEvt2

Definition at line 128 of file gRwghtNCorrelatedParams.cxx.

int gOptNSyst = 0

Definition at line 130 of file gRwghtNCorrelatedParams.cxx.

int gOptNTwk = 0

Definition at line 131 of file gRwghtNCorrelatedParams.cxx.

string gOptOutFilename

Definition at line 126 of file gRwghtNCorrelatedParams.cxx.

int gOptRunKey = 0

Definition at line 129 of file gRwghtNCorrelatedParams.cxx.

vector<double> gOptVCentVal

Definition at line 123 of file gRwghtNCorrelatedParams.cxx.

vector<GSyst_t> gOptVSyst

Definition at line 122 of file gRwghtNCorrelatedParams.cxx.

TRandom* tRnd = new TRandom()

Definition at line 132 of file gRwghtNCorrelatedParams.cxx.