View Javadoc

1   package org.lcsim.recon.tracking.seedtracker;
2   
3   import java.io.File;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import org.lcsim.event.EventHeader;
8   import org.lcsim.event.MCParticle;
9   import org.lcsim.fit.helicaltrack.HelicalTrackHit;
10  
11  /**
12   * This is a re-implementation of <code>SeedTracker</code> allowing consecutive track reconstruction with different startegy lists. 
13   * Hits of successfully reconstructed tracks using one strategy list will be removed from the available hits before running the next strategy list.
14   * @author cgrefe
15   */
16  public class IterativeSeedTracker extends SeedTracker {
17  	
18  	protected List<List<SeedStrategy>> _strategyLists;
19  	
20  	public IterativeSeedTracker() {
21  		_strategyLists = new ArrayList<List<SeedStrategy>>();
22  		
23          //  Instantiate the material manager
24          // _materialmanager = new MaterialManager();
25  
26          //  Instantiate the hit manager
27          _hitmanager = new HitManager();
28  
29          //  Initialize the detector sectoring
30          _hitmanager.getSectorManager().setSectorParams(_strategylist, _bfield, _rtrk);
31  
32          //  Instantiate the helix finder
33          _helixfitter = new HelixFitter(_materialmanager);
34  
35          //  Instantiate the Seed Finder
36          _finder = new SeedTrackFinder(_hitmanager, _helixfitter);
37  
38          //  Instantiate the Track Maker
39          _maketracks = new MakeTracks();
40  	}
41  	
42  	//--------------------------------------------------------------------------------
43  	// Override driver methods
44  	//--------------------------------------------------------------------------------
45  	
46  	@Override
47  	protected void startOfData() {
48  		
49  		// check if any strategy list has been added
50  		if (_strategyLists.size() == 0) {
51  			throw new RuntimeException("IterativeSeedTracker: no strategy file given!");
52  		}
53  		
54  		// get one of the strategies. This is just a workaround to not break the inherited methods. It does not affect actual reconstruction
55  		_strategylist = _strategyLists.get(0);
56  		
57  		super.startOfData();
58  	}
59  	
60  	@Override
61  	protected void process(EventHeader event) {
62  		
63          //  Pass the event to the diagnostics package
64          if (_diag != null) _diag.setEvent(event);
65  
66          //  Initialize timing
67          long last_time = System.currentTimeMillis();
68          long start_time = last_time;
69          double dtime = 0.;
70  
71          //  Get the hit collection from the event
72          List<HelicalTrackHit> hitcol = event.get(HelicalTrackHit.class, _inputCol);
73          
74          //  Prepare lists of seeded and confirmed MC Particles
75          List<MCParticle> seededmcp = new ArrayList<MCParticle>();
76          List<MCParticle> confirmedmcp = new ArrayList<MCParticle>();
77          
78          //  Prepare list of track seeds
79          List<SeedCandidate> trackseeds = new ArrayList<SeedCandidate>();
80          
81          for (List<SeedStrategy> strategyList : _strategyLists) {
82          	//  Sort the hits for this event
83          	_hitmanager.setSectorParams(strategyList, _bfield, _rtrk);
84              _hitmanager.OrganizeHits(hitcol);
85  
86              String listPrefix = "Strategy list "+ _strategyLists.indexOf(strategyList);
87              
88              //  Make the timing plots if requested
89              start_time = System.currentTimeMillis();
90              dtime = ((double) (start_time - last_time)) / 1000.;
91              last_time = start_time;
92              if (_timing) aida.cloud1D(listPrefix+"/Organize Hits").fill(dtime);
93  
94              //  Make sure that we have cleared the list of track seeds in the finder
95              _finder.clearTrackSeedList();
96  
97              //  Loop over strategies and perform track finding
98              for (SeedStrategy strategy : strategyList) {
99  
100                 //  Set the strategy for the diagnostics
101                 if (_diag != null) _diag.fireStrategyChanged(strategy);
102 
103                 //  Perform track finding under this strategy
104                 _finder.FindTracks(strategy, _bfield);
105 
106                 //  Make the timing plots if requested
107                 long time = System.currentTimeMillis();
108                 dtime = ((double) (time - last_time)) / 1000.;
109                 last_time = time;
110                 if (_timing) aida.cloud1D(listPrefix+"/Tracking time for strategy "+strategy.getName()).fill(dtime);
111             }
112 
113             //  Get the list of final list of SeedCandidates
114             List<SeedCandidate> newTrackSeeds = _finder.getTrackSeeds();
115             trackseeds.addAll(newTrackSeeds);
116             
117             //  Get the list of seeded MC Particles
118             seededmcp.addAll(_finder.getSeededMCParticles());
119             
120             //  Get the list of confirmed MC Particles
121             confirmedmcp.addAll(_finder.getConfirmedMCParticles());
122             
123             //  Find all the used hits and remove from the hit collection
124             for (SeedCandidate trackCandidate : newTrackSeeds) {
125             	for (HelicalTrackHit hit : trackCandidate.getHits()) {
126             		hitcol.remove(hit);
127             	}
128             }
129             
130             //  Make plot of number of found tracks per strategy list if requested
131             if (_timing) aida.cloud1D(listPrefix+"/Found Tracks").fill(newTrackSeeds.size());
132             
133             //  Clear the list of track seeds accumulated in the track finder
134             _finder.clearTrackSeedList();
135         }
136 
137         //  Make tracks from the final list of track seeds
138         _maketracks.Process(event, trackseeds, _bfield);
139 
140         //  Save the MC Particles that have been seeded
141         event.put("SeededMCParticles", seededmcp, MCParticle.class, 0);
142 
143         //  Save the MC Particles that have been confirmed
144         event.put("ConfirmedMCParticles", confirmedmcp, MCParticle.class, 0);
145 
146         //  Make the total time plot if requested
147         long end_time = System.currentTimeMillis();
148         dtime = ((double) (end_time - start_time)) / 1000.;
149         if (_timing) aida.cloud1D("Total tracking time").fill(dtime);
150 
151         return;
152         
153 	}
154 
155 	
156 	//--------------------------------------------------------------------------------
157 	// Adding strategy lists
158 	//--------------------------------------------------------------------------------
159 	
160 	public void setStrategyFile(String fileName) {
161 		setStrategyFile(new File(fileName));
162 	}
163 	
164 	public void setStrategyFile(File file) {
165 		_strategyLists.add(StrategyXMLUtils.getStrategyListFromFile(file));
166 	}
167 	
168 	public void setStrategyResource(String resource) {
169 		_strategyLists.add(StrategyXMLUtils.getStrategyListFromResource(resource));
170 	}
171 
172 }