CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
DotsConnection Class Reference

#include <DotsConnection.h>

+ Inheritance diagram for DotsConnection:

Classes

struct  cell
 
struct  edge
 

Public Member Functions

 DotsConnection (const std::string &name, ISvcLocator *pSvcLocator)
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 
bool dotComp (dot *dot1, dot *dot2)
 
vector< const MdcDigi * > getMdcDigiVec (cell &aCell)
 
int numSharedDots (cell &a, cell &b)
 
bool sameCell (cell &a, cell &b)
 
bool forward (cell &a, cell &b)
 
bool isNeighbour (cell &a, cell &b)
 
void print (cell &aCell)
 
bool makeOrder (Line &l)
 
bool makeEdge (cell &a, cell &b, edge &e)
 
vector< const MdcDigi * > getMdcDigiVec (edge &aEdge)
 
vector< vector< int > > CellAutomaton (vector< int > &v_cellIdx, vector< cell > &v_cell, vector< edge > &v_edge)
 
void stateAutomaton (cell &aCell, vector< cell > &v_cell, vector< edge > &v_edge)
 
void nextCellFinding (cell &aCell, vector< cell > &v_cell, vector< edge > &v_edge, map< int, pair< double, double > > &setWireHitPos, map< int, int > &setWireEntry)
 
void makeDotCellEdge (vector< int > &vecWireIdx)
 
void longestPathFromCA (vector< int > &vecWireIdx, vector< vector< int > > &v_path)
 
void longestPathFromCA (set< int > &setWireIdx, vector< vector< int > > &v_path)
 

Public Attributes

int myNCycle
 
vector< int > myCellMaxState
 
map< int, dotmyMapDots
 
vector< cellmyVecCells
 
vector< int > myVecGoodCellIdx
 
vector< edgemyVecEdges
 

Detailed Description

Definition at line 208 of file DotsConnection.h.

Constructor & Destructor Documentation

◆ DotsConnection()

DotsConnection::DotsConnection ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 27 of file DotsConnection.cxx.

27 :
28 Algorithm(name, pSvcLocator)
29{
30 myMdcCalibFunSvc=NULL;
31
32 // Part 1: Declare the properties
33 //declareProperty("MyInt", m_myInt);
34 declareProperty("Ntuple", myNtProd=0);
35 declareProperty("driftTimeUpLimit", myDriftTimeUpLimit = 400);
36 declareProperty("MdcHitChi2Cut", myMdcHitChi2Cut = 100);
37 declareProperty("ChiCut_circle", myChiCut_circle=5);
38 declareProperty("NmaxDeact_circle", myNmaxDeact_circle=1);
39 declareProperty("ChiCut_helix", myChiCut_helix=5);
40 declareProperty("NmaxDeact_helix", myNmaxDeact_helix=1);
41 declareProperty("Debug", myDebug=0);
42 declareProperty("DebugNb", myDebugNb=0);
43 declareProperty("Chi2CutDiverge", myChi2CutDiverge=99999999);
44 //declareProperty("MCparID", myMCparID=1);//1: e, 2: mu, 3: pi, 4: K, 5: p
45 declareProperty("IniHelix", myIniHelix=1);
46 declareProperty("nBinTanl", myNBinTanl= 100);
47 declareProperty("nBinDz", myNBinDz = 100);
48 declareProperty("tanlRange", myTanlRange = 3.0);
49 declareProperty("dzRange", myDzRange = 50);
50 declareProperty("useWireCrossPoint", myUseWireCrossPoint = false);
51 declareProperty("wireCrossPointAvgMode", myWireCrossPointAvgMode = false);
52 declareProperty("WireCrossPointPersistent",myWireCrossPointPersistent = false);
53 declareProperty("IdealTracking",myRunIdealTracking= false);
54 declareProperty("UseInTrkerHits",myUseInTrkerHits = true);
55 declareProperty("TrkFollow",myRunTrkFollow= true);
56}

Member Function Documentation

◆ CellAutomaton()

vector< vector< int > > DotsConnection::CellAutomaton ( vector< int > & v_cellIdx,
vector< cell > & v_cell,
vector< edge > & v_edge )

Definition at line 7036 of file DotsConnection.cxx.

7037{
7038 bool debug=false; debug=true;
7039
7040 vector<int> v_rootCellIdx;
7041
7042 vector<vector<int> > v_path;
7043 if(v_cellIdx.size()==0) return v_path;
7044
7045 // --- initialize
7046 for(vector<int>::iterator it_cellIdx=v_cellIdx.begin(); it_cellIdx!=v_cellIdx.end(); it_cellIdx++) {
7047 cell& aCell=v_cell.at(*it_cellIdx);
7048 aCell.state=-1;
7049 aCell.color=0;
7050 if(aCell.set_inEdge.empty()) v_rootCellIdx.push_back(*it_cellIdx);
7051 }
7052 myNCycle=0;
7053 myCellMaxState.clear();
7054
7055 // --- state calculation with depth-first-visit
7056 for(vector<int>::iterator it_cellIdx=v_cellIdx.begin(); it_cellIdx!=v_cellIdx.end(); it_cellIdx++) {
7057 cell& aCell=v_cell.at(*it_cellIdx);
7058 //if(aCell.color==2) continue;
7059 if(aCell.color==0) {
7060 if(debug) cout<<setw(6)<<""<<"== start state calculation with cell "<<aCell.id<<endl;
7061 stateAutomaton(aCell, v_cell, v_edge);
7062 }
7063 }
7064 if(debug) cout<<setw(6)<<""<<"The graph has a cycle? "<<myNCycle<<endl;
7065 int maxState = 0;
7066 if(myCellMaxState.size()) {
7067 maxState = v_cell.at(myCellMaxState.at(0)).state;
7068 if(debug) cout<<setw(6)<<""<<"maximum state: "<<v_cell.at(myCellMaxState.at(0)).state<<", "<<myCellMaxState.size()<<" cells"<<endl;
7069 }
7070
7071 // --- form track segments (fit to circles)
7072 for(vector<int>::iterator it_cell_maxStat=myCellMaxState.begin(); it_cell_maxStat!=myCellMaxState.end(); it_cell_maxStat++)
7073 //for(int iRootCell=0; iRootCell<=v_rootCellIdx.size(); iRootCell++)
7074 {
7075 if(debug) cout<<setw(6)<<""<<"~~~~> to find a path: "<<endl;
7076 cell& aRootCell = v_cell.at(*it_cell_maxStat);
7077 //cell& aRootCell = v_cell.at(v_rootCellIdx.at(iRootCell));
7078
7079 map<int, pair<double,double> > setWireHitPos;
7080 map<int, int> setWireEntry;
7081 if(aRootCell.state==1) {
7082 for(vector<Line>::iterator it_line=aRootCell.vecFittedLine.begin(); it_line!=aRootCell.vecFittedLine.end(); it_line++) {
7083 double rho=(*it_line).rho;
7084 double theta=(*it_line).theta;
7085 vector<double>& vS=(*it_line).S;
7086 for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++) {
7087 int wireIdx = aRootCell.dots[i]->id;
7088 double s=vS.at(i);
7089 double x, y;
7090 getXY(rho,theta,s,x,y);
7091 map<int, int>::iterator it_entry; // setWireEntry;
7092 it_entry = setWireEntry.find(wireIdx);
7093 if(it_entry!=setWireEntry.end()) {
7094 it_entry->second++;
7095 map<int, pair<double,double> >::iterator it_pos=setWireHitPos.find(wireIdx);
7096 it_pos->second.first+=x;
7097 it_pos->second.second+=y;
7098 }
7099 else {
7100 setWireEntry[wireIdx]=1;
7101 pair<double,double> xy(x,y);
7102 setWireHitPos[wireIdx]=xy;
7103 }
7104 }
7105 }
7106 }
7107 else nextCellFinding(aRootCell, v_cell, v_edge, setWireHitPos, setWireEntry);
7108 cout<<setw(6)<<""<<"a path found with "<<setWireEntry.size()<<" dots: "; //<<endl;
7109 vector<int> aTrkPath;
7110 //vector< pair<double, double> > pos_hits;
7111 //vector<double> phi_LR;
7112 for(map<int, int>::iterator it_entry=setWireEntry.begin(); it_entry!=setWireEntry.end(); it_entry++) {
7113 int wireIdx = it_entry->first;
7114 aTrkPath.push_back(wireIdx);
7115 int layer = myMdcGeomSvc->Wire(wireIdx)->Layer();
7116 int wire = myMdcGeomSvc->Wire(wireIdx)->Cell();
7117 cout<<"("<<layer<<","<<wire<<") ";
7118 //map<int, pair<double,double> >::iterator it_pos=setWireHitPos.find(wireIdx);
7119 //it_pos->second.first/=it_entry->second;
7120 //it_pos->second.second/=it_entry->second;
7121 ////cout<<"hit ("<<layer<<","<<wire<<"), filled "<<it_entry->second<<" times, mean x,y="<<it_pos->second.first<<","<<it_pos->second.second<<endl;
7122 ////pos_hits.push_back(it_pos->second);
7123 //double phiLR=atan2(it_pos->second.second-0.1*myRLayer[layer]*sin(myWirePhi[layer][wire]),
7124 // it_pos->second.first -0.1*myRLayer[layer]*cos(myWirePhi[layer][wire]));
7125 //if(myMapMdcDigiDd[wireIdx]<0.15) phiLR=-9999.;
7126 //phi_LR.push_back(phiLR);
7127 }
7128 cout<<endl;
7129 v_path.push_back(aTrkPath);
7130 //vector<double> par_Taubin = myDotsHelixFitter.CircleFitByTaubin(pos_hits);
7131 //vector<double> par_circle = myDotsHelixFitter.circleParConversion(par_Taubin);
7132 //cout<<"fitted circle: dr="<<par_circle.at(0)<<", phi0="<<par_circle.at(1)<<", kappa="<<par_circle.at(2)<<endl;
7133 //struct trkCandi oneTrkCandi=getTrkCandi(aTrkPath);
7134 //int nDropHits;
7135 //cout<<"the path fitted to circle with initial LR : "<<endl;
7136 // ---------------------------- trkCandi, chiCut, useIniHelix,hitSel,setHitFitFlag, layerMin, layerMax, use_additional_points, usePhiAmbi, vPhiAmb
7137 //nDropHits = circleFitTaubin(oneTrkCandi, 5, false, 2, true, -1, 50, false, true, phi_LR);
7138 //nDropHits = circleFitTaubin(oneTrkCandi, 5, false, 2, true);
7139 }
7140
7141 return v_path;
7142}// CellAutomaton
Double_t x[10]
XmlRpcServer s
void stateAutomaton(cell &aCell, vector< cell > &v_cell, vector< edge > &v_edge)
void nextCellFinding(cell &aCell, vector< cell > &v_cell, vector< edge > &v_edge, map< int, pair< double, double > > &setWireHitPos, map< int, int > &setWireEntry)
vector< int > myCellMaxState
const MdcGeoWire *const Wire(unsigned id)

