1 #include "SIProtonSystematics.hxx" 2 #include "ND280AnalysisUtils.hxx" 3 #include "MultiThread.hxx" 17 _ProtonInteractionsInfo = NULL;
21 SIProtonSystematics::~SIProtonSystematics(){
24 if (_ProtonInteractionsInfo){
25 for (Int_t k= 0; k<_nevents; k++){
26 if(_ProtonInteractionsInfo[k])
27 delete _ProtonInteractionsInfo[k];
28 _ProtonInteractionsInfo[k] =NULL;
32 delete [] _ProtonInteractionsInfo;
45 Float_t eventWeight = 1.;
47 Float_t totalReWeight = 1.;
52 uniqueID =
event.UniqueID;
61 std::cout <<
" ===== " << std::endl;
62 std::cout <<
" SIProtonSystematics::Apply" << std::endl;
63 std::cout <<
"nProtons = " << protonSI.nParticles << std::endl;
67 if (protonSI.nParticles == 0)
return eventWeight;
70 for (
int i = 0; i < protonSI.nParticles; i++){
74 Float_t survWeight_tmp = 0.;
77 Float_t intWeight_tmp = 1.;
84 std::cout <<
" Not relevant object " << std::endl;
94 size_t nSteps = protonSI.Particles[i].
propSteps.size();
97 std::cout <<
"nSteps = " << nSteps << std::endl;
100 for (
size_t ns = 0; ns < nSteps; ns++){
102 size_t nInts = protonSI.Particles[i].
propSteps[ns].size();
103 for (
size_t nint = 0; nint < nInts; nint++){
106 Float_t xsec_tmp = protonSI.Particles[i].
propSteps[ns][nint].XSec +
108 survWeight_tmp += std::max<Double_t>(xsec_tmp, 0.) -
109 protonSI.Particles[i].
propSteps[ns][nint].XSec;
117 intWeight_tmp *= 1 + protonSI.Particles[i].
XSecData.XSecErr * var;
119 totalReWeight *= protonSI.Particles[i].
Weight;
122 std::cout <<
" ===== Particle weight ===== " << std::endl;
123 std::cout <<
"survWeight \t= " << survWeight_tmp << std::endl;
124 std::cout <<
"exp(-survWeight) \t= " << exp(-survWeight_tmp) << std::endl;
125 std::cout <<
"intWeight \t= " << intWeight_tmp << std::endl;
126 std::cout <<
"ReWeight \t= " << protonSI.Particles[i].
Weight << std::endl;
127 std::cout <<
" ========== " << std::endl;
130 Float_t factor = exp(-survWeight_tmp) * intWeight_tmp;
131 if (factor == 0 || !TMath::Finite(factor) || factor != factor)
134 eventWeight *= factor;
139 std::cout <<
" ===== Total weight ===== " << std::endl;
140 std::cout <<
" eventWeight \t= " << eventWeight << std::endl;
141 std::cout <<
" totalReWeight \t= " << totalReWeight << std::endl;
142 std::cout <<
" ========== " << std::endl;
147 if (eventWeight == 0 || !TMath::Finite(eventWeight) || eventWeight != eventWeight)
151 std::cout <<
" eventWeight \t= " << eventWeight << std::endl;
152 std::cout <<
" totalReWeight \t= " << totalReWeight << std::endl;
153 std::cout <<
" finalWeightt \t= " << totalReWeight * eventWeight << std::endl;
154 std::cout <<
" ===== " << std::endl;
158 eventWeightFinal.Correction = totalReWeight;
159 eventWeightFinal.Systematic = totalReWeight * eventWeight;
162 return eventWeightFinal;
182 if((UInt_t)count > NMAXTRUEPARTICLES) count = NMAXTRUEPARTICLES;
187 _ProtonInteractionsInfo[uniqueID] = _pInfoManager.CollectParticleInteractions(allTrajInBunch, count,
188 static_cast<SubDetId::SubDetEnum>(sel.
GetDetectorFV(ibranch)));
202 if (_ProtonInteractionsInfo)
return;
210 for (Int_t k = 0; k < nevents; k++)
211 _ProtonInteractionsInfo[k] = NULL;
227 uniqueID =
event.UniqueID;
230 if (_ProtonInteractionsInfo[uniqueID])
231 delete _ProtonInteractionsInfo[uniqueID];
232 _ProtonInteractionsInfo[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 FillSystBox(const AnaEventC &event, const SelectionBase &sel, Int_t ibranch)
Fill the SystBox for this event, selection and branch.
void FinalizeEvent(const AnaEventC &event)
Delete the ProtonInteractionSystematic for this event.
void Initialize(Int_t nsel, Int_t isel, Int_t nbranch, Int_t nevents)
Create the array of ProtonInteractionSystematic.
int GetAllTrajInBunch(const AnaEventB &event, AnaTrueParticleB *traj[])
void SetNParameters(int N)
Set the number of systematic parameters associated to this systematic.
si_syst::SIXSecData XSecData
Store both the cross-section and error.
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.
Representation of a true Monte Carlo trajectory/particle.
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.
Float_t Weight
Weight for this particle, to be applied to correspond to a reference cross-section.
const AnaTrueParticleB * trueTrack
A pointer to the original true track.
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
std::vector< StepInfo > propSteps
Vector of steps considered with the corresponding info.
bool GetParametersForBin(Int_t index, Float_t &mean, Float_t &sigma)
Gets the bin values for a source provided the bin index.
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) ...
Weight_h ComputeWeight(const ToyExperiment &, const AnaEventC &, const ToyBoxB &)
Apply the systematic.
Int_t GetNBins()
Get the number of bins.
SubDetId_h GetDetectorFV(Int_t ibranch=0) const
Get the detector in which the Fiducial Volume is defined.