CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/L1Trigger/RegionalCaloTrigger/src/L1RCTNeighborMap.cc

Go to the documentation of this file.
00001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTNeighborMap.h"
00002 
00003 #include <vector>
00004 using std::vector;
00005 
00006 vector<int> L1RCTNeighborMap::north(int crate,int card,int region){
00007   std::vector<int> north(3);
00008   int newregion(0),newcard(0),newcrate(0);
00009   if(card == 0 || card == 2 || card == 4){
00010     newcard = card+1;
00011     newregion = region;
00012     if(crate != 0 && crate != 9)
00013       newcrate = crate-1;
00014     else
00015       newcrate = crate+8;
00016   }
00017   else if(card == 1 || card == 3 || card == 5){
00018     newcard = card-1;
00019     newregion = region;
00020     newcrate = crate;
00021   }
00022   else if(card == 6){
00023     if(region == 0){
00024       newcard = card;
00025       newregion = region+1;
00026       if(crate != 0 && crate != 9)
00027         newcrate = crate-1;
00028       else
00029         newcrate = crate+8;
00030     }
00031     else {
00032       newcard = card;
00033       newregion = region-1;
00034       newcrate = crate;
00035     }
00036   }
00037   north.at(0) = newcrate;
00038   north.at(1) = newcard;
00039   north.at(2) = newregion;
00040   return north;
00041 }
00042 
00043 vector<int> L1RCTNeighborMap::south(int crate, int card, int region){
00044   int newcrate(0),newcard(0),newregion(0);
00045   std::vector<int> south(3);
00046   if(card == 0 || card == 2 || card == 4){
00047     newcard = card+1;
00048     newregion = region;
00049     newcrate = crate;
00050   }
00051   else if(card == 1 || card == 3 || card == 5){
00052     newcard = card-1;
00053     newregion = region;
00054     if(crate != 8 && crate != 17)
00055       newcrate = crate+1;
00056     else
00057       newcrate = crate-8;
00058   }
00059   else if(card == 6){
00060     if(region == 0){
00061       newcrate = crate;
00062       newcard = card;
00063       newregion = region+1;
00064     }
00065     else {
00066       newcard = card;
00067       newregion = region-1;
00068       if(crate != 8 && crate != 17)
00069         newcrate = crate+1;
00070       else
00071         newcrate = crate-8;
00072     }
00073   }
00074   south.at(0) = newcrate;
00075   south.at(1) = newcard;
00076   south.at(2) = newregion;
00077   return south;
00078 }
00079   
00080 vector<int> L1RCTNeighborMap::west(int crate,int card, int region){
00081   int newcrate(0),newcard(0),newregion(0);
00082   std::vector<int> west(3);
00083   if(crate < 9){
00084     newcrate = crate;
00085     if(card != 6){
00086       if(region == 0){
00087         newcard = card;
00088         newregion = region+1;
00089       }
00090       else{
00091         if(card != 4 && card != 5){
00092           newcard = card+2;
00093           newregion = region-1;
00094         }
00095         else if(card == 4){
00096           newcard = 6;
00097           newregion = 0;
00098         }
00099         else if(card == 5){
00100           newcard = 6;
00101           newregion = 1;
00102         }
00103       }
00104     }
00105     else{
00106       newcrate = -1;
00107       newcard = -1;
00108       newregion = -1;
00109     }
00110   }
00111   else{
00112     if(card == 0 || card == 1){
00113       if(region == 0){
00114         newcrate = crate-9;
00115         newregion = region;
00116         newcard = card;
00117       }
00118       else {
00119         newcrate = crate;
00120         newregion = region-1;
00121         newcard = card;
00122       }
00123     }
00124     else if(card != 6){
00125       newcrate = crate;
00126       if(region == 0){
00127         newcard = card-2;
00128         newregion = region+1;
00129       }
00130       else{
00131         newcard = card;
00132         newregion = region-1;
00133       }
00134     }
00135     else if(card == 6){
00136       newcrate = crate;
00137       newregion = 1;
00138       if(region == 0)
00139         newcard = 4;
00140       else
00141         newcard = 5;
00142     }
00143   }
00144   west.at(0) = newcrate;
00145   west.at(1) = newcard;
00146   west.at(2) = newregion;
00147   return west;
00148 }
00149 
00150 vector<int> L1RCTNeighborMap::east(int crate,int card, int region){
00151   int newcrate(0),newcard(0),newregion(0);
00152   std::vector<int> east(3);
00153   if(crate < 9){
00154     if(card != 0 && card != 1 && card != 6){
00155       newcrate = crate;
00156       if(region == 0){
00157         newregion = region+1;
00158         newcard = card-2;
00159       }
00160       else{
00161         newregion = region-1;
00162         newcard = card;
00163       }
00164     }
00165     else if(card == 0 || card == 1){
00166       newcard = card;
00167       if(region == 0){
00168         newcrate = crate+9;
00169         newregion = region;
00170       }
00171       else {
00172         newcrate = crate;
00173         newregion = region-1;
00174       }
00175     }
00176     else if(card == 6){
00177       newcrate = crate;
00178       newregion = 1;
00179       if(region == 0)
00180         newcard = 4;
00181       else
00182         newcard = 5;
00183     }
00184   }
00185   else {
00186     newcrate = crate;
00187     if(card != 6){
00188       if(region == 0){
00189         newcard = card;
00190         newregion = region+1;
00191       }
00192       else{
00193         if(card != 4 && card != 5){
00194           newcard = card+2;
00195           newregion = region-1;
00196         }
00197         else if(card == 4){
00198           newcard = 6;
00199           newregion = 0;
00200         }
00201         else if(card == 5){
00202           newcard = 6;
00203           newregion = 1;
00204         }
00205       }
00206     }
00207     else{
00208       newcrate = -1;
00209       newcard = -1;
00210       newregion = -1;
00211     }
00212   }
00213   east.at(0) = newcrate;
00214   east.at(1) = newcard;
00215   east.at(2) = newregion;
00216   return east;
00217 }
00218 
00219 vector<int> L1RCTNeighborMap::se(int crate,int card,int region){
00220   int newcrate(0),newcard(0),newregion(0);
00221   std::vector<int> se(3);
00222   if(crate < 9){
00223     if(card == 0){
00224       if(region == 0){
00225         newcrate = crate+9;
00226         newregion = region;
00227         newcard = 1;
00228       }
00229       else{
00230         newcrate = crate;
00231         newregion = 0;
00232         newcard = 1;
00233       }
00234     }
00235     else if(card == 1){
00236       if(region == 0){
00237         if(crate != 8)
00238           newcrate = crate+10;
00239         else 
00240           newcrate = 9;
00241         newregion = 0;
00242         newcard = 0;
00243       }
00244       else {
00245         if(crate != 8)
00246           newcrate = crate+1;
00247         else
00248           newcrate = 0;
00249         newregion = 0;
00250         newcard = 0;
00251       }
00252     }
00253     else if(card == 2 || card == 4){
00254       newcrate = crate;
00255       newregion = !region;
00256       newcard = card-1+2*region;
00257     }
00258     else if(card == 5 || card == 3){
00259       newregion = !region;
00260       newcard = card-3+2*region;
00261       if(crate != 8)
00262         newcrate = crate+1;
00263       else
00264         newcrate = 0;
00265     }
00266     else if(card == 6){
00267       if(region == 0){
00268         newcard = 5;
00269         newregion = 1;
00270         newcrate = crate;
00271       }
00272       else{
00273         newcard = 4;
00274         newregion = 1;
00275         if(crate != 8)
00276           newcrate = crate+1;
00277         else
00278           newcrate = 0;
00279       }
00280     }
00281   }
00282   else{
00283     if(card == 0 || card == 2){
00284       newregion = !region;
00285       newcrate = crate;
00286       newcard = card+2*region+1;
00287     }
00288     else if(card == 1 || card == 3){
00289       newregion = !region;
00290       newcard = card-1+2*region;
00291       if(crate != 17)
00292         newcrate = crate+1;
00293       else
00294         newcrate = 9;
00295     }
00296     else if(card == 4){
00297       newcrate = crate;
00298       if(region == 0){
00299         newregion = 1;
00300         newcard = 5;
00301       }
00302       else{
00303         newregion = 1;
00304         newcard = 6;
00305       }
00306     }
00307     else if(card == 5){
00308       if(region == 0){
00309         newcard = 4;
00310         newregion = 1;
00311       }
00312       else{
00313         newcard = 6;
00314         newregion = 0;
00315       }
00316       if(crate != 17)
00317         newcrate = crate+1;
00318       else 
00319         newcrate = 9;
00320     }
00321     else if(card == 6){
00322       newcard = -1;
00323       newregion = -1;
00324       newcrate = -1;
00325     }
00326   }
00327 
00328   se.at(0) = newcrate;
00329   se.at(1) = newcard;
00330   se.at(2) = newregion;
00331   return se;
00332 }
00333 
00334 vector<int> L1RCTNeighborMap::sw(int crate,int card,int region){
00335   int newcrate(0),newcard(0),newregion(0);
00336   std::vector<int> sw(3);
00337   if(crate > 8){
00338     if(card == 0){
00339       if(region == 0){
00340         newcrate = crate-9;
00341         newregion = region;
00342         newcard = 1;
00343       }
00344       else{
00345         newcrate = crate;
00346         newregion = 0;
00347         newcard = 1;
00348       }
00349     }
00350     else if(card == 1){
00351       if(region == 0){
00352         if(crate != 17)
00353           newcrate = crate-8;
00354         else
00355           newcrate = 0;
00356         newregion = 0;
00357         newcard = 0;
00358       }
00359       else {
00360         if(crate != 17)
00361           newcrate = crate+1;
00362         else
00363           newcrate = 9;
00364         newregion = 0;
00365         newcard = 0;
00366       }
00367     }
00368     else if(card == 2 || card == 4){
00369       newcrate = crate;
00370       newregion = !region;
00371       newcard = card-1+2*region;
00372     }
00373     else if(card == 5 || card == 3){
00374       newregion = !region;
00375       newcard = card-3+2*region;
00376       if(crate != 17)
00377         newcrate = crate+1;
00378       else
00379         newcrate = 9;
00380     }
00381     else if(card == 6){
00382       if(region == 0){
00383         newcard = 5;
00384         newregion = 1;
00385         newcrate = crate;
00386       }
00387       else{
00388         newcard = 4;
00389         newregion = 1;
00390         if(crate != 17)
00391           newcrate = crate+1;
00392         else
00393           newcrate = 9;
00394       }
00395     }
00396   }
00397   else{
00398     if(card == 0 || card == 2){
00399       newregion = !region;
00400       newcrate = crate;
00401       newcard = card+1+2*region;
00402     }
00403     else if(card == 1 || card == 3){
00404       newregion = !region;
00405       newcard = card-1+2*region;
00406       if(crate != 8)
00407         newcrate = crate+1;
00408       else
00409         newcrate = 0;
00410     }
00411     else if(card == 4){
00412       newcrate = crate;
00413       if(region == 0){
00414         newregion = 1;
00415         newcard = 5;
00416       }
00417       else{
00418         newregion = 1;
00419         newcard = 6;
00420       }
00421     }
00422     else if(card == 5){
00423       if(region == 0){
00424         newcard = 4;
00425         newregion = 1;
00426       }
00427       else{
00428         newcard = 6;
00429         newregion = 0;
00430       }
00431       if(crate != 8)
00432         newcrate = crate+1;
00433       else 
00434         newcrate = 0;
00435     }
00436     else if(card == 6){
00437       newcard = -1;
00438       newregion = -1;
00439       newcrate = -1;
00440     }
00441   }
00442 
00443   sw.at(0) = newcrate;
00444   sw.at(1) = newcard;
00445   sw.at(2) = newregion;
00446   return sw;
00447 }
00448 
00449 vector<int> L1RCTNeighborMap::ne(int crate,int card,int region){
00450   int newcrate(0),newcard(0),newregion(0);
00451   std::vector<int> ne(3);
00452   if(crate < 9){
00453     if(card == 0){
00454       newregion = 0;
00455       newcard = 1;
00456       if(region == 0){
00457         if(crate != 0)
00458           newcrate = crate +8;
00459         else
00460           newcrate = 17;
00461       }
00462       else{
00463         if(crate != 0)
00464           newcrate = crate-1;
00465         else
00466           newcrate = 8;
00467       }
00468     }
00469     else if(card == 1){
00470       newregion = 0;
00471       newcard = 0;
00472       if(region == 0)
00473         newcrate = crate+9;
00474       else
00475         newcrate = crate;
00476     }
00477     else if(card == 2 || card == 4){
00478       newregion = !region;
00479       newcard = card-1+2*region;
00480       if(crate != 0)
00481         newcrate = crate-1;
00482       else
00483         newcrate = 8;
00484     }
00485     else if(card == 5 || card == 3){
00486       newregion = !region;
00487       newcard = card-3+2*region;
00488       newcrate = crate;
00489     }
00490     else if(card == 6){
00491       newregion = 1;
00492       if(region==0){
00493         newcard = 5;
00494         if(crate != 0)
00495           newcrate = crate-1;
00496         else
00497           newcrate = 8;
00498       }
00499       else {
00500         newcard = 4;
00501         newcrate = crate;
00502       }
00503     }
00504   }
00505   else {
00506     if(card == 0 || card ==2){
00507       newregion = !region;
00508       newcard = card+1+2*region;
00509       if(crate!=9)
00510         newcrate = crate-1;
00511       else
00512         newcrate = 17;
00513     }
00514     else if(card == 1 || card == 3){
00515       newregion = !region;
00516       newcard = card-1+2*region;
00517       newcrate = crate;
00518     }
00519     else if(card == 4){
00520       newregion = 1;
00521       if(crate != 9)
00522         newcrate = crate-1;
00523       else
00524         newcrate = 17;
00525       if(region == 0)
00526         newcard = 5;
00527       else
00528         newcard = 6;
00529     }
00530     else if(card == 5){
00531       newregion = !region;
00532       newcrate = crate;
00533       if(region == 0)
00534         newcard = 4;
00535       else
00536         newcard = 6;
00537     }
00538     else if(card == 6){
00539       newcrate = -1;
00540       newcard = -1;
00541       newregion = -1;
00542     }
00543   }
00544   ne.at(0) = newcrate;
00545   ne.at(1) = newcard;
00546   ne.at(2) = newregion;
00547   return ne;
00548 }
00549 
00550 vector<int> L1RCTNeighborMap::nw(int crate,int card,int region){
00551   int newcrate(0),newcard(0),newregion(0);
00552   std::vector<int> nw(3);
00553   if(crate > 8){
00554     if(card == 0){
00555       newregion = 0;
00556       newcard = 1;
00557       if(region == 0){
00558         if(crate != 9)
00559           newcrate = crate -10;
00560         else
00561           newcrate = 8;
00562       }
00563       else{
00564         if(crate != 9)
00565           newcrate = crate-1;
00566         else
00567           newcrate = 17;
00568       }
00569     }
00570     else if(card == 1){
00571       newregion = 0;
00572       newcard = 0;
00573       if(region == 0)
00574         newcrate = crate-9;
00575       else
00576         newcrate = crate;
00577     }
00578     else if(card == 2 || card == 4){
00579       newregion = !region;
00580       newcard = card-1+2*region;
00581       if(crate != 9)
00582         newcrate = crate-1;
00583       else
00584         newcrate = 17;
00585     }
00586     else if(card == 5 || card == 3){
00587       newregion = !region;
00588       newcard = card-3+2*region;
00589       newcrate = crate;
00590     }
00591     else if(card == 6){
00592       newregion = 1;
00593       if(region==0){
00594         newcard = 5;
00595         if(crate != 9)
00596           newcrate = crate-1;
00597         else
00598           newcrate = 17;
00599       }
00600       else {
00601         newcard = 4;
00602         newcrate = crate;
00603       }
00604     }
00605   }
00606   else {
00607     if(card == 0 || card ==2){
00608       newregion = !region;
00609       newcard = card+1+2*region;
00610       if(crate!=0)
00611         newcrate = crate-1;
00612       else
00613         newcrate = 8;
00614     }
00615     else if(card == 1 || card == 3){
00616       newregion = !region;
00617       newcard = card-1+2*region;
00618       newcrate = crate;
00619     }
00620     else if(card == 4){
00621       newregion = 1;
00622       if(crate != 0)
00623         newcrate = crate-1;
00624       else
00625         newcrate = 8;
00626       if(region == 0)
00627         newcard = 5;
00628       else
00629         newcard = 6;
00630     }
00631     else if(card == 5){
00632       newregion = !region;
00633       newcrate = crate;
00634       if(region == 0)
00635         newcard = 4;
00636       else
00637         newcard = 6;
00638     }
00639     else if(card == 6){
00640       newcrate = -1;
00641       newcard = -1;
00642       newregion = -1;
00643     }
00644   }
00645   nw.at(0) = newcrate;
00646   nw.at(1) = newcard;
00647   nw.at(2) = newregion;
00648   return nw;
00649 }