Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing iss887 #919

Merged
merged 25 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
eb91b89
First version lcsim file 2021 MC FEE
andrea-celentano Sep 4, 2021
a881ecc
Explicitly setting the hit threshold in the steering file
andrea-celentano Sep 4, 2021
7f1fcea
Adding two steering files, one to recon data (FEE only), oe to proces…
andrea-celentano Oct 26, 2021
1aa7e16
Fixing two steering files
andrea-celentano Oct 27, 2021
a016ce6
Fixing EcalFEECAlibration2021
andrea-celentano Oct 29, 2021
118b257
fixing steering file
andrea-celentano Oct 29, 2021
aff2696
2021 MC ECAlFEECalibration fixing threshold to 30 MeV
andrea-celentano Jan 17, 2022
ae403ff
Adding 30 MeV thr for 2021 to both data and MC; adding list of broken…
andrea-celentano Feb 15, 2022
4d0c41c
Fixing the IterateGainFactorDriver for the bad channels
andrea-celentano Feb 15, 2022
a3d0fb5
Fixing the IterateGainFactorDriver for the bad channels n.2
andrea-celentano Feb 15, 2022
963d69f
Ecal 2021 slopes file
andrea-celentano Feb 28, 2022
5b9a944
fix
andrea-celentano Feb 28, 2022
f69c22a
Adding 2021 SF driver, MC
andrea-celentano Mar 10, 2022
5ecc511
missing save
andrea-celentano Mar 10, 2022
5e129b8
Adding 2021 SF parameters for MC only
andrea-celentano Mar 22, 2022
d708b76
2021 MC corrections in ClusterCorrectionUtilities
andrea-celentano Mar 22, 2022
a0e5fe8
2021 corrections
andrea-celentano Apr 2, 2022
23ee996
Fix ClusterCorrectionUtilities2021
andrea-celentano Apr 14, 2022
8f60f75
Adding 2021SF_parameters_data.dat, for the moment this is a copy of 2…
andrea-celentano Apr 14, 2022
65b0f2f
Temporary fix to ClusterEnergyCorrection2021.jaava to use always MC c…
andrea-celentano Apr 14, 2022
f9ce849
fix energy correction 2021 to be mc only also for data
andrea-celentano Apr 15, 2022
9be69c5
2021SF for data
andrea-celentano Apr 22, 2022
50b2005
Update ClusterEnergyCorrection2021.java
Apr 28, 2022
91ca608
Added new detector HPS_Run2021Pass2FEE_1pt92
Apr 28, 2022
cfc5124
Merge pull request #918 from JeffersonLab/master
andrea-celentano Jun 27, 2022
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
424 changes: 424 additions & 0 deletions analysis/src/main/java/org/hps/analysis/ecal/SF2021Driver.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
samplingFraction: 1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
samplingFraction: 1.0
791 changes: 791 additions & 0 deletions detector-data/detectors/HPS_Run2021Pass2FEE_1pt92/compact.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: HPS_Run2021Pass2FEE_1pt92
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,43 @@ public void setOutputCollectionName(final String outputCollectionName) {
}

private final String ecalReadoutName = "EcalHits";

/**
private int calibYear=0;
private ArrayList<Integer> badChannels = null;
/*
* Basic no argument constructor.
A.C.: I add a year-specific set of crystals that are broken, with the corresponding energy to be set to zero for both data and MC.
For the moment, this is hard-coded
*/
public IterateGainFactorDriver() {
badChannels=new ArrayList<Integer>();
}

public void setGainFile(String filename) {
this.gainFileName = filename;
}

public void setCalibYear(int year) {
this.calibYear=year;
System.out.println("IterateGainFactorDriver: setting calib year to "+this.calibYear);

}


public void setBadChannels() {
if (this.calibYear==2021) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be hard coding bad channel lists like this. The database is the preferred solution for these sorts of things.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a calibration driver, not used at all in reconstruction/analysis, so not sure it's such a big deal. There are gains in the database already which are appropriate for killing a channel in reconstruction and are already used for such. And, since this is reading a gains file during calibrations, they can/should be killed from there too, so we can probably just delete or at least ignore these hard-coded numbers.

System.out.println("Adding the 2021 bad channels");
badChannels.add(6);
badChannels.add(15);
badChannels.add(26);
badChannels.add(153);
badChannels.add(192);
badChannels.add(198);
badChannels.add(275);
badChannels.add(334);
badChannels.add(419);
}
System.out.println("IterateGainFactorDriver: bad channels are "+badChannels);
}

