View Javadoc

1   /*
2    * ProcessHitsDriver.java
3    *
4    * Created on May 22, 2008, 12:10 PM
5    *
6    * $Id: ProcessHitsDriver.java,v 1.2 2008/06/06 14:58:29 ngraf Exp $
7    */
8   
9   package org.lcsim.cal.calib;
10  
11  import java.util.ArrayList;
12  import java.util.HashMap;
13  import java.util.List;
14  import java.util.Map;
15  import org.lcsim.conditions.ConditionsManager;
16  import org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException;
17  import org.lcsim.conditions.ConditionsSet;
18  import org.lcsim.event.CalorimeterHit;
19  import org.lcsim.event.EventHeader;
20  import org.lcsim.event.base.BaseCalorimeterHit;
21  import org.lcsim.util.Driver;
22  
23  /**
24   *
25   * @author Norman Graf
26   */
27  public class ProcessHitsDriver extends Driver
28  {
29      private ConditionsSet _cond;
30      private boolean _initialized;
31      
32      private String[] _hitCollectionNames;
33      private List<String> _emCalNames = new ArrayList<String>();
34      private List<String> _hadCalNames = new ArrayList<String>();
35      
36      private double _timeCut;
37  //    private int _isolationMinNeighbors;
38      private int _hadCalorimeterMaxLayer;
39      
40      private double _ECalMipCut;
41      private double _HCalMipCut;
42      private double[] _rawMipCut;
43      
44      private CollectionManager _collectionmanager = CollectionManager.defaultInstance();
45      
46      /** Creates a new instance of ProcessHitsDriver */
47      public ProcessHitsDriver()
48      {
49      }
50      
51      protected void process(EventHeader event)
52      {
53          super.process(event);
54          
55          if(!_initialized)
56          {
57              ConditionsManager mgr = ConditionsManager.defaultInstance();
58              try
59              {
60                  _cond = mgr.getConditions("CalorimeterCalibration");
61              }
62              catch(ConditionsSetNotFoundException e)
63              {
64                  System.out.println("ConditionSet CalorimeterCalibration not found for detector "+mgr.getDetector());
65                  System.out.println("Please check that this properties file exists for this detector ");
66              }
67              
68              
69              // The SimCalorimeterHit collections to process...
70              String names = _cond.getString("BaseHitCollectionNames");
71              
72              _hitCollectionNames = names.split(",\\s");
73              
74              names = _cond.getString("HadCalorimeterCollections");
75              String[] hadCalCollectionNames = names.split(",\\s");
76              for(int i=0; i<hadCalCollectionNames.length; ++i)
77              {
78                  _hadCalNames.add(hadCalCollectionNames[i]);
79              }
80              
81              //TODO allow eachhad calorimeter to have its own max layer.
82              // may want to study barrel and endcap separately.
83              _hadCalorimeterMaxLayer = _cond.getInt("HadCalorimeterMaxLayer");
84              
85              names = _cond.getString("EMCalorimeterCollections");
86              String[] emCalCollectionNames = names.split(",\\s");
87              for(int i=0; i<emCalCollectionNames.length; ++i)
88              {
89                  _emCalNames.add(emCalCollectionNames[i]);
90              }
91              
92              // cut on late times
93              _timeCut = _cond.getDouble("timeCut");
94              
95              // cut on small energy depositions
96              _ECalMipCut = _cond.getDouble("ECalMip_Cut");
97              _HCalMipCut = _cond.getDouble("HCalMip_Cut");
98              
99  //            // isolation cut on number of neighbors
100 //            _isolationMinNeighbors = _cond.getInt("isolationMinNeighbors");
101             
102             // use same values for barrel and endcap
103             _rawMipCut = new double[_hitCollectionNames.length];
104             for(int i=0; i<_rawMipCut.length; ++i)
105             {
106                 if(_emCalNames.contains(_hitCollectionNames[i]))
107                 {
108                     _rawMipCut[i] = _ECalMipCut;
109                 }
110                 else if (_hadCalNames.contains(_hitCollectionNames[i]))
111                 {
112                     _rawMipCut[i] = _HCalMipCut;
113                 }
114             }
115             _initialized = true;
116         }
117         
118         // All the calorimeter hits keyed by their ID
119 //        Map<Long, CalorimeterHit> allHitsMap = new HashMap<Long, CalorimeterHit>();
120 //        for(String name : _hitCollectionNames)
121 //        {
122 //            List<CalorimeterHit> hits = event.get(CalorimeterHit.class, name);
123 //            for(CalorimeterHit hit : hits)
124 //            {
125 //                long id = hit.getCellID();
126 //                allHitsMap.put(id, hit);
127 //            }
128 //        }
129         
130         // The list of all of the calorimeter hits after cuts...
131         List<CalorimeterHit> hitsToCluster = new ArrayList<CalorimeterHit>();
132         int i = 0;
133         
134         for(String name : _hitCollectionNames)
135         {
136             boolean isHadCal = _hadCalNames.contains(name);
137             List<CalorimeterHit> hits = event.get(CalorimeterHit.class, name);
138             // let's look at the hits and see if we need to cut on energy or time...
139             // continue out of the loop to fail fast
140             for(CalorimeterHit hit: hits)
141             {
142                 BaseCalorimeterHit h = (BaseCalorimeterHit) hit;
143                 
144                 //throw out low energy hits
145                 if(h.getRawEnergy() < _rawMipCut[i]) continue;
146                 
147                 // throw out late hits
148                 if(h.getTime() > _timeCut) continue;
149                 
150                 // special studies of hcal depth require the following
151                 if(isHadCal && h.getLayerNumber() > _hadCalorimeterMaxLayer) continue;
152                 
153 //                if(_isolationMinNeighbors !=0)
154 //                {
155 //                    if (isIsolated(hit, allHitsMap)) continue;
156 //                }
157                 // passed all the cuts, add to list
158                 hitsToCluster.add(hit);
159             }
160             ++i;
161         }
162         // add the processed hits back to the event
163         // here we use the collection manager to handle these instead of the event
164         String outputCollectionName = _cond.getString("ProcessedHitsCollectionName");
165         
166         _collectionmanager.addList(outputCollectionName, hitsToCluster);
167     }
168     
169 //    private boolean isIsolated(CalorimeterHit h, Map<Long, CalorimeterHit> allHitsMap)
170 //    {
171 //        return false;
172 //    }
173 }