00001
00002
00003
00004
00005 #define SexyPedestal_cxx
00006
00007 #include <TMath.h>
00008 #include <SexyPedestal.h>
00009
00010 using namespace std;
00011
00012 CVSID("$Id: SexyPedestal.cxx,v 1.4 2005/05/19 14:41:51 anatael Exp $");
00013
00014
00015 Int_t SexyPedestal::fSparsFactor = 5;
00016 Int_t SexyPedestal::fTruncFactor = 5;
00017 Int_t SexyPedestal::fTruncFlag = 2;
00018
00019 const Int_t SexyPedestal::CRATEMAX;
00020 const Int_t SexyPedestal::VARCMAX;
00021 const Int_t SexyPedestal::VMMMAX;
00022 const Int_t SexyPedestal::VFBMAX;
00023 const Int_t SexyPedestal::VAMAX;
00024 const Int_t SexyPedestal::VACHMAX;
00025
00026 const Int_t SexyPedestal::TRTHRPMT;
00027 const Int_t SexyPedestal::TRTHRLGPIN;
00028 const Int_t SexyPedestal::TRTHRHGPIN;
00029
00030
00031
00032 SexyPedestal::SexyPedestal() {
00033 MSG("SexyPedestal",Msg::kDebug) << "Sexy Pedestal constructing..." << endl;
00034
00035 fcrate = -1;
00036 fvarc = -1;
00037 fvmm = -1;
00038 fvfb = -1;
00039 fva = -1;
00040 fvach = -1;
00041
00042 fplane = -1;
00043
00044 fnumPointsT1 = -1;
00045 fnumPointsT2 = -1;
00046 fnumPointsRaw = -1;
00047
00048
00049
00050 frawMean = -1;
00051 frawRms = -1;
00052
00053 fmeanTruc1 = -1;
00054 frmsTrunc1 = -1;
00055 ftruncthrT1 = -1;
00056
00057 fmeanTruc2 = -1;
00058 frmsTrunc2 = -1;
00059
00060 ferror = -1;
00061
00062
00063
00064
00065
00066
00067
00068 MSG("SexyPedestal",Msg::kDebug) << "Sexy Pedestal constructed!" << endl;
00069 }
00070
00071
00072
00073 SexyPedestal::~SexyPedestal() {
00074 MSG("SexyPedestal",Msg::kDebug) << "Destructing Sexy Pedestal" << endl;
00075 }
00076
00077
00078
00079 Bool_t SexyPedestal::SparsifiedChannel() {
00080
00081
00082
00083
00084 if(fvach==0) return true;
00085 if(fvach==18 && fva==2) return true;
00086
00087 return false;
00088 }
00089
00090
00091
00092 Bool_t SexyPedestal::IsLGPIN() {
00093
00094 if(fvach==18 && fva==0 ) return true;
00095 return false;
00096 }
00097
00098
00099
00100 Bool_t SexyPedestal::IsHGPIN() {
00101
00102 if(fvach==18 && fva==1 ) return true;
00103 return false;
00104 }
00105
00106
00107
00108 Bool_t SexyPedestal::IsTPMTchannel() {
00109
00110 if(fcrate==1 && fvarc==2 && fvmm==5 && fva==1) return true;
00111 return false;
00112
00113 }
00114
00115
00116
00117 Bool_t SexyPedestal::IsCMchannel() {
00118
00119 if(fvach==1 || fvach==19 || fvach==20 || fvach==21 ) return true;
00120 return false;
00121 }
00122
00123
00124
00125 void SexyPedestal::AddressMe(const Int_t crate,
00126 const Int_t varc,
00127 const Int_t vmm,
00128 const Int_t vfb,
00129 const Int_t va,
00130 const Int_t vach ) {
00131 fcrate = crate;
00132 fvarc = varc;
00133 fvmm = vmm;
00134 fvfb = vfb;
00135 fva = va;
00136 fvach = vach;
00137 }
00138
00139
00140
00141 Bool_t SexyPedestal::AreYouAt(const Int_t crate,
00142 const Int_t varc,
00143 const Int_t vmm,
00144 const Int_t vfb,
00145 const Int_t va,
00146 const Int_t vach ) {
00147
00148 if(crate==fcrate && varc==fvarc && vmm==fvmm && vfb==fvfb && va==fva && vach==vach)
00149 return true;
00150 else return false;
00151 }
00152
00153
00154
00155 void SexyPedestal::GetSTAT() {
00156
00157 if(fSPentries_v.size()<=0) {
00158 MSG("SexyPedestal",Msg::kError) << "ERROR: No pedestal data has been input for this channel" << endl;
00159 return;
00160 }
00161
00162 MSG("SexyPedestal",Msg::kDebug) << "Entries: " << fSPentries_v.size() << endl;
00163
00164
00165 fnumPointsRaw = this->GetInfoRaw();
00166
00167 switch(fTruncFlag) {
00168 case 0:
00169 break;
00170 case 1:
00171
00172 fnumPointsT1 = this->GetInfoTrunc1();
00173 break;
00174 case 2:
00175
00176 fnumPointsT2 = this->GetInfoTrunc2();
00177 break;
00178 }
00179 return;
00180 }
00181
00182
00183
00184 Int_t SexyPedestal::GetInfoRaw() {
00185
00186 Int_t rawSum = 0;
00187 Int_t rawSumSq = 0;
00188
00189 Int_t counterRaw = 0;
00190
00191
00192 vector<Short_t>::iterator iterPedestal = fSPentries_v.begin();
00193
00194 while(iterPedestal != fSPentries_v.end()) {
00195
00196 rawSum += (*iterPedestal);
00197 rawSumSq += (*iterPedestal)*(*iterPedestal);
00198 counterRaw++;
00199
00200 iterPedestal++;
00201 }
00202
00203 if(counterRaw != 0) {
00204 frawMean = (Float_t) rawSum / (Float_t) counterRaw;
00205
00206 frawRms = (Float_t) rawSumSq/ (Float_t) counterRaw;
00207 frawRms -= pow(frawMean,2);
00208 frawRms = sqrt(TMath::Abs(frawRms));
00209 }
00210
00211 MSG("SexyPedestal",Msg::kDebug) << "Raw: " << frawMean << "-"
00212 << frawRms << "-" << counterRaw << endl;
00213 return counterRaw;
00214 }
00215
00216
00217
00218
00219 Int_t SexyPedestal::GetInfoTrunc1() {
00220
00221 Int_t sumT1 = 0;
00222 Int_t sumSqT1 = 0;
00223 Int_t counterT1 = 0;
00224
00225 ftruncthrT1 = frawRms * fTruncFactor;
00226
00227
00228 vector<Short_t>::iterator iterPedestal = fSPentries_v.begin();
00229
00230 while(iterPedestal!=fSPentries_v.end()) {
00231
00232 if(TMath::Abs((*iterPedestal)-frawMean)<ftruncthrT1) {
00233
00234 sumT1 += (*iterPedestal);
00235 sumSqT1 += (*iterPedestal)*(*iterPedestal);
00236 counterT1++;
00237 }
00238 iterPedestal++;
00239 }
00240
00241 if(counterT1 != 0) {
00242 fmeanTruc1 = (Float_t) sumT1 / (Float_t) counterT1;
00243
00244 frmsTrunc1 = (Float_t) sumSqT1/ (Float_t) counterT1;
00245 frmsTrunc1 -= pow(fmeanTruc1,2);
00246 frmsTrunc1 = sqrt(TMath::Abs(frmsTrunc1));
00247 }
00248
00249 MSG("SexyPedestal",Msg::kDebug) << "T1: " << fmeanTruc1
00250 << "-" << frmsTrunc1 << "-" << counterT1 << endl;
00251
00252 return counterT1;
00253 }
00254
00255
00256
00257 Int_t SexyPedestal::GetInfoTrunc2() {
00258
00259 Int_t sumT2 = 0;
00260 Int_t sumSqT2 = 0;
00261 Int_t counterT2 = 0;
00262
00263
00264 vector<Short_t>::iterator iterPedestal = fSPentries_v.begin();
00265
00266 while(iterPedestal!=fSPentries_v.end()) {
00267
00268 if(TMath::Abs((*iterPedestal) - frawMean) < this->GetTrThresholdT2() ) {
00269 sumT2 += (*iterPedestal);
00270 sumSqT2 += (*iterPedestal)*(*iterPedestal);
00271 counterT2++;
00272 }
00273 iterPedestal++;
00274 }
00275
00276 if(counterT2 != 0) {
00277 fmeanTruc2 = (Float_t) sumT2 / (Float_t) counterT2;
00278
00279 frmsTrunc2 = (Float_t) sumSqT2/ (Float_t) counterT2;
00280 frmsTrunc2 -= pow(fmeanTruc2,2);
00281 frmsTrunc2 = sqrt(TMath::Abs(frmsTrunc2));
00282 }
00283
00284 MSG("SexyPedestal",Msg::kDebug) << "T2: " << fmeanTruc2 << "-"
00285 << frmsTrunc2 << "-" << counterT2 << endl;
00286
00287 return counterT2;
00288 }
00289
00290
00291
00292 Int_t SexyPedestal::GetIDKey() {
00293
00294 Int_t key = VACHMAX*fva+fvach;
00295 key += VACHMAX*VAMAX*fvfb;
00296 key += VACHMAX*VAMAX*VFBMAX*fvmm;
00297 key += VACHMAX*VAMAX*VFBMAX*VMMMAX*fvarc;
00298 key += VACHMAX*VAMAX*VFBMAX*VMMMAX*VARCMAX*fcrate;
00299
00300 return key;
00301 }
00302
00303
00304
00305
00306 Int_t SexyPedestal::EncriptMeAKey(const Int_t crate,
00307 const Int_t varc,
00308 const Int_t vmm,
00309 const Int_t vfb,
00310 const Int_t va,
00311 const Int_t vach ){
00312 Int_t key = VACHMAX*va+vach;
00313 key += VACHMAX*VAMAX*vfb;
00314 key += VACHMAX*VAMAX*VFBMAX*vmm;
00315 key += VACHMAX*VAMAX*VFBMAX*VMMMAX*varc;
00316 key += VACHMAX*VAMAX*VFBMAX*VMMMAX*VARCMAX*crate;
00317
00318 return key;
00319 }
00320
00321