(*Draft 2.0,
written by A.Kostritsky*)

General information about muon reconstruction and identification in Run II can be found here.

This document describes only combinatorial algorithm of segment reconstruction. There is another algorithm of segment reconstruction (Linked List Algorithm) that can be used in muon reconstructing. Its documentation is located here.

The algorithm can be divided in the following steps:

**1.
****Transform
‘global’ hits to ‘local’ hits. **

Because the segment finder will try to reconstruct segment in a given muon detector section, all hits are sorted by lists that correspond to detector sections. In the case of WAMUS, a section is associated with a given octant and barrel. In the case of FAMUS a section corresponds a given octant.

After it hit coordinates are transformed to a local coordinate system, with the y-axis along the drift direction and the z –axis along the wire. The y-axis of local coordinate is defined such that it is more sensitive to measurement of a track bending and as a consequence to a momentum resolution of reconstructed track.

**2.
****Pattern recognition. **

Pattern recognition is performed in
the local (x,y) plane. Pairs of hits (called **base hits**) from two
different outermost planes are used to form roads for adding hits in the
remaining planes. The size of a road is
adjustable (**rcp** parameters are *MaxWamusDriftRes*
and *MaxFamusDriftRes*, for Wamus and Famus,
respectively). If a segment road associated with selected base hits exists, all
other hits in the section are checked to be in the road and, if it is so, the
hit is added to the list of hits that formed a segment. The minimum number of hits in one segment is a parameter
and equals to the number of planes in the section (It is changed at step 4).
Segment candidates with no missing hits are fitted. The c^{2} is calculated
as a sum of the squares of the residuals divided by position resolution (equal
to drift distance error of reconstructed hits), allowing for one hit cell.
Quality of segment is defined as c^{2}/ndf. The segment position is defined as a
center of gravity of hit positions.

That process is repeated for all possible combination of base hits. Thus, a list of all possible segments in one detector section has been created. It needs to note here the created list can contain the segments that shared the same hits.

**3.
****Select the best segments.**

To remove the effect of hit sharing
the best segment is selected from all segments shared one hit. The selection is
based on the number of hits on a segment, and, for two segments with equal
number of hits, on the fit **quality**. Hits on the selected segments are
marked and are not used for further segment finding.

4.
**Loop over steps 2, and 3**.

The steps 2-3 are repeated, with the minimum number of planes contributing to the segment decremented by one, as long as the number is >= 3, and there remain unmarked hits to define new roads.

At this step the list of all segments found in the detector section has been created.

5.
**Match found segments with scintillator hits**.

In the current algorithm the
segment-to-scintillator match is performed for FAMUS segments only. Before
matching all global scintillator hits move to local hits. If the segment
matches to a scintillator (a line associated with the current position and
direction of segment goes throw scintillator) z-coordinate of all segment hits
is updated. In the case of combined BC segment the update is only carried out
if difference between j positions of B and C scintillators is less than
0.1. *IMPORTANT: Scintillator hits
are not included in the list of hits that forms the segment.* After it the
direction of segment is refitted and, hence, a new segment quality is
calculated.

**6.
****Transform local segment to global segments.**

The algorithm process can be
controlled with RCP parameters that are located in* muo_segmentreco/rcp/MuoSegmentReco.rcp*
file.

*PackageName *The
name of framework package (“MuoSegmentReco”). Don’t change it, please.

*SegmentAlgorithm *The name of
segment algorithm (“Combinatorial” or “LinkedList”)

*debugLevel *Control
of printout amount for debugging purpose (“0” means a minimum printout)

*combineBC * Switch on/off * *B and C layers combining for segment
reconstructing

Special patrameters are listed under the header “Combinatorial algorithm parameters”:

*MaxWamusDriftRes *Drift distance
resolution of WAMUS tubes (in cm)

*MaxWamusAxialRes *Axial distance
resolution of WAMUS tubes (in cm)

*MaxFamusDriftRes *Drift distance
resolution of FAMUS tubes (in cm)

*MaxWamusAxialRes *Axial distance
resolution of FAMUS tubes (in cm)

Classes and methods that are reasonable for the algorithm are described at this part of the document.

