HighLAND
P0DELossResolSystematics.cxx
1 #include "P0DELossResolSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "BaseDataClasses.hxx"
4 #include "EventBoxTracker.hxx"
5 #include <iostream>
6 
7 const bool debug = false;
8 
9 //********************************************************************
11 //********************************************************************
12 
13  BinnedParams::SetName("P0DELossResol");
14  BinnedParams::SetType(k1D_SYMMETRIC);
15  // SetBaseIndex(0);
16 
17  char dirname[256];
18  sprintf(dirname,"%s/data",getenv("PSYCHESYSTEMATICSROOT"));
19  BinnedParams::Read(dirname);
20  // BinnedParams::Print();
21  if (debug){
22  std::cout <<"Nbins: "<<GetNBins();
23  for (int i = 0 ; i < GetNBins(); i++)
24  {
25  Float_t mean,sigma;
26  GetParametersForBin(i,mean,sigma);
27  std::cout<<"Mean, sigma = "<<mean<<" "<<sigma<<std::endl;
28 
29  }
30 
31  }
32 }
33 
34 //********************************************************************
36 //********************************************************************
37 
38  (void)event;
39 
40 
41  // Get the relevant tracks for this systematic
42  //AnaTrackB** tracks = box.RelevantRecObjects;
43 
44  SystBoxB* box = GetSystBox(event);
45  // Nothing to do If there are no relevant tracks
46  if (box->nRelevantRecObjects == 0) return;
47 #ifdef DEBUG
48  std::cout << "P0DELossResolsystematics::Apply()"<<std::endl;
49 
50 #endif
51 
52  // loop over the relevant tracks for this systematic
53  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
54 #ifdef DEBUG
55  std::cout <<"Track "<< itrk << std::endl;
56 #endif
57 
58  AnaTrackB* track = static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk]);
59 
60  //At the moment only one P0D track can be saved
61  if (!track->nP0DSegments) continue;
62  if (!track->GetTrueParticle()) continue;
63  if (track->GetTrueParticle()->nDetCrossings < 2) continue;
64  AnaP0DParticleB* p0d = (AnaP0DParticleB*) track->P0DSegments[0];//returns an AnaP0DParticle*
65 
66  // Get a reference to the momentum to be varied
67  Float_t& p = track->Momentum;
68 
69  Float_t p0dlength = p0d->Length;
70  Float_t p0dEloss = p0d->ELoss;
71  Float_t trueMomentum = track->GetTrueParticle()->Momentum;
72  AnaDetCrossingB* cross = track->GetTrueParticle()->DetCrossings[1];// Check index before using
73  Float_t postP0DMomentum = sqrt(cross->EntranceMomentum[0]*cross->EntranceMomentum[0]
74  + cross->EntranceMomentum[1]*cross->EntranceMomentum[1]
75  + cross->EntranceMomentum[2]*cross->EntranceMomentum[2]);
76  Float_t trueP0dEloss = trueMomentum - postP0DMomentum;
77 
78  Float_t scale, scaleError;
79 
80 
81  if (p0dEloss > p) continue;
82 
83 #ifdef DEBUG
84  std::cout << "Toy variation: " << toy.GetToyVariations(_index)->Variations[0] << std::endl;
85 
86  std::cout << "p0 = " << p << std::endl;
87 // std::cout << "TPC1 mom = "<<track_pt->TrackerMomentum<<std::endl;
88  std::cout <<"P0D Length: "<<p0dlength<<std::endl;
89  std::cout <<"True P0D loss: "<<trueP0dEloss<<std::endl;
90  std::cout <<"P0D Loss: "<<p0dEloss<<std::endl;
91  std::cout <<"Entrance Position: "<<cross->EntrancePosition[0]<<" "<<cross->EntrancePosition[1]<<" "<<cross->EntrancePosition[2]<<std::endl;
92  std::cout <<"In TPC1? "<< anaUtils::InDetVolume(SubDetId::kTPC1,cross->EntrancePosition)<<std::endl;
93 #endif
94 
95 
96  if (!GetBinValues(p0dlength,scale,scaleError)) continue;
97  //if (!GetParametersForBin(0,scale,scaleError)) continue;
98 #ifdef DEBUG
99  std::cout <<"Bin values retrieved"<<std::endl;
100  std::cout << "Scale = "<<scale<<" Scale Err = " <<scaleError<<std::endl;
101 #endif
102  // Apply the momentum scale factor
103  p += (scale + scaleError * toy.GetToyVariations(_index)->Variations[0]) * (p0dEloss - trueP0dEloss);
104 
105 #ifdef DEBUG
106  std::cout << "p = " << p << std::endl;
107 #endif
108  }
109 }
110 
111 //********************************************************************
113 //********************************************************************
114 
115  SystBoxB* box = GetSystBox(event);
116  // Get the relevant tracks for this systematic
117  AnaRecObjectC** tracks = box->RelevantRecObjects;
118 
119  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
120  AnaTrackB* track = static_cast<AnaTrackB*>(tracks[itrk]);
121  if(!track->Original) continue;
122 
123  // Go back to the corrected momentum
124  track->Momentum = track->GetOriginalTrack()->Momentum;
125  }
126 
127  // Don't reset the spill to corrected
128  return false;
129 }
130 
131 //************************************************************
133 //************************************************************
134 
135 
136  SubDetId_h det = sel.GetDetectorFV();
137 
138  if (det == SubDetId::kP0D){
139  IDs[0] = EventBoxTracker::kTracksWithTPCInP0DFV;
140  return 1;
141  }
142 
143  return 0;
144 
145 }
Int_t _index
The index of this systematic (needed by SystematicsManager);.
virtual void Apply(const ToyExperiment &toy, AnaEventC &event)
Apply the systematic.
int nP0DSegments
How many P0D tracks are associated with this track.
const AnaTrackB * GetOriginalTrack() const
Return a casted version of the original AnaParticleB associated.
AnaP0DParticleB * P0DSegments[NMAXP0DS]
The P0D segments that contributed to this global track.
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
int nDetCrossings
The number of DetCrossing objects.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
void SetType(TypeEnum type)
Set the type.
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 SetName(const std::string &name)
Set the name.
Float_t Momentum
The initial momentum of the true particle.
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
Float_t Momentum
The reconstructed momentum of the particle, at the start position.
const AnaParticleB * Original
Float_t EntrancePosition[4]
for each subdetector tell the entrance position
AnaDetCrossingB ** DetCrossings
Representation of a detector crossing info for a true particle (G4 trajectory).
void Read(const std::string &inputDirName, const std::string &extension="")
Read from a file the systematic source values.
Representation of a global track.
virtual bool UndoSystematic(AnaEventC &event)
Undo the systematic variations done by ApplyVariation. This is faster than resetting the full Spill...
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
bool InDetVolume(SubDetId::SubDetEnum det, const Float_t *pos)
Int_t nRelevantRecObjects
----—— Relevant rec objects and true objects for each systematic ------------—— ...
Definition: SystBoxB.hxx:20
bool GetParametersForBin(Int_t index, Float_t &mean, Float_t &sigma)
Gets the bin values for a source provided the bin index.
Representation of a P0D segment of a global track.
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
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.
Float_t EntranceMomentum[3]
for each subdetector tell the entrance momentum