// these needed to read reconstructed data. --------------------- import org.jlab.io.hipo.*; import org.jlab.io.base.*; import org.jlab.io.evio.*; import org.jlab.clas.physics.*; // for hists import org.jlab.groot.data.TDirectory; import org.root.group.*; import org.root.pad.*; import org.root.func.*; import org.root.histogram.*; import org.root.attr.*; import java.lang.Math; import org.jlab.groot.data.H1F; import org.jlab.groot.data.H2F; import org.jlab.groot.group.DataGroup; import org.jlab.groot.math.FunctionFactory; import org.jlab.groot.ui.TCanvas; // to make plots import org.jlab.groot.data.H1F; import org.jlab.groot.ui.TCanvas; import org.jlab.groot.graphics.*; import javax.swing.JFrame; import org.jlab.groot.math.*; import org.jlab.groot.fitter.*; // language utils import java.util.Arrays; // code to read output file from the CLAS12 BST reconstruction, create and fill hists, // skim events into another file, and save the histogram output. // - gpg 2/9/16 // // streamlined event selection. gpg 3/7/16 // // started life as readBSTalignType1v2b.groovy // // // extractType2v4.groovy - updated extractType2v2.groovy for coatjava 3a.0. put in alignment/run. // extractType2v5.groovy - updated extractType2v4.groovy to read hipo files. // extractType2v6.groovy - changed extractType2v5.groovy to 3 SVT regions. // extractType2v7.groovy - updated extractType2v6.groovy to new banks // extractType2v8.groovy - cleaned out a bunch of old debugging crap. // // to run // // // // user quantities. *********************************************************** HipoDataEvent event; PhysicsEvent recEvent; Particle recCosmic; // constants and type 1 listing of required hits by region and sector. double pi=3.141592654, Ebeam=11.0, Mp=0.938272, pitch=0.156, resolution=0.080; //int[][] type1topologyArray=[[4,1],[3,1],[2,1],[1,1],[1,6],[2,8],[3,10],[4,13]]; int[][] type1topologyArray=[[3,1],[2,1],[1,1],[1,6],[2,8],[3,10]]; // first argument is the filename. String inputFile = args[0]; // second argument is write output or not ('y' or 'n') String writeOutput = args[1]; // create the object to read in the data file. HipoDataSource reader = new HipoDataSource(); reader.open(inputFile); System.out.println("------------> reading file" + inputFile); // print out stuff. // open output data files. ********************************************* HipoDataSync writer1 = new HipoDataSync(); HipoDataSync writer2 = new HipoDataSync(); if (writeOutput == "y") { writer1.open("extract_rec_cosmicsSimType1.hipo"); writer2.open("extract_rec_cosmicsSimType2.hipo"); } // define output directory here. ******************************************** TDirectory histFile = new TDirectory(); // make subdirectory for the global plots (not by sector). String dirPlots = new String("/bstEvents/align/plots"); histFile.mkdir(dirPlots); histFile.cd(dirPlots); // Define global histograms for all events in the output file. *********************************** H1F hyx_slope = new H1F("hyx_slope", "hyx_slope", 80, -4, 4.0); H1F hyz_slope = new H1F("hyz_slope", "hyz_slope", 80, -4, 4.0); H1F hphi = new H1F("hphi", "hphi", 90, 0, 180.0); H1F htheta = new H1F("htheta", "htheta", 90, 0, 180.0); H1F hHits = new H1F("hHits", "hHits", 80, 0, 80.0); H1F hresidual = new H1F("hresidual", "hresidual", 100, -0.75, 0.75); H1F hlayers = new H1F("hlayers", "hlayers", 10, 0, 10.0); H1F hchisq1 = new H1F("hchisq1", "hchisq1", 100, 0, 4.0); // set some plot parameters. hyx_slope.setOptStat("1110"); hyx_slope.setTitle("hyx_slope"); hyz_slope.setOptStat("1110"); hyz_slope.setTitle("hyz_slope"); hphi.setOptStat("1110"); hphi.setTitle("hphi"); htheta.setOptStat("1110"); htheta.setTitle("htheta"); hHits.setOptStat("1110"); hHits.setTitle("hHits"); hresidual.setOptStat("1110"); hresidual.setTitle("hresidual"); hlayers.setOptStat("1110"); hlayers.setTitle("hlayers"); hchisq1.setOptStat("1110"); hchisq1.setTitle("hchisq1"); // add hists to dirPlots directory. histFile.cd(dirPlots); histFile.addDataSet(hyx_slope,hyz_slope,hphi,htheta,hHits,hresidual,hlayers); histFile.addDataSet(hchisq1); // debugging hists H1F hcentL1S1a = new H1F("hcentL1S1a", "hcentL1S1a", 100, -1.49, 1.49); H1F hcentL1S1b = new H1F("hcentL1S1b", "hcentL1S1b", 100, -1.49, 1.49); H1F hcentL1S1c = new H1F("hcentL1S1c", "hcentL1S1c", 100, -1.49, 1.49); H1F hcentL1S1d = new H1F("hcentL1S1d", "hcentL1S1d", 100, -1.49, 1.49); H1F hcentL1S2a = new H1F("hcentL1S2a", "hcentL1S2a", 100, -1.49, 1.49); H1F hcentL1S2b = new H1F("hcentL1S2b", "hcentL1S2b", 100, -1.49, 1.49); H1F hcentL1S2c = new H1F("hcentL1S2c", "hcentL1S2c", 100, -1.49, 1.49); H1F hcentL1S2d = new H1F("hcentL1S2d", "hcentL1S2d", 100, -1.49, 1.49); H2F hlayerVSresidual = new H2F("hlayerVSresidual", "hlayerVSresidual", 100, -2, 2.0, 10,0,10); // make list of subdirectories for the sectors to store histograms. //gpg int nsectors = 24; int nsectors = 18; String[] dirList = new String[nsectors]; for (int isector = 0; isector < nsectors; isector++) { if (isector<9) { String sectorNumber = Integer.toString(isector+1); String dirName = "/bstEvents/align/sector0" + sectorNumber; dirList[isector]=dirName; histFile.mkdir(dirList[isector]); } else { String sectorNumber = Integer.toString(isector+1); String dirName = "/bstEvents/align/sector" + sectorNumber; dirList[isector]=dirName; histFile.mkdir(dirList[isector]); } } // define the sector plots: residuals and phi vs. residual. //gpg int nlayers=8; int nlayers=6; // define directories in output file for hists. for (isector=0; isector 1.222 && phiBST < 1.920) {phiCut=true;} // 70-110 deg // extract theta double denom = Math.sqrt(1 + Math.pow(yz_slope[counter],2) + Math.pow(yx_slope[counter],2)); double costheta = yz_slope[counter]/denom; double theta = Math.acos(costheta); //H1F htheta = (H1F) histFile.getDirectory(dirPlots).getObject("htheta"); htheta.fill(theta*180/pi); thetaCut=false; // theta cut on track - hardwired in. This should be fixed. if (theta > 1.222 && theta < 1.920) {thetaCut=true;} // 70-110 deg // cut on verticality of track angleCut=false; if (phiCut && thetaCut) {angleCut=true;} // chisq histogram hchisq1.fill(chi2[counter]); } // end of loop over cosmic ray tracks in the event } // end of if/check on Cosmics bank existence. // Make plots for all events and all sectors and regions from Hits bank. ----------------------- if (event.hasBank("BSTRec::Hits")){ //nHits=bstHitsBank.rows(); histFile.cd(dirPlots); //H1F hHits = (H1F) histFile.getObject("hHits"); hHits.fill(nHits); } // // Pick out type 2 events here. ******************************************************************** // Require 12 hits, all different nlayer/sector combinations. // boolean type2topology=false; boolean type1topology=false; boolean allSingleStripClusters=false; // test that we have the necessary banks. if (event.hasBank("BSTRec::Hits") && event.hasBank("BSTRec::Crosses") && event.hasBank("BSTRec::Clusters")){ // get the stuff needed from the Hits bank. double[] residual = bstHitsBank.getFloat("fitResidual"); double[] layer = bstHitsBank.getByte("layer"); double[] sectorNo = bstHitsBank.getByte("sector"); double[] stripNo = bstHitsBank.getInt("strip"); // get the stuff from the Crosses bank. int[] sectorCrosses = crossesBank.getByte("sector"); int[] regionCrosses = crossesBank.getByte("region"); int[] clusterID1 = crossesBank.getShort("Cluster1_ID"); int[] clusterID2 = crossesBank.getShort("Cluster2_ID"); // get the stuff from the Clusters bank. double[] centroidResidual = clustersBank.getFloat("centroidResidual"); double[] clusterLayer = clustersBank.getByte("layer"); double[] clusterSector = clustersBank.getByte("sector"); int[] clusterSize = clustersBank.getShort("size"); // loop over all the crosses in the event. **************************************************** // // This algorithm captures type 1 and type 2 events. // // 1. check the event has exactly 6 crosses and 12 clusters. // 2. loop over the crosses in the data. // 3. loop again over the data and count the region-sector overlaps with the current one. // 4. break if overlaps ever > 1. // 5. keep event if you found overlaps=1 exactly 6 times. //gpg int wantedCrosses=8, goodCrosses=0, wantedClusters=16, wantedHits=16; int wantedCrosses=6, goodCrosses=0, wantedClusters=12, wantedHits=12, goodSingleClusters=0, wantedSingleClusters=12; // check we have exactly the right number of crosses and the right number of clusters //if (nCrosses == wantedCrosses && nClusters == wantedClusters) { if (nCrosses == wantedCrosses) { // data for the crosses in the event. goodCrosses = 0; goodSingleClusters= 0; // use this array to count the number of region-sector combinations that match the type-1 topology. int[] type1crossHitsSeen=[0,0,0,0,0,0]; // use this array to count the number of region-sector combinations that match the type-1 topology. int[] type1crossHitsExpected=[1,1,1,1,1,1]; // outer loop over the crosses in the event. for (int iCross=0; iCross 1) { // found a double hit. break; // leave the inner loop over the crosses } } // end of inner loop over the crosses if (nThisTopology > 1) { // deal with the double hit. type2topology = false; break; // leave the outer loop over the crosses since we can't use this event. } else if (nThisTopology == 1) { goodCrosses++; } // still processing this event. // get array of hits to check for type-1s. we now have the right number of crosses so // count the hits for each entry in the type 1 topology. should be just one of each for // type 1 so type1crossHitsSeen=1 for each element in the array. // for (int jCross=0; jCross 0 && nClusters > 0 && type2topology==true) { // get the chisq myself from the fit residuals. mychisq=0; for (counter=0; counter