38 #include "StPmdUtil/StPmdGeom.h"
39 #include "StPmdCalibConstMaker.h"
40 #include "StPmdUtil/StPmdDetector.h"
41 #include "StPmdUtil/StPmdModule.h"
42 #include "StPmdUtil/StPmdCollection.h"
43 #include "StPmdUtil/StPmdHit.h"
45 #include "TStopwatch.h"
46 #include "StarClassLibrary/SystemOfUnits.h"
50 #include "StDbLib/StDbManager.hh"
51 #include "StDbLib/StDbTable.h"
52 #include "StDbLib/StDbConfigNode.hh"
54 #ifndef ST_NO_NAMESPACES
69 Double_t MipArray[PMD_CRAMS_MAX*2][PMD_ROW_MAX][PMD_COL_MAX][MIP_CH_MAX];
75 Int_t StPmdCalibConstMaker::neiby[PMD_CELL_NEIGHBOUR] = {0,1,1,0,-1,-1};
77 Int_t StPmdCalibConstMaker::imax[2*PMD_CRAMS_MAX] = {48,72,48,72,72,72,48,48,48,72,72,96,48,72,48,72,72,72,48,48,48,72,72,96};
79 Int_t StPmdCalibConstMaker::jmax[2*PMD_CRAMS_MAX] = {48,48,72,72,48,48,48,72,48,72,48,72,48,48,72,72,48,48,48,72,48,72,48,72};
83 StPmdCalibConstMaker::StPmdCalibConstMaker(
const char *name):
StMaker(name)
86 mSaveCalibToDB = kTRUE;
98 cout <<
"**** I am in StPmdCalibConstMaker::~StPmdCalibConstMaker()"<< endl;
100 if(mPmdGeom){mPmdGeom=0;
delete mPmdGeom;}
101 if(mPmdDbUtil){mPmdDbUtil=0;
delete mPmdDbUtil;}
102 if(mOptHist)ClearHists();
109 if(mOptHist)BookHistograms();
123 return StMaker::Init();
127 void StPmdCalibConstMaker::BookHistograms()
130 for(Int_t sm=0;sm<2*PMD_CRAMS_MAX;sm++){
131 for(Int_t i =0;i<imax[sm];i++){
132 for(Int_t j =0;j<jmax[sm];j++){
133 char text[40],title[80];
134 sprintf(text,
"calib_%02d_%02d_%02d",sm,i,j);
135 sprintf(title,
"MIP plot for %02d_%02d_%2d",sm,i,j);
136 mMipEnergy[sm][i][j]=
new TH1F(text,title,200,0.,150.);
147 if (mDate==0) {mDate = GetDate();}
148 if (mTime==0) {mTime = GetTime();}
150 TDataSet* CalibIn = GetDataSet(
"pmdReader");
151 if (!CalibIn){CalibIn = GetDataSet(
"PmdSimulator");}
157 GetIsoHit(pmd_det,cpv_det);
160 else{cout<<
"Could not find Simulator/Reader"<<endl;
return kStOK;}
170 Int_t xpad,ypad,gsuper,idet;
172 Float_t d0[PMD_ROW_MAX][PMD_COL_MAX];
175 for(Int_t
id=0;
id<PMD_CRAMS_MAX;
id++){
176 for(Int_t j=0;j<PMD_ROW_MAX;j++){
178 for(Int_t k=0;k<PMD_COL_MAX;k++){
187 TIter next(cpv_mod->Hits());
189 for(Int_t im=0; im<nmh; im++){
194 xpad=spmhit0->Column();
195 edep=spmhit0->Edep();
196 Int_t adc=spmhit0->Adc();
197 gsuper = spmhit0->Gsuper();
198 idet=spmhit0->SubDetector();
200 if((xpad>0 && xpad<=PMD_ROW_MAX) && (ypad>0 && ypad <=PMD_COL_MAX))d0[xpad-1][ypad-1]=adc;
207 for(Int_t i=0;i<imax[id];i++){
208 for(Int_t j=0;j<jmax[id];j++){
211 for(Int_t ii=0;ii<PMD_CELL_NEIGHBOUR;ii++){
212 Int_t id1 = i + neibx[ii];
213 Int_t jd1 = j + neiby[ii];
214 if(d0[id1][jd1]==0.){
216 if(count == PMD_CELL_NEIGHBOUR){
217 gsuper = spmhit0->Gsuper();
219 if(mOptHist)
mMipEnergy[gsuper][i][j]->Fill(d0[i][j]);
220 Int_t channel=(Int_t)d0[i][j];
221 if(channel<MIP_CH_MAX)MipArray[gsuper][i][j][channel]++;
236 Float_t d1[PMD_ROW_MAX][PMD_COL_MAX];
239 for(Int_t
id=0;
id<PMD_CRAMS_MAX;
id++){
240 for(Int_t j=0;j<PMD_ROW_MAX;j++){
242 for(Int_t k=0;k<PMD_COL_MAX;k++){
250 TIter next(pmd_mod->Hits());
252 for(Int_t im=0; im<nmh; im++){
257 xpad=spmhit1->Column();
258 edep=spmhit1->Edep();
259 Int_t adc=spmhit1->Adc();
260 gsuper = spmhit1->Gsuper();
261 idet=spmhit1->SubDetector();
263 if((xpad>0 && xpad<=PMD_ROW_MAX) && (ypad>0 && ypad <=PMD_COL_MAX))d1[xpad-1][ypad-1]=adc;
270 for(Int_t i=0;i<imax[id];i++){
271 for(Int_t j=0;j<jmax[id];j++){
274 for(Int_t ii=0;ii<PMD_CELL_NEIGHBOUR;ii++){
275 Int_t id1 = i + neibx[ii];
276 Int_t jd1 = j + neiby[ii];
277 if(d1[id1][jd1]==0.){
279 if(count == PMD_CELL_NEIGHBOUR){
280 gsuper = spmhit1->Gsuper();
281 gsuper = gsuper + 11;
282 if(mOptHist)
mMipEnergy[gsuper][i][j]->Fill(d1[i][j]);
283 Int_t channel=(Int_t)d1[i][j];
284 if(channel<MIP_CH_MAX)MipArray[gsuper][i][j][channel]++;;
300 Float_t MipFitParam[3];
301 Float_t MipFitChiSqr, MipPeakPosition, MipPeakWidth;
302 TF1 LandauFunction(
"LandauFunction",
"landau",0,100);
303 LandauFunction.SetParameters(1,1,1);
304 LandauFunction.SetParNames(
"Constant",
"MPV",
"Sigma");
309 for(Int_t sm=0;sm<2*PMD_CRAMS_MAX;sm++){
310 for(Int_t i =0;i<imax[sm];i++){
311 for(Int_t j =0;j<jmax[sm];j++){
313 miphist=
new TH1F(
"miphist",
"MipHist",200,0.,140.);
314 for(Int_t k =0;k<10;k++){
315 miphist->SetBinContent(k+1,(Stat_t)MipArray[sm][i][j][k]);
317 entryFlag = miphist->GetEntries();
319 if(mOptHist)entryFlag =
mMipEnergy[sm][i][j]->GetEntries();
322 if(entryFlag > MIP_MIN_ENTRY){
323 if(mOptHist)
mMipEnergy[sm][i][j]->Fit(
"LandauFunction",
"q",
"r");
324 if(!mOptHist)miphist->Fit(
"LandauFunction",
"q",
"r");
325 for(Int_t m=0; m < 3; m++){
326 MipFitParam[m] = LandauFunction.GetParameter(m);
329 if(MipFitParam[1] > 0.){
330 MPV_Sum = MPV_Sum + MipFitParam[1];
331 MPV_Entry[sm][i][j] = MipFitParam[1];
334 MipFitChiSqr = LandauFunction.GetChisquare();
337 MipPeakPosition =
mMipEnergy[sm][i][j]->GetMean();
338 MipPeakWidth =
mMipEnergy[sm][i][j]->GetRMS();
341 MipPeakPosition = miphist->GetMean();
342 MipPeakWidth = miphist->GetRMS();
346 mPmdDbUtil->BoardNumber(sm,i,j,BrdNo);
348 mPmdDbUtil->ChannelInBoard(sm,i,j,BrdCh);
351 mMipWidth[BrdNo][BrdCh]=MipPeakWidth;
354 if(!mOptHist)
delete miphist;
359 Float_t MPV_Av = MPV_Sum/MPV_Count;
362 for(Int_t sm=0;sm<2*PMD_CRAMS_MAX;sm++){
363 for(Int_t i =0;i<imax[sm];i++){
364 for(Int_t j =0;j<jmax[sm];j++){
365 if(MPV_Entry[sm][i][j] > 0.)
366 normFactor[sm][i][j] = (Float_t) MPV_Av/(Float_t) MPV_Entry[sm][i][j];
368 mPmdDbUtil->BoardNumber(sm,i,j,BrdNo);
370 mPmdDbUtil->ChannelInBoard(sm,i,j,BrdCh);
381 cout <<
" *** I am in StPmdCalibConstMaker::Finish() " << endl;
387 if(mSaveCalibToDB)SaveCalibration();
389 gMessMgr->Info(
"StPmdCalibConstMaker::Finish()");
395 void StPmdCalibConstMaker::SaveCalibration()
398 cout <<
" ***** I am now saving the Calibration to DB : Wait !!" << endl;
411 StDbTable* tab1=node->addDbTable(
"pmdBrdMipCalib");
412 StDbTable* tab2=node->addDbTable(
"pmdCalSummary");
413 pmdBrdMipCalib_st pbd[PMD_BOARD_MAX];
414 memset(pbd,0,PMD_BOARD_MAX*
sizeof(pmdBrdMipCalib_st));
415 for(Int_t ism=0;ism<2*PMD_CRAMS_MAX;ism++){
416 for(Int_t irow=0;irow<jmax[ism];irow++){
417 for(Int_t icol=0;icol<imax[ism];icol++){
420 mPmdDbUtil->BoardNumber(ism,irow,icol,brd);
421 mPmdDbUtil->ChannelInBoard(ism,irow,icol,brd_ch);
422 pbd[brd].FEEBoardNumber = brd;
425 pbd[brd].MipPeakPosition[brd_ch] = mMipPeak[brd][brd_ch];
426 pbd[brd].MipPeakWidth[brd_ch] = mMipWidth[brd][brd_ch];
430 tab1->
SetTable((
char*)pbd,PMD_BOARD_MAX);
432 pmdCalSummary_st pcs[1];
433 memset(pcs,0,
sizeof(pmdCalSummary_st));
440 sprintf(timestamp,
"%08d%06d",mDate,mTime);
441 mgr->setStoreTime(timestamp);
443 cout<<
"PMD Calib: storing in DB"<<endl;
445 mgr->storeDbTable(tab1);
446 mgr->storeDbTable(tab2);
447 cout<<
"PMD Calib: Stored in DB "<<endl;
452 void StPmdCalibConstMaker::InitMipParams()
454 for(Int_t i=0;i<PMD_BOARD_MAX;i++){
455 for(Int_t j=0;j<PMD_BOARD_CH_MAX;j++){
463 void StPmdCalibConstMaker::ClearHists()
465 cout <<
" *** Let me to clear the Histograms in PmdCalib" << endl;
467 for(Int_t sm=0;sm<2*PMD_CRAMS_MAX;sm++){
468 for(Int_t i =0;i<imax[sm];i++){
469 for(Int_t j =0;j<jmax[sm];j++){
479 void StPmdCalibConstMaker::ClearMipArray()
481 for(Int_t sm=0;sm<2*PMD_CRAMS_MAX;sm++){
482 for(Int_t i =0;i<imax[sm];i++){
483 for(Int_t j =0;j<jmax[sm];j++){
484 for(Int_t k =0;k<MIP_CH_MAX;k++){
485 MipArray[sm][i][j][k]=0;
Int_t module_hit(Int_t)
module number
StPmdDetector * detector(Int_t)
destructor
TH1F * mMipEnergy[2 *PMD_CRAMS_MAX][PMD_ROW_MAX][PMD_COL_MAX]
booking Pmd cluster histograms
virtual Int_t Init()
Init method.
virtual ~StPmdCalibConstMaker()
Default destructor.
Float_t normFactor[2 *PMD_CRAMS_MAX][PMD_ROW_MAX][PMD_COL_MAX]
deposited energy of isolated cells
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc'd version of data for StRoot
virtual Int_t Make()
Make mathod - process each event.
virtual Int_t Finish()
Finish method - save final numbers.
static StDbManager * Instance()
strdup(..) is not ANSI
StPmdModule * module(unsigned int)
number of hits
virtual Int_t FindMipParameters()
virtual TDataSet * Find(const char *path) const