Referenced by longestPathFromCA().

◆ dotComp()

bool DotsConnection::dotComp ( dot * dot1,
dot * dot2 )
inline

Definition at line 215 of file DotsConnection.h.

215 {
216 bool less=false;
217 int layer1=myMdcGeomSvc->Wire(dot1->id)->Layer();
218 int layer2=myMdcGeomSvc->Wire(dot2->id)->Layer();
219 if(layer1<layer2) less=true;
220 else if(layer1==layer2) {
221 int wCell1=myMdcGeomSvc->Wire(dot1->id)->Cell();
222 int wCell2=myMdcGeomSvc->Wire(dot2->id)->Cell();
223 if(wCell1<wCell2) {
224 if(fabs(wCell1-wCell2)<0.5*myNWire[layer1]) less=true;
225 }
226 else if(fabs(wCell1-wCell2)>0.5*myNWire[layer1]) less=true;
227 }
228 return less;
229 };

Referenced by forward().

◆ execute()

StatusCode DotsConnection::execute ( )

Definition at line 293 of file DotsConnection.cxx.

293 {
294 cout.precision(4);
295
296 // Part 1: Get the messaging service, print where you are
297 MsgStream log(msgSvc(), name());
298 log << MSG::INFO << "DotsConnection execute()" << endreq;
299
300 // Part 2: Print out the different levels of messages
301 /*log << MSG::DEBUG << "A DEBUG message" << endreq;
302 log << MSG::INFO << "An INFO message" << endreq;
303 log << MSG::WARNING << "A WARNING message" << endreq;
304 log << MSG::ERROR << "An ERROR message" << endreq;
305 log << MSG::FATAL << "A FATAL error message" << endreq;
306 */
307
308 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
309 if (!eventHeader) {
310 log << MSG::WARNING << "Could not find Event Header" << endreq;
311 return StatusCode::FAILURE;
312 }
313 myRun = eventHeader->runNumber();
314 myEvt = eventHeader->eventNumber();
315 if(myDebug) {
316 cout<<endl<<"------------------------------ "<<endl;
317 cout<<"run:"<<myRun<<" , event: "<<myEvt<<endl;
318 }
319 if(myDebugNb==2) {
320 cout<<endl<<"------------------------------ "<<endl;
321 cout<<"DotsConnection: run:"<<myRun<<" , event: "<<myEvt<<endl;
322 }
323
324
325 //if(!(myEvt==240|| myEvt==1374 || myEvt==5084 || myEvt==9015) )
326 //if(myEvt!=6746)
327 // return StatusCode::SUCCESS;
328 //if(myRun==763)
329 //if(myEvt!=3946) return StatusCode::SUCCESS;// run for specific events
330 //if(myEvt!=3946) return StatusCode::SUCCESS;// run for specific events
331
332 //testDotsHelixFitterAllHits();
333 //testDotsHelixFitterPartHits();
334
335 // --- event start time
336 getEventStartTime();
337
338 // --- register RecMdcTrack/HitCol if not there
339 bool bookTrkCol = registerRecMdcTrack();
340 if(!bookTrkCol)
341 {
342 cout<<"DotsConnection::execute(): failed to register RecMdcTrackCol!"<<endl;
343 return StatusCode::FAILURE;
344 }
345
346 //if(myEvt!=2376) return StatusCode::SUCCESS;// run for specific events
347
348 // --- tracking starting with grouping neighboured digis
349 if(myRunTrkFollow) {
350 myVecTrkCandidates.clear();
351 //cout<<"test 3"<<endl;
352 //myMdcDigiGroup[503].GetWire()->GetNeighborIDType1();
353 //cout<<"test 3 done "<<endl;
354 vector<const MdcDigi*> vecDigi = getMdcDigiVec();
355 if(vecDigi.size()<2000) {
356 // fillMdcDigiBuildNeighbors(vecDigi,1,1); // expired
357 fillMdcDigiMap(vecDigi);
358 buildMdcDigiNeighbors(myMapMdcDigi, 3, 3);
359 findOuterEnds();
360 getMdcHitCluster();
361 getCgemClusters();
362 //matchCgemClusterMdcDigi();
363 processTrkCandi();
364 //processMdcHitCluter();
365 findCgemTrkSeg();
366 saveGoodTrkCandi();
367 }
368 else log << MSG::WARNING << "Too Many MDC digis: "<<vecDigi.size() << endreq;
369 }
370
371 // --- ideal tracking
372 if(myRunIdealTracking) {
373 getMcFinalChargedStates();
374 //myWatch_tot.Start(myWatch_reset);
375 associateDigisToMcParticles();
376 //myWatch_reset=kFALSE;
377 //myWatch_tot.Stop();
378 //cout<<"associateDigisToMcParticles used CPU time: "<<myWatch_tot.CpuTime()<<" s"<<endl;
379 //cout<<" finding "<<myWatch_finding.CpuTime()<<" s"<<endl;
380 //cout<<" fitting "<<myWatch_fitting.CpuTime()<<" s"<<endl;
381 }
382
383 return StatusCode::SUCCESS;
384}
IMessageSvc * msgSvc()
vector< const MdcDigi * > getMdcDigiVec(cell &aCell)

◆ finalize()

StatusCode DotsConnection::finalize ( )

Definition at line 388 of file DotsConnection.cxx.

388 {
389
390 // Part 1: Get the messaging service, print where you are
391 MsgStream log(msgSvc(), name());
392 log << MSG::INFO << "DotsConnection finalize()" << endreq;
393
394 if(myDebugNb==2) {
395 cout<<"DotsConnection finalize(): " << endl;
396 //cout<<" associateDigisToMcParticles used CPU time: "<<myWatch_tot.CpuTime()<<" s"<<endl;
397 //cout<<" finding "<<myWatch_finding.CpuTime()<<" s"<<endl;
398 //cout<<" fitting "<<myWatch_fitting.CpuTime()<<" s"<<endl;
399 }
400
401 return StatusCode::SUCCESS;
402}

◆ forward()

bool DotsConnection::forward ( cell & a,
cell & b )

Definition at line 6752 of file DotsConnection.cxx.

