00001
00002 #include <string.h>
00003 #include <stdlib.h>
00004
00005 #include <TObjArray.h>
00006 #include <TClonesArray.h>
00007
00008 #include <TH2.h>
00009 #include <TFile.h>
00010
00011 #include <StMessMgr.h>
00012
00013 #include "EEqaSorterA.h"
00014 #include "StMuDSTMaker/EZTREE/EztEmcRawData.h"
00015
00016 ClassImp(EEqaSorterA)
00017
00018
00019 EEqaSorterA::EEqaSorterA()
00020 : TObject()
00021 , hCrate(0)
00022 , hCrateHot(0)
00023 , hotTwThres(40)
00024 {
00025 memset(feePed,0,sizeof(feePed));
00026 }
00027
00028
00029 EEqaSorterA::~EEqaSorterA() {
00030 for(int icr = 0;icr < MaxAnyCrate;icr++) {
00031 if (hCrate && hCrate[icr]) delete hCrate[icr];
00032 }
00033 if (hCrate) delete hCrate;
00034 for(int icr = 0;icr < MaxTwCrateID;icr++) {
00035 if (hCrateHot && hCrateHot[icr]) delete hCrateHot[icr];
00036 }
00037 if (hCrateHot) delete hCrateHot;
00038 }
00039
00040
00041 void EEqaSorterA::sort(const EztEmcRawData *t, const EztEmcRawData *s, int ver) {
00042 sortDaqTower1(t);
00043 sortDaqMapmt0(s, ver);
00044 sortDaqTowerHot(t);
00045 }
00046
00047
00048 void EEqaSorterA::Finish(){
00049 }
00050
00051
00052 void EEqaSorterA::sortDaqTower1(const EztEmcRawData *t){
00053
00054
00055
00056
00057 if(!t) return;
00058 for(int icr=0;icr<t->getNBlocks() && icr<MaxTwCrateID;icr++) {
00059 if(t->isCrateVoid(icr)) continue;
00060 int crateID=icr+1;
00061 const UShort_t* data=t->data(icr);
00062 for(int i=0;i<t->sizeData(icr) && i<MaxTwCrateCh;i++) {
00063 int chan=i;
00064 float adc=data[i];
00065 if (hCrate && hCrate[crateID - 1]) hCrate[crateID - 1]->Fill(adc, chan);
00066 }
00067 }
00068 }
00069
00070
00071 void EEqaSorterA::sortDaqTowerHot(const EztEmcRawData *t){
00072
00073
00074
00075
00076 if(!t) return;
00077 for(int icr=0;icr<t->getNBlocks() && icr<MaxTwCrateID;icr++) {
00078 if(t->isCrateVoid(icr)) continue;
00079 int crateID=icr+1;
00080 const UShort_t* data=t->data(icr);
00081 int *pedA= &feePed[(crateID-1)*MaxTwCrateCh];
00082 if (data) for(int i=0;i<t->sizeData(icr) && i<MaxTwCrateCh;i++) {
00083 int chan=i;
00084 float adc=data[i]-24+ pedA[i];
00085 if(adc<hotTwThres) continue;
00086 if (hCrateHot && hCrateHot[crateID-1]) hCrateHot[crateID-1]->Fill(chan);
00087 }
00088 }
00089 }
00090
00091
00092 void EEqaSorterA::sortDaqMapmt0(const EztEmcRawData *s, int ver){
00093
00094
00095
00096 if(!s) return;
00097 for(int icr=0;icr<s->getNBlocks();icr++) {
00098 if(s->isCrateVoid(icr)) continue;
00099 int crateID=icr+64;
00100
00101 if(ver<0x22) {
00102 if(icr>=16) break;
00103 crateID=icr+84;
00104 }
00105 const UShort_t* data=s->data(icr);
00106 for(int i=0;i<s->sizeData(icr) && i<MaxMapmtCrateCh;i++) {
00107 int chan=i;
00108 float adc=data[i];
00109 if (hCrate && hCrate[crateID-1]) hCrate[crateID-1]->Fill(adc,chan);
00110 }
00111 }
00112
00113 }
00114
00115
00116 void EEqaSorterA::initCrateHisto(TObjArray *HList, int nBin, int mxADC) {
00117 const char *sectL[]={"11TD-1TC", "1TD-3TC", "3TD-5TC", "5TD-7TC", "7TD-9TC", "9TD-11TC"};
00118 LOG_DEBUG << Form(" EEqaSorterA::initCrateHisto(nb=%d, max=%d)\n", nBin,mxADC) << endm;
00119
00120 int nOK=0;
00121 hCrate = new TH2F *[MaxAnyCrate];
00122 for(int icr=0;icr<MaxAnyCrate;icr++) {
00123
00124 int crateID=icr+1;
00125 hCrate[icr]=0;
00126 int mxChan=0;
00127 TString physDet;
00128 if(crateID>=MinTwCrateID && crateID<=MaxTwCrateID) {
00129
00130 mxChan=MaxTwCrateCh;
00131 physDet=sectL[crateID-1];
00132 } else if (crateID>=MinMapmtCrateID && crateID<=MaxMapmtCrateID ){
00133
00134 mxChan=MaxMapmtCrateCh;
00135 int sec=1+(7+crateID/4)%MaxSectors;
00136 int box=1+crateID%4;
00137 physDet = (box==4) ? Form("%dP1",sec) : Form("%dS%d",sec,box);
00138 }
00139
00140 if(mxChan==0) continue;
00141 nOK++;
00142 hCrate[icr] = new TH2F(Form("cr%d",crateID),Form(" %s",physDet.Data()),nBin,-0.5, mxADC-0.5, mxChan, -0.5, mxChan-0.5);
00143 if (HList) HList->Add(hCrate[icr]);
00144
00145 }
00146 hCrateHot = new TH1F *[MaxTwCrateID];
00147 for(int icr=0;icr<MaxTwCrateID;icr++) {
00148 int crateID=icr+1;
00149 hCrateHot[icr]=0;
00150 int mxChan=MaxTwCrateCh;
00151 hCrateHot[icr] = new TH1F(Form("cr%dHot",crateID),Form("%s thr=feePed+%d",sectL[crateID-1],hotTwThres), mxChan, -0.5, mxChan-0.5);
00152 hCrateHot[icr]->SetFillColor(kBlue);
00153 if (HList) HList->Add(hCrateHot[icr]);
00154 }
00155 LOG_DEBUG << "Initialized " << nOK << " 2D carte-histos" << endm;
00156 }
00157
00158 void EEqaSorterA::saveHisto(TFile *f) const {
00159 if (f) f->cd();
00160 for(int icr = 0;icr < MaxAnyCrate;icr++) {
00161 if (hCrate && hCrate[icr]) hCrate[icr]->Write();
00162 }
00163 for(int icr = 0;icr < MaxTwCrateID;icr++) {
00164 if (hCrateHot && hCrateHot[icr]) hCrateHot[icr]->Write();
00165 }
00166 }
00167
00168 void EEqaSorterA::resetHisto() {
00169 for(int icr = 0;icr < MaxAnyCrate;icr++) {
00170 if (hCrate && hCrate[icr]) hCrate[icr]->Reset();
00171 }
00172 for(int icr = 0;icr < MaxTwCrateID;icr++) {
00173 if (hCrateHot && hCrateHot[icr]) hCrateHot[icr]->Reset();
00174 }
00175 }
00176
00177
00178 int EEqaSorterA::usePed4(const Char_t *filename) {
00179 int ok = 0;
00180
00181 LOG_DEBUG << " EEqaSorterA::usePed4(\"" << filename << "\") ..." << endm;
00182 FILE *fd=fopen(filename,"r");
00183 if (fd) {
00184 ok = 1;
00185 for(int cr=MinTwCrateID;cr<=MaxTwCrateID;cr++) {
00186 for(int ch=0;ch<MaxTwCrateCh; ch++) {
00187 int xcr = -1, xch = -1, ped4 = 0;
00188 float xped = 0;
00189 int ret=fscanf(fd,"%d %d %f %d",&xcr,&xch,&xped,&ped4);
00190 if ((ret == 4) && (xcr >= MinTwCrateID) && (xcr <= MaxTwCrateID) && (xch >= 0) && (xch < MaxTwCrateCh)) {
00191 feePed[(xcr - 1)*MaxTwCrateCh + xch]=4*ped4;
00192 } else {
00193 LOG_ERROR << "Bad format in " << filename << ": read xcr=" << xcr << ", xch=" << xch << ", xped=" << xped << ", ped4=" << ped4 << ", ret=" << ret << "; expected xcr=" << cr << ", xch=" << ch << endm;
00194 ok = 0;
00195 }
00196 }
00197 }
00198 fclose(fd);
00199 fd = 0;
00200 LOG_DEBUG << " EEqaSorterA::usePed4(...) Loaded" << endm;
00201 } else {
00202 LOG_ERROR << "Cannot read file " << filename << endm;
00203 }
00204 return ok;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253