// // $Id: SmtAddressTranslation.cpp,v 1.15 2000/07/13 15:49:30 illingwo Exp $ // // File: SmtAddressTranslation.cpp // Purpose: // Created: 27-NOV-1998 Meenakshi Narain // // $Revision: 1.15 $ // // // Include files #include #include #ifndef STRIPADDRESS_HPP #include "smtutil/StripAddress.hpp" #endif #ifndef STRIPFEADDRESS_HPP #include "smtutil/StripFEAddress.hpp" #endif #ifndef SMTADDRESS_HPP #include "smtutil/SmtAddress.hpp" #endif #ifndef SMTFEADDRESS_HPP #include "smtutil/SmtFEAddress.hpp" #endif #ifndef SMTADDRESSTRANSLATION_HPP #include "smtutil/SmtAddressTranslation.hpp" #endif #ifndef SMTPARAMS_HPP #include "smtutil/SmtParams.hpp" #endif #ifndef READSMTTRANSLATION_HPP #include "smtutil/ReadSmtTranslation.hpp" #endif // Global definitions //using namespace std; using std::cout; using std::cerr; using std::endl; #ifndef WIN32 using std::floor; using std::ceil; #endif // Constructors/Destructors SmtAddressTranslation::SmtAddressTranslation(){ _UseMap = true; _UseFile = false; setupTranslation(_StripAddressMap, _StripFEAddressMap); } SmtAddressTranslation::SmtAddressTranslation(bool UseMap){ _UseMap = UseMap; _UseFile = false; if(_UseMap) setupTranslation(_StripAddressMap,_StripFEAddressMap); } SmtAddressTranslation::SmtAddressTranslation(const char* filename) { _UseMap = true; _UseFile = true; ReadSmtTranslation filetranslate; if(filetranslate.ReadFile(filename)) { for(filetranslate.start();!filetranslate.end();filetranslate.nextChip()) { int smtfeaddress, smtaddress; filetranslate.getmapping(smtfeaddress,smtaddress); StripAddress aStripAddr(smtaddress); StripFEAddress aStripFEAddr(smtfeaddress); _StripFEAddressMap.insert(aStripFEAddr,aStripAddr); _StripAddressMap.insert(aStripAddr,aStripFEAddr); } } else { cerr << "Failed to read SMT Translation file " << filename << endl; } } // Accessors bool SmtAddressTranslation::translator(const StripAddress& physaddr, StripFEAddress& hwaddr){ bool ok = true; if(_UseMap || _UseFile){ int stripno = physaddr.Strip(); int channo = (stripno - 1) % 128; StripAddress tmp = physaddr.FirstChannel(); //(SmtAddress::FirstChannel(physaddr.get_StripAddress())); StripAddressHash::const_iterator p; p = _StripAddressMap.find(tmp); if (p!= _StripAddressMap.end()) { hwaddr = p->second.Increment(channo); } else{ ok = false; } } else{ int int_hwaddr; int_hwaddr = GetFEAddress(physaddr.get_StripAddress()); hwaddr = StripFEAddress(int_hwaddr); } return ok; } bool SmtAddressTranslation::translator(const StripFEAddress& hwaddr, StripAddress& physaddr){ StripFEAddressHash::const_iterator p; bool ok = true; if(_UseMap || _UseFile) { int channo = hwaddr.SvxChanIndex(); StripFEAddress tmp = hwaddr.FirstChannel(); //(SmtFEAddress::FirstChannel(hwaddr.get_Address())); p = _StripFEAddressMap.find(tmp); if (p!= _StripFEAddressMap.end()) { physaddr = p->second.Increment(channo); } else{ ok = false; } } else{ int int_physaddr; int_physaddr = GetSMTAddress(hwaddr.get_Address()); physaddr = StripAddress(int_physaddr); } return ok; } void SmtAddressTranslation::setupTranslation (SmtAddressTranslation::StripAddressHash& StripAddressMap, SmtAddressTranslation::StripFEAddressHash& StripFEAddressMap) { int crateID, vrbID, hdiID, chipID, chanID; int isector, detpos; // int ioff; for (int aDetType=1; aDetType<=3; aDetType++){ if (aDetType == 1) { cout << " Intializing Barrel Address Map " << endl; for (int ibar=1; ibar<=SmtParams::numBarrels(); ibar++){ for (int ilay=1; ilay<=SmtParams::numLayers(); ilay++){ vrbID = assignVRB(ibar,ilay); // cout << "At barrel /layer : " << ibar << ", " << ilay << endl; for (int ilad=1; ilad<=SmtParams::numLadders(ilay); ilad++){ assignSector(ilay,ilad,ibar,isector,detpos); crateID = isector-1; // hdiID = assignHDI(ilay,ibar,detpos); hdiID = assignHDI(ilay,ibar,ilad); //modified call (look up) for (int iview=1; iview<=2; iview++){ int maxStrip = SmtParams::numLadderStrips(ibar,ilay,iview); for (int istrip=1; istrip<=maxStrip; istrip++){ assignChanID(ibar,ilay,iview,istrip,chipID,chanID); StripAddress aStripAddr = StripAddress(SmtAddress::Encoder(aDetType,ibar,ilay,ilad, iview,istrip)); StripFEAddress aStripFEAddr = StripFEAddress(SmtFEAddress::Encoder(crateID,vrbID,hdiID, chipID,chanID)); StripFEAddressMap.insert(aStripFEAddr,aStripAddr); StripAddressMap.insert(aStripAddr,aStripFEAddr); } } } } } } // aDetType = 1(Barrel) else { if (aDetType == 2) { cout << " Intializing F-Disk Address Map " << endl; for (int idisk=1; idisk<=SmtParams::numDisks(aDetType); idisk++) { crateID = ceil(idisk/3.0)+5; for (int iwedge=1; iwedge<=SmtParams::numWedges(aDetType); iwedge++){ isector = ceil(iwedge/2.0); // ioff = idisk - 3*((idisk-1)/3); //vrbID = 3*(ioff-1) + (iwedge-1)/4; if(idisk %3 ==0) vrbID = ceil(isector/2.0) + 2*((iwedge-1)/4); else vrbID = isector - 1 +(iwedge+1)/4; // cout <<" At F disk / wedge : "<< idisk <<", " << iwedge <328 && istrip<340)){ //cout << aStripAddr << aStripFEAddr; //} } } } } } // aDetType = 2 (FDisk) else { if (aDetType == 3) { cout << " Intializing H-Disk Address Map " << endl; for (int idisk=1; idisk<=SmtParams::numDisks(aDetType); idisk++){ crateID = 10 + (idisk-1)/2; for (int iwedge=1; iwedge<=SmtParams::numWedges(aDetType); iwedge++){ //cout <<" At H Disk / wedge : "<< idisk <<", " << iwedge << endl; for (int iview=1; iview<=2; iview ++){ // isector = (iwedge-1)/8; isector = ceil(iwedge/4.0); vrbID = 6*((idisk - 1)%2) + ceil(iwedge/4.0) - 1; hdiID = ((iwedge-1)%4)*2 + iview - 1; int maxStrip = SmtParams::numWedgeStrips(aDetType,iview); /** cout << aDetType <<" "<< idisk <<" "<< iwedge; cout <<" " << iview <<" "; //cout << istrip <<" "; cout << vrbID <<" "<< crateID <<" "<< hdiID <<" "; // cout << chipID <<" "<< chanID <<" "; cout << ioff <<" "<< isector << endl; **/ for (int istrip=1; istrip<=maxStrip; istrip++){ assignChanID(istrip,chipID,chanID); StripAddress aStripAddr = StripAddress(SmtAddress::Encoder(aDetType,idisk,iwedge, iview,istrip)); StripFEAddress aStripFEAddr = StripFEAddress(SmtFEAddress::Encoder(crateID,vrbID,hdiID, chipID,chanID)); StripFEAddressMap.insert(aStripFEAddr,aStripAddr); StripAddressMap.insert(aStripAddr,aStripFEAddr); } } } } } } // aDetType = 3 (HDisk) } } } void SmtAddressTranslation::assignSector(int layer, int ladder, int barrel, int& sector, int& detpos){ detpos = 0; if ((barrel <= 3) && (barrel >= 1)){ // barrel 1..3 if ((layer <= 4) && (layer >= 1)){ // layer 1..4 sector = ladder; } else { if (layer <= 8 && layer >= 5){ // layer 5..8 sector = ceil(ladder / 2.0); if( (layer == 6 || layer == 7) && ladder%2==0) { sector = ceil(ladder/2)+1; if(sector > 6) sector = 1; } } } } else if ((barrel <= 6) && (barrel >= 4)) { // barrel 4..6 if ((layer <= 4) && (layer >= 1)){ // layer 1..4 sector = ladder; } else { if ((layer <= 8) && (layer >= 5)) { sector = ceil(ladder / 2.0); if( (layer == 6 || layer == 8) && ladder%2==0) { sector = ceil(ladder/2)+1; if(sector > 6) sector = 1; } } } } /* This Code doesn't seem to work correctly detpos = 0; if (ilay<=4) { isector = ilad; } else { if (ibar <=3){ if (ilay==5 || ilay==8){ isector = (ilad-1)/2+1; detpos = (ilad-1) - 2*(isector-1); } if (ilay==6 || ilay==7){ isector = ilad/2+1; detpos = ilad - 2*(isector-1); if (ilad==12) { isector=1; detpos =1; } } } else { if (ilay==6 || ilay==7){ isector = (ilad-1)/2+1; detpos = (ilad-1) - 2*(isector-1); } if (ilay==5 || ilay==8){ isector = ilad/2+1; detpos = ilad - 2*(isector-1); if (ilad==12) { isector=1; detpos =1; } } } } */ } int SmtAddressTranslation::assignVRB(int ibar, int ilay){ int vrbID; if (ilay<=6){ if (ibar == 1 || ibar == 3 || ibar == 5) { vrbID = (ibar-3)/2 + ibar; } else { if (ibar == 2 || ibar == 4 || ibar == 6) { vrbID = (ibar-2)/2 + ibar; } } } else { if ( ibar == 1 || ibar == 2) {vrbID = 1;} if ( ibar == 3 || ibar == 4) {vrbID = 4;} if ( ibar == 5 || ibar == 6) {vrbID = 7;} } return vrbID; } int SmtAddressTranslation::assignHDI(int layer, int barrel, int ladder){ int hdi_index; if ((layer <= 4) && (layer >= 1)){ // layer 1..4 hdi_index = layer - 1; } else if ((layer <= 6) && (layer >= 5)) { // layer 5..6 if (ladder % 2 == 0) { // ladder is even hdi_index = layer; } else if ((ladder % 2) == 1) { // ladder is odd hdi_index = layer + 2 * (layer / 6) - 1; // cout << "layer % 6 = "<= 7)){ // layer 7..8 if ((barrel <= 3) && (barrel >= 1)){ // barrel 1..3 if (layer == 7) // ladder is odd hdi_index = ((barrel-1)%2)*4+ladder%2; if (layer == 8) hdi_index = ((barrel-1)%2)*4+(ladder-1)%2+2; // if(barrel != 2) hdi_index = hdi_index - 6; } else if ((barrel <= 6) && (barrel >= 4)){ // barrel 4..6 if(layer == 7) hdi_index = ((barrel-1)%2)*4+(ladder-1)%2; if(layer ==8) hdi_index = ((barrel-1)%2)*4+ladder%2+2; } } return hdi_index; /* Code int hdiID; if (ilay <=4) { return ilay-1; } if (ilay == 5) hdiID = 4 + detpos; if (ilay == 6) hdiID = 6 + detpos; int ioff = 0; if (ibar == 2 || ibar == 4 || ibar ==6){ioff = 4;} if (ilay == 7) hdiID = ioff + detpos; if (ilay == 8) hdiID = ioff + 2 + detpos; return hdiID; */ } //void SmtAddressTranslation::assignChanID(int ibar, int ilay, int iview, // int istrip, int& chipID, int& chanID){ void SmtAddressTranslation::assignChanID(int barrel, int layer, int view, int strip, int& chip_index, int& channel_index){ if ((barrel<=5)&&(barrel>=2)) { // barrel 2..5 if (((layer==3)||(layer==4))||((layer==7)||(layer==8))){ chip_index = (strip - 1) / 128 + 5*(view-1) ; channel_index = (strip-1) - ( chip_index - 5*(view-1) )*128; } else{ chip_index = ((strip>384?strip-384:strip)-1)/128; if (view==1) { channel_index = (strip-1) - 128*chip_index;} else{ channel_index = 384 - 128*chip_index - ((strip>384?strip-384:strip)-1); chip_index = } } } else{ // barrel 1 and 6 if (((layer==3)||(layer==4))||((layer==7)||(layer==8))){ chip_index = (strip - 1) / 128 + 5*(view-1) ; channel_index = (strip-1) - (chip_index - 5*(view-1))*128; } else{ chip_index = (384-strip)/128; channel_index = 384 - strip - 128*chip_index } } } // End of Barrel segment /* code...which doesn't seem to work chipID = (istrip-1)/128; chanID = (istrip - 1) - 128*chipID; if (ilay==1 || ilay == 3) { if (ibar==1 || ibar==6){ // single sided detector if (iview != 1) { cout << "Wrong view for a single sided detector " << endl; chipID = 0; chanID = 0; } } else { // for Barrels 2,3,4,5 // 90 degree double sided NARROW detectors - 6 chip ladders chipID = chipID + 3*(iview-1); } } else { // small angle double sided WIDE detectors - 9 chip ladders chipID = chipID + 5*(iview-1); } } */ void SmtAddressTranslation::assignChanID(int istrip, int& chipID, int& chanID){ chipID = (istrip-1)/128; chanID = (istrip-1) -128 *chipID; } // *************************************************************** // GetSMTAddress // Purpose: Unpack raw FE data element, translate into SMT coordinates, // repack into compact SMTAddress word. // // The general idea of this long function is to use simple algebra // and boolean logic to decompose a 'packed' FEAddress into it's // components, translate these integral components into new types of // addresses, and then to repack those new addresses into the SMTAddress. // See SmtAddress.hpp, SMTAddressTranslation.hpp and other header files // for definitions of the above concepts. // // Decomposing the FEAddress is accomplished by functions already // present in the SmtAddressTranslation.hpp header file. Intermediate // variables are given the values for the detector, strip, wedge, and other // detector parameters. // // The boolean algebra (if-thens, etc) gets quite cumbersome, and I'd // urge you not to waste time deciphering it. In any event, I looked // for patters in the way addresses were put together in relation to // the detector, and tried to translate those patterns into simple formulas. // // Repacking the address is accomplished via the Encoder function in // the SmtFEAddress.hpp header file. // **************************************************************** int SmtAddressTranslation::GetSMTAddress(const int FEAddress) { // This is hacked in to use the translation map file if required // (In a somewhat awkward way) if (_UseFile==true) { StripFEAddress stripfe(FEAddress); StripAddress strip; translator(stripfe,strip); return strip.get_StripAddress(); } int wedge_index; // Definitions of FEAddress int disk_index; int detector_index; int layer_index; int view_index; int ladder_index; int barrel_index; int strip_index; int crate; // Intermediate SMT Address variables int vrb; int hdi; int chip; // int channel; crate = SmtFEAddress::CrateIndex(FEAddress); vrb = SmtFEAddress::VRBIndex(FEAddress); hdi = SmtFEAddress::HDIIndex(FEAddress); chip = SmtFEAddress::ChipIndex(FEAddress); strip_index = (128*chip) + SmtFEAddress::SvxChanIndex(FEAddress)+1; /* cout <<"Input Data to Get SMTAddress.."<= 0) && (crate <=5)){ // if a barrel... detector_index = 1; if(vrb%3!=1){ if(vrb == 0) barrel_index = vrb + 1; else barrel_index = vrb - (vrb-1)/3; } else barrel_index = vrb -((vrb-1)/3) + hdi/4; if (barrel_index == 0) barrel_index++; // cout << "Barrel id is ..."< 8)layer_index = 8;} else{ if(hdi <= 5)layer_index = 7; if(hdi >5)layer_index = 8; } } // find view index: if ((barrel_index == 1) || (barrel_index == 6)){ if (((layer_index ==1)||(layer_index == 2)) ||((layer_index==5)||(layer_index==6))){ view_index = 1; } else if (((layer_index ==3)||(layer_index ==4)) ||((layer_index ==7)||(layer_index==8))){ if ((chip >= 0) && (chip <= 4)){ view_index = 1; } else { view_index = 2; chip_offset = 5; } } } else if ((barrel_index <= 5) && (barrel_index >= 2)){ if (((layer_index ==1)||(layer_index ==2)) ||((layer_index ==5)||(layer_index==6))){ if (chip <= 2){ view_index = 1; } else if (chip > 2){ view_index = 2; chip_offset = 3; } } else if (((layer_index ==3)||(layer_index==4)) ||((layer_index ==7)||(layer_index==8))){ if ((chip >= 0)&&(chip <= 4)){ view_index = 1; } else { view_index = 2; chip_offset = 5; } } } // find ladder index: ladder_index = get_ladder(layer_index, barrel_index, hdi, crate); } // F-Disks and H-Disks else if ((crate >= 6) && (crate <= 9)){ // If F-disk... detector_index = 2; view_index = (hdi % 2) + 1; // find view index if ((vrb % 3) != 1){ // find wedge/disk index wedge_index = (hdi % 4)/2 + 1 + vrb + (vrb / 3); disk_index = (crate % 6)*3 + 1 + (hdi / 4); } else if ((vrb % 3) == 1){ wedge_index = (hdi / 2) + 1 + 4 * (vrb / 3); disk_index = (crate % 6)*3 + 3; } } else if ((crate >=10) && (crate <=11)){ // if an H-disk detector_index = 3; view_index = (hdi % 2) + 1; wedge_index = (vrb % 6) * 4 + (hdi / 2) + 1; disk_index = (vrb / 6) + 1 + (crate % 10) * 2; } int retAddress; strip_index = strip_index - (view_index - 1)*(chip_offset)*128; // cout << "Data for Quick SMT Address --> " << endl; if (detector_index == 1){ /* cout << "detector index:\t" << detector_index << endl; cout << "barrel_index:\t" << barrel_index << endl; cout << "layer_index:\t" << layer_index << endl; cout << "ladder_index:\t" << ladder_index << endl; cout << "view_index :\t" << view_index << endl; cout << "strip_index :\t"<< strip_index << endl; */ retAddress = SmtAddress::Encoder(detector_index, barrel_index, layer_index, ladder_index, view_index, strip_index); } else if ((detector_index == 2) || (detector_index == 3)){ /* cout << "detector_index:\t" << detector_index << endl; cout << "disk_index:\t" << disk_index << endl; cout << "wedge_index:\t" << wedge_index << endl; cout << "view_index :\t" << view_index << endl; cout << "strip_index :\t"<< strip_index << endl; */ retAddress = SmtAddress::Encoder(detector_index, disk_index, wedge_index, view_index, strip_index); } return retAddress; } // ******************************************************* int SmtAddressTranslation::get_ladder(int layer, int barrel, int hdi, int crate){ // Support for GetFEAddress and GetSmtAddress int ladder; if(layer <= 4) ladder = crate + 1; if(barrel <=3){ if(layer == 5 || layer == 8) ladder = crate*2+(hdi%2)+1; if(layer == 6 || layer == 7){ ladder = crate*2 +hdi%2; if (ladder == 0)ladder = 12; } } else{ if(layer == 5 || layer == 7) ladder = crate*2+(hdi%2)+1; if(layer == 6 || layer == 8){ ladder = crate*2 +hdi%2; if (ladder == 0)ladder= 12; } } return ladder; } // ********************************************** int SmtAddressTranslation::GetFEAddress(const int SmtAddress) { // This is hacked in to use the translation map file if required // (In a somewhat awkward way) if (_UseFile==true) { StripFEAddress stripfe; StripAddress strip(SmtAddress); translator(strip,stripfe); return stripfe.get_Address(); } int crate_index; // Definitions of FE address components. int vrb_index; int hdi_index; int chip_index; int channel_index; int detector; // Definitions for intermediate variables. int strip; int barrel, layer, ladder, view, disk, wedge, sector; // find detector type: all addresses will have a detector type // find strip address: all addresses will point to a strip detector = SmtAddress::DetAddressDecoder(SmtAddress); strip = SmtAddress::Strip(SmtAddress); view = SmtAddress::View(SmtAddress); // cout << "GetFEAdress inputs (chopra)"; // cout << endl; // if a barrel... if (detector == 1){ // all barrel detectors have layers and ladders barrel = SmtAddress::Barrel(SmtAddress); layer = SmtAddress::Layer(SmtAddress); ladder = SmtAddress::Ladder(SmtAddress); view = SmtAddress::View(SmtAddress); /* cout << "detector:\t" << detector << endl; cout << "barrel:\t" << barrel << endl; cout << "layer:\t" << layer << endl; cout << "ladder:\t" << ladder << endl; cout << "strip :\t"<< strip << endl; cout <<"View :\t"<= 1)){ // layer 1..6 vrb_index = barrel + floor(barrel/2) - 1; } // MN use my method to assign VRB index... vrb_index = assignVRB(barrel, layer); hdi_index = barrel_hdi(layer, ladder, barrel); // calculate chip number if ((barrel<=5)&&(barrel>=2)){ // barrel 2..5 if (((layer==3)||(layer==4))||((layer==7)||(layer==8))){ chip_index = (strip - 1) / 128 + 5*(view-1) ; channel_index = (strip-1) - (chip_index - 5*(view-1))*128; } else{ chip_index = 3*(view-1)+((strip>384?strip-384:strip)-1)/128; channel_index = ((strip>384?strip-384:strip)-1) - (chip_index - 3*(view-1))*128; } } else{ // p-side // int xxx1 = ceil((strip + 1) / 128); if (((layer==3)||(layer==4))||((layer==7)||(layer==8))){ chip_index = (strip - 1) / 128 + 5*(view-1) ; channel_index = (strip-1) - (chip_index - 5*(view-1))*128; } else{ chip_index = (strip - 1)/128; channel_index = strip - 1 - chip_index*128; } // cout << " huh B " << xxx1 << " " << chip_index << endl; } // calculate channel number } // End of Barrel segment // H-disks and F-Disks else if ((detector == 2) || (detector == 3)){ disk = SmtAddress::Disk(SmtAddress); wedge = SmtAddress::Wedge(SmtAddress); // F-Disks if (detector == 2){ view = SmtAddress::View(SmtAddress); /* cout << "detector:\t" << detector << endl; cout << "disk:\t" << disk << endl; cout << "wedge:\t" << wedge << endl; cout << "strip:\t" << strip << endl; cout <<"View :\t"<= 3){ // 3..4 crate_index = 11; } // vrb address vrb_index = ceil(wedge / 4.0) - 1 + 6 * ((disk - 1)%2); // hdi address hdi_index = ((wedge - 1) % 4) * 2 + (view - 1); // chip address --> numbered backwards! aie carumba... // chip_index = 7 - ceil((strip + 1) / 128); // channel address // channel_index = (strip-1) % 128 ; assignChanID(strip,chip_index,channel_index); } // END of H-Disk calculations. } // END of boolean logic, et al. // Repack the SmtAddress as an FEAddress... /* cout << "Data for Quick FEAddress --> " << endl; cout << "crate_index:\t" << crate_index << endl; cout << "vrb_index:\t" << vrb_index << endl; cout << "hdi_index:\t" << hdi_index << endl; cout << "chip_index:\t" << chip_index << endl; cout << "channel_index:\t" << channel_index << endl; */ return SmtFEAddress::Encoder(crate_index, vrb_index, hdi_index, chip_index, channel_index); } // End of GetFEAddress // ********************************************************** int SmtAddressTranslation::barrel_sector(int barrel,int layer,int ladder){ // calculate sectors of barrel. Sectors are 60 degree // segments of the barrel detector running along the length of // the particle beam (z-axis). int sector; if ((barrel <= 3) && (barrel >= 1)){ // barrel 1..3 if ((layer <= 4) && (layer >= 1)){ // layer 1..4 sector = ladder; } else { if (layer <= 8 && layer >= 5){ // layer 5..8 sector = ceil(ladder / 2.0); if( (layer == 6 || layer == 7) && ladder%2==0) { sector = ceil(ladder/2)+1; if(sector > 6) sector = 1; } } } } else if ((barrel <= 6) && (barrel >= 4)){ // barrel 4..6 if ((layer <= 4) && (layer >= 1)){ // layer 1..4 sector = ladder; } else { if ((layer <= 8) && (layer >= 5)) { // layer 5..8 sector = ceil(ladder / 2.0); if( (layer == 6 || layer == 8) && ladder%2==0) { sector = ceil(ladder/2)+1; if(sector > 6) sector = 1; } } } } return sector; } // ************************************************* int SmtAddressTranslation::barrel_hdi(int layer,int ladder,int barrel){ // calculate hdi_index int hdi_index; if ((layer <= 4) && (layer >= 1)){ // layer 1..4 hdi_index = layer - 1; } else if ((layer <= 6) && (layer >= 5)){ // layer 5..6 if (ladder % 2 == 0){ // ladder is even hdi_index = layer; } else if ((ladder % 2) == 1){ // ladder is odd hdi_index = layer + 2 * (layer / 6) - 1; // cout << "layer % 6 = "<= 7)){ // layer 7..8 if ((barrel <= 3) && (barrel >= 1)){ // barrel 1..3 if (layer == 7) // ladder is odd hdi_index = ((barrel-1)%2)*4+ladder%2; if (layer == 8) hdi_index = ((barrel-1)%2)*4+(ladder-1)%2+2; // if(barrel != 2) hdi_index = hdi_index - 6; } else if ((barrel <= 6) && (barrel >= 4)){ // barrel 4..6 if(layer == 7) hdi_index = ((barrel-1)%2)*4+(ladder-1)%2; if(layer ==8) hdi_index = ((barrel-1)%2)*4+ladder%2+2; } } return hdi_index; }