6753{
6754 bool forward=false;
6755 //set<int>::iterator it_dot_a = a.set_dotIdx.begin();
6756 //set<int>::iterator it_dot_b = b.set_dotIdx.begin();
6757 for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++)
6758 {
6759 //if(*it_dot_a == *it_dot_b)
6760 if(a.dots[i]->id == b.dots[i]->id)
6761 {
6762 //it_dot_a++; it_dot_b++;
6763 continue;
6764 }
6765 //else if(*it_dot_a < *it_dot_b)
6766 else if(dotComp(a.dots[i], b.dots[i]))
6767 {
6768 //int layer=myMdcGeomSvc->Wire(*it_dot_a)->Layer();
6769 //if(layer==myMdcGeomSvc->Wire(*it_dot_b)->Layer())
6770 //{// same layer
6771 // int Cell_a=myMdcGeomSvc->Wire(*it_dot_a)->Cell();
6772 // if(Cell_a+1!=myMdcGeomSvc->Wire(*it_dot_b)->Cell()) break;// at the boundary
6773 //}
6774 forward=true;
6775 break;
6776 }
6777 }
6778 return forward;
6779}
bool forward(cell &a, cell &b)
bool dotComp(dot *dot1, dot *dot2)

Referenced by forward().

◆ getMdcDigiVec() [1/2]

vector< const MdcDigi * > DotsConnection::getMdcDigiVec ( cell & aCell)

Definition at line 6701 of file DotsConnection.cxx.

6702{
6703 vector<const MdcDigi*> aMdcDigiVec;
6704 //set<int>::iterator it = aCell.set_dotIdx.begin();
6705 //for(; it != aCell.set_dotIdx.end(); it++)
6706 for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++)
6707 {
6708 //aMdcDigiVec.push_back(myMapMdcDigi[*it]);
6709 aMdcDigiVec.push_back(myMapMdcDigi[aCell.dots[i]->id]);
6710 }
6711 return aMdcDigiVec;
6712}

Referenced by execute(), getMdcDigiVec(), getMdcDigiVec(), makeDotCellEdge(), and makeEdge().

◆ getMdcDigiVec() [2/2]

vector< const MdcDigi * > DotsConnection::getMdcDigiVec ( edge & aEdge)

Definition at line 7024 of file DotsConnection.cxx.

7025{
7026 vector<const MdcDigi*> aMdcDigiVec;
7027 //set<int>::iterator it = aEdge.set_dotIdx.begin(); for(; it != aEdge.set_dotIdx.end(); it++)
7028 vector<dot*>::iterator it_dot=aEdge.dots.begin();
7029 for(; it_dot!=aEdge.dots.end(); it_dot++)
7030 {
7031 aMdcDigiVec.push_back(myMapMdcDigi[(*it_dot)->id]);
7032 }
7033 return aMdcDigiVec;
7034}

◆ initialize()

StatusCode DotsConnection::initialize ( )

Definition at line 60 of file DotsConnection.cxx.

