s_ForwardEMcal_t* pickForwardEMcal () { s_ForwardEMcal_t* box; s_ForwardEMcal_t* item; #if TESTING_CAL_CONTAINMENT double Etotal = 0; #endif if ((blockCount == 0) && (showerCount == 0)) { return HDDM_NULL; } box = make_s_ForwardEMcal(); box->fcalBlocks = make_s_FcalBlocks(blockCount); box->fcalTruthShowers = make_s_FcalTruthShowers(showerCount); while ((item = (s_ForwardEMcal_t*) pickTwig(&forwardEMcalTree))) { s_FcalBlocks_t* blocks = item->fcalBlocks; int block; s_FcalTruthShowers_t* showers = item->fcalTruthShowers; int shower; for (block=0; block < blocks->mult; ++block) { int row = blocks->in[block].row; int column = blocks->in[block].column; float y0 = (row - CENTRAL_ROW)*WIDTH_OF_BLOCK; float x0 = (column - CENTRAL_COLUMN)*WIDTH_OF_BLOCK; float dist = sqrt(x0*x0+y0*y0); s_FcalTruthHits_t* hits = blocks->in[block].fcalTruthHits; /* compress out the hits outside the active region */ if (dist < ACTIVE_RADIUS) { int m = box->fcalBlocks->mult; /* compress out the hits below threshold */ int i,iok; for (iok=i=0; i < hits->mult; i++) { if (hits->in[i].E >= THRESH_MEV/1e3) { #if TESTING_CAL_CONTAINMENT Etotal += hits->in[i].E; #endif if (iok < i) { hits->in[iok] = hits->in[i]; } ++iok; } } if (iok) { hits->mult = iok; box->fcalBlocks->in[m] = blocks->in[block]; box->fcalBlocks->mult++; } else if (hits != HDDM_NULL) { FREE(hits); } } else if (hits != HDDM_NULL) { FREE(hits); } } for (shower=0; shower < showers->mult; ++shower) { int m = box->fcalTruthShowers->mult++; box->fcalTruthShowers->in[m] = showers->in[shower]; } if (blocks != HDDM_NULL) { FREE(blocks); } if (showers != HDDM_NULL) { FREE(showers); } FREE(item); } blockCount = showerCount = 0; if ((box->fcalBlocks != HDDM_NULL) && (box->fcalBlocks->mult == 0)) { FREE(box->fcalBlocks); box->fcalBlocks = HDDM_NULL; } if ((box->fcalTruthShowers != HDDM_NULL) && (box->fcalTruthShowers->mult == 0)) { FREE(box->fcalTruthShowers); box->fcalTruthShowers = HDDM_NULL; } if ((box->fcalBlocks->mult == 0) && (box->fcalTruthShowers->mult == 0)) { FREE(box); box = HDDM_NULL; } #if TESTING_CAL_CONTAINMENT printf("FCal energy sum: %f\n",Etotal/0.614); #endif return box; }
s_Tagger_t* pickTagger () { s_Tagger_t* box; s_Tagger_t* item; if (microCount == 0 && hodoCount == 0) { return HDDM_NULL; } box = make_s_Tagger(); box->microChannels = make_s_MicroChannels(microCount); while ((item = (s_Tagger_t*) pickTwig(µTree))) { s_MicroChannels_t* channels = item->microChannels; int channel; for (channel=0; channel < channels->mult; ++channel) { s_TaggerTruthHits_t* hits = channels->in[channel].taggerTruthHits; /* constraint t values to lie within time range */ int i; int iok=0; for (iok=i=0; i < hits->mult; i++) { if ((hits->in[i].t >= TAG_T_MIN_NS) && (hits->in[i].t <= TAG_T_MAX_NS)) { if (iok < i) { hits->in[iok] = hits->in[i]; } ++iok; } } if (iok) { hits->mult = iok; int m = box->microChannels->mult++; box->microChannels->in[m] = channels->in[0]; } else if (hits != HDDM_NULL) { FREE(hits); } } if (channels != HDDM_NULL) { FREE(channels); } FREE(item); } box->hodoChannels = make_s_HodoChannels(hodoCount); while ((item = (s_Tagger_t*) pickTwig(&hodoTree))) { s_HodoChannels_t* channels = item->hodoChannels; int channel; for (channel=0; channel < channels->mult; ++channel) { s_TaggerTruthHits_t* hits = channels->in[channel].taggerTruthHits; /* constraint t values to lie within time range */ int i; int iok=0; for (iok=i=0; i < hits->mult; i++) { if ((hits->in[i].t >= TAG_T_MIN_NS) && (hits->in[i].t <= TAG_T_MAX_NS)) { if (iok < i) { hits->in[iok] = hits->in[i]; } ++iok; } } if (iok) { hits->mult = iok; int m = box->hodoChannels->mult++; box->hodoChannels->in[m] = channels->in[0]; } else if (hits != HDDM_NULL) { FREE(hits); } } if (channels != HDDM_NULL) { FREE(channels); } FREE(item); } microCount = 0; hodoCount = 0; if ((box->microChannels != HDDM_NULL) && (box->microChannels->mult == 0)) { FREE(box->microChannels); box->microChannels = HDDM_NULL; } if ((box->hodoChannels != HDDM_NULL) && (box->hodoChannels->mult == 0)) { FREE(box->hodoChannels); box->hodoChannels = HDDM_NULL; } if (box->microChannels->mult == 0 && box->hodoChannels->mult == 0) { FREE(box); box = HDDM_NULL; } return box; }
s_PairSpectrometerFine_t* pickPs () { s_PairSpectrometerFine_t* box; s_PairSpectrometerFine_t* item; if ((tileCount == 0) && (pointCount == 0)) { return HDDM_NULL; } box = make_s_PairSpectrometerFine(); box->psTiles = make_s_PsTiles(tileCount); box->psTruthPoints = make_s_PsTruthPoints(pointCount); while ((item = (s_PairSpectrometerFine_t*) pickTwig(&psTree))) { s_PsTiles_t* tiles = item->psTiles; int tile; s_PsTruthPoints_t* points = item->psTruthPoints; int point; for (tile=0; tile < tiles->mult; ++tile) { int m = box->psTiles->mult; s_PsTruthHits_t* hits = tiles->in[tile].psTruthHits; /* compress out the hits below threshold */ int i,iok; for (iok=i=0; i < hits->mult; i++) { if (hits->in[i].dE >= THRESH_MEV/1e3) { if (iok < i) { hits->in[iok] = hits->in[i]; } ++iok; } } if (iok) { hits->mult = iok; box->psTiles->in[m] = tiles->in[tile]; box->psTiles->mult++; } else if (hits != HDDM_NULL) { FREE(hits); } } if (tiles != HDDM_NULL) { FREE(tiles); } for (point=0; point < points->mult; ++point) { int m = box->psTruthPoints->mult++; box->psTruthPoints->in[m] = item->psTruthPoints->in[point]; } if (points != HDDM_NULL) { FREE(points); } FREE(item); } tileCount = pointCount = 0; if ((box->psTiles != HDDM_NULL) && (box->psTiles->mult == 0)) { FREE(box->psTiles); box->psTiles = HDDM_NULL; } if ((box->psTruthPoints != HDDM_NULL) && (box->psTruthPoints->mult == 0)) { FREE(box->psTruthPoints); box->psTruthPoints = HDDM_NULL; } if ((box->psTiles->mult == 0) && (box->psTruthPoints->mult == 0)) { FREE(box); box = HDDM_NULL; } return box; }
s_StartCntr_t* pickStartCntr () { s_StartCntr_t* box; s_StartCntr_t* item; if ((paddleCount == 0) && (pointCount == 0)) { return HDDM_NULL; } box = make_s_StartCntr(); box->stcPaddles = make_s_StcPaddles(paddleCount); box->stcTruthPoints = make_s_StcTruthPoints(pointCount); while ((item = (s_StartCntr_t*) pickTwig(&startCntrTree))) { s_StcPaddles_t* paddles = item->stcPaddles; int paddle; s_StcTruthPoints_t* points = item->stcTruthPoints; int point; for (paddle=0; paddle < paddles->mult; ++paddle) { int m = box->stcPaddles->mult; s_StcTruthHits_t* hits = paddles->in[paddle].stcTruthHits; /* compress out the hits below threshold */ int i,iok; for (iok=i=0; i < hits->mult; i++) { if (hits->in[i].dE >= THRESH_MEV/1e3) { if (iok < i) { hits->in[iok] = hits->in[i]; } ++iok; } } if (iok) { hits->mult = iok; box->stcPaddles->in[m] = paddles->in[paddle]; box->stcPaddles->mult++; } else if (hits != HDDM_NULL) { FREE(hits); } } if (paddles != HDDM_NULL) { FREE(paddles); } for (point=0; point < points->mult; ++point) { int m = box->stcTruthPoints->mult++; box->stcTruthPoints->in[m] = item->stcTruthPoints->in[point]; } if (points != HDDM_NULL) { FREE(points); } FREE(item); } paddleCount = pointCount = 0; if ((box->stcPaddles != HDDM_NULL) && (box->stcPaddles->mult == 0)) { FREE(box->stcPaddles); box->stcPaddles = HDDM_NULL; } if ((box->stcTruthPoints != HDDM_NULL) && (box->stcTruthPoints->mult == 0)) { FREE(box->stcTruthPoints); box->stcTruthPoints = HDDM_NULL; } if ((box->stcPaddles->mult == 0) && (box->stcTruthPoints->mult == 0)) { FREE(box); box = HDDM_NULL; } return box; }
s_ComptonEMcal_t* pickComptonEMcal () { s_ComptonEMcal_t* box; s_ComptonEMcal_t* item; if ((blockCount == 0) && (showerCount == 0)) { return HDDM_NULL; } box = make_s_ComptonEMcal(); box->ccalBlocks = make_s_CcalBlocks(blockCount); box->ccalTruthShowers = make_s_CcalTruthShowers(showerCount); while ((item = (s_ComptonEMcal_t*) pickTwig(&ComptonCalTree))) { s_CcalBlocks_t* blocks = item->ccalBlocks; int block; s_CcalTruthShowers_t* showers = item->ccalTruthShowers; int shower; for (block=0; block < blocks->mult; ++block) { s_CcalTruthHits_t* hits = blocks->in[block].ccalTruthHits; if (hits) { int m = box->ccalBlocks->mult; /* compress out the hits below threshold */ int i,iok; for (iok=i=0; i < hits->mult; i++) { if (hits->in[i].E >= THRESH_MEV/1e3) { if (iok < i) { hits->in[iok] = hits->in[i]; } ++iok; } } if (iok) { hits->mult = iok; box->ccalBlocks->in[m] = blocks->in[block]; box->ccalBlocks->mult++; } else if (hits != HDDM_NULL) { FREE(hits); } } else if (hits != HDDM_NULL) { FREE(hits); } } for (shower=0; shower < showers->mult; ++shower) { int m = box->ccalTruthShowers->mult++; box->ccalTruthShowers->in[m] = showers->in[shower]; } if (blocks != HDDM_NULL) { FREE(blocks); } if (showers != HDDM_NULL) { FREE(showers); } FREE(item); } blockCount = showerCount = 0; if ((box->ccalBlocks != HDDM_NULL) && (box->ccalBlocks->mult == 0)) { FREE(box->ccalBlocks); box->ccalBlocks = HDDM_NULL; } if ((box->ccalTruthShowers != HDDM_NULL) && (box->ccalTruthShowers->mult == 0)) { FREE(box->ccalTruthShowers); box->ccalTruthShowers = HDDM_NULL; } if ((box->ccalBlocks->mult == 0) && (box->ccalTruthShowers->mult == 0)) { FREE(box); box = HDDM_NULL; } return box; }