00001 #include "DigiSignal.h"
00002 #include "DigiPE.h"
00003 #include "Conventions/Munits.h"
00004
00005
00006 #include "TString.h"
00007
00008
00009
00010 static UInt_t sSignalIdCounter = 0;
00011
00012 DigiSignal::DigiSignal() :
00013 fCharge(0),
00014 fPes(0),
00015 fNumPe(0),
00016 fHits(0),
00017 fHitWeights(0),
00018 fTruth(kUnknown)
00019 {
00020 fSignalId = sSignalIdCounter++;
00021 }
00022
00023 DigiSignal::DigiSignal(Float_t charge,
00024 PEList_t& pes,
00025 HitList_t& hits,
00026 HitWeightList_t& weights,
00027 DigiPmtTruth_t truth) :
00028 fCharge(charge),
00029 fPes(pes),
00030 fNumPe((int)pes.size()),
00031 fHits(hits),
00032 fHitWeights(weights),
00033 fTruth(truth)
00034 {
00035 fSignalId = sSignalIdCounter++;
00036 }
00037
00038
00039
00040 DigiSignal::DigiSignal( const DigiSignal& rhs ) :
00041 TObject(rhs),
00042 fSignalId(rhs.fSignalId),
00043 fCharge(rhs.fCharge),
00044 fPes(rhs.fPes),
00045 fNumPe(rhs.GetNumPe()),
00046 fHits(rhs.fHits),
00047 fHitWeights(rhs.fHitWeights),
00048 fTruth(rhs.fTruth)
00049 {
00050 }
00051
00052 DigiSignal::~DigiSignal()
00053 {
00054
00055 }
00056
00057 void DigiSignal::AddDigiPE(const DigiPE* digipe)
00058 {
00059 if(digipe) {
00060 fPes.push_back(digipe);
00061 const DigiScintHit* hit = digipe->GetHitPointer();
00062 fNumPe+=1;
00063 if(hit) AddHit(hit, 1.0);
00064 }
00065 }
00066
00067 void DigiSignal::AddHit(const DigiScintHit* hitptr, Double_t weight )
00068 {
00069
00070 UInt_t n = fHits.size();
00071 for(UInt_t i=0; i<n; i++) {
00072 const DigiScintHit* oldhit = GetHit(i);
00073 if (oldhit->GetUniqueID() == hitptr->GetUniqueID()) {
00074
00075 fHitWeights[i] += weight;
00076 return;
00077 }
00078 }
00079
00080
00081 TRef ref((TObject*)hitptr);
00082 fHits.push_back(ref);
00083 fHitWeights.push_back(weight);
00084 }
00085
00086 void DigiSignal::Merge(DigiSignal& other)
00087 {
00088 fCharge += other.fCharge;
00089 fPes.insert(fPes.end(),other.fPes.begin(),other.fPes.end());
00090 fNumPe+=other.GetNumPe();
00091
00092 UInt_t n = other.GetNumberOfHits();
00093 for(UInt_t i=0; i<n; i++) {
00094 AddHit(other.GetHit(i), other.GetHitWeight(i));
00095 }
00096
00097 fTruth |= other.fTruth;
00098 }
00099
00100
00101 const char* AsString(DigiSignal::DigiPmtTruth_t truth)
00102 {
00103
00104
00105 if(truth == DigiSignal::kUnknown) return "|Unknown|";
00106
00107 std::string result("|");
00108 if(truth & DigiSignal::kGenuine) result = result + "Genuine|";
00109 if(truth & DigiSignal::kDarkNoise) result = result + "DarkNoise|";
00110 if(truth & DigiSignal::kFibreLight) result = result + "FibreLight|";
00111 if(truth & DigiSignal::kCrosstalk) result = result + "CrossTalk|";
00112 if(truth & DigiSignal::kCrosstalkOptical) result = result + "CrossTalkOptical|";
00113 if(truth & DigiSignal::kLeakFromNextBucket) result = result + "LeakFromNextBucket|";
00114 if(truth & DigiSignal::kLeakFromPrevBucket) result = result + "LeakFromPrevBucket|";
00115
00116 return Form("%s",result.c_str());
00117 }
00118
00119
00120
00121 ostream& operator<<(ostream& os, const DigiSignal& s)
00122 { return s.FormatToOStream(os); }
00123
00124
00125 void DigiSignal::Print(Option_t *option) const
00126 {
00127 std::cout << this->AsString(option) << std::endl;
00128 }
00129
00130
00131 std::ostream& DigiSignal::FormatToOStream(std::ostream& os,
00132 Option_t *option) const
00133 {
00134 os << AsString(option);
00135 return os;
00136 }
00137
00138
00139 const char* DigiSignal::AsString(Option_t *option) const
00140 {
00141 const char* fmt_default =
00142 "DigiSignal [%d] %s Q=%.1ffC Npe=%d Nhits=%d";
00143 const char* fmt_extended =
00144 "DigiSignal ID=%d Truth=%s Charge=%.1ffC Npe=%d Nhits=%d";
00145
00146 const char* fmt = fmt_default;
00147
00148 switch(option[0]) {
00149 case 'e':
00150 case 'E':
00151 fmt = fmt_extended;
00152 break;
00153 default:
00154 fmt = fmt_default;
00155 }
00156
00157 DigiSignal::DigiPmtTruth_t truth = GetTruth();
00158 const char* truthstr = ::AsString(truth);
00159 return Form(fmt,
00160 GetId(),
00161 truthstr,
00162 GetCharge()/Munits::fC,
00163 GetNumPe(),
00164 GetNumberOfHits()
00165 );
00166
00167 }