60 {
61
62 //bool debug=false; //debug=true;
63
64 // Part 1: Get the messaging service, print where you are
65 MsgStream log(msgSvc(), name());
66 log << MSG::INFO << " DotsConnection initialize()" << endreq;
67
68 // Part 2: Print out the property values
69 // log << MSG::INFO << " MyInt = " << m_myInt << endreq;
70
71 // --- Get MdcGeomSvc ---
72 IMdcGeomSvc* imdcGeomSvc;
73 //StatusCode sc1 =Gaudi::svcLocator()->service("MdcGeomSvc", imdcGeomSvc);
74 StatusCode sc = service ("MdcGeomSvc", imdcGeomSvc);
75 myMdcGeomSvc = dynamic_cast<MdcGeomSvc*> (imdcGeomSvc);
76 if (sc.isFailure()) {
77 return( StatusCode::FAILURE);
78 }
79 int nWire = myMdcGeomSvc->getWireSize();
80 int nLayer= myMdcGeomSvc->getLayerSize();
81 int nSuperLayer= myMdcGeomSvc->getSuperLayerSize();
82 int nSeg= myMdcGeomSvc->getSegmentNo();
83 /*cout<<"nWire = "<<nWire
84 <<" nLayer="<<nLayer
85 <<" nSuperLayer="<<nSuperLayer
86 <<" nSeg="<<nSeg
87 <<endl;*/
88 int nCellTot=0;
89 int lastWireFlag=-1;
90 int iArea=0;
91 for(int i=0; i<nLayer; i++)
92 {
93 const MdcGeoLayer* aLayer = myMdcGeomSvc->Layer(i);
94 myNWire[i]=aLayer->NCell();
95 myRLayer[i]=aLayer->Radius();
96 //cout<<"layer "<<i<<", "<<aLayer->NCell()<<" cells, slant "<<aLayer->Slant()<<", R="<<aLayer->Radius()<<endl;
97
98 double nomShift = aLayer->nomShift();
99 if(nomShift>0) myWireFlag[i]=1;
100 else if(nomShift<0) myWireFlag[i]=-1;
101 else myWireFlag[i]=0;
102 if(i>0&&myWireFlag[i]!=lastWireFlag) {
103 iArea++;
104 }
105 myAreaLayer[i]=iArea;
106 lastWireFlag=myWireFlag[i];
107 //cout<<"layer "<<i<<" in area "<<iArea<<endl;
108
109 //nCellTot+=aLayer->NCell();
110 nCellTot+=myNWire[i];
111 for(int j=0; j<myNWire[i]; j++)
112 {
113 const MdcGeoWire* aWire = myMdcGeomSvc->Wire(i,j);
114 //cout<<" wire "<<j<<", BWpos ="<<aWire->Backward()
115 // <<", "<<aWire->BWirePos()
116 // <<", FWpos ="<<aWire->Forward()
117 // <<", "<<aWire->FWirePos()
118 // <<endl;
119 int wireidx = aWire->Id();
120 myMdcDigiGroup[wireidx].SetWire(aWire);// set wire pointer
121 //myMdcDigiGroupPnt[i][j]=&(myMdcDigiGroup[wireidx]);
122 myWirePhi[i][j]=aWire->Forward().phi();
123 //cout<<"Mdc layer "<<i<<", wire "<<j<<", phi="<<myWirePhi[i][j]<<endl;
124 //int layer = aWire->Layer();
125 //int cell = aWire->Cell();
126 //cout<<"wire idx "<<wireidx<<", WireLayer "<<layer<<", cell "<<cell<<", previous idx:"<<aWire->GetNeighborIDType1()<<endl;
127 int iInnerLayer = i-1;
128 if(iInnerLayer>=0) {
129 for(int k=0; k<myNWire[iInnerLayer]; k++)
130 {
131 int k_last = k-1;
132 if(k_last<0) k_last=myNWire[iInnerLayer]-1;
133 double dphi_last = dPhi(myWirePhi[iInnerLayer][k_last], myWirePhi[i][j]);
134 double dphi = dPhi(myWirePhi[iInnerLayer][k], myWirePhi[i][j]);
135 if(dphi_last<0&&dphi>0) {
136 myInnerWire[i][j][0]=k_last;
137 myInnerWire[i][j][1]=k;
138 //cout<<"k_last, k ="<<k_last<<", "<<k<<endl;
139 break;
140 }
141 }
142 }
143 }
144 }
145
146 //cout<<"test "<<endl;
147 //myMdcDigiGroup[503].GetWire()->GetNeighborIDType1();
148 //cout<<"test done "<<endl;
149
150 for(int i=0; i<nLayer; i++)
151 {
152 for(int j=0; j<myNWire[i]; j++)
153 {
154 int iOuterLayer = i+1;
155 if(iOuterLayer<nLayer) {
156 for(int k=0; k<myNWire[iOuterLayer]; k++)
157 {
158 int k_last = k-1;// index of previous wire
159 if(k_last<0) k_last=myNWire[iOuterLayer]-1;
160 double dphi_last = dPhi(myWirePhi[iOuterLayer][k_last], myWirePhi[i][j]);
161 double dphi = dPhi(myWirePhi[iOuterLayer][k], myWirePhi[i][j]);
162 if(dphi_last<0&&dphi>0) {
163 myOuterWire[i][j][0]=k_last;
164 myOuterWire[i][j][1]=k;
165 //cout<<"k_last, k ="<<k_last<<", "<<k<<endl;
166 //cout<<"phi="<<myWirePhi[i][j]<<", outer phi = "<<myWirePhi[iOuterLayer][k_last]<<", "<<myWirePhi[iOuterLayer][k]<<endl;
167 break;
168 }
169 }
170 }
171 }
172 }
173 cout<<"Total "<<nCellTot<<" cells"<<endl;
174 // ----------------------
175
176 // --- some specific tests
177 int layer=14;
178 int wire=50;
179 vector<int> innerWires_tem = myMdcGeomSvc->Wire(layer,wire)->GetNeighborIDType3();
180 int n_wire = innerWires_tem.size();
181 cout<<" Layer "<<layer<<", wire "<<wire<<", inner neighbours: "<<endl;
182 for(int i=0; i<n_wire; i++) {
183 int wireIdx = innerWires_tem[i];
184 layer=myMdcGeomSvc->Wire(wireIdx)->Layer();
185 wire=myMdcGeomSvc->Wire(wireIdx)->Cell();
186 cout<<"(L"<<layer<<", W"<<wire<<") ";
187 }
188 cout<<endl;
189
190
191 ICgemGeomSvc* ISvc;
192 StatusCode Cgem_sc = service ("CgemGeomSvc", ISvc);
193 if(Cgem_sc.isSuccess()) myCgemGeomSvc=dynamic_cast<CgemGeomSvc *>(ISvc);
194 else cout<<"DotsConnection::initialize(): can not get CgemGeomSvc"<<endl;
195
196 // --- Initialize RawDataProviderSvc ---
197 IRawDataProviderSvc* irawDataProviderSvc;
198 sc = service ("RawDataProviderSvc", irawDataProviderSvc);
199 myRawDataProviderSvc = dynamic_cast<RawDataProviderSvc*> (irawDataProviderSvc);
200 if ( sc.isFailure() ){
201 log << MSG::FATAL << name()<<" Could not load RawDataProviderSvc!" << endreq;
202 return StatusCode::FAILURE;
203 }
204
205 // --- MdcCalibFunSvc ---
206 IMdcCalibFunSvc* imdcCalibSvc;
207 sc = service("MdcCalibFunSvc", imdcCalibSvc);
208 if ( sc.isSuccess() ){
209 myMdcCalibFunSvc = dynamic_cast<MdcCalibFunSvc*>(imdcCalibSvc);
210 }
211 else {
212 cout<<"DotsConnection::initialize(): can not get MdcCalibFunSvc"<<endl;
213 }
214 // --- initialize DotsHelixFitter ---
215 myDotsHelixFitter.initialize();
216 myDotsHelixFitter.setChi2Diverge(myChi2CutDiverge);
217 myDotsHelixFitter.setModeWireCrossPointPersistent(myWireCrossPointPersistent);
218 if(myNtProd&1)
219 {
220 NTuplePtr nt_ptr(ntupleSvc(),"TestDotsHelixFitter/trkPar");
221 if( nt_ptr ) myNtHelixFitter = nt_ptr;
222 else
223 {
224 myNtHelixFitter = ntupleSvc()->book("TestDotsHelixFitter/trkPar",CLID_ColumnWiseTuple,"trkPar");
225 if( myNtHelixFitter ) {
226 myNtHelixFitter->addItem ("run", myRUN);
227 myNtHelixFitter->addItem ("evt", myEVT);
228 myNtHelixFitter->addItem ("pid", myPID);
229 myNtHelixFitter->addItem ("Npar", myNPar, 0,5);
230 myNtHelixFitter->addIndexedItem("HelixMC", myNPar, myArrayHelixMC);
231 myNtHelixFitter->addIndexedItem("HelixFitted", myNPar, myArrayHelixFitted);
232 myNtHelixFitter->addItem ("NhitCircle", myNHitsCircle, 0,100);
233 myNtHelixFitter->addIndexedItem("LayerHitsCircle", myNHitsCircle, myLayerHitsCircle);
234 myNtHelixFitter->addIndexedItem("ChiHitsCircle", myNHitsCircle, myChiHitsCircle);
235 myNtHelixFitter->addItem ("Nhit", myNHits, 0,100);
236 myNtHelixFitter->addIndexedItem("LayerHits", myNHits, myLayerHits);
237 myNtHelixFitter->addIndexedItem("ChiHits", myNHits, myChiHits);
238 myNtHelixFitter->addItem ("NXhit", myNXHits, 0,100);
239 myNtHelixFitter->addItem ("NVhit", myNVHits, 0,100);
240 myNtHelixFitter->addItem ("NXCluster", myNXCluster, 0,100);
241 myNtHelixFitter->addItem ("NVCluster", myNVCluster, 0,100);
242 myNtHelixFitter->addItem ("TrkIdBest", myTrkIdBest);
243 myNtHelixFitter->addItem ("NHitsBestTrk", myNHitsBestTrk);
244 myNtHelixFitter->addItem ("NSameHitsBestTrk", myNSameHitsBestTrk);
245 //cout<<"myNtHelixFitter added !"<<endl;
246 }
247 }
248 }
249
250 if(myNtProd&2 || myNtProd&4) {
251 NTuplePtr nt_ptr(ntupleSvc(),"TestDotsHelixFitter/lineTrkSegHough");
252 if( nt_ptr ) myNtTrkSeg = nt_ptr;
253 else
254 {
255 myNtTrkSeg = ntupleSvc()->book("TestDotsHelixFitter/lineTrkSegHough",CLID_ColumnWiseTuple,"hough");
256 if( myNtTrkSeg ) {
257 myNtTrkSeg->addItem ("run", myRUN);
258 myNtTrkSeg->addItem ("evt", myEVT);
259 myNtTrkSeg->addItem ("nhits", myNt_nhits, 0,100);
260 myNtTrkSeg->addIndexedItem("layer", myNt_nhits, myNt_layer);
261 myNtTrkSeg->addIndexedItem("wire", myNt_nhits, myNt_wire);
262 myNtTrkSeg->addIndexedItem("xhit", myNt_nhits, myNt_Xhit);
263 myNtTrkSeg->addIndexedItem("yhit", myNt_nhits, myNt_Yhit);
264 myNtTrkSeg->addIndexedItem("DDhit", myNt_nhits, myNt_DDhit);
265 myNtTrkSeg->addItem ("rho", myNt_rho);
266 myNtTrkSeg->addItem ("theta", myNt_theta);
267 }
268 }
269 }
270
271 // --- get MdcUtilitySvc
272 /*
273 sc = service("MdcUtilitySvc", myMdcUtilitySvc);
274 if( sc != StatusCode::SUCCESS ){
275 log << MSG::FATAL << "can not use MdcUtilitySvc" << endreq;
276 }*/
277
278 //myWatch_reset=kTRUE;
279
280 cout<<"DotsConnection::initialize() myIniHelix = "<<myIniHelix<<endl;
281
282 // --- Hough maps
283 myRoughTanlDzMap = TH2D("roughTanlDzMap","roughTanlDzMap",myNBinTanl,-1.*myTanlRange,myTanlRange,myNBinDz,-1.*myDzRange,myDzRange);
284
285 myRhoRange=78;// in cm
286 myThetaRange=acos(-1); // pi
287 myRoughRhoThetaMap=TH2D("roughRhoThetaMap","roughRhoThetaMap",100,0,myThetaRange,100,-1.*myRhoRange,myRhoRange);
288
289 return StatusCode::SUCCESS;
290}
INTupleSvc * ntupleSvc()
void setChi2Diverge(double cut=1000000)
void setModeWireCrossPointPersistent(bool mode)
void SetWire(const MdcGeoWire *aWire)
vector< int > GetNeighborIDType3(void) const
const MdcGeoLayer *const Layer(unsigned id)

◆ isNeighbour()

bool DotsConnection::isNeighbour ( cell & a,
cell & b )

Definition at line 6781 of file DotsConnection.cxx.

6782{
6783 bool twoDotsShare=false;
6784
6785 //if(a.dots[0]->id==b.dots[1]->id) {
6786 // if(a.dots[1]->id==b.dots[0]->id && a.dots[2]->id!=b.dots[2]->id) twoDotsShare=true;
6787 // else if(a.dots[2]->id==b.dots[0]->id && a.dots[1]->id!=b.dots[2]->id) twoDotsShare=true;
6788 //}
6789 //else if(a.dots[0]->id==b.dots[2]->id) {
6790 // if(a.dots[1]->id==b.dots[0]->id && a.dots[2]->id!=b.dots[1]->id) twoDotsShare=true;
6791 // else if(a.dots[2]->id==b.dots[0]->id && a.dots[1]->id!=b.dots[1]->id) twoDotsShare=true;
6792 //}
6793
6794 if(a.dots[0]->id!=b.dots[2]->id && ( (a.dots[1]->id==b.dots[0]->id&&a.dots[2]->id==b.dots[1]->id )||( a.dots[1]->id==b.dots[1]->id&&a.dots[2]->id==b.dots[0]->id)) ) twoDotsShare=true;
6795 else if(a.dots[2]->id!=b.dots[0]->id && ( (a.dots[0]->id==b.dots[1]->id&&a.dots[1]->id==b.dots[2]->id )||( a.dots[0]->id==b.dots[2]->id&&a.dots[1]->id==b.dots[1]->id)) ) twoDotsShare=true;
6796
6797 return twoDotsShare;
6798}

Referenced by makeDotCellEdge().

◆ longestPathFromCA() [1/2]

void DotsConnection::longestPathFromCA ( set< int > & setWireIdx,
vector< vector< int > > & v_path )

Definition at line 7446 of file DotsConnection.cxx.

