00001
00002
00003
00004
00005 #include <TFile.h>
00006 #include <TH1.h>
00007 #include <TF1.h>
00008 #include <StMessMgr.h>
00009
00010 #include "StFeePedMaker.h"
00011
00012 #include "StMuDSTMaker/COMMON/StMuEvent.h"
00013 #include "StMuDSTMaker/COMMON/StMuDst.h"
00014 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
00015
00016 #include "StMuDSTMaker/EZTREE/EztEventHeader.h"
00017 #include "StMuDSTMaker/EZTREE/EztEmcRawData.h"
00018
00019 ClassImp(StFeePedMaker)
00020
00021
00022
00023 StFeePedMaker::StFeePedMaker( const char* self ,const char* muDstMakerName) : StMaker(self){
00024 mMuDstMaker = (StMuDstMaker*)GetMaker(muDstMakerName);
00025 assert(mMuDstMaker);
00026
00027 nInpEve=0;
00028 HList=0;
00029
00030 }
00031
00032
00033
00034
00035 StFeePedMaker::~StFeePedMaker(){
00036
00037 }
00038
00039
00040
00041 void
00042 StFeePedMaker::saveHisto(TString fname){
00043 TString outName=fname+".hist.root";
00044 TFile f( outName,"recreate");
00045 assert(f.IsOpen());
00046 printf("%d histos are written to '%s' ...\n",HList->GetEntries(),outName.Data());
00047 HList->Write();
00048 f.Close();
00049
00050 }
00051
00052
00053
00054 Int_t
00055 StFeePedMaker::Init(){
00056
00057 assert(HList);
00058
00059 int i,j;
00060
00061 for(i=0;i<MaxTwCrates;i++) {
00062 int crate=i+MinTwCrateID;
00063 for (j=0;j<MaxTwCrateCh;j++){
00064 char tt1[100], tt2[100];
00065 sprintf(tt1,"cr%d_ch%3.3d",crate,j);
00066 sprintf(tt2,"Pedestals for Crate %d and FEE ch %d",crate,j);
00067 TH1F* h=new TH1F(tt1,tt2,400,-0.5,395.5);
00068 HList->Add(h);
00069 int k=MaxTwCrateCh*i+j;
00070
00071 hped[k]=h;
00072 }
00073 }
00074 printf("Initialized %d tower histos\n",MxTwFeeCh);
00075
00076 return StMaker::Init();
00077 }
00078
00079
00080
00081 Int_t
00082 StFeePedMaker::Finish(){
00083 return kStOK;
00084 }
00085
00086
00087
00088
00089 Int_t
00090 StFeePedMaker::Make(){
00091 nInpEve++;
00092
00093 gMessMgr->Message("","D") <<GetName()<<"::Make() is called "<<endm;
00094
00095
00096 EztEventHeader* header= mMuDstMaker->muDst()->eztHeader();
00097 if(header==0) {
00098 gMessMgr->Message("","E") <<GetName()<<"::Make() no EztEventHeader, skip event "<<endm;
00099 return kStOK;
00100 }
00101
00102 int token= header->getToken();
00103 EztEmcRawData* eETow=mMuDstMaker->muDst()->eztETow();
00104 assert(eETow);
00105
00106
00107 int lenCount=0xa4;
00108 int errFlag=0;
00109 int trigComm=0x4;
00110
00111 int nOK=0;
00112 int icr;
00113 for(icr=0;icr<eETow->getNBlocks();icr++) {
00114 if(eETow->isCrateVoid(icr)) continue;
00115 if(eETow->purgeCrateOFF(icr)) continue;
00116 int crID=icr+1;
00117 eETow->tagHeadValid(icr,token, crID,lenCount,trigComm,errFlag);
00118 UShort_t isSick=eETow->getCorruption(icr);
00119 if(isSick) continue;
00120 nOK++;
00121 }
00122
00123
00124 if(nOK!=MaxTwCrates) return kStOK;
00125
00126
00127
00128
00129 for(icr=0;icr<eETow->getNBlocks();icr++) {
00130 if(eETow->isCrateVoid(icr)) continue;
00131 int i;
00132 const UShort_t* data=eETow->data(icr);
00133 for(i=0;i<eETow->sizeData(icr);i++) {
00134 int chan=i;
00135 if(chan>=MaxTwCrateCh) continue;
00136 float adc=data[i];
00137
00138 int k=icr*MaxTwCrateCh+chan;
00139
00140 assert(k>=0 && k<MxTwFeeCh);
00141 hped[k]->Fill(adc);
00142 }
00143 }
00144
00145 return kStOK;
00146 }
00147
00148
00149
00150
00151 Int_t
00152 StFeePedMaker::fitPed(TH1F *h, int Xlow, int Xhigh) {
00153 int sumMin=100;
00154 if (h->GetEntries() < sumMin) return -1;
00155
00156
00157 float *y=h->GetArray();
00158
00159 float ym=0,sum=0;
00160 int i;
00161 int j=-1;
00162 for(i=2;i<=100;i++){
00163 sum+=y[i];
00164 if(ym>y[i]) continue;
00165 ym=y[i];
00166 j=i;
00167 }
00168
00169 if (sum < sumMin) return -2;
00170
00171 float xm=h->GetBinCenter(j);
00172 float x1=xm-Xlow;
00173 float x2=xm+Xhigh;
00174
00175
00176
00177 TF1* fitF = new TF1("pedFun","gaus");
00178 fitF->SetLineColor(kGreen);;
00179 fitF->SetLineWidth(1);;
00180 h->Fit(fitF,"RQ+W","",x1,x2);
00181
00182 return 0;
00183 }
00184
00185
00186
00187
00188
00189
00190