/**
* Read in a text file that has multiplicative factors on the original gain
Expand Down Expand Up @@ -105,13 +132,15 @@ private void readGainFile() {
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("ECAL Gain Factors were read");
}

@Override
public void detectorChanged(Detector detector) {
// ECAL combined conditions object.
ecalConditions = DatabaseConditionsManager.getInstance().getEcalConditions();
readGainFile();
setBadChannels();
}

/**
Expand All @@ -127,9 +156,14 @@ public List<CalorimeterHit> iterateHits(final List<CalorimeterHit> hits) {
for (final CalorimeterHit hit : hits) {
double time = hit.getTime();
long cellID = hit.getCellID();
double energy = hit.getCorrectedEnergy() * gainFileGains.get(findChannelId(cellID));
CalorimeterHit newHit = CalorimeterHitUtilities.create(energy, time, cellID);
newHits.add(newHit);
/*If the channels is not flagged as "bad", re-compute the energy and create a new CalorimterHit
* Otherwise ignore the hit
* */
if (this.badChannels.contains(findChannelId(cellID))==false) {
double energy = hit.getCorrectedEnergy() * gainFileGains.get(findChannelId(cellID));
CalorimeterHit newHit = CalorimeterHitUtilities.create(energy, time, cellID);
newHits.add(newHit);
}
}
return newHits;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ public final class ClusterCorrectionUtilities {
static final double NOISE_B = 1.3725E-4;
static final double NOISE_C = 3.01E-4;

static final int N_ITERATIONS_2019 = 5;

static final Random random = new Random();

static final int N_ITERATIONS_2019 = 5;
static final double deltaClusterEnergy_thr2019 = 0.5 / 100; // relative deltaE/E
static final double deltaClusterX_thr2019 = 0.5; // abs dX in mm
static final double deltaClusterY_thr2019 = 0.5; // abs dY in mm

static final int N_ITERATIONS_2021 = 5;
static final double deltaClusterEnergy_thr2021 = 0.5 / 100; // relative deltaE/E
static final double deltaClusterX_thr2021 = 0.5; // abs dX in mm
static final double deltaClusterY_thr2021 = 0.5; // abs dY in mm

// Calculate the noise factor to smear the Ecal energy by
public static double calcNoise(double energy) {
return random.nextGaussian() * Math.sqrt(NOISE_A + NOISE_B * energy + NOISE_C * Math.pow(energy, 2));
Expand Down Expand Up @@ -98,7 +102,53 @@ public static void applyCorrections(double beamEnergy, HPSEcal3 ecal, List<Clust
}

}
} else {
} else if (beamEnergy > 3.0) {
for (int it = 0; it < N_ITERATIONS_2021; it++) {
if (it == 0)
addNoise = true;
else
addNoise = false;

// get the cluster energy and cluster position from last iteration
double clusterPosition[] = baseCluster.getPosition();
double clusterEnergy = baseCluster.getEnergy();

// To correct the energy, need the correct position - from previous iteration -
// and the raw energy
baseCluster.setPosition(clusterPosition);
baseCluster.setEnergy(clusterEnergy_NC);
ClusterEnergyCorrection2021.setCorrectedEnergy(ecal, baseCluster, isMC, addNoise);
double clusterEnergy_C = baseCluster.getEnergy();

// To correct the position, need the correct energy - from previous iteration -
// and the raw position
baseCluster.setEnergy(clusterEnergy);
baseCluster.setPosition(clusterPosition_NC);
ClusterPositionCorrection2021.setCorrectedPosition(baseCluster);

// now set back the energy after correction (the position is already set)
baseCluster.setEnergy(clusterEnergy_C);

// absolute POS, relative in energy
double deltaClusterEnergy = clusterEnergy - clusterEnergy_C;
double deltaClusterX = clusterPosition[0] - baseCluster.getPosition()[0];
double deltaClusterY = clusterPosition[1] - baseCluster.getPosition()[1];

// A.C. : add a condition on the relative variation of the energy before-after
// iteration
// add a condition on the absolute variation of the position before-after
// iteration
// if all are satisfied, break the loop
if ((Math.abs(deltaClusterEnergy / clusterEnergy) < deltaClusterEnergy_thr2021)
&& (Math.abs(deltaClusterX) < deltaClusterX_thr2021)
&& (Math.abs(deltaClusterY) < deltaClusterY_thr2021)) {
break;
}

}
}

