int search_states(char *netname, char *layname) { int net, k, j, lay = -1, ok = TRUE; /* search of network */ if (strlen(netname) == 0) net = ptdn-1; else net = search_network (netname); if (net >= 0) { /* search of layer */ lay = search_layer(net, layname); if (lay >= 0) if (net != (ptdn-1)) { /* insert a virtual layer */ k = search_layer(ptdn-1, layname); if (k < 0) /* the layer is created in "tdl" */ if (ptdl == MaxTdL) yyerror("Table of layerss is completely full"); else { tdl[ptdl].name = layname; tdl[ptdl].type = tdl[lay].type; tdl[ptdl].refnet = net; tdl[ptdl].root = TRUE; /* the table "tdn" is updated */ if (tdn[ptdn-1].belem < 0) tdn[ptdn-1].belem = tdn[ptdn-1].eelem = ptdl; else tdn[ptdn-1].eelem = ptdl; lay = ptdl; ptdl++; tdl[ptdl] = tdlini; } else lay = k; } else ; else yyerror("The name of the layer does not exist on this network"); } else yyerror("Network name does not exist"); return lay; }
/* Gathers layers which are supposed to occupy the same layer position on the Tilecal. This function is smart enough to live with search_layer() defficiency of returning the first layer that matches the required depth (see discussion above on search_layer(). Actually, the layer returned by search_layer() is the one that is going to be used as destination to all other layers that have the same depth, but cannot be picked-up by search_layer(). This is Ok for tilecal because all layers have the same granularity approximately. */ bool_t gather_tilecal_layers(hadtt_t tt) { int i; /* iterator */ int tt_e,tt_p; /* iterators */ int layer_idx; for (tt_p=0; tt_p < HadRoIGran; ++tt_p) for (tt_e=0; tt_e < HadRoIGran; ++tt_e) for (i=0; i < tt[tt_p][tt_e].NoOfLayers; ++i) if (tt[tt_p][tt_e].layer[i].calo == TILECAL) { bool_t sum_ok = TRUE; /* If I've got one of these and and previous layer which is *NOT* those, I have to add them up. */ switch (tt[tt_p][tt_e].layer[i].level) { case 1: case 4: case 9: layer_idx = search_layer(&tt[tt_p][tt_e], HAD, 1); if (layer_idx != i) sum_ok = add_equal_layers(&tt[tt_p][tt_e].layer[layer_idx], &tt[tt_p][tt_e].layer[i]); break; case 2: case 5: case 7: case 10: layer_idx = search_layer(&tt[tt_p][tt_e], HAD, 2); if (layer_idx != i) sum_ok = add_equal_layers(&tt[tt_p][tt_e].layer[layer_idx], &tt[tt_p][tt_e].layer[i]); break; case 3: case 6: case 8: case 11: layer_idx = search_layer(&tt[tt_p][tt_e], HAD, 3); if (layer_idx != i) sum_ok = add_equal_layers(&tt[tt_p][tt_e].layer[layer_idx], &tt[tt_p][tt_e].layer[i]); break; } /* If something went wrong I'll warn, but that's it, after that I'll wash my hands. */ if (!sum_ok) { /* fprintf(stderr, "(uniform.c)ERROR: Can't add layers\n"); */ return (FALSE); } } return (TRUE); }
/* Given a roi and a layer to uniformize, this function can do it, verifying the RoI integrity for the specific layer and applying the correct algorithm for placing cells correctly. */ bool_t uniformize_em_tt(const emtt_t tt, CaloLayer* layer) { int tt_eta; /* The trigger tower position within a layer */ int tt_phi; /* The trigger tower position within a layer */ int cell_eta; /* The cell position within a trigger tower */ int cell_phi; /* The cell position within a trigger tower */ const int maxcell_eta = layer->EtaGran / EMRoIGran; /* Granularity within a TT */ const int maxcell_phi = layer->PhiGran / EMRoIGran; /* Granularity within a TT */ index_t d2_index; /* The 2-D and 1-D indexes respectively */ int d1_index; for(tt_phi = 0; tt_phi < EMRoIGran; ++tt_phi) for(tt_eta = 0; tt_eta < EMRoIGran; ++tt_eta) { /* What I have to do for each trigger tower */ /* 1) Find out if the layer is there */ int layer_idx = -1; /* default is: no layer found == -1 */ layer_idx = search_layer(&tt[tt_phi][tt_eta], layer->calo, layer->level); if (layer_idx == -1) { /* fprintf(stderr, "(uniform.c)ERROR: Can't find layer in TT\n"); */ return (FALSE); /* No such layer */ } /* 2) If it is, then I can process each cell */ for(cell_phi = 0; cell_phi < maxcell_phi; ++cell_phi) for(cell_eta = 0; cell_eta < maxcell_eta; ++cell_eta) { /* What I have to do for each cell */ /* A. Evaluate the position of the cell into the original TT */ int ttindex = cell_phi * tt[tt_phi][tt_eta].layer[layer_idx].EtaGran + cell_eta; /* B. Evaluate the cell linear position into the new uniform layer*/ d2_index.eta = tt_eta * maxcell_eta + cell_eta; d2_index.phi = tt_phi * maxcell_phi + cell_phi; d1_index = d2_index.phi * layer->EtaGran + d2_index.eta; /* C. Finally, copy the energy values */ layer->cell[d1_index].energy = tt[tt_phi][tt_eta].layer[layer_idx].cell[ttindex].energy; } /* end for all cells into TT */ } /* end for all TT's into RoI */ return (TRUE); } /* end of uniformize_em_tt() */
/* Given a roi and a layer to uniformize, this function can do it, verifying the RoI integrity for the specific layer and applying the correct algorithm for placing cells correctly. */ bool_t uniformize_had_tt(const hadtt_t tt, CaloLayer* layer) { int tt_eta; /* The trigger tower position within a layer */ int tt_phi; /* The trigger tower position within a layer */ int cell_eta; /* The cell position within a trigger tower */ int cell_phi; /* The cell position within a trigger tower */ const int maxcell_eta = layer->EtaGran / HadRoIGran; /* Granularity within a TT */ const int maxcell_phi = layer->PhiGran / HadRoIGran; /* Granularity within a TT */ index_t d2_index; /* The 2-D and 1-D indexes respectively */ int d1_index; hadtt_t mytt; /* The next 2 instructions should flatten the information on layers 1/4, 2/5 and 3/6 on the TILECAL. This is important because the energy information is splitted among different parts of it and a 1st. layer is not exactly defined. See descriptions. The other layers are ignored for the time being. */ copy_had_tt(mytt,tt); if (!gather_tilecal_layers(mytt)) return (FALSE); for(tt_phi = 0; tt_phi < HadRoIGran; ++tt_phi) for(tt_eta = 0; tt_eta < HadRoIGran; ++tt_eta) { /* What I have to do for each trigger tower */ /* 1) Find out if the layer is there */ int layer_idx = -1; /* default is: no layer found == -1 */ layer_idx = search_layer(&mytt[tt_phi][tt_eta], layer->calo, layer->level); if (layer_idx == -1) { /* fprintf(stderr, "(uniform.c)ERROR: Can't find layer in TT\n"); */ return (FALSE); /* No such layer */ } /* 2) If it is, then I can process each cell */ for(cell_phi = 0; cell_phi < maxcell_phi; ++cell_phi) for(cell_eta = 0; cell_eta < maxcell_eta; ++cell_eta) { /* What I have to do for each cell */ /* A. Evaluate the position of the cell into the original TT */ int ttindex = cell_phi * mytt[tt_phi][tt_eta].layer[layer_idx].EtaGran + cell_eta; /* B. Evaluate the cell linear position into the new uniform layer*/ d2_index.eta = tt_eta * maxcell_eta + cell_eta; d2_index.phi = tt_phi * maxcell_phi + cell_phi; d1_index = d2_index.phi * layer->EtaGran + d2_index.eta; /* C. Finally, copy the energy values */ layer->cell[d1_index].energy = mytt[tt_phi][tt_eta].layer[layer_idx].cell[ttindex].energy; } /* end for all cells into TT */ } /* end for all TT's into RoI */ /* Before finishing, I have to free what I've allocated */ free_had_tt (mytt); return (TRUE); } /* end of uniformize_had_tt() */