HighLAND
P0DELossScaleSystematics.cxx
1 #include "P0DELossScaleSystematics.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("P0DELossScale");
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 
46  // Nothing to do If there are no relevant tracks
47  if (box->nRelevantRecObjects == 0) return;
48 
49 #ifdef DEBUG
50  std::cout << "P0DELossScaleSystematics::Apply(): " << std::endl;
51 #endif
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 << itrk << std::endl;
56 #endif
57 
58  AnaTrackB* track = static_cast<AnaTrackB*>(box->RelevantRecObjects[itrk]);
59 
60 #ifdef DEBUG
61  std::cout <<"P0D Segments: "<<track->nP0DSegments<<std::endl;
62  std::cout <<"TPC Segments: "<<track->nTPCSegments<<std::endl;
63 #endif
64  //At the moment only one P0D track can be saved
65  if (!track->nP0DSegments) continue;
66  AnaP0DParticleB* p0d = (AnaP0DParticleB*) track->P0DSegments[0];//returns an AnaP0DParticleB*
67 
68  // Get a reference to the momentum to be varied
69  Float_t& p = track->Momentum;
70 
71  Float_t p0dlength = p0d->Length;
72  Float_t p0dEloss = p0d->ELoss;
73  Float_t scale, scaleError;
74  if (p0dEloss < 0 ) continue;
75 #ifdef DEBUG
76  std::cout << "Toy variation: "<<toy.GetToyVariations(_index)->Variations[0]<<std::endl;
77 
78  std::cout << "p0 = " << p << std::endl;
79 // std::cout << "TPC1 Mom = "<<track_pt->TrackerMomentum<<std::endl;
80  std::cout <<"P0D Length: "<<p0dlength<<std::endl;
81  std::cout <<"P0D Eloss: "<<p0dEloss<<std::endl;
82  std::cout <<"Getting bin values:"<<std::endl;
83 #endif
84 
85 
86  if (!GetBinValues(p0dlength,scale,scaleError)) continue;
87  //if (!GetParametersForBin(0,scale,scaleError)) continue;
88 #ifdef DEBUG
89  std::cout <<"Bin values retrieved"<<std::endl;
90  std::cout << "Scale = "<<scale<<" Scale Err = " <<scaleError<<std::endl;
91 #endif
92  // Apply the momentum scale factor
93  p += (scale +scaleError*toy.GetToyVariations(_index)->Variations[0])*(p0dEloss);
94 
95 #ifdef DEBUG
96  std::cout << "p = " << p << std::endl;
97 #endif
98  }
99 }
100 
101 //********************************************************************
103 //********************************************************************
104 
105  SystBoxB* box = GetSystBox(event);
106  // Get the relevant tracks for this systematic
107  AnaRecObjectC** tracks = box->RelevantRecObjects;
108 
109  for (Int_t itrk=0;itrk<box->nRelevantRecObjects;itrk++){
110  AnaTrackB* track = static_cast<AnaTrackB*>(tracks[itrk]);
111  if(!track->Original) continue;
112 
113  // Go back to the corrected momentum
114  track->Momentum = track->GetOriginalTrack()->Momentum;
115  }
116 
117  // Don't reset the spill to corrected
118  return false;
119 }
120 
121 //************************************************************
123 //************************************************************
124 
125 
126  SubDetId_h det = sel.GetDetectorFV();
127 
128  if (det == SubDetId::kP0D){
129  IDs[0] = EventBoxTracker::kTracksWithTPCInP0DFV;
130  return 1;
131  }
132 
133  return 0;
134 
135 }
Int_t _index
The index of this systematic (needed by SystematicsManager);.
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
virtual bool UndoSystematic(AnaEventC &event)
Undo the systematic variations done by ApplyVariation. This is faster than resetting the full Spill...
virtual void Apply(const ToyExperiment &toy, AnaEventC &event)
Apply the 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.
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.
int nTPCSegments
How many TPC tracks are associated with this track.
const AnaParticleB * Original
void Read(const std::string &inputDirName, const std::string &extension="")
Read from a file the systematic source values.
Representation of a global track.
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
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.
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.