else {
ClusterPositionCorrection.setCorrectedPosition(baseCluster);
ClusterEnergyCorrection.setCorrectedEnergy(ecal, baseCluster, isMC);
}
Expand All @@ -119,11 +169,12 @@ public static void applyCorrections(double beamEnergy, HPSEcal3 ecal, Cluster cl

BaseCluster baseCluster = (BaseCluster) cluster;
boolean addNoise = false;
// Apply PID based energy correction.
// Apply PID based energy correction. 2019 and 2021 are a special case
if (beamEnergy > 4.0) {
// here we need to play a little bit.
// ClusterEnergyCorrection2019 requires the CORRECT position and the RAW energy
// ClusterPositionCorrection2019 requires the CORRECT energy and the RAW
// ClusterEnergyCorrection2019/2021 requires the CORRECT position and the RAW
// energy
// ClusterPositionCorrection2019/2021 requires the CORRECT energy and the RAW
// position.
// Idea: iterate from the non-corrected values

Expand All @@ -146,13 +197,16 @@ public static void applyCorrections(double beamEnergy, HPSEcal3 ecal, Cluster cl
// and the raw energy
baseCluster.setPosition(clusterPosition);
baseCluster.setEnergy(clusterEnergy_NC);

ClusterEnergyCorrection2019.setCorrectedEnergy(ecal, baseCluster, isMC, addNoise);

double clusterEnergy_C = baseCluster.getEnergy();

// To correct the position, need the correct energy - from previous iteration -
// and the raw position
baseCluster.setEnergy(clusterEnergy);
baseCluster.setPosition(clusterPosition_NC);

ClusterPositionCorrection2019.setCorrectedPosition(baseCluster);

// now set back the energy after correction (the position is already set)
Expand All @@ -175,8 +229,68 @@ public static void applyCorrections(double beamEnergy, HPSEcal3 ecal, Cluster cl
}

}
} else if (beamEnergy > 3.0) {
// here we need to play a little bit.
// ClusterEnergyCorrection2019/2021 requires the CORRECT position and the RAW
// energy
// ClusterPositionCorrection2019/2021 requires the CORRECT energy and the RAW
// position.
// Idea: iterate from the non-corrected values

} else {
baseCluster.setNeedsPropertyCalculation(false); // should have been set already before calling this -
// just in case.
double clusterPosition_NC[] = baseCluster.getPosition();
double clusterEnergy_NC = baseCluster.getEnergy();

for (int it = 0; it < N_ITERATIONS_2021; it++) {
if (it == 0)
addNoise = true;
else
addNoise = false;

// get the cluster energy and cluster position from last iteration
double clusterPosition[] = baseCluster.getPosition();
double clusterEnergy = baseCluster.getEnergy();

// To correct the energy, need the correct position - from previous iteration -
// and the raw energy
baseCluster.setPosition(clusterPosition);
baseCluster.setEnergy(clusterEnergy_NC);

ClusterEnergyCorrection2021.setCorrectedEnergy(ecal, baseCluster, isMC, addNoise);

double clusterEnergy_C = baseCluster.getEnergy();

// To correct the position, need the correct energy - from previous iteration -
// and the raw position
baseCluster.setEnergy(clusterEnergy);
baseCluster.setPosition(clusterPosition_NC);

ClusterPositionCorrection2021.setCorrectedPosition(baseCluster);

// now set back the energy after correction (the position is already set)
baseCluster.setEnergy(clusterEnergy_C);

// absolute POS, relative in energy
double deltaClusterEnergy = clusterEnergy - clusterEnergy_C;
double deltaClusterX = clusterPosition[0] - baseCluster.getPosition()[0];
double deltaClusterY = clusterPosition[1] - baseCluster.getPosition()[1];
// A.C. : add a condition on the relative variation of the energy before-after
// iteration
// add a condition on the absolute variation of the position before-after
// iteration
// if all are satisfied, break the loop
if ((Math.abs(deltaClusterEnergy / clusterEnergy) < deltaClusterEnergy_thr2021)
&& (Math.abs(deltaClusterX) < deltaClusterX_thr2021)
&& (Math.abs(deltaClusterY) < deltaClusterY_thr2021)) {
break;
}

}

}

else {
// Apply PID based position correction, which should happen before final energy
// correction.
ClusterPositionCorrection.setCorrectedPosition(baseCluster);
Expand Down Expand Up @@ -204,7 +318,17 @@ public static void applyCorrections(double beamEnergy, HPSEcal3 ecal, Cluster cl
// is different from below, since 2019 corrections are based on the CORRECTED
// ENERGY
ClusterPositionCorrection2019.setCorrectedPosition(baseCluster);
} else {
} else if (beamEnergy > 3.0) {
// Apply energy correction - this depends on the non-corrected energy (from
// baseCluster) and ypos, from tracking.
ClusterEnergyCorrection2021.setCorrectedEnergy(ecal, baseCluster, ypos, isMC);
// Now the energy is correct, can use the 2021 correction. Note that the order
// is different from below, since 2021 corrections are based on the CORRECTED
// ENERGY
ClusterPositionCorrection2021.setCorrectedPosition(baseCluster);
}

else {
// Apply PID based position correction, which should happen before final energy
// correction.
ClusterPositionCorrection.setCorrectedPosition(baseCluster);
Expand Down
Loading