185 #include "StSequence.hh"
186 #include "StMCTruth.h"
187 #include "StSvtClassLibrary/StSvtData.hh"
188 #include "StSvtClassLibrary/StSvtHybridData.hh"
189 #include "StSvtClassLibrary/StSvtHybridPed.hh"
190 #include "StSvtClassLibrary/StSvtHybridCollection.hh"
191 #include "StSvtInverseProducts.hh"
192 #include "StSvtProbValues.hh"
193 #include "StSvtPedSub.h"
194 #include "StSvtClassLibrary/StSvtHybridBadAnodes.hh"
195 #include "StSvtSeqAdjMaker.h"
196 #include "StSvtCalibMaker/StSvtPedMaker.h"
197 #include "StMessMgr.h"
198 #include "StIOMaker/StIOMaker.h"
200 #include "St_DataSetIter.h"
201 #include "TObjectSet.h"
206 StSvtSeqAdjMaker::StSvtSeqAdjMaker(
const char *name) :
StMaker(name)
212 mSvtBadAnodes = NULL;
213 mHybridRawData = NULL;
214 mHybridAdjData = NULL;
226 m_thresh_lo = 3+mPedOffSet;
227 m_thresh_hi = 5+mPedOffSet;
235 StSvtSeqAdjMaker::~StSvtSeqAdjMaker(){
238 Int_t StSvtSeqAdjMaker::Init(){
250 for (
int barrel = 1;barrel <= mSvtRawData->getNumberOfBarrels();barrel++) {
251 for (
int ladder = 1;ladder <= mSvtRawData->getNumberOfLadders(barrel);ladder++) {
252 for (
int wafer = 1;wafer <= mSvtRawData->getNumberOfWafers(barrel);wafer++) {
253 for (
int hybrid = 1;hybrid <= mSvtRawData->getNumberOfHybrids();hybrid++) {
254 int index = mSvtRawData->getHybridIndex(barrel,ladder,wafer,hybrid);
255 if(index < 0)
continue;
256 if (mSvtPedColl && mSvtPedColl->at(index))
259 sigma = mProbValue->GetSigma();
260 mProbValue->SetProbValue(sigma);
261 mInvProd->SetProbTable(mProbValue);
267 return StMaker::Init();
270 Int_t StSvtSeqAdjMaker::InitRun(
int runnumber)
273 if(GetSvtRawData() ){
276 dataSet = GetDataSet(
"StSvtConfig");
284 mTotalNumberOfHybrids = mSvtRawData->getTotalNumberOfHybrids();
291 string ioMakerFileName;
297 cout <<
"************************" << mIOMaker << endl;
299 ioMakerFileName = string(mIOMaker->GetFile());
300 FileName = buildFileName( DirName+
"/", baseName(ioMakerFileName),
".SvtGainCal.root");
304 FileName=buildFileName( DirName+
"/",
"SeqAdj-Run"+
GetRunNumber(),
".SvtGainCal.root");
307 CreateHist(mTotalNumberOfHybrids);
313 gMessMgr->Info()<<
" StSvtSeqAdjMaker-info:"<<endm;
314 gMessMgr->Info() <<
" PedOffSet = "<<mPedOffSet<<endm;
315 gMessMgr->Info() <<
" thresh_lo = "<<m_thresh_lo <<endm;
316 gMessMgr->Info() <<
" thresh_hi = "<<m_thresh_hi <<endm;
317 gMessMgr->Info() <<
" n_seq_lo = "<<m_n_seq_lo <<endm;
318 gMessMgr->Info() <<
" n_seq_hi = "<< m_n_seq_hi <<endm;
319 gMessMgr->Info() <<
" inv_prod_lo = "<<m_inv_prod_lo <<endm;
327 Int_t StSvtSeqAdjMaker::GetSvtRawData()
331 dataSet = GetDataSet(
"StSvtRawData");
333 gMessMgr->Warning() <<
" No Svt Raw data set" << endm;
339 gMessMgr->Warning() <<
" No Svt Raw data " << endm;
348 Int_t StSvtSeqAdjMaker::GetSvtPedestals()
354 sdaq->ReadFromFile( mPedFile);
359 dataSet = GetDataSet(
"StSvtPedestal");
367 mSvtRawData->setPedOffset(mPedOffSet);
376 Int_t StSvtSeqAdjMaker::SetSvtData()
381 mSvtAdjData =
new StSvtData(*mSvtRawData);
383 mSvtDataSet->
SetObject((TObject*)mSvtAdjData);
391 Int_t StSvtSeqAdjMaker::SetMinAdcLevels(
int MinAdc1,
int MinAbove1,
392 int MinAdc2,
int MinAbove2,
int PedOffset){
394 m_thresh_lo = MinAdc1+PedOffset;
395 m_thresh_hi = MinAdc2+PedOffset;
396 m_n_seq_lo = MinAbove1;
397 m_n_seq_hi = MinAbove2;
400 mPedOffSet = PedOffset;
407 Int_t StSvtSeqAdjMaker::SetPedestalFile(
const char* pedFile)
409 if(Debug()) gMessMgr->Debug() <<
"opening file called " << pedFile <<
" "
420 Int_t StSvtSeqAdjMaker::SetLowInvProd(
int LowInvProd)
422 m_inv_prod_lo = LowInvProd;
429 Int_t StSvtSeqAdjMaker::GetBadAnodes()
434 dataSet = GetDataSet(
"StSvtBadAnodes");
436 gMessMgr->Warning() <<
" No Svt Bad Anodes data set" << endm;
441 if( !mSvtBadAnodes) {
442 gMessMgr->Warning() <<
" No Svt Bad Anodes data " << endm;
449 Int_t StSvtSeqAdjMaker::CreateHist(Int_t tNuOfHyb)
455 mRawAdc =
new TH1F*[tNuOfHyb];
456 mAdcAfter =
new TH1F*[tNuOfHyb];
459 char RawTitle[25], AdcAfterTitle[25], TimeAnTitle[25];
464 for (
int barrel = 1;barrel <= mSvtRawData->getNumberOfBarrels();barrel++) {
465 for (
int ladder = 1;ladder <= mSvtRawData->getNumberOfLadders(barrel);ladder++) {
466 for (
int wafer = 1;wafer <= mSvtRawData->getNumberOfWafers(barrel);wafer++) {
467 for (
int hybrid = 1;hybrid <= mSvtRawData->getNumberOfHybrids();hybrid++) {
469 int index = mSvtRawData->getHybridIndex(barrel,ladder,wafer,hybrid);
470 if(index < 0)
continue;
472 sprintf(RawTitle,
"RawAdcIn");
473 sprintf(AdcAfterTitle,
"numOfhitsIn");
474 sprintf(TimeAnTitle,
"TimeAn");
475 sprintf(Index,
"%d", index);
476 RawTitle_cut = strcat(RawTitle,Index);
477 AdcAf_cut = strcat(AdcAfterTitle,Index);
478 TimeAnCh = strcat(TimeAnTitle,Index);
480 mRawAdc[index] =
new TH1F(RawTitle_cut,
"Raw ADC for each anode",241,0,241);
481 mAdcAfter[index] =
new TH1F(AdcAf_cut,
"Number of hits in each anode",241,0,241);
487 mOcupancyHisto =
new TH1F(
"OcupancyHisto",
"Anode Occupancy in an event",129,0,128);
488 EventOccupancy =
new TH1F(
"EventOccup",
"Event Occupancy",200,0,100000);
503 if ( GetSvtRawData() )
return kStWarn;
510 gMessMgr->Info() <<
"Working On Event: " << mSvtAdjData->getEventNumber() << endm;
515 for(
int Barrel = 1;Barrel <= mSvtRawData->getNumberOfBarrels();Barrel++){
516 for (
int Ladder = 1;Ladder <= mSvtRawData->getNumberOfLadders(Barrel);Ladder++){
517 for (
int Wafer = 1;Wafer <= mSvtRawData->getNumberOfWafers(Barrel);Wafer++){
518 for(
int Hybrid = 1;Hybrid <=mSvtRawData->getNumberOfHybrids();Hybrid++){
520 int index = mSvtRawData->getHybridIndex(Barrel,Ladder,Wafer,Hybrid);
522 if( index < 0)
continue;
527 if( !mHybridRawData)
continue;
539 mSvtAdjData->put_at(0,index);
540 delete mHybridAdjData;
542 mHybridAdjData->setTimeZero(mHybridRawData->getTimeZero());
543 mHybridAdjData->setSCAZero(mHybridRawData->getSCAZero());
546 mNAnodes = FindBlackAnodes();
548 if( doCommon || !mNAnodes ){
549 if (Debug()) gMessMgr->Debug() <<
"Doing Common mode average for index " << index << endl;
552 for(
int Timebin=0; Timebin<128; Timebin++){
553 mCommonModeNoise[Timebin]=0;
554 mCommonModeNoiseAn[Timebin]=0;
557 for(
int iAnode= 0; iAnode< mHybridRawData->getAnodeList(anolist); iAnode++)
559 Anode = anolist[iAnode];
563 if( doCommon) CommonModeNoiseCalc(iAnode);
567 int TimeLast, TimeAv, TimeSum, TimeAvSav;
572 for(
int TimeBin=0; TimeBin<128; TimeBin++){
573 if(mCommonModeNoiseAn[TimeBin] > 30)
574 mCommonModeNoise[TimeBin] /= mCommonModeNoiseAn[TimeBin];
575 else mCommonModeNoise[TimeBin] =0;
578 if( index < 4 && mCommonModeNoiseAn[TimeBin] > 20){
579 if( TimeLast < TimeBin-3 && TimeSum > 0){
597 for(
int iAnode= 0; iAnode<mHybridRawData->getAnodeList(anolist); iAnode++)
599 Anode = anolist[iAnode];
603 if( BadAnode && BadAnode->isBadAnode(Anode))
continue;
605 if( doCommon) CommonModeNoiseSub(iAnode);
606 else SubtractFirstAnode(iAnode);
609 AdjustSequences1(iAnode, Anode);
613 mInvProd->FindInvProducts(mHybridAdjData,iAnode,mPedOffSet);
615 AdjustSequences2(iAnode, Anode);
619 MakeHistogramsAdc(mHybridRawData,index,Anode,2);
623 mHybridAdjData->setAnodeList();
624 mSvtAdjData->put_at(mHybridAdjData,index);
627 mInvProd->ResetBuffer();
632 cout <<
" Event Occupancy = " << Evt_counts << endl;
634 EventOccupancy->Fill((
float)Evt_counts);
643 Int_t StSvtSeqAdjMaker::AdjustSequences1(
int iAnode,
int Anode){
649 int nSeqOrig, nSeqNow, nSeqTruth, length, count1, count2;
650 int startTimeBin, status;
661 status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
662 status= mHybridRawData->getListTruth (iAnode,nSeqTruth,SeqTruth );
668 for(
int nSeq=0; nSeq< nSeqOrig ; nSeq++){
670 adc=Sequence[nSeq].firstAdc;
671 length = Sequence[nSeq].length;
672 startTimeBin=Sequence[nSeq].startTimeBin;
679 while( (
int)adc[j] > m_thresh_lo && j<length){
682 if( (
int)adc[j] > m_thresh_hi){
689 if( count2 > m_n_seq_hi && count1 > m_n_seq_lo){
691 firstTimeBin = startTimeBin + j - count1 - ExtraBefore;
693 tempSeq1[nSeqNow].firstAdc=&adc[j- count1 - ExtraBefore];
694 tempSeq1[nSeqNow].startTimeBin = firstTimeBin;
695 tempSeq1[nSeqNow].length = 0;
696 if((startTimeBin + j - count1 - ExtraBefore) < 0){
697 tempSeq1[nSeqNow].startTimeBin=0;
698 tempSeq1[nSeqNow].firstAdc=&adc[0];
701 tempSeq1[nSeqNow].length = startTimeBin + j - count1 - ExtraBefore;
704 if((startTimeBin + j - count1 - ExtraBefore) < startTimeBin){
705 tempSeq1[nSeqNow].startTimeBin=startTimeBin;
706 tempSeq1[nSeqNow].firstAdc=&adc[0];
709 tempSeq1[nSeqNow].length = startTimeBin + j - count1 - ExtraBefore
714 tempSeq1[nSeqNow].length += count1+ ExtraAfter+ ExtraBefore;
717 if( tempSeq1[nSeqNow].length + tempSeq1[nSeqNow].startTimeBin > 128)
718 tempSeq1[nSeqNow].length=128-tempSeq1[nSeqNow].startTimeBin +1;
719 if ( tempSeq1[nSeqNow].startTimeBin+ tempSeq1[nSeqNow].length >
720 startTimeBin +length){
721 tempSeq1[nSeqNow].length = (startTimeBin +length) -
722 tempSeq1[nSeqNow].startTimeBin ;
724 if (SeqTruth) tempTru1[nSeqNow]=SeqTruth[nSeq];
735 if (SeqTruth) SeqTruth=tempTru1;
736 mNumOfSeq = MergeSequences(tempSeq1,nSeqNow,SeqTruth);
739 mHybridAdjData->setListSequences(iAnode, Anode,mNumOfSeq, tempSeq1);
741 mHybridAdjData->setListTruth (iAnode, Anode,mNumOfSeq, tempTru1);
753 Int_t StSvtSeqAdjMaker::AdjustSequences2(
int iAnode,
int Anode){
758 int nSeqBefore, nSeqNow, count1, nSeqTruth;
759 int startTimeBin, length, status;
770 double tempBuffer = 0;
775 status = mHybridAdjData->getListSequences(iAnode,nSeqBefore,Sequence);
776 status = mHybridRawData->getListTruth (iAnode,nSeqTruth ,SeqTruth );
778 for(
int Seq = 0; Seq < nSeqBefore; Seq++)
780 startTimeBin =Sequence[Seq].startTimeBin;
781 length = Sequence[Seq].length;
782 adc = Sequence[Seq].firstAdc;
788 tempBuffer = mInvProd->GetBuffer(startTimeBin + j);
790 while(tempBuffer > m_inv_prod_lo && j < length)
794 tempBuffer = mInvProd->GetBuffer(startTimeBin + j);
796 if(count1 > 0 && (tempBuffer < m_inv_prod_lo || j == length))
798 firstTimeBin = startTimeBin + j - count1 - ExtraBefore;
800 tempSeq1[nSeqNow].firstAdc=&adc[j- count1 - ExtraBefore];
801 tempSeq1[nSeqNow].startTimeBin = firstTimeBin;
802 tempSeq1[nSeqNow].length = 0;
803 if((startTimeBin + j - count1 - ExtraBefore) < 0){
804 tempSeq1[nSeqNow].startTimeBin=0;
805 tempSeq1[nSeqNow].firstAdc=&adc[0];
808 tempSeq1[nSeqNow].length = startTimeBin + j - count1 - ExtraBefore;
811 if((startTimeBin + j - count1 - ExtraBefore) < startTimeBin){
812 tempSeq1[nSeqNow].startTimeBin=startTimeBin;
813 tempSeq1[nSeqNow].firstAdc=&adc[0];
816 tempSeq1[nSeqNow].length = startTimeBin + j -
817 count1 - ExtraBefore -startTimeBin;
821 tempSeq1[nSeqNow].length += count1+ ExtraAfter+ ExtraBefore;
824 if( tempSeq1[nSeqNow].length + tempSeq1[nSeqNow].startTimeBin > 128)
825 tempSeq1[nSeqNow].length=128-tempSeq1[nSeqNow].startTimeBin +1;
826 if ( tempSeq1[nSeqNow].startTimeBin+ tempSeq1[nSeqNow].length >
827 startTimeBin +length){
828 tempSeq1[nSeqNow].length = (startTimeBin +length) -
829 tempSeq1[nSeqNow].startTimeBin ;
831 if(SeqTruth) tempTru1[nSeqNow] = SeqTruth[Seq];
842 if (SeqTruth) SeqTruth = tempTru1;
843 mNumOfSeq = MergeSequences(tempSeq1, nSeqNow,SeqTruth);
844 mHybridAdjData->setListSequences(iAnode, Anode,mNumOfSeq, tempSeq1);
846 mHybridAdjData->setListTruth (iAnode, Anode,mNumOfSeq, tempTru1);
863 if (tru) pivo.Add(tru[0]);
864 for(
int i=1; i<nSeq; i++){
866 if( (seq[nSeqNow].startTimeBin + seq[nSeqNow].length)
867 >= seq[i].startTimeBin){
868 EndTime = seq[i].startTimeBin + seq[i].length;
869 seq[nSeqNow].length = EndTime - seq[nSeqNow].startTimeBin;
870 if (tru) { pivo.Add(tru[i]); tru[nSeqNow] = pivo.Get();}
875 seq[nSeqNow] = seq[i];
876 if (tru){ pivo.Reset(); pivo.Add(tru[i]);}
885 void StSvtSeqAdjMaker::CommonModeNoiseCalc(
int iAnode){
889 int nSeqOrig, length;
890 int startTimeBin, status;
896 status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
898 for(
int nSeq=0; nSeq< nSeqOrig ; nSeq++){
900 adc=Sequence[nSeq].firstAdc;
901 length = Sequence[nSeq].length;
902 startTimeBin=Sequence[nSeq].startTimeBin;
907 mCommonModeNoise[j+startTimeBin] += (int)adc[j] - mPedOffSet;
908 mCommonModeNoiseAn[j+startTimeBin]++;
918 void StSvtSeqAdjMaker::CommonModeNoiseSub(
int iAnode){
922 int nSeqOrig, length;
923 int startTimeBin, status;
929 status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
931 for(
int nSeq=0; nSeq< nSeqOrig ; nSeq++){
933 adc=Sequence[nSeq].firstAdc;
934 length = Sequence[nSeq].length;
935 startTimeBin=Sequence[nSeq].startTimeBin;
939 if( (
int) adc[j]-mCommonModeNoise[j+startTimeBin] < 0) adc[j]=0;
941 adc[j] -=mCommonModeNoise[j+startTimeBin];
951 void StSvtSeqAdjMaker::SubtractFirstAnode(
int iAnode){
955 int nSeq, nSeqOrig, length;
956 int startTimeBin, status, j;
962 status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
965 for( nSeq=0; nSeq< nSeqOrig ; nSeq++){
967 adc=Sequence[nSeq].firstAdc;
968 length = Sequence[nSeq].length;
969 startTimeBin=Sequence[nSeq].startTimeBin;
973 if( mNAnodes) adcMean = adcCommon[j+startTimeBin]/mNAnodes;
976 if( (
int)adc[j]- adcMean < 0) adc[j]=0;
977 else if( adcMean < 0){
978 adc[j] += (
unsigned char)(-1*adcMean);
981 adc[j] -= (
unsigned char)adcMean;
991 int StSvtSeqAdjMaker::FindBlackAnodes(){
997 int i, j, startTimeBin;
1006 status= mHybridRawData->getSequences(240,nSequence,Seq);
1008 for(j=0; j<128; j++) adcCommon[j]=0;
1009 for( i=0; i<nSequence; i++) length += Seq[i].length;
1012 status= mHybridRawData->getSequences(239,nSequence,Seq);
1015 for( i=0; i<nSequence; i++) length += Seq[i].length;
1018 status= mHybridRawData->getSequences(2,nSequence,Seq);
1021 for( i=0; i<nSequence; i++) length += Seq[i].length;
1033 for(
int nSeq=0; nSeq< nSequence ; nSeq++){
1035 adc=Seq[nSeq].firstAdc;
1036 length = Seq[nSeq].length;
1037 startTimeBin=Seq[nSeq].startTimeBin;
1040 adcCommon[startTimeBin+j] = adc[j]-mPedOffSet;
1041 adcAv += (int) adc[j];
1046 if( adcAv <100 || adcAv> 25000) {
1048 for(j=0; j<128; j++) adcCommon[j]=0;
1054 status= mHybridRawData->getSequences(2,nSequence,Seq);
1057 for( i=0; i<nSequence; i++) length += Seq[i].length;
1059 status= mHybridRawData->getSequences(1,nSequence,Seq);
1062 for( i=0; i<nSequence; i++) length += Seq[i].length;
1071 for(
int nSeq=0; nSeq< nSequence ; nSeq++){
1073 adc=Seq[nSeq].firstAdc;
1074 length = Seq[nSeq].length;
1075 startTimeBin=Seq[nSeq].startTimeBin;
1078 adcCommon[startTimeBin+j] += adc[j]-mPedOffSet;
1079 adcAv += (int) adc[j];
1084 if( adcAv <100 || adcAv> 25000) {
1089 for(
int nSeq=0; nSeq< nSequence ; nSeq++){
1091 adc=Seq[nSeq].firstAdc;
1092 length = Seq[nSeq].length;
1093 startTimeBin=Seq[nSeq].startTimeBin;
1096 adcCommon[startTimeBin+j] -= adc[j]-mPedOffSet;
1097 adcAv += (int) adc[j];
1108 void StSvtSeqAdjMaker::MakeHistogramsAdc(
StSvtHybridData* hybridData,
int index,
int Anode,
int Count){
1121 status = hybridData->getSequences(Anode,mSequence,svtSequence);
1124 for(
int mSeq = 0; mSeq < mSequence; mSeq++)
1126 adc = svtSequence[mSeq].firstAdc;
1127 len = svtSequence[mSeq].length;
1128 if (len>12)
continue;
1129 for(
int j = 0 ; j < len; j++){
1130 mRawAdc[index]->Fill(Anode,(
int)adc[j]);
1132 mAdcAfter[index]->Fill(Anode);
1134 if (adc[j] >0) numOfPixels++;
1135 if (adc[j] >0) Evt_counts++;
1138 mOcupancyHisto->Fill(numOfPixels);
1142 Int_t StSvtSeqAdjMaker::Reset(){
1150 mHybridRawData = NULL;
1151 mHybridAdjData = NULL;
1154 mSvtBadAnodes = NULL;
1161 string StSvtSeqAdjMaker::baseName(
string s){
1165 pos = name.find_last_of(
"/");
1166 if (pos!=string::npos ) name.erase(0, pos );
1167 pos = name.find_first_of(
".");
1168 if (pos!=string::npos ) name.erase(pos,name.length()-pos );
1172 string StSvtSeqAdjMaker::buildFileName(
string dir,
string fileName,
string extention){
1174 fileName = dir + fileName + extention;
1175 while (fileName.find(
"//")!=string::npos) {
1176 int pos = fileName.find(
"//");
1177 fileName.erase(pos,1);
1185 if (Debug()) gMessMgr->Debug() <<
"In StSvtSeqAdjMaker::Finish() "
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
virtual const char * GetName() const
special overload
virtual Int_t GetRunNumber() const
Returns the current RunNumber.