1 #include "SIPionSystematics.hxx" 2 #include "ND280AnalysisUtils.hxx" 3 #include "MultiThread.hxx" 12 char inputFileName[256];
13 #define JMDEBUGFIXMATERIAL 1 14 #if JMDEBUGFIXMATERIAL == 0 15 sprintf(inputFileName,
"%s/data/SIPionXsec.dat",getenv(
"PSYCHESYSTEMATICSROOT"));
17 sprintf(inputFileName,
"%s/data/SIPionXsecFixG10.dat",getenv(
"PSYCHESYSTEMATICSROOT"));
27 _pionWeightInfo = NULL;
28 _pionSIManager = NULL;
38 if (_initialized)
return;
48 SIPionSystematics::~SIPionSystematics(){
51 std::map<Int_t, std::pair<TGraphErrors*,TGraph*> > xsecs = PiXSec::AllXSecs;
52 std::map<Int_t, std::pair<TGraphErrors*,TGraph*> >::iterator it;
54 for (it = xsecs.begin(); it != xsecs.end(); it++) {
55 delete it->second.first;
56 delete it->second.second;
60 delete _pionSIManager;
62 _pionSIManager = NULL;
76 uniqueID =
event.UniqueID;
85 std::cout <<
"nPions = " << pionSI.nPions << std::endl;
89 if(pionSI.nPions == 0)
return eventWeight;
92 eventWeight.Correction = pionSI.weightMCToData ;
94 if (!TMath::Finite(eventWeight.Correction) || eventWeight.Correction != eventWeight.Correction){
99 Float_t nC = 4.6487939E22;
103 Float_t weightExp[3] = {0,0,0};
105 int stepsConsidered = 0;
108 Float_t siUncWeight[3] = {1,1,1};
111 for(
int ns = 0; ns < pionSI.nPions; ns++){
117 std::cout <<
"nSteps = " << pionSI.nSteps[ns] << std::endl;
121 for(
unsigned int ts = stepsConsidered; ts < (
unsigned int)(stepsConsidered + pionSI.nSteps[ns]); ts++){
124 std::cout <<
"ts = " << ts << std::endl;
127 if (ts >= 128)
break;
131 Float_t pStep = pionSI.initMom[ns] - 10.0*((Float_t)(ts - stepsConsidered));
133 std::cout <<
"pStep = " << pStep << std::endl;
138 int unsigned momBin = (int)((pStep*0.1) + 0.5);
140 std::cout <<
"momBin = " << momBin << std::endl;
144 if (momBin > NMAXMOMBINS-1) momBin = NMAXMOMBINS-1;
166 if(pionSI.pionType[ns] != 1) pim_offset = 100;
168 for (Int_t mech=0;mech<3;mech++){
173 weightExp[mech] += (std::max((Float_t)(_xsec_data[_interactionID[mech]+pim_offset][momBin] + _err_data[_interactionID[mech]+pim_offset][momBin] *
175 - ( _xsec_data[_interactionID[mech]+pim_offset][momBin]))*(1E-27)*(0.1)*pionSI.stepLengths[ts];
179 std::cout << _xsec_data[4+pim_offset][momBin] <<
" " << _err_data[4+pim_offset][momBin] <<
" " << pionSI.stepLengths[ts] << std::endl;
180 std::cout <<
"weightExp = " << weightExp[0] <<
" " << weightExp[1] <<
" " << weightExp[2] << std::endl;
186 stepsConsidered += pionSI.nSteps[ns];
192 for (
int mech=0;mech<3;mech++)
193 siUncWeight[mech] = exp(-nC*weightExp[mech]);
197 for(
int ii = 0; ii < pionSI.nInteractions; ii++){
203 unsigned int momBin = (int)((pionSI.pInteraction[ii]*0.1) + 0.5);
208 if (momBin > NMAXMOMBINS) momBin = NMAXMOMBINS;
210 int intType = pionSI.typeInteraction[ii];
222 if(_xsec_data[intType][momBin] != 0.0){
224 if (intType%10 == _interactionID[0]) mech = 0;
225 else if (intType%10 == _interactionID[1]) mech = 1;
226 else if (intType%10 == _interactionID[2]) mech = 2;
231 siUncWeight[mech] *= (std::max((Float_t)(_xsec_data[intType][momBin]
233 /_xsec_data[intType][momBin]);
240 Float_t siUncWeightTotal=1.;
241 for (
int mech=0;mech<3;mech++){
242 siUncWeightTotal*=siUncWeight[mech];
246 eventWeight.Systematic = eventWeight.Correction * siUncWeightTotal;
248 if (!TMath::Finite(eventWeight.Systematic) || eventWeight.Systematic != eventWeight.Systematic){
251 std::cout <<
event.EventInfo.Event <<
" " <<
event.EventInfo.SubRun <<
" " <<
event.EventInfo.Run <<
" " << pionSI.nPions <<
" " << pionSI.nInteractions <<
" " << eventWeight << std::endl;
253 for (
int mech=0;mech<3;mech++)
257 eventWeight.Systematic = eventWeight.Correction;
278 _pionWeightInfo[uniqueID] = _pionSIManager->ComputePionWeightInfo(event, sel, ibranch);
293 if (_pionWeightInfo)
return;
300 for (Int_t k= 0;k<nevents;k++)
301 _pionWeightInfo[k]=NULL;
316 uniqueID =
event.UniqueID;
319 if (_pionWeightInfo[uniqueID])
320 delete _pionWeightInfo[uniqueID];
321 _pionWeightInfo[uniqueID]=NULL;
Int_t _index
The index of this systematic (needed by SystematicsManager);.
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
void SetNParameters(int N)
Set the number of systematic parameters associated to this systematic.
virtual void Initialize(Int_t nsel, Int_t isel, Int_t nbranch, Int_t nevents)
Create the array of SystBox.
virtual void FinalizeEvent(const AnaEventC &event)
Delete the SystBox for this event.
Weight_h ComputeWeight(const ToyExperiment &, const AnaEventC &, const ToyBoxB &)
Apply the systematic.
Int_t UniqueID
The event unique ID.
Int_t SuccessfulBranch
The branch that is successful for this toy in the selection this ToyBox belongs to.
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
void FinalizeEvent(const AnaEventC &event)
Delete the PionInteractionSystematic for this event.
virtual void Initialize()
Initilaize the systematics itself, basically the manager.
virtual bool IsRelevantTrueObjectForSystematicInToy(const AnaEventC &, const ToyBoxB &, AnaTrueObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this true track relevant for a given systematic (after selection, called for each toy) ...
void LoadPionCrossSections(char *inputFileName, Float_t(&xsec_array)[nIntBins][nMomBins], Float_t(&err_array)[nIntBins][nMomBins])
Method to load external ipon cross section data into arrays.
void FillSystBox(const AnaEventC &event, const SelectionBase &sel, Int_t ibranch)
Fill the SystBox for this event, selection and branch.
Int_t GetNBins()
Get the number of bins.