7447{
7448 vector<int> vecWireIdx(setWireIdx.begin(),setWireIdx.end());
7449 longestPathFromCA(vecWireIdx, v_path);
7450}
void longestPathFromCA(vector< int > &vecWireIdx, vector< vector< int > > &v_path)

◆ longestPathFromCA() [2/2]

void DotsConnection::longestPathFromCA ( vector< int > & vecWireIdx,
vector< vector< int > > & v_path )

Definition at line 7428 of file DotsConnection.cxx.

7429{
7430 makeDotCellEdge(vecWireIdx);
7431
7433
7434 int n_path = v_path.size();
7435 //for(int i_path=0; i_path<n_path; i_path++) {
7436 // vector<int>& aPath = v_path.at(i_path);
7437 //}
7438 if(n_path>0) {
7439 //path = v_path.at(0);
7440 //if(n_path>1)
7441 cout<<setw(6)<<""<<n_path<<" longest paths found"<<endl;
7442 }
7443 else cout<<setw(6)<<""<<"no path found"<<endl;
7444}
vector< int > myVecGoodCellIdx
vector< cell > myVecCells
vector< edge > myVecEdges
void makeDotCellEdge(vector< int > &vecWireIdx)
vector< vector< int > > CellAutomaton(vector< int > &v_cellIdx, vector< cell > &v_cell, vector< edge > &v_edge)

Referenced by longestPathFromCA().

◆ makeDotCellEdge()

void DotsConnection::makeDotCellEdge ( vector< int > & vecWireIdx)

Definition at line 7231 of file DotsConnection.cxx.

7232{
7233 bool debug=false; //debug=true;
7234 myMapDots.clear();
7235 myVecCells.clear();
7236 myVecGoodCellIdx.clear();
7237 myVecEdges.clear();
7238
7239 // --- make dots and put into myMapDots
7240 int nHit=vecWireIdx.size();
7241 for(int i=0; i<nHit; i++) {
7242 int wireIdx=vecWireIdx.at(i);
7243 dot aDot;
7244 aDot.detector = dot::MDC;
7245 aDot.digi.mdcDigi=myMapMdcDigi[wireIdx];
7246 aDot.id=wireIdx;
7247 aDot.cluId=-1;
7248 myMapDots[wireIdx]=aDot;
7249 }
7250
7251 // --- make Cells, fill myVecCells, myVecGoodCellIdx, associate cells to wireMids
7252 map<int, dot>::iterator it_mapDots = myMapDots.begin();
7253 for(; it_mapDots!=myMapDots.end(); it_mapDots++)
7254 {
7255 int wireIdx=it_mapDots->first;
7256 int layer= myMdcGeomSvc->Wire(wireIdx)->Layer(); //myWireFlag[layer]
7257 int Cell = myMdcGeomSvc->Wire(wireIdx)->Cell();
7258
7259 //vector<int> vec_neib = myMdcDigiGroup[wireIdx].GetNeiborHits();// get all neighbours, but causes cell duplication
7260 vector<int> vec_neib = myMdcDigiGroup[wireIdx].GetNeiborHits(1);// get all neighbours and nbs nb, but causes cell duplication
7261 for(vector<int>::iterator it_nb1=vec_neib.begin(); it_nb1!=vec_neib.end(); it_nb1++)
7262 {
7263 // --- get a neighbour
7264 int wireIdx1=*it_nb1;
7265 if(myMapDots.find(wireIdx1)==myMapDots.end()) continue;// good dot
7266 int layer1= myMdcGeomSvc->Wire(wireIdx1)->Layer();
7267 if(myWireFlag[layer1]!=myWireFlag[layer]) continue;// same stereo angle
7268 int Cell1 = myMdcGeomSvc->Wire(wireIdx1)->Cell();
7269
7270 // --- get another neighbour
7271 vector<int>::iterator it_nb2=it_nb1; it_nb2++;
7272 while(true) {// loops
7273 if(it_nb2==vec_neib.end()) break; // end of loops
7274 int wireIdx2=*it_nb2;
7275 if(myMapDots.find(wireIdx2)==myMapDots.end()) {it_nb2++; continue;}// good dot
7276 int layer2= myMdcGeomSvc->Wire(wireIdx2)->Layer();
7277 if(myWireFlag[layer2]!=myWireFlag[layer]) {it_nb2++; continue;}// same stereo angle
7278 int Cell2 = myMdcGeomSvc->Wire(wireIdx2)->Cell();
7279 if(debug) cout<<" === try cell (id, L, W): "
7280 <<"("<<setw(5)<<wireIdx1<<","<<setw(3)<<layer1<<","<<setw(3)<<Cell1<<") "
7281 <<"("<<setw(5)<<wireIdx<<","<<setw(3)<<layer<<","<<setw(3)<<Cell<<") "
7282 <<"("<<setw(5)<<wireIdx2<<","<<setw(3)<<layer2<<","<<setw(3)<<Cell2<<") "
7283 <<endl;
7284 // --- create a cell
7285 cell aCell;
7286 aCell.dots[0]=&(myMapDots[wireIdx1]);
7287 aCell.dots[1]=&(myMapDots[wireIdx]);
7288 aCell.dots[2]=&(myMapDots[wireIdx2]);
7289 // --- check if the cell has already exist
7290 int wireMid = aCell.dots[1]->id;// wire index of the middle hit
7291 int nCell_wireMid = myMapDots[wireMid].vecCellIdx.size();
7292 bool cellExist=false;
7293 if(debug) cout<<" wireMid="<<wireMid<<" with "<<nCell_wireMid<<" cells"<<endl;
7294 for(int iCell=0; iCell<nCell_wireMid; iCell++) {
7295 if(debug) cout<<" i-cell "<<iCell<<endl;
7296 if(sameCell(aCell, myVecCells.at(myMapDots[wireMid].vecCellIdx[iCell]))) { cellExist=true; break; }
7297 }
7298 if(cellExist) {
7299 if(debug) cout<<" the cell exists"<<endl;
7300 it_nb2++; continue;
7301 }// drop a duplicated cell
7302 else if(debug) cout<<" the cell is new"<<endl;
7303 // --- a new cell found
7304 aCell.id=myVecCells.size();
7305 myMapDots.find(wireMid)->second.vecCellIdx.push_back(myVecCells.size());// associate the cell to wireMid
7306 myVecCells.push_back(aCell);
7307 myVecCells.back().idInGood=-1;
7308 // --- fit the cell
7309 vector<const MdcDigi*> aVecMdcDigi=getMdcDigiVec(aCell);
7310 vector<double> vRho; vector<double> vTheta; vector<vector<int> > vvLR; vector<vector<double> > vvS;
7311 bool hasGdLine = LineFit_TLS(aVecMdcDigi, vRho,vTheta,vvLR,vvS);
7312 if(hasGdLine) {
7313 int n_rho = vRho.size();
7314 if(debug) cout<<" the cell is good with N_lines="<<setw(2)<<n_rho<<endl;
7315 for(int i_line=0; i_line<n_rho; i_line++) {
7316 Line aLine;
7317 aLine.rho=vRho[i_line];
7318 aLine.theta=vTheta[i_line];
7319 aLine.LR=vvLR[i_line];
7320 aLine.S=vvS[i_line];
7321 if(debug) cout<<" S={"
7322 <<setw(5)<<aLine.S[0]<<" "
7323 <<setw(5)<<aLine.S[1]<<" "
7324 <<setw(5)<<aLine.S[2]<<"}"
7325 <<endl;
7326 // --- only keep the line fit if the middle hit has a middle S
7327 if(aLine.S[0]<aLine.S[1]&&aLine.S[2]<aLine.S[1]) {
7328 if(debug) cout<<" line "<<i_line<<" has a min S_middle"<<endl;
7329 continue;
7330 }
7331 if(aLine.S[0]>aLine.S[1]&&aLine.S[2]>aLine.S[1]) {
7332 if(debug) cout<<" line "<<i_line<<" has a max S_middle"<<endl;
7333 continue;
7334 }
7335 //if(aLine.S[0]*aLine.S[2]<0) {
7336 // if(debug) cout<<" line "<<i_line<<" has different sign for S"<<endl;
7337 // continue;
7338 //}
7339 if(fabs(aLine.S[0])<fabs(aLine.S[2])) {
7340 aLine.order.push_back(0);
7341 aLine.order.push_back(1);
7342 aLine.order.push_back(2);
7343 }
7344 else {
7345 aLine.order.push_back(2);
7346 aLine.order.push_back(1);
7347 aLine.order.push_back(0);
7348 }
7349 if(debug) cout<<" line "<<i_line<<" hits' order "<<aLine.order[0]<<" "<<aLine.order[1]<<" "<<aLine.order[2]<<endl;
7350
7351 // --- save the good fitted line to the cell
7352 myVecCells.back().vecFittedLine.push_back(aLine);
7353 }
7354 if(myVecCells.back().vecFittedLine.size()>0) {
7355 if(debug) cout<<"Good Cell "<<myVecGoodCellIdx.size()<<endl;
7356 cout<<setw(6)<<""<<"# Good Cell "<<myVecCells.back().id<<endl;
7357 myVecCells.back().idInGood=myVecGoodCellIdx.size();
7358 myMapDots[wireMid].vecGoodCellIdx[0].push_back(myVecGoodCellIdx.size());// associate the good cell to wireMid
7359 myVecGoodCellIdx.push_back(myVecCells.size()-1);// good cells
7360 }
7361 }
7362 it_nb2++;
7363 }// loop nb2
7364 }// loop nb1
7365 }// loop the map of dots to make cells
7366
7367 // --- make edges
7368 debug=true;
7369 vector<int>::iterator i1_goodCell = myVecGoodCellIdx.begin();
7370 vector<int>::iterator i2_goodCell;
7371 int iGdCell=0;
7372 for(; i1_goodCell!=myVecGoodCellIdx.end(); i1_goodCell++, iGdCell++) {// ---> loop good cells
7373 // --- set Cells' id, state, weight
7374 cell& cell_a = myVecCells.at(*i1_goodCell);
7375 for(int idot=0; idot<3; idot++) {// loop the two end-dots of the good cell (non-middle)
7376 int ivc=0;
7377 vector<int>& vCellIdx=myMapDots[cell_a.dots[idot]->id].vecGoodCellIdx[ivc];
7378 i2_goodCell=vCellIdx.begin();
7379 for(; i2_goodCell!=vCellIdx.end(); i2_goodCell++) {// loop another good cells
7380 int iGdCell2=*i2_goodCell;
7381 if(iGdCell2<iGdCell) continue;//reduce number of comparisons
7382 cell& cell_b = myVecCells.at(myVecGoodCellIdx.at(*i2_goodCell));
7383 if(debug) {
7384 cout<<" ===> compare two cells: "<<endl;
7385 cout<<setw(6)<<""<<"Good cell "<<iGdCell<<", "; print(cell_a);
7386 cout<<setw(6)<<""<<"Good cell "<<*i2_goodCell<<", "; print(cell_b);
7387 }
7388 //if( (cell_b.dots[0]->id==cell_a.dots[1]->id&&cell_b.dots[2]->id!=cell_a.dots[2-idot]->id) || (cell_b.dots[2]->id==cell_a.dots[1]->id&&cell_b.dots[0]->id!=cell_a.dots[2-idot]->id) )
7389 if(isNeighbour(cell_a,cell_b))
7390 {
7391 if(debug) cout<<setw(6)<<""<<"neighbour with two shared dots in the middle"<<endl;
7392 cell* cell_bkd;
7393 cell* cell_fwd;
7394 int idx_cell_fwd;
7395 if(cell_a.dots[1]->id>cell_b.dots[1]->id)
7396 {
7397 cell_bkd = &cell_b;
7398 cell_fwd = &cell_a;
7399 idx_cell_fwd = *i1_goodCell;
7400 if(debug) cout<<setw(6)<<""<<"two cells' order reversed"<<endl;
7401 }
7402 else {
7403 cell_bkd = &cell_a;
7404 cell_fwd = &cell_b;
7405 idx_cell_fwd = myVecGoodCellIdx.at(*i2_goodCell);
7406 }
7407 if(cell_bkd->set_fwdCell.find(idx_cell_fwd)==cell_bkd->set_fwdCell.end()) {// a new forward cell
7408 cell_bkd->set_fwdCell.insert(idx_cell_fwd);
7409 if(debug) cout<<setw(6)<<""<<"cell "<<cell_fwd->id<<" tagged as a new forward cell of cell "<<cell_bkd->id<<endl;
7410 edge aNewEdge;
7411 if(makeEdge(cell_a,cell_b,aNewEdge)) {
7412 cell& cell_first = myVecCells.at(aNewEdge.twoCells.first);
7413 cell_first.set_outEdge.insert(myVecEdges.size());
7414 cell& cell_second = myVecCells.at(aNewEdge.twoCells.second);
7415 cell_second.set_inEdge.insert(myVecEdges.size());
7416 aNewEdge.id=myVecEdges.size();
7417 myVecEdges.push_back(aNewEdge);
7418 if(debug) cout<<setw(6)<<""<<"a good out edge added to cell "<<aNewEdge.twoCells.first<<" and "<<aNewEdge.twoCells.second<<endl;
7419 }
7420 }
7421 }
7422 }
7423 }// loop the two end-dots of the good cell (non-middle)
7424 }// <--- loop good cells
7425
7426}// makeDotCellEdge(vector<int>& vecWireIdx)
void print(cell &aCell)
bool makeEdge(cell &a, cell &b, edge &e)
bool sameCell(cell &a, cell &b)
map< int, dot > myMapDots
bool isNeighbour(cell &a, cell &b)
vector< int > GetNeiborHits()
vector< double > S
vector< int > LR
double rho
vector< int > order
double theta
DigiPtr digi
DetectorEnum detector
int cluId
const MdcDigi * mdcDigi

