Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 49 additions & 11 deletions ecal-recon/src/main/java/org/hps/recon/ecal/HodoRawConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import org.lcsim.event.RawTrackerHit;
import org.hps.conditions.hodoscope.HodoscopeConditions;
import org.hps.conditions.hodoscope.HodoscopeChannel.GeometryId;
import org.hps.conditions.hodoscope.HodoscopeChannel;
import org.hps.conditions.hodoscope.HodoscopeChannelConstants;
import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
import java.util.ArrayList;
import java.util.Map;
import org.lcsim.geometry.Subdetector;

public class HodoRawConverter {

Expand All @@ -20,6 +23,11 @@ public class HodoRawConverter {
private boolean useUserGain = false;
private double userGains = 0;
private int tet = HodoConstants.TET_AllCh;

private boolean isMC = false;

private Subdetector subDetector;
private IIdentifierHelper helper;

public ArrayList<Integer> FindThresholdCrossings(RawTrackerHit hit, double ped) {

Expand Down Expand Up @@ -70,7 +78,7 @@ public ArrayList<Integer> FindThresholdCrossings(RawTrackerHit hit, double ped)
public ArrayList<CalorimeterHit> getCaloHits(RawTrackerHit hit, ArrayList<Integer> thr_crosings, double ped) {

// Getting the cellID of the hit
final long cellID = hit.getCellID();
long cellID = hit.getCellID();

// ADC values for this hit
final short samples[] = hit.getADCValues();
Expand All @@ -84,6 +92,12 @@ public ArrayList<CalorimeterHit> getCaloHits(RawTrackerHit hit, ArrayList<Intege
gain = findChannel(cellID).getGain().getGain();
}
//System.out.println("The Gains = " + findChannel(cellID).getGain().toString());

if(isMC) {
int[] identifier = getHodoIdentifiers(cellID);
GeometryId id_geometry = new GeometryId(helper, new int[]{subDetector.getSystemID(), identifier[0], identifier[1], identifier[2], identifier[3]});
cellID = id_geometry.encode();
}

ArrayList<CalorimeterHit> curHits = new ArrayList<CalorimeterHit>();

Expand All @@ -105,7 +119,7 @@ public ArrayList<CalorimeterHit> getCaloHits(RawTrackerHit hit, ArrayList<Intege
double Energy = ADC_Sum * gain;
double time = crs_time * HodoConstants.NSPerSample;

//System.out.println("time = " + time + " gain = " + gain + " Energy = " + Energy + "ADC Sum is " + ADC_Sum);
//System.out.println("time = " + time + " gain = " + gain + " Energy = " + Energy + "ADC Sum is " + ADC_Sum);
curHits.add(CalorimeterHitUtilities.create(Energy, time, cellID));
}

Expand All @@ -117,31 +131,46 @@ public double getPedestal(EventHeader event, long cellid) {
if (useRunningPedestal && event != null) {

Map<HodoscopeChannel, Double> runningPedMap = (Map<HodoscopeChannel, Double>) event.get("HodoRunningPedestals");
HodoscopeChannel chan = hodoConditions.getChannels().findGeometric(cellid);


HodoscopeChannel chan;
if(!isMC)
chan = hodoConditions.getChannels().findGeometric(cellid);
else
chan = hodoConditions.getChannels().findChannel((int)cellid);

return runningPedMap.get(chan);
} else {
return findChannel(cellid).getCalibration().getPedestal();
}
}

public void setConditions(HodoscopeConditions condition) {
public void setConditions(HodoscopeConditions condition, Subdetector subDetector, IIdentifierHelper helper) {
hodoConditions = condition;
this.subDetector = subDetector;
this.helper = helper;
}

public HodoscopeChannelConstants findChannel(long cellID) {
//System.out.println(hodoConditions.getChannels().findGeometric(cellID));
return hodoConditions.getChannelConstants(hodoConditions.getChannels().findGeometric(cellID));
if(!isMC)
return hodoConditions.getChannelConstants(hodoConditions.getChannels().findGeometric(cellID));
else
return hodoConditions.getChannelConstants(hodoConditions.getChannels().findChannel((int)cellID));
}

// =========== Computed Hodoscop identifiers from cellID
public int[] getHodoIdentifiers(long cellID) {

HodoscopeChannel chan;
if(!isMC)
chan = hodoConditions.getChannels().findGeometric(cellID);
else
chan = hodoConditions.getChannels().findChannel((int)cellID);

int[] hodo_ids = new int[4];
hodo_ids[0] = hodoConditions.getChannels().findGeometric(cellID).getIX();
hodo_ids[1] = hodoConditions.getChannels().findGeometric(cellID).getIY();
hodo_ids[2] = hodoConditions.getChannels().findGeometric(cellID).getLayer();
hodo_ids[3] = hodoConditions.getChannels().findGeometric(cellID).getHole();
hodo_ids[0] = chan.getIX();
hodo_ids[1] = chan.getIY();
hodo_ids[2] = chan.getLayer();
hodo_ids[3] = chan.getHole();

return hodo_ids;
}
Expand All @@ -159,5 +188,14 @@ public void setUseUserGain(double a_usergain) {
this.userGains = a_usergain;
useUserGain = true;
}

/**
* Set MC mode.
*
* @param isMC
*/
public void setIsMC(final boolean isMC) {
this.isMC = isMC;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import org.lcsim.util.Driver;
import org.hps.conditions.database.DatabaseConditionsManager;
import org.hps.conditions.hodoscope.HodoscopeConditions;
import org.hps.conditions.hodoscope.HodoscopeChannel.GeometryId;
import org.lcsim.detector.IDetectorElementContainer;
//import org.hps.conditions.hodoscope.HodoscopeChannel.GeometryId;
import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.detector.identifier.Identifier;
//import org.lcsim.detector.identifier.Identifier;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.RawTrackerHit;
import org.lcsim.event.EventHeader;
import org.lcsim.geometry.Detector;
import org.lcsim.geometry.Subdetector;
import org.lcsim.lcio.LCIOConstants;

import java.util.List;
Expand All @@ -20,11 +27,17 @@ public class HodoRawConverterDriver extends Driver {
private HodoscopeConditions hodoConditions = null;

private HodoRawConverter converter = null;

private boolean isMC = false;

// ===== The Mode1 Hodo hit collection name =====
private String rawCollectionName = "HodoReadoutHits";

private String hodoCollectionName = "HodoCalHits";

private IIdentifierHelper helper = null;
private Subdetector subDetector;
private static final String subdetectorName = "Hodoscope";

// ===== **NOTE** Seems this name can not be arbitrary, it is taken from the detector
// ===== For example you can find out this by running this method of the detector
Expand All @@ -42,6 +55,17 @@ public void setUseRunningPedestal(boolean useRunningPedestal) {
public void setUseUserGains(double aUserGain){
converter.setUseUserGain(aUserGain);
}


/**
* Set MC mode.
*
* @param isMC
*/
public void setIsMC(boolean isMC){
this.isMC = isMC;
converter.setIsMC(isMC);
}

public void setTETAllChannels(int arg_tet) {
if (arg_tet <= 0)
Expand All @@ -59,11 +83,14 @@ public void startOfData() {

@Override
public void detectorChanged(Detector detector) {

subDetector = DatabaseConditionsManager.getInstance().getDetectorObject().getSubdetector(subdetectorName);
helper = subDetector.getDetectorElement().getIdentifierHelper();

// Hodo conditions object.
hodoConditions = DatabaseConditionsManager.getInstance().getHodoConditions();

converter.setConditions(hodoConditions);
converter.setConditions(hodoConditions, subDetector, helper);

}

Expand Down Expand Up @@ -95,12 +122,21 @@ public void process(EventHeader event) {
ArrayList<Integer> thr_crosings = converter.FindThresholdCrossings(hit, ped);

// ===== For now we will calculate coarse time, which is the threshold crossing sample time.
// ===== Later will implement the mode7 time
// ===== Later will implement the mode7 time
ArrayList<CalorimeterHit> hits_in_this_channel = converter.getCaloHits(hit, thr_crosings, ped);

// Propagate the detector element information to these found_hits so it can be used later.
for(CalorimeterHit found_hit: hits_in_this_channel) {
found_hit.setDetectorElement(hit.getDetectorElement());
if(!isMC)
found_hit.setDetectorElement(hit.getDetectorElement());
else {
// Set detector element for MC hits
int[] identifier = converter.getHodoIdentifiers(cellID);
GeometryId id_geometry = new GeometryId(helper, new int[]{subDetector.getSystemID(), identifier[0], identifier[1], identifier[2], 0});
long id_det = id_geometry.encode();
IDetectorElementContainer srch = subDetector.getDetectorElement().findDetectorElement(new Identifier(id_det));
found_hit.setDetectorElement(srch.get(0));
}
}

hodoHits.addAll(hits_in_this_channel);
Expand Down Expand Up @@ -134,7 +170,7 @@ public void process(EventHeader event) {
SimpleGenericObject generic_cl_time = new SimpleGenericObject();
SimpleGenericObject generic_cl_detid = new SimpleGenericObject();
ArrayList<Integer> paired = new ArrayList<Integer>();

for (int i = 0; i < hodoHits.size(); i++) {

// Check if this hit is already paired, if so, then let's pass to the next hit
Expand All @@ -158,11 +194,12 @@ public void process(EventHeader event) {
cl_Energy = ArrayUtils.add(cl_Energy, this_hit.getRawEnergy());
cl_Time = ArrayUtils.add(cl_Time, this_hit.getTime());
cl_detid = ArrayUtils.add(cl_detid, (int)this_hit.getDetectorElement().getIdentifier().getValue());

continue;
}

boolean pair_found = false;


for (int j = i + 1; j < hodoHits.size(); j++) {

Expand Down Expand Up @@ -240,6 +277,15 @@ public void process(EventHeader event) {

}
}

/**
* Set the input collection name (source).
*
* @param inputCollectionName the input collection name
*/
public void setInputCollectionName(final String inputCollectionName) {
this.rawCollectionName = inputCollectionName;
}

/**
* Set to <code>true</code> to use a running pedestal calibration from mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class HodoRunningPedestalDriver extends Driver {
// (discard older readouts ; negative = no time limit)
private long maxLookbackTime = -1; // units = ms

private static final String rawCollectionName = "HodoReadoutHits";
private String rawCollectionName = "HodoReadoutHits";
private static final String extraDataRelationsName = "HodoReadoutExtraDataRelations";
private static final String runningPedestalsName = "HodoRunningPedestals";

Expand All @@ -55,6 +55,8 @@ public class HodoRunningPedestalDriver extends Driver {

private boolean debug = false;
private HodoscopeConditions hodoConditions = null;

private boolean isMC = false;

public HodoRunningPedestalDriver() {
}
Expand Down Expand Up @@ -276,12 +278,35 @@ public HodoscopeChannel findChannel(int channel_id) {
return hodoConditions.getChannels().findChannel(channel_id);
}

public HodoscopeChannel findChannel(RawTrackerHit hit) {
return hodoConditions.getChannels().findGeometric(hit.getCellID());
public HodoscopeChannel findChannel(RawTrackerHit hit) {
if(!isMC)
return hodoConditions.getChannels().findGeometric(hit.getCellID());
else
return hodoConditions.getChannels().findChannel((int)hit.getCellID());
}

public HodoscopeChannel findChannel(RawCalorimeterHit hit) {
return hodoConditions.getChannels().findGeometric(hit.getCellID());
if(!isMC)
return hodoConditions.getChannels().findGeometric(hit.getCellID());
else
return hodoConditions.getChannels().findChannel((int)hit.getCellID());
}


/**
* Set the input collection name (source).
*
* @param inputCollectionName the input collection name
*/
public void setInputCollectionName(final String inputCollectionName) {
this.rawCollectionName = inputCollectionName;
}

/**
* Set MC mode.
*
* @param isMC
*/
public void setIsMC(final boolean isMC) {
this.isMC = isMC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@
<outputCollectionName>EcalClustersCorr</outputCollectionName>
</driver>
<!-- Hodo reconstruction drivers -->
<driver name="HodoRunningPedestal" type="org.hps.recon.ecal.HodoRunningPedestalDriver">
<driver name="HodoRunningPedestal"
type="org.hps.recon.ecal.HodoRunningPedestalDriver">
<inputCollectionName>HodoscopeReadoutHits</inputCollectionName>
<logLevel>CONFIG</logLevel>
<isMC>true</isMC>
</driver>
<driver name="HodoRawConverter" type="org.hps.recon.ecal.HodoRawConverterDriver">
<useRunningPedestal>true</useRunningPedestal>
<inputCollectionName>HodoscopeReadoutHits</inputCollectionName>
<tETAllChannels>8</tETAllChannels>
<logLevel>CONFIG</logLevel>
<isMC>true</isMC>
</driver>
<!-- SVT reconstruction drivers -->
<!-- Driver used to associate raw tracker hits to corresponding sensor. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@
<!-- Hodo reconstruction drivers -->

<driver name="HodoRunningPedestal" type="org.hps.recon.ecal.HodoRunningPedestalDriver">
<inputCollectionName>HodoscopeReadoutHits</inputCollectionName>
<logLevel>CONFIG</logLevel>
<isMC>true</isMC>
</driver>

<driver name="HodoRawConverter" type="org.hps.recon.ecal.HodoRawConverterDriver">
<useRunningPedestal>true</useRunningPedestal>
<inputCollectionName>HodoscopeReadoutHits</inputCollectionName>
<tETAllChannels>8</tETAllChannels>
<logLevel>CONFIG</logLevel>
<isMC>true</isMC>
</driver>

<!-- SVT reconstruction drivers -->
Expand Down