00001 #include <stdio.h>
00002 #include <assert.h>
00003 #include <string.h>
00004
00005
00006 #include <TObjArray.h>
00007 #include <TClonesArray.h>
00008
00009 #include <TH2.h>
00010 #include <TF2.h>
00011 #include <TFile.h>
00012
00013 #include "StMuDSTMaker/EZTREE/EztEmcRawData.h"
00014
00015 #include "StEEmcUtil/EEfeeRaw/EEname2Index.h"
00016 #include "StEEmcUtil/EEfeeRaw/EEdims.h"
00017
00018 #include "StEEmcUtil/database/EEmcDbItem.h"
00019 #include "StEEmcUtil/database/StEEmcDb.h"
00020
00021 #include "RawPixels.h"
00022
00023
00024
00025 RawPixels::RawPixels(TObjArray*L,StEEmcDb*dbx) {
00026
00027
00028 HList=L; assert(HList);
00029 hPix=new TH1F * [EEindexMax];
00030 memset(hPix,0,sizeof(void*)*EEindexMax);
00031
00032 hSmd=new TH2F * [MaxSmdPlains*MaxSectors];
00033 memset(hSmd,0,sizeof(void*)*MaxSmdPlains*MaxSectors);
00034
00035 eeDb=dbx;
00036 setLimits(0,0);
00037 }
00038
00039
00040
00041
00042 void RawPixels::initHisto() {
00043 assert(eeDb);
00044
00045 assert(c_x1>=0);
00046 assert(c_x2>c_x1);
00047
00048 TString mode="";
00049 switch(c_convMode) {
00050 case kRawAdc: mode="rawAdc"; break;
00051 case kPedSub: mode="pedSub"; break;
00052 case kPedAndGain: mode="pedAndGain"; break;
00053 default:
00054 assert(2==3);
00055 }
00056
00057 int i,k=0;
00058 for(i=0;i<EEindexMax;i++) {
00059 const EEmcDbItem *x=eeDb->getByIndex(i);
00060 if(x==0) continue;
00061
00062 k++;
00063 char tt1[100],tt2[200];
00064 sprintf(tt1,"a%s",x->name);
00065 sprintf(tt2,"ADC for %s, cr/chan=%3.3d/%3.3d, tube=%s; ADC (mode=%s)",x->name,
00066 x->crate,x->chan,x->tube,mode.Data());
00067 TH1F* h=new TH1F(tt1,tt2,c_x2-c_x1+1,c_x1-0.5,c_x2+0.5);
00068 hPix[i]=h;
00069 HList->Add(h);
00070
00071 }
00072
00073
00074 int sec1=eeDb->getFirstSecID();
00075 int sec2=eeDb->getLastSecID();
00076 int secID;
00077 for(secID=sec1; secID<=sec2; secID++) {
00078 int iuv;
00079 for(iuv=0;iuv<MaxSmdPlains;iuv++) {
00080 char tt1[100], tt2[100];
00081 sprintf(tt1,"a%2.2d%c",secID,iuv+'U');
00082 sprintf(tt2,"%2.2d%c-SMD strip vs. raw ADC",secID,iuv+'U');
00083 TH2F* h2=new TH2F(tt1,tt2,200,0,4000,MaxSmdStrips,0.5,MaxSmdStrips+0.5);
00084 int key1=secID-1+iuv*MaxSectors;
00085 hSmd[key1]=h2;
00086 HList->Add(h2);
00087
00088 }
00089 }
00090
00091
00092 {
00093 char tt2[100];
00094 sprintf(tt2," stat info ");
00095
00096 hInfo=new TH1F("info",tt2,20,-0.5,19.5);
00097 HList->Add(hInfo);
00098 }
00099
00100 printf("RawPixels: Initialized histos for %d pixels\n",k);
00101 }
00102
00103
00104
00105 void RawPixels::sort(EztEmcRawData *eRaw){
00106
00107 assert(eeDb);
00108
00109 hInfo->Fill(0);
00110 if(eRaw==0) return;
00111
00112 int icr;
00113 for(icr=0;icr<eRaw->getNBlocks();icr++) {
00114 if(eRaw->isCrateVoid(icr)) continue;
00115 const UShort_t* data=eRaw->data(icr);
00116 int crateID=eRaw->getCrateID(icr);
00117 hInfo->Fill(crateID);
00118 int nd=eRaw->sizeData(icr);
00119
00120
00121 int chan;
00122 for(chan=0;chan<nd;chan++) {
00123 const EEmcDbItem *x=eeDb->getByCrate(crateID,chan);
00124 if(x==0) continue;
00125
00126
00127 float value=data[chan];
00128 switch(c_convMode) {
00129 case kRawAdc: break;
00130 case kPedSub:
00131 value-=x->ped; break;
00132 case kPedAndGain:
00133 value-=x->ped;
00134 value/=x->gain;
00135
00136 break;
00137 default:
00138 assert(2==3);
00139 }
00140
00141 hPix[x->key]->Fill(value);
00142
00143
00144 if(x->isSMD()) {
00145 int key=(x->plane-'U')*MaxSectors + x->sec-1;
00146
00147
00148 #if 0
00149 if(key<=0 || key>=MaxSmdPlains*MaxSectors) {
00150 printf("cr=%2d ch=%3d val=%.1f ped=%4.1f '%s' \n",crateID,chan,value,x->ped,x->name);
00151 x->print();
00152 printf("key=%d\n",key);
00153 }
00154 #endif
00155
00156 assert(key>=0 && key<MaxSmdPlains*MaxSectors);
00157 assert(hSmd[key]);
00158 hSmd[key]->Fill(value,x->strip);
00159 }
00160
00161
00162 }
00163 }
00164
00165 }