diff --git a/StRoot/StBFChain/BigFullChain.h b/StRoot/StBFChain/BigFullChain.h index 0ce20af62e6..64c9c046cf0 100644 --- a/StRoot/StBFChain/BigFullChain.h +++ b/StRoot/StBFChain/BigFullChain.h @@ -1425,6 +1425,7 @@ Bfc_st BFC[] = { // standard chains {"TpcMixer","","tpcChain","StEvent,rts,-Mixer,-tpx,TpxClu" ,"StTpcMixerMaker","StTpcHitMaker","",kFALSE}, {"TpxClu","tpc_hits","tpcChain","rts,tpcDb,detDb,-tpx,-tpc_daq,-fcf","StTpcRTSHitMaker" ,"StTpcHitMaker", "RTS(online) cluster maker",kFALSE}, + {"TPC23" ,"","","TpxClu","","", "RTS(online, daq5k) tpc23-cluster maker",kFALSE}, {"TpxClu2D" ,"","","TpxClu","","", "RTS(online) 2D-cluster maker",kFALSE}, {"TpcAvCluster","TpcAvCluster","tpcChain","rts,detDb","StTpcAvClusterMaker","StTpcHitMaker" , "TPC+TPX averaging laser events into Sparse histogram on cluster level", kFALSE}, diff --git a/StRoot/StBFChain/StBFChain.cxx b/StRoot/StBFChain/StBFChain.cxx index 5de367510c4..566db07be1f 100644 --- a/StRoot/StBFChain/StBFChain.cxx +++ b/StRoot/StBFChain/StBFChain.cxx @@ -752,6 +752,7 @@ Int_t StBFChain::Instantiate() // TPC if (maker == "StTpcRTSHitMaker") { if ( GetOption("TpxClu2D")) mk->SetAttr("TpxClu2D", kTRUE); + if ( GetOption("TPC23")) mk->SetAttr("TPC23", kTRUE); } if (maker == "StTpcDbMaker"){ if ( GetOption("Simu") && ! GetOption("NoSimuDb")) mk->SetAttr("Simu",kTRUE); diff --git a/StRoot/StTpcHitMaker/StTpcHitMaker.cxx b/StRoot/StTpcHitMaker/StTpcHitMaker.cxx index 146cc020ad6..2c6de24fadd 100644 --- a/StRoot/StTpcHitMaker/StTpcHitMaker.cxx +++ b/StRoot/StTpcHitMaker/StTpcHitMaker.cxx @@ -305,12 +305,11 @@ static Int_t _debug = 0; static const Char_t *Names[StTpcHitMaker::kAll] = {"undef", "tpc_hits","tpx_hits","itpc_hits", "TpcPulser","TpxPulser","iTPCPulser", - "TpcDumpPxls2Nt","TpxDumpPxls2Nt", "TpcRaw","TpxRaw","iTPCRaw", - "TpcAvLaser","TpxAvLaser"}; + "TpcAvLaser","TpxAvLaser","tpc_hitsO"}; //_____________________________________________________________ StTpcHitMaker::StTpcHitMaker(const char *name) : StRTSBaseMaker("tpc",name), kMode(kUndefined), - kReaderType(kUnknown), mQuery(""), fTpc(0), fAvLaser(0), fSectCounts(0) { + kReaderType(kUnknown), mQuery(""), fTpc(0), fAvLaser(0), fSectCounts(0), fThr(0), fSeq(0) { SetAttr("minSector",1); SetAttr("maxSector",24); SetAttr("minRow",1); @@ -318,8 +317,8 @@ StTpcHitMaker::StTpcHitMaker(const char *name) : StRTSBaseMaker("tpc",name), kMo } //_____________________________________________________________ Int_t StTpcHitMaker::Init() { - LOG_INFO << "StTpcHitMaker::Init as\t" << GetName() << endm; - TString MkName(GetName()); + LOG_INFO << "StTpcHitMaker::Init as\t" << GetName() << endm; + TString MkName(GetName()); for (Int_t k = 1; k < kAll; k++) { if (MkName.CompareTo(Names[k],TString::kIgnoreCase) == 0) {kMode = (EMode) k; break;} } @@ -497,6 +496,7 @@ Int_t StTpcHitMaker::Make() { switch (kMode) { case kTpc: case kiTPC: + case kTpxO: case kTpx: hitsAdded += UpdateHitCollection(sector); break; case kTpcPulser: case kTpxPulser: if (fTpc) DoPulser(sector); break; @@ -506,13 +506,11 @@ Int_t StTpcHitMaker::Make() { else TpxAvLaser(sector); fSectCounts->Fill(sector); break; - case kTpcDumpPxls2Nt: - case kTpxDumpPxls2Nt: if (fTpc) DumpPixels2Ntuple(sector); break; case kTpcRaw: case kTpxRaw: case kiTPCRaw: if ( fTpc) RawTpcData(sector); - else RawTpxData(sector); + else RawTpxData(sector); break; default: break; @@ -534,16 +532,71 @@ Int_t StTpcHitMaker::Make() { << ") starting at time bin 0. Skipping event." << endm; return kStSkip; } - if (kMode == kTpc || kMode == kTpx) { // || kMode == kiTPC) { --> no after burner for iTpc + if (kMode == kTpc || kMode == kTpx || kMode == kTpxO) { // || kMode == kiTPC) { --> no after burner for iTpc StEvent *pEvent = dynamic_cast (GetInputDS("StEvent")); if (Debug()) {LOG_INFO << "StTpcHitMaker::Make : StEvent has been retrieved " <tpcHitCollection(); if (hitCollection && ! IAttr("NoTpxAfterBurner")) AfterBurner(hitCollection); } + if (IAttr("CheckThrSeq") && (kMode == kTpcRaw || kMode == kTpxRaw || kMode == kiTPCRaw)) { + CheckThrSeq(); + } return kStOK; } //_____________________________________________________________ +void StTpcHitMaker::CheckThrSeq() { + if (! fThr || !fSeq) { + fThr = new TH2C("Thr","ADC Thresold value versus sector and row",24,0.5,24.5,72,0.5,72.5); fThr->SetDirectory(0); + fSeq = new TH2C("Seq","ADC sequnce value versus sector and row",24,0.5,24.5,72,0.5,72.5); fSeq->SetDirectory(0); + for (Int_t s = 1; s <= 24; s++) + for (Int_t r = 1; r <= 72; r++) { + fThr->SetBinContent(s,r,127); + fSeq->SetBinContent(s,r,127); + } + } + for (Int_t s = 1; s <= 24; s++){ + StTpcDigitalSector *digitalSector = GetDigitalSector(s); + if (! digitalSector) continue; + Int_t Nrows = digitalSector->numberOfRows(); + for (Int_t r = 1; r <= Nrows; r++) { + Int_t Npads = digitalSector->numberOfPadsInRow(r); + for (Int_t p = 1; p <= Npads; p++) { + Int_t ntb = digitalSector->numberOfTimeBins(r,p); + if (! ntb) continue; + digitalSector->getTimeAdc(r,p,ADCs,IDTs); + Int_t adcMin = 127; + Int_t seq = 127; + Int_t tbF = -1, tbL = -1; + for (Int_t tb = 0; tb < __MaxNumberOfTimeBins__; tb++) { + if (! ADCs[tb]) { + if (tbF > -1 && tbL >= tbF) { + if (seq > tbL - tbF + 1) seq = tbL - tbF + 1; + } + tbF = tbL = -1; + continue; + } + if (ADCs[tb] < adcMin) { + adcMin = TMath::Max(ADCs[tb-2],TMath::Max(ADCs[tb-1],TMath::Max(ADCs[tb],TMath::Max(ADCs[tb+1],ADCs[tb+1])))); + } + if (tbF < 0) tbF = tb; + tbL = tb; + } + if (adcMin < 127 && seq < 127) { + if (seq == 1 && adcMin == 1) { + static Int_t ibreak = 0; + ibreak++; + } + Char_t th = fThr->GetBinContent(s,r); + if (th > adcMin) fThr->SetBinContent(s,r, adcMin); + Char_t sq = fSeq->GetBinContent(s,r); + if (sq > seq) fSeq->SetBinContent(s,r, seq); + } + } + } + } +} +//_____________________________________________________________ Int_t StTpcHitMaker::Finish() { #ifdef __USE__THnSparse__ if (GetTFile() && fAvLaser) { @@ -558,6 +611,38 @@ Int_t StTpcHitMaker::Finish() { } } #endif /* __USE__THnSparse__ */ + if (fThr && fSeq) { + Int_t adcMinFL = 127; + Int_t seqFL = 127; + Int_t s1 = -1, s2 = -1, r1 = -1, r2 = -1; + for (Int_t s = 1; s <= 24; s++){ + for (Int_t r = 1; r <= 72; r++) { + Int_t adcMin = fThr->GetBinContent(s,r); + Int_t seq = fSeq->GetBinContent(s,r); + if (adcMin == 127 || seq == 127) continue; + if (adcMinFL == 127 && seqFL == 127) { + adcMinFL = adcMin; + seqFL = seq; + s1 = s2 = s; + r1 = r2 = r; + } else { + if (adcMinFL == adcMin && seqFL == seq) { + r2 = r; + s2 = s; + } else { + LOG_INFO << "StTpcHitMaker::Finish CheckThrSeq in sectors [" << s1 << "," << s2 << "] and rows[" << r1 << "," << r2 << "] Threshold = " << adcMinFL << " and sequence = " << seqFL << endm; + adcMinFL = adcMin; + seqFL = seq; + s1 = s2 = s; + r1 = r2 = r; + } + } + } + } + LOG_INFO << "StTpcHitMaker::Finish CheckThrSeq in sectors [" << s1 << "," << s2 << "] and rows[" << r1 << "," << r2 << "] Threshold = " << adcMinFL << " and sequence = " << seqFL << endm; + } + SafeDelete(fThr); + SafeDelete(fSeq); return StMaker::Finish(); } //_____________________________________________________________ @@ -588,6 +673,7 @@ Int_t StTpcHitMaker::UpdateHitCollection(Int_t sector) { if (! c || ! c->charge) continue; if (c->flags && (c->flags & ~(FCF_ONEPAD | FCF_MERGED | FCF_BIG_CHARGE))) continue; + if (kMode == kTpxO) c->flags |= 256; // mark cluster if it is coming from extra online maker Int_t row = padrow + 1; Float_t pad = c->p; Int_t iRdo = StDetectorDbTpcRDOMasks::instance()->rdoForPadrow(sector,row,pad); @@ -624,6 +710,7 @@ Int_t StTpcHitMaker::UpdateHitCollection(Int_t sector) { if (cld->t2 < 0 || cld->t2 >= __MaxNumberOfTimeBins__) continue; if (cld->flags && (cld->flags & ~(FCF_ONEPAD | FCF_MERGED | FCF_BIG_CHARGE))) continue; + if (kMode == kTpxO) cld->flags |= 256; // mark cluster if it is coming from extra online maker Float_t pad = cld->pad; Int_t iRdo = StDetectorDbTpcRDOMasks::instance()->rdoForPadrow(sector,row,pad); if ( ! StDetectorDbTpcRDOMasks::instance()->isOn(sector,iRdo)) continue; @@ -661,7 +748,6 @@ StTpcHit *StTpcHitMaker::CreateTpcHit(const tpc_cl &cluster, Int_t sector, Int_t Double_t wire_coupling = (row<=St_tpcPadConfigC::instance()->innerPadRows(sector)) ? St_tss_tssparC::instance()->wire_coupling_in() : St_tss_tssparC::instance()->wire_coupling_out(); #endif Double_t q = 0; //cluster.charge * ((Double_t)St_tss_tssparC::instance()->ave_ion_pot() * (Double_t)St_tss_tssparC::instance()->scale())/(gain*wire_coupling) ; - StTpcHit *hit = StTpcHitFlag(global.position(),hard_coded_errors,hw,q , (UChar_t ) 0 // c , (Int_t) 0 // idTruth=0 @@ -674,7 +760,7 @@ StTpcHit *StTpcHitMaker::CreateTpcHit(const tpc_cl &cluster, Int_t sector, Int_t , pad , time , cluster.charge - , cluster.flags); + ,cluster.flags); if (hit->minTmbk() == 0) bin0Hits++; if (Debug()) { LOG_INFO << "StTpcHitMaker::CreateTpcHit fromt tpc_cl\t" <<*hit << endm; @@ -694,10 +780,14 @@ StTpcHit *StTpcHitMaker::CreateTpcHit(const daq_cld &cluster, Int_t sector, Int_ #else /* used in TFG till 07/31/20 */ Double_t q = 0; #endif - - // Correct for slewing (needs corrected q, and time in microsec) - Double_t freq = gStTpcDb->Electronics()->samplingFrequency(); - time = freq * St_tpcSlewingC::instance()->correctedT(sector,row,q,time/freq); + // Check that slewing is active + static St_tpcSlewingC *tpcSlewing = St_tpcSlewingC::instance(); + if (tpcSlewing && tpcSlewing->type() != 1001) tpcSlewing = 0; + if (tpcSlewing) { + // Correct for slewing (needs corrected q, and time in microsec) + Double_t freq = gStTpcDb->Electronics()->samplingFrequency(); + time = freq * tpcSlewing->correctedT(sector,row,q,time/freq); + } static StTpcCoordinateTransform transform(gStTpcDb); static StTpcLocalSectorCoordinate local; static StTpcLocalCoordinate global; @@ -709,6 +799,8 @@ StTpcHit *StTpcHitMaker::CreateTpcHit(const daq_cld &cluster, Int_t sector, Int_ hw += sector << 4; // (row/100 << 4); // sector hw += row << 9; // (row%100 << 9); // row static StThreeVector hard_coded_errors(fgDp,fgDt,fgDperp); + UShort_t flag = cluster.flags; + if (kMode == kTpxO) flag |= 256; // mark cluster if it is coming from extra online maker StTpcHit *hit = StTpcHitFlag(global.position(),hard_coded_errors,hw,q , (UChar_t ) 0 // c @@ -722,7 +814,7 @@ StTpcHit *StTpcHitMaker::CreateTpcHit(const daq_cld &cluster, Int_t sector, Int_ , pad , time , cluster.charge - , cluster.flags); + , flag); if (hit->minTmbk() == 0) bin0Hits++; if (Debug()) { LOG_INFO << "StTpcHitMaker::CreateTpcHit fromt daq_cld\t" <<*hit << endm; @@ -888,75 +980,28 @@ void StTpcHitMaker::TpxAvLaser(Int_t sector) { } } //________________________________________________________________________________ -void StTpcHitMaker::DumpPixels2Ntuple(Int_t sector) { +void StTpcHitMaker::DumpPixels2Ntuple(Int_t sector, Int_t row, Int_t pad) { struct BPoint_t { - Float_t sector, row, pad, tb, adc, ped, t0, peak; + Float_t event, sector, row, pad, tb, adc, idt; }; - static const Char_t *BName = "sector:row:pad:tb:adc:ped:t0:peak"; + static const Char_t *BName = "event:sector:row:pad:tb:adc:idt"; static TNtuple *adcP = 0; - if (! adcP) { - assert(GetTFile()); + if (! adcP && GetTFile() ) { GetTFile()->cd(); adcP = new TNtuple("adcP","Pulser ADC",BName); } + if (! adcP) return; static BPoint_t P; - if (! fTpc) return; - Int_t r, p, tb, tbmax; - // if (! fTpc->channels_sector) return; - for(Int_t row = 1; row <= St_tpcPadConfigC::instance()->numberOfRows(sector); row++) { - r = row - 1; - for (Int_t pad = 1; pad <= 182; pad++) { - p = pad - 1; - Int_t ncounts = fTpc->counts[r][p]; - if (! ncounts) continue; - static UShort_t adc[512]; - memset (adc, 0, sizeof(adc)); - tbmax = 513; - UShort_t adcmax = 0; - for (Int_t i = 0; i < ncounts; i++) { - tb = fTpc->timebin[r][p][i]; - adc[tb] = log8to10_table[fTpc->adc[r][p][i]]; - if (adc[tb] > adcmax) { - tbmax = tb; - adcmax = adc[tb]; - } - } - if (tbmax < 2 || tbmax > 504) continue; - Int_t npeak = 0, nped = 0; - Int_t i1s = TMath::Max( 0, tbmax - 2); - Int_t i2s = TMath::Min(511, tbmax + 7); - Int_t i1 = TMath::Max(0 ,i1s - 20); - Int_t i2 = TMath::Min(511,i2s + 20); - Double_t peak = 0; - Double_t ped = 0; - Double_t t0 = 0; - for (Int_t i = i1; i <= i2; i++) { - if (i >= i1s && i <= i2s) continue; - nped++; - ped += adc[i]; - } - if (nped) ped /= nped; - for (Int_t i = i1s; i <= i2s; i++) { - npeak++; - peak += adc[i] - ped; - t0 += i*(adc[i] - ped); - } - if (peak <= 0) continue; - t0 /= peak; - i1 = (Int_t) TMath::Max(0.,t0 - 20); - i2 = (Int_t) TMath::Min(511., t0 + 80); - for (Int_t i = i1; i <= i2; i++) { - P.sector = sector; - P.row = row; - P.pad = pad; - P.tb = i - t0; - P.adc = adc[i]; - P.ped = ped; - P.t0 = t0; - P.peak = peak; - adcP->Fill(&P.sector); - } - } + P.event = GetEventNumber(); + P.sector = sector; + P.row = row; + P.pad = pad; + for (Int_t i = 0; i < __MaxNumberOfTimeBins__; i++) { + if (! ADCs[i]) continue; + P.tb = i; + P.adc = ADCs[i]; + P.idt = IDTs[i]; + adcP->Fill(&P.event); } } //________________________________________________________________________________ @@ -1067,6 +1112,9 @@ Int_t StTpcHitMaker::RawTpxData(Int_t sector) { } } digitalSector->putTimeAdc(r_old+1,p_old+1,ADCs,IDTs); + if (IAttr("TpxDumpPxls2Nt")) { + DumpPixels2Ntuple(sector,r_old+1,p_old+1); + } memset(ADCs, 0, sizeof(ADCs)); memset(IDTs, 0, sizeof(IDTs)); } @@ -1131,6 +1179,9 @@ Int_t StTpcHitMaker::RawTpcData(Int_t sector) { #endif } digitalSector->putTimeAdc(row,pad,ADCs,IDTs); + if (IAttr("TpxDumpPxls2Nt")) { + DumpPixels2Ntuple(sector,row,pad); + } } } if (Total_data) { diff --git a/StRoot/StTpcHitMaker/StTpcHitMaker.h b/StRoot/StTpcHitMaker/StTpcHitMaker.h index 02bfffe9b96..97ed33695fc 100644 --- a/StRoot/StTpcHitMaker/StTpcHitMaker.h +++ b/StRoot/StTpcHitMaker/StTpcHitMaker.h @@ -87,6 +87,7 @@ #include "StThreeVectorF.hh" //#define __USE__THnSparse__ #include "TH1.h" +#include "TH2.h" #ifdef __USE__THnSparse__ #include "THnSparse.h" #else /* ! __USE__THnSparse__ */ @@ -104,9 +105,9 @@ class StTpcHitMaker : public StRTSBaseMaker { enum EMode {kUndefined, kTpc, kTpx, kiTPC, kTpcPulser, kTpxPulser, kiTPCPulser, - kTpcDumpPxls2Nt, kTpxDumpPxls2Nt, kTpcRaw, kTpxRaw, kiTPCRaw, kTpcAvLaser, kTpxAvLaser, // averaging on pixel level + kTpxO, kAll}; StTpcHitMaker(const char *name="tpc_hits"); virtual ~StTpcHitMaker() {} @@ -119,16 +120,20 @@ class StTpcHitMaker : public StRTSBaseMaker { void TpcAvLaser(Int_t sector); void PadMonitor(Int_t sector); Int_t UpdateHitCollection(Int_t sector); - void DumpPixels2Ntuple(Int_t sector); + void DumpPixels2Ntuple(Int_t sector, Int_t row, Int_t pad); void PrintSpecial(Int_t sector); Int_t RawTpcData(Int_t sector); Int_t RawTpxData(Int_t sector); void InitializeHistograms(Int_t token); + void CheckThrSeq(); + TH2C *Thr() {return fThr;} + TH2C *Seq() {return fSeq;} #ifdef __USE__THnSparse__ THnSparseF *CompressTHn(THnSparseF *hist, Double_t compress = 1e4); #endif /* __USE__THnSparse__ */ StTpcDigitalSector *GetDigitalSector(Int_t sector); virtual Int_t Finish(); + Int_t getADC(Int_t i) {if (i < 0 || i > 511) {return 0;} else {return ADCs[i];}} private: EMode kMode; @@ -171,6 +176,8 @@ class StTpcHitMaker : public StRTSBaseMaker { static Float_t fgDt; static Float_t fgDperp; static Bool_t fgCosmics; + TH2C *fThr; + TH2C *fSeq; // cvs virtual const char *GetCVS() const { static const char cvs[]="Tag $Name: $Id: built " __DATE__ " " __TIME__ ; return cvs; diff --git a/StRoot/StTpcHitMaker/StTpcRTSHitMaker.cxx b/StRoot/StTpcHitMaker/StTpcRTSHitMaker.cxx index d088730d6a2..e5ca8598abd 100644 --- a/StRoot/StTpcHitMaker/StTpcRTSHitMaker.cxx +++ b/StRoot/StTpcHitMaker/StTpcRTSHitMaker.cxx @@ -6,7 +6,6 @@ *************************************************************************** * * Description: Make clusters from StTpcRawData and fill the StEvent */ -//#define __USE_GAIN_FROM_FILE__ #include #include #include "StTpcHitMaker.h" @@ -29,10 +28,9 @@ #include "StDetectorDbMaker/St_itpcPadPlanesC.h" #include "StDetectorDbMaker/St_tpcPadConfigC.h" #include "StDetectorDbMaker/St_tpcStatusC.h" -#ifdef __USE_GAIN_FROM_FILE__ #include "StDetectorDbMaker/StPath2tpxGain.h" #include "StDetectorDbMaker/StPath2itpcGain.h" -#endif /* __USE_GAIN_FROM_FILE__ */ +#include "StDetectorDbMaker/St_tpcPadConfigC.h" #include "StMessMgr.h" #include "StDAQMaker/StDAQReader.h" #include "StRtsTable.h" @@ -49,11 +47,14 @@ #include "RTS/src/DAQ_TPX/tpxFCF.h" #include "RTS/src/DAQ_TPX/tpxStat.h" #include "RTS/src/DAQ_ITPC/itpcFCF.h" -#ifdef __TFG__VERSION__ -#include "TPC23/tpx23.h" -#include "TPC23/itpc23.h" -#endif /* __TFG__VERSION__ */ +#include "RTS/src/DAQ_TPC23/tpc23_base.h" +#include "RTS/src/DAQ_TPC23/tpx23.h" +#include "RTS/src/DAQ_TPC23/itpc23.h" #include "TBenchmark.h" +#include "TH2.h" +#include "TFile.h" +#include "TPolyMarker.h" +#include "TBox.h" ClassImp(StTpcRTSHitMaker); #define __DEBUG__ #ifdef __DEBUG__ @@ -61,14 +62,13 @@ ClassImp(StTpcRTSHitMaker); #else #define PrPP(A,B) #endif +StTpcRTSHitMaker *StTpcRTSHitMaker::fgStTpcRTSHitMaker = 0; //________________________________________________________________________________ StTpcRTSHitMaker::~StTpcRTSHitMaker() { SafeDelete(fTpx); SafeDelete(fiTpc); -#ifdef __TFG__VERSION__ SafeDelete(fTpx23); SafeDelete(fiTpc23); -#endif /* __TFG__VERSION__ */ } //________________________________________________________________________________ Int_t StTpcRTSHitMaker::Init() { @@ -77,7 +77,6 @@ Int_t StTpcRTSHitMaker::Init() { bin0Hits = 0; return StMaker::Init(); } -#ifdef __USE_GAIN_FROM_FILE__ //________________________________________________________________________________ Int_t StTpcRTSHitMaker::from_file(daq_dta *gain_dta, const Char_t *fname) { // example of gains; will use file for that @@ -127,7 +126,27 @@ Int_t StTpcRTSHitMaker::from_file(daq_dta *gain_dta, const Char_t *fname) { } return 1; } -#endif /* __USE_GAIN_FROM_FILE__ */ +//________________________________________________________________________________ +Int_t StTpcRTSHitMaker::FixGains(tpc23_base *tpc23, Int_t sec, Int_t row, Int_t Npads) { + // from tpc23_base::gains_from_cache, fix dead pads and edges + Int_t ok = 0; + tpc23_base::row_pad_t (*rp_gain)[tpc23_base::ROW_MAX+1][tpc23_base::PAD_MAX+1] = tpc23->rp_gain; + for (Int_t pad = 1; pad <= Npads; pad++) { + Float_t g = rp_gain[sec-1][row][pad].gain; + if(g<0.01) { + int p1 = pad - 1 ; + int p2 = pad + 1 ; + if(p1<1) p1 = 1 ; + if(p2>Npads) p2 = Npads ; + rp_gain[sec-1][row][pad].flags |= FCF_DEAD_EDGE ; + rp_gain[sec-1][row][p1].flags |= FCF_DEAD_EDGE ; + rp_gain[sec-1][row][p2].flags |= FCF_DEAD_EDGE ; + } + } + rp_gain[sec-1][row][1].flags |= FCF_ROW_EDGE ; // row edge + rp_gain[sec-1][row][Npads].flags |= FCF_ROW_EDGE ; // row edge + return ok; +} //________________________________________________________________________________ Int_t StTpcRTSHitMaker::InitRun(Int_t runnumber) { SetAttr("minSector",1); @@ -137,31 +156,45 @@ Int_t StTpcRTSHitMaker::InitRun(Int_t runnumber) { SetAttr("maxRow",St_tpcPadConfigC::instance()->numberOfRows(20)); SafeDelete(fTpx); SafeDelete(fiTpc); -#ifdef __TFG__VERSION__ SafeDelete(fTpx23); SafeDelete(fiTpc23); -#endif /* __TFG__VERSION__ */ -#ifdef __USE_GAIN_FROM_FILE__ - const Char_t *fname = StPath2tpxGain::instance()->GetPath(); - const Char_t *fnameITPC = StPath2itpcGain::instance()->GetPath(); -#else - const Char_t *fname = "none"; - const Char_t *fnameITPC = "none"; -#endif /* __USE_GAIN_FROM_FILE__ */ -#ifdef __TFG__VERSION__ + TString fnameTPX("none"); + TString fnameITPC("none"); + if (IAttr("USE_GAIN_FROM_FILE")) { + fnameTPX = StPath2tpxGain::instance()->GetPath(); + LOG_INFO << "StTpcRTSHitMaker::InitRun: use " << fnameTPX.Data() << " for TPX" << endm; + fnameITPC = StPath2itpcGain::instance()->GetPath(); + LOG_INFO << "StTpcRTSHitMaker::InitRun: use " << fnameITPC.Data() << " for iTPC" << endm; + } if ( IAttr("TPC23")) { // TPC23 + LOG_INFO << "StTpcRTSHitMaker::InitRun:: use TPC23 mode" << endm; Int_t log_level = 0 ; + // Int_t fmt_version = 0 ; + Int_t run_type = 3; + Int_t online = 0 ; // NOTE setting for Offline mode! fTpx23 = new tpx23; - fTpx23->log_level = log_level; - if (fTpx23->gains_from_cache(fname) < 0) { // REQUIRED even if no gain correction + fTpx23->online = online ; + fTpx23->run_type = run_type ; + fTpx23->log_level = log_level ; + if (fTpx23->gains_from_cache(fnameTPX) < 0 || fnameTPX == "none") { // REQUIRED even if no gain correction // Tpx Load gains from Db + Int_t NoPadsWithLoadedGain = 0; for(Int_t sector=1;sector<=24;sector++) { Int_t rowMin = 1; if (St_tpcPadConfigC::instance()->iTPC(sector)) rowMin = 14; - for(Int_t rowO = 1; rowO <= 45; rowO++) { + for(Int_t rowO = 1; rowO < rowMin; rowO++) { + Int_t Npads = St_tpcPadPlanesC::instance()->padsPerRow(rowO); + for(Int_t pad = 0; pad <= Npads; pad++) { + fTpx23->rp_gain[sector-1][rowO][pad].gain = 0.; // be sure that dead pads are killed + fTpx23->rp_gain[sector-1][rowO][pad].t0 = -9.99; + fTpx23->rp_gain[sector-1][rowO][pad].flags = 64; + } + } + for(Int_t rowO = rowMin; rowO <= 45; rowO++) { Int_t Npads = St_tpcPadPlanesC::instance()->padsPerRow(rowO); Int_t padMin = 1; Int_t padMax = Npads; + Int_t NoPadsWithLoadedGainPerRow = 0; for(Int_t pad = 0; pad <= Npads; pad++) { fTpx23->rp_gain[sector-1][rowO][pad].gain = 0.; // be sure that dead pads are killed fTpx23->rp_gain[sector-1][rowO][pad].t0 = 0.; @@ -169,20 +202,44 @@ Int_t StTpcRTSHitMaker::InitRun(Int_t runnumber) { if (St_tpcPadGainT0C::instance()->Gain(sector,rowO,pad) <= 0) continue; fTpx23->rp_gain[sector-1][rowO][pad].gain = St_tpcPadGainT0C::instance()->Gain(sector,rowO,pad); fTpx23->rp_gain[sector-1][rowO][pad].t0 = St_tpcPadGainT0C::instance()->T0(sector,rowO,pad); + NoPadsWithLoadedGainPerRow++; } } + if (NoPadsWithLoadedGainPerRow > 0) { + NoPadsWithLoadedGain += NoPadsWithLoadedGainPerRow; + FixGains(fTpx23, sector, rowO, Npads); + } } } + LOG_INFO << "StTpcRTSHitMaker::InitRun:: loaded gains for " << NoPadsWithLoadedGain << " pads in TPX23" << endm; + } + //#define __DEBUG_GAIN__ +#ifdef __DEBUG_GAIN__ + LOG_INFO << "StTpcRTSHitMaker::InitRun:: Print gains for Tpx23" << endm; + for(Int_t sector=1;sector<=24;sector++) { + for(Int_t rowO = 1; rowO <= 45; rowO++) { + Int_t Npads = St_tpcPadPlanesC::instance()->padsPerRow(rowO); + for(Int_t pad = 1; pad <= Npads; pad++) { + cout << Form("Gain/T0 s/r/p %3i/%3i/%3i %7.3f %7.3f %i",sector,rowO,pad,fTpx23->rp_gain[sector-1][rowO][pad].gain,fTpx23->rp_gain[sector-1][rowO][pad].t0,fTpx23->rp_gain[sector-1][rowO][pad].flags) << endl; + } + } + } +#endif /* __DEBUG_GAIN__ */ fTpx23->run_start() ; // iTPC23 fiTpc23 = new itpc23 ; - fiTpc23->log_level = log_level; - if (fiTpc23->gains_from_cache(fnameITPC) < 0) { // REQUIRED even if no gain correction + fiTpc23->online = online ; + fiTpc23->run_type = run_type ; + fiTpc23->log_level = log_level ; + Int_t ok = fiTpc23->gains_from_cache(fnameITPC); + if (ok < 0 || fnameITPC == "none") { // REQUIRED even if no gain correction + Int_t NoPadsWithLoadedGain = 0; for(Int_t sector=1;sector<=24;sector++) { if (! St_tpcPadConfigC::instance()->iTPC(sector)) continue; for(Int_t row = 1; row <= 40; row++) { Int_t Npads = St_itpcPadPlanesC::instance()->padsPerRow(row); + Int_t NoPadsWithLoadedGainPerRow = 0; for(Int_t pad = 0; pad <= Npads; pad++) { fiTpc23->rp_gain[sector-1][row][pad].gain = 0.; // be sure that dead pads are killed fiTpc23->rp_gain[sector-1][row][pad].t0 = 0.; @@ -191,16 +248,29 @@ Int_t StTpcRTSHitMaker::InitRun(Int_t runnumber) { fiTpc23->rp_gain[sector-1][row][pad].gain = St_itpcPadGainT0C::instance()->Gain(sector,row,pad); fiTpc23->rp_gain[sector-1][row][pad].t0 = St_itpcPadGainT0C::instance()->T0(sector,row,pad); //#define __DEBUG_GAIN__ -#ifdef __DEBUG_GAIN__ - cout << Form("Gain/T0 s/r/p %3i/%3i/%3i %7.2f %7.2f",sector,row,pad,fiTpc23->rp_gain[sector-1][row][pad].gain,fiTpc23->rp_gain[sector-1][row][pad].t0) << endl; -#endif /* __DEBUG_GAIN__ */ + NoPadsWithLoadedGainPerRow++; + } + if (NoPadsWithLoadedGainPerRow > 0) { + NoPadsWithLoadedGain += NoPadsWithLoadedGainPerRow; + FixGains(fiTpc23, sector, row, Npads); } } } + LOG_INFO << "StTpcRTSHitMaker::InitRun:: loaded gains for " << NoPadsWithLoadedGain << " pads in iTPC23" << endm; } +#ifdef __DEBUG_GAIN__ + LOG_INFO << "StTpcRTSHitMaker::InitRun:: Print gains for iTpc23" << endm; + for(Int_t sector=1;sector<=24;sector++) { + for(Int_t row = 1; row <= 40; row++) { + Int_t Npads = St_itpcPadPlanesC::instance()->padsPerRow(row); + for(Int_t pad = 1; pad <= Npads; pad++) { + cout << Form("Gain/T0 s/r/p %3i/%3i/%3i %7.3f %7.3f %i",sector,row,pad,fiTpc23->rp_gain[sector-1][row][pad].gain,fiTpc23->rp_gain[sector-1][row][pad].t0,fiTpc23->rp_gain[sector-1][row][pad].flags) << endl; + } + } + } +#endif /* __DEBUG_GAIN__ */ fiTpc23->run_start() ; } else { -#endif /* __TFG__VERSION__ */ fTpx = new daq_tpx() ; if (GetDate() >= 20091215) fTpx->fcf_run_compatibility = 10 ; if (GetDate() >= 20191215) fTpx->fcf_run_compatibility = 22 ; @@ -212,7 +282,8 @@ Int_t StTpcRTSHitMaker::InitRun(Int_t runnumber) { // daq_dta *dta_Tpx = fTpx->put("gain"); tpxGain *gain = fTpx->gain_algo; // gain->do_default(sector) ; // zap to all 1... - if (gain->from_file(fname, 0) < 0) { + Int_t ok = gain->from_file(fnameTPX, 0); + if (ok < 0 &&fnameTPX == "none") { for(Int_t sector=1;sector<=24;sector++) { // Tpx Int_t rowMin = 1; @@ -252,9 +323,8 @@ Int_t StTpcRTSHitMaker::InitRun(Int_t runnumber) { // iTpc if (fiTpc) { daq_dta * dta_iTpc = fiTpc->put("gain"); // , 0, 40, 0, miTpc_RowLen); -#ifdef __USE_GAIN_FROM_FILE__ - if (from_file(dta_iTpc, fname) < 0) { -#endif /* __USE_GAIN_FROM_FILE__ */ + Int_t ok = from_file(dta_iTpc, fnameITPC); + if (ok < 0 || fnameITPC == "none") { for(Int_t sector=1;sector<=24;sector++) { if (! St_tpcPadConfigC::instance()->iTPC(sector)) continue; for(Int_t row = 1; row <= 40; row++) { @@ -277,13 +347,9 @@ Int_t StTpcRTSHitMaker::InitRun(Int_t runnumber) { } // ((daq_itpc *) dta_iTpc)->InitRun(runnumber); } -#ifdef __USE_GAIN_FROM_FILE__ } -#endif /* __USE_GAIN_FROM_FILE__ */ } // -#ifdef __TFG__VERSION__ } -#endif /* __TFG__VERSION__ */ PrintAttr(); ////////////////////////////////////// @@ -408,9 +474,7 @@ Int_t StTpcRTSHitMaker::Make() { LOG_WARN << "TPC status indicates it is unusable for this event. Ignoring hits." << endm; return kStOK; } -#ifdef __TFG__VERSION__ if (IAttr("TPC23")) return Make23(); -#endif /* __TFG__VERSION__ */ static Short_t ADCs[__MaxNumberOfTimeBins__]; #ifdef __TFG__VERSION__ static Int_t IDTs[__MaxNumberOfTimeBins__]; @@ -662,7 +726,6 @@ Int_t StTpcRTSHitMaker::Make() { #endif return kStOK; } -#ifdef __TFG__VERSION__ //________________________________________________________________________________ Int_t StTpcRTSHitMaker::Make23() { if (! fTpx23 && ! fiTpc23) return kStErr; @@ -676,7 +739,11 @@ Int_t StTpcRTSHitMaker::Make23() { return kStOK; } static Short_t ADCs[__MaxNumberOfTimeBins__]; +#ifdef __TFG__VERSION__ static Int_t IDTs[__MaxNumberOfTimeBins__]; +#else + static UShort_t IDTs[__MaxNumberOfTimeBins__]; +#endif static StTpcCoordinateTransform transform; static StThreeVectorF hard_coded_errors; StEvent* rEvent = (StEvent*) GetInputDS("StEvent"); @@ -735,6 +802,10 @@ Int_t StTpcRTSHitMaker::Make23() { tpc23 = fTpx23; } if (! tpc23) continue; +#ifndef __TFG__VERSION__ + Double_t ADC2GeV = 0; + Int_t rowOld = -1; +#endif /* ! __TFG__VERSION__ */ for (Int_t row = row1; row <= row2; row++) { if (! St_tpcPadGainT0BC::instance()->livePadrow(sector,row)) continue; tpc23->sim_evt_start(sector) ; // prepare start of event @@ -755,14 +826,21 @@ Int_t StTpcRTSHitMaker::Make23() { // add adc data for this specific sector:row:pad digitalSector->getTimeAdc(row,pad,ADCs,IDTs); UInt_t l = 0; + static UShort_t adcs[__MaxNumberOfTimeBins__]; + memset(adcs, 0, sizeof(adcs)); + static Int_t idts[__MaxNumberOfTimeBins__]; + memset(idts, 0, sizeof(idts)); for (UInt_t k = 0; k < __MaxNumberOfTimeBins__; k++) { if (ADCs[k]) { + adcs[k] = ADCs[k]; + idts[k] = IDTs[k]; l++; } } if (l > 0) { Int_t padrow = rowO; - tpc23->sim_do_pad(padrow,pad,ADCs,IDTs) ; + // tpc23->sim_do_pad(padrow,pad,ADCs,IDTs) ; + tpc23->do_ch_sim(padrow,pad,adcs,idts) ; NoAdcs += l; } } // pad loop @@ -806,7 +884,7 @@ Int_t StTpcRTSHitMaker::Make23() { version = (padrow>>16) ; - ints_per_cluster = 5 ; // 5 for sim, 2 for real + ints_per_cluster = fTpx23 -> online? 2 : 5; // 5 for sim, 2 for real, Tommy's fix } else { padrow = *p_buff++ ; @@ -887,6 +965,17 @@ Int_t StTpcRTSHitMaker::Make23() { hw += sector << 4; // (row/100 << 4); // sector hw += row << 9; // (row%100 << 9); // row #ifndef __TFG__VERSION__ + if (row != rowOld) { + rowOld = row; + Double_t gain = St_tpcPadConfigC::instance()->IsRowInner(sector,row) ? + St_tss_tssparC::instance()->gain_in() : + St_tss_tssparC::instance()->gain_out(); + Double_t wire_coupling = St_tpcPadConfigC::instance()->IsRowInner(sector,row) ? + St_tss_tssparC::instance()->wire_coupling_in() : + St_tss_tssparC::instance()->wire_coupling_out(); + ADC2GeV = ((Double_t) St_tss_tssparC::instance()->ave_ion_pot() * + (Double_t) St_tss_tssparC::instance()->scale())/(gain*wire_coupling) ; + } Double_t q = ADC2GeV*dc.cld.charge; #else /* used in TFG till 07/31/20 */ Double_t q = 0; @@ -938,4 +1027,87 @@ Int_t StTpcRTSHitMaker::Make23() { #endif return kStOK; } -#endif /* __TFG__VERSION__ */ +//________________________________________________________________________________ +TH2F *StTpcRTSHitMaker::PlotSecRow(Int_t sec, Int_t row, Int_t flags) { + /* + Usage: + root.exe ' bfc.C(1,"P2019a,StiCA,evout,NoHistos,noTags,noRunco,PicoVtxVpdOrDefault,TpxRaw,TPC23,TpxRaw,TPC23,USE_GAIN_FROM_FILE,tpxO,NoTpxAfterBurner","/RTS/TONKO/data/st_physics_adc_20192001_raw_5500002.daq","","Plot.root")' + TH2F *plot = StTpcRTSHitMaker::instance()->PlotSecRow(2,43,-1); + */ + TH2F *plot = 0; + StEvent* pEvent = (StEvent*) StMaker::GetChain()->GetInputDS("StEvent"); + if (!pEvent) { cout << "Can't find StEvent" << endl; return plot;} + StTpcHitCollection* TpcHitCollection = pEvent->tpcHitCollection(); + if (! TpcHitCollection) { cout << "No TPC Hit Collection" << endl; return plot;} + StTpcSectorHitCollection* sectorCollection = TpcHitCollection->sector(sec-1); + if (! sectorCollection) { cout << "No TPC Hit Collection for sector " << sec << endl; return plot;} + StTpcPadrowHitCollection *rowCollection = sectorCollection->padrow(row-1); + if (! rowCollection) { cout << "No TPC Hit Collection for sector " << sec << " and row " << row << endl; return plot;} + TFile *f = StMaker::GetChain()->GetTFile(); + if (! f) {cout << "No TFile is opened" << endl; return plot;} + f->cd(); + TString PlotName(Form("s%02ir%03i",sec,row)); + plot = (TH2F *) f->Get(PlotName); + if (plot) { + plot->Reset(); + plot->SetTitle(Form("ADC versus pad and time buckets for sec = %i and row = %i in event %i",sec,row, pEvent->id())); + } else { + Int_t npad = St_tpcPadConfigC::instance()->padsPerRow(sec,row); + plot = new TH2F(PlotName,Form("ADC versus pad and time buckets for sec = %i and row = %i in event %i",sec,row, pEvent->id()), 360,-0.5,359.5,npad,0.5,npad+0.5); + plot->SetStats(1); + } + TDataSet* tpcRawEvent = StMaker::GetChain()->GetInputDS("Event"); + if (! tpcRawEvent) { + LOG_WARN << "There is not Tpc Raw Event" << endm; + } else { + StTpcRawData *tpcRawData = (StTpcRawData *) tpcRawEvent->GetObject(); + if (! tpcRawData) { + LOG_WARN << "There is not Tpc Raw Data" << endm; + } else { + StTpcDigitalSector *digitalSector = tpcRawData->GetSector(sec); + if (! digitalSector) { + LOG_WARN << "There is not digital sector" << sec << endm; + } else { + Int_t Npads = digitalSector->numberOfPadsInRow(row); + for(Int_t pad = 1; pad <= Npads; pad++) { + static Short_t ADCs[__MaxNumberOfTimeBins__]; +#ifdef __TFG__VERSION__ + static Int_t IDTs[__MaxNumberOfTimeBins__]; +#else + static UShort_t IDTs[__MaxNumberOfTimeBins__]; +#endif + digitalSector->getTimeAdc(row,pad,ADCs,IDTs); + for (UInt_t k = 0; k < __MaxNumberOfTimeBins__; k++) { + if (ADCs[k]) plot->Fill(k,pad,ADCs[k]); + } + } + } + } + } + StSPtrVecTpcHit &hits = rowCollection->hits(); + Long_t NoHits = hits.size(); + for (Long64_t k = 0; k < NoHits; k++) { + const StTpcHit *tpcHit = static_cast (hits[k]); + Int_t color = 1; + Int_t style = 43; + Double_t offset = 0.0; + Int_t flag = tpcHit->flag(); + if (flag & 256) {color = 2; style = 29; offset = 0.1; flag &= ~0x100;} // online kTpxO + if (flags > -1 && flag < flags) continue; + Double_t tb = tpcHit->timeBucket(); + Double_t pad = tpcHit->pad(); + TPolyMarker *pm = new TPolyMarker(1,&tb, &pad); + pm->SetMarkerStyle(style); + pm->SetMarkerColor(color); + pm->SetMarkerSize(2); + plot->GetListOfFunctions()->Add(pm); + TBox *box = new TBox(tpcHit->minTmbk()-0.5 + offset,tpcHit->minPad()-0.5 + offset, tpcHit->maxTmbk()+0.5 + offset,tpcHit->maxPad()+0.5 + offset); + box->SetLineWidth(4); + box->SetLineColor(color); + box->SetFillStyle(0); + box->SetFillColor(0); + plot->GetListOfFunctions()->Add(box); + } + plot->Draw("colz"); + return plot; +} diff --git a/StRoot/StTpcHitMaker/StTpcRTSHitMaker.h b/StRoot/StTpcHitMaker/StTpcRTSHitMaker.h index 263455fedae..c570724c234 100644 --- a/StRoot/StTpcHitMaker/StTpcRTSHitMaker.h +++ b/StRoot/StTpcHitMaker/StTpcRTSHitMaker.h @@ -71,39 +71,35 @@ class daq_itpc; class daq_dta; class daq_cld; class tpc23_base; +class TH2F; class StTpcRTSHitMaker : public StMaker { public: StTpcRTSHitMaker(const char *name="tpc_hits") : StMaker(name), fTpx(0), fiTpc(0), -#ifdef __TFG__VERSION__ fTpx23(0), fiTpc23(0), -#endif /* __TFG__VERSION__ */ - fminCharge(0) {} + fminCharge(0) {fgStTpcRTSHitMaker = this;} virtual ~StTpcRTSHitMaker(); - + static StTpcRTSHitMaker *instance() {return fgStTpcRTSHitMaker;} Int_t Init(); Int_t InitRun(Int_t runnumber); Int_t InitRun23(Int_t runnumber); Int_t Make(); -#ifdef __TFG__VERSION__ Int_t Make23(); -#endif /* __TFG__VERSION__ */ -#ifdef __USE_GAIN_FROM_FILE__ Int_t from_file(daq_dta *gain_dta, const Char_t *fname = ""); -#endif /* __USE_GAIN_FROM_FILE__ */ void PrintCld(daq_cld *cld = 0, Int_t IdTruth = 0, Int_t quality=0); void PrintAdc(daq_dta *dta = 0); + static TH2F *PlotSecRow(Int_t sec = 1, Int_t row = 1, Int_t flags = 2); private: daq_tpx *fTpx; //! daq_itpc *fiTpc; //! -#ifdef __TFG__VERSION__ tpc23_base *fTpx23; //! tpc23_base *fiTpc23; //! -#endif /* __TFG__VERSION__ */ + Int_t FixGains(tpc23_base *tpc23, Int_t sector, Int_t row, Int_t npads); // fix dead pads and edges Bool_t fNoiTPCLu; //! Double_t fminCharge; // ! minimum cluster charge in ADC Int_t maxHits[24]; Int_t maxBin0Hits; Int_t bin0Hits; + static StTpcRTSHitMaker *fgStTpcRTSHitMaker; // cvs virtual const char *GetCVS() const { static const char cvs[]="Tag $Name: $ $Id: StTpcRTSHitMaker.h,v 1.19 2021/05/10 21:13:19 fisyak Exp $ built " __DATE__ " " __TIME__ ; return cvs;