1 #include "FancyTTreeInterpolator.h" 23 fXmin = gr->GetX()[0];
24 fXmax = gr->GetX()[gr->GetN()-1];
33 std::cerr.precision(10);
47 std::map<TString, TGraph*> ::iterator i;
48 for(i=fStringToGraph.begin(); i!=fStringToGraph.end(); ++i){
65 return makeSortedTGraph(drawText,
"", 0);
80 return makeSortedTGraph(drawText, cutString, 0);
99 return makeSortedTGraph(drawText,
"", wrapValue);
129 const Int_t nEntries = fTree->Draw(drawText, cutString,
"goff");
132 std::vector<Int_t> sortedIndices(nEntries);
133 TMath::Sort(nEntries, fTree->GetV2(), &sortedIndices.front(), kFALSE);
134 std::vector<Double_t> newX(nEntries);
135 std::vector<Double_t> newY(nEntries);
137 for(
int i=0; i<nEntries; i++){
138 newX.at(i) = fTree->GetV2()[sortedIndices.at(i)];
139 newY.at(i) = fTree->GetV1()[sortedIndices.at(i)];
145 for(
int i=1; i<nEntries; i++){
149 while (newY.at(i) - newY.at(i-1) > wrapValue/2){
150 newY.at(i) -= wrapValue;
156 while (newY.at(i) - newY.at(i-1) < -wrapValue/2){
157 newY.at(i) += wrapValue;
164 TGraph* gr(
new TGraph(nEntries,&newX.front(), &newY.front()));
165 gr->SetTitle(drawText +
", " + cutString);
166 gr->GetXaxis()->SetTitle(fXAxisText);
167 gr->GetYaxis()->SetTitle(drawText);
184 add(yAxisText,
"", 0);
198 add(yAxisText, cutString, 0);
213 add(yAxisText,
"", wrapValue);
229 TString drawText = yAxisText +
":" + fXAxisText;
230 TGraph* gr = makeSortedTGraph(drawText, cutString, wrapValue);
231 fStringToGraph[yAxisText] = gr;
232 fStringToWrapValue[yAxisText] = wrapValue;
249 if(fStringToGraph.count(yAxisText)==0){
250 std::cerr <<
"Can't find TGraph in FancyTTreeInterpolator created with text " + yAxisText << std::endl;
253 throw std::invalid_argument(
"Can't find TGraph in FancyTTreeInterpolator created with text " + std::string(yAxisText.Data()));
256 return fStringToGraph.find(yAxisText)->second;
276 TGraph* gr =
get(yAxisText);
278 if(xAxisValue >= fXmin && xAxisValue <= fXmax){
279 Double_t tempVal = gr->Eval(xAxisValue);
282 Double_t wrap = fStringToWrapValue.find(yAxisText)->second;
287 while (tempVal >= wrap){
294 std::cerr <<
"Value " << xAxisValue <<
" lies outside range of " << fXAxisText << std::endl;
295 std::cerr <<
"xMin = " << fXmin <<
", xMax = " << fXmax << std::endl;
296 throw std::domain_error(
"");
TString fXAxisText
Branch name with which the intepolater was initialized.
TGraph * makeSortedTGraph(TString yAxisText)
Makes a sorted TGraph from fTree->Draw() with no cuts.
Double_t fXmax
Stored x-axis lower limit.
TTree * fTree
TTree with which the intepolater was initialized.
~FancyTTreeInterpolator()
Desonstructor.
void add(TString yAxisText)
Adds a TGraph to the interally stored TGraphs.
Double_t interp(TString yAxisText, Double_t xAxisValue)
Get interpolated yAxisText variable at xAxisValue (time).
Double_t fXmin
Stored x-axis lower limit.
FancyTTreeInterpolator(TTree *t, TString xAxisText)
Constructor.
TGraph * get(TString yAxisText)
Access the interally stored TGraph via the yAxisText.