1 #include "ChargeIDEffSystematics.hxx" 2 #include "ND280AnalysisUtils.hxx" 3 #include "CutUtils.hxx" 4 #include "SystematicUtils.hxx" 5 #include "VersioningUtils.hxx" 6 #include "MultiThread.hxx" 8 #include "EventBoxId.hxx" 9 #include "Parameters.hxx" 13 ChargeIDEffSystematics::ChargeIDEffSystematics(
bool comp):
EventWeightBase(2){
15 _computecounters=comp;
17 _globalCharge =
new BinnedParams(
"globChargeIDEff", BinnedParams::k2D_EFF_SYMMETRIC, versionUtils::Extension());
19 _localCharge =
new BinnedParams(
"localChargeIDEff",BinnedParams::k2D_EFF_SYMMETRIC, versionUtils::Extension());
23 int nbins= _globalCharge->GetNBins()/5.+_localCharge->GetNBins()/4;
24 if(versionUtils::prod6_systematics)
29 _globalCharge->InitializeEfficiencyCounter();
31 _full_correlations = ND::params().
GetParameterI(
"psycheSystematics.Tracker.FullCorrelations");
41 _globalCharge->InitializeEfficiencyCounter();
60 if (!cutUtils::TrackQualityCut(*track))
continue;
70 if (nTPCSegments==0)
continue;
74 if (!tpcTrack1orig)
continue;
81 Float_t momMAX = tpcTrack1->
Momentum;
82 Float_t momorig = tpcTrack1orig->
Momentum;
83 Float_t momMAXorig = tpcTrack1orig->
Momentum;
85 Int_t charge =track->
Charge;
86 Int_t locCharge =tpcTrack1->
Charge;
88 Float_t globWeight_momerr=1;
89 Float_t locWeight_momerr=1;
92 if(momerr!=momerr || !TMath::Finite(momerr) || momerr < 0.00001)
continue;
93 if(mom!=mom || !TMath::Finite(mom))
continue;
95 }
else if(nTPCSegments==2){
98 if (!tpcTrack2orig)
continue;
101 if(tmpmomerr1!=tmpmomerr1 || !TMath::Finite(tmpmomerr1) || tmpmomerr1 < 0.00001) tmpmomerr1 = 99999999;
102 if(tmpmomerr2!=tmpmomerr2 || !TMath::Finite(tmpmomerr2) || tmpmomerr2 < 0.00001) tmpmomerr2 = 99999999;
103 momerr=std::min(tmpmomerr1,tmpmomerr2);
104 if(tmpmomerr1==99999999)tmpmomerr1 = -99999999;
105 if(tmpmomerr2==99999999)tmpmomerr2 = -99999999;
106 momerrMAX=std::max(tmpmomerr1,tmpmomerr2);
108 if(momerr==99999999)
continue;
109 if(momerrMAX==-99999999)
continue;
114 locCharge =tpcTrack2->
Charge;
117 if(mom!=mom || !TMath::Finite(mom) || mom < 0.00001)
continue;
120 momMAXorig =tpcTrack2orig->
Momentum;
123 Int_t Q1=tpcTrack1->
Charge;
124 Int_t Q2=tpcTrack2->
Charge;
126 if(Q1==Q2)syst_case=1;
129 else if (nTPCSegments==3){
135 if (!tpcTrack2orig)
continue;
136 if (!tpcTrack3orig)
continue;
141 if(tmpmomerr1!=tmpmomerr1 || !TMath::Finite(tmpmomerr1) || tmpmomerr1 < 0.00001) tmpmomerr1 = 99999999;
142 if(tmpmomerr2!=tmpmomerr2 || !TMath::Finite(tmpmomerr2) || tmpmomerr2 < 0.00001) tmpmomerr2 = 99999999;
143 if(tmpmomerr3!=tmpmomerr3 || !TMath::Finite(tmpmomerr3) || tmpmomerr3 < 0.00001) tmpmomerr3 = 99999999;
144 Float_t momerr12=std::min(tmpmomerr1,tmpmomerr2);
145 momerr=std::min(momerr12,tmpmomerr3);
146 if(momerr==99999999)
continue;
149 locCharge =tpcTrack2->
Charge;
156 locCharge =tpcTrack3->
Charge;
160 if(mom!=mom || !TMath::Finite(mom) || mom < 0.00001)
continue;
161 if(tmpmomerr1==99999999)tmpmomerr1 = -99999999;
162 if(tmpmomerr2==99999999)tmpmomerr2 = -99999999;
163 if(tmpmomerr3==99999999)tmpmomerr3 = -99999999;
164 Float_t momerrMAX12=std::max(tmpmomerr1,tmpmomerr2);
165 momerrMAX=std::max(momerrMAX12,tmpmomerr3);
166 if(momerrMAX==-99999999)
continue;
169 momMAXorig =tpcTrack2orig->
Momentum;
173 momMAXorig =tpcTrack3orig->
Momentum;
177 Int_t Q1=tpcTrack1->
Charge;
178 Int_t Q2=tpcTrack2->
Charge;
179 Int_t Q3=tpcTrack3->
Charge;
180 if( Q1==Q2 && Q2==Q3) syst_case=3;
181 if((Q1!=Q2 && Q2==Q3) || (Q1!=Q3 && Q1==Q2) || (Q1!=Q2 && Q1==Q3)) syst_case=4;
185 if(versionUtils::prod6_systematics && syst_case>0){
186 if(momMAX<1 )
continue;
187 bool areEqual= (syst_case==1 || syst_case==3) ?
true :
false;
189 for(Int_t ipar=0;ipar<4;ipar++){
190 _localCharge->GetBinValues(syst_case,ipar, parloc[ipar]);
194 if(syst_case>2) index_loc=1;
195 Float_t effmc=ComputeEffFromLocalParametrization(parloc,momMAX, momerrMAX);
196 Float_t effmcorig=ComputeEffFromLocalParametrization(parloc,momMAXorig, momerrMAXOrig);
197 Float_t ww= (areEqual) ? effmc/effmcorig : (1-effmc)/(1-effmcorig);
198 if(effmcorig==0 && areEqual) ww=1;
199 if(effmcorig==1 && !areEqual) ww=1;
203 locWeight_momerr*=ww;
205 ComputeEffFromLocalParametrization(parloc,momMAX,momerrMAX,paramsloc );
209 if (_full_correlations) index_loc = 0;
211 localWeight *= systUtils::ComputeEffLikeWeight(areEqual, toy,
GetIndex(), index_loc, paramsloc);
214 if(localWeight.Correction!=0 ) eventWeight.Correction*=(localWeight.Correction);
215 if(localWeight.Systematic!=0 ) eventWeight.Systematic*=(localWeight.Systematic*locWeight_momerr);
229 if(!versionUtils::prod6_systematics){
231 if(!_globalCharge->GetBinValues(0,p0, params, index))
continue;
234 found= (trueCharge*charge>0 && trueDir*dir>0) || (trueCharge*charge<0 && trueDir*dir<0);
249 for(Int_t ipar=0;ipar<5;ipar++){
250 _globalCharge->GetBinValues(syst_case,ipar, par[ipar]);
252 found = (charge*locCharge>0);
254 Float_t effmc=ComputeEffFromGlobalLocalParametrization(par,mom, momerr);
255 Float_t effmcorig=ComputeEffFromGlobalLocalParametrization(par,momorig, momerrOrig);
256 Float_t ww= (found) ? effmc/effmcorig : (1-effmc)/(1-effmcorig);
257 if(effmcorig==0 && found) ww=1;
258 if(effmcorig==1 && !found) ww=1;
260 globWeight_momerr*=ww;
262 ComputeEffFromGlobalLocalParametrization(par,mom, momerr,params );
265 index = syst_case +_localCharge->GetNBins()/4;
269 if (_full_correlations) index = 0;
272 Weight_h globWeight = systUtils::ComputeEffLikeWeight(found, toy,
GetIndex(), index, params);
274 if(globWeight!=globWeight){
284 if(globWeight.Correction!=0 ) eventWeight.Correction*=(globWeight.Correction);
285 if(globWeight.Systematic!=0 ) eventWeight.Systematic*=(globWeight.Systematic*globWeight_momerr);
291 _globalCharge->UpdateEfficiencyCounter(index,found);
302 Float_t vvv=fabs((0.48+7.7E-4*mom)*momerr/mom);
304 Float_t var=TMath::Log(vvv);
310 if (fabs(1-ratio) > err) err = fabs(1-ratio);
311 Float_t effDATA = ratio * effMC;
312 Float_t effDATA_err= err *effMC;
338 params.sigmaDATAh=effDATA_err;
346 Float_t ChargeIDEffSystematics::ComputeEffFromGlobalLocalParametrization(
BinnedParamsParams *par,Float_t mom, Float_t momerr ){
350 vvv= fabs((0.48+7.7E-4*mom)*momerr/mom);
352 Float_t var=TMath::Log(vvv);
353 Float_t effMC = (par[0].
meanMC +par[1].
meanMC*var +par[2].
meanMC*pow(var,2) +par[3].
meanMC*pow(var,3))*(1+par[4].meanMC*pow(vvv,2));
354 Float_t eff=std::max(effMC,(Float_t)0.);
355 eff=std::min(effMC,(Float_t)1.);
365 Float_t effMC = ComputeEffFromGlobalLocalParametrization(par,mom,momerr);
370 if (fabs(1-ratio) > err) err = fabs(1-ratio);
371 Float_t effDATA = ratio * effMC;
372 Float_t effDATA_err= err *effMC;
398 params.sigmaDATAh=effDATA_err;
405 Float_t ChargeIDEffSystematics::ComputeEffFromLocalParametrization(
BinnedParamsParams *par,Float_t mom, Float_t momerr ){
411 var=fabs((0.48+7.7E-4*mom)*momerr/mom);
413 Float_t effMC = par[0].
meanMC +(par[1].
meanMC +par[2].
meanMC*var)*exp(-par[3].meanMC/var);
415 Float_t eff=std::max(effMC,(Float_t)0.);
416 eff=std::min(effMC,(Float_t)1.);
424 Float_t effMC = ComputeEffFromLocalParametrization(par,mom,momerr);
429 if (fabs(1-ratio) > err) err = fabs(1-ratio);
430 Float_t effDATA = ratio * effMC;
431 Float_t effDATA_err= err *effMC;
448 params.sigmaDATAh=effDATA_err;
463 uniqueID =
event.UniqueID;
473 anaUtils::CreateArray(groups,10);
475 anaUtils::ResizeArray(groups,nGroups);
477 EventBoxB* EventBox =
event.EventBoxes[EventBoxId::kEventBoxTracker];
481 for (Int_t g = 0; g<nGroups;g++)
484 if (box.RelevantRecObjects)
delete box.RelevantRecObjects;
485 anaUtils::CreateArray(box.RelevantRecObjects, nMaxTracks);
488 for (Int_t g = 0; g<nGroups;g++){
490 AnaRecObjectC** tracks0 = EventBox->RecObjectsInGroup[groups[g]];
493 bool used[NMAXPARTICLES]={
false};
494 bool used_forQC[NMAXPARTICLES]={
true};
496 for (Int_t it1=0;it1<nOrig;it1++){
503 if(!track1)
continue;
505 if(!used[it1]) used_forQC[it1]=
true;
506 Float_t Q1=track1->
Charge;
508 for (Int_t it2 = it1+1; it2<nOrig; it2++){
516 Float_t Q2=track2->
Charge;
519 if(Q1*Q2<0 && ID1==ID2){
521 used_forQC[it1]=
false;
522 used_forQC[it2]=
true;
523 used[it1]=used[it2]=
true;
526 used_forQC[it1]=
true;
527 used_forQC[it2]=
false;
528 used[it1]=used[it2]=
true;
533 for (Int_t it1=0;it1<nOrig;it1++){
543 if (groups)
delete [] groups;
574 if (det == SubDetId::kFGD1){
576 IDs[0] = EventBoxTracker::kTracksWithTPCInFGD1FV;
579 else if (det == SubDetId::kFGD2){
581 IDs[0] = EventBoxTracker::kTracksWithTPCInFGD2FV;
584 else if (det == SubDetId::kFGD){
587 IDs[0] = EventBoxTracker::kTracksWithTPCInFGD1FV;
588 IDs[1] = EventBoxTracker::kTracksWithTPCInFGD2FV;
590 }
else if (det == SubDetId::kP0D){
591 IDs[0] = EventBoxTracker::kTracksWithTPCInP0DFV;
Int_t _index
The index of this systematic (needed by SystematicsManager);.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Is this track relevant for this systematic ?
Int_t GetIndex() const
Return the index of this systematic.
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
Int_t SelectionEnabledIndex
The enabled index of this selection this ToyBox belongs to.
SystBoxB * GetSystBox(const AnaEventC &event, Int_t isel=0, Int_t ibranch=0) const
Get the SystBox corresponding to a selection, branch and event.
AnaTPCParticleB * TPCSegments[NMAXTPCS]
The TPC segments that contributed to this global track.
void SetNParameters(int N)
Set the number of systematic parameters associated to this systematic.
AnaTrueObjectC * TrueObject
The link to the true oject that most likely generated this reconstructed object.
Float_t Charge
The reconstructed charge of the particle.
Int_t ID
The ID of the trueObj, which corresponds to the ID of the TTruthParticle that created it...
Float_t MomentumError
Error of the momentum at the start of the segment.
Float_t meanDATA
The mean value for each of the systematic parameters of the control sample.
Int_t nRecObjectsInGroup[NMAXRECOBJECTGROUPS]
----—— RecObjects and TrueRecObjects used in the selection and systematics ------------—— ...
Float_t Momentum
The reconstructed momentum of the particle, at the start position.
int nTPCSegments
How many TPC tracks are associated with this track.
virtual bool IsRelevantRecObjectForSystematicInToy(const AnaEventC &, const ToyBoxB &, AnaRecObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this track relevant for a given systematic (after selection, called for each toy) ...
const AnaParticleB * Original
void FillSystBox(const AnaEventC &event, const SelectionBase &sel, Int_t ibranch)
Fill the SystBox for this event, selection and branch.
Weight_h ComputeWeight(const ToyExperiment &, const AnaEventC &, const ToyBoxB &)
Apply the systematic.
Int_t SuccessfulBranch
The branch that is successful for this toy in the selection this ToyBox belongs to.
Float_t meanMC
The mean value for each of the systematic parameters of the control sample.
Representation of a global track.
Representation of a TPC segment of a global track.
Float_t DirectionStart[3]
The reconstructed start direction of the particle.
virtual bool IsRelevantRecObjectForSystematic(const AnaEventC &, AnaRecObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this track relevant for a given systematic (prior to selection, call when initializing the event...
Float_t meanMCANA
The mean value for each of the systematic parameters of the analysis sample.
Float_t sigmaDATAl
The sigma value for each of the systematic parameters of the control sample /// with possibility of a...
Int_t nRelevantRecObjects
----—— Relevant rec objects and true objects for each systematic ------------—— ...
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
Float_t Charge
The true charge of the particle.
SystBoxB **** _systBoxes
----—— Relevant objects for this systematic ------------——
Float_t Direction[3]
The initial direction of the true particle.
virtual bool IsRelevantRecObject(const AnaEventC &, const AnaRecObjectC &) const
Check whether a AnaRecObject is relevant for this systematic or not.
SubDetId_h GetDetectorFV(Int_t ibranch=0) const
Get the detector in which the Fiducial Volume is defined.
Int_t GetEnabledIndex() const
Get the Selection index.