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 #include "StBFChain.h"
00172 #include "St_DataSetIter.h"
00173 #include "St_DataSet.h"
00174 #include "StDAQMaker/StDAQReader.h"
00175 #include "tables/St_raw_sec_m_Table.h"
00176 #include "tables/St_raw_pad_Table.h"
00177 #include "tables/St_raw_row_Table.h"
00178 #include "tables/St_raw_seq_Table.h"
00179 #include "tables/St_tcl_tphit_Table.h"
00180 #include "tables/St_type_shortdata_Table.h"
00181 #include "tables/St_tpcGain_Table.h"
00182 #include "tables/St_tss_tsspar_Table.h"
00183 #include "StDaqLib/TPC/trans_table.hh"
00184 #include "TH1.h"
00185 #include "TH2.h"
00186 #include "TFile.h"
00187 #include <TError.h>
00188 #include <string.h>
00189 #include <sys/types.h>
00190 #include <sys/stat.h>
00191 #include <fcntl.h>
00192 #include <unistd.h>
00193 #include <StMessMgr.h>
00194 #include <StEvent.h>
00195 #include <StEvent/StTpcHitCollection.h>
00196 #include <StEvent/StTpcHit.h>
00197 #include <StThreeVectorF.hh>
00198
00199
00200
00201 #include <rtsSystems.h>
00202 #include <fcfClass.hh>
00203 #include <TPC/padfinder.h>
00204 #include <TPC/rowlen.h>
00205
00206 #include "FCFMaker.h"
00207
00208 #include "StDbUtilities/StCoordinates.hh"
00209 #include "StDetectorDbMaker/StDetectorDbTpcRDOMasks.h"
00210 #include "StDaqLib/TPC/fee_pin.h"
00211 #include "StDAQMaker/StDAQReader.h"
00212
00213 ClassImp(StRTSClientFCFMaker);
00214
00215
00216 #ifdef FCF_DEBUG_OUTPUT
00217 static FILE *ff ;
00218 #endif
00219
00220
00221 #if !defined(__CINT__) || defined(__MAKECINT__)
00222 #include "Riostream.h"
00223 #include "StMaker.h"
00224 #include "tables/St_g2t_tpc_hit_Table.h"
00225 #else
00226 class StMaker;
00227 class St_g2t_tpc_hit;
00228 class g2t_tpc_hit_st;
00229 #endif
00230 #ifdef FCF_ANNOTATE_CLUSTERS
00231 #include "tables/St_fcfPixel_Table.h"
00232 static TDataSet *fcfPixATop = 0;
00233 extern struct fcfPixAnnotate pixStruct[183][512] ;
00234 #endif
00235 #ifdef FCF_DEBUG_OUTPUT
00236
00237 double x, y, z, charge ;
00238 };
00239 static Hit_t Hit;
00240
00241 static Hit_t *getHitInfo(int sector=1, int row=1, int track_id=1) {
00242 StMaker *mk = StMaker::GetChain();
00243 if (mk) {
00244 StMaker *geant = mk->Maker("geant");
00245 if (geant) {
00246 St_g2t_tpc_hit *hit = (St_g2t_tpc_hit *) geant->DataSet("g2t_tpc_hit");
00247 if (hit) {
00248 Int_t N = hit->GetNRows();
00249 g2t_tpc_hit_st *tpc_hit = hit->GetTable();
00250 for (int i = 0; i < N; i++, tpc_hit++) {
00251 Int_t volId = tpc_hit->volume_id;
00252 Int_t isDet = (volId/100000);
00253 if (isDet) continue;
00254 volId -= (isDet)*100000;
00255 Int_t iSector = volId/100;
00256 if (iSector != sector) continue;
00257 volId -= (iSector)*100;
00258 Int_t iPadrow = volId;
00259 if (iPadrow != row) continue;
00260 if (tpc_hit->track_p != track_id) continue;
00261 Hit.x = tpc_hit->x[0];
00262 Hit.y = tpc_hit->x[1];
00263 Hit.z = tpc_hit->x[2];
00264 Hit.charge = tpc_hit->de;
00265
00266
00267
00268 return &Hit;
00269 }
00270 }
00271 }
00272 }
00273 return 0;
00274 }
00275 #endif
00276
00277
00278 static int Event_counter ;
00279
00280 static class fcfAfterburner fcf_after;
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 StRTSClientFCFMaker::StRTSClientFCFMaker(const char *name):StMaker(name)
00298 {
00299 LOG_DEBUG << "Constructor for StRTSClientFCFMaker()" << endm;
00300 fcf = NULL;
00301 mCTransform = NULL;
00302
00303 gainCorr = NULL;
00304 t0Corr = NULL;
00305
00306 ignoreFileClusters = false;
00307 ignoreRawData = false;
00308 hasSim = 0;
00309 mDp = .1;
00310 mDt = .2;
00311 mDperp = .1;
00312 #ifndef FCF_ANNOTATE_CLUSTERS
00313 splitRows = 1;
00314 #else
00315 splitRows = 0;
00316 #endif
00317 doT0Corrections = 1;
00318 doGainCorrections = 1;
00319 #if 0
00320 doZeroTruncation = 0;
00321 #else
00322 doZeroTruncation = 1;
00323 #endif
00324 fillDeconFlag = 1;
00325
00326 mStEvent = NULL;
00327 mT_tphit = NULL;
00328
00329 m_WestOff = false;
00330 m_EastOff = false;
00331
00332
00333
00334
00335
00336 }
00337
00338
00339 StRTSClientFCFMaker::~StRTSClientFCFMaker()
00340 {
00341
00342 if(gainCorr) free(gainCorr);
00343 if(t0Corr) free(t0Corr);
00344
00345 LOG_DEBUG << "Destructor for StRTSClientFCFMaker()" << endm;
00346
00347 if(fcf != NULL)
00348 {
00349 delete fcf;
00350 fcf = NULL;
00351 }
00352
00353 if(mCTransform != NULL)
00354 {
00355 delete mCTransform;
00356 mCTransform = NULL;
00357 }
00358 }
00359
00360 StDAQReader *daqReader;
00361 StTPCReader *tpcReader;
00362
00363
00364 void StRTSClientFCFMaker::SetMode(Int_t mode)
00365 {
00366 m_Mode = mode;
00367 if (m_Mode & 0x1) ignoreFileClusters = true;
00368 if (m_Mode & 0x2) ignoreRawData = true;
00369 hasSim = m_Mode & 0x4;
00370 if(ignoreRawData)
00371 printf("FCFMaker::SetMode Not calculating clusters from raw data\n");
00372 else
00373 printf("FCFMaker::SetMode Will calculate clusters from raw data if present\n");
00374
00375 if(ignoreFileClusters)
00376 printf("FCFMaker::SetMode Not reading clusters from data file\n");
00377 else
00378 printf("FCFMaker::SetMode Will read clusters from data file if present\n");
00379 if(hasSim)
00380 printf("<FCFMaker:SetMode> event has simulation information\n");
00381 else
00382 printf("<FCFMaker:SetMode> no simulation information\n");
00383 }
00384
00385
00386 Int_t StRTSClientFCFMaker::Init()
00387 {
00388 PrintInfo();
00389
00390 daqReader = NULL;
00391 tpcReader = NULL;
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 fcf = new fcfClass(TPC_ID,NULL);
00412
00413 for(int i=0;i<FCF_MAX_PADS_EVER+1;i++)
00414 {
00415 croat_adcOff[i] = (char*)(&croat_adc[i][0]) - (char*)(&croat_adc[0][0]);
00416 croat_cppOff[i] = (char*)(&croat_cpp[i][0]) - (char*)(&croat_cpp[0][0]);
00417 }
00418 fcf->adcOff = croat_adcOff;
00419 fcf->cppOff = (short unsigned int *)croat_cppOff;
00420 fcf->maxClusters = FCF_MAX_CLUSTERS;
00421
00422 #ifdef FCF_DEBUG_OUTPUT
00423 ff = fopen("fcf.dta","w") ;
00424 #endif
00425
00426
00427 memset(startFlags,0,sizeof(startFlags)) ;
00428 fcf->startFlags = startFlags ;
00429 fcf_after.setVerbose(false);
00430 return StMaker::Init();
00431 }
00432
00433
00434
00435
00436
00437 Int_t StRTSClientFCFMaker::InitRun(int run)
00438 {
00439
00440
00441 m_tsspar = (St_tss_tsspar *) GetDataBase("tpc/tsspars/tsspar");
00442 assert(m_tsspar);
00443
00444 tss_tsspar_st *tsspar = m_tsspar->GetTable();
00445 tsspar->threshold = 1;
00446
00447 int t1,t2;
00448 t1 = time(NULL);
00449
00450 fprintf(stderr,"StRTSClientFCFMaker::InitRun called with run %u...\n",run) ;
00451
00452 Event_counter = 0 ;
00453
00454 St_DataSet *dr = GetDataSet("StDAQReader");
00455 if(dr)
00456 daqReader = (StDAQReader *)(dr->GetObject());
00457
00458 if(daqReader == NULL) {
00459 LOG_INFO << "FCFMaker::InitRun No daqReader available..." << endm;
00460 }
00461
00462 t2 = time(NULL);
00463 LOG_INFO << Form("<FCFMaker>: Done with InitRun: %d secs",t2-t1) << endm;
00464 return kStOK ;
00465 }
00466
00467
00468 Int_t StRTSClientFCFMaker::Make()
00469 {
00470 int t1,t2;
00471 t1 = time(NULL);
00472
00473 t2 = time(NULL);
00474
00475
00476 int anyRawData = anyRawDataInFile();
00477 t2 = time(NULL);
00478
00479
00480 if(anyRawData && !ignoreRawData) {
00481
00482
00483 if(!t0Corr || !gainCorr) {
00484 if(t0Corr || gainCorr) {
00485 printf("<FCFMaker:Make>: Thats funny: we have one set of corrections but not the other? t0=0x%p, gain=0x%p\n",(char*)t0Corr, (char*)gainCorr);
00486 }
00487
00488 t0Corr = (t0_corr_t *)malloc(sizeof(t0_corr_t));
00489 if(!t0Corr) {
00490 LOG_FATAL << "<FCFMaker:Make>: Not enough memory for t0 corrections!" << endm;
00491 assert(false);
00492 }
00493
00494 gainCorr = (gain_corr_t *)malloc(sizeof(gain_corr_t));
00495 if(!gainCorr) {
00496 LOG_FATAL << "<FCFMaker:Make>: Not enough memory for gain corrections!" << endm;
00497 assert(false);
00498 }
00499
00500
00501
00502 for(int i=0;i<24;i++) {
00503 for(int j=0;j<45;j++) {
00504 getCorrections(i+1, j);
00505 }
00506 }
00507
00508 t2 = time(NULL);
00509 LOG_INFO << Form("<FCFMaker>: Got T0/gain corrections: %d secs",t2-t1) << endm;
00510 }
00511 }
00512
00513 int anyClusters = anyClustersInFile();
00514 t2 = time(NULL);
00515
00516
00517
00518 int doFile = anyClusters && !ignoreFileClusters;
00519 int doCroat = anyRawData && !ignoreRawData;
00520
00521
00522
00523
00524 croat_out_t *croat_out = NULL;
00525 resptr_t *croat_resptr = NULL;
00526 daq_out_t *daq_file_out = NULL;
00527 resptr_t *daq_file_resptr = NULL;
00528 croat_out_t *simu_out = NULL;
00529 resptr_t *simu_resptr = NULL;
00530
00531 if(doCroat) {
00532 croat_out = (croat_out_t *)malloc(sizeof(croat_out_t));
00533 if(!croat_out) {
00534 LOG_FATAL << Form("Not enough memory for croat_out (%d bytes)",sizeof(croat_out_t)) << endm;
00535 assert(false);
00536 }
00537 croat_resptr = (resptr_t *)malloc(sizeof(resptr_t));
00538 if(!croat_resptr) {
00539 LOG_FATAL << Form("Not enough memory for croat_resptr (%d bytes)",sizeof(resptr_t)) << endm;
00540 assert(false);
00541 }
00542 }
00543
00544 if(doFile) {
00545 daq_file_out = (daq_out_t *)malloc(sizeof(daq_out_t));
00546 if(!daq_file_out) {
00547 LOG_FATAL << Form("Not enough memory for daq_file_out (%d bytes)",sizeof(daq_out_t)) << endm;
00548 assert(false);
00549 }
00550 daq_file_resptr = (resptr_t *)malloc(sizeof(resptr_t));
00551 if(!daq_file_resptr) {
00552 LOG_FATAL << Form("Not enough memory for daq_file_resptr (%d bytes)",sizeof(resptr_t)) << endm;
00553 assert(false);
00554 }
00555 }
00556
00557 if(hasSim) {
00558 simu_out = (croat_out_t *)malloc(sizeof(croat_out_t));
00559 if(!simu_out) {
00560 LOG_FATAL << Form("Not enough memory for croat_resptr (%d bytes)",sizeof(croat_out_t)) << endm;
00561 assert(false);
00562 }
00563 simu_resptr = (resptr_t *)malloc(sizeof(resptr_t));
00564 if(!simu_resptr) {
00565 LOG_FATAL << Form("Not enough memory for simu_resptr (%d bytes)",sizeof(resptr_t)) << endm;
00566 assert(false);
00567 }
00568 }
00569
00570 Event_counter++ ;
00571 clustercount = 0 ;
00572
00573 PrintInfo();
00574
00575 int do_annot = 0 ;
00576 #ifdef FCF_ANNOTATE_CLUSTERS
00577 fcfPixATop = new TDataSet("fcfPixATop");
00578 AddData(fcfPixATop);
00579 do_annot = 1 ;
00580 #endif
00581
00582 LOG_INFO << Form("<FCFMaker::Make> Making event %d, annotation %d...",Event_counter,do_annot)
00583 << endm;
00584
00585
00586 if(!gStTpcDb)
00587 {
00588 LOG_FATAL << "There is no gStTpcDb pointer" << endm;
00589 exit(0);
00590 }
00591
00592
00593 if(!mCTransform)
00594 {
00595 mCTransform = new StTpcCoordinateTransform(gStTpcDb);
00596 }
00597
00598
00599
00600 mStEvent = NULL;
00601 mT_tphit = NULL;
00602
00603 mStEvent = dynamic_cast<StEvent *> (GetInputDS("StEvent"));
00604 if(mStEvent) {
00605 LOG_INFO << "<FCFMaker::Make> StEvent exists. Not filling tphit table" << endm;
00606 }
00607 else {
00608 LOG_INFO << "<FCFMaker::Make> No StEvent yet. Use tphit table" << endm;
00609
00610 St_DataSetIter outputDataSet(m_DataSet);
00611 mT_tphit = (St_tcl_tphit *)outputDataSet("tphit");
00612 if(mT_tphit == NULL) {
00613 mT_tphit = new St_tcl_tphit("tphit",10);
00614 outputDataSet.Add(mT_tphit);
00615 }
00616 }
00617
00618 if(mStEvent)
00619 {
00620
00621 mTpcHitColl = new StTpcHitCollection();
00622 assert(mTpcHitColl);
00623 }
00624
00625
00626
00627 int n_daq_file_cl=0;
00628 int n_croat_cl=0;
00629 int n_daq_file_cl_sector=0;
00630 int n_croat_cl_sector=0;
00631
00632 int n_burned_daq_file_cl=0;
00633 int n_burned_croat_cl=0;
00634 int n_burned_daq_file_cl_sector=0;
00635 int n_burned_croat_cl_sector=0;
00636
00637 int mismatch_tot=0;
00638 int mismatch_sector=0;
00639
00640
00641 for(int sector = 0;sector < 24; sector++) {
00642
00643 if(m_EastOff && sector >= 12) continue;
00644 if(m_WestOff && sector < 12) continue;
00645
00646 n_daq_file_cl_sector = 0;
00647 n_croat_cl_sector = 0;
00648 n_burned_daq_file_cl_sector = 0;
00649 n_burned_croat_cl_sector = 0;
00650
00651 if(doFile) {
00652 t2 = time(NULL);
00653
00654
00655 n_daq_file_cl_sector = build_daq_file_clusters(sector, daq_file_out, daq_file_resptr);
00656 n_daq_file_cl += n_daq_file_cl_sector;
00657
00658 t2 = time(NULL);
00659
00660 }
00661
00662 if(doCroat) {
00663 t2 = time(NULL);
00664
00665
00666 n_croat_cl_sector = build_croat_clusters(sector, croat_out, croat_resptr, simu_out, simu_resptr);
00667 n_croat_cl += n_croat_cl_sector;
00668
00669 t2 = time(NULL);
00670
00671 }
00672
00673
00674 for(int pr=0;pr<45;pr++)
00675 {
00676 fcfHit h;
00677
00678
00679 if((n_croat_cl_sector > 0) &&
00680 (n_daq_file_cl_sector > 0)) {
00681
00682 if(hasSim) {
00683 LOG_INFO << "FCFMaker: have simulated data as well as daq file clusters. disabling comparison between calculated and file clusters"
00684 << endm;
00685 } else {
00686 int e = fcf_after.compare(daq_file_resptr->v[pr],
00687 croat_resptr->v[pr]);
00688
00689 mismatch_sector += e;
00690 mismatch_tot += e;
00691 }
00692 }
00693
00694
00695 if(n_daq_file_cl_sector > 0) {
00696
00697 fcf_after.burn(daq_file_resptr->v[pr], NULL);
00698
00699 while(fcf_after.next(&h)) {
00700 n_burned_daq_file_cl++;
00701 n_burned_daq_file_cl_sector++;
00702
00703 if(doFile) {
00704 saveCluster(h.pad,h.tm,h.f,h.c,h.p1,h.p2,h.t1,h.t2,pr,sector+1,-1,0,0);
00705 }
00706 }
00707 }
00708
00709
00710 if(n_croat_cl_sector > 0) {
00711
00712 fcf_after.burn(croat_resptr->v[pr], (simu_resptr) ? simu_resptr->v[pr]: NULL);
00713
00714 while(fcf_after.next(&h)) {
00715 n_burned_croat_cl++;
00716 n_burned_croat_cl_sector++;
00717
00718 if(!doFile) {
00719 saveCluster(h.pad,h.tm,h.f,h.c,h.p1,h.p2,h.t1,h.t2,pr,sector+1,h.cl_id,h.id_simtrk, h.id_quality);
00720 }
00721 }
00722 }
00723 }
00724
00725 t2 = time(NULL);
00726
00727
00728
00729 if(mismatch_sector != 0) {
00730 LOG_INFO << Form("<FCFMaker::Make> There were mismatches between file & calculated clusters (sector=%02d mismatches=%6d nfile=%6d nraw=%6d)",
00731 sector+1,mismatch_sector,n_burned_daq_file_cl_sector,n_burned_croat_cl_sector)
00732 << endm;
00733 }
00734 }
00735
00736 if(doFile) {
00737 LOG_INFO << Form("<FCFMaker::Make> Merged %d of %d file clusters",
00738 n_daq_file_cl-n_burned_daq_file_cl,n_daq_file_cl)
00739 << endm;
00740 }
00741
00742 if(doCroat) {
00743 LOG_INFO << Form("<FCFMaker::Make> Merged %d of %d calculated clusters",
00744 n_croat_cl-n_burned_croat_cl,n_croat_cl)
00745 << endm;
00746 }
00747
00748
00749 if(!doFile && !doCroat)
00750 {
00751 LOG_INFO << "<FCFMaker::Make> No clusters available" << endm;
00752 }
00753 else if(doCroat && !doFile)
00754 {
00755 LOG_INFO << "<FCFMaker::Make> Only raw data available. No daq file clusters" << endm;
00756 }
00757 else if(doFile && !doCroat)
00758 {
00759 LOG_INFO << "<FCFMaker::Make> Only daq file clusters available. No raw data" << endm;
00760 }
00761 else
00762 {
00763 if(n_burned_daq_file_cl != n_burned_croat_cl)
00764 {
00765 printf("*-------------------------------------------------------*\n");
00766 printf("* FCFMaker: both raw data and clusters exist, but the *\n");
00767 printf("* FCFMaker: number of clusters is different *\n");
00768 printf("* FCFMaker: file-> %6d, computed-> %6d *\n",
00769 n_burned_daq_file_cl,
00770 n_burned_croat_cl);
00771 printf("* FCFMaker: Check calibrations etc.... *\n");
00772 printf("* FCFMaker: Using clusters from datafile *\n");
00773 printf("*-------------------------------------------------------*\n");
00774 }
00775 else {
00776 printf("*-------------------------------------------------------*\n");
00777 printf("* FCFMaker: both raw data and clusters exist *\n");
00778 printf("* FCFMaker: they agree on %6d clusters *\n",n_burned_croat_cl);
00779 if(mismatch_tot == 0) {
00780 printf("* FCFMaker: and the contents are equal!!! \n");
00781 }
00782 else {
00783 printf("* FCFMaker: but the contents are not equal!!! \n");
00784 }
00785 printf("*-------------------------------------------------------*\n");
00786 }
00787 }
00788
00789
00790 if(mStEvent)
00791 {
00792 mStEvent->setTpcHitCollection(mTpcHitColl);
00793 mTpcHitColl = NULL;
00794 }
00795
00796 if(croat_out) free(croat_out);
00797 if(daq_file_out) free(daq_file_out);
00798 if(croat_resptr) free(croat_resptr);
00799 if(daq_file_resptr) free(daq_file_resptr);
00800
00801 if(simu_out) free(simu_out);
00802 if(simu_resptr) free(simu_resptr);
00803
00804 t2 = time(NULL);
00805 if (Debug()){
00806 LOG_DEBUG << Form("<FCFMaker::Make> Done with make (%d secs)",t2-t1) << endm;
00807 }
00808
00809 return kStOK;
00810 }
00811
00812
00813
00814
00815
00816
00817 Int_t StRTSClientFCFMaker::BuildCPP(int nrows, raw_row_st *row, raw_pad_st *pad, raw_seq_st *seq, int sector)
00818 {
00819 int i,j,k;
00820 int r,p;
00821 int offset;
00822
00823 offset = -1 ;
00824 for(i=0;i<nrows;i++) {
00825 int pad_off = row[i].ipad;
00826 r = row[i].RowId;
00827
00828 for(j=0;j<row[i].npad;j++) {
00829 int seq_off = (row[i].iseq + pad[pad_off + j].SeqOffset);
00830 p = pad[pad_off + j].PadId;
00831
00832
00833 offset = (row[i].ipixel +
00834 pad[pad_off + j].PadOffset);
00835
00836
00837
00838
00839
00840
00841
00842 int raw_s=0;
00843 int merged_s=0;
00844
00845 for(k=0;k<pad[pad_off + j].nseq;k++) {
00846 int tb = seq[seq_off+k].m + ((k>=pad[pad_off + j].SeqModBreak) ? 256 : 0);
00847 int n = seq[seq_off+k].i;
00848
00849
00850
00851
00852
00853
00854
00855 raw_s = k;
00856
00857 if( (r>45) || (p>184) ||
00858 (r<1) || (p<1) || (raw_s<0)) {
00859 LOG_ERROR << "got an illegal sequence row=" << r
00860 << ", pad=" << p
00861 << ", seq=" << raw_s
00862 << endm;
00863 }
00864
00865
00866
00867
00868
00869
00870 int domerge=0;
00871 if(merged_s > 0) {
00872 if(tb == (cpp[r-1].r[p-1][merged_s-1].start_bin +
00873 cpp[r-1].r[p-1][merged_s-1].length)) {
00874
00875
00876 domerge = 1;
00877 }
00878 }
00879
00880 if(!domerge) {
00881 cpp[r-1].r[p-1][merged_s].start_bin = tb;
00882 cpp[r-1].r[p-1][merged_s].offset = offset;
00883 cpp[r-1].r[p-1][merged_s].length = n+1;
00884
00885 merged_s++;
00886 }
00887 else {
00888 if(cpp[r-1].r[p-1][merged_s-1].length % 31 != 0) {
00889 LOG_INFO << Form("FCFMaker: What is going on? merging short sequence len=%d",
00890 cpp[r-1].r[p-1][merged_s-1].length)
00891 << endm;
00892 }
00893
00894 cpp[r-1].r[p-1][merged_s-1].length += n+1;
00895 }
00896 offset += n+1;
00897 }
00898 }
00899 }
00900
00901 return offset;
00902 }
00903
00904
00905 StDaqClfCppRow *StRTSClientFCFMaker::GetCPPRow(int r, int i, StDaqClfCppRow *storage)
00906 {
00907 if(splitRows) {
00908 int found = 0;
00909
00910 memset(storage, 0xff, sizeof(StDaqClfCppRow));
00911
00912 if(padfinder[r][i].mezz == 0) return NULL;
00913
00914 for(int p=padfinder[r][i].minpad;
00915 p<=padfinder[r][i].maxpad;
00916 p++)
00917 {
00918 for(int s=0;s<32;s++)
00919 {
00920 if(cpp[r].r[p-1][s].start_bin == 0xffff) continue;
00921 storage->r[p-1][s] = cpp[r].r[p-1][s];
00922 found = 1;
00923 }
00924 }
00925 if(found)
00926 return storage;
00927 else
00928 {
00929 return NULL;
00930 }
00931 }
00932 else {
00933 if(i==0) {
00934 memcpy(storage, &cpp[r], sizeof(StDaqClfCppRow));
00935 return storage;
00936 }
00937 }
00938 return 0;
00939 }
00940
00941
00942
00943
00944 double StRTSClientFCFMaker::lxFromPad(int row, double pad)
00945 {
00946 double pitch = (row<14) ?
00947 gStTpcDb->PadPlaneGeometry()->innerSectorPadPitch() :
00948 gStTpcDb->PadPlaneGeometry()->outerSectorPadPitch();
00949
00950 double pads2move = pad - (gStTpcDb->PadPlaneGeometry()->numberOfPadsAtRow(row))/2.;
00951 double dist2move = -pitch*(pads2move-.5);
00952
00953
00954 return(dist2move);
00955 }
00956
00957
00958 double StRTSClientFCFMaker::lyFromRow(int row)
00959 {
00960 return (gStTpcDb->PadPlaneGeometry()->radialDistanceAtRow(row));
00961 }
00962
00963
00964
00965 double StRTSClientFCFMaker::lzFromTB(double timeBin, int sector, int row, int pad)
00966 {
00967 double tbWidth = (1./gStTpcDb->Electronics()->samplingFrequency());
00968
00969 double zoffset ((row > 13) ?
00970 gStTpcDb->Dimensions()->zOuterOffset() :
00971 gStTpcDb->Dimensions()->zInnerOffset());
00972
00973 double t0zoffset=0.0;
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985 double z =
00986 gStTpcDb->DriftVelocity(sector)*1e-6*
00987 (gStTpcDb->triggerTimeOffset()*1e6
00988 + gStTpcDb->Electronics()->tZero()
00989 + (timeBin)*tbWidth );
00990
00991 return(z - zoffset + t0zoffset);
00992 }
00993
00994
00995 void StRTSClientFCFMaker::getCorrections(int sector, int row)
00996 {
00997 int pad;
00998
00999
01000 TDataSet *tpc_calib = GetDataBase("Calibrations/tpc"); assert(tpc_calib);
01001 St_tpcGain *gainObj = (St_tpcGain*) tpc_calib->Find("tpcGain"); assert(gainObj);
01002
01003 assert(gainObj->GetNRows()==24);
01004 tpcGain_st *gains = gainObj->GetTable(); assert(gains);
01005 assert(sector>=1&§or<=24);
01006
01007 static StDetectorDbTpcRDOMasks* mask=0;
01008 static int tRDOFromRowAndPad[45][182];
01009 if(!mask) {
01010 mask = StDetectorDbTpcRDOMasks::instance();
01011 assert(mask);
01012 for(int tiFee=0;tiFee<182;tiFee++) {
01013 for(int tiPin=0;tiPin<32;tiPin++) {
01014 if(row_vs_fee[tiFee][tiPin]!=0 && pad_vs_fee[tiFee][tiPin]!=0) {
01015 tRDOFromRowAndPad[(row_vs_fee[tiFee][tiPin]-1)]
01016 [(pad_vs_fee[tiFee][tiPin]-1)]=
01017 rdo_vs_fee[tiFee][tiPin];
01018 }
01019 }
01020 }
01021 }
01022
01023
01024 for(pad=0;pad<tpc_rowlen[row+1];pad++) {
01025 double gain, t0;
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039 if(mask->isOn(sector,tRDOFromRowAndPad[row][pad])) {
01040 if(doGainCorrections) {
01041 gain = gains[sector-1].Gain[row][pad] ;
01042 }
01043 else {
01044 gain = 1.0 ;
01045
01046
01047
01048 }
01049
01050 }
01051 else {
01052 gain = 0.0 ;
01053 }
01054
01055
01056
01057 gainCorr->v[sector-1][row][pad+1] = (int)(gain*64.0 + 0.5);
01058
01059
01060
01061
01062 if(doT0Corrections) {
01063 t0 = gStTpcDb->tpcT0()->T0(sector,row+1,pad+1);
01064 }
01065 else t0 = 0.0 ;
01066
01067
01068 t0Corr->v[sector-1][row][pad+1] = (short)(gain*fabs(t0)*64.0 + 0.5) ;
01069 if(t0 < 0.0) t0Corr->v[sector-1][row][pad+1] *= -1 ;
01070
01071 #ifdef FCF_DEBUG_OUTPUT
01072
01073
01074 #endif
01075
01076 }
01077 }
01078
01079
01080
01081
01082
01083
01084
01085
01086 void StRTSClientFCFMaker::saveCluster(int cl_x, int cl_t, int cl_f, int cl_c, int p1, int p2, int t1, int t2, int r, int sector, int cl_id, int id_simtrk, int id_quality)
01087 {
01088 tss_tsspar_st *tsspar = m_tsspar->GetTable();
01089 StTpcPadCoordinate Pad(sector,r+1,((Float_t) cl_x)/64.0, ((Float_t) cl_t)/64.0);
01090 static StTpcLocalCoordinate global;
01091 (*mCTransform)(Pad,global,kFALSE);
01092
01093
01094 tcl_tphit_st hit;
01095 memset(&hit,0,sizeof(hit));
01096
01097
01098 if(cl_id != -1) {
01099 hit.cluster = cl_id ;
01100 hit.id = cl_id;
01101 }
01102 else {
01103 hit.cluster = clustercount ;
01104 hit.id = clustercount;
01105 }
01106 clustercount++ ;
01107
01108
01109
01110 if(fillDeconFlag == 0)
01111 hit.flag = 0;
01112 else
01113 {
01114 if( (cl_f & FCF_DOUBLE_PAD) ||
01115 (cl_f & FCF_DOUBLE_T))
01116 {
01117 hit.flag = 1;
01118 }
01119 }
01120
01121
01122
01123 hit.row = (r+1) + sector * 100;
01124
01125
01126
01127 double tmp_q ;
01128
01129 tmp_q = (double)cl_c ;
01130
01131
01132
01133 double gain = (r<13) ? tsspar->gain_in : tsspar->gain_out;
01134 double wire_coupling = (r<13) ? tsspar->wire_coupling_in : tsspar->wire_coupling_out;
01135
01136 tmp_q *= ((double)tsspar->ave_ion_pot * (double)tsspar->scale)/(gain*wire_coupling) ;
01137
01138
01139
01140 hit.q = tmp_q;
01141 hit.x = global.position().x();
01142 hit.dx = mDp;
01143 hit.y = global.position().y();
01144 hit.dy = mDperp;
01145 hit.z = global.position().z();
01146 hit.dz = mDt;
01147
01148
01149
01150 if(doZeroTruncation)
01151 {
01152 if((hit.z < -5.0) && (sector <=12))
01153 return;
01154 if((hit.z > 5.0) && (sector > 12))
01155 return;
01156 }
01157
01158 hit.minpad = p1;
01159 hit.maxpad = p2;
01160
01161 hit.npads = p2 - p1 + 1 ;
01162
01163 hit.mintmbk = t1;
01164 hit.maxtmbk = t2;
01165
01166 hit.ntmbk = hit.maxtmbk - hit.mintmbk + 1;
01167
01168 hit.nseq = hit.npads;
01169
01170
01171 hit.prf = hit.npads * ((r>=13) ? .1316 : .0636);
01172 hit.zrf = hit.ntmbk * .1059;
01173 hit.cl_x = ((double)(cl_x))/64.0;
01174 hit.cl_t = ((double)(cl_t))/64.0;
01175 hit.id_simtrk = id_simtrk;
01176 hit.id_quality = id_quality;
01177
01178
01179 #ifdef FCF_DEBUG_OUTPUT
01180 struct Hit_t *ht = getHitInfo(hit.row/100,hit.row%100,hit.id_simtrk) ;
01181
01182 fprintf(ff,"%d %d %d %d %d %d %f %f %f %f %d %d %d %d %d %d ",
01183 Event_counter, hit.row/100, hit.row%100, hit.id, hit.id_simtrk,hit.id_quality,
01184 hit.x,hit.y,hit.z,hit.q*1000000.0,cl_x,cl_t,cl_f,cl_c,p2-p1+1,t2-t1+1) ;
01185
01186 if(!ht) {
01187 fprintf(ff,"0.0 0.0 0.0 0.0\n") ;
01188 }
01189 else {
01190 fprintf(ff,"%f %f %f %f\n",ht->x,ht->y,ht->z,ht->charge*1000000.0) ;
01191 }
01192
01193 #endif
01194 #if 0
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247 #endif
01248
01249 if(mT_tphit)
01250 {
01251 filltphit(&hit);
01252 }
01253
01254 if(mStEvent)
01255 {
01256 fillStEvent(&hit);
01257 }
01258 }
01259
01260
01261 void StRTSClientFCFMaker::fillStEvent(tcl_tphit_st *hit)
01262 {
01263 assert(mStEvent);
01264 assert(mTpcHitColl);
01265
01266 StThreeVectorF p(hit->x,hit->y,hit->z);
01267 StThreeVectorF e(hit->dx,hit->dy,hit->dz);
01268
01269 unsigned int hw = 1;
01270 hw += (hit->row/100 << 4);
01271 hw += (hit->row%100 << 9);
01272 hw += (hit->npads << 15);
01273 hw += (hit->ntmbk << 22);
01274
01275 StTpcHit *tpcHit = new StTpcHit(p,e,hw,hit->q, 0,
01276 hit->id_simtrk,hit->id_quality, hit->id,
01277 hit->minpad, hit->maxpad, hit->mintmbk, hit->maxtmbk,hit->cl_x,hit->cl_t);
01278
01279 if(!mTpcHitColl->addHit(tpcHit)) {
01280 assert(false);
01281 }
01282
01283 }
01284
01285
01286 void StRTSClientFCFMaker::filltphit(tcl_tphit_st *hit)
01287 {
01288 assert(mT_tphit);
01289
01290 int nAlloc = mT_tphit->GetTableSize();
01291 int nUsed = mT_tphit->GetNRows();
01292 if(nUsed>nAlloc-10)
01293 {
01294 mT_tphit->ReAllocate(Int_t(nAlloc*1.2+10));
01295 }
01296 mT_tphit->AddAt(hit, nUsed);
01297 }
01298
01299
01300 int StRTSClientFCFMaker::runClusterFinder(j_uintptr *result_mz_ptr,
01301 u_int *result_buff,
01302 int sector,
01303 int row,
01304 StDaqClfCppRow *cppRow,
01305 unsigned short *adc,
01306 unsigned short *trk,
01307 u_int *simu_result_buff,
01308 j_uintptr *simu_mz_ptr)
01309 {
01310 int total_clusters=0;
01311
01312
01313 u_int charge_on_row = 0 ;
01314
01315 for(int i=0;i<3;i++) result_mz_ptr[i] = NULL;
01316
01317 if(hasSim) {
01318 for(int i=0;i<3;i++) simu_mz_ptr[i] = NULL;
01319 }
01320
01321
01322
01323 fcf->t0Corr = t0Corr->v[sector-1][row];
01324 fcf->gainCorr = gainCorr->v[sector-1][row];
01325
01326 fcf->sb = sector ;
01327
01328
01329
01330 u_int *res_ptr = result_buff ;
01331 u_int *simu_res_ptr = simu_result_buff ;
01332 u_int *rows_count = result_buff ;
01333 u_int *croat_outp ;
01334 u_int nclusters ;
01335
01336 *rows_count = 0 ;
01337
01338 res_ptr++ ;
01339 if(hasSim) simu_res_ptr++;
01340
01341 int i ;
01342 for(i=0;i<3;i++) {
01343
01344
01345
01346
01347
01348
01349
01350
01351 fcf->row = row+1;
01352 fcf->padStart = 1000000;
01353 fcf->padStop = 0;
01354
01355 memset(startFlags,0,sizeof(startFlags)) ;
01356 int start, stop ;
01357
01358
01359
01360
01361 if(!splitRows) {
01362 if(i>=1) break ;
01363
01364 start = fcf->padStart = 1 ;
01365 stop = fcf->padStop = tpc_rowlen[row+1] ;
01366 }
01367 else {
01368 if(padfinder[row][i].rdo == 0) break ;
01369 start = fcf->padStart = padfinder[row][i].minpad ;
01370 stop = fcf->padStop = padfinder[row][i].maxpad ;
01371 }
01372
01373 if(start == 1) fcf->startFlags[start] |= FCF_ROW_EDGE ;
01374 else fcf->startFlags[start] |= FCF_BROKEN_EDGE ;
01375
01376 if(stop == tpc_rowlen[row+1]) fcf->startFlags[stop] |= FCF_ROW_EDGE ;
01377 else fcf->startFlags[stop] |= FCF_BROKEN_EDGE ;
01378
01379 for(int k=start;k<=stop;k++) {
01380 if(fcf->gainCorr[k] == 0) {
01381 fcf->startFlags[k] |= FCF_DEAD_EDGE ;
01382 if((k-1)>=start) fcf->startFlags[k-1] |= FCF_DEAD_EDGE ;
01383 if((k+1)<=stop) fcf->startFlags[k+1] |= FCF_DEAD_EDGE ;
01384 }
01385 }
01386
01387 if(hasSim) memset(&croat_trk[0][0], 0, sizeof(croat_trk));
01388 memset(&croat_adc[0][0], 0, sizeof(croat_adc));
01389 memset(&croat_cpp[0][0], 0xff, sizeof(croat_cpp));
01390
01391
01392 for(int pp=fcf->padStart;pp<=fcf->padStop;pp++)
01393 {
01394 for(int ss=0;ss<FCF_MAX_SEQ;ss++)
01395 {
01396
01397
01398
01399 if(cppRow->r[pp-1][ss].offset == 0xffffffff) break;
01400
01401 for(int ii=0;ii<cppRow->r[pp-1][ss].length;ii++)
01402 {
01403 int time = ii + cppRow->r[pp-1][ss].start_bin;
01404 int pnt = ii + cppRow->r[pp-1][ss].offset;
01405
01406
01407
01408
01409
01410
01411 croat_adc[pp][time] = log10to8_table[adc[pnt]];
01412
01413 charge_on_row += adc[pnt] ;
01414
01415
01416
01417 if(hasSim) {
01418 croat_trk[pp][time] = trk[pnt];
01419
01420
01421 }
01422
01423 #ifdef FCF_DEBUG_OUTPUT
01424
01425
01426 #endif
01427 }
01428 }
01429 }
01430
01431
01432 for(int pp=fcf->padStart;pp<=fcf->padStop;pp++)
01433 {
01434 for(int ss=0;ss<FCF_MAX_SEQ;ss++)
01435 {
01436 if(cppRow->r[pp-1][ss].start_bin == 0xffff) break;
01437
01438 croat_cpp[pp][2*ss] = cppRow->r[pp-1][ss].start_bin;
01439 croat_cpp[pp][2*ss+1] = (cppRow->r[pp-1][ss].start_bin +
01440 cppRow->r[pp-1][ss].length -1);
01441 }
01442 }
01443
01444 if(hasSim) {
01445 fcf->simIn = (short *)croat_trk;
01446 fcf->simOut = simu_res_ptr;
01447 } else {
01448 fcf->simIn = 0;
01449 fcf->simOut = 0;
01450 }
01451
01452 u_int words = fcf->finder((u_char *)croat_adc,
01453 (u_short *)croat_cpp,
01454 (u_int *)res_ptr);
01455
01456
01457
01458
01459 croat_outp = res_ptr;
01460 u_int wrow = *croat_outp++;
01461 nclusters = *croat_outp++;
01462
01463 if(words == 1)
01464 {
01465 wrow = row+1;
01466 nclusters = 0;
01467 }
01468
01469 total_clusters += nclusters;
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481 if((int)wrow != row+1)
01482 {
01483 LOG_ERROR << "Fatal error: padrow "<< wrow <<" does not match "<< row+1 << endm;
01484 exit(0);
01485 }
01486
01487 if((nclusters * 2 + 2 != words) &&
01488 (nclusters != 0))
01489 {
01490 LOG_ERROR << "Fatal error: nclusters="<< nclusters <<" words="<< words << endm;
01491 exit(0);
01492 }
01493
01494 if(nclusters) {
01495 result_mz_ptr[i] = res_ptr ;
01496
01497 if(hasSim)
01498 simu_mz_ptr[i] = simu_res_ptr;
01499
01500 (*rows_count)++ ;
01501 res_ptr += 2+2*nclusters ;
01502
01503 if(hasSim)
01504 simu_res_ptr += 2+2*nclusters;
01505 }
01506 }
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516 #ifdef FCF_DEBUG_OUTPUT
01517
01518 #endif
01519
01520 return total_clusters;
01521 }
01522
01523
01524 int StRTSClientFCFMaker::anyClustersInFile()
01525 {
01526 for(u_int hs=0;hs<24;hs += 2) {
01527 for(u_int rb=0;rb<12;rb++) {
01528 for(u_int mz=0;mz<3;mz++) {
01529 u_int len;
01530 if(getMZCLD(hs,rb,mz,&len)) return 1;
01531 }
01532 }
01533 }
01534
01535 return 0;
01536 }
01537
01538
01539 u_int *StRTSClientFCFMaker::getMZCLD(u_int hsector, u_int rb, u_int mz, u_int *len)
01540 {
01541 if(!daqReader) {
01542 LOG_DEBUG << "FCFMaker: No daq reader" << endm;
01543 return NULL;
01544 }
01545
01546 tpcReader = daqReader->getTPCReader();
01547 if(!tpcReader) {
01548 LOG_DEBUG << "FCFMaker: No tpc reader" << endm;
01549 return NULL;
01550 }
01551
01552 u_int *tpcp = (u_int *)tpcReader->ptrTPCP;
01553
01554 if(memcmp("TPCP", (char *)tpcp, 4) != 0) {
01555 LOG_WARN << Form("FCFMaker: Bad tpcp bank (%s)",(char *)tpcp) << endm;
01556 return NULL;
01557 }
01558
01559 int swap_tpcp = checkSwap(tpcp[5]);
01560 int off = swap32(swap_tpcp, tpcp[10+2*hsector]);
01561 *len = swap32(swap_tpcp, tpcp[10+2*hsector+1]);
01562
01563 if(*len == 0) return NULL;
01564
01565 u_int *tpcsecp = tpcp + off;
01566 if(memcmp("TPCSECP", (char *)tpcsecp, 7) != 0) {
01567 LOG_WARN << Form("FCFMaker: Bad tpcsecp bank (%s)",(char *)tpcsecp) << endm;
01568 return NULL;
01569 }
01570
01571 int swap_tpcsecp = checkSwap(tpcsecp[5]);
01572 off = swap32(swap_tpcsecp, tpcsecp[8]);
01573 int format = swap32(swap_tpcsecp, tpcsecp[6]);
01574
01575
01576
01577 if(off==0) return NULL;
01578 if(format < 2) return NULL;
01579
01580 u_int *tpcseclp = tpcsecp + off;
01581 if(memcmp("TPCSECLP", (char *)tpcseclp, 8) != 0) {
01582 LOG_WARN << Form("FCFMaker: Bad tpcseclp bank (%s)",(char *)tpcseclp) << endm;
01583 return NULL;
01584 }
01585 u_int swap_tpcseclp = checkSwap(tpcseclp[5]);
01586 if((hsector+1) != swap32(swap_tpcseclp, tpcseclp[3])) {
01587 LOG_WARN << Form("FCFMaker: Bad tpcseclp sector %d vs %d",
01588 swap32(swap_tpcseclp, tpcseclp[3]),
01589 hsector+1)
01590 << endm;
01591 return NULL;
01592 }
01593
01594 off = swap32(swap_tpcseclp, tpcseclp[10+2*rb]);
01595 *len = swap32(swap_tpcseclp, tpcseclp[10+2*rb+1]);
01596 if(*len == 0) return NULL;
01597
01598 u_int *tpcrbclp = tpcseclp + off;
01599 if(memcmp("TPCRBCLP", tpcrbclp, 8) != 0) {
01600 LOG_WARN << Form("FCFMaker: Bad TPCRBCLP bank (%s)", (char *)tpcrbclp)
01601 << endm;
01602 return NULL;
01603 }
01604 int swap_tpcrbclp = checkSwap(tpcrbclp[5]);
01605
01606 off = swap32(swap_tpcrbclp, tpcrbclp[10+2*mz]);
01607 *len = swap32(swap_tpcrbclp, tpcrbclp[10+2*mz+1]);
01608 if(*len==0) return NULL;
01609
01610 u_int *tpcmzcld = tpcrbclp + off;
01611 if(memcmp("TPCMZCLD", tpcmzcld, 8) != 0) {
01612 LOG_WARN << Form("FCFMaker: Bad TPCMZCLD bank (%s)", (char *)tpcmzcld)
01613 << endm;
01614 return NULL;
01615 }
01616
01617 return tpcmzcld;
01618 }
01619
01620
01621 int StRTSClientFCFMaker::build_daq_file_clusters(u_int sector,daq_out_t *daq_file_out, resptr_t *daq_file_resptr)
01622 {
01623
01624
01625
01626
01627 memset(daq_file_resptr, 0, sizeof(resptr_t));
01628 memset(daq_file_out, 0, sizeof(daq_out_t));
01629
01630 u_int hsector = (sector / 2) * 2;
01631 u_int sadd = sector % 2;
01632 u_int len;
01633
01634 int nClusters=0;
01635
01636 for(u_int rb = sadd*6; rb < sadd*6 + 6; rb++) {
01637 for(u_int mz = 0;mz<3;mz++) {
01638
01639 u_int *tpcmzcld = getMZCLD(hsector, rb, mz, &len);
01640
01641 if(!tpcmzcld) continue;
01642
01643
01644
01645 int swap_tpcmzcld = checkSwap(tpcmzcld[5]);
01646
01647 u_int *p = daq_file_out->v[rb%6][mz];
01648
01649
01650 memcpy(p, &tpcmzcld[10], len*4 - 40);
01651
01652 int n_padrows = swap32(swap_tpcmzcld, p[0]);
01653
01654 u_int *curr = &p[1];
01655 for(int i=0;i<n_padrows;i++) {
01656 u_int r = rb % 6;
01657
01658 u_int pr = swap32(swap_tpcmzcld, *curr);
01659 if(pr > 45) {
01660 LOG_WARN << Form("FCFMaker: Bad padrow %d",pr)
01661 << endm;
01662 }
01663
01664 u_int ncl = swap32(swap_tpcmzcld, *(curr+1));
01665 nClusters += ncl;
01666
01667
01668
01669 if(pr > 45) {
01670 LOG_WARN << Form("FCFMaker: Bad padrow s=%d, rb=%d, mz=%d pr=%d",
01671 sector+1,r,mz,pr)
01672 << endm;
01673 return -1;
01674 }
01675
01676
01677 j_uintptr *resptr = daq_file_resptr->v[pr-1];
01678 int j;
01679 for(j=0;j<3;j++) {
01680 if(resptr[j] == NULL) break;
01681 }
01682 if(j >= 3) {
01683 LOG_WARN << Form("FCFMaker: All three resptr already filled! s=%d, rb=%d mz=%d pr=%d",
01684 sector+1,r,mz,pr)
01685 << endm;
01686 return -1;
01687 }
01688
01689 resptr[j] = curr;
01690
01691 curr += ncl*2+2;
01692 }
01693 }
01694 }
01695
01696
01697
01698
01699
01700 return nClusters;
01701 }
01702
01703
01704 bool StRTSClientFCFMaker::checkSwap(int x)
01705 {
01706 return (x==0x04030201) ? false : true;
01707 }
01708
01709 u_int StRTSClientFCFMaker::swap32(bool test, u_int x)
01710 {
01711 if(!test) return x;
01712 else
01713 {
01714 char *hh,temp[4];
01715 hh=(char*)(&x);
01716 temp[0]=hh[3]; temp[1]=hh[2]; temp[2]=hh[1]; temp[3]=hh[0];
01717 return *((unsigned int*)temp);
01718 }
01719 }
01720
01721
01722 int StRTSClientFCFMaker::anyRawDataInFile()
01723 { St_DataSet *data = (St_DataSet *)GetInputDS("tpc_raw");
01724 if(!data) return 0;
01725
01726 St_DataSetIter rawIter(data);
01727
01728
01729 for(int sectorIdx=1;sectorIdx<=24;sectorIdx++) {
01730 char sectorName[100];
01731 sprintf(sectorName, "Sector_%d", sectorIdx);
01732
01733
01734
01735 rawIter.Reset();
01736 St_DataSet *sector = (St_DataSet *)rawIter.Find(sectorName);
01737 if(!sector) continue;
01738
01739
01740
01741
01742 St_DataSetIter sectorIter(sector);
01743 St_type_shortdata *Tadc_in, *Tadc_ot;
01744 Tadc_in = (St_type_shortdata *)sectorIter.Find("pixel_data_in");
01745 Tadc_ot = (St_type_shortdata *)sectorIter.Find("pixel_data_out");
01746
01747
01748 if(Tadc_ot && Tadc_ot->GetNRows()) return 1;
01749 if(Tadc_in && Tadc_in->GetNRows()) return 1;
01750 }
01751
01752 return 0;
01753 }
01754
01755
01756 int StRTSClientFCFMaker::build_croat_clusters(u_int s,
01757 croat_out_t *croat_out,
01758 resptr_t *croat_resptr,
01759 croat_out_t *simu_out,
01760 resptr_t *simu_resptr)
01761 {
01762 memset(croat_out, 0, sizeof(croat_out_t));
01763 memset(croat_resptr, 0, sizeof(resptr_t));
01764
01765 if(hasSim) {
01766 memset(simu_out, 0, sizeof(croat_out_t));
01767 memset(simu_resptr, 0, sizeof(resptr_t));
01768 }
01769
01770 int nclusters=0;
01771 int haveAnyRaw=0;
01772 int haveRaw=0;
01773
01774 St_DataSet *rawData;
01775 St_DataSet *sector;
01776
01777 int sz;
01778
01779 rawData = (St_DataSet *)GetInputDS("tpc_raw");
01780 if(!rawData) return -1;
01781
01782 St_DataSetIter rawIter(rawData);
01783
01784
01785 int sectorIdx = s+1;
01786 haveRaw = 0;
01787
01788 St_raw_row *Trow_in=0, *Trow_out=0;
01789 St_raw_pad *Tpad_in=0, *Tpad_out=0;
01790 St_raw_seq *Tseq_in=0, *Tseq_out=0;
01791 St_type_shortdata *Tadc_in=0, *Tadc_out=0;
01792 St_type_shortdata *Ttrk_in=0, *Ttrk_out=0;
01793
01794
01795 raw_row_st *row_in=0, *row_out=0;
01796 raw_pad_st *pad_in=0, *pad_out=0;
01797 raw_seq_st *seq_in=0, *seq_out=0;
01798 unsigned short *adc_in=0, *adc_out=0;
01799 unsigned short *trk_in=NULL;
01800 unsigned short *trk_out=NULL;
01801
01802
01803 rawIter.Reset();
01804 while((sector = rawIter()) != NULL) {
01805 char sectorName[100];
01806 sprintf(sectorName, "Sector_%d", sectorIdx);
01807
01808 if(strcmp(sector->GetName(), sectorName) != 0) continue;
01809
01810
01811
01812
01813 St_DataSetIter sectorIter(sector);
01814
01815 Trow_in = (St_raw_row *)sectorIter.Find("raw_row_in");
01816 Trow_out = (St_raw_row *)sectorIter.Find("raw_row_out");
01817 Tpad_in = (St_raw_pad *)sectorIter.Find("raw_pad_in");
01818 Tpad_out = (St_raw_pad *)sectorIter.Find("raw_pad_out");
01819 Tseq_in = (St_raw_seq *)sectorIter.Find("raw_seq_in");
01820 Tseq_out = (St_raw_seq *)sectorIter.Find("raw_seq_out");
01821 Tadc_in = (St_type_shortdata *)sectorIter.Find("pixel_data_in");
01822 Tadc_out = (St_type_shortdata *)sectorIter.Find("pixel_data_out");
01823 Ttrk_in = (St_type_shortdata *)sectorIter.Find("pixel_indx_in");
01824 Ttrk_out = (St_type_shortdata *)sectorIter.Find("pixel_indx_out");
01825
01826
01827 row_in = Trow_in->GetTable();
01828 row_out = Trow_out->GetTable();
01829 pad_in = Tpad_in->GetTable();
01830 pad_out = Tpad_out->GetTable();
01831 seq_in = Tseq_in->GetTable();
01832 seq_out = Tseq_out->GetTable();
01833 adc_in = (unsigned short *)Tadc_in->GetTable();
01834 adc_out = (unsigned short *)Tadc_out->GetTable();
01835
01836 if(hasSim) {
01837 if(!Ttrk_in || !Ttrk_out) {
01838 LOG_INFO << "<FCFMaker> didn't find pixel_indx tables, but simulation are on" << endm;
01839 }
01840
01841 trk_in = (unsigned short *)Ttrk_in->GetTable();
01842 trk_out = (unsigned short *)Ttrk_out->GetTable();
01843
01844
01845 }
01846 else {
01847 if(Ttrk_in || Ttrk_out) {
01848 LOG_INFO << "<FCFMaker> found pixel_indx tables, but simulations are off" << endm;
01849 }
01850 trk_in = NULL;
01851 trk_out = NULL;
01852 }
01853
01854 haveRaw = 1;
01855 haveAnyRaw = 1;
01856 }
01857
01858
01859
01860
01861 if(haveRaw) {
01862
01863 memset(&cpp[0],0xff,sizeof(cpp));
01864 sz = 0;
01865 int sz2;
01866
01867 sz2 = BuildCPP(Trow_in->GetNRows(), row_in, pad_in, seq_in, sectorIdx);
01868 if(sz2 == -1 && Debug()){
01869 LOG_DEBUG << Form("<StRTSClientFCFMaker::build_croat_clusters> No data for sector %d, inner",
01870 sectorIdx)
01871 << endm;
01872 }
01873 else sz += sz2;
01874
01875 sz2 = BuildCPP(Trow_out->GetNRows(), row_out, pad_out, seq_out, sectorIdx);
01876 if(sz2 == -1 && Debug()){
01877 LOG_DEBUG << Form("<StRTSClientFCFMaker::build_croat_clusters> No data for sector %d, outer",
01878 sectorIdx)
01879 << endm;
01880 }
01881 else sz += sz2;
01882 }
01883
01884
01885 for(int r=44;r>=0;r--) {
01886
01887 if(r==12) continue ;
01888
01889 j_uintptr *raw_resptr = croat_resptr->v[r];
01890 j_uintptr *sim_resptr = (hasSim) ? simu_resptr->v[r] : NULL;
01891
01892 if(haveRaw) {
01893
01894 nclusters +=
01895 runClusterFinder(raw_resptr,
01896 croat_out->v[r],
01897 sectorIdx,
01898 r,
01899 &cpp[r],
01900 ((r<13) ? adc_in : adc_out),
01901 ((r<13) ? trk_in : trk_out),
01902 (hasSim) ? simu_out->v[r] : NULL,
01903 sim_resptr);
01904
01905
01906
01907
01908
01909
01910
01911
01912 #if defined(FCF_ANNOTATE_CLUSTERS) && defined(__ROOT__)
01913 St_fcfPixel *fcfPixA = new St_fcfPixel(Form("fcfPixA%i_%i",sectorIdx,r+1),1000);
01914 fcfPixATop->Add(fcfPixA);
01915 fcfPixel_st pix;
01916 for(int i=1;i<=182;i++) {
01917 for(int j=0;j<512;j++) {
01918 if(pixStruct[i][j].adc) {
01919 pix.pad = i;
01920 pix.tbin = j;
01921 pix.adc = pixStruct[i][j].adc;
01922 pix.cl_id = pixStruct[i][j].cl_id;
01923 pix.id_simtrk = pixStruct[i][j].id_simtrk;
01924 fcfPixA->AddAt(&pix);
01925 }
01926 }
01927 }
01928 #endif
01929 }
01930 }
01931
01932
01933
01934
01935 if(haveAnyRaw == 0) return -1;
01936 return nclusters;
01937 }
01938
01939