Referenced by longestPathFromCA().

◆ makeEdge()

bool DotsConnection::makeEdge ( cell & a,
cell & b,
edge & e )

Definition at line 6816 of file DotsConnection.cxx.

6817{
6818 // --- get the set of shared dots
6819 int a_shared[NUMBER_OF_DOTS_PER_CELL]={0,0,0};
6820 int b_shared[NUMBER_OF_DOTS_PER_CELL]={0,0,0};
6821 int n_shared=0;
6822 set<int> comDots;
6823 vector<int> viDotShared_a;
6824 vector<int> viDotShared_b;
6825 //set<int>& dots_a = a.set_dotIdx;
6826 //set<int>& dots_b = b.set_dotIdx;
6827 //std::set_intersection(dots_a.begin(), dots_a.end(), dots_b.begin(), dots_b.end(),
6828 // std::inserter(comDots, comDots.begin()));
6829 for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++) {
6830 int id_a=a.dots[i]->id;
6831 for(int j=0; j<NUMBER_OF_DOTS_PER_CELL; j++) {
6832 int id_b=b.dots[j]->id;
6833 if(id_a==id_b) {
6834 comDots.insert(id_a);
6835 viDotShared_a.push_back(i);
6836 viDotShared_b.push_back(j);
6837 //e.set_dotIdx.insert(id_a);
6838 e.dots.push_back(a.dots[i]);// fill the common hits as the 1st, 2ed hits
6839 a_shared[i]=1;
6840 b_shared[j]=1;
6841 n_shared++;
6842 }
6843 }
6844 }
6845 if(n_shared!=2) {
6846 cout<<setw(6)<<""<<"cannot make edge due to n_shared="<<n_shared<<endl;
6847 return false;
6848 }
6849
6850 // --- get the indices of shared dots
6851 //set<int>::iterator it_dots_a=dots_a.begin();
6852 //for(int i=0; it_dots_a!=dots_a.end(); it_dots_a++, i++) if(comDots.find(*it_dots_a)!=comDots.end()) viDotShared_a.push_back(i);
6853 //for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++) if(comDots.find(a.dots[i]->id)!=comDots.end()) viDotShared_a.push_back(i);
6854
6855 //for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++) if(comDots.find(b.dots[i]->id)!=comDots.end()) viDotShared_b.push_back(i);
6856 //set<int>::iterator it_dots_b=dots_b.begin();
6857 //for(int i=0; it_dots_b!=dots_b.end(); it_dots_b++, i++) if(comDots.find(*it_dots_b)!=comDots.end()) viDotShared_b.push_back(i);
6858
6859 // --- compare rho, theta
6860 double diff_theta_min=9999.;
6861 double diff_rho_min =9999.;
6862 //vector<Line>::iterator itL_a_match = a.vecFittedLine.end();
6863 //vector<Line>::iterator itL_b_match = b.vecFittedLine.end();
6864 int iL_a_match(-1), iL_b_match(-1);
6865 int nReverse_b_match=0;
6866 vector<Line>::iterator itL_a=a.vecFittedLine.begin();
6867 for(int iL_a=0; itL_a!=a.vecFittedLine.end(); itL_a++, iL_a++) {
6868 double rho_a = (*itL_a).rho;
6869 double theta_a = (*itL_a).theta;
6870 vector<Line>::iterator itL_b=b.vecFittedLine.begin();
6871 for(int iL_b=0; itL_b!=b.vecFittedLine.end(); itL_b++, iL_b++) {
6872 double rho_b = (*itL_b).rho;
6873 double theta_b = (*itL_b).theta;
6874 int nReverse=0;
6875 while( fabs(theta_b-acos(-1.)-theta_a) < fabs(theta_b-theta_a) ) {
6876 theta_b-=acos(-1.);
6877 rho_b*=-1;
6878 nReverse++;
6879 }
6880 while( fabs(theta_b+acos(-1.)-theta_a) < fabs(theta_b-theta_a) ) {
6881 theta_b+=acos(-1.);
6882 rho_b*=-1;
6883 nReverse++;
6884 }
6885 if(diff_theta_min>fabs(theta_b-theta_a)) {
6886 diff_theta_min=fabs(theta_b-theta_a);
6887 diff_rho_min = fabs(rho_b-rho_a);
6888 //itL_a_match=itL_a; itL_b_match=itL_b;
6889 iL_a_match=iL_a; iL_b_match=iL_b;
6890 nReverse_b_match=nReverse;
6891 }
6892 }// loop lines of cell b
6893 }// loop lines of cell a
6894 if(diff_theta_min>0.1) // || diff_rho_min>1.0)
6895 {
6896 //cout<<"theta or rho unmatched!"<<endl;
6897 cout<<setw(6)<<""<<"theta unmatched!"<<endl;
6898 return false;
6899 }
6900 else cout<<setw(6)<<""<<"theta matched!"<<endl;
6901
6902 // --- compare LR of shared dots
6903 vector<int>& LR_a=a.vecFittedLine.at(iL_a_match).LR;
6904 vector<int>& LR_b=b.vecFittedLine.at(iL_b_match).LR;
6905 int nShared=viDotShared_a.size();
6906 cout<<setw(6)<<""<<"shared LR in a: (";
6907 for(int i=0; i<nShared; i++) cout<<setw(3)<<LR_a.at(viDotShared_a.at(i));
6908 cout<<")"<<endl;
6909 int reverse=1; if(nReverse_b_match%2!=0) {reverse=-1; cout<<setw(6)<<""<<"LR reversed for b"<<endl;}
6910 cout<<setw(6)<<""<<"shared LR in b: (";
6911 for(int i=0; i<nShared; i++) cout<<setw(3)<<reverse*LR_b.at(viDotShared_b.at(i));
6912 cout<<")"<<endl;
6913 bool LR_match=true;
6914 const double shortDD=0.16;// to be optimized
6915 for(int i=0; i<nShared; i++) {
6916 if( reverse*LR_b.at(viDotShared_b.at(i)) != LR_a.at(viDotShared_a.at(i)) ) {
6917 if(myMapMdcDigiDd[b.dots[viDotShared_b.at(i)]->id]<shortDD) continue;// to be optimized
6918 LR_match=false;
6919 break;
6920 }
6921 }
6922 if(LR_match) cout<<setw(6)<<""<<"LR matched"<<endl;
6923 else {
6924 cout<<setw(6)<<""<<"LR unmatched"<<endl;
6925 return false;
6926 }
6927
6928 // --- fill mapWidxLR and uncommon dots of the edge
6929 map<int, int> mapWidxLR;
6930 vector<int>::iterator it =LR_a.begin();
6931 int idot_a_uncom=-1;
6932 for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++, it++) {
6933 mapWidxLR[a.dots[i]->id]=*it;
6934 if(a_shared[i]==0)
6935 {
6936 e.dots.push_back(a.dots[i]);// fill the uncommon hit of cell a as the 3rd hit
6937 idot_a_uncom=i;
6938 }
6939 }
6940 it =LR_b.begin();
6941 int idot_b_uncom=-1;
6942 for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++, it++) {
6943 mapWidxLR[b.dots[i]->id]=(*it)*reverse;
6944 if(b_shared[i]==0)
6945 {
6946 e.dots.push_back(b.dots[i]);// fill the uncommon hit of cell b as the 4th hit
6947 idot_b_uncom=i;
6948 }
6949 }
6950
6951 // --- get all dots
6952 //std::set_union(dots_a.begin(), dots_a.end(), dots_b.begin(), dots_b.end(),
6953 // std::inserter(e.set_dotIdx, e.set_dotIdx.begin()) );
6954 //set<int>::iterator it_dot = e.set_dotIdx.begin();
6955 //for(; it_dot!=e.set_dotIdx.end(); it_dot++) {
6956 // int idx = *it_dot;
6957 // if(comDots.find(idx)!=comDots.end()) e.vDotStatus.push_back(edge::Common);
6958 // else {
6959 // if(dots_a.find(idx)!=dots_a.end()) e.vDotStatus.push_back(edge::Prev);
6960 // else if(dots_b.find(idx)!=dots_b.end()) e.vDotStatus.push_back(edge::Next);
6961 // }
6962 //}
6963 vector<int> LR_ini;
6964 vector<dot*>::iterator it_dot=e.dots.begin();
6965 for(; it_dot!=e.dots.end(); it_dot++) {
6966 int idx = (*it_dot)->id;
6967 int LR_i=0;
6968 if(myMapMdcDigiDd[idx]>=shortDD) LR_i=mapWidxLR[idx];
6969 LR_ini.push_back(LR_i);
6970 }
6971
6972 // --- fit
6973 //double rho_ini =0.5*(a.vecFittedLine.at(iL_a_match).rho +b.vecFittedLine.at(iL_b_match).rho);
6974 //double theta_ini=0.5*(a.vecFittedLine.at(iL_a_match).theta+b.vecFittedLine.at(iL_b_match).theta);
6975 double rho_ini = a.vecFittedLine.at(iL_a_match).rho ;
6976 double theta_ini = a.vecFittedLine.at(iL_a_match).theta;
6977 vector<double> vRho; vector<double> vTheta; vector<vector<int> > vvLR; vector<vector<double> > vvS;
6978 vector<const MdcDigi*> aVecMdcDigi=getMdcDigiVec(e);
6979 bool hasGdLine = LineFit_TLS(aVecMdcDigi, vRho,vTheta,vvLR,vvS,true,rho_ini,theta_ini,LR_ini);
6980 if(!hasGdLine) {
6981 cout<<setw(6)<<""<<" no good line fit for the edge"<<endl;
6982 return false;
6983 }
6984
6985 // --- make an edge
6986 e.twoCells.first=a.id;
6987 e.twoCells.second=b.id;
6988 e.twoLines.first=iL_a_match;
6989 e.twoLines.second=iL_b_match;
6990 int n_rho = vRho.size();
6991 cout<<setw(6)<<""<<"an good edge with "<<n_rho<<" fitted lines"<<endl;
6992 for(int i_line=0; i_line<n_rho; i_line++) {
6993 Line aLine;
6994 aLine.rho=vRho[i_line];
6995 aLine.theta=vTheta[i_line];
6996 aLine.LR=vvLR[i_line];
6997 aLine.S=vvS[i_line];
6998 // --- save the good fitted line to the edge
6999 if(makeOrder(aLine))
7000 {
7001 if(aLine.order.front()>1&&aLine.order.back()>1)
7002 {
7003 e.vecFittedLine.push_back(aLine);
7004 cout<<setw(6)<<""<<"good S order : ";
7005 for(int i=0; i<aLine.order.size(); i++) cout<<setw(2)<<aLine.order.at(i);
7006 cout<<endl;
7007 if(aLine.order.front()==3) { // uncommon hit of cell b
7008 e.twoCells.first=b.id;
7009 e.twoCells.second=a.id;
7010 e.twoLines.first=iL_b_match;
7011 e.twoLines.second=iL_a_match;
7012 }
7013 else if(aLine.order.front()!=2) {// uncommon hit of cell a
7014 cout<<setw(6)<<""<<" something wrong about the dots' order"<<endl;
7015 }
7016 }
7017 }
7018 }// loop fitted lines
7019
7020 if(e.vecFittedLine.size()>0) return true;
7021 else return false;
7022}
bool makeOrder(Line &l)

