22 #include "St_pp2pp_Maker.h"
23 #include "StRtsTable.h"
24 #include "TDataSetIter.h"
25 #include "RTS/src/DAQ_PP2PP/pp2pp.h"
27 #include "St_db_Maker/St_db_Maker.h"
29 #include "tables/St_pp2ppPedestal_Table.h"
30 #include "tables/St_pp2ppPedestal160_Table.h"
31 #include "tables/St_pp2ppOffset_Table.h"
32 #include "tables/St_pp2ppZ_Table.h"
33 #include "tables/St_pp2ppRPpositions_Table.h"
34 #include "tables/St_pp2ppAcceleratorParameters_Table.h"
35 #include "tables/St_pp2ppPMTSkewConstants_Table.h"
37 #include "StEvent/StEvent.h"
38 #include "StEvent/StRunInfo.h"
39 #include "StEvent/StRpsCollection.h"
40 #include "StEvent/StRpsCluster.h"
41 #include "StEvent/StRpsTrackPoint.h"
42 #include "StEvent/StRpsTrack.h"
44 #include "StEvent/StTriggerData2009.h"
45 #include "StEvent/StTriggerData2012.h"
46 #include "StEvent/StTriggerData2013.h"
47 #include "StEvent/StTriggerData2016.h"
48 #include "StEvent/StTriggerData2017.h"
55 mPedestalPerchannelFilename("pedestal.in.perchannel"), mLDoCluster(kTRUE),
56 kMaxPitchesToMatch(3.0),
57 kPitch{ kpitch_6svx, kpitch_4svx }{
65 mThetaXY_tilt[kX] = 0.0;
66 mThetaXY_tilt[kY] = 0.0;
67 mDistanceFromIPtoDX[StBeamDirection::east] = 9.8;
68 mDistanceFromIPtoDX[StBeamDirection::west] = 9.8;
69 mLDX[StBeamDirection::east] = 3.7;
70 mLDX[StBeamDirection::west] = 3.7;
71 mBendingAngle[StBeamDirection::east] = 0.018832292;
72 mBendingAngle[StBeamDirection::west] = 0.018826657;
73 mConversion_TAC_time = 18e-12;
78 St_pp2pp_Maker::~St_pp2pp_Maker() {
85 mLastChain = ErrorCode;
86 mLastSeq = ErrorCode ;
87 return StMaker::Init();
90 Int_t St_pp2pp_Maker::InitRun(
int runumber) {
92 if ( runumber < 16000000 )
94 else if ( runumber < 18000000 )
99 cout <<
"St_pp2pp_Maker: Timestamp - Day: " << GetDateTime().GetDate() <<
" , DB-Time: " << GetDBTime().GetDate() << endl ;
100 cout <<
"St_pp2pp_Maker: Timestamp - Time: " << GetDateTime().GetTime() <<
" , DB-Date: " << GetDBTime().GetTime() << endl ;
103 readPedestalPerchannel() ;
104 readOffsetPerplane() ;
108 if ( mVersion >= 2 ) {
109 readSkewParameter() ;
110 readAccelerateParameter() ;
117 Int_t St_pp2pp_Maker::readPedestalPerchannel() {
123 memset(mPedave,0,
sizeof(mPedave));
124 memset(mPedrms,0,
sizeof(mPedrms));
126 Int_t s, c, sv, ch, idb = 0 ;
143 if ( mVersion == 1 ) {
145 DB = GetInputDB(
"Calibrations/pp2pp/pp2ppPedestal");
147 LOG_ERROR <<
"ERROR: cannot find database Calibrations_pp2pp/pp2ppPedestal ?" << endm ;
151 St_pp2ppPedestal *descr = 0;
152 descr = (St_pp2ppPedestal*) DB->
Find(
"pp2ppPedestal");
155 pp2ppPedestal_st *table = descr->GetTable();
157 for ( idb = 0; idb < descr->GetNRows(); idb++ ) {
158 s = (Int_t) table[idb].sequencer ;
159 c = (Int_t) table[idb].chain ;
160 sv = (Int_t) table[idb].SVX ;
161 ch = (Int_t) table[idb].channel ;
164 mPedave[s-1][c][sv][ch] = table[idb].mean ;
165 mPedrms[s-1][c][sv][ch] = table[idb].rms ;
171 LOG_ERROR <<
"St_pp2pp_Maker: No data in pp2ppPedestal table (wrong timestamp?). Nothing to return, then." << endm ;
177 DB = GetDataBase(
"Calibrations/pp2pp/pp2ppPedestal160");
179 LOG_ERROR <<
"ERROR: cannot find database Calibrations/pp2pp/pp2ppPedestal160 ?" << endm ;
183 St_pp2ppPedestal160 *dataset = 0;
184 dataset = (St_pp2ppPedestal160*) DB->
Find(
"pp2ppPedestal160");
187 if ( dataset->GetNRows() > 1 ) {
188 LOG_ERROR <<
"St_pp2pp_Maker : Found INDEXED table with " << dataset->GetNRows() <<
" rows \?!" << endm ;
191 pp2ppPedestal160_st *table = dataset->GetTable();
192 for (Int_t j = 0; j < 160; j++) {
199 else if ( (j%20) < 10 ) {
203 else if ( (j%20) < 14 ) {
212 LOG_DEBUG << j <<
"th element: seq = " << s+1 <<
" chain = " << c <<
" svx = " << sv
213 <<
" => mean: " << table[0].mean[j] <<
", rms: " << table[0].rms[j] << endm ;
215 mPedrms[s][c][sv][0] = table[0].rms[j] ;
220 LOG_ERROR <<
"St_pp2pp_Maker: dataset does not contain requested table" << endm ;
233 Int_t St_pp2pp_Maker::readOffsetPerplane() {
236 mRPpositionsTable = 0 ;
239 DB = GetInputDB(
"Geometry/pp2pp/pp2ppOffset");
241 LOG_ERROR <<
"ERROR: cannot find database Geometry_pp2pp/pp2ppOffset ?" << endm ;
246 St_pp2ppOffset *descr = 0;
247 descr = (St_pp2ppOffset*) DB->
Find(
"pp2ppOffset");
250 mOffsetTable = descr->GetTable();
251 LOG_DEBUG <<
"St_pp2pp_Maker : Reading pp2ppOffset table with nrows = " << descr->GetNRows() << endm ;
260 LOG_ERROR <<
"St_pp2pp_Maker : No data in pp2ppOffset table (wrong timestamp?). Nothing to return, then" << endm ;
265 if ( mVersion >= 2 ) {
267 DB = GetInputDB(
"Calibrations/pp2pp/pp2ppRPpositions");
269 LOG_ERROR <<
"ERROR: cannot find database Calibrations_pp2pp/pp2ppRPpositions ?" << endm ;
273 St_pp2ppRPpositions *descr = 0;
274 descr = (St_pp2ppRPpositions*) DB->
Find(
"pp2ppRPpositions");
276 LOG_DEBUG <<
"St_pp2pp_Maker : Reading pp2ppRPpositions table with nrows = " << descr->GetNRows() << endm ;
277 mRPpositionsTable = descr->GetTable();
278 mLVDT_pos[0] = mRPpositionsTable[0].y_right_E1U ;
279 mLVDT_pos[1] = mRPpositionsTable[0].y_left_E1D ;
280 mLVDT_pos[2] = mRPpositionsTable[0].y_top_E2U ;
281 mLVDT_pos[3] = mRPpositionsTable[0].y_bot_E2D ;
282 mLVDT_pos[4] = mRPpositionsTable[0].b_right_W1U ;
283 mLVDT_pos[5] = mRPpositionsTable[0].b_left_W1D ;
284 mLVDT_pos[6] = mRPpositionsTable[0].b_top_W2U ;
285 mLVDT_pos[7] = mRPpositionsTable[0].b_bot_W2D ;
295 LOG_ERROR <<
"St_pp2pp_Maker : No data in pp2ppRPpositions table (wrong timestamp?). Nothing to return, then" << endm ;
308 Int_t St_pp2pp_Maker::readZPerplane() {
313 DB = GetInputDB(
"Geometry/pp2pp/pp2ppZ");
315 LOG_ERROR <<
"ERROR: cannot find database Geometry_pp2pp/pp2ppZ ?" << endm ;
320 St_pp2ppZ *descr = 0;
321 descr = (St_pp2ppZ*) DB->
Find(
"pp2ppZ");
324 mZTable = descr->GetTable();
325 LOG_DEBUG <<
"Reading pp2ppZ table with nrows = " << descr->GetNRows() << endm ;
334 LOG_ERROR <<
"St_pp2pp_Maker : No data in pp2ppZ table (wrong timestamp?). Nothing to return, then" << endm ;
344 Int_t St_pp2pp_Maker::readSkewParameter() {
346 memset(mSkew_param,0,
sizeof(mSkew_param));
352 DB = GetDataBase(
"Calibrations/pp2pp/pp2ppPMTSkewConstants");
354 LOG_ERROR <<
"ERROR: cannot find database Calibrations/pp2pp/pp2ppPMTSkewConstants ?" << endm ;
358 St_pp2ppPMTSkewConstants *dataset = 0;
359 dataset = (St_pp2ppPMTSkewConstants*) DB->
Find(
"pp2ppPMTSkewConstants");
363 if ( dataset->GetNRows() > 1 ) {
364 LOG_ERROR <<
"St_pp2pp_Maker : Found INDEXED table with " << dataset->GetNRows() <<
" rows \?!" << endm ;
367 pp2ppPMTSkewConstants_st *table = dataset->GetTable();
368 for (
int j = 0; j < 64; j++) {
372 ipar = j - 4*ipmt - s*kMAXSEQ ;
374 LOG_DEBUG << j <<
"th element: RP = " << s <<
" PMT = " << ipmt <<
" parameter = " << ipar
375 <<
" with parameter : " << table[0].skew_param[j] << endm ;
377 mSkew_param[s][ipmt][ipar] = table[0].skew_param[j] ;
382 LOG_ERROR <<
"St_pp2pp_Maker: dataset does not contain requested table pp2ppPMTSkewConstants ." << endm ;
392 Int_t St_pp2pp_Maker::readAccelerateParameter() {
395 DB = GetInputDB(
"Geometry/pp2pp/pp2ppAcceleratorParameters");
397 LOG_ERROR <<
"ERROR: cannot find database Geometry_pp2pp/pp2ppAcceleratorParameters ?" << endm ;
402 St_pp2ppAcceleratorParameters *descr = 0;
403 descr = (St_pp2ppAcceleratorParameters*) DB->
Find(
"pp2ppAcceleratorParameters");
406 pp2ppAcceleratorParameters_st *table = descr->GetTable();
407 LOG_DEBUG <<
"St_pp2pp_Maker : Reading pp2ppAcceleratorParameters table with nrows = " << descr->GetNRows() << endm ;
409 mXYZ_IP[0] = table[0].x_IP ;
410 mXYZ_IP[1] = table[0].y_IP ;
411 mXYZ_IP[2] = table[0].z_IP ;
413 mThetaXY_tilt[0] = table[0].theta_x_tilt ;
414 mThetaXY_tilt[1] = table[0].theta_y_tilt ;
416 mDistanceFromIPtoDX[0] = table[0].distancefromDX_east ;
417 mDistanceFromIPtoDX[1] = table[0].distancefromDX_west ;
419 mLDX[0] = table[0].LDX_east ;
420 mLDX[1] = table[0].LDX_west ;
422 mBendingAngle[0] = table[0].bendingAngle_east ;
423 mBendingAngle[1] = table[0].bendingAngle_west ;
425 mConversion_TAC_time = table[0].conversion_TAC_time ;
427 LOG_DEBUG << mXYZ_IP[0] <<
" " << mXYZ_IP[1] <<
" " << mXYZ_IP[2] <<
" "
428 << mThetaXY_tilt[0] <<
" " << mThetaXY_tilt[1] <<
" "
429 << mDistanceFromIPtoDX[0] <<
" " << mDistanceFromIPtoDX[1] <<
" "
430 << mLDX[0] <<
" " << mLDX[1] <<
" "
431 << mBendingAngle[0] <<
" " << mBendingAngle[1] <<
" "
432 << mConversion_TAC_time << endm ;
435 LOG_ERROR <<
"St_pp2pp_Maker : No data in pp2ppAcceleratorParameters table (wrong timestamp?). Nothing to return, then" << endm ;
451 for ( Int_t i=0; i<kMAXSEQ; i++)
452 for ( Int_t j=0; j<kMAXCHAIN; j++)
453 (mValidHits[i][j]).clear();
482 if ( mVersion == 1 ) {
483 while ( GetNextAdc() ) {
486 for (;iword != DaqDta()->end();++iword) {
489 if ( DoerPp2pp(d,*pp2ppRawHits) !=
kStOK )
491 if ( counter == 0 ) mSiliconBunch = d.bunch_xing ;
495 while ( GetNext(
"adc_ped_sub") ) {
498 for (;iword != DaqDta()->end();++iword) {
501 if ( DoerPp2pp(d,*pp2ppRawHits) !=
kStOK )
503 if ( counter == 0 ) mSiliconBunch = d.bunch_xing ;
509 LOG_DEBUG <<
"There was no pp2pp data for this event. " << endm;
511 LOG_DEBUG <<
"End of pp2pp data for this event : " << GetEventNumber() <<
", Total = " << counter+1
512 <<
" records were found" << endm;
515 AddData(pp2ppRawHits);
522 for ( Int_t i=0; i<kMAXSEQ; i++)
523 for ( Int_t j=0; j<kMAXCHAIN; j++) {
524 sort( (mValidHits[i][j]).begin(), (mValidHits[i][j]).end(), hitcompare);
541 oneSihit.sec = Sector() ;
542 oneSihit.sequencer = d.seq_id ;
543 oneSihit.chain = d.chain_id ;
544 oneSihit.svx = d.svx_id ;
553 if ( mVersion == 1 ) {
554 if ( (oneSihit.svx != mLastSvx) && (mLastSvx != ErrorCode) ) {
556 if ( Int_t(oneSihit.svx-1) != mLastSvx )
558 if ( ( (oneSihit.svx-mLastSvx) != -3 && ( (oneSihit.chain%2)==1 ) ) ||
559 ( (oneSihit.svx-mLastSvx) != -5 && ( (oneSihit.chain%2)==0 ) ) ) {
561 if ( oneSihit.svx == 7 && oneSihit.sequencer == 3 && oneSihit.chain == 2 )
564 else if ( oneSihit.svx < mLastSvx && ( GetRunNumber()<10185015 || (mLastSeq!=2 && mLastChain!=2)) ) {
566 LOG_WARN <<
"Decreased ? " << GetEventNumber() <<
" : mLastSeq = " << mLastSeq <<
", mLastChain = " << mLastChain <<
", mLastSvx = " << mLastSvx << endm ;
567 LOG_WARN <<
"Decreased ? " << GetEventNumber() <<
" : Now, seq = " << (int) oneSihit.sequencer <<
", chain = " << (
int) oneSihit.chain <<
", svx = " << (int) oneSihit.svx << endm ;
569 oneSihit.svx = mLastSvx + 1 ;
571 LOG_WARN <<
"Decreased ? : So -> " <<
" svx is now = " << (
int) oneSihit.svx << endm ;
575 else if ( GetRunNumber()<10185015 || ( mLastSeq!=2 && mLastChain!=2 ) ) {
577 LOG_WARN << GetEventNumber() <<
" : mLastSeq = " << mLastSeq <<
", mLastChain = " << mLastChain <<
", mLastSvx = " << mLastSvx << endm ;
578 LOG_WARN << GetEventNumber() <<
" : Now, seq = " << (int) oneSihit.sequencer <<
", chain = " << (
int) oneSihit.chain <<
", svx = " << (int) oneSihit.svx << endm ;
586 else if ( (oneSihit.chain==mLastChain) && (mLastChain != ErrorCode) ) {
587 LOG_WARN <<
"Repeated ? :" << GetEventNumber() <<
" : mLastSeq = " << mLastSeq <<
", mLastChain = " << mLastChain <<
", mLastSvx = " << mLastSvx << endm ;
588 LOG_WARN <<
"Repeated ? : " << GetEventNumber() <<
" : Now, seq = " << (int) oneSihit.sequencer <<
", chain = " << (
int) oneSihit.chain <<
", svx = " << (int) oneSihit.svx << endm ;
590 oneSihit.svx = mLastSvx + 1 ;
592 LOG_WARN <<
"Repeated : So -> " <<
" svx is now = " << (
int) oneSihit.svx << endm ;
600 if ( oneSihit.svx == 7 && oneSihit.sequencer == 7 && oneSihit.chain == 2 )
604 mRpStatus[oneSihit.sequencer - 1] = d.bunch_xing ;
606 mLastSeq = oneSihit.sequencer;
607 mLastChain = oneSihit.chain;
608 mLastSvx = oneSihit.svx;
612 for(
unsigned int c=0;c<
sizeof(d.adc);c++) {
615 if ( d.trace[c] == 1 ) {
616 oneSihit.channel = c ;
617 oneSihit.adc = d.adc[c];
618 hitsTable.
AddAt(&oneSihit);
622 if ( mLDoCluster && (c != (kMAXSTRIP-1)) && (c != 0) ) {
627 if ( ( mLastSeq == 4 ) && ( mLastChain == 0 ) && ( mVersion>=2 ) )
628 onehit.first = mLastSvx*(kMAXSTRIP) + oneSihit.channel ;
630 onehit.first = mLastSvx*(kMAXSTRIP-2) + oneSihit.channel - 1 ;
635 onehit.second = oneSihit.adc - mPedave[mLastSeq-1][mLastChain][mLastSvx][oneSihit.channel] ;
637 if ( onehit.second > 5*mPedrms[mLastSeq-1][mLastChain][mLastSvx][oneSihit.channel] ) {
638 (mValidHits[mLastSeq-1][mLastChain]).push_back(onehit);
644 onehit.second = oneSihit.adc ;
646 if ( onehit.second > 5*mPedrms[mLastSeq-1][mLastChain][mLastSvx][0] ) {
647 (mValidHits[mLastSeq-1][mLastChain]).push_back(onehit);
655 else if ( d.trace[c] == 2 ) {
656 LOG_ERROR <<
"St_pp2pp_Maker : d->trace[c] == 2 ! " << endm ;
659 else if ( d.trace[c] != 0 )
660 std::cout << GetEventNumber() <<
" : trace = " << (Int_t) d.trace[c] <<
", Seq " << (Int_t) oneSihit.sequencer
661 <<
", chain " << (Int_t) oneSihit.chain <<
", SVX " << (Int_t) oneSihit.svx <<
", channel " << c
662 <<
" is duplicated ? ==> " << (Int_t) d.adc[c] << std::endl ;
676 const short orientations[kMAXCHAIN*kMAXSEQ] = {-1,1,-1,1, 1,-1,1,-1, 1,1,1,1, -1,-1,-1,-1, -1,-1,-1,-1, 1,1,1,1, -1,1,-1,1, 1,-1,1,-1 };
679 const short orientations2[kMAXCHAIN*kMAXSEQ] = {1,1,1,1, -1,-1,-1,-1, 1,1,1,1, -1,-1,-1,-1, 1,-1,1,-1, -1,1,-1,1, 1,-1,1,-1, -1,1,-1,1 };
681 const double zcoordinates[kMAXSEQ] = { -55.496, -55.496, -58.496, -58.496, 55.496, 55.496, 58.496, 58.496 };
684 const short EW[kMAXSEQ] = { 0, 0, 0, 0, 1, 1, 1, 1 } ;
685 const short VH[kMAXSEQ] = { 1, 1, 0, 0, 1, 1, 0, 0 } ;
686 const short UDOI[kMAXSEQ] = { 1, 0, 0, 1, 1, 0, 1, 0 } ;
688 const short UD[kMAXSEQ] = { 1, 0, 0, 1, 1, 0, 0, 1 } ;
692 const double LVDT_OFFSET[32] = {
693 4.991, -36.620, 4.945, -36.610, -4.147, 41.738, -4.103, 41.722,
694 5.114, -14.433, 5.197, -14.490, -4.439, 64.106, -4.679, 63.878,
695 4.708, 42.106, 4.764, 41.758, -5.443, -37.980, -5.365, -38.274,
696 4.065, 63.583, 4.072, 63.513, -3.665, -16.674, -3.714, -16.881,
699 const double LVDT_SCALE[32] = {
700 0.999, -0.010, 0.999, -0.011, 0.999, 0.000, 0.999, 0.000,
701 0.997, 0.000, 0.997, 0.000, 0.997, 0.000, 0.997, 0.000,
702 0.993, 0.000, 0.993, 0.000, 0.966, 0.000, 0.965, 0.000,
703 1.004, 0.000, 1.004, 0.000, 1.050, 0.000, 1.049, 0.000,
709 const double LVDT_OFFSET_2017[32] = {
710 3.752, -37.124, 3.699, -37.169, -5.160, 42.434, -5.115, 42.355,
711 4.236, -19.230, 4.321, -19.339, -5.311, 59.894, -5.533, 59.612,
712 4.864, 41.480, 4.908, 41.213, -4.293, -37.968, -4.315, -38.297,
713 5.169, 63.474, 5.106, 63.479, 3.377, -15.926, 3.412, -16.133,
716 const double LVDT_SCALE_2017[32] = {
717 0.998, 0.000, 0.998, 0.000, 0.998, 0.000, 0.998, 0.000,
718 0.996, 0.000, 0.996, 0.000, 0.996, 0.000, 0.998, 0.000,
719 0.997, 0.000, 0.997, 0.000, 1.002, 0.000, 1.002, 0.000,
720 1.003, 0.000, 1.003, 0.000, 1.007, 0.000, 1.007, 0.000,
724 Bool_t is_candidate_to_store ;
726 Int_t NCluster_Length, Diff_Bunch ;
727 Double_t ECluster, POStimesE, POStimesESq, position, positionRMS, offset, pitch ;
741 pp2ppColl->setSiliconBunch(mSiliconBunch) ;
743 vector< HitChannel >::iterator it, it_next ;
745 for ( Int_t i=0; i<kMAXSEQ; i++)
746 for ( Int_t j=0; j<kMAXCHAIN; j++) {
753 if ( mVersion == 1 ) {
754 pp2ppColl->romanPot(i)->setAdc((uint32_t) trg_p->pp2ppADC( (StBeamDirection) EW[i],VH[i],UDOI[i],0),
755 (uint32_t) trg_p->pp2ppADC( (StBeamDirection) EW[i],VH[i],UDOI[i],1) );
756 pp2ppColl->romanPot(i)->setTac((uint32_t) trg_p->pp2ppTAC( (StBeamDirection) EW[i],VH[i],UDOI[i],0),
757 (uint32_t) trg_p->pp2ppTAC( (StBeamDirection) EW[i],VH[i],UDOI[i],1) );
760 pp2ppColl->romanPot(i)->setAdc((uint32_t) trg_p->pp2ppADC( (StBeamDirection) EW[i],VH[i],UD[i],0),
761 (uint32_t) trg_p->pp2ppADC( (StBeamDirection) EW[i],VH[i],UD[i],1) );
762 pp2ppColl->romanPot(i)->setTac((uint32_t) trg_p->pp2ppTAC( (StBeamDirection) EW[i],VH[i],UD[i],0),
763 (uint32_t) trg_p->pp2ppTAC( (StBeamDirection) EW[i],VH[i],UD[i],1) );
767 Diff_Bunch = mRpStatus[i] - trg_p->bunchId7Bit() ;
768 if ( Diff_Bunch < 0 ) Diff_Bunch += 120 ;
769 pp2ppColl->romanPot(i)->setStatus( (
unsigned char) Diff_Bunch ) ;
773 LOG_WARN <<
"No StTriggerData ?! " << endm ;
776 NCluster_Length = 0 ;
782 pp2ppColl->romanPot(i)->plane(j)->setZ( mZTable[0].rp_z_plane[4*i+j] ) ;
784 pp2ppColl->romanPot(i)->plane(j)->setZ(zcoordinates[i]) ;
786 if ( mVersion < 2 ) {
788 offset = mOffsetTable[0].rp_offset_plane[4*i+j]/1000. ;
790 offset = double(ErrorCode) ;
794 if ( mRPpositionsTable ) {
797 offset = ( LVDT_OFFSET[4*i+j] + LVDT_SCALE[4*i+j]*mLVDT_pos[i] )/1000. ;
799 offset = ( LVDT_OFFSET_2017[4*i+j] + LVDT_SCALE_2017[4*i+j]*mLVDT_pos[i] )/1000. ;
802 offset = double(ErrorCode) ;
806 pp2ppColl->romanPot(i)->plane(j)->setOffset( offset ) ;
809 pp2ppColl->romanPot(i)->plane(j)->setOrientation( orientations[4*i+j] ) ;
811 pp2ppColl->romanPot(i)->plane(j)->setOrientation( orientations2[4*i+j] ) ;
813 it = (mValidHits[i][j]).begin() ;
815 while ( it != (mValidHits[i][j]).end() ) {
819 ECluster += it->second ;
820 POStimesE += it->first*it->second ;
821 POStimesESq += it->first * it->first * it->second ;
825 is_candidate_to_store = kFALSE ;
828 if ( it_next != (mValidHits[i][j]).end() ) {
831 if ( (it_next->first - it->first)!=1 )
832 is_candidate_to_store = kTRUE ;
836 is_candidate_to_store = kTRUE ;
839 if ( is_candidate_to_store == kTRUE ) {
846 oneStCluster->setEnergy(ECluster);
847 oneStCluster->setLength(NCluster_Length);
848 position = POStimesE/ECluster ;
850 positionRMS = POStimesESq/ECluster - position*position ;
851 if ( positionRMS > 0 )
852 positionRMS = sqrt( positionRMS ) ;
856 if ( (j % 2) == 0 ) {
859 if ( ( mVersion >= 2 ) && ( i == 3 ) && ( j == 0 ) ) {
860 pitch = kpitch_4svx2 ;
863 pitch = kpitch_4svx ;
867 pitch = kpitch_6svx ;
870 position = position*pitch ;
871 positionRMS = positionRMS*pitch ;
873 oneStCluster->setPosition(position);
874 oneStCluster->setPositionRMS(positionRMS);
877 oneStCluster->setXY( offset + orientations[4*i+j]*position ) ;
879 oneStCluster->setXY( offset + orientations2[4*i+j]*position ) ;
881 pp2ppColl->romanPot(i)->plane(j)->addCluster(oneStCluster);
894 NCluster_Length = 0 ;
904 mEvent = (
StEvent *) GetInputDS(
"StEvent");
908 MakeTracks(*pp2ppColl, mEvent->runInfo()->beamEnergy(StBeamDirection::blue), mEvent->runInfo()->beamEnergy(StBeamDirection::yellow) );
911 mEvent->setRpsCollection(pp2ppColl);
914 LOG_ERROR <<
"St_pp2pp_Maker : StEvent not found !" << endm ;
926 vector< StRpsTrackPoint* > trackPointsVec[kMAXSEQ];
927 vector< StRpsTrack* > trackVec;
930 formTrackPoints( RpsColl, trackPointsVec );
933 formTracks( &trackVec, trackPointsVec, blue_beamenergy, yellow_beamenergy );
936 for(
int i=0; i<kMAXSEQ; ++i){
937 for(
unsigned int j=0; j<trackPointsVec[i].size(); ++j){
938 RpsColl.addTrackPoint( trackPointsVec[i][j] );
941 for(
unsigned int j=0; j<trackVec.size(); ++j){
942 RpsColl.addTrack( trackVec[j] );
950 void St_pp2pp_Maker::formTracks( vector< StRpsTrack* > *trackVec,
const vector< StRpsTrackPoint* > *trackPointVec,
const float beamMomentumWest,
const float beamMomentumEast )
const{
952 double beamMomentum[2];
953 beamMomentum[StBeamDirection::east] = beamMomentumEast;
954 beamMomentum[StBeamDirection::west] = beamMomentumWest;
956 for(
int branch=0; branch<kBranches; ++branch){
958 unsigned int side = ( branch < kBranches/2 ? StBeamDirection::east : StBeamDirection::west );
959 int sign = (side == StBeamDirection::east ? -1 : 1 );
960 int nPts[kStationsPerBranch];
961 nPts[kRP1] = trackPointVec[ kRpInBranch[branch][kRP1] ].size();
962 nPts[kRP2] = trackPointVec[ kRpInBranch[branch][kRP2] ].size();
964 if( nPts[kRP1] && nPts[kRP2] ){
966 for(
int i=0; i<nPts[kRP1]; ++i){
967 for(
int j=0; j<nPts[kRP2]; ++j){
970 track->setBranch( branch );
971 track->setType( StRpsTrack::rpsGlobal );
972 track->setTrackPoint( trackPointVec[ kRpInBranch[branch][kRP1] ][i], kRP1 );
973 track->setTrackPoint( trackPointVec[ kRpInBranch[branch][kRP2] ][j], kRP2 );
976 double localThetaX = track->thetaRp( StRpsTrack::rpsAngleThetaX ) - sign*mThetaXY_tilt[kX];
977 double localThetaY = track->thetaRp( StRpsTrack::rpsAngleThetaY ) - sign*mThetaXY_tilt[kY];
978 double x_BCS = trackPointVec[ kRpInBranch[branch][kRP1] ][i]->x() - mXYZ_IP[kX] - sin(mThetaXY_tilt[kX])*( trackPointVec[ kRpInBranch[branch][kRP1] ][i]->z() - mXYZ_IP[kZ] );
979 double d2 = abs( trackPointVec[ kRpInBranch[branch][kRP1] ][i]->z() ) - mLDX[side] - mDistanceFromIPtoDX[side];
980 double thetaX_IP = ( x_BCS - (d2 + 0.5*mLDX[side])*localThetaX ) / ( mDistanceFromIPtoDX[side] + 0.5*mLDX[side] );
981 double xi = 1. / ( 1 + (mBendingAngle[side]*(mDistanceFromIPtoDX[side] + 0.5*mLDX[side])) / ( localThetaX*abs( trackPointVec[ kRpInBranch[branch][kRP1] ][i]->z() ) - x_BCS ) );
982 double momentumValue = beamMomentum[side] * (1.-xi);
985 momentumVector.rotateX( -sign*localThetaY );
986 momentumVector.rotateY( sign*thetaX_IP );
987 track->setP( momentumVector );
989 trackVec->push_back( track );
993 else if( nPts[kRP1] || nPts[kRP2] ){
995 int station = nPts[kRP1] ? kRP1 : kRP2;
996 for(
int i=0; i<nPts[station]; ++i){
999 track->setBranch( branch );
1000 track->setType( StRpsTrack::rpsLocal );
1001 track->setTrackPoint( trackPointVec[ kRpInBranch[branch][station] ][i], station );
1004 double x_BCS = trackPointVec[ kRpInBranch[branch][station] ][i]->x() - mXYZ_IP[kX] - sin(mThetaXY_tilt[kX])*( trackPointVec[ kRpInBranch[branch][station] ][i]->z() - mXYZ_IP[kZ] );
1005 double y_BCS = trackPointVec[ kRpInBranch[branch][station] ][i]->y() - mXYZ_IP[kY] - sin(mThetaXY_tilt[kY])*( trackPointVec[ kRpInBranch[branch][station] ][i]->z() - mXYZ_IP[kZ] );
1006 double localThetaX = x_BCS / abs( trackPointVec[ kRpInBranch[branch][station] ][i]->z() );
1007 double localThetaY = y_BCS / abs( trackPointVec[ kRpInBranch[branch][station] ][i]->z() );
1008 double momentumValue = beamMomentum[side];
1011 momentumVector.rotateX( -sign*localThetaY );
1012 momentumVector.rotateY( sign*localThetaX );
1013 track->setP( momentumVector );
1015 trackVec->push_back( track );
1023 void St_pp2pp_Maker::formTrackPoints(
const StRpsCollection& RpsColl, vector< StRpsTrackPoint* > *trackPointVec )
const{
1025 for(
int i=0; i<kMAXSEQ; ++i){
1028 vector<St_pp2pp_Maker::StRpsHit> hits[kCoordinates];
1029 hits[kY] = formHits(RpsColl.romanPot(i), kY);
1030 if( hits[kY].size()==0 )
continue;
1031 hits[kX] = formHits(RpsColl.romanPot(i), kX);
1032 if( hits[kX].size()==0 )
continue;
1035 double time[2] = {-1, -1};
1036 for(
unsigned int pmt=0; pmt<2; ++pmt){
1037 if( RpsColl.romanPot(i)->tac(pmt) < kMaxPedestalTAC )
continue;
1038 time[pmt] = timeFromTAC( i, pmt, RpsColl.romanPot(i)->tac(pmt), RpsColl.romanPot(i)->adc(pmt) );
1042 for(
unsigned int j=0; j<hits[kX].size(); ++j){
1043 for(
unsigned int k=0; k<hits[kY].size(); ++k){
1047 double x = hits[kX][j].mPositionXY;
1048 double y = hits[kY][k].mPositionXY;
1049 double z = (hits[kX][j].mPositionZ*hits[kX][j].mPlanesUsed + hits[kY][k].mPositionZ*hits[kY][k].mPlanesUsed) / (hits[kX][j].mPlanesUsed + hits[kY][k].mPlanesUsed);
1051 trackPoint->setPosition( pos );
1054 trackPoint->setRpId( i );
1057 for(
int l=0; l<kPlanesPerCoordinate; ++l){
1058 trackPoint->setClusterId( hits[kY][k].mClusterId[l], kPlanes[kY][l] );
1059 trackPoint->setClusterId( hits[kX][j].mClusterId[l], kPlanes[kX][l] );
1063 for(
unsigned int pmt=0; pmt<trackPoint->mNumberOfPmtsInRp; ++pmt){
1064 trackPoint->setTime( time[pmt], pmt );
1068 if( hits[kX][j].mGolden && hits[kY][k].mGolden ) trackPoint->setQuality( StRpsTrackPoint::rpsGolden );
1069 else trackPoint->setQuality( StRpsTrackPoint::rpsNormal );
1072 trackPointVec[i].push_back( trackPoint );
1080 vector<St_pp2pp_Maker::StRpsHit> St_pp2pp_Maker::formHits(
const StRpsRomanPot* Rp,
const int coordinate)
const{
1082 vector<St_pp2pp_Maker::StRpsHit> hitVec;
1084 vector<double> pos[kPlanesPerCoordinate];
1085 vector<int> en[kPlanesPerCoordinate];
1086 vector<int> len[kPlanesPerCoordinate];
1087 vector<int>
id[kPlanesPerCoordinate];
1089 preselectClusters(Rp, coordinate, pos, en, len,
id);
1090 int clCase = classifyClustersCase(pos);
1094 std::vector<int> validClusters[kPlanesPerCoordinate];
1095 bool matched = matchClusters(coordinate, clCase, pos, validClusters);
1098 for(
unsigned int k=0; k<validClusters[kFirst].size(); ++k){
1099 St_pp2pp_Maker::StRpsHit
hit;
1100 hit.mPositionXY = ( pos[kFirst][validClusters[kFirst][k]] + pos[kSecond][validClusters[kSecond][k]] )/2;
1101 hit.mPositionZ = ( Rp->plane(kPlanes[coordinate][kFirst])->z() + Rp->plane(kPlanes[coordinate][kSecond])->z() )/2;
1102 for(
int j=0; j<kPlanesPerCoordinate; ++j) hit.mClusterId[j] =
id[j][validClusters[j][k]];
1103 hit.mPlanesUsed = kPlanesPerCoordinate;
1104 if(clCase==5) hit.mGolden =
true;
1105 else hit.mGolden =
false;
1107 hitVec.push_back( hit );
1111 for(
int j=0; j<kPlanesPerCoordinate; ++j){
1112 for(
unsigned int k=0; k<pos[j].size(); ++k){
1113 St_pp2pp_Maker::StRpsHit hit;
1114 hit.mPositionXY = pos[j][k];
1115 hit.mPositionZ = Rp->plane(kPlanes[coordinate][j])->z();
1116 for(
int l=0; l<kPlanesPerCoordinate; ++l){
1117 if(l==j) hit.mClusterId[l] =
id[l][k];
1118 else hit.mClusterId[l] = -1;
1120 hit.mPlanesUsed = 1;
1121 hit.mGolden =
false;
1122 hitVec.push_back( hit );
1133 void St_pp2pp_Maker::preselectClusters(
const StRpsRomanPot* Rp,
const int coordinate, vector<double>* pos, vector<int>* en, vector<int>* len, vector<int>*
id)
const{
1134 for(
int j=0; j<kPlanesPerCoordinate; ++j){
1135 const StRpsPlane* SiPlane = Rp->plane( kPlanes[coordinate][j] );
1136 int nClusters = SiPlane->numberOfClusters();
1137 if(nClusters < kMaxNumberOfClusterPerPlane)
1138 for(
int k=0; k < nClusters; ++k){
1140 int lenCluster = Cluster->length();
1141 if(lenCluster <= kMaxClusterLength && lenCluster>0){
1142 int enCluster = Cluster->energy();
1143 if(enCluster >= kEmin[ Rp->romanPotId() ][lenCluster-1]){
1144 pos[j].push_back( Cluster->xy() );
1145 en[j].push_back( enCluster );
1146 len[j].push_back( lenCluster );
1147 id[j].push_back( k );
1155 Int_t St_pp2pp_Maker::classifyClustersCase(vector<double>* pos)
const{
1156 int lA = pos[kFirst].size();
1157 int lB = pos[kSecond].size();
1159 if( lA==0 && lB==0 )
return -1;
else
1160 if( lA==1 && lB==1 )
return 5;
else
1161 if( lA==1 && lB >1 )
return 6;
else
1162 if( lA >1 && lB==1 )
return 7;
else
1163 if( lA==0 && lB==1 )
return 2;
else
1164 if( lA==1 && lB==0 )
return 1;
else
1165 if( lA>=2 && lB>=2 )
return 8;
else
1166 if( lA==0 && lB >1 )
return 4;
else
1167 if( lA >1 && lB==0 )
return 3;
else
1172 Bool_t St_pp2pp_Maker::matchClusters(
const int coordinate,
const int clCase,
const vector<double>* pos, std::vector<int>* validClusters)
const{
1174 case 5:
if( areMatched(coordinate, pos[kFirst][0], pos[kSecond][0]) ){
1175 validClusters[kFirst].push_back( 0 );
1176 validClusters[kSecond].push_back( 0 );
1180 case 7: {
double DeltaPosition = 1e9;
1181 double minDeltaPosition = 1e9;
1182 int index[kPlanesPerCoordinate] = { -1, -1 };
1183 for(
unsigned int c1=0; c1<pos[kFirst].size(); ++c1){
1184 for(
unsigned int c2=0; c2<pos[kSecond].size(); ++c2){
1185 if(areMatched(coordinate, pos[kFirst][c1], pos[kSecond][c2], &DeltaPosition)){
1186 if(abs(DeltaPosition) < minDeltaPosition){
1187 minDeltaPosition = abs(DeltaPosition);
1189 index[kSecond] = c2;
1194 if(index[kFirst]>-1){
1195 validClusters[kFirst].push_back( index[kFirst] );
1196 validClusters[kSecond].push_back( index[kSecond] );
1198 }
else return false;}
1199 case 8: {
for(
unsigned int c1=0; c1<pos[kFirst].size(); ++c1){
1200 for(
unsigned int c2=0; c2<pos[kSecond].size(); ++c2){
1201 if(areMatched(coordinate, pos[kFirst][c1], pos[kSecond][c2])){
1202 validClusters[kFirst].push_back( c1 );
1203 validClusters[kSecond].push_back( c2 );
1207 if(validClusters[kFirst].size()>0)
return true;
1209 default:
return false;
1215 Bool_t St_pp2pp_Maker::areMatched(
const int coordinate,
const double p1,
const double p2,
double *deltaPitches)
const{
1216 if(deltaPitches) *deltaPitches = (p1 - p2) / kPitch[coordinate];
1217 return abs( p1 - p2 ) < kMaxPitchesToMatch*kPitch[coordinate] ?
true :
false;
1222 const double St_pp2pp_Maker::kEmin[kMAXSEQ][kMaxClusterLength] =
1223 {{20, 20, 20, 20, 20},
1224 {20, 20, 20, 20, 20},
1225 {20, 20, 20, 20, 20},
1226 {20, 20, 20, 20, 20},
1227 {20, 20, 20, 20, 20},
1228 {20, 20, 20, 20, 20},
1229 {20, 20, 20, 20, 20},
1230 {20, 20, 20, 20, 20}};
1232 const int St_pp2pp_Maker::kPlanes[kCoordinates][kPlanesPerCoordinate] =
1236 const int St_pp2pp_Maker::kRpInBranch[kBranches][kStationsPerBranch] =
For pp2pp analysis : mainly to create clusters from raw data silicon hits.
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
virtual Int_t Make()
Make - this method is called in loop for each event.
virtual void Clear(Option_t *option="")
User defined functions.
Int_t MakeTracks(StRpsCollection &RpsColl, float blue_beamenergy, float yellow_beamenergy)
Int_t DoerPp2pp(const pp2pp_t &d, TGenericTable &hitsTable)
DoerPp2pp - this method is called as soon as next pp2pp record is read in.
virtual Int_t AddAt(const void *c)
virtual void Clear(Option_t *option="")
Clear - this method is called in loop for prepare the maker for the next event.
virtual Int_t Init()
Init - is a first method the top level StChain calls to initialize all its makers.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
virtual TDataSet * Find(const char *path) const