lcsim/src/org/lcsim/rpc
diff -u -r1.1 -r1.2
--- PadDigiDriver.java 4 Feb 2013 22:14:39 -0000 1.1
+++ PadDigiDriver.java 5 Feb 2013 00:25:57 -0000 1.2
@@ -10,35 +10,37 @@
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.event.LCRelation;
import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.event.base.BaseCalorimeterHit;
+import org.lcsim.event.base.BaseLCRelation;
import org.lcsim.geometry.IDDecoder;
import org.lcsim.util.Driver;
import org.lcsim.util.lcio.LCIOConstants;
-// FIXME: The code to for charge deposition on barrel and endcap is essentially copied and pasted.
-// This should be one method called with parameters.
-// TODO: Represent output data as RawCalorimeterHit possible. Charge should be converted to int from double.
+// FIXME: The code for charge deposition on barrel and endcap is essentially copied and pasted.
+// This should instead be one method called with different parameters.
// TODO: Move histograms to separate Driver.
-// TODO: Add settable input parameters:
-// -q0 (what is it???)
public class PadDigiDriver extends Driver
{
// Charge distribution data.
ChargeDistributionTables chargeTables;
- // charge cut
- // units???
+ // charge cut in pC
double minimumCharge = 0.400;
// distance cut in mm
double distanceCut = 0.90;
- // Collection names.
+ // Collection names with defaults. These can all be overridden via set methods.
private String barrelInputCollection = "HcalBarrelHits";
private String endcapInputCollection = "HcalEndcapHits";
- private static String defaultOutputTag = "_pad_digi";
- private String barrelOutputCollection = barrelInputCollection + defaultOutputTag;
- private String endcapOutputCollection = endcapInputCollection + defaultOutputTag;
+ private static String defaultDigiOutputTag = "_pad_digi";
+ private String barrelOutputCollection = barrelInputCollection + defaultDigiOutputTag;
+ private String endcapOutputCollection = endcapInputCollection + defaultDigiOutputTag;
+ private static String defaultRelationsOutputTag = "_relations";
+ private String barrelOutputRelationCollection = barrelOutputCollection + defaultRelationsOutputTag;
+ private String endcapOutputRelationCollection = endcapOutputCollection + defaultRelationsOutputTag;
public void setMinimumCharge(double minimumCharge)
{
@@ -68,8 +70,18 @@
public void setEndcapOutputCollection(String endcapOutputCollection)
{
this.endcapOutputCollection = endcapOutputCollection;
+ }
+
+ public void setBarrelOutputRelationCollection(String barrelOutputRelationCollection)
+ {
+ this.barrelOutputRelationCollection = barrelOutputRelationCollection;
+ }
+
+ public void setEndcapOutputRelationCollection(String endcapOutputRelationCollection)
+ {
+ this.endcapOutputRelationCollection = endcapOutputRelationCollection;
}
-
+
public void setup() throws Exception
{
// Initialize charge distrubtion tables.
@@ -91,13 +103,13 @@
// FIXME: What are these parameters? Should be settable on Driver?
double q0 = -0.062; // ?????
- List<SimCalorimeterHit> barrelHits = event.get(SimCalorimeterHit.class, barrelInputCollection);
- System.out.println("number of hits in barrel = " + barrelHits.size());
+ List<SimCalorimeterHit> barrelInputHits = event.get(SimCalorimeterHit.class, barrelInputCollection);
+ //System.out.println("number of hits in barrel = " + barrelInputHits.size());
- List<SimCalorimeterHit> endcapHits = event.get(SimCalorimeterHit.class, endcapInputCollection);
- System.out.println("number of hits in endcap = " + endcapHits.size());
+ List<SimCalorimeterHit> endcapInputHits = event.get(SimCalorimeterHit.class, endcapInputCollection);
+ //System.out.println("number of hits in endcap = " + endcapInputHits.size());
- IDDecoder decoder = event.getMetaData(barrelHits).getIDDecoder();
+ IDDecoder decoder = event.getMetaData(barrelInputHits).getIDDecoder();
/*
* // id = 0 doesn't exist --> id=0 can be used to indicate no cell found decoder.setID(0);
@@ -107,15 +119,21 @@
long[] ordered_ids = new long[25];
ArrayList<Hep3Vector> used_points = new ArrayList<Hep3Vector>();
- int count_points = 0;
+ //int count_points = 0;
- ArrayList<RPCHit> br_rpchits = new ArrayList<RPCHit>(); // hit storage for barrel hits after rpc
+ ArrayList<BaseCalorimeterHit> br_rpchits = new ArrayList<BaseCalorimeterHit>();
+ //ArrayList<RPCHit> br_rpchits = new ArrayList<RPCHit>(); // hit storage for barrel hits after rpc
// simulation
- ArrayList<RPCHit> ec_rpchits = new ArrayList<RPCHit>(); // hit storage for endcap hits after rpc
+ //ArrayList<RPCHit> ec_rpchits = new ArrayList<RPCHit>(); // hit storage for endcap hits after rpc
// simulation
+ ArrayList<BaseCalorimeterHit> ec_rpchits = new ArrayList<BaseCalorimeterHit>();
+
+ ArrayList<LCRelation> barrelRelations = new ArrayList<LCRelation>();
+
+ ArrayList<LCRelation> endcapRelations = new ArrayList<LCRelation>();
int count = 0;
- for (SimCalorimeterHit hit : barrelHits) {
+ for (SimCalorimeterHit hit : barrelInputHits) {
decoder.setID(hit.getCellID());
Hep3Vector cellPos = decoder.getPositionVector();
int ncontribs = hit.getMCParticleCount();
@@ -201,7 +219,7 @@
Hep3Vector stepVec = new BasicHep3Vector(stepPos[0], stepPos[1], stepPos[2]);
int ifound = 0;
- count_points++;
+ //count_points++;
if (used_points.size() > 0) {
for (Hep3Vector ivec : used_points) {
Hep3Vector tmpv = VecOp.sub(ivec, stepVec);
@@ -273,34 +291,44 @@
charge[k] = icharge * (mid1 + mid2 * k2) / (1 + k2);
}
- // if (event.getEventNumber() < 1)
- // System.out.println("barrel charge["+k+"] = "+charge[k]);
-
if ((Math.abs(ordered_ids[k]) > 0) && (charge[k] > 0)) // pad exist on the
// neighber or hit pad
// list, and there's
// charge to deposit
{
- if (br_rpchits.size() == 0) // first hit, just add
- {
- RPCHit tmphit = new RPCHit(ordered_ids[k], charge[k]);
+ // first hit, just add
+ if (br_rpchits.size() == 0) {
+ // Make a new hit.
+ BaseCalorimeterHit tmphit = new BaseCalorimeterHit(ordered_ids[k], charge[k], 0.);
br_rpchits.add(tmphit);
- } else // need to see if the pad is already there
- {
+
+ // Connect digi hit with original hit.
+ barrelRelations.add(new BaseLCRelation(tmphit, hit));
+
+ } else {
+ // need to see if the pad is already there
int hfound = 0;
int j = 0;
+ // FIXME: Should use a map here instead. This loop is probably slow.
while ((hfound == 0) && (j < br_rpchits.size())) {
- if (br_rpchits.get(j).getCid() == ordered_ids[k]) {
+ if (br_rpchits.get(j).getCellID() == ordered_ids[k]) {
hfound = 1;
- br_rpchits.get(j).addCharge(charge[k]);
+ br_rpchits.get(j).addCorrectedEnergy(charge[k]);
+
+ // Connect digi hit with original hit.
+ barrelRelations.add(new BaseLCRelation(br_rpchits.get(j), hit));
}
j++;
}
if (hfound == 0) {
- RPCHit tmphit = new RPCHit(ordered_ids[k], charge[k]);
+ // Make a new hit.
+ BaseCalorimeterHit tmphit = new BaseCalorimeterHit(ordered_ids[k], charge[k], 0.);
br_rpchits.add(tmphit);
+
+ // Connect digi hit with original hit.
+ barrelRelations.add(new BaseLCRelation(tmphit, hit));
}
}
}
@@ -312,12 +340,12 @@
}
used_points.clear();
- count_points = 0;
+ //count_points = 0;
- decoder = event.getMetaData(endcapHits).getIDDecoder();
+ decoder = event.getMetaData(endcapInputHits).getIDDecoder();
count = 0;
- for (SimCalorimeterHit hit : endcapHits) {
+ for (SimCalorimeterHit hit : endcapInputHits) {
decoder.setID(hit.getCellID());
Hep3Vector cellPos = decoder.getPositionVector();
int ncontribs = hit.getMCParticleCount();
@@ -402,7 +430,7 @@
Hep3Vector stepVec = new BasicHep3Vector(stepPos[0], stepPos[1], stepPos[2]);
int ifound = 0;
- count_points++;
+ //count_points++;
if (used_points.size() > 0) {
for (Hep3Vector ivec : used_points) {
// if
@@ -486,24 +514,36 @@
{
if (ec_rpchits.size() == 0) // first hit, just add
{
- RPCHit tmphit = new RPCHit(ordered_ids[k], charge[k]);
+ //RPCHit tmphit = new RPCHit(ordered_ids[k], charge[k]);
+ BaseCalorimeterHit tmphit = new BaseCalorimeterHit(ordered_ids[k], charge[k], 0);
ec_rpchits.add(tmphit);
+
+ // Connect original hit with its digi hit.
+ endcapRelations.add(new BaseLCRelation(tmphit, hit));
+
} else // need to see if the pad is already there
{
int hfound = 0;
int j = 0;
while ((hfound == 0) && (j < ec_rpchits.size())) {
- if (ec_rpchits.get(j).getCid() == ordered_ids[k]) {
+ if (ec_rpchits.get(j).getCellID() == ordered_ids[k]) {
hfound = 1;
- ec_rpchits.get(j).addCharge(charge[k]);
+ ec_rpchits.get(j).addCorrectedEnergy(charge[k]);
+
+ // Connect digi hit with original hit.
+ barrelRelations.add(new BaseLCRelation(ec_rpchits.get(j), hit));
}
j++;
}
if (hfound == 0) {
- RPCHit tmphit = new RPCHit(ordered_ids[k], charge[k]);
+ //RPCHit tmphit = new RPCHit(ordered_ids[k], charge[k]);
+ BaseCalorimeterHit tmphit = new BaseCalorimeterHit(ordered_ids[k], charge[k], 0);
ec_rpchits.add(tmphit);
+
+ // Connect original hit with its digi hit.
+ endcapRelations.add(new BaseLCRelation(tmphit, hit));
}
}
}
@@ -516,26 +556,28 @@
}
used_points.clear();
- count_points = 0;
+ //count_points = 0;
//System.out.println("before thr cut, barrel cells with charge = " + br_rpchits.size());
//System.out.println("before thr cut, endcap cells with charge = " + ec_rpchits.size());
- ArrayList<RPCHit> br_final = new ArrayList<RPCHit>(); // barrel hits after rpc simulation
- ArrayList<RPCHit> ec_final = new ArrayList<RPCHit>(); // endcap hits after rpc simulation
+ ArrayList<BaseCalorimeterHit> barrelHitsFinal = new ArrayList<BaseCalorimeterHit>(); // barrel hits after rpc simulation
+ ArrayList<BaseCalorimeterHit> endcapHitsFinal = new ArrayList<BaseCalorimeterHit>(); // endcap hits after rpc simulation
- decoder = event.getMetaData(barrelHits).getIDDecoder();
+ decoder = event.getMetaData(barrelInputHits).getIDDecoder();
for (int i = 0; i < br_rpchits.size(); i++) {
- if (br_rpchits.get(i).getCharge() > minimumCharge) {
- br_final.add(br_rpchits.get(i));
- }
+ // DEBUG: Removed cut for now.
+ //if (br_rpchits.get(i).getCorrectedEnergy() > minimumCharge) {
+ barrelHitsFinal.add(br_rpchits.get(i));
+ //}
}
- decoder = event.getMetaData(endcapHits).getIDDecoder();
+ decoder = event.getMetaData(endcapInputHits).getIDDecoder();
for (int i = 0; i < ec_rpchits.size(); i++) {
- if (ec_rpchits.get(i).getCharge() > minimumCharge) {
- ec_final.add(ec_rpchits.get(i));
- }
+ // DEBUG: Removed cut for now.
+ //if (ec_rpchits.get(i).getCorrectedEnergy() > minimumCharge) {
+ endcapHitsFinal.add(ec_rpchits.get(i));
+ //}
}
//br_rpchits.clear();
@@ -548,21 +590,27 @@
flag = flag | (1 << LCIOConstants.RCHBIT_ID1);
// Store final collection of barrel hits in event.
- LCMetaData barrelMetaData = event.getMetaData(barrelHits);
+ LCMetaData barrelMetaData = event.getMetaData(barrelInputHits);
event.put(
barrelOutputCollection,
- br_final,
+ barrelHitsFinal,
CalorimeterHit.class,
flag,
barrelMetaData.getName());
// Store final collection of endcap hits in event.
- LCMetaData endcapMetaData = event.getMetaData(endcapHits);
+ LCMetaData endcapMetaData = event.getMetaData(endcapInputHits);
event.put(
endcapOutputCollection,
- ec_final,
+ endcapHitsFinal,
CalorimeterHit.class,
flag,
endcapMetaData.getName());
+
+ // Barrel relations.
+ event.put(barrelOutputRelationCollection, barrelRelations, LCRelation.class, 0);
+
+ // Endcap relations.
+ event.put(endcapOutputRelationCollection, endcapRelations, LCRelation.class, 0);
}
}
\ No newline at end of file