00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 #include "TFile.h"
00180 #include "TH1.h"
00181 #include "TH2.h"
00182 #include "StSequence.hh"
00183 #include "StMCTruth.h"
00184 #include "StSvtClassLibrary/StSvtData.hh"
00185 #include "StSvtClassLibrary/StSvtHybridData.hh"
00186 #include "StSvtClassLibrary/StSvtHybridPed.hh"
00187 #include "StSvtClassLibrary/StSvtHybridCollection.hh"
00188 #include "StSvtInverseProducts.hh"
00189 #include "StSvtProbValues.hh"
00190 #include "StSvtPedSub.h"
00191 #include "StSvtClassLibrary/StSvtHybridBadAnodes.hh"
00192 #include "StSvtSeqAdjMaker.h"
00193 #include "StSvtCalibMaker/StSvtPedMaker.h"
00194 #include "StMessMgr.h"
00195 #include "StIOMaker/StIOMaker.h"
00196
00197 #include "St_DataSetIter.h"
00198 #include "TObjectSet.h"
00199
00200
00201
00202
00203 StSvtSeqAdjMaker::StSvtSeqAdjMaker(const char *name) : StMaker(name)
00204 {
00205
00206 mSvtDataSet = NULL;
00207 mSvtAdjData = NULL;
00208 mSvtRawData = NULL;
00209 mSvtBadAnodes = NULL;
00210 mHybridRawData = NULL;
00211 mHybridAdjData = NULL;
00212 mSvtPedSub = NULL;
00213 mSvtPedColl = NULL;
00214 anolist = NULL;
00215 mInvProd = NULL;
00216 mProbValue = NULL;
00217
00218
00219
00220 mPedFile = NULL;
00221 mPedOffSet = 20;
00222 m_thresh_lo = 3+mPedOffSet;
00223 m_thresh_hi = 5+mPedOffSet;
00224 m_n_seq_lo = 2;
00225 m_n_seq_hi = 0;
00226 m_inv_prod_lo = 0;
00227
00228 }
00229
00230
00231 StSvtSeqAdjMaker::~StSvtSeqAdjMaker(){
00232 }
00233
00234 Int_t StSvtSeqAdjMaker::Init(){
00235
00236
00237 hfile = NULL;
00238 GetSvtRawData();
00239
00240 SetSvtData();
00241
00242 mInvProd = new StSvtInverseProducts();
00243 mProbValue = new StSvtProbValues();
00244
00245 float sigma;
00246
00247 for (int barrel = 1;barrel <= mSvtRawData->getNumberOfBarrels();barrel++) {
00248 for (int ladder = 1;ladder <= mSvtRawData->getNumberOfLadders(barrel);ladder++) {
00249 for (int wafer = 1;wafer <= mSvtRawData->getNumberOfWafers(barrel);wafer++) {
00250 for (int hybrid = 1;hybrid <= mSvtRawData->getNumberOfHybrids();hybrid++) {
00251 int index = mSvtRawData->getHybridIndex(barrel,ladder,wafer,hybrid);
00252 if(index < 0) continue;
00253 if (mSvtPedColl && mSvtPedColl->at(index))
00254 sigma = ((StSvtHybridPed*)mSvtPedColl->at(index))->getRMS();
00255 else
00256 sigma = mProbValue->GetSigma();
00257 mProbValue->SetProbValue(sigma);
00258 mInvProd->SetProbTable(mProbValue);
00259 }
00260 }
00261 }
00262 }
00263
00264 return StMaker::Init();
00265 }
00266
00267 Int_t StSvtSeqAdjMaker::InitRun( int runnumber)
00268 {
00269
00270 if(GetSvtRawData() ){
00271
00272 St_DataSet *dataSet = NULL;
00273 dataSet = GetDataSet("StSvtConfig");
00274
00275 if (!dataSet) return kStWarn;
00276
00277 mSvtRawData = new StSvtData((StSvtConfig*)(dataSet->GetObject()));
00278 AddData(new TObjectSet("StSvtRawData",mSvtRawData));
00279 }
00280
00281 mTotalNumberOfHybrids = mSvtRawData->getTotalNumberOfHybrids();
00282
00283 if( hfile){
00284 hfile->Write();
00285 hfile->Close();
00286 }
00287
00288 string ioMakerFileName;
00289 string FileName;
00290 string DirName;
00291 DirName=".";
00292
00293 StIOMaker* mIOMaker = (StIOMaker*)GetMaker("inputStream");
00294 cout << "************************" << mIOMaker << endl;
00295 if (mIOMaker){
00296 ioMakerFileName = string(mIOMaker->GetFile());
00297 FileName = buildFileName( DirName+"/", baseName(ioMakerFileName),".SvtGainCal.root");
00298
00299 }else
00300 {
00301 FileName=buildFileName( DirName+"/", "SeqAdj-Run"+GetRunNumber(),".SvtGainCal.root");
00302 }
00303
00304 CreateHist(mTotalNumberOfHybrids);
00305
00306 GetBadAnodes();
00307
00308 GetSvtPedestals();
00309
00310 gMessMgr->Info()<< " StSvtSeqAdjMaker-info:"<<endm;
00311 gMessMgr->Info() << " PedOffSet = "<<mPedOffSet<<endm;
00312 gMessMgr->Info() << " thresh_lo = "<<m_thresh_lo <<endm;
00313 gMessMgr->Info() << " thresh_hi = "<<m_thresh_hi <<endm;
00314 gMessMgr->Info() << " n_seq_lo = "<<m_n_seq_lo <<endm;
00315 gMessMgr->Info() << " n_seq_hi = "<< m_n_seq_hi <<endm;
00316 gMessMgr->Info() << " inv_prod_lo = "<<m_inv_prod_lo <<endm;
00317
00318 return kStOK;
00319 }
00320
00321
00322
00323
00324 Int_t StSvtSeqAdjMaker::GetSvtRawData()
00325 {
00326 St_DataSet *dataSet;
00327
00328 dataSet = GetDataSet("StSvtRawData");
00329 if( !dataSet) {
00330 gMessMgr->Warning() << " No Svt Raw data set" << endm;
00331 return kStWarn;
00332 }
00333
00334 mSvtRawData = (StSvtData*)(dataSet->GetObject());
00335 if( !mSvtRawData) {
00336 gMessMgr->Warning() << " No Svt Raw data " << endm;
00337 return kStWarn;
00338 }
00339 return kStOK;
00340 }
00341
00342
00343
00344
00345 Int_t StSvtSeqAdjMaker::GetSvtPedestals()
00346 {
00347 if (mPedFile) {
00348 StSvtPedMaker* sdaq = (StSvtPedMaker*)GetMaker("SvtPed");
00349
00350 if( sdaq)
00351 sdaq->ReadFromFile( mPedFile);
00352 }
00353
00354 St_DataSet *dataSet;
00355
00356 dataSet = GetDataSet("StSvtPedestal");
00357
00358
00359 if (dataSet) {
00360 mSvtPedColl = (StSvtHybridCollection*)(dataSet->GetObject());
00361 mSvtPedSub = new StSvtPedSub(mSvtPedColl);
00362
00363
00364 mSvtRawData->setPedOffset(mPedOffSet);
00365 }
00366
00367 return kStOK;
00368 }
00369
00370
00371
00372
00373 Int_t StSvtSeqAdjMaker::SetSvtData()
00374 {
00375 mSvtDataSet = new St_ObjectSet("StSvtData");
00376 AddData(mSvtDataSet);
00377
00378 mSvtAdjData = new StSvtData(*mSvtRawData);
00379
00380 mSvtDataSet->SetObject((TObject*)mSvtAdjData);
00381
00382
00383 return kStOK;
00384 }
00385
00386
00387
00388 Int_t StSvtSeqAdjMaker::SetMinAdcLevels( int MinAdc1, int MinAbove1,
00389 int MinAdc2, int MinAbove2, int PedOffset){
00390
00391 m_thresh_lo = MinAdc1+PedOffset;
00392 m_thresh_hi = MinAdc2+PedOffset;
00393 m_n_seq_lo = MinAbove1;
00394 m_n_seq_hi = MinAbove2;
00395
00396
00397 mPedOffSet = PedOffset;
00398
00399 return kStOK;
00400 }
00401
00402
00403
00404 Int_t StSvtSeqAdjMaker::SetPedestalFile(const char* pedFile)
00405 {
00406 if(Debug()) gMessMgr->Debug() << "opening file called " << pedFile << " "
00407 << GetName() << endm;
00408
00409 mPedFile = pedFile;
00410
00411 return kStOK;
00412 }
00413
00414
00415
00416
00417 Int_t StSvtSeqAdjMaker::SetLowInvProd(int LowInvProd)
00418 {
00419 m_inv_prod_lo = LowInvProd;
00420
00421 return kStOK;
00422 }
00423
00424
00425
00426 Int_t StSvtSeqAdjMaker::GetBadAnodes()
00427 {
00428
00429 St_DataSet *dataSet;
00430
00431 dataSet = GetDataSet("StSvtBadAnodes");
00432 if( !dataSet) {
00433 gMessMgr->Warning() << " No Svt Bad Anodes data set" << endm;
00434 return kStWarn;
00435 }
00436
00437 mSvtBadAnodes = (StSvtHybridCollection*)(dataSet->GetObject());
00438 if( !mSvtBadAnodes) {
00439 gMessMgr->Warning() << " No Svt Bad Anodes data " << endm;
00440 return kStWarn;
00441 }
00442 return kStOK;
00443 }
00444
00445
00446 Int_t StSvtSeqAdjMaker::CreateHist(Int_t tNuOfHyb)
00447 {
00448
00449
00450
00451
00452 mRawAdc = new TH1F*[tNuOfHyb];
00453 mAdcAfter = new TH1F*[tNuOfHyb];
00454
00455
00456 char RawTitle[25], AdcAfterTitle[25], TimeAnTitle[25];
00457 char Index[4];
00458 char* RawTitle_cut;
00459 char* AdcAf_cut;
00460 char* TimeAnCh;
00461 for (int barrel = 1;barrel <= mSvtRawData->getNumberOfBarrels();barrel++) {
00462 for (int ladder = 1;ladder <= mSvtRawData->getNumberOfLadders(barrel);ladder++) {
00463 for (int wafer = 1;wafer <= mSvtRawData->getNumberOfWafers(barrel);wafer++) {
00464 for (int hybrid = 1;hybrid <= mSvtRawData->getNumberOfHybrids();hybrid++) {
00465
00466 int index = mSvtRawData->getHybridIndex(barrel,ladder,wafer,hybrid);
00467 if(index < 0) continue;
00468
00469 sprintf(RawTitle,"RawAdcIn");
00470 sprintf(AdcAfterTitle,"numOfhitsIn");
00471 sprintf(TimeAnTitle,"TimeAn");
00472 sprintf(Index,"%d", index);
00473 RawTitle_cut = strcat(RawTitle,Index);
00474 AdcAf_cut = strcat(AdcAfterTitle,Index);
00475 TimeAnCh = strcat(TimeAnTitle,Index);
00476
00477 mRawAdc[index] = new TH1F(RawTitle_cut,"Raw ADC for each anode",241,0,241);
00478 mAdcAfter[index] = new TH1F(AdcAf_cut,"Number of hits in each anode",241,0,241);
00479
00480 }
00481 }
00482 }
00483 }
00484 mOcupancyHisto = new TH1F("OcupancyHisto","Anode Occupancy in an event",129,0,128);
00485 EventOccupancy = new TH1F("EventOccup","Event Occupancy",200,0,100000);
00486
00487 return kStOK;
00488 }
00489
00490
00491
00492 Int_t StSvtSeqAdjMaker::Make()
00493 {
00494
00495 int Anode;
00496
00497 StSvtHybridBadAnodes* BadAnode=NULL;
00498
00499
00500 if ( GetSvtRawData() ) return kStWarn;
00501
00502 SetSvtData();
00503
00504
00505
00506
00507 gMessMgr->Info() << "Working On Event: " << mSvtAdjData->getEventNumber() << endm;
00508
00509
00510 Evt_counts=0;
00511
00512 for(int Barrel = 1;Barrel <= mSvtRawData->getNumberOfBarrels();Barrel++){
00513 for (int Ladder = 1;Ladder <= mSvtRawData->getNumberOfLadders(Barrel);Ladder++){
00514 for (int Wafer = 1;Wafer <= mSvtRawData->getNumberOfWafers(Barrel);Wafer++){
00515 for( int Hybrid = 1;Hybrid <=mSvtRawData->getNumberOfHybrids();Hybrid++){
00516
00517 int index = mSvtRawData->getHybridIndex(Barrel,Ladder,Wafer,Hybrid);
00518
00519 if( index < 0) continue;
00520
00521 mHybridRawData = (StSvtHybridData *)mSvtRawData->at(index);
00522
00523
00524 if( !mHybridRawData) continue;
00525
00526
00527
00528
00529
00530
00531
00532 if (mSvtBadAnodes)
00533 BadAnode = (StSvtHybridBadAnodes*)mSvtBadAnodes->at(index);
00534
00535 mHybridAdjData = (StSvtHybridData *)mSvtAdjData->at(index);
00536 mSvtAdjData->put_at(0,index);
00537 delete mHybridAdjData;
00538 mHybridAdjData = new StSvtHybridData(Barrel,Ladder,Wafer,Hybrid);
00539 mHybridAdjData->setTimeZero(mHybridRawData->getTimeZero());
00540 mHybridAdjData->setSCAZero(mHybridRawData->getSCAZero());
00541
00542 doCommon = 1;
00543 mNAnodes = FindBlackAnodes();
00544
00545 if( doCommon || !mNAnodes ){
00546 if (Debug()) gMessMgr->Debug() << "Doing Common mode average for index " << index << endl;
00547
00548
00549 for(int Timebin=0; Timebin<128; Timebin++){
00550 mCommonModeNoise[Timebin]=0;
00551 mCommonModeNoiseAn[Timebin]=0;
00552 }
00553 }
00554 for( int iAnode= 0; iAnode< mHybridRawData->getAnodeList(anolist); iAnode++)
00555 {
00556 Anode = anolist[iAnode];
00557
00558
00559
00560 if( doCommon) CommonModeNoiseCalc(iAnode);
00561 }
00562
00563 if( doCommon){
00564 int TimeLast, TimeAv, TimeSum, TimeAvSav;
00565 TimeLast = 0;
00566 TimeSum = 0;
00567 TimeAv=0;
00568 TimeAvSav = 0;
00569 for( int TimeBin=0; TimeBin<128; TimeBin++){
00570 if(mCommonModeNoiseAn[TimeBin] > 30)
00571 mCommonModeNoise[TimeBin] /= mCommonModeNoiseAn[TimeBin];
00572 else mCommonModeNoise[TimeBin] =0;
00573
00574 if( Debug()){
00575 if( index < 4 && mCommonModeNoiseAn[TimeBin] > 20){
00576 if( TimeLast < TimeBin-3 && TimeSum > 0){
00577
00578 TimeAv /= TimeSum;
00579 TimeLast = TimeBin;
00580 TimeAvSav = TimeAv;
00581 TimeAv = 0;
00582 TimeSum=0;
00583 }
00584 else{
00585 TimeAv +=TimeBin;
00586 TimeSum++;
00587 TimeLast = TimeBin;
00588 }
00589 }
00590 }
00591 }
00592 }
00593
00594 for( int iAnode= 0; iAnode<mHybridRawData->getAnodeList(anolist); iAnode++)
00595 {
00596 Anode = anolist[iAnode];
00597
00598
00599
00600 if( BadAnode && BadAnode->isBadAnode(Anode)) continue;
00601
00602 if( doCommon) CommonModeNoiseSub(iAnode);
00603 else SubtractFirstAnode(iAnode);
00604
00605
00606 AdjustSequences1(iAnode, Anode);
00607
00608
00609 if(m_inv_prod_lo){
00610 mInvProd->FindInvProducts(mHybridAdjData,iAnode,mPedOffSet);
00611
00612 AdjustSequences2(iAnode, Anode);
00613
00614 }
00615
00616 MakeHistogramsAdc(mHybridRawData,index,Anode,2);
00617 }
00618
00619
00620 mHybridAdjData->setAnodeList();
00621 mSvtAdjData->put_at(mHybridAdjData,index);
00622 }
00623
00624 mInvProd->ResetBuffer();
00625 }
00626 }
00627 }
00628 cout << endl;
00629 cout << " Event Occupancy = " << Evt_counts << endl;
00630
00631 EventOccupancy->Fill((float)Evt_counts);
00632 Evt_counts=0;
00633
00634 return kStOK;
00635
00636 }
00637
00638
00639
00640 Int_t StSvtSeqAdjMaker::AdjustSequences1(int iAnode, int Anode){
00641
00642
00643
00644
00645
00646 int nSeqOrig, nSeqNow, nSeqTruth, length, count1, count2;
00647 int startTimeBin, status;
00648 StSequence* Sequence;
00649 StMCTruth* SeqTruth;
00650 unsigned char* adc;
00651
00652
00653 int ExtraBefore = 0;
00654 int ExtraAfter = 0;
00655 int firstTimeBin;
00656
00657
00658 status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
00659 status= mHybridRawData->getListTruth (iAnode,nSeqTruth,SeqTruth );
00660
00661
00662 nSeqNow = 0;
00663 StSequence tempSeq1[128];
00664 StMCTruth tempTru1[128];
00665 for( int nSeq=0; nSeq< nSeqOrig ; nSeq++){
00666
00667 adc=Sequence[nSeq].firstAdc;
00668 length = Sequence[nSeq].length;
00669 startTimeBin=Sequence[nSeq].startTimeBin;
00670
00671 int j =0;
00672 while( j<length){
00673 count1=0;
00674 count2=0;
00675
00676 while( (int)adc[j] > m_thresh_lo && j<length){
00677 count1++;
00678
00679 if( (int)adc[j] > m_thresh_hi){
00680 count2++;
00681 }
00682
00683 j++;
00684 }
00685
00686 if( count2 > m_n_seq_hi && count1 > m_n_seq_lo){
00687
00688 firstTimeBin = startTimeBin + j - count1 - ExtraBefore;
00689
00690 tempSeq1[nSeqNow].firstAdc=&adc[j- count1 - ExtraBefore];
00691 tempSeq1[nSeqNow].startTimeBin = firstTimeBin;
00692 tempSeq1[nSeqNow].length = 0;
00693 if((startTimeBin + j - count1 - ExtraBefore) < 0){
00694 tempSeq1[nSeqNow].startTimeBin=0;
00695 tempSeq1[nSeqNow].firstAdc=&adc[0];
00696
00697
00698 tempSeq1[nSeqNow].length = startTimeBin + j - count1 - ExtraBefore;
00699 }
00700
00701 if((startTimeBin + j - count1 - ExtraBefore) < startTimeBin){
00702 tempSeq1[nSeqNow].startTimeBin=startTimeBin;
00703 tempSeq1[nSeqNow].firstAdc=&adc[0];
00704
00705
00706 tempSeq1[nSeqNow].length = startTimeBin + j - count1 - ExtraBefore
00707 -startTimeBin;
00708 }
00709
00710
00711 tempSeq1[nSeqNow].length += count1+ ExtraAfter+ ExtraBefore;
00712
00713
00714 if( tempSeq1[nSeqNow].length + tempSeq1[nSeqNow].startTimeBin > 128)
00715 tempSeq1[nSeqNow].length=128-tempSeq1[nSeqNow].startTimeBin +1;
00716 if ( tempSeq1[nSeqNow].startTimeBin+ tempSeq1[nSeqNow].length >
00717 startTimeBin +length){
00718 tempSeq1[nSeqNow].length = (startTimeBin +length) -
00719 tempSeq1[nSeqNow].startTimeBin ;
00720 }
00721 if (SeqTruth) tempTru1[nSeqNow]=SeqTruth[nSeq];
00722 nSeqNow++;
00723 }
00724
00725
00726 j++;
00727 }
00728 }
00729
00730 mNumOfSeq=0;
00731 if( nSeqNow > 0){
00732 if (SeqTruth) SeqTruth=tempTru1;
00733 mNumOfSeq = MergeSequences(tempSeq1,nSeqNow,SeqTruth);
00734 }
00735
00736 mHybridAdjData->setListSequences(iAnode, Anode,mNumOfSeq, tempSeq1);
00737 if (SeqTruth)
00738 mHybridAdjData->setListTruth (iAnode, Anode,mNumOfSeq, tempTru1);
00739
00740
00741
00742
00743
00744
00745 return kStOK;
00746 }
00747
00748
00749
00750 Int_t StSvtSeqAdjMaker::AdjustSequences2(int iAnode, int Anode){
00751
00752
00753
00754
00755 int nSeqBefore, nSeqNow, count1, nSeqTruth;
00756 int startTimeBin, length, status;
00757 StSequence* Sequence;
00758 StMCTruth* SeqTruth;
00759 unsigned char* adc;
00760
00761
00762 int ExtraBefore=0;
00763 int ExtraAfter=0;
00764
00765 int firstTimeBin;
00766
00767 double tempBuffer = 0;
00768
00769 nSeqNow = 0;
00770 StSequence tempSeq1[128];
00771 StMCTruth tempTru1[128];
00772 status = mHybridAdjData->getListSequences(iAnode,nSeqBefore,Sequence);
00773 status = mHybridRawData->getListTruth (iAnode,nSeqTruth ,SeqTruth );
00774
00775 for(int Seq = 0; Seq < nSeqBefore; Seq++)
00776 {
00777 startTimeBin =Sequence[Seq].startTimeBin;
00778 length = Sequence[Seq].length;
00779 adc = Sequence[Seq].firstAdc;
00780
00781 int j=0;
00782 while( j < length)
00783 {
00784 count1 = 0;
00785 tempBuffer = mInvProd->GetBuffer(startTimeBin + j);
00786
00787 while(tempBuffer > m_inv_prod_lo && j < length)
00788 {
00789 ++count1;
00790 ++j;
00791 tempBuffer = mInvProd->GetBuffer(startTimeBin + j);
00792 }
00793 if(count1 > 0 && (tempBuffer < m_inv_prod_lo || j == length))
00794 {
00795 firstTimeBin = startTimeBin + j - count1 - ExtraBefore;
00796
00797 tempSeq1[nSeqNow].firstAdc=&adc[j- count1 - ExtraBefore];
00798 tempSeq1[nSeqNow].startTimeBin = firstTimeBin;
00799 tempSeq1[nSeqNow].length = 0;
00800 if((startTimeBin + j - count1 - ExtraBefore) < 0){
00801 tempSeq1[nSeqNow].startTimeBin=0;
00802 tempSeq1[nSeqNow].firstAdc=&adc[0];
00803
00804
00805 tempSeq1[nSeqNow].length = startTimeBin + j - count1 - ExtraBefore;
00806 }
00807
00808 if((startTimeBin + j - count1 - ExtraBefore) < startTimeBin){
00809 tempSeq1[nSeqNow].startTimeBin=startTimeBin;
00810 tempSeq1[nSeqNow].firstAdc=&adc[0];
00811
00812
00813 tempSeq1[nSeqNow].length = startTimeBin + j -
00814 count1 - ExtraBefore -startTimeBin;
00815 }
00816
00817
00818 tempSeq1[nSeqNow].length += count1+ ExtraAfter+ ExtraBefore;
00819
00820
00821 if( tempSeq1[nSeqNow].length + tempSeq1[nSeqNow].startTimeBin > 128)
00822 tempSeq1[nSeqNow].length=128-tempSeq1[nSeqNow].startTimeBin +1;
00823 if ( tempSeq1[nSeqNow].startTimeBin+ tempSeq1[nSeqNow].length >
00824 startTimeBin +length){
00825 tempSeq1[nSeqNow].length = (startTimeBin +length) -
00826 tempSeq1[nSeqNow].startTimeBin ;
00827 }
00828 if(SeqTruth) tempTru1[nSeqNow] = SeqTruth[Seq];
00829 nSeqNow++;
00830
00831 }
00832 j++;
00833 }
00834
00835 }
00836
00837
00838 if( nSeqBefore >0){
00839 if (SeqTruth) SeqTruth = tempTru1;
00840 mNumOfSeq = MergeSequences(tempSeq1, nSeqNow,SeqTruth);
00841 mHybridAdjData->setListSequences(iAnode, Anode,mNumOfSeq, tempSeq1);
00842 if (SeqTruth)
00843 mHybridAdjData->setListTruth (iAnode, Anode,mNumOfSeq, tempTru1);
00844 }
00845
00846
00847 return kStOK;
00848
00849 }
00850
00851
00852 Int_t StSvtSeqAdjMaker::MergeSequences( StSequence* seq, int nSeq, StMCTruth* tru){
00853
00854
00855
00856
00857 int nSeqNow = 0;
00858 int EndTime;
00859 StMCPivotTruth pivo(1);
00860 if (tru) pivo.Add(tru[0]);
00861 for( int i=1; i<nSeq; i++){
00862
00863 if( (seq[nSeqNow].startTimeBin + seq[nSeqNow].length)
00864 >= seq[i].startTimeBin){
00865 EndTime = seq[i].startTimeBin + seq[i].length;
00866 seq[nSeqNow].length = EndTime - seq[nSeqNow].startTimeBin;
00867 if (tru) { pivo.Add(tru[i]); tru[nSeqNow] = pivo.Get();}
00868
00869 }
00870 else{
00871 nSeqNow++;
00872 seq[nSeqNow] = seq[i];
00873 if (tru){ pivo.Reset(); pivo.Add(tru[i]);}
00874 }
00875
00876 }
00877
00878 return nSeqNow+1;
00879 }
00880
00881
00882 void StSvtSeqAdjMaker::CommonModeNoiseCalc(int iAnode){
00883
00884
00885
00886 int nSeqOrig, length;
00887 int startTimeBin, status;
00888 StSequence* Sequence;
00889 unsigned char* adc;
00890
00891
00892
00893 status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
00894
00895 for( int nSeq=0; nSeq< nSeqOrig ; nSeq++){
00896
00897 adc=Sequence[nSeq].firstAdc;
00898 length = Sequence[nSeq].length;
00899 startTimeBin=Sequence[nSeq].startTimeBin;
00900
00901 int j =0;
00902 while( j<length){
00903
00904 mCommonModeNoise[j+startTimeBin] += (int)adc[j] - mPedOffSet;
00905 mCommonModeNoiseAn[j+startTimeBin]++;
00906 j++;
00907
00908
00909 }
00910 }
00911 return;
00912 }
00913
00914
00915 void StSvtSeqAdjMaker::CommonModeNoiseSub(int iAnode){
00916
00917
00918
00919 int nSeqOrig, length;
00920 int startTimeBin, status;
00921 StSequence* Sequence;
00922 unsigned char* adc;
00923
00924
00925
00926 status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
00927
00928 for( int nSeq=0; nSeq< nSeqOrig ; nSeq++){
00929
00930 adc=Sequence[nSeq].firstAdc;
00931 length = Sequence[nSeq].length;
00932 startTimeBin=Sequence[nSeq].startTimeBin;
00933
00934 int j =0;
00935 while( j<length){
00936 if( (int) adc[j]-mCommonModeNoise[j+startTimeBin] < 0) adc[j]=0;
00937 else{
00938 adc[j] -=mCommonModeNoise[j+startTimeBin];
00939 }
00940 j++;
00941 }
00942 }
00943 return;
00944 }
00945
00946
00947
00948 void StSvtSeqAdjMaker::SubtractFirstAnode(int iAnode){
00949
00950
00951
00952 int nSeq, nSeqOrig, length;
00953 int startTimeBin, status, j;
00954 int adcMean;
00955 StSequence* Sequence;
00956 unsigned char* adc;
00957
00958
00959 status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
00960
00961 adcMean = 0;
00962 for( nSeq=0; nSeq< nSeqOrig ; nSeq++){
00963
00964 adc=Sequence[nSeq].firstAdc;
00965 length = Sequence[nSeq].length;
00966 startTimeBin=Sequence[nSeq].startTimeBin;
00967 j =0;
00968 while( j<length){
00969
00970 if( mNAnodes) adcMean = adcCommon[j+startTimeBin]/mNAnodes;
00971
00972
00973 if( (int)adc[j]- adcMean < 0) adc[j]=0;
00974 else if( adcMean < 0){
00975 adc[j] += (unsigned char)(-1*adcMean);
00976 }
00977 else{
00978 adc[j] -= (unsigned char)adcMean;
00979 }
00980
00981 j++;
00982 }
00983 }
00984 return;
00985 }
00986
00987
00988 int StSvtSeqAdjMaker::FindBlackAnodes(){
00989
00990
00991
00992
00993 int status, length;
00994 int i, j, startTimeBin;
00995 int nSequence = 0;
00996 StSequence* Seq = NULL;
00997 unsigned char *adc;
00998
00999 doCommon = 0;
01000 mNAnodes=2;
01001 int adcAv=0;
01002
01003 status= mHybridRawData->getSequences(240,nSequence,Seq);
01004 length = 0;
01005 for(j=0; j<128; j++) adcCommon[j]=0;
01006 for( i=0; i<nSequence; i++) length += Seq[i].length;
01007 if( length < 126){
01008
01009 status= mHybridRawData->getSequences(239,nSequence,Seq);
01010 length = 0;
01011
01012 for( i=0; i<nSequence; i++) length += Seq[i].length;
01013 if( length < 126){
01014
01015 status= mHybridRawData->getSequences(2,nSequence,Seq);
01016 length = 0;
01017
01018 for( i=0; i<nSequence; i++) length += Seq[i].length;
01019 if( length < 126){
01020
01021 doCommon =1;
01022 }
01023 }
01024 }
01025
01026
01027 if( !doCommon){
01028
01029
01030 for( int nSeq=0; nSeq< nSequence ; nSeq++){
01031
01032 adc=Seq[nSeq].firstAdc;
01033 length = Seq[nSeq].length;
01034 startTimeBin=Seq[nSeq].startTimeBin;
01035 j=0;
01036 while( j<length){
01037 adcCommon[startTimeBin+j] = adc[j]-mPedOffSet;
01038 adcAv += (int) adc[j];
01039 j++;
01040 }
01041 }
01042
01043 if( adcAv <100 || adcAv> 25000) {
01044 mNAnodes--;
01045 for(j=0; j<128; j++) adcCommon[j]=0;
01046 }
01047 }
01048
01049
01050
01051 status= mHybridRawData->getSequences(2,nSequence,Seq);
01052 length = 0;
01053
01054 for( i=0; i<nSequence; i++) length += Seq[i].length;
01055 if( length < 126){
01056 status= mHybridRawData->getSequences(1,nSequence,Seq);
01057 length = 0;
01058
01059 for( i=0; i<nSequence; i++) length += Seq[i].length;
01060 if( length < 126){
01061 doCommon=1;
01062 }
01063
01064 }
01065 if( !doCommon){
01066
01067 adcAv=0;
01068 for( int nSeq=0; nSeq< nSequence ; nSeq++){
01069
01070 adc=Seq[nSeq].firstAdc;
01071 length = Seq[nSeq].length;
01072 startTimeBin=Seq[nSeq].startTimeBin;
01073 j=0;
01074 while( j<length){
01075 adcCommon[startTimeBin+j] += adc[j]-mPedOffSet;
01076 adcAv += (int) adc[j];
01077 j++;
01078 }
01079 }
01080
01081 if( adcAv <100 || adcAv> 25000) {
01082 mNAnodes--;
01083
01084
01085 if( mNAnodes){
01086 for( int nSeq=0; nSeq< nSequence ; nSeq++){
01087
01088 adc=Seq[nSeq].firstAdc;
01089 length = Seq[nSeq].length;
01090 startTimeBin=Seq[nSeq].startTimeBin;
01091 j=0;
01092 while( j<length){
01093 adcCommon[startTimeBin+j] -= adc[j]-mPedOffSet;
01094 adcAv += (int) adc[j];
01095 j++;
01096 }
01097 }
01098 }
01099 }
01100 }
01101 return mNAnodes;
01102 }
01103
01104
01105 void StSvtSeqAdjMaker::MakeHistogramsAdc(StSvtHybridData* hybridData, int index, int Anode, int Count){
01106
01107
01108 int mSequence;
01109 int len,status;
01110 unsigned char* adc;
01111
01112 StSequence* svtSequence;
01113 mSequence = 0;
01114 svtSequence = NULL;
01115
01116
01117
01118 status = hybridData->getSequences(Anode,mSequence,svtSequence);
01119
01120 int numOfPixels=0;
01121 for(int mSeq = 0; mSeq < mSequence; mSeq++)
01122 {
01123 adc = svtSequence[mSeq].firstAdc;
01124 len = svtSequence[mSeq].length;
01125 if (len>12) continue;
01126 for(int j = 0 ; j < len; j++){
01127 mRawAdc[index]->Fill(Anode,(int)adc[j]);
01128
01129 mAdcAfter[index]->Fill(Anode);
01130
01131 if (adc[j] >0) numOfPixels++;
01132 if (adc[j] >0) Evt_counts++;
01133 }
01134 }
01135 mOcupancyHisto->Fill(numOfPixels);
01136 }
01137
01138
01139 Int_t StSvtSeqAdjMaker::Reset(){
01140
01141
01142
01143
01144 mSvtDataSet = NULL;
01145 mSvtAdjData = NULL;
01146 mSvtRawData = NULL;
01147 mHybridRawData = NULL;
01148 mHybridAdjData = NULL;
01149 mSvtPedSub = NULL;
01150 mSvtPedColl = NULL;
01151 mSvtBadAnodes = NULL;
01152 mInvProd = NULL;
01153 mProbValue = NULL;
01154
01155 m_ConstSet->Delete();
01156
01157 return kStOK;
01158 }
01159
01160 string StSvtSeqAdjMaker::baseName(string s){
01161
01162 string name(s);
01163 size_t pos;
01164 pos = name.find_last_of("/");
01165 if (pos!=string::npos ) name.erase(0, pos );
01166 pos = name.find_first_of(".");
01167 if (pos!=string::npos ) name.erase(pos,name.length()-pos );
01168 return name;
01169 }
01170
01171 string StSvtSeqAdjMaker::buildFileName(string dir, string fileName, string extention){
01172
01173 fileName = dir + fileName + extention;
01174 while (fileName.find("//")!=string::npos) {
01175 int pos = fileName.find("//");
01176 fileName.erase(pos,1);
01177 }
01178 return fileName;
01179 }
01180
01181 Int_t StSvtSeqAdjMaker::Finish(){
01182
01183
01184 if (Debug()) gMessMgr->Debug() << "In StSvtSeqAdjMaker::Finish() "
01185 << GetName() << endm;
01186
01187 if ( hfile ){
01188 hfile->Write();
01189 hfile->Close();
01190 }
01191
01192 return kStOK;
01193 }
01194
01195
01196 ClassImp(StSvtSeqAdjMaker)