129 #include "StPmdReadMaker.h"
130 #include "St_DataSetIter.h"
132 #include "StDbLib/StDbManager.hh"
133 #include "StDbLib/StDbTable.h"
134 #include "StDbLib/StDbConfigNode.hh"
136 #include "StGlobals.hh"
137 #include "StPmdUtil/StPmdCollection.h"
138 #include "StPmdUtil/StPmdDetector.h"
139 #include "StPmdUtil/StPmdHit.h"
140 #include "StPmdUtil/StPmdModule.h"
141 #include "StPmdUtil/StPmdGeom.h"
142 #include "StPmdUtil/StPmdDBUtil.h"
143 #include<StMessMgr.h>
144 #include "StRtsTable.h"
145 #include "RTS/src/DAQ_PMD/pmd.h"
152 #include "StDaqLib/GENERIC/EventReader.hh"
153 #include "StDaqLib/PMD/PMD_Reader.hh"
154 #include "StDAQMaker/StDAQReader.h"
158 #include "StEvent/StEvent.h"
159 #include "StEvent/StEventTypes.h"
162 #include "StPmdCleanConstants.h"
163 Int_t BadChainZero[25];
165 Float_t SM_chain_factor[24][48];
169 ClassImp(StPmdReadMaker)
172 StPmdReadMaker::StPmdReadMaker(const
char *name) :
StRTSBaseMaker("pmd",name)
175 mEvtPmdCollection=NULL;
182 m_PmdCalibConst=NULL;
196 StPmdReadMaker::~StPmdReadMaker() {
197 delete mPmdGeom; mPmdGeom =0;
198 delete mPmdDBUtil; mPmdDBUtil =0;
212 Int_t StPmdReadMaker::Init() {
213 if(mPmdPrint)gMessMgr->Info(
"StPmdReadMaker::Init()");
214 mCalibFlag = !(IAttr(
"pmdRaw"));
218 return StMaker::Init();
222 Int_t StPmdReadMaker::InitRun(Int_t runnr) {
223 if(mPmdPrint)gMessMgr->Info(
"StPmdReaderMaker::InitRun()");
226 mPmdGeom->readBoardDetail(runnr);
229 if(mRunNumber < 5034042) mVmeCond = 1;
230 else if(mRunNumber >= 5034042 && mRunNumber < 5049020) mVmeCond = 2;
231 else if(mRunNumber >= 5049020 && mRunNumber < 6000000) mVmeCond = 3;
232 else if(mRunNumber >= 6000000 && mRunNumber < 7000000) mVmeCond = 4;
233 else if(mRunNumber >= 8000000 && mRunNumber < 9000000) mVmeCond = 5;
234 else if(mRunNumber >= 9000000) mVmeCond = 5;
240 for(Int_t i=0;i<25;i++) BadChainZero[i]=0;
242 ReadBadChains(runnr);
243 ReadCalibrationsConst();
259 return StMaker::InitRun(runnr);
264 void StPmdReadMaker::ReadBadChains(Int_t runNo){
267 mPmdGeom->GetRunYear(runNo,rn,year);
268 if(Debug())cout<<
"runNo="<<runNo<<
" year="<<year<<endl;
269 cout<<
"runNo="<<runNo<<
" year="<<year<<endl;
273 BadChain = PmdClean::BadChain_y12d172;
274 }
else if(runNo>12114000){
275 BadChain = PmdClean::BadChain_y12d114;
277 BadChain = PmdClean::BadChain_y12d0;
285 BadChain = PmdClean::BadChain_y10d148;
286 }
else if(runNo>11105000){
287 BadChain = PmdClean::BadChain_y10d105;
288 }
else if(runNo>11100000){
289 BadChain = PmdClean::BadChain_y10d100;
290 }
else if(runNo>11091000){
291 BadChain = PmdClean::BadChain_y10d91;
292 }
else if(runNo>11001000){
293 BadChain = PmdClean::BadChain_y10d0;
300 BadChain = PmdClean::BadChain_y8d342;
301 }
else if(runNo>8143000){
302 BadChain = PmdClean::BadChain_y8d143;
303 }
else if(runNo>8135000){
304 BadChain = PmdClean::BadChain_y8d135;
305 }
else if(runNo>8131000){
306 BadChain = PmdClean::BadChain_y8d131;
307 }
else if(runNo>8122000){
308 BadChain = PmdClean::BadChain_y8d122;
309 }
else if(runNo>8116000){
310 BadChain = PmdClean::BadChain_y8d116;
311 }
else if(runNo>8108000){
312 BadChain = PmdClean::BadChain_y8d108;
313 }
else if(runNo>8102000){
314 BadChain = PmdClean::BadChain_y8d102;
315 }
else if(runNo > 8095000){
316 BadChain = PmdClean::BadChain_y8d95;
317 }
else if(runNo>8089001){
318 BadChain = PmdClean::BadChain_y8d89;
320 BadChain = PmdClean::BadChain_y8d0;
323 BadChain = BadChainZero;
326 if (BadChain[0]>0 && Debug()){
328 cout<<
"BadChains are ";
329 for(Int_t i=0;i<25;i++){
330 if (BadChain[i]>0) cout<<BadChain[i]<<
" ";
360 Int_t StPmdReadMaker::Make() {
362 if(mPmdPrint)gMessMgr->Info(
"StPmdReadMaker::Make()");
363 Int_t adc[2*PMD_CRAMS_MAX*2*(PMD_CRAMS_CH_MAX)];
365 mPmdGeom->GetRunYear(mRunNumber,rn,year);
366 if(Debug())cout<<
"runNo="<<mRunNumber<<
" year="<<year<<endl;
377 for (
int sector=1; sector<2;++sector) {
379 while ( GetNextLegacy(sector) ) {
383 for(Int_t crate=0;crate<2;crate++) {
385 for(Int_t c=0;c<12;c++) {
386 for(Int_t s=0;s<2;s++) {
389 for(Int_t ch=0;ch<1728;ch++) {
390 if(s==0){ nChain=c+12*crate;}
391 if(s==1){ nChain=(c+24)+12*crate;}
392 Double_t ped_mean= (double)fpmd->ped[crate][c][s][ch]/16.0;
393 Double_t ped_rms= (
double)fpmd->rms[crate][c][s][ch]/16.0;
395 Int_t adc_ch = fpmd->adc[crate][c][s][ch];
396 if(adc_ch>0 && chmax<ch) {chmax = ch; chain = nChain;}
397 adc[adcChCount]=adc_ch;
405 if(adc_ch>0 ||ped_mean>0){
406 chain_adc[nChain]->Fill(ch,adc_ch);
407 chain_mean[nChain]->Fill(ch,ped_mean);
408 chain_rms[nChain]->Fill(ch,ped_rms);
421 Int_t result=ApplyMapping(&adc[0]);
423 if(result!=
kStOK){gMessMgr->Info(
"Problem in getting PMD data:ApplyMap");
487 Int_t StPmdReadMaker:: ApplyMapping(
int *adc)
504 Int_t rn=0; Int_t year=0;
505 mPmdGeom->GetRunYear(mRunNumber,rn,year);
506 if(Debug())cout<<
"runNo="<<mRunNumber<<
" year="<<year<<endl;
510 gMessMgr->Info(
"Run number >11 , returning from applymapping ");
513 mPmdGeom->readBoardDetail(mRunNumber);
516 AddData(mPmdCollection);
521 Int_t Chain_No,supmod,row,col,SubDet=0,chtemp;
523 Int_t orig_nhits = 0;
525 Int_t nhits_sm[24]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
526 for(Int_t SEC=0; SEC < PMD_SECTOR; SEC++){
527 for(Int_t CRAM=0; CRAM < PMD_CRAMS_MAX; CRAM++){
528 for(Int_t BLOCK=0; BLOCK < PMD_CRAMS_BLOCK; BLOCK++){
529 for(Int_t CHANNEL=0; CHANNEL < PMD_CRAMS_CH_MAX; CHANNEL++){
530 Int_t channel=CHANNEL;
539 if(BLOCK==0)Chain_No=25+CRAM;
540 if(BLOCK==1)Chain_No=37+CRAM;
547 Chain_No=(CRAM+1)+(SEC*PMD_CRAMS_MAX)+(BLOCK*2*PMD_CRAMS_MAX);
552 if(SEC==0 && BLOCK==0 && CRAM==9) Chain_No = 39;
553 else if(SEC==0 && BLOCK==0 && CRAM==10) Chain_No = 40;
554 else Chain_No=(CRAM+1)+(SEC*PMD_CRAMS_MAX)+(BLOCK*2*PMD_CRAMS_MAX);
559 if(SEC==0 && BLOCK==0 && CRAM==5) Chain_No = 36;
560 else Chain_No=(CRAM+1)+(SEC*PMD_CRAMS_MAX)+(BLOCK*2*PMD_CRAMS_MAX);
566 if(SEC==0 && BLOCK==0 && CRAM==5) Chain_No = 36;
567 else Chain_No=(CRAM+1)+(SEC*PMD_CRAMS_MAX)+(BLOCK*2*PMD_CRAMS_MAX);
574 Int_t Chain_original=Chain_No;
575 if(Chain_original==45)Chain_No=46;
576 if(Chain_original==46)Chain_No=45;
583 if (Chain_No >= 1 && Chain_No < 25) SubDet = 2;
584 if (Chain_No >= 25 && Chain_No <= 48) SubDet = 1;
595 if(mRunNumber < 6000000)mapp=mPmdGeom->ChainMapping(Chain_No,channel,supmod,col,row,chtemp);
596 if(mRunNumber >= 6000000)mapp=mPmdGeom->ChainMapping(Chain_No,channel,supmod,col,row,chtemp,year);
597 Int_t DaqADC=adc[AddCh_Count];
599 if(channel==0)DaqADC=0;
603 if(DaqADC>0 && mapp==
kStOK){
606 m_chain_channel->Fill(channel,Chain_No-1);
610 Float_t cellgain = 1;
611 Float_t smchaingain = 1;
612 Float_t cellstatus = 1;
617 Float_t final_factor = 0;
619 if(supmod<=(2*PMD_CRAMS_MAX) && row <=PMD_ROW_MAX && col <=PMD_COL_MAX){
621 Int_t stCalib = GetCalib(supmod,row,col,calib);
622 if(stCalib !=
kStOK)gMessMgr->Info(
"Problem in getting Calibration Constant");
624 if(mRunNumber < 8000000){
628 if(mRunNumber >= 8000000){
631 smchaingain=SM_chain_factor[supmod-1][Chain_No-1];
633 final_factor=calib*SM_chain_factor[supmod-1][Chain_No-1];
635 if(!Accept(Chain_No,channel)){
663 edep = DaqADC *cellstatus/(cellgain*smchaingain);
670 nhits_sm[supmod-1]++;
671 if(supmod>PMD_CRAMS_MAX)supmod-=PMD_CRAMS_MAX;
673 pmdhit->setSubDetector(Int_t(SubDet));
674 pmdhit->setRow(Int_t(row));
675 pmdhit->setColumn(Int_t(col));
676 pmdhit->setAdc(Int_t(DaqADC));
677 pmdhit->setEdep(Float_t(edep));
679 pmdhit->setGainCell(Float_t(cellgain));
680 pmdhit->setGainSmChain(Float_t(smchaingain));
681 pmdhit->setCellStatus(Float_t(cellstatus));
683 if(SubDet==2)det0->
addHit(pmdhit);
684 if(SubDet==1)det1->
addHit(pmdhit);
696 cout<<
" NUmber of channels read ="<<AddCh_Count<<endl;
697 cout<<
" NUmber of original hits ="<<orig_nhits<<endl;
698 cout<<
" number of hits="<<nhits<<endl;
699 for(Int_t ism = 0;ism<24;ism++){
700 if(nhits_sm[ism]>0) cout<<
"number of hits in module "<<ism+1<<
" is ="<<nhits_sm[ism]<<endl;
703 if(mPmdPrint)gMessMgr->Info(
"StEvent to be called **");
704 Int_t testevt=fillStEvent(det0,det1);
706 gMessMgr->Info(
"Problem in fillStEvent");
719 gMessMgr->Info(
"NO STEVENT**");
728 currevent->setPhmdCollection(mEvtPmdCollection);
731 if(mEvtPmdCollection){
732 mPmdEvent = mEvtPmdCollection->detector(StDetectorId(kPhmdId));
733 mCpvEvent = mEvtPmdCollection->detector(StDetectorId(kPhmdCpvId));
749 for(Int_t
id=1;
id<(PMD_CRAMS_MAX+1);
id++){
759 TIter next(pmd_mod->Hits());
761 for(Int_t im=0; im<nmh1; im++)
765 Int_t subdet=spmcl1->SubDetector();
766 Int_t gsuper=spmcl1->Gsuper();
767 Int_t col=spmcl1->Column();
768 Int_t row=spmcl1->Row();
769 Float_t edep=spmcl1->Edep();
770 Int_t adc=spmcl1->Adc();
784 phit->setSuperModule(Int_t(gsuper-1));
785 phit->setSubDetector(Int_t(subdet-1));
786 phit->setRow(Int_t(row-1));
787 phit->setColumn(Int_t(col-1));
788 phit->setEnergy(edep);
791 if(mPmdEvent)mPmdEvent->addHit(phit);
803 cout<<
" PMD: Filled "<<nmh2<<
" hits in CPV"<<endl;
804 TIter next(cpv_mod->Hits());
806 for(Int_t im=0; im<nmh2; im++)
810 Int_t subdet=spmcl2->SubDetector();
811 Int_t gsuper=spmcl2->Gsuper();
812 Int_t col=spmcl2->Column();
813 Int_t row=spmcl2->Row();
814 Float_t edep=spmcl2->Edep();
815 Int_t adc=spmcl2->Adc();
820 phit->setSuperModule(Int_t(gsuper-1));
821 phit->setSubDetector(Int_t(subdet-1));
822 phit->setRow(Int_t(row-1));
823 phit->setColumn(Int_t(col-1));
824 phit->setEnergy(edep);
828 if(mCpvEvent)mCpvEvent->addHit(phit);
841 Int_t StPmdReadMaker::Finish() {
842 if(mPmdPrint)gMessMgr->Info(
"StPmdReadMaker::Finish()");
843 TFile * f =
new TFile(
"11030019run_2010_histo_QA.root",
"RECREATE");
844 for(Int_t nchain=0; nchain<49; nchain++)
846 chain_mean[nchain]->Write();
847 chain_rms[nchain]->Write();
848 chain_adc[nchain]->Write();
858 void StPmdReadMaker::bookHist(){
861 pmdhit_tof =
new TH2F(
"pmdhit_tof",
"",1000,0,100000, 1000, 0, 10000);
862 pmdadc_tof =
new TH2F(
"pmdadc_tof",
"",1000,0,100000, 1000, 0, 10000);
864 m_chain_channel =
new TH2F(
"chain_chan",
"channel vs chain No ",1728,-0.5,1727.5,48,-0.5,47.5);
865 for (Int_t chain1 =0;chain1<49;chain1++)
867 Char_t text[20],title[20];
868 sprintf(text,
"chain_rms%02d",chain1);
869 sprintf(title,
"chain_rms%02d",chain1);
870 chain_rms[chain1] =
new TH1D(text,title,1730,0,1730);
871 sprintf(text,
"chain_mean%02d",chain1);
872 sprintf(title,
"chain_mean%02d",chain1);
873 chain_mean[chain1] =
new TH1D(text,title,1730,0,1730);
874 Char_t text1[20],title1[20];
875 sprintf(text1,
"chain_adc%02d",chain1);
876 sprintf(title1,
"chain_adc%02d",chain1);
877 chain_adc[chain1] =
new TH1D(text1,title1,1730,0,1730);
882 Bool_t StPmdReadMaker::IsHot(Int_t chain,Int_t channel){
886 if (!mHotCells)
return kFALSE;
889 Int_t offset = channel/32;
890 Int_t bit = channel%32;
892 pmdHotCells_st* chainCells = mHotCells->GetTable(chain-1);
893 unsigned int* bitMask = &(chainCells->m00);
895 Bool_t isHot = ( ((*bitMask) & (((
unsigned int) 1) << (31-bit))) != 0 );
912 Bool_t StPmdReadMaker::Accept(Int_t chain,Int_t channel){
914 if (channel==0)
return kFALSE;
917 for(Int_t i=0;i<25;i++){
919 if (chain==BadChain[i]){
926 return !IsHot(chain,channel);
932 Bool_t StPmdReadMaker::ReadCalibrationsConst(){
934 if(Debug()) cout<<
" StPmdReadMaker::I AM IN READCALIB "<<endl;
938 node->setVersion(
"SMChain");
941 m_PmdCalibConst=NULL;
942 TString DbName =
"Calibrations/pmd";
943 mDb=GetInputDB(DbName.Data());
944 if(Debug())cout<<
"after mDB"<<endl;
945 if(!mDb)
return kFALSE;
948 for(Int_t ism=0;ism<24;ism++){
949 for(Int_t chain=0;chain<48;chain++){
950 SM_chain_factor[ism][chain]=0.;
956 pmdCalSummary_st* pmdcalsum = NULL;
957 St_pmdCalSummary* summ = (St_pmdCalSummary*) mDb->
Find(
"pmdCalSummary");
958 if(summ) pmdcalsum = summ->GetTable();
960 pmdSMCalib_st* pmdcalibst = NULL;
962 St_pmdSMCalib* a = (St_pmdSMCalib*) mDb->
Find(
"pmdSMCalib");
963 if(a) pmdcalibst = a->GetTable();
964 if(!pmdcalibst)
return kFALSE;
965 m_PmdCalibConst=pmdcalibst;
966 if(Debug())cout<<
"obtained the Cell_GNF Tables"<<endl;
969 mHotCells = (St_pmdHotCells*) mDb->
Find(
"pmdHotCells");
971 gMessMgr->Warning(
"pmdHotCells not found!");
975 for (Int_t chain=1; chain <= 48; chain++) {
976 pmdHotCells_st* chainCells = mHotCells->GetTable(chain-1);
978 cout<<
"End-of-DbTable. Stopping."<<endl;
982 for (Int_t offset=0; offset<54; offset++) {
983 unsigned int* bitMask = &(chainCells->m00);
986 for (Int_t bit=31; bit>=0; bit--) {
987 if ( ((*bitMask) & (((
unsigned int) 1) << bit)) != 0 ) {
997 if(Debug()) cout<<
" number of hot cells is "<< nhot<<endl;
1002 St_pmdSMChain_GNF * tab = (St_pmdSMChain_GNF*) mDb->
Find(
"pmdSMChain_GNF");
1004 cout<<
"No pmdSMChain_GNF DBTable. Stopping."<<endl;
1014 for (Int_t ismchain=0; ismchain<64; ismchain++) {
1015 pmdSMChain_GNF_st* smchain = tab->GetTable(ismchain);
1017 cout<<
"End-of-SmChain DbTable. Stopping."<<endl;
1021 long supmod = smchain->sm;
1022 long chainNo=smchain->chain;
1023 float MeanFactor = smchain->mean_factor;
1024 float MPVFactor = smchain->mpv_factor;
1026 SM_chain_factor[supmod-1][chainNo-1]=MeanFactor;
1037 if(supmod>0 && chainNo>0){
1038 cout<<
"SM,Chain,mean_factor,mpv_factor "<<supmod<<
" "<<chainNo<<
" "<<MeanFactor<<
" "<<MPVFactor<<
" "<<SM_chain_factor[supmod-1][chainNo-1]<<endl;
1048 Int_t StPmdReadMaker::GetCalib(
int sm,
int row,
int col,
float& calib)
1050 if(sm>0 && row>0 && col>0)
1051 if(m_PmdCalibConst)calib=m_PmdCalibConst[sm-1].CellGain[row-1][col-1];
bool addHit(StPmdHit *)
no of modules
Int_t module_hit(Int_t)
module number
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
void setGsuper(Int_t)
Cell status (chain selection based)
static StDbManager * Instance()
strdup(..) is not ANSI
StPmdModule * module(unsigned int)
number of hits
virtual TDataSet * Find(const char *path) const