HighLAND
TPCTrackEffSystematics.cxx
1 #include "TPCTrackEffSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "EventBoxTracker.hxx"
4 #include "BasicUtils.hxx"
5 #include "SystematicUtils.hxx"
6 #include "SubDetId.hxx"
7 #include "SystId.hxx"
8 #include "Parameters.hxx"
9 
10 //********************************************************************
11 TPCTrackEffSystematics::TPCTrackEffSystematics(bool comp):BinnedParams("TPCTrackEff",k1D_EFF_ASSYMMETRIC, versionUtils::Extension()){
12 //********************************************************************
13 
14  _computecounters=comp;
16  if( _computecounters)
18 
19  _full_correlations = ND::params().GetParameterI("psycheSystematics.Tracker.FullCorrelations");
20 }
21 
22 //********************************************************************
24 //********************************************************************
25 
26  // Get the SystBox for this event, and the appropriate selection and branch
28 
31 
32  /*
33  //this case happen when:
34  // -the reco track is broken
35  // -the true track don't pass the cut dist>30 and mom> 5MeV
36  // -the reco track is absurd and matched to a true track that is not happening in the same bunch
37  */
38  BinnedParamsParams params;
39  Weight_h eventWeight=1;
40 
41  // Loop over all TrueParticles in the TPC
42  for (Int_t itrue=0;itrue< SystBox->nRelevantTrueObjects; itrue++){
43  AnaTrueParticleB* truePart = static_cast<AnaTrueParticleB*>(SystBox->RelevantTrueObjects[itrue]);
44  // retrieve the reconstructed track associated
45  // AnaTrackB* recoTrack = static_cast<AnaTrackB*>(SystBox->RelevantTrueObjectsReco[itrue]);
46 
47  // For example in numuCC inclusive selection, only the TrueTrack associated to the muon candidate, and other true muon tracks should be considered
48  if (!sel.IsRelevantTrueObjectForSystematicInToy(event,box,truePart,SystId::kTpcTrackEff,box.SuccessfulBranch)) continue;
49 
50  // Is there any reconstructed track associated to this true track ?
51  bool found=false;
52  int tpc_true=-1; //save the closest tpc to the FGD
53  for(Int_t idet=0;idet<truePart->nDetCrossings;idet++){
54  if ( box.DetectorFV == SubDetId::kFGD1 && SubDetId::GetDetectorUsed(truePart->DetCrossings[idet]->Detector,SubDetId::kTPC1)) tpc_true=1;
55  if ((box.DetectorFV == SubDetId::kFGD1 || box.DetectorFV == SubDetId::kFGD2) && SubDetId::GetDetectorUsed(truePart->DetCrossings[idet]->Detector,SubDetId::kTPC2)) tpc_true=2;
56  if ( box.DetectorFV == SubDetId::kFGD2 && SubDetId::GetDetectorUsed(truePart->DetCrossings[idet]->Detector,SubDetId::kTPC3)) tpc_true=3;
57  if ( box.DetectorFV == SubDetId::kP0D && SubDetId::GetDetectorUsed(truePart->DetCrossings[idet]->Detector,SubDetId::kTPC1)) tpc_true = 1;
58  }
59 
60  int tpc_rec=-1;
61  for (Int_t irec=0;irec<(int) SystBox->nRelevantRecObjects; irec++){
62  AnaTrackB* track = static_cast<AnaTrackB*>(SystBox->RelevantRecObjects[irec]);
63  for(int ii = 0; ii < track->nTPCSegments; ii++){
64  AnaTPCParticleB* tpc_track = track->TPCSegments[ii];
65  if(!tpc_track->TrueObject)continue;
66  if(truePart->ID==tpc_track->TrueObject->ID){
68  if (tpcnum == SubDetId::kTPC2) tpc_rec=2;
69  else if (tpcnum == SubDetId::kTPC3) tpc_rec=3;
70  else if (tpcnum == SubDetId::kTPC1) tpc_rec=1;
71  if(tpc_true==tpc_rec)//search for the segment that match the one we are looking at, at the true level.
72  break;
73  }
74  // Try to recover some of the particles associated to parents or grandparents of the recon objects.
75  else if ( truePart->ID > tpc_track->TrueObject->ID && (truePart->PDG == tpc_track->GetTrueParticle()->ParentPDG || truePart->PDG == tpc_track->GetTrueParticle()->GParentPDG)) {
77  if (tpcnum == SubDetId::kTPC2) tpc_rec=2;
78  else if (tpcnum == SubDetId::kTPC3) tpc_rec=3;
79  else if (tpcnum == SubDetId::kTPC1) tpc_rec=1;
80  if(tpc_true==tpc_rec)
81  break;
82  }
83  }
84  if(tpc_true==tpc_rec) break;
85  }
86  if(tpc_true==tpc_rec && tpc_rec>-1) found=true;
87  if(tpc_rec==-1) tpc_rec=tpc_true;
88 
89  // Get the TPC tracking efficiency for bin 0 (there is a single bin);
90  int index;
91  if(!GetBinValues((Float_t)tpc_rec, params, index)) continue;
92 
93  // override to ensure same variations for all params (see bugzilla 1271)
94  if (_full_correlations) index = 0;
95 
96  // bool found = (recoTrack);
97  eventWeight *= systUtils::ComputeEffLikeWeight(found, toy, GetIndex(), index, params);
98 
100  UpdateEfficiencyCounter(index,found);
101 
102  }
103 
104  return eventWeight;
105 }
106 
107 //********************************************************************
109 //********************************************************************
110 
111  (void)event;
112 
113  const AnaTrueParticleB& truePart = *static_cast<const AnaTrueParticleB*>(&trueObj);
114 
115  if(truePart.Charge==0) return false;
116 
117  // true momentum larger than 60 MeV
118  if( truePart.Momentum < 60. ) return false;
119 
120  // compute the linear length
121  Float_t zlength;
122  Float_t length = anaUtils::GetTrueLinearLengthInTPC(truePart,zlength);
123 
124  // linear length must be larger than 18 cm
125  if( length < 180. ) return false;
126  // and start position in FGD1 FV
127  // if (!anaUtils::InFiducialVolume(event.EventBoxes[EventBoxId::kEventBoxTracker]->DetectorFV, truePart.Position)) return false;
128 
129  Float_t dist=-9999999;
130  for(Int_t idet=0;idet<truePart.nDetCrossings;idet++){
131  //i.e crossing the active part of the tpc
132  if(SubDetId::GetDetectorUsed(truePart.DetCrossings[idet]->Detector, SubDetId::kTPC) && truePart.DetCrossings[idet]->InActive) {
133  Float_t sep = anaUtils::GetSeparationSquared(truePart.DetCrossings[idet]->EntrancePosition, truePart.DetCrossings[idet]->ExitPosition);
134  if(sep>dist) dist=sep;
135  }
136  }
137  // 30* 30 originally
138  //bigger than 3 TPC hits (30*30 is faster that sqrt(dist)), and momentum > 5 MeV
139  if((dist)<900) return false;
140 
141  return true;
142 }
143 
144 
145 //********************************************************************
147 //********************************************************************
148 
149  (void) truePart;
150  (void) track;
151 
152 /*
153  if(truePart.ID==track.TrueObject->ID ||
154  // Try to recover some of the particles associated to parents or grandparents of the recon objects.
155  (truePart.ID > track.TrueObject->ID && (truePart.PDG == track.GetTrueParticle()->ParentPDG || truePart.PDG == track.GetTrueParticle()->GParentPDG))) {
156  return true;
157  }
158 */
159 
160  return false;
161 }
162 
163 //********************************************************************
164 Int_t TPCTrackEffSystematics::GetRelevantRecObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
165 //********************************************************************
166 
167  (void)sel;
168  (void)ibranch;
169  IDs[0] = EventBoxTracker::kTracksWithTPC;
170  return 1;
171 }
172 
173 //********************************************************************
174 Int_t TPCTrackEffSystematics::GetRelevantTrueObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
175 //********************************************************************
176 
177  (void)sel;
178  (void)ibranch;
179  IDs[0] = EventBoxTracker::kTrueParticlesChargedInTPCInBunch;
180  return 1;
181 }
bool InActive
If the particle passes through an active part of the subdetector.
unsigned long Detector
Int_t GetIndex() const
Return the index of this systematic.
unsigned long Detector
int nDetCrossings
The number of DetCrossing objects.
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
Definition: Parameters.cxx:217
Float_t ExitPosition[4]
for each subdetector tell the exit position
bool _full_correlations
value of psycheSystematics.Tracker.FullCorrelations parameter
Int_t SelectionEnabledIndex
The enabled index of this selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:49
SubDetId_h DetectorFV
Indicate the FV we are interested in.
Definition: ToyBoxB.hxx:52
Int_t GParentPDG
The PDG code of this particle&#39;s grandparent, or 0 if there is no grandparent.
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.
bool _computecounters
The systematic source parameters.
AnaTrueObjectC * TrueObject
The link to the true oject that most likely generated this reconstructed object.
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
Float_t Momentum
The initial momentum of the true particle.
bool CheckTrueRecoAssociation(const AnaTrueObjectC &trueTrack, const AnaRecObjectC &track) const
Check the true-reco association.
float GetSeparationSquared(const Float_t *pos1, const Float_t *pos2)
Calculate the distance between two points.
Int_t ID
The ID of the trueObj, which corresponds to the ID of the TTruthParticle that created it...
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
bool UpdateEfficiencyCounter(Int_t index, bool correct)
Update the efficiency variables _ncorrect and _nwrong.
int nTPCSegments
How many TPC tracks are associated with this track.
Representation of a true Monte Carlo trajectory/particle.
Int_t GetRelevantTrueObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrueTrackGroup IDs array for this systematic.
Float_t EntrancePosition[4]
for each subdetector tell the entrance position
Int_t SuccessfulBranch
The branch that is successful for this toy in the selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:46
AnaDetCrossingB ** DetCrossings
SubDetEnum
Enumeration of all detector systems and subdetectors.
Definition: SubDetId.hxx:25
Int_t PDG
The PDG code of this particle.
Int_t ParentPDG
The PDG code of this particle&#39;s immediate parent, or 0 if there is no parent.
Representation of a global track.
Int_t nRelevantTrueObjects
Array of Relevant True RecObjects for each systematic.
Definition: SystBoxB.hxx:24
static SubDetId::SubDetEnum GetSubdetectorEnum(unsigned long BitField)
Get the single subdetector that this track is from.
Definition: SubDetId.cxx:165
Representation of a TPC segment of a global track.
TPCTrackEffSystematics(bool computecounters=false)
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
Float_t GetTrueLinearLengthInTPC(const AnaTrueParticleB &trueTrack, Float_t &distz)
Return the true linear length traversed in the TPC.
Definition: TruthUtils.cxx:32
bool IsRelevantTrueObject(const AnaEventC &event, const AnaTrueObjectC &trueTrack) const
Is this true track relevant for this systematic ?
Int_t nRelevantRecObjects
----—— Relevant rec objects and true objects for each systematic ------------—— ...
Definition: SystBoxB.hxx:20
void InitializeEfficiencyCounter()
Initialize counters.
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
Float_t Charge
The true charge of the particle.
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 &)
Int_t GetNBins()
Get the number of bins.