Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:16

0001 /**
0002   * \file
0003   * A test for EEDetId::hashedIndex()
0004   *
0005   */
0006 
0007 #include <iostream>
0008 #include <string>
0009 #include <stdexcept>
0010 #include <assert.h>
0011 #include <cstdio>
0012 
0013 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0014 
0015 const int nBegin[EEDetId::IX_MAX] = {41, 41, 41, 36, 36, 26, 26, 26, 21, 21, 21, 21, 21, 16, 16, 14, 14, 14, 14, 14,
0016                                      9,  9,  9,  9,  9,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  4,  4,  4,  4,  4,
0017                                      1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
0018                                      4,  4,  4,  4,  4,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  9,  9,  9,  9,  9,
0019                                      14, 14, 14, 14, 14, 16, 16, 21, 21, 21, 21, 21, 26, 26, 26, 36, 36, 41, 41, 41};
0020 
0021 int main(int argc, char *argv[]) {
0022   FILE *ofile = fopen("ee_numbering.dat", "w");
0023   FILE *ofile_2 = fopen("ee_next_to_boundary.dat", "w");
0024   int hi = -1;
0025   try {
0026     for (int iz = -1; iz < 2; iz += 2) {
0027       for (int ix = EEDetId::IX_MIN; ix <= EEDetId::IX_MAX; ix++) {
0028         for (int iy = nBegin[ix - 1]; iy <= 100 - nBegin[ix - 1] + 1; iy++) {
0029           hi = -1;
0030           if (EEDetId::validDetId(ix, iy, iz)) {
0031             EEDetId id = EEDetId(ix, iy, iz);
0032             hi = id.hashedIndex();
0033             assert(EEDetId::unhashIndex(hi) == id);
0034             //std::cout << id << " " << hi << " " << EEDetId::unhashIndex( hi ) << std::endl;
0035             fprintf(ofile, "%d %d %d %d %d\n", ix, iy, iz, hi, 1);
0036             if (EEDetId::isNextToBoundary(id)) {
0037               fprintf(ofile_2, "%d %d %d %d %d\n", ix, iy, iz, hi, 1);
0038             } else {
0039               fprintf(ofile_2, "%d %d %d %d %d\n", ix, iy, iz, hi, 0);
0040             }
0041           } else {
0042             fprintf(ofile, "%d %d %d %d %d\n", ix, iy, iz, hi, 0);
0043             //std::cout << "Invalid detId " << ix << " " << iy << " " << iz << std::endl;
0044           }
0045         }
0046       }
0047     }
0048     for (int i = 0; i < 15480; i++) {
0049       EEDetId id = EEDetId::unhashIndex(hi);
0050       assert(EEDetId::validDetId(id.ix(), id.iy(), id.zside()));
0051     }
0052   } catch (std::exception &e) {
0053     std::cerr << e.what();
0054   }
0055   fclose(ofile);
0056   fclose(ofile_2);
0057 }
0058 
0059 // to plot the output file:
0060 //gnuplot> set terminal postscript enhanced eps color colourtext dl 1.0 lw 1.5 "Helvetica" 21
0061 //gnuplot> set out 'ee_numbering.eps'
0062 //gnuplot> set size square
0063 //gnuplot> set xlabel 'ix'
0064 //gnuplot> set ylabel 'iy'
0065 //gnuplot> p [0:101][0:101] 'ee_numbering.dat' u 1:($5>0 ? $2 : 1/0) not, '' u 1:($5==0 ? $2 : 1/0) not