Skip to content

Commit

Permalink
Added code to count/compare gen and rec particles
Browse files Browse the repository at this point in the history
  • Loading branch information
naharrison committed Jul 30, 2018
1 parent f14d5c3 commit d4f1936
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
9 changes: 9 additions & 0 deletions release-validation-1/.gitignore
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
6 changes: 6 additions & 0 deletions release-validation-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo docker run -it -v $PWD/:/jlab/workdir/shared --rm jeffersonlab/clas12tags:4
* From the docker container, run GEMC:
```
gemc clas12.gcard -INPUT_GEN_FILE="LUND, shared/11gev_sidis_500.dat" -USE_GUI=0 -N=500 -PRINT_EVENT=20 -RUNNO=11 -OUTPUT="evio, shared/out.evio"
exit # exit docker, do the remaining steps from your normal shell
```
* Tip: divide up the lund file and run several instances of GEMC:
```
Expand Down Expand Up @@ -44,3 +45,8 @@ echo "exit" >> cook.clara
$CLARA_HOME/bin/clara-shell cook.clara
```

## Analysis
```
mvn install
mvn exec:java -Dexec.mainClass="org.jlab.c12val.ParticleCounter"
```
32 changes: 32 additions & 0 deletions release-validation-1/pom.xml
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>
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();
}

}

0 comments on commit d4f1936

Please sign in to comment.