1 #include "StMuEEmcCrateTimingMaker.h"
6 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
7 #include "StMuDSTMaker/COMMON/StMuDst.h"
8 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
10 #include "StMuDSTMaker/EZTREE/EztEventHeader.h"
11 #include "StMuDSTMaker/EZTREE/EztEmcRawData.h"
16 mMuDstMaker = mudstmaker;
30 outputFile = mDirectory +
"/eemc" + mFlavor +
"Crates-timeDelay";
32 sprintf(samus,
"%0.2f.root",mTimeDelay);
34 mOutputFile =
new TFile(outputFile.Data(),
"RECREATE");
35 mOutputTree =
new TTree(
"ints",
"Integrals of Each Channel");
36 kludge = MxMapmtFeeCh;
40 mOutputTree->Branch(
"kludge",&kludge,
"kludge/I");
41 mOutputTree->Branch(
"chanint",totalIntegral,
"chanint[kludge]/F");
42 mOutputTree->Branch(
"chanerr",totalError,
"chanerr[kludge]/F");
43 mOutputTree->Branch(
"delay",&mTimeDelay,
"delay/F");
44 mOutputTree->Branch(
"channelIds",channelIds,
"channelIds[kludge]/I");
45 mOutputTree->Branch(
"crateIds",crateIds,
"crateIds[kludge]/I");
46 mOutputTree->Branch(
"mPhase",&mPhase,
"mPhase/I");
47 mOutputTree->Branch(
"mCycle",&mCycle,
"mCycle/I");
49 TString tmpstr =
"histograms for " + mFlavor +
" crate channels";
52 cratehist =
new TH2F(
"cratehistogram",tmpstr.Data(),MxMapmtFeeCh,-0.5,MxMapmtFeeCh + 0.5,500,0,500);
53 cratehist->GetXaxis()->SetTitle(
"crate channel id");
54 cratehist->GetYaxis()->SetTitle(
"adc");
57 for(
int i=0; i<MxMapmtFeeCh; i++) {
75 int token= header->getToken();
78 if(mFlavor ==
"tower") {
81 }
else if(mFlavor ==
"mapmt") {
86 std::cout <<
"Unknown flavor you fool! " << mFlavor << std::endl;
98 for(
int icr=0;icr<eE->getNBlocks();icr++) {
99 if(eE->isCrateVoid(icr))
continue;
100 if(eE->purgeCrateOFF(icr))
continue;
102 if (mFlavor==
"mapmt") crID=64+icr;
103 eE->tagHeadValid(icr,token, crID,lenCount,trigComm,errFlag);
104 UShort_t isSick=eE->getCorruption(icr);
109 if((mFlavor ==
"mapmt" && nOK!=MaxMapmtCrates) ||
110 (mFlavor ==
"tower" && nOK!=MaxTwCrates)) {
111 cout <<
"SICK EVENTS IN THIS RUN" << endl;
116 totalIntegral[MxMapmtFeeCh-1]++;
143 for(
int icr=0; icr < eE->getNBlocks(); icr++ ) {
145 if(eE->isCrateVoid(icr))
continue;
146 const UShort_t*
data=eE->data(icr);
147 int j = icr*MaxMapmtCrateCh/16;
152 for(
int i=mPhase;i<eE->sizeData(icr);i+=mCycle,j++) {
154 if(i>=MaxMapmtCrateCh)
continue;
156 int k=(icr*MaxMapmtCrateCh+i)/16;
157 assert(k>=0 && k<MxMapmtFeeCh);
158 cratehist->Fill(j,adc);
182 TString outputFile = mDirectory +
"/eemc" + mFlavor +
"Crates-timeDelay";
184 sprintf(samus,
"%0.2f.txt",mTimeDelay);
186 ofstream ofs(outputFile.Data());
187 ofs <<
"-1" <<
"\t" << setprecision(5) << totalIntegral[MxMapmtFeeCh-1] << endl;
189 for (Int_t i = 2; i <= cratehist->GetXaxis()->GetNbins(); i++) {
190 Int_t chanId =
static_cast<Int_t
>(cratehist->GetXaxis()->GetBinCenter(i));
192 TH1D* proj = cratehist->ProjectionY(
"projTemp",i,i);
197 if ( proj -> GetEntries() < mMinCounts )
201 Float_t maxValue = -1;
202 for (Int_t j = 1; j < proj->GetXaxis()->GetNbins(); j++) {
203 if (proj->GetBinContent(j) > maxValue) {
205 maxValue = proj->GetBinContent(j);
208 Float_t pedMean = proj->GetXaxis()->GetBinCenter(maxBin);
210 if ( !(( i - mPhase )%mCycle) ) {
212 TString myname=
"channel"; myname+=chanId;
213 TH1D *cl=(TH1D*)proj->Clone(myname);
220 TF1* gaus =
new TF1(
"gaus",
"gaus");
221 gaus->SetParameter(0,maxValue);
222 gaus->SetParameter(1,pedMean);
223 gaus->SetParameter(2,3.5);
224 gaus->SetRange(pedMean-10,pedMean+10);
225 proj->Fit(gaus,
"0RQ");
226 Float_t pedestalmean = gaus->GetParameter(1);
227 Float_t pedestalwidth = gaus->GetParameter(2);
230 Float_t xmin = pedestalmean;
232 xmin += mNsigma * pedestalwidth;
235 Int_t minBin = proj->GetXaxis()->FindFixBin( xmin );
237 maxBin = proj->GetXaxis()->GetNbins() - 1;
238 Stat_t nHitsAbovePedestal = proj->Integral(minBin,maxBin);
242 if ( nHitsAbovePedestal > 0. && totalIntegral[MxMapmtFeeCh-1] > 0. ) {
243 delR = 1.0 / nHitsAbovePedestal + 1.0 / totalIntegral[MxMapmtFeeCh-1];
246 totalIntegral[chanId] = nHitsAbovePedestal/totalIntegral[MxMapmtFeeCh-1];
247 totalError[chanId] = delR * totalIntegral[chanId];
249 ofs << chanId <<
"\t" << setprecision(5) << nHitsAbovePedestal/totalIntegral[MxMapmtFeeCh-1] << endl;
257 mOutputFile->Write();
static EztEmcRawData * eztESmd()
returns pointer to eztESmd +pre/post
static EztEventHeader * eztHeader()
returns pointer to eztHeader
static EztEmcRawData * eztETow()
returns pointer to ETOW