**Purpose:**This method does the main preliminary work that is needed for segment reconstruction and calls the segment builder.**Inputs:***edm::Event &Event**MuoWireHit*is adaptor for a*MuoHit*class.*MuoScintHit*is adaptor for a*MuoHit*class.**Workflow:**- Find
*MuoHitChuncks*and get reconstructed hits - Create
*MuoWrireHits*and*MuoScintHits*adaptors for the real hits to provide an additional functionality, which is needed to make segment reconstruction. - Call
*MuoSegmentRecoCombi::findSegment*method, which is the segment builder.

**Purpose:**The segment builder.

**Inputs:**

*1.
**const MuonHitCollection::WireMap& wireMap*

*2.
**const MuonHitCollection::ScintMap& scintMap*

**Used objects:**

1. *LocalWireHit*
describes the hit in local coordinate system.

2.
*ListOfHits*
list of hits in one plane.

3. *ListOfPlanes*
list of plane in one section.

4. *ListOfSections*
list of all muon detector sections. The
section is defined as a logical unit in what the segment search is performed.
For example, it is an A-layer FAMUS octant. In the case of BC-combining the B
and C planes are combined in one section.

5. *MuoLocalSegment*
class – a muon segment in local coordinate system.

6. *ListOfSegments
*– list of* MuoLocalSegments.*

7. *MuoSegment
*class – a muon segment in global coordinate system.

**Workflow:**- Call
*MuoSegmentRecoCombi::createLocalHit*method and create a*ListOfSections*in the local coordinate system. - Loops
over all
*ListOfSections*and performs the following:

q
Call *MuoSegmentAlgCombi::createSegments* to find
a list of *MuoLocalSegments*
in each *ListOfSections*.

q
Call *MuoSegmentAlgCombi::matchSegments*
to match found *MuoLocalSegment*
with reconstructed *MuoScintHits*.

o
Loops over all found *MuoLocalSegments* in *ListOfSections* and
make a transformation from *MuoLocalSegment* (local coordinate
system) to *MuoSegment*
(global coordinate system).

·
**Purpose: **Transform *MuoWireHits*
from the global to a local coordinate system and create *ListOfHits*
that are combined to *ListOfPlanes* and *ListOfSections*.

·
**Inputs: ***const MuoHitCollection::WireMap&
wireMap – *hit collection created in the *findSegment*
method.

·
**Used objects:**

1.
*ListOfHits* list of hits in
one plane.

2.
*ListOfPlanes* list of plane
in one section.

3.
*ListOfSections* list of
all muon detector sections.

4.
*MuoWireHit* is adaptor for
wire hits.

5.
*MuoIndex*
is muon index.

6. *MuoXForm
*is container of the coordinate transformation for different part of muon
detector.

7. *SwapXYZ*
describes the coordinate transformation for given part of the muon system.

·
**Workflow:**

o Loop
over all hits in the wireMap and sort it by *ListOfHits*,
*ListOfPlanes*, and *ListOfSections*.

o Transform
the position of each hit from global to local coordinate system. The
transformation is performed by *SwapXYZ::apply*
method that applies the coordinate transformation for given part of muon
system. *IMPORTANT: At the time the transformation doesn’t take into account
alignment information of the muon detector. It must be changed in the future.*

o In
the case a BC-combining has been selected in the *RCP
parameter* call *MuoSegmentRecoCombi::combineBC*
method to combine B and C hit sections in one section.

** **

·
**Purpose: **Create a list of *MuoLocalSegments* for the given section of muon detector.

·
**Inputs:** *ListOfPlanes*
of a section.

·
**Used objects:**

·
**Workflow**:

o
Select two base planes and call *MuoSegmentAlgCombi::createSegments4Planes*
method to create a list of all possible segments for a selected base planes.
The base plane is a plane that contains a hit,
which is used to build a road within that all segment hits are located. The *MuoSegmentAlgCombi::createSegments4Planes*
method takes a minimum number of hits that can build a segment (that is to be
located within the segment road) as a parameter.

o Loop over all combinations of base planes.

o
If the number of found *MuoLocalSegments*
is more then 1, call* MuoSegmentAlgCombi::cleanSegments*
method to check the existence of segments that are shared the same hits, and to
select the best segment.

o Loop over all possible minimum number of hits. This initial value is equal the number of planes in the section; the minimal value is 3.