Referenced by makeDotCellEdge().

◆ makeOrder()

bool DotsConnection::makeOrder ( Line & l)
inline

Definition at line 270 of file DotsConnection.h.

271 {
272 if(l.S.size()==0) return false;
273 map<double, int> map_S_i;
274 int n_minus(0), n_plus(0);
275 vector<double>::iterator it_S=l.S.begin();
276 //cout<<" S= ";
277 for(int i=0; it_S!=l.S.end(); it_S++,i++)
278 {
279 //cout<<setw(5)<<*it_S<<" ";
280 if((*it_S)<0) n_minus++;
281 else n_plus++;
282 map_S_i[fabs(*it_S)]=i;
283 }
284 //cout<<endl;
285 if(n_minus==l.S.size()||n_plus==l.S.size())
286 {
287 map<double, int>::iterator it=map_S_i.begin();
288 for(; it!=map_S_i.end(); it++) l.order.push_back((*it).second);
289 return true;
290 }
291 else return false;
292 };

Referenced by makeEdge().

◆ nextCellFinding()

void DotsConnection::nextCellFinding ( cell & aCell,
vector< cell > & v_cell,
vector< edge > & v_edge,
map< int, pair< double, double > > & setWireHitPos,
map< int, int > & setWireEntry )

Definition at line 7182 of file DotsConnection.cxx.

