00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <iostream>
00014 #include <cstdio>
00015 #include <Rtypes.h>
00016 #include "emcTracedValue.h"
00017 #include <cmath>
00018
00019 using namespace std;
00020
00021
00022 emcTracedValue::emcTracedValue(Float_t* BP, bool isconstant)
00023 {
00024
00025 if (BP) {
00026 Set(static_cast<int>(floor(BP[0])),BP[3],BP[2],isconstant) ;
00027 } else {
00028 Set(0,0,0,isconstant) ;
00029 }
00030 }
00031
00032
00033 emcTracedValue::emcTracedValue(int thetime, float constant,
00034 float slope, bool isconstant)
00035 {
00036 Set(thetime,constant,slope,isconstant) ;
00037 }
00038
00039
00040 emcTracedValue::emcTracedValue(const emcTracedValue& val)
00041 {
00042 GLine[0] = val.GLine[0] ;
00043 GLine[1] = val.GLine[1] ;
00044 GLine[2] = val.GLine[2] ;
00045 fIsConstant = val.fIsConstant ;
00046 }
00047
00048
00049 emcTracedValue&
00050 emcTracedValue::operator=(const emcTracedValue& val)
00051 {
00052 if ( this == &val ) return *this ;
00053 GLine[0] = val.GLine[0] ;
00054 GLine[1] = val.GLine[1] ;
00055 GLine[2] = val.GLine[2] ;
00056 fIsConstant = val.fIsConstant ;
00057 return *this ;
00058 }
00059
00060
00061 Float_t emcTracedValue::getValue(Float_t t)
00062 {
00063 if ( t >= GLine[0] && !fIsConstant ) {
00064 return GLine[1]+GLine[2]*(t-GLine[0]) ;
00065 }
00066 else {
00067 return GLine[1] ;
00068 }
00069 }
00070
00071
00072 void emcTracedValue::Set(int thetime, float constant,
00073 float slope)
00074 {
00075 GLine[0] = thetime ;
00076 GLine[1] = constant ;
00077 GLine[2] = slope ;
00078 }
00079
00080
00081 void emcTracedValue::Set(int thetime, float constant,
00082 float slope, bool isconstant)
00083 {
00084 Set(thetime,constant,slope) ;
00085 fIsConstant = isconstant ;
00086 }
00087
00088
00089
00090 void emcTracedValue::readData(FILE * fp)
00091 {
00092 fscanf(fp,"%f %f %f", &GLine[0],&GLine[1],&GLine[2]);
00093 }
00094
00095
00096 void emcTracedValue::writeData(FILE * fp)
00097 {
00098 fprintf(fp," %10.0f %10.5f %14.9f", GLine[0],GLine[1],GLine[2]);
00099 }
00100
00101
00102 ostream& operator << (ostream& out, const emcTracedValue& val)
00103 {
00104 out << ((int)val.GLine[0])
00105 << " " << val.GLine[1] << " " << val.GLine[2] ;
00106 if ( val.isConstant() ) out << " (constant) " ;
00107 out << endl ;
00108 return out ;
00109 }
00110