507 bool print_debug =
false;
510 MsgStream log(
msgSvc(), name());
517 ISvcLocator* svcLocator = Gaudi::svcLocator();
518 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
520 cout<<
"Could not accesss EventDataSvc!"<<endl;
523 SmartDataPtr<CgemDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/CgemDigiCol");
525 cout<<
"Could not retrieve CGEM digi collection"<<endl;
526 nhit = aDigiCol->size();
533 CgemDigiCol::iterator iDigiCol;
534 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
537 const Identifier ident = (*iDigiCol)->identify();
543 if(is_xstrip ==
true) view = 0;
544 double charge = (*iDigiCol)->getCharge_fc();
545 double time = (*iDigiCol)->getTime_ns();
547 hit_strip[ihit] = strip;
548 hit_layer[ihit] = layer;
549 hit_sheet[ihit] = sheet;
550 hit_view[ihit] = view;
552 hit_q[ihit] = charge;
556 else hit_length[ihit] = anode->
getLength();
558 int channel = lutreader->
GetChannel(layer, sheet, view, strip);
559 int roc = lutreader->
GetROC(layer, sheet, view, strip);
560 int feb = lutreader->
GetFEB(layer, sheet, view, strip);
561 int tiger = lutreader->
GetTIGER(layer, sheet, view, strip);
562 int chip = lutreader->
GetChip(layer, sheet, view, strip);
563 int quality = lutreader->
GetQuality(layer, sheet, view, strip);
565 hit_channel[ihit] = channel;
568 hit_tiger[ihit] = tiger;
569 hit_chip[ihit] = chip;
570 hit_quality[ihit] = quality;
573 if(print_debug) cout<<
"Id: "<<ihit<<
" layer: "<<layer<<
" sheet: "<<sheet<<
" view: "<<view<<
" strip: "<<strip<<endl;
576 double time_rising = myCgemCalibSvc->
getTimeRising(layer, view, sheet, 0, 0, 0.);
577 double time_falling = myCgemCalibSvc->
getTimeFalling(layer, view, sheet, 0, 0, 0.);
578 double time_gap = time_falling-time_rising;
579 double drift_velocity =
drift_gap/time_gap;
580 double time_ns = get_Time(iDigiCol);
583 if(striptype ==
true) flagxv = 0;
588 hit_x_tpc[ihit] = pos;
589 hit_z_tpc[ihit] = time_ns*drift_velocity;
592 if(selDigi(iDigiCol, m_selGoodDigi)==
true) {
593 hit_selgooddigi[ihit] = 1;
597 std::map<int, std::vector < int > > *map_strip_to_hit = GetStripToHitMap(layer, sheet, view);
598 std::map<int, std::vector < int > >::iterator it1 = map_strip_to_hit->find(strip);
599 if (it1 != map_strip_to_hit->end()) {
600 it1->second.push_back(ihit);
603 std::vector< int > hitlist;
604 hitlist.push_back(ihit);
605 std::pair<int, std::vector < int> > pair(strip, hitlist);
606 map_strip_to_hit->insert(pair);
617 SmartDataPtr<RecCgemClusterCol> aClusterCol(m_evtSvc,
"/Event/Recon/RecCgemClusterCol");
619 cout<<
"Could not retrieve CGEM cluster collection"<<endl;
620 int nclu = aClusterCol->size();
623 std::cout <<
"nclu " << nclu << std::endl;
631 int tmp_cluster_L1_S1 = -1;
632 int tmp_cluster_L2_S1 = -1;
633 int tmp_cluster_L2_S2 = -1;
634 int tmp_cluster_L3_S1 = -1;
635 int tmp_cluster_L3_S2 = -1;
636 double tmp_charge_L1_S1 = 0.;
637 double tmp_charge_L2_S1 = 0.;
638 double tmp_charge_L2_S2 = 0.;
639 double tmp_charge_L3_S1 = 0.;
640 double tmp_charge_L3_S2 = 0.;
646 RecCgemClusterCol::iterator iClusterCol;
647 for(iClusterCol=aClusterCol->begin(); iClusterCol!=aClusterCol->end(); iClusterCol++)
653 int flag = (*iClusterCol)->getflag();
654 int clusterid = (*iClusterCol)->getclusterid();
655 int trkid = (*iClusterCol)->getTrkId();
656 int layerid = (*iClusterCol)->getlayerid();
657 int sheetid = (*iClusterCol)->getsheetid();
658 double edep = (*iClusterCol)->getenergydeposit();
659 double phi = (*iClusterCol)->getrecphi();
660 double v = (*iClusterCol)->getrecv();
661 double z = (*iClusterCol)->getRecZ();
662 double phi_cc = (*iClusterCol)->getrecphi_CC();
663 double v_cc = (*iClusterCol)->getrecv_CC();
664 double z_cc = (*iClusterCol)->getRecZ_CC();
665 double phi_tpc = (*iClusterCol)->getrecphi_mTPC();
666 double v_tpc = (*iClusterCol)->getrecv_mTPC();
667 double z_tpc = (*iClusterCol)->getRecZ_mTPC();
668 double slope_tpc = (*iClusterCol)->getSlope_mTPC();
669 double inter_tpc = (*iClusterCol)->getInter_mTPC();
683 int flagB = (*iClusterCol)->getclusterflagb();
684 int flagE = (*iClusterCol)->getclusterflage();
686 int min_strip = 9999;
687 int max_strip =-9999;
690 if(flag==0 || flag == 1) {
691 cluster_1d_ID[ncluster] = (int) clusterid;
693 cluster_1d_t[ncluster] = 0;
694 cluster_1d_tmean[ncluster] = 0;
695 cluster_1d_tqmax[ncluster] = 0;
696 cluster_1d_q[ncluster] = edep;
698 cluster_1d_layerid[ncluster] = layerid;
699 cluster_1d_sheetid[ncluster] = sheetid;
700 cluster_1d_view[ncluster] = flag;
701 cluster_1d_r[ncluster] = anode_mid_gap;
702 cluster_1d_phi[ncluster] = phi;
703 cluster_1d_phi_cc[ncluster] = phi_cc;
704 cluster_1d_phi_tpc[ncluster] = phi_tpc;
705 cluster_1d_v[ncluster] =
v;
706 cluster_1d_v_cc[ncluster] = v_cc;
707 cluster_1d_v_tpc[ncluster] = v_tpc;
708 cluster_1d_slope_tpc[ncluster] = slope_tpc;
709 cluster_1d_inter_tpc[ncluster] = inter_tpc;
711 cluster_1d_strip1[ncluster] = flagB;
712 cluster_1d_strip2[ncluster] = flagE;
713 int size = flagE - flagB + 1;
714 cluster_1d_size[ncluster] = size;
719 std::map<int, std::vector < int > > *read_map_strip_to_hit = GetStripToHitMap(layerid, sheetid, flag);
720 std::map<int, std::vector < int > >::iterator it2;
729 for(
int istrip = 0; istrip < size; istrip++) {
734 int stripid = flagB + istrip;
736 it2 = read_map_strip_to_hit->find(stripid);
739 if(it2->first!=stripid){
745 if(it2->second.size()!=1){
750 std::vector< int > hitlist = it2->second;
756 int size_hitlist = hitlist.size();
757 cluster_1d_hitindex[ncluster][istrip] = hitlist[size_hitlist-1];
760 if(print_debug) cout<<
"N clus: "<<ncluster<<endl;
761 if(print_debug) cout<<
"size: "<<size<<endl;
763 float min_hit_time = 999999;
764 float hit_mean_time = 0;
765 float hit_qmax_time = 0;
766 float hit_qmax = -99999;
769 CgemDigiCol::iterator iDigiCol;
770 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++){
771 const Identifier ident = (*iDigiCol)->identify();
777 if(is_xstrip ==
true) view = 0;
778 if(layer==cluster_1d_layerid[ncluster] && sheet==cluster_1d_sheetid[ncluster] && view==cluster_1d_view[ncluster] && strip>=cluster_1d_strip1[ncluster] && strip<=cluster_1d_strip2[ncluster]){
779 if(strip<min_strip) min_strip = strip;
780 if(strip>max_strip) max_strip = strip;
784 cluster_1d_size_real[ncluster]=size_real;
785 cluster_1d_size_max[ncluster]=max_strip-min_strip+1;
787 for(
int istrip = 0; istrip < size; istrip++) {
789 int idhit = cluster_1d_hitindex[ncluster][istrip];
790 if(hit_t[idhit]<min_hit_time) min_hit_time = hit_t[idhit];
792 hit_mean_time += hit_t[idhit];
794 if(hit_qmax<hit_q[idhit]) {
795 hit_qmax=hit_q[idhit];
796 hit_qmax_time=hit_t[idhit];
799 hit_mean_time /= size;
801 cluster_1d_t[ncluster] = min_hit_time;
802 cluster_1d_tmean[ncluster] = hit_mean_time;
803 cluster_1d_tqmax[ncluster] = hit_qmax_time;
805 if(print_debug) cout<<
"size real: "<<cluster_1d_size_real[ncluster]<<endl;
806 if(print_debug) cout<<
"size max : "<<cluster_1d_size_max[ncluster]<<endl;
810 for(
int istrip = 0; istrip < size; istrip++) {
811 int idhit = cluster_1d_hitindex[ncluster][istrip];
812 cout<<cluster_1d_hitindex[ncluster][istrip]<<
" ";
816 cout<<
"Strip in the cluster: ";
817 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++){
818 const Identifier ident = (*iDigiCol)->identify();
824 if(is_xstrip ==
true) view = 0;
825 if(layer==cluster_1d_layerid[ncluster] && sheet==cluster_1d_sheetid[ncluster] && view==cluster_1d_view[ncluster] && strip>=cluster_1d_strip1[ncluster] && strip<=cluster_1d_strip2[ncluster]){
830 cout<<
"Check STRIP hit-cluster: ";
831 for(
int istrip = 0; istrip < size; istrip++) {
832 int idhit = cluster_1d_hitindex[ncluster][istrip];
833 cout<<hit_strip[idhit]<<
" ";
837 cout<<
"Check x_tpc: ";
838 for(
int istrip = 0; istrip < size; istrip++) {
839 int idhit = cluster_1d_hitindex[ncluster][istrip];
840 cout<<hit_x_tpc[idhit]<<
" ";
844 cout<<
"Check z_tpc: ";
845 for(
int istrip = 0; istrip < size; istrip++) {
846 int idhit = cluster_1d_hitindex[ncluster][istrip];
847 cout<<hit_z_tpc[idhit]<<
" ";
851 TF1 *f_tpc_cluster1 =
new TF1(
"f_tpc_cluster1",
"pol1");
852 f_tpc_cluster1->SetParameters(cluster_1d_inter_tpc[ncluster],cluster_1d_slope_tpc[ncluster]);
853 cout<<
"Check deltaX_tpc: ";
854 for(
int istrip = 0; istrip < size; istrip++) {
855 int idhit = cluster_1d_hitindex[ncluster][istrip];
856 float deltaX = hit_x_tpc[idhit]-f_tpc_cluster1->GetX(hit_z_tpc[idhit]);
860 cout<<
"Check deltaZ_tpc: ";
861 for(
int istrip = 0; istrip < size; istrip++) {
862 int idhit = cluster_1d_hitindex[ncluster][istrip];
863 float deltaZ = hit_z_tpc[idhit]-f_tpc_cluster1->Eval(hit_x_tpc[idhit]);
866 delete f_tpc_cluster1;
870 double time_rising = myCgemCalibSvc->
getTimeRising(cluster_1d_layerid[ncluster], cluster_1d_view[ncluster], cluster_1d_sheetid[ncluster], 0, 0, 0.);
871 double time_falling = myCgemCalibSvc->
getTimeFalling(cluster_1d_layerid[ncluster], cluster_1d_view[ncluster], cluster_1d_sheetid[ncluster], 0, 0, 0.);
872 double time_gap = time_falling-time_rising;
873 double drift_velocity = 5/time_gap;
876 float p0_tpc_corr = 0.003206 + size * (-0.0006184);
877 float p1_tpc_corr = -0.000500 + size * ( 0.0001325);
878 float shift0_tpc_corr = 0.003489 + size * ( 0.0003489);
880 p0_tpc_corr += 0.001030 + size * (-0.0006295);
881 p1_tpc_corr += 0.000902;
882 shift0_tpc_corr += 0.001105 + size * (-0.0002084);
884 p1_tpc_corr += 0.0005;
886 p1_tpc_corr += 0.0005;
888 p1_tpc_corr += 0.0005;
890 p1_tpc_corr += 0.0005;
892 p1_tpc_corr += 0.0005;
894 p1_tpc_corr += 0.0010;
896 p1_tpc_corr += 0.0010;
899 if(cluster_1d_view[ncluster]!=0 || cluster_1d_inter_tpc[ncluster]== -9999 || cluster_1d_slope_tpc[ncluster]==-9999){
900 for(
int istrip = 0; istrip < size; istrip++) {
901 int idhit = cluster_1d_hitindex[ncluster][istrip];
902 if(idhit==-1)
continue;
903 hit_deltax_tpc[idhit] = -9999;
904 hit_deltaz_tpc[idhit] = -9999;
905 hit_ex_tpc[idhit] = -9999;
906 hit_ez_tpc[idhit] = -9999;
907 hit_order[idhit] = -9999;
917 for(
int istrip = 0; istrip < size; istrip++) {
918 int idhit = cluster_1d_hitindex[ncluster][istrip];
919 if(idhit==-1)
continue;
921 float eX = sqrt(pow(pitch/sqrt(12.),2)+pow(pitch/sqrt(12.)*cluster_1d_q[ncluster]/cluster_1d_size[ncluster]/hit_q[idhit],2));
922 float eZ = 5*drift_velocity;
923 hit_ex_tpc[idhit] = eX;
924 hit_ez_tpc[idhit] = eZ;
925 hit_order[idhit]=istrip;
927 float deltaX_corr = 0;
929 if(cluster_1d_slope_tpc[ncluster]>0){
932 if(istrip==0) deltaX_corr -= p0_tpc_corr - shift0_tpc_corr;
939 if(istrip==size-1) deltaX_corr += p0_tpc_corr - shift0_tpc_corr;
945 hit_x_tpc[idhit] += deltaX_corr;
946 double x_expc = (hit_z_tpc[idhit]-cluster_1d_inter_tpc[ncluster])/cluster_1d_slope_tpc[ncluster];
947 double z_expc = cluster_1d_slope_tpc[ncluster]*hit_x_tpc[idhit]+cluster_1d_inter_tpc[ncluster];
948 float deltaX = hit_x_tpc[idhit]-x_expc;
949 float deltaZ = hit_z_tpc[idhit]-z_expc;
950 hit_deltax_tpc[idhit] = deltaX;
951 hit_deltaz_tpc[idhit] = deltaZ;
993 else if(flag==2 || flag==3) {
994 cluster_2d_ID[ncluster] = clusterid;
996 cluster_2d_t[ncluster] = 0;
997 cluster_2d_tmean[ncluster] = 0;
998 cluster_2d_tqmax[ncluster] = 0;
999 cluster_2d_q[ncluster] = edep;
1001 cluster_2d_layerid[ncluster] = layerid;
1002 cluster_2d_sheetid[ncluster] = sheetid;
1003 if(layerid==0 && phi>0) cluster_2d_sheetid[ncluster] = 1;
1004 cluster_2d_view[ncluster] = flag;
1005 cluster_2d_r[ncluster] = anode_mid_gap;
1006 cluster_2d_z[ncluster] = z;
1007 cluster_2d_z_cc[ncluster] = z_cc;
1008 cluster_2d_z_tpc[ncluster] = z_tpc;
1009 cluster_2d_phi[ncluster] = phi;
1010 cluster_2d_phi_cc[ncluster] = phi_cc;
1011 cluster_2d_phi_tpc[ncluster] = phi_tpc;
1013 cluster_2d_idx[ncluster] = flagB;
1014 cluster_2d_idv[ncluster] = flagE;
1017 if(cluster_1d_t[flagB]<cluster_1d_t[flagE]) cluster_2d_t[ncluster]=cluster_1d_t[flagB];
1018 else cluster_2d_t[ncluster]=cluster_1d_t[flagE];
1020 cluster_2d_tmean[ncluster] = 0.5*cluster_1d_tmean[flagB]+0.5*cluster_1d_tmean[flagE];
1022 if(cluster_1d_q[flagB]>cluster_1d_q[flagE]) cluster_2d_tqmax[ncluster]=cluster_1d_tqmax[flagB];
1023 else cluster_2d_tqmax[ncluster]=cluster_1d_tqmax[flagE];
1034 if(edep > tmp_charge_L1_S1) {
1035 tmp_charge_L1_S1 = edep; tmp_cluster_L1_S1 = ncluster;
1038 else if(layerid==1 && sheetid==0) {
1039 if(edep > tmp_charge_L2_S1){
1040 tmp_charge_L2_S1 = edep; tmp_cluster_L2_S1 = ncluster;
1043 else if(layerid==1 && sheetid==1) {
1044 if(edep > tmp_charge_L2_S2){
1045 tmp_charge_L2_S2 = edep; tmp_cluster_L2_S2 = ncluster;
1048 else if(layerid==2 && sheetid==0) {
1049 if(edep > tmp_charge_L3_S1){
1050 tmp_charge_L3_S1 = edep; tmp_cluster_L3_S1 = ncluster;
1053 else if(layerid==2 && sheetid==1) {
1054 if(edep > tmp_charge_L3_S2){
1055 tmp_charge_L3_S2 = edep; tmp_cluster_L3_S2 = ncluster;
1066 if(layerid == 0) ncluster_1d_L1_S1_x++;
1067 else if(layerid == 1) {
1068 if(sheetid == 0) ncluster_1d_L2_S1_x++;
1069 else ncluster_1d_L2_S2_x++;
1071 else if(layerid == 2) {
1072 if(sheetid == 0) ncluster_1d_L3_S1_x++;
1073 else ncluster_1d_L3_S2_x++;
1076 else if(flag == 1) {
1078 if(layerid == 0) ncluster_1d_L1_S1_v++;
1079 else if(layerid == 1) {
1080 if(sheetid == 0) ncluster_1d_L2_S1_v++;
1081 else ncluster_1d_L2_S2_v++;
1083 else if(layerid == 2) {
1084 if(sheetid == 0) ncluster_1d_L3_S1_v++;
1085 else ncluster_1d_L3_S2_v++;
1088 else if(flag == 2) {
1090 if(layerid == 0) ncluster_2d_L1_S1++;
1091 else if(layerid == 1) {
1092 if(sheetid == 0) ncluster_2d_L2_S1++;
1093 else ncluster_2d_L2_S2++;
1095 else if(layerid == 2) {
1096 if(sheetid == 0) ncluster_2d_L3_S1++;
1097 else ncluster_2d_L3_S2++;
1109 if(tmp_cluster_L1_S1!=-1) cluster_2d_highest[tmp_cluster_L1_S1]=1;
1110 if(tmp_cluster_L2_S1!=-1) cluster_2d_highest[tmp_cluster_L2_S1]=1;
1111 if(tmp_cluster_L2_S2!=-1) cluster_2d_highest[tmp_cluster_L2_S2]=1;
1112 if(tmp_cluster_L3_S1!=-1) cluster_2d_highest[tmp_cluster_L3_S1]=1;
1113 if(tmp_cluster_L3_S2!=-1) cluster_2d_highest[tmp_cluster_L3_S2]=1;
1116 SmartDataPtr<RecMdcTrackCol> aTrackCol(m_evtSvc,
"/Event/Recon/RecMdcTrackCol");
1125 RecMdcTrackCol::iterator iTrackCol;
1126 for(iTrackCol=aTrackCol->begin(); iTrackCol!=aTrackCol->end(); iTrackCol++)
1138 if(track->
trackId() != 0)
continue;
1140 track_chi2 = track->
chi2();
1142 track_dr = track->
helix(0);
1143 track_phi0 = track->
helix(1);
1144 track_dz = track->
helix(3);
1145 track_tanL = track->
helix(4);
1148 track_nfitpoint = vecclusters.size();
1151 bool istestplane[3][2];
1152 for(
int ilay=0; ilay<
MAXNOFLAYER; ilay++)
for(
int ishe=0; ishe<
MAXNOFSHEET; ishe++) istestplane[ilay][ishe] =
true;
1154 for(
int iclus=0; iclus < track_nfitpoint; iclus++) {
1157 double z = tcluster->
getRecZ();
1160 track_layerid[iclus] = tcluster->
getlayerid();
1161 track_sheetid[iclus] = tcluster->
getsheetid();
1162 if(phi > 0) track_sheetid[iclus] = 1;
1168 istestplane[track_layerid[iclus]][track_sheetid[iclus]] =
false;
1176 if(istestplane[ilay][ishe] ==
true) {
1177 track_test_layerid = ilay;
1178 track_test_sheetid = ishe;
1186 double xP;
double yP;
double zP;
1187 ComputePOCA(xP, yP, zP);
1190 double xP1;
double yP1;
double zP1;
double phiP1;
double vP1;
1191 double xP2;
double yP2;
double zP2;
double phiP2;
double vP2;
1193 double angCR_xy_L1, angCR_yz_L1;
1195 bool gotit1 = ComputeIntersection(0, xP1, yP1, zP1, phiP1, vP1, xP2, yP2, zP2, phiP2, vP2, angCR_xy_L1, angCR_yz_L1);
1197 ang_xy_L1 = angCR_xy_L1;
1198 ang_yz_L1 = angCR_yz_L1;
1201 double xP3;
double yP3;
double zP3;
double phiP3;
double vP3;
1202 double xP4;
double yP4;
double zP4;
double phiP4;
double vP4;
1204 double angCR_xy_L2, angCR_yz_L2;
1206 bool gotit2 = ComputeIntersection(1, xP3, yP3, zP3, phiP3, vP3, xP4, yP4, zP4, phiP4, vP4, angCR_xy_L2, angCR_yz_L2);
1208 ang_xy_L2 = angCR_xy_L2;
1209 ang_yz_L2 = angCR_yz_L2;
1212 double xP5;
double yP5;
double zP5;
double phiP5;
double vP5;
1213 double xP6;
double yP6;
double zP6;
double phiP6;
double vP6;
1215 double angCR_xy_L3, angCR_yz_L3;
1217 bool gotit3 = ComputeIntersection(2, xP5, yP5, zP5, phiP5, vP5, xP6, yP6, zP6, phiP6, vP6, angCR_xy_L3, angCR_yz_L3);
1219 ang_xy_L3 = angCR_xy_L3;
1220 ang_yz_L3 = angCR_yz_L3;
1222 if(gotit1==
false || gotit2==
false || gotit3==
false) cout <<
"TestTrack: error in intersection calculation. Intersection on L1 " << gotit1 <<
", on L2 " << gotit2 <<
", on L3 " << gotit3 << endl;
1226 track_xpoca_glo = xP; track_ypoca_glo = yP; track_zpoca_glo = zP;
1229 track_x1top_glo = xP1; track_y1top_glo = yP1; track_z1top_glo = zP1; track_phi1top_loc = phiP1; track_v1top_loc = vP1;
1230 track_x1bot_glo = xP2; track_y1bot_glo = yP2; track_z1bot_glo = zP2; track_phi1bot_loc = phiP2; track_v1bot_loc = vP2;
1232 track_x2top_glo = xP3; track_y2top_glo = yP3; track_z2top_glo = zP3; track_phi2top_loc = phiP3; track_v2top_loc = vP3;
1233 track_x2bot_glo = xP4; track_y2bot_glo = yP4; track_z2bot_glo = zP4; track_phi2bot_loc = phiP4; track_v2bot_loc = vP4;
1235 track_x3top_glo = xP5; track_y3top_glo = yP5; track_z3top_glo = zP5; track_phi3top_loc = phiP5; track_v3top_loc = vP5;
1236 track_x3bot_glo = xP6; track_y3bot_glo = yP6; track_z3bot_glo = zP6; track_phi3bot_loc = phiP6; track_v3bot_loc = vP6;
1246 return StatusCode::SUCCESS;