7183{
7184 bool debug=false; debug=true;
7185
7186 set<int>& outEdges = aCell.set_outEdge;
7187 if(debug) {
7188 cout<<setw(5)<<""<<"cell "<<aCell.id<<", state="<<aCell.state;
7189 if(outEdges.size()) cout<<", to fine the next cell";
7190 else cout<<", no next cell"<<endl;
7191 }
7192 for(set<int>::iterator it_edgeIdx=outEdges.begin(); it_edgeIdx!=outEdges.end(); it_edgeIdx++) {
7193 edge& aEdge = v_edge.at(*it_edgeIdx);
7194 for(vector<Line>::iterator it_line=aEdge.vecFittedLine.begin(); it_line!=aEdge.vecFittedLine.end(); it_line++) {
7195 double rho=(*it_line).rho;
7196 double theta=(*it_line).theta;
7197 vector<double>& vS=(*it_line).S;
7198 vector<dot*>::iterator it_dot=aEdge.dots.begin();
7199 for(int i=0; it_dot!=aEdge.dots.end(); it_dot++, i++) {
7200 int wireIdx = (*it_dot)->id;
7201 double s=vS.at(i);
7202 double x, y;
7203 getXY(rho,theta,s,x,y);
7204 map<int, int>::iterator it_entry; // setWireEntry;
7205 it_entry = setWireEntry.find(wireIdx);
7206 if(it_entry!=setWireEntry.end()) {
7207 it_entry->second++;
7208 map<int, pair<double,double> >::iterator it_pos=setWireHitPos.find(wireIdx);
7209 it_pos->second.first+=x;
7210 it_pos->second.second+=y;
7211 }
7212 else {
7213 setWireEntry[wireIdx]=1;
7214 pair<double,double> xy(x,y);
7215 setWireHitPos[wireIdx]=xy;
7216 }
7217 }
7218 }
7219
7220 cell& aNextCell = v_cell.at(v_edge.at(*it_edgeIdx).twoCells.second);
7221 //cout<<setw(5)<<""<<"cell "<<aNextCell.id<<endl;
7222 if((aNextCell.state+1)==aCell.state) {// find the next cell
7223 if(debug) cout<<", cell "<<aNextCell.id<<" found, state = "<<aNextCell.state<<endl;
7224 nextCellFinding(aNextCell, v_cell, v_edge, setWireHitPos, setWireEntry);
7225 break;
7226 }
7227 }// loop out edges
7228}// nextCellFinding

Referenced by CellAutomaton(), and nextCellFinding().

◆ numSharedDots()

int DotsConnection::numSharedDots ( cell & a,
cell & b )

Definition at line 6714 of file DotsConnection.cxx.

6715{
6716 int nShare=0;
6717
6718 //set<int>::iterator it_dot_a = a.set_dotIdx.begin();
6719 //set<int>::iterator it_dot_b = b.set_dotIdx.begin();
6720 //set<int>::iterator it_dot_b_lastMatch = it_dot_b;
6721 //for(; it_dot_a!=a.set_dotIdx.end(); it_dot_a++) {
6722 // it_dot_b = it_dot_b_lastMatch;
6723 // for(; it_dot_b!=b.set_dotIdx.end(); it_dot_b++) {
6724 // if(*it_dot_a == *it_dot_b) {
6725 // nShare++;
6726 // it_dot_b_lastMatch=it_dot_b;
6727 // it_dot_b_lastMatch++;
6728 // break;
6729 // }
6730 // }
6731 //}
6732
6733 for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++) {
6734 int id_a=a.dots[i]->id;
6735 for(int j=0; j<NUMBER_OF_DOTS_PER_CELL; j++) {
6736 int id_b=b.dots[j]->id;
6737 if(id_a==id_b) {
6738 nShare++;
6739 break;
6740 }
6741 }
6742 }
6743
6744 return nShare;
6745}

Referenced by sameCell().

◆ print()

void DotsConnection::print ( cell & aCell)

Definition at line 6800 of file DotsConnection.cxx.

6801{
6802 cout<<" cell "<<setw(5)<<aCell.id;
6803 //cout<<": (id, L, W) = ";
6804 cout<<": (L, W, id) = ";
6805 for(int i=0; i<NUMBER_OF_DOTS_PER_CELL; i++) {
6806 if(aCell.dots[i]->detector==dot::MDC) {
6807 int layer = myMdcGeomSvc->Wire(aCell.dots[i]->id)->Layer();
6808 int Cell = myMdcGeomSvc->Wire(aCell.dots[i]->id)->Cell();
6809 cout<<"("<<setw(3)<<layer<<","<<setw(3)<<Cell<<", "<<setw(5)<<aCell.dots[i]->id<<") ";
6810 }
6811 }
6812 cout<<endl;
6813}

Referenced by makeDotCellEdge(), and stateAutomaton().

◆ sameCell()

bool DotsConnection::sameCell ( cell & a,
cell & b )

Definition at line 6747 of file DotsConnection.cxx.

6748{
6749 return numSharedDots(a, b)==NUMBER_OF_DOTS_PER_CELL ;
6750}
int numSharedDots(cell &a, cell &b)

Referenced by makeDotCellEdge().

◆ stateAutomaton()

void DotsConnection::stateAutomaton ( cell & aCell,
vector< cell > & v_cell,
vector< edge > & v_edge )

Definition at line 7144 of file DotsConnection.cxx.

7145{
7146 bool debug=false; debug=true;
7147 aCell.color=1;
7148 if(debug) {
7149 cout<<"[ discover"; print(aCell);
7150 cout<<setw(5)<<""<<"loop next cells:"<<endl;
7151 }
7152 set<int>& outEdges = aCell.set_outEdge;
7153 int state_max=0;
7154 for(set<int>::iterator it_edgeIdx=outEdges.begin(); it_edgeIdx!=outEdges.end(); it_edgeIdx++) {
7155 cell& aNextCell = v_cell.at(v_edge.at(*it_edgeIdx).twoCells.second);
7156 if(debug) cout<<setw(5)<<""<<"cell "<<aNextCell.id<<endl;
7157 if(aNextCell.color==0) stateAutomaton(aNextCell, v_cell, v_edge);
7158 else if(aNextCell.color==1) myNCycle++;
7159 if(aNextCell.state>state_max) state_max=aNextCell.state;
7160 }
7161 aCell.state=1;
7162 aCell.state+=state_max;
7163 aCell.color=2;
7164
7165 //if(!(myCellMaxState.size()>0&&aCell.state<v_cell.at(myCellMaxState.at(0)).state)) {
7166 // myCellMaxState.push_back(aCell.id);
7167 //}
7168 if(myCellMaxState.size()==0) myCellMaxState.push_back(aCell.id);
7169 else if(v_cell.at(myCellMaxState.at(0)).state==aCell.state) myCellMaxState.push_back(aCell.id);
7170 else if(v_cell.at(myCellMaxState.at(0)).state<aCell.state) {
7171 myCellMaxState.clear();
7172 myCellMaxState.push_back(aCell.id);
7173 }
7174 if(debug) {
7175 cout<<"finish cell "<<aCell.id<<" with state "<<aCell.state;//<<endl;
7176 if(myCellMaxState.size())
7177 cout<<" maximum state: "<<v_cell.at(myCellMaxState.at(0)).state<<", "<<myCellMaxState.size()<<" cells"<<endl;
7178 cout<<"]"<<endl;
7179 }
7180}

Referenced by CellAutomaton(), and stateAutomaton().

Member Data Documentation

◆ myCellMaxState

vector<int> DotsConnection::myCellMaxState

Definition at line 314 of file DotsConnection.h.

Referenced by CellAutomaton(), and stateAutomaton().

◆ myMapDots

map<int, dot> DotsConnection::myMapDots

Definition at line 318 of file DotsConnection.h.

Referenced by makeDotCellEdge().

◆ myNCycle

int DotsConnection::myNCycle

Definition at line 313 of file DotsConnection.h.

Referenced by CellAutomaton(), and stateAutomaton().

◆ myVecCells

vector<cell> DotsConnection::myVecCells

Definition at line 319 of file DotsConnection.h.

Referenced by longestPathFromCA(), and makeDotCellEdge().

◆ myVecEdges

vector<edge> DotsConnection::myVecEdges

Definition at line 321 of file DotsConnection.h.

Referenced by longestPathFromCA(), and makeDotCellEdge().

◆ myVecGoodCellIdx

vector<int> DotsConnection::myVecGoodCellIdx

Definition at line 320 of file DotsConnection.h.

Referenced by longestPathFromCA(), and makeDotCellEdge().


The documentation for this class was generated from the following files: