Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:27

0001 #include "CondFormats/PhysicsToolsObjects/interface/PhysicsTGraphPayload.h"
0002 
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 
0005 #include <iomanip>
0006 
0007 PhysicsTGraphPayload::PhysicsTGraphPayload() : numPoints_(0) {}
0008 
0009 PhysicsTGraphPayload::PhysicsTGraphPayload(const TGraph& graph) : numPoints_(0) {
0010   if (graph.GetN() >= 1) {
0011     name_ = graph.GetName();
0012     numPoints_ = graph.GetN();
0013     x_.resize(numPoints_);
0014     y_.resize(numPoints_);
0015     for (int iPoint = 0; iPoint < numPoints_; ++iPoint) {
0016       Double_t xPoint, yPoint;
0017       graph.GetPoint(iPoint, xPoint, yPoint);
0018       x_[iPoint] = xPoint;
0019       y_[iPoint] = yPoint;
0020     }
0021   }
0022 }
0023 
0024 PhysicsTGraphPayload::operator TGraph() const {
0025   if (numPoints_ >= 1) {
0026     TGraph graph(numPoints_);
0027     graph.SetName(name_.data());
0028     for (int iPoint = 0; iPoint < numPoints_; ++iPoint) {
0029       graph.SetPoint(iPoint, x_[iPoint], y_[iPoint]);
0030     }
0031     return graph;
0032   } else {
0033     throw cms::Exception("PhysicsTGraphPayload") << "Invalid TGraph object !!\n";
0034   }
0035 }
0036 
0037 void PhysicsTGraphPayload::print(std::ostream& stream) const {
0038   stream << "<PhysicsTGraphPayload::print (name = " << name_ << ")>:" << std::endl;
0039   for (int iPoint = 0; iPoint < numPoints_; ++iPoint) {
0040     stream << "point #" << iPoint << ": x = " << x_[iPoint] << ", y = " << y_[iPoint] << std::endl;
0041   }
0042 }