-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code to count/compare gen and rec particles
- Loading branch information
1 parent
f14d5c3
commit d4f1936
Showing
4 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
11gev_sidis_250.dat | ||
11gev_sidis_250b.dat | ||
cook.clara | ||
files.list | ||
install-claracre-clas.sh | ||
myclara | ||
*.evio | ||
*.hipo | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.jlab.c12val</groupId> | ||
<artifactId>rv1</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<repositories> | ||
<repository> | ||
<id>clas12maven</id> | ||
<url>https://clasweb.jlab.org/clas12maven</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jlab.coat</groupId> | ||
<artifactId>coat-libs</artifactId> | ||
<version>5.1-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
</project> |
92 changes: 92 additions & 0 deletions
92
release-validation-1/src/main/java/org/jlab/c12val/ParticleCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.jlab.c12val; | ||
|
||
import org.jlab.io.base.DataBank; | ||
import org.jlab.io.base.DataEvent; | ||
import org.jlab.io.hipo.HipoDataSource; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
|
||
public class ParticleCounter { | ||
|
||
public ArrayList<Integer> pids, genCounts, recCounts; | ||
public static final HashMap<Integer, Integer> chargeOfPid = new HashMap<Integer, Integer>(); | ||
static { | ||
chargeOfPid.put(11, -1); | ||
chargeOfPid.put(-11, 1); | ||
chargeOfPid.put(211, 1); | ||
chargeOfPid.put(-211, -1); | ||
chargeOfPid.put(2212, 1); | ||
chargeOfPid.put(321, 1); | ||
chargeOfPid.put(-321, -1); | ||
chargeOfPid.put(22, 0); | ||
chargeOfPid.put(2112, 0); | ||
} | ||
|
||
|
||
public ParticleCounter(int... pids) { | ||
this.pids = new ArrayList<>(); | ||
for(int pid : pids) this.pids.add(pid); | ||
this.genCounts = new ArrayList<Integer>(Collections.nCopies(this.pids.size(), 0)); | ||
this.recCounts = new ArrayList<Integer>(Collections.nCopies(this.pids.size(), 0)); | ||
} | ||
|
||
|
||
public void processEvent(DataEvent event) { | ||
DataBank genBank, recBank; | ||
if(event.hasBank("MC::Particle")) genBank = event.getBank("MC::Particle"); | ||
else genBank = null; | ||
if(event.hasBank("REC::Particle")) recBank = event.getBank("REC::Particle"); | ||
else recBank = null; | ||
if(genBank != null) processGenRecBanks(genBank, recBank); | ||
} | ||
|
||
|
||
public void processGenRecBanks(DataBank genBank, DataBank recBank) { | ||
for(int i = 0; i < genBank.rows(); i++) { | ||
int pid = genBank.getInt("pid", i); | ||
if(pids.contains(pid)) { | ||
int ipid = pids.indexOf(pid); | ||
genCounts.set(ipid, genCounts.get(ipid) + 1); | ||
Integer charge = chargeOfPid.get(pid); | ||
if(recBank != null && recBank.rows() > 0) processRecBank(recBank, pid, charge, genBank.getFloat("px", i), genBank.getFloat("py", i), genBank.getFloat("pz", i)); | ||
} | ||
} | ||
} | ||
|
||
|
||
public void processRecBank(DataBank recBank, int gpid, Integer gq, double gpx, double gpy, double gpz) { | ||
for(int i = 0; i < recBank.rows(); i++) { | ||
byte rq = recBank.getByte("charge", i); | ||
float rpx = recBank.getFloat("px", i); | ||
float rpy = recBank.getFloat("py", i); | ||
float rpz = recBank.getFloat("pz", i); | ||
int ipid = pids.indexOf(gpid); | ||
if(gq == null || gq == rq) { | ||
if(Math.abs(gpx - rpx) < 0.2 && Math.abs(gpy - rpy) < 0.2 && Math.abs(gpz - rpz) < 0.2) recCounts.set(ipid, recCounts.get(ipid) + 1); | ||
} | ||
} | ||
} | ||
|
||
|
||
public void printResults() { | ||
System.out.printf("%-7s %-7s %-7s %n", "pid", "#gen", "#rec"); | ||
for(int i = 0; i < pids.size(); i++) { | ||
System.out.printf("%-7d %-7d %-7d %n", pids.get(i), genCounts.get(i), recCounts.get(i)); | ||
} | ||
} | ||
|
||
|
||
public static void main(String[] args) { | ||
ParticleCounter pcounter = new ParticleCounter(11, 211, -211, 2212, 321, 22, 2112); | ||
HipoDataSource reader = new HipoDataSource(); | ||
reader.open("out_out.hipo"); | ||
while(reader.hasEvent()) { | ||
DataEvent event = reader.getNextEvent(); | ||
pcounter.processEvent(event); | ||
} | ||
pcounter.printResults(); | ||
} | ||
|
||
} |