**Purpose**: Create a list of all possible*MuoLocalSegments*for given base planes and given minimum number of hits that can build one segment. This method finds not more than one segment for each pair of hits from base planes.**Inputs**:

1.
*ListOfPlanes* – list of planes for given section of muon detector

*2.
**const int nPlanes* –
total number of planes in the detector section

*3.
**const int plane1 –
*the number of first base plane

*4.
**const int plane1
– *the number of second base plane

*5.
**const int minN
– *the minimum number of
hits that can build one segment*.*

**Used objects**:**Workflow**:

o
Call *createRoads *method
and create segment roads for given hit pair from base plane. Each pair of hits
corresponds to four roads, because there is a left-right ambiguity of hit drift
position. So, every hit could be located in one of two possible positions and,
hence, there are four roads for two given hits. The size of a road is adjustable
(**rcp** parameters are *MaxWamusDriftRes*
and *MaxFamusDriftRes*, for Wamus and Famus,
respectively).

o
Loop over all hits from other planes, check is they in
the road and add hits (*MuoLocalSegment::addHit*
method) to a segment that corresponds to a given road.

o Check the number of hits in a segment is larger than the min number. Select “best” segment from four segments, which are associated with four roads. The “best” segment has smallest value of segment quality. Because the segments had not been fitted yet, the quality is calculated as a summa of square distance from position of a given hit to the middle line of road.

o Loop over all combinations of hit pairs for given base planes and create a list of “best” segments.

o
Perform the fit of all segments to determine a
direction of each segment. At this step the quality
of segment is also re-calculated and becomes to equal to c^{2}
/ndf of the fit (*MuoLocalSegment::fit*
method). Actual fitting are performed by *LineFitterCwt::fit*
method. This method calculates c^{2} as _{} (where y_{hit},
and y_{fit} are a hit and fit result positions, respectively, and *s _{i}
*is an error of hit position), value of ndf equals to the number of fitted
hits that have

**Purpose**: Check the intersections (sharing of the same hits) between found*MuoLocalSegments*, select the best one, and erase ‘worse’ segments from the*ListOfSegments*.**Inputs**:*ListOfSegments*– list of found*MuoLocalSegments*.**Used objects**:**Workflow**:- Take
first segment from
*ListOfSegments*and compare it with all other segments to find that share hits. The comparison is done with the*MuoLocalSegment::intersect*method. - If
there are segments that share the same hits, the “best” segment is that
has larger number of hits. If the numbers of hits are equal each other,
the “best” segment must to have smaller quality value (because quality = c
^{2}/ndf). - Erase
all intersecting segments from the
*ListOfSegments,*except for the “best” one. - Repeat the procedure from beginning for next segment from the updated list.

**Purpose**: Create four roads correspond to a given pair of base hits. Create new segment for each road.**Inputs**:

1.
const *LocalWireHit* &
hit1 – reference to the first base hit;

2.
const *LocalWireHit *&
hit2 – reference to the second base hit;

**Used objects**:**Workflow**:- Create
two CartesianPoints for each base hit. Due to left-right drift time
ambiguity an actual y-coordinate of hit can take two values y
_{hit }= y_{wire}± y_{drift}, where y_{wire }is y-coordinate of wire and y_{drift}is drift distance of hit. - Create new segment that corresponds to a given combination of CartesianPoints.

**Purpose**: Perform match the found segments with scintillator hits. Current version is doing the match for Famus segment only.**Inputs**:

1.
*ListOfSegments* * segList
– list of found segments

2.
const *MuoHitCollection::ScintMap*&
scintMap – collection of scintillator hits

**Used objects**:**Workflow**:- Perform
re-fit the segment by
*MuoLocalSegment::refit()*method. - In
the case of A-layer Famus segment loop over all scintillator hits and
check that they are matched with the segment (by
*MuoLocalSegment::matchPixel*method). If a hit matchs with the segment*MuoLocalSegment::updatePosition*method updates the segment position and direction.*IMPORTANT: The scintillator hit isn’t added to the list of segment hits*. - In
the case of B, C or BC-combined segments the match is performed if the
there are scintillator hits
. If it so, and a segment matchs both pixel hits (in the B and C layers), and difference between j positions of matched B and C scintillator hits not large than 0.1, segment position and direction are updated by*in the B and C layers, simultaneously**MuoLocalSegment::updatePosition.*