13 modified files
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/CTPEcalClusterer.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/CTPEcalClusterer.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -50,6 +50,10 @@
// The minimum energy needed for a hit to be considered.
double addEMin = 0;
+ // Must be declared now to use database conditions
+ HPSEcalCluster cluster = new HPSEcalCluster();
+ HPSCalorimeterHit seedHit = new HPSCalorimeterHit();
+
public CTPEcalClusterer() {
}
@@ -87,6 +91,11 @@
@Override
public void detectorChanged(Detector detector) {
+
+ // Must be done to be able to use the database conditions
+ seedHit.setDetector(detector);
+ cluster.setDetector(detector);
+
// Get the Subdetector.
ecal = (HPSEcal3) detector.getSubdetector(ecalName);
@@ -195,7 +204,7 @@
for (CalorimeterHit hit : hits) {
// Make a hit map for quick lookup by ID.
hitMap.put(hit.getCellID(), hit);
-
+
// Get the cell ID for the current crystal's neighbors.
Set<Long> neighbors = neighborMap.get(hit.getCellID());
@@ -344,11 +353,11 @@
}
// Generate a new cluster seed hit from the above results.
- CalorimeterHit seedHit = new HPSCalorimeterHit(0.0, clusterTime, possibleCluster, hits.get(0).getType());
+ seedHit.setParameters(0.0, clusterTime, possibleCluster, hits.get(0).getType());
seedHit.setMetaData(hits.get(0).getMetaData());
// Generate a new cluster from the seed hit.
- HPSEcalCluster cluster = new HPSEcalCluster(seedHit);
+ cluster.setParameters(seedHit);
// Populate the cluster with each of the chosen neighbors.
for (CalorimeterHit clusterHit : hits) {
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalClusterIC.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalClusterIC.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -6,6 +6,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -21,352 +22,519 @@
/**
* This Driver creates clusters from the CalorimeterHits of an
* {@link org.lcsim.geometry.subdetectur.HPSEcal3} detector.
+ *
+ * This clustering logic is based on that from the CLAS-Note-2005-001.
+ * This sorts hits from highest to lowest energy and build clusters around
+ * each local maximum/seed hit. Common hits are distributed between clusters
+ * when minimum between two clusters. There is a threshold cut for minimum
+ * hit energy, minimum cluster energy, and minimum seed hit energy. There is
+ * also a timing threshold with respect to the seed hit. All of these parameters
+ * are tunable and should be refined with more analysis.
*
*
- * @author Holly Szumila-Vance <h[log in to unmask]>
+ * @author Holly Szumila-Vance <h[log in to unmask]>
+ * @author Kyle McCarty <[log in to unmask]>
*
*/
public class EcalClusterIC extends Driver {
- FileWriter writeHits;
- HPSEcal3 ecal;
+ // File writer to output cluster results.
+ FileWriter writeHits;
+ // LCIO collection name for calorimeter hits.
String ecalCollectionName;
+ // Name of the calorimeter detector object.
String ecalName = "Ecal";
+ // LCIO cluster collection name to which to write.
String clusterCollectionName = "EcalClusters";
+ // File path to which to write event display output.
+ String outfile = "cluster-hit-IC.txt";
// Map of crystals to their neighbors.
NeighborMap neighborMap = null;
- //Minimum energy that counts as hit
- double Emin = 0.001;
+ // Minimum energy threshold for hits; lower energy hits will be
+ // excluded from clustering. Units in GeV.
+ double hitEnergyThreshold = 0.0075;
+ // Minimum energy threshold for seed hits; if seed hit is below
+ // cluster is excluded from output. Units in GeV.
+ double seedEnergyThreshold = 0.2;
+ // Minimum energy threshold for cluster hits; if total cluster
+ // energy is below, the cluster is excluded. Units in GeV.
+ double clusterEnergyThreshold = 0.4;
+ // A Comparator that sorts CalorimeterHit objects from highest to
+ // lowest energy.
+ private static final EnergyComparator ENERGY_COMP = new EnergyComparator();
+ // Track the event number for the purpose of outputting to event
+ // display format.
+ private int eventNum = -1;
+ // Apply time cut to hits
+ boolean timeCut = false;
+ // Minimum time cut window range. Units in ns.
+ double minTime = 0.0;
+ // Maximum time cut window range. Units in ns.
+ double timeWindow = 20.0;
-
- public EcalClusterIC() {
- }
-
+ HPSEcalCluster cluster = new HPSEcalCluster();
+
+
public void setClusterCollectionName(String clusterCollectionName) {
this.clusterCollectionName = clusterCollectionName;
}
-
+
public void setEcalCollectionName(String ecalCollectionName) {
this.ecalCollectionName = ecalCollectionName;
}
-
+
public void setEcalName(String ecalName) {
this.ecalName = ecalName;
}
+
+ /**
+ * Minimum energy for a hit to be used in a cluster. Default of 0.0075 GeV
+ *
+ * @param hitEnergyThreshold
+ */
+ public void sethitEnergyThreshold(double hitEnergyThreshold) {
+ this.hitEnergyThreshold = hitEnergyThreshold;
+ }
+ /**
+ * Minimum energy for a seed hit. Default of 0.2 GeV
+ *
+ * @param seedEnergyThreshold
+ */
+ public void setseedEnergyThreshold(double seedEnergyThreshold) {
+ this.seedEnergyThreshold = seedEnergyThreshold;
+ }
+
+ /**
+ * Minimum energy for a cluster. Default of 0.4 GeV
+ *
+ * @param clusterEnergyThreshold
+ */
+ public void setclusterEnergyThreshold(double clusterEnergyThreshold) {
+ this.clusterEnergyThreshold = clusterEnergyThreshold;
+ }
+
+ /**
+ * Apply time cuts to hits. Defaults to false.
+ *
+ * @param timeCut
+ */
+ public void setTimeCut(boolean timeCut) {
+ this.timeCut = timeCut;
+ }
+
+ /**
+ * Minimum hit time, if timeCut is true. Default of 0 ns.
+ *
+ * @param minTime
+ */
+ public void setMinTime(double minTime) {
+ this.minTime = minTime;
+ }
+
+ /**
+ * Width of time window, if timeCut is true. Default of 20 ns.
+ *
+ * @param timeWindow
+ */
+ public void setTimeWindow(double timeWindow) {
+ this.timeWindow = timeWindow;
+ }
+
+
public void startOfData() {
+ // Make sure that the calorimeter hit collection name is defined.
if (ecalCollectionName == null) {
throw new RuntimeException("The parameter ecalCollectionName was not set!");
}
-
+
+ // Make sure the name of calorimeter detector is defined.
if (ecalName == null) {
throw new RuntimeException("The parameter ecalName was not set!");
}
- try{
- writeHits = new FileWriter("cluster-hit-IC.txt");
- writeHits.write("");
- }
- catch(IOException e) {};
+ // Create a file writer and clear the output file, if it exists.
+ try {
+ writeHits = new FileWriter(outfile);
+ writeHits.write("");
+ }
+ catch(IOException e) { }
}
public void detectorChanged(Detector detector) {
- // Get the Subdetector.
- ecal = (HPSEcal3) detector.getSubdetector(ecalName);
-
- // Cache ref to neighbor map.
+
+ // Must be set to use database conditions
+ cluster.setDetector(detector);
+
+ // Get the calorimeter.
+ HPSEcal3 ecal = (HPSEcal3) detector.getSubdetector(ecalName);
+
+ // Store the map of neighbor crystals for the current calorimeter set-up.
neighborMap = ecal.getNeighborMap();
}
public void process(EventHeader event) {
-
-
-
+ // Make sure the current event contains calorimeter hits.
if (event.hasCollection(CalorimeterHit.class, ecalCollectionName)) {
- // Get the list of raw ECal hits.
- List<CalorimeterHit> hits = event.get(CalorimeterHit.class, ecalCollectionName);
-
- // Make a hit map for quick lookup by ID.
- Map<Long, CalorimeterHit> hitMap = new HashMap<Long, CalorimeterHit>();
+ // Get the list of raw calorimeter hits.
+ List<CalorimeterHit> hitList = event.get(CalorimeterHit.class, ecalCollectionName);
- for (CalorimeterHit hit : hits) {
- hitMap.put(hit.getCellID(), hit);
- }
+ // Generate clusters from the calorimeter hits.
+ List<HPSEcalCluster> clusterList = null;
+ try { clusterList = createClusters(hitList); }
+ catch(IOException e) { }
- //System.out.println("Number of ECal hits: "+hitMap.size());
-
- // Put Cluster collection into event.
- int flag = 1 << LCIOConstants.CLBIT_HITS;
- try {
-
- event.put(clusterCollectionName, createClusters(hitMap), HPSEcalCluster.class, flag);
+ // If clusters were successfully created, put them in the event.
+ if(clusterList != null) {
+ int flag = 1 << LCIOConstants.CLBIT_HITS;
+ event.put(clusterCollectionName, clusterList, HPSEcalCluster.class, flag);
}
- catch(IOException e) { }
}
}
- public List<HPSEcalCluster> createClusters(Map<Long, CalorimeterHit> map) throws IOException {
-
- // New Cluster list to be added to event.
- List<HPSEcalCluster> clusters = new ArrayList<HPSEcalCluster>();
-
- //Create a Calorimeter hit list in each event, then sort with highest energy first
- ArrayList<CalorimeterHit> chitList = new ArrayList<CalorimeterHit>(map.size());
- for(CalorimeterHit h : map.values()) {
- if(h.getCorrectedEnergy()>Emin){
- chitList.add(h);}
+ public List<HPSEcalCluster> createClusters(List<CalorimeterHit> hitList) throws IOException {
+ // Create a list to store the newly created clusters in.
+ ArrayList<HPSEcalCluster> clusterList = new ArrayList<HPSEcalCluster>();
- Collections.sort(chitList, new EnergyComparator());}
+ // Sort the list of hits by energy.
+ Collections.sort(hitList, ENERGY_COMP);
- //New Seed list containing each local maximum energy hit
- List<CalorimeterHit> seedHits = new ArrayList<CalorimeterHit>();
-
- //Create map to contain common hits for evaluation later, key is crystal and values are seed
- Map<CalorimeterHit, List<CalorimeterHit>> commonHits = new HashMap<CalorimeterHit, List<CalorimeterHit>>();
-
- //Created map to contain seeds with listed hits, key is crystal, and value is seed
- Map<CalorimeterHit, CalorimeterHit> clusterHits = new HashMap<CalorimeterHit, CalorimeterHit>();
-
- //Create map to contain the total energy of each cluster
- Map<CalorimeterHit, Double> seedEnergy = new HashMap<CalorimeterHit,Double>();
-
- //Quick Map to access hits from cell IDs
- Map<Long, CalorimeterHit> hitID = new HashMap<Long, CalorimeterHit>();
-
- //List to contain all hits already put into clusters
- List<CalorimeterHit> clusterHitList = new ArrayList<CalorimeterHit>();
-
- //Fill Map with cell ID and hit
- for (CalorimeterHit hit : chitList){
- hitID.put(hit.getCellID(), hit);
- }
-
- for (CalorimeterHit hit : chitList) {
- Set<Long> neighbors = neighborMap.get(hit.getCellID()); //get all neighbors of hit
- List<CalorimeterHit> neighborHits = new ArrayList<CalorimeterHit>();
- for(Long neighbor : neighbors){
- if(hitID.containsKey(neighbor)){//map contains (neighbor's cell id, neighbor hit)
- neighborHits.add(hitID.get(neighbor));
+ // Filter the hit list of any hits that fail to pass the
+ // designated threshold.
+ filterLoop:
+ for(int index = hitList.size() - 1; index >= 0; index--) {
+ // If the hit is below threshold or outside of time window, kill it.
+ if((hitList.get(index).getCorrectedEnergy() < hitEnergyThreshold)||
+ (timeCut && (hitList.get(index).getTime() < minTime || hitList.get(index).getTime() > minTime + timeWindow))) {
+ hitList.remove(index);
}
+
+ // Since the hits are sorted by energy from highest to
+ // lowest, any hit that is above threshold means that all
+ // subsequent hits will also be above threshold. Continue through
+ // list to check in time window.
+ else { continue; }
}
- Collections.sort(neighborHits, new EnergyComparator());
+ // Create a map to connect the cell ID of a calorimeter crystal
+ // to the hit which occurred in that crystal.
+ HashMap<Long, CalorimeterHit> hitMap = new HashMap<Long, CalorimeterHit>();
+ for (CalorimeterHit hit : hitList) { hitMap.put(hit.getCellID(), hit); }
- boolean highestE = true;
- for(CalorimeterHit neighborHit : neighborHits){//check for seed hit
- if(hit.getCorrectedEnergy()>neighborHit.getCorrectedEnergy()){
- continue;
- }
- else {
- highestE = false;
- break;
- }
- }
+ // Map a crystal to a list of all clusters in which it is a member.
+ Map<CalorimeterHit, List<CalorimeterHit>> commonHits = new HashMap<CalorimeterHit, List<CalorimeterHit>>();
- if (highestE == true){//seed hit, local maximum
- seedHits.add(hit);
- clusterHits.put(hit, hit);
- clusterHitList.add(hit);
- }
+ // Map a crystal to the seed of the cluster of which it is a member.
+ HashMap<CalorimeterHit, CalorimeterHit> hitSeedMap = new HashMap<CalorimeterHit, CalorimeterHit>();
- //not seed hit
- else {
- //builds immediate clusters around seed hits
- for(CalorimeterHit neighborHit : neighborHits){
- //if neighbor to seed, add to seed
- if (seedHits.contains(neighborHit)&&!clusterHits.containsKey(hit)){
- CalorimeterHit seed = clusterHits.get(neighborHit);
- clusterHits.put(hit, seed);
- clusterHitList.add(hit);
- }
- //if neighbor to two seeds, add to common hits
- else if (seedHits.contains(neighborHit)&&clusterHits.containsKey(hit)){
- CalorimeterHit prevSeed = clusterHits.get(neighborHit);
- CalorimeterHit currSeed = clusterHits.get(hit);
- List<CalorimeterHit> commonHitList = new ArrayList<CalorimeterHit>();
- commonHitList.add(prevSeed);
- commonHitList.add(currSeed);
- commonHits.put(hit, commonHitList);
- }
- }
- }
- }
+ // Set containing hits immediately around a seed hit.
+ HashSet<CalorimeterHit> surrSeedSet = new HashSet<CalorimeterHit>();
- //loop over hit list, find neighbors, compare energies, add to list
- for(CalorimeterHit nHit : chitList){
- Set<Long> neighbors2 = neighborMap.get(nHit.getCellID()); //get all neighbors of hit
- List<CalorimeterHit> neighborHits2 = new ArrayList<CalorimeterHit>();
- for(Long neighbor : neighbors2){
- if(hitID.containsKey(neighbor)){//map contains (neighbor's cell id, neighbor hit)
- if(!clusterHitList.contains(hitID.get(neighbor))){
- neighborHits2.add(hitID.get(neighbor));
- }
+ // Loop through all calorimeter hits to locate seeds and perform
+ // first pass calculations for component and common hits.
+ for (CalorimeterHit hit : hitList) {
+ // Get the set of all neighboring crystals to the current hit.
+ Set<Long> neighbors = neighborMap.get(hit.getCellID());
+
+ // Generate a list to store any neighboring hits in.
+ ArrayList<CalorimeterHit> neighborHits = new ArrayList<CalorimeterHit>();
+
+ // Sort through the set of neighbors and, if a hit exists
+ // which corresponds to a neighbor, add it to the list of
+ // neighboring hits.
+ for (Long neighbor : neighbors) {
+ // Get the neighboring hit.
+ CalorimeterHit neighborHit = hitMap.get(neighbor);
+
+ // If it exists, add it to the list.
+ if(neighborHit != null) { neighborHits.add(neighborHit); }
+ }
+
+ // Track whether the current hit is a seed hit or not.
+ boolean isSeed = true;
+
+ // Loops through all the neighboring hits to determine if
+ // the current hit is the local maximum within its set of
+ // neighboring hits.
+ seedHitLoop:
+ for(CalorimeterHit neighbor : neighborHits) {
+ if(hit.getCorrectedEnergy() <= neighbor.getCorrectedEnergy()) {
+ isSeed = false;
+ break seedHitLoop;
}
}
- Collections.sort(neighborHits2, new EnergyComparator());
- for(CalorimeterHit neighbor : neighborHits2){
- if(clusterHits.containsKey(nHit) && neighbor.getCorrectedEnergy()<nHit.getCorrectedEnergy()){
- CalorimeterHit seed = clusterHits.get(nHit);
- clusterHits.put(neighbor, seed);
- clusterHitList.add(neighbor);
- }
- else{continue;}
- }
- }
- //loop over cluster hits, compare energies of neighbors with diff seeds, if min->add to commonHits
- for (CalorimeterHit mHit : clusterHitList){
- //exclude seed hits as possible common hits
- if(clusterHits.get(mHit) != mHit){
-
- Set<Long> neighbors3 = neighborMap.get(mHit.getCellID()); //get all neighbors of hit
- List<CalorimeterHit> neighborHits3 = new ArrayList<CalorimeterHit>();
- for(Long neighbor : neighbors3){
- if(hitID.containsKey(neighbor)){//map contains (neighbor's cell id, neighbor hit)
- neighborHits3.add(hitID.get(neighbor));
-
+ // If this hit is a seed hit, just map it to itself.
+ if (isSeed) { hitSeedMap.put(hit, hit); }
+
+ // If this hit is not a seed hit, see if it should be
+ // attached to any neighboring seed hits.
+ else {
+ // Sort through the list of neighboring hits.
+ for (CalorimeterHit neighborHit : neighborHits) {
+ // Check whether the neighboring hit is a seed.
+ if(hitSeedMap.get(neighborHit) == neighborHit) {
+ // If the neighboring hit is a seed hit and the
+ // current hit has been associated with a cluster,
+ // then it is a common hit between its previous
+ // seed and the neighboring seed.
+ if (hitSeedMap.containsKey(hit)) {
+ // Check and see if a list of common seeds
+ // for this hit already exists or not.
+ List<CalorimeterHit> commonHitList = commonHits.get(hit);
+
+ // If it does not, make a new one.
+ if(commonHitList == null) { commonHitList = new ArrayList<CalorimeterHit>(); }
+
+ // Add the neighbors to the seeds to set of
+ // common seeds.
+ commonHitList.add(neighborHit);
+ commonHitList.add(hitSeedMap.get(hit));
+
+ // Put the common seed list back into the set.
+ commonHits.put(hit, commonHitList);
+ }
+
+ // If the neighboring hit is a seed hit and the
+ // current hit has not been added to a cluster yet
+ // associate it with the neighboring seed and note
+ // that it has been clustered.
+ else {
+ hitSeedMap.put(hit, neighborHit);
+ surrSeedSet.add(hit);
+ }
}
}
-
- Collections.sort(neighborHits3, new EnergyComparator());
+ }
+ } // End primary seed loop.
+
+ // Performs second pass calculations for component hits.
+ secondaryHitsLoop:
+ for (CalorimeterHit secondaryHit : hitList) {
+ // If the secondary hit is not associated with a seed, then
+ // the rest of there is nothing further to be done.
+ if(!hitSeedMap.containsKey(secondaryHit)) { continue secondaryHitsLoop; }
+
+ // Get the secondary hit's neighboring crystals.
+ Set<Long> secondaryNeighbors = neighborMap.get(secondaryHit.getCellID());
+
+ // Make a list to store the hits associated with the
+ // neighboring crystals.
+ List<CalorimeterHit> secondaryNeighborHits = new ArrayList<CalorimeterHit>();
+
+ // Loop through the neighboring crystals.
+ for (Long secondaryNeighbor : secondaryNeighbors) {
+ // Get the hit associated with the neighboring crystal.
+ CalorimeterHit secondaryNeighborHit = hitMap.get(secondaryNeighbor);
- CalorimeterHit compSeed = clusterHits.get(mHit);
- for(CalorimeterHit neighbor : neighborHits3){
- if(clusterHits.containsKey(neighbor) && clusterHits.get(neighbor)!=compSeed){//borders clusters
- if(mHit.getCorrectedEnergy() < neighbor.getCorrectedEnergy()){
- //add to common hits,
- List<CalorimeterHit> commonHitList = new ArrayList<CalorimeterHit>();
- commonHitList.add(compSeed);
- commonHitList.add(clusterHits.get(neighbor));
- commonHits.put(mHit, commonHitList);
- }
- }
- }
- }
+ // If the neighboring crystal exists and is not already
+ // in a cluster, add it to the list of neighboring hits.
+ if (secondaryNeighborHit != null && !hitSeedMap.containsKey(secondaryNeighborHit)) { //!clusteredHitSet.contains(secondaryNeighborHit)) {
+ secondaryNeighborHits.add(secondaryNeighborHit);
+ }
+ }
+
+ // Loop over the secondary neighbor hits.
+ for (CalorimeterHit secondaryNeighborHit : secondaryNeighborHits) {
+ // If the neighboring hit is of lower energy than the
+ // current secondary hit, then associate the neighboring
+ // hit with the current secondary hit's seed.
+ if (secondaryNeighborHit.getCorrectedEnergy() < secondaryHit.getCorrectedEnergy()) {
+ hitSeedMap.put(secondaryNeighborHit, hitSeedMap.get(secondaryHit));
+ }
+ }
+ } // End component hits loop.
+
+ // Performs second pass calculations for common hits.
+ commonHitsLoop:
+ for (CalorimeterHit clusteredHit : hitSeedMap.keySet()) {
+ // Seed hits are never common hits and can be skipped.
+ if(hitSeedMap.get(clusteredHit) == clusteredHit || surrSeedSet.contains(clusteredHit)) { continue commonHitsLoop; }
+
+ // Get the current clustered hit's neighboring crystals.
+ Set<Long> clusteredNeighbors = neighborMap.get(clusteredHit.getCellID());
+
+ // Store a list of all the clustered hits neighboring
+ // crystals which themselves contain hits.
+ List<CalorimeterHit> clusteredNeighborHits = new ArrayList<CalorimeterHit>();
+
+ // Loop through the neighbors and see if they have hits.
+ for (Long neighbor : clusteredNeighbors) {
+ // Get the hit associated with the neighbor.
+ CalorimeterHit clusteredNeighborHit = hitMap.get(neighbor);
+
+ // If it exists, add it to the neighboring hit list.
+ if (clusteredNeighborHit != null) {
+ clusteredNeighborHits.add(clusteredNeighborHit);
+ }
+ }
+
+ // Get the seed hit associated with this clustered hit.
+ CalorimeterHit clusteredHitSeed = hitSeedMap.get(clusteredHit);
+
+ // Loop over the clustered neighbor hits.
+ for (CalorimeterHit clusteredNeighborHit : clusteredNeighborHits) {
+ // Check to make sure that the clustered neighbor hit
+ // is not already associated with the current clustered
+ // hit's seed.
+ if (hitSeedMap.get(clusteredNeighborHit) != clusteredHitSeed) {
+ if (clusteredHit.getCorrectedEnergy() < clusteredNeighborHit.getCorrectedEnergy()) {
+ // Check and see if a list of common seeds
+ // for this hit already exists or not.
+ List<CalorimeterHit> commonHitList = commonHits.get(clusteredHit);
+
+ // If it does not, make a new one.
+ if(commonHitList == null) { commonHitList = new ArrayList<CalorimeterHit>(); }
+
+ // Add the neighbors to the seeds to set of
+ // common seeds.
+ commonHitList.add(clusteredHitSeed);
+ commonHitList.add(hitSeedMap.get(clusteredNeighborHit));
+
+ // Put the common seed list back into the set.
+ commonHits.put(clusteredHit, commonHitList);
+ }
+ }
+ }
+ } // End common hits loop.
+
+ // Remove any common hits from the clustered hits collection.
+ for(CalorimeterHit commonHit : commonHits.keySet()) {
+ hitSeedMap.remove(commonHit);
}
- //remove common hits from cluster hits list
- for(CalorimeterHit commHit : clusterHitList){
- if(clusterHitList.contains(commHit)&&commonHits.containsKey(commHit)){
- clusterHits.remove(commHit);
- }
- else{
- continue;
- }
+
+
+ /*
+ * All hits are sorted from above. The next part of the code is for calculating energies. Still
+ * needs implementation into new cluster collection so as to preserve shared hit energy
+ * distribution within clusters.
+ */
+
+ //Create map to contain the total energy of each cluster
+ Map<CalorimeterHit, Double> seedEnergy = new HashMap<CalorimeterHit, Double>();
+
+ // Get energy of each cluster, excluding common hits
+ for (CalorimeterHit iSeed : hitList) {
+ if(hitSeedMap.get(iSeed) == iSeed) {
+ seedEnergy.put(iSeed, 0.0);
+ }
}
-
-
- //Get energy of each cluster, excluding common hits
- for(CalorimeterHit iSeed : seedHits){
- seedEnergy.put(iSeed, 0.0);
- }
//Putting total cluster energies excluding common hit energies into map with seed keys
- for (Map.Entry<CalorimeterHit, CalorimeterHit> entry : clusterHits.entrySet()) {
- CalorimeterHit eSeed = entry.getValue();
- double eEnergy = seedEnergy.get(eSeed);
- eEnergy += entry.getKey().getRawEnergy();
- seedEnergy.put(eSeed, eEnergy);
+ for (Map.Entry<CalorimeterHit, CalorimeterHit> entry : hitSeedMap.entrySet()) {
+ CalorimeterHit eSeed = entry.getValue();
+ double eEnergy = seedEnergy.get(eSeed);
+ eEnergy += entry.getKey().getRawEnergy();
+ seedEnergy.put(eSeed, eEnergy);
}
//Distribute common hit energies with clusters
Map<CalorimeterHit, Double> seedEnergyTot = seedEnergy;
for (Map.Entry<CalorimeterHit, List<CalorimeterHit>> entry1 : commonHits.entrySet()) {
- CalorimeterHit commonCell = entry1.getKey();
- List<CalorimeterHit> commSeedList = entry1.getValue();
- CalorimeterHit seedA = commSeedList.get(0);
- CalorimeterHit seedB = commSeedList.get(1);
- double eFractionA = seedEnergy.get(seedA)/(seedEnergy.get(seedA)+seedEnergy.get(seedB));
+ CalorimeterHit commonCell = entry1.getKey();
+ List<CalorimeterHit> commSeedList = entry1.getValue();
+ CalorimeterHit seedA = commSeedList.get(0);
+ CalorimeterHit seedB = commSeedList.get(1);
+ double eFractionA = seedEnergy.get(seedA)/(seedEnergy.get(seedA)+seedEnergy.get(seedB));
double eFractionB = seedEnergy.get(seedB)/(seedEnergy.get(seedA)+seedEnergy.get(seedB));
- double currEnergyA = seedEnergyTot.get(seedA);
- double currEnergyB = seedEnergyTot.get(seedB);
- currEnergyA += eFractionA*commonCell.getCorrectedEnergy();
- currEnergyB += eFractionB*commonCell.getCorrectedEnergy();
-
- seedEnergyTot.put(seedA, currEnergyA);
- seedEnergyTot.put(seedB, currEnergyB);
+ double currEnergyA = seedEnergyTot.get(seedA);
+ double currEnergyB = seedEnergyTot.get(seedB);
+ currEnergyA += eFractionA * commonCell.getCorrectedEnergy();
+ currEnergyB += eFractionB * commonCell.getCorrectedEnergy();
+
+ seedEnergyTot.put(seedA, currEnergyA);
+ seedEnergyTot.put(seedB, currEnergyB);
}
-
-
- //Do some system.out for number of crystals in each cluster, energy of each cluster
- for (Map.Entry<CalorimeterHit, Double> entryEnergy : seedEnergyTot.entrySet()){
- // System.out.println(entryEnergy.getKey().getCellID()+"\t"+entryEnergy.getKey().getCorrectedEnergy()+
- // "\t"+entryEnergy.getValue());
- }
- // System.out.println("Number of clusters: "+seedHits.size());
-
- if (map.size()!=0){
- writeHits.append("Event"+"\t"+"1"+"\n");
- for (CalorimeterHit n : chitList){
- writeHits.append("EcalHit" + "\t" + n.getIdentifierFieldValue("ix") + "\t" + n.getIdentifierFieldValue("iy")
- + "\t" +n.getCorrectedEnergy() + "\n");
- }
-
- for (Map.Entry<CalorimeterHit, CalorimeterHit> entry2 : clusterHits.entrySet()){
- if (entry2.getKey()==entry2.getValue()){//seed
- writeHits.append("Cluster" + "\t" + entry2.getKey().getIdentifierFieldValue("ix")+
- "\t"+entry2.getKey().getIdentifierFieldValue("iy")+"\t"+seedEnergyTot.get(entry2.getKey())+"\n");
-
- HPSEcalCluster cluster = new HPSEcalCluster(entry2.getKey());
+
+
+ /*
+ * Prints the results in event display format. Not analyzed
+ * for efficiency, as this will ultimately not be a part of
+ * the driver and should be handled by the event display output
+ * driver instead.
+ */
+ // Only write to the output file is something actually exists.
+ if (hitMap.size() != 0) {
+ // Increment the event number.
+ eventNum++;
+
+ // Write the event header.
+// writeHits.append(String.format("Event\t%d%n", eventNum));
+
+ // Write the calorimeter hits that passed the energy cut.
+ for (CalorimeterHit n : hitList) {
+ int hix = n.getIdentifierFieldValue("ix");
+ int hiy = n.getIdentifierFieldValue("iy");
+ double energy = n.getCorrectedEnergy();
+// writeHits.append(String.format("EcalHit\t%d\t%d\t%f%n", hix, hiy, energy));
+ }
+
+
+ for (Map.Entry<CalorimeterHit, CalorimeterHit> entry2 : hitSeedMap.entrySet()) {
+ if ((entry2.getKey() == entry2.getValue())&&(entry2.getKey().getCorrectedEnergy()>=seedEnergyThreshold)
+ &&(seedEnergyTot.get(entry2.getKey())>=clusterEnergyThreshold)) {//seed and passes all thresholds
+ int six = entry2.getKey().getIdentifierFieldValue("ix");
+ int siy = entry2.getKey().getIdentifierFieldValue("iy");
+ double energy = seedEnergyTot.get(entry2.getKey());
+// writeHits.append(String.format("Cluster\t%d\t%d\t%f%n", six, siy, energy));
+
+ cluster.setParameters(entry2.getKey());
cluster.addHit(entry2.getKey());
-
- for (Map.Entry<CalorimeterHit, CalorimeterHit> entry3 : clusterHits.entrySet()){
- if (entry3.getValue() == entry2.getValue()){
- writeHits.append("CompHit" + "\t" + entry3.getKey().getIdentifierFieldValue("ix")+ "\t"
- +entry3.getKey().getIdentifierFieldValue("iy") + "\n");
-
- cluster.addHit(entry3.getKey());
- }
- }
- for (Map.Entry<CalorimeterHit, List<CalorimeterHit>> entry4 : commonHits.entrySet()){
- if (entry4.getValue().contains(entry2.getKey())){
- writeHits.append("SharHit" + "\t" + entry4.getKey().getIdentifierFieldValue("ix")+ "\t"
- +entry4.getKey().getIdentifierFieldValue("iy") + "\n");
-
- cluster.addHit(entry4.getKey());
-
- }
- }
-
- clusters.add(cluster);
- }
- }
- writeHits.append("EndEvent\n");
-
- }
-
- //Clear all maps for next event iteration
- hitID.clear();
- clusterHits.clear();
- seedHits.clear();
- commonHits.clear();
- chitList.clear();
- seedEnergy.clear();
-
- return clusters;
-
-
-
- }
+ for (Map.Entry<CalorimeterHit, CalorimeterHit> entry3 : hitSeedMap.entrySet()) {
+ if (entry3.getValue() == entry2.getValue()) {
+ int ix = entry3.getKey().getIdentifierFieldValue("ix");
+ int iy = entry3.getKey().getIdentifierFieldValue("iy");
+// writeHits.append(String.format("CompHit\t%d\t%d%n", ix, iy));
+
+ cluster.addHit(entry3.getKey());
+ }
+ }
+ for (Map.Entry<CalorimeterHit, List<CalorimeterHit>> entry4 : commonHits.entrySet()) {
+ if (entry4.getValue().contains(entry2.getKey())) {
+ int ix = entry4.getKey().getIdentifierFieldValue("ix");
+ int iy = entry4.getKey().getIdentifierFieldValue("iy");
+// writeHits.append(String.format("SharHit\t%d\t%d%n", ix, iy));
+
+ cluster.addHit(entry4.getKey());
+ }
+ }
+
+ clusterList.add(cluster);
+ }
+ }
+
+ // Write the event termination header.
+// writeHits.append("EndEvent\n");
+ } //End event display output loop.
+
+
+
+
+
+ // Return the resulting cluster list.
+ return clusterList;
+ }
public void endOfData() {
- try{
- writeHits.close();
- }
- catch (IOException e){ }
+ // Close the event display output writer.
+ try { writeHits.close(); }
+ catch (IOException e) { }
}
-
- private class EnergyComparator implements Comparator<CalorimeterHit>{
-
- @Override
- public int compare(CalorimeterHit o1, CalorimeterHit o2) {
- // TODO Auto-generated method stub
- double diff = o1.getCorrectedEnergy()-o2.getCorrectedEnergy();
- if(diff < 0) { return 1; }
- if(diff > 0) { return -1; }
- else { return 0; }
- }
- }
+
+ private static class EnergyComparator implements Comparator<CalorimeterHit> {
+ public int compare(CalorimeterHit o1, CalorimeterHit o2) {
+ // If the energies are equivalent, the same, the two hits
+ // are considered equivalent.
+ if(o1.getCorrectedEnergy() == o2.getCorrectedEnergy()) { return 0; }
+
+ // Higher energy hits are ranked higher than lower energy hits.
+ else if(o1.getCorrectedEnergy() > o2.getCorrectedEnergy()) { return -1; }
+
+ // Lower energy hits are ranked lower than higher energy hits.
+ else { return 1; }
+ }
+ }
}
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalClusterer.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalClusterer.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -39,6 +39,8 @@
boolean oddX;
// Map of crystals to their neighbors.
NeighborMap neighborMap = null;
+
+ HPSEcalCluster cluster = new HPSEcalCluster();
public EcalClusterer() {
}
@@ -77,6 +79,10 @@
}
public void detectorChanged(Detector detector) {
+
+ // Must be set to use database conditions
+ cluster.setDetector(detector);
+
// Get the Subdetector.
ecal = (HPSEcal3) detector.getSubdetector(ecalName);
@@ -158,7 +164,7 @@
// Did we find a seed?
if (isSeed) {
// Make a cluster from the hit list.
- HPSEcalCluster cluster = new HPSEcalCluster(hit);
+ cluster.setParameters(hit);
cluster.addHit(hit);
for (CalorimeterHit clusHit : neighborHits) {
cluster.addHit(clusHit);
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalConverterDriver.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalConverterDriver.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -2,9 +2,16 @@
import java.util.ArrayList;
import java.util.List;
+
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
import org.lcsim.event.RawCalorimeterHit;
+import org.lcsim.geometry.Detector;
import org.lcsim.util.Driver;
import org.lcsim.lcio.LCIOConstants;
@@ -14,6 +21,13 @@
* @version $Id: EcalConverterDriver.java,v 1.1 2013/02/25 22:39:24 meeg Exp $
*/
public class EcalConverterDriver extends Driver {
+
+ // To import database conditions
+ static EcalConditions ecalConditions = null;
+ static IIdentifierHelper helper = null;
+ static EcalChannelCollection channels = null;
+
+ HPSCalorimeterHit h = new HPSCalorimeterHit();
String rawCollectionName;
String ecalReadoutName = "EcalHits";
@@ -23,6 +37,25 @@
// double pedestal = 0.0;
double period = 4.0;
double dt = 0.0;
+
+ @Override
+ public void detectorChanged(Detector detector) {
+
+ // set the detector for the converter
+ h.setDetector(detector);
+
+ // ECAL combined conditions object.
+ ecalConditions = ConditionsManager.defaultInstance()
+ .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+
+ // List of channels.
+ channels = ecalConditions.getChannelCollection();
+
+ // ID helper.
+ helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
+
+ System.out.println("You are now using the database conditions for EcalRawConverterDriver.");
+ }
public EcalConverterDriver() {
flags = 0;
@@ -77,7 +110,10 @@
}
private CalorimeterHit HitDtoA(RawCalorimeterHit hit) {
- return new HPSCalorimeterHit(DtoA(hit.getAmplitude(), hit.getCellID()), period * hit.getTimeStamp() + dt, hit.getCellID(), 0);
+
+ h.setParameters(DtoA(hit.getAmplitude(), hit.getCellID()), period * hit.getTimeStamp() + dt, hit.getCellID(), 0);
+
+ return h;
}
// private RawCalorimeterHit HitAtoD(CalorimeterHit hit) {
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalEdepToTriggerConverterDriver.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalEdepToTriggerConverterDriver.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -3,12 +3,15 @@
import java.util.ArrayList;
import java.util.List;
+
+//import org.hps.conditions.deprecated.EcalConditions;
import org.hps.conditions.ConditionsDriver;
import org.hps.conditions.TableConstants;
import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
import org.hps.conditions.ecal.EcalChannel.GeometryId;
import org.hps.conditions.ecal.EcalChannelConstants;
import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalConditionsUtil;
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.detector.identifier.IIdentifier;
import org.lcsim.detector.identifier.IIdentifierHelper;
@@ -26,9 +29,9 @@
*/
public class EcalEdepToTriggerConverterDriver extends Driver {
- EcalConditions ecalConditions = null;
- IIdentifierHelper helper = null;
- EcalChannelCollection channels = null;
+ static EcalConditions ecalConditions = null;
+ static IIdentifierHelper helper = null;
+ static EcalChannelCollection channels = null;
private String ecalReadoutName = "EcalHits";
private String inputCollection = "EcalHits";
private String readoutCollection = "EcalCalHits";
@@ -36,14 +39,17 @@
private boolean applyBadCrystalMap = true;
private double tp = 14.0;
private double readoutPeriod = 4.0;
- private int readoutThreshold = 50;
- private int triggerThreshold = 80;
+ private int readoutThreshold = 10;
+ private int triggerThreshold = 10;
private int truncateScale = 128;
private double pulseIntegral = tp * Math.E / readoutPeriod;
private double gainScale = 1.0; //gain miscalibration factor
private double _gain = -1.0; //constant gain, activated if >0
private boolean addNoise = false;
private double pePerMeV = 2.0; //photoelectrons per MeV, used to calculate noise
+ private static boolean isBadChannelLoaded = true;
+ HPSCalorimeterHit h = new HPSCalorimeterHit();
+ HPSCalorimeterHit h2 = new HPSCalorimeterHit();
public EcalEdepToTriggerConverterDriver() {
}
@@ -88,18 +94,33 @@
}
@Override
- public void detectorChanged(Detector detector) {
+ public void detectorChanged(Detector detector) {
+
+ //Must be set to use the database conditions
+ h.setDetector(detector);
+ h2.setDetector(detector);
+
// ECAL combined conditions object.
ecalConditions = ConditionsManager.defaultInstance()
.getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
// List of channels.
- channels = ecalConditions.getChannelMap();
+ channels = ecalConditions.getChannelCollection();
// ID helper.
helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
+
+ System.out.println("You are now using the database conditions for EcalEdepToTriggerConverterDriver.");
}
+ public static boolean isBadCrystal(CalorimeterHit hit) {
+
+ // Get the channel data.
+ EcalChannelConstants channelData = findChannel(hit.getCellID());
+
+ return isBadChannelLoaded ? channelData.isBadChannel() : false;
+ }
+
@Override
public void process(EventHeader event) {
ArrayList<CalorimeterHit> triggerHits = new ArrayList<CalorimeterHit>();
@@ -109,11 +130,7 @@
List<CalorimeterHit> hits = event.get(CalorimeterHit.class, inputCollection);
for (CalorimeterHit hit : hits) {
-
- // Get the channel data.
- EcalChannelConstants channelData = findChannel(hit.getCellID());
-
- if (applyBadCrystalMap && channelData.isBadChannel()) {
+ if (applyBadCrystalMap && isBadCrystal(hit)) {
continue;
}
double amplitude = hitAmplitude(hit);
@@ -162,7 +179,8 @@
int truncatedIntegral = (int) Math.floor(triggerIntegral / truncateScale);
if (truncatedIntegral > 0) {
- return new HPSCalorimeterHit(truncatedIntegral, hit.getTime(), hit.getCellID(), 0);
+ h.setParameters(truncatedIntegral, hit.getTime(), hit.getCellID(), 0);
+ return h;
}
return null;
}
@@ -200,8 +218,8 @@
// System.out.format("dumb: %f, full: %f\n",hit.getRawEnergy() * 1000.0,readoutIntegral * HPSEcalConditions.physicalToGain(id));
// System.out.format("readout: %f %f\n", amplitude, integral);
- CalorimeterHit h = new HPSCalorimeterHit(integral, hit.getTime(), hit.getCellID(), 0);
- return h;
+ h2.setParameters(integral, hit.getTime(), hit.getCellID(), 0);
+ return h2;
}
private double hitAmplitude(CalorimeterHit hit) {
@@ -241,24 +259,20 @@
* @param cellID (long)
* @return channel constants (EcalChannelConstants)
*/
- private EcalChannelConstants findChannel(long cellID) {
+ private static EcalChannelConstants findChannel(long cellID) {
// Make an ID object from raw hit ID.
IIdentifier id = new Identifier(cellID);
// Get physical field values.
+ int system = helper.getValue(id, "system");
int x = helper.getValue(id, "ix");
int y = helper.getValue(id, "iy");
// Create an ID to search for in channel collection.
- GeometryId geometryId = new GeometryId();
- geometryId.x = x;
- geometryId.y = y;
-
- // Find the ECAL channel.
-// return channels.findChannel(geometryId);
+ GeometryId geometryId = new GeometryId(helper, new int[] { system, x, y });
// Get the channel data.
- return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
+ return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
}
}
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverter.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverter.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -29,12 +29,15 @@
private boolean constantGain = false;
private double gain;
private boolean use2014Gain = true;
- Detector detector = null;
+ Detector detector = null;
static EcalConditions ecalConditions = null;
static IIdentifierHelper helper = null;
static EcalChannelCollection channels = null;
+ HPSCalorimeterHit h1 = new HPSCalorimeterHit();
+ HPSCalorimeterHit h2 = new HPSCalorimeterHit();
+
public EcalRawConverter() {
}
@@ -74,9 +77,9 @@
long id = hit.getCellID();
double rawEnergy = adcToEnergy(sumADC(hit), id);
// double[] pos = hit.getDetectorElement().getGeometry().getPosition().v();
- CalorimeterHit h = new HPSCalorimeterHit(rawEnergy + 0.0000001, time, id, 0);
+ h1.setParameters(rawEnergy + 0.0000001, time, id, 0);
//+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
- return h;
+ return h1;
}
public CalorimeterHit HitDtoA(RawCalorimeterHit hit, int window, double timeOffset) {
@@ -89,9 +92,9 @@
EcalChannelConstants channelData = findChannel(id);
double adcSum = hit.getAmplitude() - window * channelData.getCalibration().getPedestal();
double rawEnergy = adcToEnergy(adcSum, id);
- CalorimeterHit h = new HPSCalorimeterHit(rawEnergy + 0.0000001, time + timeOffset, id, 0);
+ h2.setParameters(rawEnergy + 0.0000001, time + timeOffset, id, 0);
//+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
- return h;
+ return h2;
}
public RawCalorimeterHit HitAtoD(CalorimeterHit hit, int window) {
@@ -144,8 +147,15 @@
return h;
}
*/
-
+ /**
+ * Must be set when an object EcalRawConverter is created.
+ * @param detector (long)
+ */
void setDetector(Detector detector) {
+
+ h1.setDetector(detector);
+ h2.setDetector(detector);
+
this.detector = detector;
// ECAL combined conditions object.
@@ -182,4 +192,4 @@
return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
}
-}
+}
\ No newline at end of file
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverterDriver.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverterDriver.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -32,10 +32,12 @@
*/
public class EcalRawConverterDriver extends Driver {
+ // To import database conditions
static EcalConditions ecalConditions = null;
static IIdentifierHelper helper = null;
static EcalChannelCollection channels = null;
- EcalRawConverter converter = null;
+
+ EcalRawConverter converter = new EcalRawConverter();
String rawCollectionName = "EcalReadoutHits";
String ecalReadoutName = "EcalHits";
String ecalCollectionName = "EcalCalHits";
@@ -50,7 +52,6 @@
private static boolean isBadChannelLoaded = true;
public EcalRawConverterDriver() {
- converter = new EcalRawConverter();
}
public void setUse2014Gain(boolean use2014Gain) {
@@ -102,6 +103,10 @@
@Override
public void detectorChanged(Detector detector) {
+
+ // set the detector for the converter
+ converter.setDetector(detector);
+
// ECAL combined conditions object.
ecalConditions = ConditionsManager.defaultInstance()
.getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
@@ -118,8 +123,7 @@
* @return false if the channel is a good one, true if it is a bad one
* @param CalorimeterHit
*/
- public static boolean isBadCrystal(CalorimeterHit hit) {
-
+ public static boolean isBadCrystal(CalorimeterHit hit) {
// Get the channel data.
EcalChannelConstants channelData = findChannel(hit.getCellID());
@@ -158,7 +162,7 @@
if (useTimestamps) {
double t0ECal = getTimestamp(SYSTEM_ECAL, event);
double t0Trig = getTimestamp(SYSTEM_TRIGGER, event);
- timeOffset += (t0ECal - t0Trig);
+ timeOffset += (t0ECal - t0Trig) + 200.0;
}
if (useTruthTime) {
double t0ECal = getTimestamp(SYSTEM_ECAL, event);
@@ -263,7 +267,11 @@
return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
}
- // Return crate number from cellID
+ /**
+ * Return crate number from cellID
+ * @param cellID (long)
+ * @return Crate number (int)
+ */
private int getCrate(long cellID) {
EcalConditionsUtil util = new EcalConditionsUtil();
@@ -272,7 +280,11 @@
return util.getCrate(helper, cellID);
}
- // Return slot number from cellID.
+ /**
+ * Return slot number from cellID
+ * @param cellID (long)
+ * @return Slot number (int)
+ */
private int getSlot(long cellID) {
EcalConditionsUtil util = new EcalConditionsUtil();
@@ -281,4 +293,3 @@
}
}
-
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalReadoutToTriggerConverterDriver.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalReadoutToTriggerConverterDriver.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -49,6 +49,8 @@
private double timeShift = 0;
private int truncateScale = 128;
private static boolean isBadChannelLoaded = true;
+
+ HPSCalorimeterHit h = new HPSCalorimeterHit();
public EcalReadoutToTriggerConverterDriver() {
}
@@ -93,7 +95,11 @@
}
@Override
- public void detectorChanged(Detector detector) {
+ public void detectorChanged(Detector detector) {
+
+ // Must be set to use database conditions
+ h.setDetector(detector);
+
// ECAL combined conditions object.
ecalConditions = ConditionsManager.defaultInstance()
.getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
@@ -203,7 +209,7 @@
if (truncatedIntegral <= 0) {
truncatedIntegral = 0;
}
- CalorimeterHit h = new HPSCalorimeterHit(truncatedIntegral, hitTime, id, 0);
+ h.setParameters(truncatedIntegral, hitTime, id, 0);
// CalorimeterHit h = new HPSRawCalorimeterHit(triggerIntegral + 0.0000001, hit.getPosition(), hitTime, id, 0);
//+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
return h;
@@ -271,4 +277,3 @@
}
}
-
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalTriggerFilterDriver.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalTriggerFilterDriver.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -44,6 +44,8 @@
private int bottomDelay = 5;
private Queue<List<CalorimeterHit>> topHitsQueue = null;
private Queue<List<CalorimeterHit>> bottomHitsQueue = null;
+
+ HPSCalorimeterHit h = new HPSCalorimeterHit();
public EcalTriggerFilterDriver() {
}
@@ -74,6 +76,10 @@
@Override
public void detectorChanged(Detector detector) {
+
+ // Must be set to use database conditions
+ h.setDetector(detector);
+
// ECAL combined conditions object.
ecalConditions = ConditionsManager.defaultInstance()
.getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
@@ -141,8 +147,9 @@
// Creating the new channel from cell id, ix and iy, then reading its ID
long newID = makeID(ix,iy);
+ h.setParameters(hit.getRawEnergy(), hit.getTime()+delay*4, newID, hit.getType());
//make new hit; set position to null so it gets recalculated
- return new HPSCalorimeterHit(hit.getRawEnergy(), hit.getTime()+delay*4, newID, hit.getType());
+ return h;
}
/**
@@ -221,4 +228,3 @@
return newID;
}
}
-
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/FADCConverterDriver.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/FADCConverterDriver.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -150,4 +150,3 @@
}
}
-
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/GTPEcalClusterer.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/GTPEcalClusterer.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -34,6 +34,8 @@
* @author Sho Uemura
*/
public class GTPEcalClusterer extends Driver {
+
+ HPSEcalCluster cluster = new HPSEcalCluster();
/**
* <b>calorimeter</b><br/><br/>
@@ -110,6 +112,10 @@
*/
@Override
public void detectorChanged(Detector detector) {
+
+ // Must be set to use database conditions
+ cluster.setDetector(detector);
+
// Get the calorimeter object.
calorimeter = (HPSEcal3) detector.getSubdetector(ecalName);
@@ -153,7 +159,7 @@
// Store the crystals that are part of this potential cluster,
// starting with the cluster seed candidate.
- HPSEcalCluster cluster = new HPSEcalCluster(currentHit);
+ cluster.setParameters(currentHit);
cluster.addHit(currentHit);
// Get the set of neighbors for this hit.
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/HPSCalorimeterHit.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/HPSCalorimeterHit.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -4,11 +4,24 @@
import java.util.Comparator;
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ConditionsDriver;
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ecal.EcalChannel.GeometryId;
+import org.hps.conditions.ecal.EcalChannelConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalConditionsUtil;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.detector.identifier.Identifier;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.IDetectorElementContainer;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.base.BaseCalorimeterHit;
+import org.lcsim.geometry.Detector;
/**
* An implementation of CalorimeterHit, with a constructor that sets rawEnergy
@@ -19,7 +32,21 @@
*/
public class HPSCalorimeterHit extends BaseCalorimeterHit {
+ Detector detector = null;
+ static EcalConditions ecalConditions = null;
+ static IIdentifierHelper helper = null;
+ static EcalChannelCollection channels = null;
+
/**
+ * Fully qualified constructor
+ * WARNING: any HPSCalorimeterHit created should be created empty
+ * then yourHit.setDetector(detector) called in detectorChanged
+ * then one can use yourHit.setParameters(...) to set the parameters
+ */
+ public HPSCalorimeterHit() {
+ }
+
+ /**
* Fully qualified constructor that sets rawEnergy
*
* @param energy Raw energy for this cell
@@ -28,7 +55,7 @@
* @param id Cell ID
* @param type Type
*/
- public HPSCalorimeterHit(double energy, double time, long id, int type) {
+ public void setParameters(double energy, double time, long id, int type) {
this.rawEnergy = energy;
// if (position != null) {
// this.positionVec = new BasicHep3Vector(position);
@@ -44,7 +71,7 @@
public IDetectorElement getDetectorElement() {
if (de == null) {
// findDetectorElementByPosition();
- IDetectorElementContainer detectorElements = EcalConditions.getSubdetector().getDetectorElement().findDetectorElement(getIdentifier());
+ IDetectorElementContainer detectorElements = detector.getDetectorElement().findDetectorElement(getIdentifier());
if (detectorElements.size() != 1) {
throw new RuntimeException("Expected exactly one DetectorElement matching ID " + getIdentifier() + ", got " + detectorElements.size());
} else {
@@ -72,4 +99,25 @@
return Double.compare(o1.getTime(), o2.getTime());
}
}
+
+ /**
+ * Must be set when an object HPSCalorimeterHit is created.
+ * @param detector (long)
+ */
+ public void setDetector(Detector detector) {
+ this.detector = detector;
+
+ // ECAL combined conditions object.
+ ecalConditions = ConditionsManager.defaultInstance()
+ .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+
+ // List of channels.
+ channels = ecalConditions.getChannelCollection();
+
+ // ID helper.
+ helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
+
+ System.out.println("You are now using the database conditions for HPSCalorimeterHit.");
+ }
+
}
java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/HPSEcalCluster.java 2014-06-03 09:59:04 UTC (rev 655)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/HPSEcalCluster.java 2014-06-03 14:19:19 UTC (rev 656)
@@ -3,11 +3,19 @@
import hep.physics.vec.BasicHep3Vector;
import hep.physics.vec.Hep3Vector;
import hep.physics.vec.VecOp;
+
import java.util.List;
+
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.lcsim.conditions.ConditionsManager;
import org.lcsim.detector.IGeometryInfo;
+import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.detector.solids.Trd;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.base.BaseCluster;
+import org.lcsim.geometry.Detector;
/**
* Cluster with position defined by seed hit (for 1-bit trigger)
@@ -20,6 +28,13 @@
private CalorimeterHit seedHit = null;
private long cellID;
+ HPSCalorimeterHit h1 = new HPSCalorimeterHit();
+
+ Detector detector = null;
+ static EcalConditions ecalConditions = null;
+ static IIdentifierHelper helper = null;
+ static EcalChannelCollection channels = null;
+
static final double eCriticalW = 800.0*ECalUtils.MeV/(74+1);
static final double radLenW = 8.8; //mm
double[] electronPosAtDepth = new double[3];
@@ -27,11 +42,37 @@
double[] photonPosAtDepth = new double[3];
private boolean needsPhotonPosCalculation = true;
- public HPSEcalCluster(Long cellID) {
+ /**
+ * Must be set when an object EcalRawConverter is created.
+ * @param detector (long)
+ */
+ public void setDetector(Detector detector) {
+
+ h1.setDetector(detector);
+
+ this.detector = detector;
+
+ // ECAL combined conditions object.
+ ecalConditions = ConditionsManager.defaultInstance()
+ .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+
+ // List of channels.
+ channels = ecalConditions.getChannelCollection();
+
+ // ID helper.
+ helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
+
+ System.out.println("You are now using the database conditions for HPSEcalCluster.");
+ }
+
+ public HPSEcalCluster() {
+ }
+
+ public void setParameters(Long cellID) {
this.cellID = cellID;
}
- public HPSEcalCluster(CalorimeterHit seedHit) {
+ public void setParameters(CalorimeterHit seedHit) {
this.seedHit = seedHit;
this.cellID = seedHit.getCellID();
}
@@ -42,7 +83,8 @@
if (hit == null) {
throw new RuntimeException("HPSEcalCluster has no hits");
}
- seedHit = new HPSCalorimeterHit(0.0, 0.0, cellID, hit.getType());
+ h1.setParameters(0.0, 0.0, cellID, hit.getType());
+ seedHit = h1;
seedHit.setMetaData(hit.getMetaData());
}
return seedHit;
SVNspam 0.1