HighLAND
TPCP0DMatchEffSystematics.cxx
1 #include "TPCP0DMatchEffSystematics.hxx"
2 #include "CutUtils.hxx"
3 #include "SystematicUtils.hxx"
4 #include "SystId.hxx"
5 #include <cmath>
6 
7 //#define DEBUG
8 
9 //********************************************************************
10 TPCP0DMatchEffSystematics::TPCP0DMatchEffSystematics(bool comp):BinnedParams("TPCP0DMatchEff",k2D_EFF_ASSYMMETRIC){
11  //********************************************************************
12 
13  _computecounters=comp;
15  if(_computecounters)
17 
18  //Fill graphs to interpolate
19 
20 }
21 
22 //********************************************************************
24  //********************************************************************
25 
26 
27  if(_computecounters)
29 
30  (void)event;
31 
32  // Get the SystBox for this event, and the appropriate selection and branch
33  SystBoxB* SystBox = GetSystBox(event, box.SelectionEnabledIndex, box.SuccessfulBranch);
34 
35 
36  Weight_h eventWeight = 1.;
37 
38 #ifdef DEBUG
39  std::cout << "TPCP0DMatchEffSystematics::Apply(): " << SystBox->nRelevantTrueObjects<< std::endl;
40 #endif
41 
42  // Loop over relevant true tracks
43  for (Int_t itrk=0;itrk<SystBox->nRelevantTrueObjects;itrk++){
44 
45  AnaTrueParticleB* truePart = static_cast<AnaTrueParticleB*>(SystBox->RelevantTrueObjects[itrk]);
46 
47  AnaTrackB* recoTrack = static_cast<AnaTrackB*>(SystBox->RelevantTrueObjectsReco[itrk]);
48 
49  if (!truePart || !recoTrack) continue;
50 
51  // For example in numuCC inclusive selection, only the TrueTrack associated to the muon candidate, and other true muon tracks should be considered
52  if (!sel.IsRelevantTrueObjectForSystematicInToy(event, box, truePart, SystId::kTpcP0dMatchEff, box.SuccessfulBranch)) continue;
53 
54  AnaTPCParticleB* tpcTrack = static_cast<AnaTPCParticleB*>(anaUtils::GetSegmentWithMostNodesInDet(*recoTrack, SubDetId::kTPC1));
55 
56  if(!tpcTrack) continue;
57 
58  if (!tpcTrack) continue;
59 
60  BinnedParamsParams params;
61  int index;
62 
63  if (!GetBinValues(13, tpcTrack->Momentum, params, index)) continue;
64 
65  // Now check detector bits
66  bool found = SubDetId::GetDetectorUsed(recoTrack->Detector, SubDetId::kP0D);
67 
68  eventWeight *= systUtils::ComputeEffLikeWeight(found, toy, GetIndex(), index, params);
69 
70 #ifdef DEBUG
71  std::cout<<"tpc1-p0d found "<< found<<" eventWeight "<<eventWeight<<std::endl;
72 #endif
73 
74  if(_computecounters)
75  UpdateEfficiencyCounter(index,found);
76 
77  }
78 
79  return eventWeight;
80 }
81 
82 //********************************************************************
84  //********************************************************************
85 
86  (void)event;
87 
88  //for the moment just require a track to enter P0D
89  if (!anaUtils::TrueParticleEntersDet(static_cast<const AnaTrueParticleB*>(&track), SubDetId::kP0D)) return false;
90 
91  return true;
92 
93 }
94 
95 //**************************************************
97  //**************************************************
98 
99  (void)event;
100 
101  //should use TPC1: probably good quality as well?
102  AnaParticleB* tpcTrack = anaUtils::GetSegmentWithMostNodesInDet(*static_cast<const AnaTrackB*>(&track), SubDetId::kTPC1);
103 
104  if(!tpcTrack) return false;
105 
106  if (!cutUtils::TPCTrackQualityCut(*tpcTrack)) return false;
107 
108  return true;
109 }
110 
111 //********************************************************************
112 Int_t TPCP0DMatchEffSystematics::GetRelevantRecObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
113  //********************************************************************
114 
115  (void)sel;
116  (void)ibranch;
117 
118  IDs[0] = EventBoxTracker::kTracksWithTPC;
119 
120  return 1;
121 
122 }
123 
124 //********************************************************************
125 Int_t TPCP0DMatchEffSystematics::GetRelevantTrueObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
126  //********************************************************************
127 
128  (void)sel;
129  (void)ibranch;
130 
131  IDs[0] = EventBoxTracker::kTrueParticlesChargedInTPCInBunch;
132 
133  return 1;
134 }
bool TrueParticleEntersDet(const AnaTrueParticleB *track, SubDetId::SubDetEnum det)
Whether a true track enters a given sub-detector.
Definition: TruthUtils.cxx:108
unsigned long Detector
Int_t GetIndex() const
Return the index of this systematic.
Int_t GetRelevantTrueObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrueTrackGroup IDs array for this systematic.
Int_t SelectionEnabledIndex
The enabled index of this selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:49
SystBoxB * GetSystBox(const AnaEventC &event, Int_t isel=0, Int_t ibranch=0) const
Get the SystBox corresponding to a selection, branch and event.
void SetNParameters(int N)
Set the number of systematic parameters associated to this systematic.
static bool GetDetectorUsed(unsigned long BitField, SubDetId::SubDetEnum det)
Method to see if a certain subdetector or subdetector system is used.
Definition: SubDetId.cxx:40
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
bool UpdateEfficiencyCounter(Int_t index, bool correct)
Update the efficiency variables _ncorrect and _nwrong.
Float_t Momentum
The reconstructed momentum of the particle, at the start position.
Representation of a true Monte Carlo trajectory/particle.
bool IsRelevantTrueObject(const AnaEventC &event, const AnaTrueObjectC &track) const
Is this track relevant for this systematic ?
Int_t SuccessfulBranch
The branch that is successful for this toy in the selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:46
Representation of a global track.
Int_t nRelevantTrueObjects
Array of Relevant True RecObjects for each systematic.
Definition: SystBoxB.hxx:24
Representation of a TPC segment of a global track.
Weight_h ComputeWeight(const ToyExperiment &, const AnaEventC &, const ToyBoxB &)
Apply the systematic.
AnaRecObjectC ** RelevantTrueObjectsReco
Definition: SystBoxB.hxx:29
void InitializeEfficiencyCounter()
Initialize counters.
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) ...
AnaParticleB * GetSegmentWithMostNodesInDet(const AnaTrackB &track, SubDetId::SubDetEnum det)
Method to get the subtrack with most nodes in a given detector.
Representation of a reconstructed particle (track or shower).
Int_t GetNBins()
Get the number of bins.
bool IsRelevantRecObject(const AnaEventC &event, const AnaRecObjectC &track) const
Is this track relevant for this systematic ?