Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-01-20 02:57:42

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 //  Contains 3 macros to extract from the ASCII files from Philippe, Chris
0004 //  and Katya to make part of the xml file to be used to define the
0005 //  geometry of the HGCal detector. There are 3 versions for the silicon
0006 //  part for the format versions V14|V15, version V16 and verion V17
0007 //
0008 //  HGCalConvert 0/2 infile outfile1 outfile2 outfile3 modeGlobal debug
0009 //               0 for the V14/V15 formats; 1 for the V16 format;
0010 //               2 for the V17 format
0011 //  infile   (const char*)   Input file from Philippe conatining layer #,
0012 //                           size, depth, x, y position, orientation, u, v
0013 //  outfile1 (const char*)   Output fle for the EE part
0014 //  outfile2 (const char*)   Output fle for the HE part (full silicon)
0015 //  outfile3 (const char*)   Output fle for the HE part (mixed layers)
0016 //  modeGlobal (int)         Flag to create parts to be inserted in the
0017 //                           global section (0) or to be inserted in
0018 //                           the ddAlgorithm part (1)
0019 //  debug     (int)          Three digit integer to set debug for each
0020 //                           of the outputs
0021 //
0022 //  HGCalConvert 3 infile outfile1 outfile2 laymin cassette debug
0023 //  infile   (const char*)   Input file from Katya (modified by Chris)
0024 //                           containing layer #. ring #, start and end
0025 //                           of ring radius, SiPM size, 4 hexadecimal
0026 //                           words specifying if the phi location in
0027 //                           120-degree sector is filled, scintillator
0028 //                           type (c: cast, m: mould)
0029 //  outfile1 (const char*)   Output file for the part to be inserted in
0030 //                           the global section
0031 //  outfile2 (const char*)   Output file for the part to be inserted in
0032 //                           the ddAlgorithm part
0033 //  laymin   (int)           First layer number of the HE part
0034 //                           (28 for versions: V14, V15; 26 for V16, V17)
0035 //  cassette (int)           Cassettes are used in geometry definition
0036 //                           (0 if none, 1 if 12 cassettes are used)
0037 //  debug    (int)           Two digit integer to set debug for each
0038 //                           of the outputs
0039 //
0040 //  HGCalConvert 4 infile outfile1 outfile2 modeGlobal debug
0041 //               4 for the V18 formats of HFNose
0042 //  infile   (const char*)   Input file from conatining layer #, size, depth,
0043 //                           x, y position, orientation, u, v, cassette
0044 //  outfile1 (const char*)   Output fle for the EE part
0045 //  outfile2 (const char*)   Output fle for the HE part
0046 //  maxLayEE (int)           Maximum layer number of the EE part
0047 //  maxLayHE (int)           Maximum layer number of the HE part
0048 //  modeGlobal (int)         Flag to create parts to be inserted in the
0049 //                           global section (0) or to be inserted in
0050 //                           the ddAlgorithm part (1)
0051 //  debug     (int)          Two digit integer to set debug for each
0052 //                           of the outputs (opional)
0053 //
0054 //////////////////////////////////////////////////////////////////////////////
0055 
0056 #include "Geometry/HGCalCommonData/interface/HGCalProperty.h"
0057 #include "Geometry/HGCalCommonData/interface/HGCalTileIndex.h"
0058 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0059 #include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
0060 #include <algorithm>
0061 #include <cstdlib>
0062 #include <fstream>
0063 #include <iomanip>
0064 #include <iostream>
0065 #include <map>
0066 #include <string>
0067 #include <vector>
0068 
0069 struct wafer {
0070   int thick, partial, orient, cassette;
0071   wafer(int t = 0, int p = 0, int o = 0, int c = 0) : thick(t), partial(p), orient(o), cassette(c){};
0072 };
0073 
0074 struct layerInfo {
0075   int layer, type;
0076   std::vector<double> deltaR;
0077   layerInfo(int ly, int ty, std::vector<double> dR) : layer(ly), type(ty), deltaR(dR){};
0078 };
0079 
0080 struct tile {
0081   double sipm;
0082   int type, hex[4];
0083   tile(double s = 0, int h1 = 0, int h2 = 0, int h3 = 0, int h4 = 0, int t = 0) : sipm(s), type(t) {
0084     hex[0] = h1;
0085     hex[1] = h2;
0086     hex[2] = h3;
0087     hex[3] = h4;
0088   };
0089 };
0090 
0091 struct tileZone {
0092   tileZone(int l0 = 0, int r0 = 0, int r1 = 0, int f0 = 0, int f1 = 0, int c0 = 0)
0093       : layer(l0), rmin(r0), rmax(r1), phimin(f0), phimax(f1), cassette(c0){};
0094   int layer, rmin, rmax, phimin, phimax, cassette;
0095 };
0096 
0097 std::vector<std::string> splitString(const std::string& fLine);
0098 
0099 class ConvertSiliconV0 {
0100 public:
0101   ConvertSiliconV0(int layMax1 = 28, int layMax2 = 36);
0102   void convert(const char* infile,
0103                const char* outfile1,
0104                const char* outfile2,
0105                const char* outfile3,
0106                int modeGlobal = 0,
0107                int debug = 0);
0108 
0109 private:
0110   void writeSilicon(const char*, const std::map<int, wafer>&, const std::string&, const bool&, const bool&);
0111 
0112   const int layMax1_, layMax2_;
0113 };
0114 
0115 class ConvertSiliconV1 {
0116 public:
0117   ConvertSiliconV1(int layMax1 = 26, int layMax2 = 33);
0118   void convert(const char* infile,
0119                const char* outfile1,
0120                const char* outfile2,
0121                const char* outfile3,
0122                int modeGlobal = 0,
0123                int debug = 0);
0124 
0125 private:
0126   void writeSilicon(
0127       const char*, const std::vector<int>&, const std::map<int, wafer>&, const std::string&, const bool&, const bool&);
0128 
0129   const int layMax1_, layMax2_;
0130 };
0131 
0132 class ConvertSiliconV2 {
0133 public:
0134   ConvertSiliconV2(unsigned int layMax1 = 26, unsigned int layMax2 = 33, unsigned int layMax3 = 47);
0135   void convert(const char* infile,
0136                const char* outfile1,
0137                const char* outfile2,
0138                const char* outfile3,
0139                int modeGlobal = 0,
0140                int debug = 0);
0141 
0142 private:
0143   void writeSilicon(const char*,
0144                     const unsigned int,
0145                     const std::vector<layerInfo>&,
0146                     const std::map<int, wafer>&,
0147                     const std::string&,
0148                     const bool&,
0149                     const bool&);
0150 
0151   const unsigned int layMax1_, layMax2_, layMax3_;
0152 };
0153 
0154 class ConvertScintillator {
0155 public:
0156   ConvertScintillator(int layMin = 26, int cassette = 0);
0157   void convert(const char*, const char*, const char*, int debug = 0);
0158 
0159 private:
0160   void makeTitle(const char* outfile,
0161                  const std::map<int, tile>& module,
0162                  const std::map<int, std::pair<double, double> >& ringR,
0163                  int lmin,
0164                  int lmax,
0165                  bool debug);
0166 
0167   const int layMin_;
0168   const int cassette_;
0169 };
0170 
0171 class ConvertNoseV0 {
0172 public:
0173   ConvertNoseV0(unsigned int layMax1 = 6, unsigned int layMax2 = 8);
0174   void convert(const char* infile, const char* outfile1, const char* outfile2, int modeGlobal = 0, int debug = 0);
0175 
0176 private:
0177   void writeNose(const char*,
0178                  const unsigned int,
0179                  const std::vector<layerInfo>&,
0180                  const std::map<int, wafer>&,
0181                  const std::string&,
0182                  const bool&,
0183                  const bool&);
0184 
0185   const unsigned int layMax1_, layMax2_;
0186 };
0187 
0188 int main(int argc, char* argv[]) {
0189   if (argc < 7) {
0190     std::cout << "Please give a minimum of 7 arguments \n"
0191               << "mode (0, 1:silicon; 2:scintillator)\n"
0192               << "input file name\n"
0193               << "output file name\n"
0194               << "for silicon 4 additional parameters:\n"
0195               << "  second output file name\n"
0196               << "  third output file name\n"
0197               << "  output mode (0: gobal; 1: local)\n"
0198               << "  debug (three digis to set debug for each output)\n"
0199               << "for scintillator 4 additional parameters after the first 3\n"
0200               << "  second output file name\n"
0201               << "  number of layers in the EE section: 28 or 26\n"
0202               << "  flag to utilize cassette partition or not\n"
0203               << "  debug flag\n"
0204               << "for HFNose 4 additional parameters after the first 3\n"
0205               << "  second output file name\n"
0206               << "  maximum layer number of the EE section: 6\n"
0207               << "  maximum layer number of the HE section: 8\n"
0208               << "  output mode (0: gobal; 1: local)\n"
0209               << std::endl;
0210     return 0;
0211   }
0212 
0213   int mode = std::atoi(argv[1]);
0214   const char* infile = argv[2];
0215   int code(0);
0216   if (mode <= 2) {
0217     const char* outfile1 = argv[3];
0218     const char* outfile2 = argv[4];
0219     const char* outfile3 = argv[5];
0220     int modeGlobal = atoi(argv[6]);
0221     int debug = atoi(argv[7]);
0222     std::cout << "Calls ConvertSilicon for i/p file " << infile << " o/p files " << outfile1 << ":" << outfile2 << ":"
0223               << outfile3 << " Mode " << modeGlobal << " Debug " << debug << std::endl;
0224     if (mode == 0) {
0225       ConvertSiliconV0 c1;
0226       c1.convert(infile, outfile1, outfile2, outfile3, modeGlobal, debug);
0227     } else if (mode == 1) {
0228       ConvertSiliconV1 c1;
0229       c1.convert(infile, outfile1, outfile2, outfile3, modeGlobal, debug);
0230     } else {
0231       ConvertSiliconV2 c1;
0232       c1.convert(infile, outfile1, outfile2, outfile3, modeGlobal, debug);
0233     }
0234   } else if (mode == 3) {
0235     const char* outfile1 = argv[3];
0236     const char* outfile2 = argv[4];
0237     int laymin = atoi(argv[5]);
0238     int cassette = atoi(argv[6]);
0239     int debug = atoi(argv[7]);
0240     std::cout << "Calls ConvertScintillator for i/p file " << infile << " o/p files " << outfile1 << ":" << outfile2
0241               << " Laymin " << laymin << " Cassette " << cassette << " Debug " << debug << std::endl;
0242     ConvertScintillator c1(laymin, cassette);
0243     c1.convert(infile, outfile1, outfile2, debug);
0244   } else if (mode == 4) {
0245     const char* outfile1 = argv[3];
0246     const char* outfile2 = argv[4];
0247     int maxLayEE = atoi(argv[5]);
0248     int maxLayHE = atoi(argv[6]);
0249     int modeGlobal = atoi(argv[7]);
0250     int debug = (argc > 7) ? atoi(argv[8]) : 0;
0251     std::cout << "Calls ConvertNose for i/p file " << infile << " o/p files " << outfile1 << ":" << outfile2
0252               << " Layers " << maxLayEE << ":" << maxLayHE << " Mode " << modeGlobal << " Debug " << debug << std::endl;
0253     ConvertNoseV0 c1(maxLayEE, maxLayHE);
0254     c1.convert(infile, outfile1, outfile2, modeGlobal, debug);
0255   } else {
0256     code = 1;
0257   }
0258   return code;
0259 }
0260 
0261 std::vector<std::string> splitString(const std::string& fLine) {
0262   std::vector<std::string> result;
0263   int start = 0;
0264   bool empty = true;
0265   for (unsigned i = 0; i <= fLine.size(); i++) {
0266     if (fLine[i] == ' ' || i == fLine.size()) {
0267       if (!empty) {
0268         std::string item(fLine, start, i - start);
0269         result.push_back(item);
0270         empty = true;
0271       }
0272       start = i + 1;
0273     } else {
0274       if (empty)
0275         empty = false;
0276     }
0277   }
0278   return result;
0279 }
0280 
0281 ConvertSiliconV0::ConvertSiliconV0(int layMax1, int layMax2) : layMax1_(layMax1), layMax2_(layMax2) {}
0282 
0283 void ConvertSiliconV0::convert(
0284     const char* infile, const char* outfile1, const char* outfile2, const char* outfile3, int modeGlobal, int debug) {
0285   std::ifstream fInput(infile);
0286   if (!fInput.good()) {
0287     std::cout << "Cannot open file " << infile << std::endl;
0288   } else {
0289     //First read in all records
0290     char buffer[1024];
0291     std::string thick[3] = {"120", "200", "300"};
0292     std::string partial[8] = {"F", "b", "g", "gm", "a", "d", "dm", "c"};
0293     std::map<int, wafer> module1, module2, module3;
0294     unsigned int all(0), comments(0), others(0), bad(0), good(0);
0295     bool global = (modeGlobal < 1);
0296     while (fInput.getline(buffer, 1024)) {
0297       ++all;
0298       if (debug % 10 > 1)
0299         std::cout << "[" << all << "] " << buffer << std::endl;
0300       if (buffer[0] == '#') {
0301         ++comments;
0302       } else {
0303         ++others;
0304         std::vector<std::string> items = splitString(std::string(buffer));
0305         if (items.size() != 8) {
0306           ++bad;
0307         } else {
0308           ++good;
0309           int layer = std::atoi(items[0].c_str());
0310           int waferU = std::atoi(items[6].c_str());
0311           int waferV = std::atoi(items[7].c_str());
0312           int thck = static_cast<int>(std::find(thick, thick + 3, items[2]) - thick);
0313           int part = static_cast<int>(std::find(partial, partial + 8, items[1]) - partial);
0314           int orient = std::atoi(items[5].c_str());
0315           wafer waf(thck, part, orient, 0);
0316           if (layer <= layMax1_) {
0317             int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV, false);
0318             module1[index] = waf;
0319           } else if ((layer <= layMax2_) || global) {
0320             int index = HGCalWaferIndex::waferIndex(layer - layMax1_, waferU, waferV, false);
0321             module2[index] = waf;
0322           } else {
0323             int index = HGCalWaferIndex::waferIndex(layer - layMax1_, waferU, waferV, false);
0324             module3[index] = waf;
0325           }
0326         }
0327       }
0328     }
0329     fInput.close();
0330     std::cout << "Read " << all << " records with " << comments << " comments " << others
0331               << " non-comment records out of which " << good << ":" << module1.size() << ":" << module2.size() << ":"
0332               << module3.size() << " are good and " << bad << " are bad\n"
0333               << std::endl;
0334     //Now write separately for EE, HEsil and HEmix
0335     writeSilicon(outfile1, module1, "EE", global, (debug % 10 > 0));
0336     // Next HEsil part
0337     writeSilicon(outfile2, module2, "HE", global, ((debug / 10) % 10 > 0));
0338     // Finally HEmix part
0339     if (!global)
0340       writeSilicon(outfile3, module3, "HE", global, ((debug / 100) % 10 > 0));
0341   }
0342 }
0343 
0344 void ConvertSiliconV0::writeSilicon(const char* outfile,
0345                                     const std::map<int, wafer>& module,
0346                                     const std::string& tag,
0347                                     const bool& mode,
0348                                     const bool& debug) {
0349   char apost('"');
0350   unsigned int k1(0), k2(0);
0351   std::map<int, wafer>::const_iterator itr;
0352   std::string blank("  ");
0353   std::ofstream fOut(outfile);
0354   std::vector<int> layerStart;
0355   int layer(-1);
0356   if (mode) {
0357     blank = "  ";
0358     fOut << blank << "<Vector name=" << apost << "WaferIndex" << tag << apost << " type=" << apost << "numeric" << apost
0359          << " nEntries=" << apost << module.size() << apost << ">";
0360   } else {
0361     blank = "    ";
0362     fOut << blank << "<Vector name=" << apost << "WaferIndex" << apost << " type=" << apost << "numeric" << apost
0363          << " nEntries=" << apost << module.size() << apost << ">";
0364   }
0365   for (itr = module.begin(); itr != module.end(); ++itr) {
0366     std::string last = ((k1 + 1) == module.size()) ? " " : ",";
0367     if (k1 % 7 == 0)
0368       fOut << "\n  " << blank << std::setw(8) << itr->first << last;
0369     else
0370       fOut << std::setw(8) << itr->first << last;
0371     if (HGCalWaferIndex::waferLayer(itr->first) != layer) {
0372       layerStart.emplace_back(k1);
0373       layer = HGCalWaferIndex::waferLayer(itr->first);
0374     }
0375     ++k1;
0376     if (debug)
0377       std::cout << "Wafer " << HGCalWaferIndex::waferLayer(itr->first) << ":" << HGCalWaferIndex::waferU(itr->first)
0378                 << ":" << HGCalWaferIndex::waferV(itr->first) << " T " << (itr->second).thick << " P "
0379                 << (itr->second).partial << " O " << (itr->second).orient << std::endl;
0380   }
0381   fOut << "\n" << blank << "</Vector>\n";
0382   if (mode)
0383     fOut << blank << "<Vector name=" << apost << "WaferProperties" << tag << apost << " type=" << apost << "numeric"
0384          << apost << " nEntries=" << apost << module.size() << apost << ">";
0385   else
0386     fOut << blank << "<Vector name=" << apost << "WaferProperties" << apost << " type=" << apost << "numeric" << apost
0387          << " nEntries=" << apost << module.size() << apost << ">";
0388   for (itr = module.begin(); itr != module.end(); ++itr) {
0389     int property = HGCalProperty::waferProperty(
0390         (itr->second).thick, (itr->second).partial, (itr->second).orient, (itr->second).cassette);
0391     std::string last = ((k2 + 1) == module.size()) ? " " : ",";
0392     if (k2 % 10 == 0)
0393       fOut << "\n  " << blank << std::setw(5) << property << last;
0394     else
0395       fOut << std::setw(5) << property << last;
0396     ++k2;
0397   }
0398   fOut << "\n" << blank << "</Vector>\n";
0399   if (mode) {
0400     fOut << blank << "<Vector name=" << apost << "WaferLayerStart" << tag << apost << " type=" << apost << "numeric"
0401          << apost << " nEntries=" << apost << layerStart.size() << apost << ">";
0402   } else {
0403     fOut << blank << "<Vector name=" << apost << "WaferLayerStart" << apost << " type=" << apost << "numeric" << apost
0404          << " nEntries=" << apost << layerStart.size() << apost << ">";
0405   }
0406   for (unsigned k3 = 0; k3 < layerStart.size(); ++k3) {
0407     std::string last = ((k3 + 1) == layerStart.size()) ? " " : ",";
0408     if (k3 % 10 == 0)
0409       fOut << "\n  " << blank << std::setw(5) << layerStart[k3] << last;
0410     else
0411       fOut << std::setw(5) << layerStart[k3] << last;
0412   }
0413   fOut << "\n" << blank << "</Vector>\n";
0414   fOut.close();
0415 }
0416 
0417 ConvertSiliconV1::ConvertSiliconV1(int layMax1, int layMax2) : layMax1_(layMax1), layMax2_(layMax2) {}
0418 
0419 void ConvertSiliconV1::convert(
0420     const char* infile, const char* outfile1, const char* outfile2, const char* outfile3, int modeGlobal, int debug) {
0421   std::ifstream fInput(infile);
0422   if (!fInput.good()) {
0423     std::cout << "Cannot open file " << infile << std::endl;
0424   } else {
0425     //First read in all records
0426     char buffer[1024];
0427     std::string thick[4] = {"h120", "l200", "l300", "h200"};
0428     int addType[4] = {HGCalTypes::WaferFineThin,
0429                       HGCalTypes::WaferCoarseThin,
0430                       HGCalTypes::WaferCoarseThick,
0431                       HGCalTypes::WaferFineThick};
0432     const int partTypeH[6] = {HGCalTypes::WaferFull,
0433                               HGCalTypes::WaferHalf2,
0434                               HGCalTypes::WaferChopTwoM,
0435                               HGCalTypes::WaferSemi2,
0436                               HGCalTypes::WaferSemi2,
0437                               HGCalTypes::WaferFive2};
0438     const int partTypeL[7] = {HGCalTypes::WaferFull,
0439                               HGCalTypes::WaferHalf,
0440                               HGCalTypes::WaferHalf,
0441                               HGCalTypes::WaferSemi,
0442                               HGCalTypes::WaferSemi,
0443                               HGCalTypes::WaferFive,
0444                               HGCalTypes::WaferThree};
0445     std::map<int, wafer> module1, module2, module3;
0446     unsigned int all(0), comments(0), others(0), bad(0), good(0);
0447     int layers(0);
0448     std::vector<int> layer1, layer2, layer3;
0449     bool global = (modeGlobal < 1);
0450     while (fInput.getline(buffer, 1024)) {
0451       ++all;
0452       if (debug % 10 > 1)
0453         std::cout << "[" << all << "] " << buffer << std::endl;
0454       if (buffer[0] == '#') {
0455         ++comments;
0456       } else {
0457         ++others;
0458         std::vector<std::string> items = splitString(std::string(buffer));
0459         if (others == 1) {
0460           layers = std::atoi(items[0].c_str());
0461         } else if (others == 2) {
0462           if (items.size() == static_cast<unsigned int>(layers)) {
0463             for (int k = 0; k < layers; ++k) {
0464               int ltype = std::atoi(items[k].c_str());
0465               if (k < layMax1_) {
0466                 layer1.emplace_back(ltype);
0467               } else if ((k < layMax2_) || global) {
0468                 layer2.emplace_back(ltype);
0469               } else {
0470                 layer3.emplace_back(ltype);
0471               }
0472             }
0473           } else {
0474             ++bad;
0475           }
0476         } else if (items.size() != 8) {
0477           ++bad;
0478         } else {
0479           ++good;
0480           int layer = std::atoi(items[0].c_str());
0481           int waferU = std::atoi(items[6].c_str());
0482           int waferV = std::atoi(items[7].c_str());
0483           int thck = static_cast<int>(std::find(thick, thick + 4, items[2]) - thick);
0484           int part = std::atoi(items[1].c_str());
0485           if ((thck < 4) && (part >= 0)) {
0486             if ((addType[thck] == HGCalTypes::WaferFineThin) || (addType[thck] == HGCalTypes::WaferFineThick))
0487               part = partTypeH[part];
0488             else
0489               part = partTypeL[part];
0490           }
0491           int orient = std::atoi(items[5].c_str());
0492           wafer waf(thck, part, orient, 0);
0493           if (layer <= layMax1_) {
0494             int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV, false);
0495             module1[index] = waf;
0496           } else if ((layer <= layMax2_) || global) {
0497             int index = HGCalWaferIndex::waferIndex(layer - layMax1_, waferU, waferV, false);
0498             module2[index] = waf;
0499           } else {
0500             int index = HGCalWaferIndex::waferIndex(layer - layMax1_, waferU, waferV, false);
0501             module3[index] = waf;
0502           }
0503         }
0504       }
0505     }
0506     fInput.close();
0507     std::cout << "Read " << all << " records with " << comments << " comments " << others
0508               << " non-comment records out of which " << good << ":" << module1.size() << ":" << module2.size() << ":"
0509               << module3.size() << " are good and " << bad << " are bad and with " << layers << " layers\n";
0510     std::cout << "\nThere are " << layer1.size() << " of types:" << std::endl;
0511     for (const auto& l : layer1)
0512       std::cout << " " << l;
0513     std::cout << "\nThere are " << layer2.size() << " of types:" << std::endl;
0514     for (const auto& l : layer2)
0515       std::cout << " " << l;
0516     if (layer3.size() > 0) {
0517       std::cout << "\nThere are " << layer3.size() << " of types:" << std::endl;
0518       for (const auto& l : layer3)
0519         std::cout << " " << l;
0520     }
0521     std::cout << std::endl << std::endl;
0522 
0523     //Now write separately for EE, HEsil and HEmix
0524     writeSilicon(outfile1, layer1, module1, "EE", global, (debug % 10 > 0));
0525     // Next HEsil part
0526     writeSilicon(outfile2, layer2, module2, "HE", global, ((debug / 10) % 10 > 0));
0527     // Finally HEmix part
0528     if (!global)
0529       writeSilicon(outfile3, layer3, module3, "HE", global, ((debug / 100) % 10 > 0));
0530   }
0531 }
0532 
0533 void ConvertSiliconV1::writeSilicon(const char* outfile,
0534                                     const std::vector<int>& layers,
0535                                     const std::map<int, wafer>& module,
0536                                     const std::string& tag,
0537                                     const bool& mode,
0538                                     const bool& debug) {
0539   char apost('"');
0540   unsigned int k0(0), k1(0), k2(0);
0541   std::map<int, wafer>::const_iterator itr;
0542   std::string blank = (mode) ? "  " : "    ";
0543   std::ofstream fOut(outfile);
0544   std::vector<int> layerStart;
0545   int layer(-1);
0546   if (mode)
0547     fOut << blank << "<Vector name=" << apost << "LayerTypes" << tag << apost << " type=" << apost << "numeric" << apost
0548          << " nEntries=" << apost << layers.size() << apost << ">";
0549   else
0550     fOut << blank << "<Vector name=" << apost << "LayerTypes" << apost << " type=" << apost << "numeric" << apost
0551          << " nEntries=" << apost << layers.size() << apost << ">";
0552   for (const auto& l : layers) {
0553     std::string last = ((k0 + 1) == layers.size()) ? " " : ",";
0554     if (k0 % 20 == 0)
0555       fOut << "\n  " << blank << std::setw(2) << l << last;
0556     else
0557       fOut << std::setw(2) << l << last;
0558     ++k0;
0559   }
0560   fOut << "\n" << blank << "</Vector>\n";
0561   if (mode) {
0562     fOut << blank << "<Vector name=" << apost << "WaferIndex" << tag << apost << " type=" << apost << "numeric" << apost
0563          << " nEntries=" << apost << module.size() << apost << ">";
0564   } else {
0565     fOut << blank << "<Vector name=" << apost << "WaferIndex" << apost << " type=" << apost << "numeric" << apost
0566          << " nEntries=" << apost << module.size() << apost << ">";
0567   }
0568   for (itr = module.begin(); itr != module.end(); ++itr) {
0569     std::string last = ((k1 + 1) == module.size()) ? " " : ",";
0570     if (k1 % 7 == 0)
0571       fOut << "\n  " << blank << std::setw(8) << itr->first << last;
0572     else
0573       fOut << std::setw(8) << itr->first << last;
0574     if (HGCalWaferIndex::waferLayer(itr->first) != layer) {
0575       layerStart.emplace_back(k1);
0576       layer = HGCalWaferIndex::waferLayer(itr->first);
0577     }
0578     ++k1;
0579     if (debug)
0580       std::cout << "Wafer " << HGCalWaferIndex::waferLayer(itr->first) << ":" << HGCalWaferIndex::waferU(itr->first)
0581                 << ":" << HGCalWaferIndex::waferV(itr->first) << " T " << (itr->second).thick << " P "
0582                 << (itr->second).partial << " O " << (itr->second).orient << std::endl;
0583   }
0584   fOut << "\n" << blank << "</Vector>\n";
0585   if (mode)
0586     fOut << blank << "<Vector name=" << apost << "WaferProperties" << tag << apost << " type=" << apost << "numeric"
0587          << apost << " nEntries=" << apost << module.size() << apost << ">";
0588   else
0589     fOut << blank << "<Vector name=" << apost << "WaferProperties" << apost << " type=" << apost << "numeric" << apost
0590          << " nEntries=" << apost << module.size() << apost << ">";
0591   for (itr = module.begin(); itr != module.end(); ++itr) {
0592     int property = HGCalProperty::waferProperty(
0593         (itr->second).thick, (itr->second).partial, (itr->second).orient, (itr->second).cassette);
0594     std::string last = ((k2 + 1) == module.size()) ? " " : ",";
0595     if (k2 % 10 == 0)
0596       fOut << "\n  " << blank << std::setw(5) << property << last;
0597     else
0598       fOut << std::setw(5) << property << last;
0599     ++k2;
0600   }
0601   fOut << "\n" << blank << "</Vector>\n";
0602   if (mode) {
0603     fOut << blank << "<Vector name=" << apost << "WaferLayerStart" << tag << apost << " type=" << apost << "numeric"
0604          << apost << " nEntries=" << apost << layerStart.size() << apost << ">";
0605   } else {
0606     fOut << blank << "<Vector name=" << apost << "WaferLayerStart" << apost << " type=" << apost << "numeric" << apost
0607          << " nEntries=" << apost << layerStart.size() << apost << ">";
0608   }
0609   for (unsigned k3 = 0; k3 < layerStart.size(); ++k3) {
0610     std::string last = ((k3 + 1) == layerStart.size()) ? " " : ",";
0611     if (k3 % 10 == 0)
0612       fOut << "\n  " << blank << std::setw(5) << layerStart[k3] << last;
0613     else
0614       fOut << std::setw(5) << layerStart[k3] << last;
0615   }
0616   fOut << "\n" << blank << "</Vector>\n";
0617   fOut.close();
0618 }
0619 
0620 ConvertSiliconV2::ConvertSiliconV2(unsigned int layMax1, unsigned int layMax2, unsigned int layMax3)
0621     : layMax1_(layMax1), layMax2_(layMax2), layMax3_(layMax3) {}
0622 
0623 void ConvertSiliconV2::convert(
0624     const char* infile, const char* outfile1, const char* outfile2, const char* outfile3, int modeGlobal, int debug) {
0625   std::ifstream fInput(infile);
0626   if (!fInput.good()) {
0627     std::cout << "Cannot open file " << infile << std::endl;
0628   } else {
0629     //First read in all records
0630     char buffer[1024];
0631     const int thksize = 4;
0632     std::string thick[thksize] = {"h120", "l200", "l300", "h200"};
0633     int addType[thksize] = {HGCalTypes::WaferFineThin,
0634                             HGCalTypes::WaferCoarseThin,
0635                             HGCalTypes::WaferCoarseThick,
0636                             HGCalTypes::WaferFineThick};
0637     const int partTypeH[6] = {HGCalTypes::WaferFull,
0638                               HGCalTypes::WaferHDTop,
0639                               HGCalTypes::WaferHDBottom,
0640                               HGCalTypes::WaferHDLeft,
0641                               HGCalTypes::WaferHDRight,
0642                               HGCalTypes::WaferHDFive};
0643     const int partTypeL[7] = {HGCalTypes::WaferFull,
0644                               HGCalTypes::WaferLDTop,
0645                               HGCalTypes::WaferLDBottom,
0646                               HGCalTypes::WaferLDLeft,
0647                               HGCalTypes::WaferLDRight,
0648                               HGCalTypes::WaferLDFive,
0649                               HGCalTypes::WaferLDThree};
0650     const unsigned int cassetteEE(12), cassetteHE(24);
0651     std::map<int, wafer> module1, module2, module3;
0652     unsigned int all(0), comments(0), others(0), bad(0), good(0);
0653     unsigned int layers(layMax3_);
0654     std::vector<layerInfo> layer1, layer2, layer3;
0655     int cminEE(-1), cmaxEE(-1), cminHE1(-1), cmaxHE1(-1), cminHE2(-1), cmaxHE2(-1);
0656     bool global = (modeGlobal < 1);
0657     while (fInput.getline(buffer, 1024)) {
0658       ++all;
0659       if (debug % 10 > 1)
0660         std::cout << "[" << all << "] " << buffer << std::endl;
0661       if (buffer[0] == '#') {
0662         ++comments;
0663       } else {
0664         ++others;
0665         std::vector<std::string> items = splitString(std::string(buffer));
0666         if (others <= layMax3_) {
0667           unsigned int cassettes = (others <= layMax1_) ? cassetteEE : cassetteHE;
0668           if (items.size() < (cassettes + 2)) {
0669             ++bad;
0670           } else {
0671             int layer = std::atoi(items[0].c_str());
0672             int type = std::atoi(items[1].c_str());
0673             std::vector<double> dR;
0674             for (unsigned int k = 0; k < cassettes; ++k)
0675               dR.emplace_back(std::atof(items[k + 2].c_str()));
0676             layerInfo ltype(layer, type, dR);
0677             if (others <= layMax1_) {
0678               layer1.emplace_back(ltype);
0679             } else if ((others <= layMax2_) || global) {
0680               layer2.emplace_back(ltype);
0681             } else {
0682               layer3.emplace_back(ltype);
0683             }
0684           }
0685         } else if (items.size() != 9) {
0686           ++bad;
0687         } else {
0688           ++good;
0689           unsigned int layer = std::atoi(items[0].c_str());
0690           int waferU = std::atoi(items[6].c_str());
0691           int waferV = std::atoi(items[7].c_str());
0692           int cassette = std::atoi(items[8].c_str());
0693           int thck = static_cast<int>(std::find(thick, thick + thksize, items[2]) - thick);
0694           int part = std::atoi(items[1].c_str());
0695           if ((thck <= thksize) && (part >= 0)) {
0696             if ((addType[thck] == HGCalTypes::WaferFineThin) || (addType[thck] == HGCalTypes::WaferFineThick))
0697               part = partTypeH[part];
0698             else
0699               part = partTypeL[part];
0700           }
0701           int orient = std::atoi(items[5].c_str());
0702           wafer waf(thck, part, orient, cassette);
0703           if (layer <= layMax1_) {
0704             int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV, false);
0705             module1[index] = waf;
0706             if ((cminEE < 0) || (cassette < cminEE))
0707               cminEE = cassette;
0708             if ((cmaxEE < 0) || (cassette > cmaxEE))
0709               cmaxEE = cassette;
0710           } else if ((layer <= layMax2_) || global) {
0711             int index = HGCalWaferIndex::waferIndex(layer - layMax1_, waferU, waferV, false);
0712             module2[index] = waf;
0713             if ((cminHE1 < 0) || (cassette < cminHE1))
0714               cminHE1 = cassette;
0715             if ((cmaxHE1 < 0) || (cassette > cmaxHE1))
0716               cmaxHE1 = cassette;
0717           } else {
0718             int index = HGCalWaferIndex::waferIndex(layer - layMax1_, waferU, waferV, false);
0719             module3[index] = waf;
0720             if ((cminHE2 < 0) || (cassette < cminHE2))
0721               cminHE2 = cassette;
0722             if ((cmaxHE2 < 0) || (cassette > cmaxHE2))
0723               cmaxHE2 = cassette;
0724           }
0725         }
0726       }
0727     }
0728     fInput.close();
0729     std::cout << "Read " << all << " records with " << comments << " comments " << others
0730               << " non-comment records out of which " << good << ":" << module1.size() << ":" << module2.size() << ":"
0731               << module3.size() << " are good and " << bad << " are bad and with " << layers << " layers\n";
0732     std::cout << "\nThere are " << layer1.size() << " of types:" << std::endl;
0733     for (const auto& l : layer1) {
0734       std::cout << "Layer " << l.layer << " Type " << l.type << " DR";
0735       for (unsigned int k = 0; k < l.deltaR.size(); ++k)
0736         std::cout << ": " << l.deltaR[k];
0737       std::cout << std::endl;
0738     }
0739     std::cout << "\nThere are " << layer2.size() << " of types:" << std::endl;
0740     for (const auto& l : layer2) {
0741       std::cout << "Layer " << l.layer << " Type " << l.type << " DR";
0742       for (unsigned int k = 0; k < l.deltaR.size(); ++k)
0743         std::cout << ": " << l.deltaR[k];
0744       std::cout << std::endl;
0745     }
0746     if (layer3.size() > 0) {
0747       std::cout << "\nThere are " << layer3.size() << " of types:" << std::endl;
0748       for (const auto& l : layer3) {
0749         std::cout << "Layer " << l.layer << " Type " << l.type << " DR";
0750         for (unsigned int k = 0; k < l.deltaR.size(); ++k)
0751           std::cout << ": " << l.deltaR[k];
0752         std::cout << std::endl;
0753       }
0754     }
0755     std::cout << "\nMinimum and Maximum Cassette #'s:: EE: " << cminEE << ":" << cmaxEE << " HEF: " << cminHE1 << ":"
0756               << cmaxHE1 << " HEB: " << cminHE2 << ":" << cmaxHE2 << std::endl;
0757     std::cout << std::endl << std::endl;
0758 
0759     //Now write separately for EE, HEsil and HEmix
0760     writeSilicon(outfile1, cassetteEE, layer1, module1, "EE", global, (debug % 10 > 0));
0761     // Next HEsil part
0762     writeSilicon(outfile2, cassetteHE, layer2, module2, "HE", global, ((debug / 10) % 10 > 0));
0763     // Finally HEmix part
0764     if (!global)
0765       writeSilicon(outfile3, cassetteHE, layer3, module3, "HE", global, ((debug / 100) % 10 > 0));
0766   }
0767 }
0768 
0769 void ConvertSiliconV2::writeSilicon(const char* outfile,
0770                                     const unsigned int cassettes,
0771                                     const std::vector<layerInfo>& layers,
0772                                     const std::map<int, wafer>& module,
0773                                     const std::string& tag,
0774                                     const bool& mode,
0775                                     const bool& debug) {
0776   char apost('"');
0777   unsigned int k0(0), k1(0), k2(0), k3(0);
0778   std::map<int, wafer>::const_iterator itr;
0779   std::string blank = (mode) ? "  " : "    ";
0780   std::ofstream fOut(outfile);
0781   std::vector<int> layerStart;
0782   int layer(-1);
0783   if (mode) {
0784     fOut << blank << "<Vector name=" << apost << "LayerTypes" << tag << apost << " type=" << apost << "numeric" << apost
0785          << " nEntries=" << apost << layers.size() << apost << ">";
0786   } else {
0787     fOut << blank << "<Vector name=" << apost << "LayerTypes" << apost << " type=" << apost << "numeric" << apost
0788          << " nEntries=" << apost << layers.size() << apost << ">";
0789   }
0790   for (const auto& l : layers) {
0791     std::string last = ((k0 + 1) == layers.size()) ? " " : ",";
0792     if (k0 % 20 == 0)
0793       fOut << "\n  " << blank << std::setw(2) << l.type << last;
0794     else
0795       fOut << std::setw(2) << l.type << last;
0796     ++k0;
0797   }
0798   fOut << "\n" << blank << "</Vector>\n";
0799   if (mode) {
0800     fOut << blank << "<Vector name=" << apost << "WaferIndex" << tag << apost << " type=" << apost << "numeric" << apost
0801          << " nEntries=" << apost << module.size() << apost << ">";
0802   } else {
0803     fOut << blank << "<Vector name=" << apost << "WaferIndex" << apost << " type=" << apost << "numeric" << apost
0804          << " nEntries=" << apost << module.size() << apost << ">";
0805   }
0806   for (itr = module.begin(); itr != module.end(); ++itr) {
0807     std::string last = ((k1 + 1) == module.size()) ? " " : ",";
0808     if (k1 % 7 == 0)
0809       fOut << "\n  " << blank << std::setw(8) << itr->first << last;
0810     else
0811       fOut << std::setw(8) << itr->first << last;
0812     if (HGCalWaferIndex::waferLayer(itr->first) != layer) {
0813       layerStart.emplace_back(k1);
0814       layer = HGCalWaferIndex::waferLayer(itr->first);
0815     }
0816     ++k1;
0817     if (debug)
0818       std::cout << "Wafer " << HGCalWaferIndex::waferLayer(itr->first) << ":" << HGCalWaferIndex::waferU(itr->first)
0819                 << ":" << HGCalWaferIndex::waferV(itr->first) << " T " << (itr->second).thick << " P "
0820                 << (itr->second).partial << " O " << (itr->second).orient << " C " << (itr->second).cassette
0821                 << " Property "
0822                 << HGCalProperty::waferProperty(
0823                        (itr->second).thick, (itr->second).partial, (itr->second).orient, (itr->second).cassette)
0824                 << std::endl;
0825   }
0826   fOut << "\n" << blank << "</Vector>\n";
0827   if (mode)
0828     fOut << blank << "<Vector name=" << apost << "WaferProperties" << tag << apost << " type=" << apost << "numeric"
0829          << apost << " nEntries=" << apost << module.size() << apost << ">";
0830   else
0831     fOut << blank << "<Vector name=" << apost << "WaferProperties" << apost << " type=" << apost << "numeric" << apost
0832          << " nEntries=" << apost << module.size() << apost << ">";
0833   for (itr = module.begin(); itr != module.end(); ++itr) {
0834     int property = HGCalProperty::waferProperty(
0835         (itr->second).thick, (itr->second).partial, (itr->second).orient, (itr->second).cassette);
0836     std::string last = ((k2 + 1) == module.size()) ? " " : ",";
0837     if (k2 % 8 == 0)
0838       fOut << "\n  " << blank << std::setw(7) << property << last;
0839     else
0840       fOut << std::setw(7) << property << last;
0841     ++k2;
0842   }
0843   fOut << "\n" << blank << "</Vector>\n";
0844   if (mode) {
0845     fOut << blank << "<Vector name=" << apost << "WaferLayerStart" << tag << apost << " type=" << apost << "numeric"
0846          << apost << " nEntries=" << apost << layerStart.size() << apost << ">";
0847   } else {
0848     fOut << blank << "<Vector name=" << apost << "WaferLayerStart" << apost << " type=" << apost << "numeric" << apost
0849          << " nEntries=" << apost << layerStart.size() << apost << ">";
0850   }
0851   for (unsigned k = 0; k < layerStart.size(); ++k) {
0852     std::string last = ((k + 1) == layerStart.size()) ? " " : ",";
0853     if (k % 10 == 0)
0854       fOut << "\n  " << blank << std::setw(5) << layerStart[k] << last;
0855     else
0856       fOut << std::setw(5) << layerStart[k] << last;
0857   }
0858   fOut << "\n" << blank << "</Vector>\n";
0859   unsigned int csize = cassettes * layers.size();
0860   if (mode) {
0861     fOut << blank << "<Vector name=" << apost << "CassetteShift" << tag << apost << " type=" << apost << "numeric"
0862          << apost << " nEntries=" << apost << csize << apost << ">";
0863   } else {
0864     fOut << blank << "<Vector name=" << apost << "CassetteShift" << apost << " type=" << apost << "numeric" << apost
0865          << " nEntries=" << apost << csize << apost << ">";
0866   }
0867   for (const auto& l : layers) {
0868     ++k3;
0869     for (unsigned int k = 0; k < cassettes; ++k) {
0870       std::string last = ((k3 == layers.size()) && ((k + 1) == cassettes)) ? "*mm" : "*mm,";
0871       if ((k % 6) == 0)
0872         fOut << "\n  " << blank << std::setw(9) << l.deltaR[k] << last;
0873       else
0874         fOut << std::setw(9) << l.deltaR[k] << last;
0875     }
0876   }
0877   fOut << "\n" << blank << "</Vector>\n";
0878   fOut.close();
0879 }
0880 
0881 ConvertScintillator::ConvertScintillator(int layMin, int cassette) : layMin_(layMin), cassette_(cassette) {}
0882 
0883 void ConvertScintillator::convert(const char* infile, const char* outfile1, const char* outfile2, int debug) {
0884   std::ifstream fInput(infile);
0885   if (!fInput.good()) {
0886     std::cout << "Cannot open file " << infile << std::endl;
0887   } else {
0888     //First read in all records
0889     char buffer[1024];
0890     std::string types[2] = {"c", "m"};
0891     std::map<int, tile> module;
0892     std::map<int, std::pair<double, double> > ringR;
0893     std::map<int, std::pair<int, int> > layerRing;
0894     unsigned int all(0), comments(0), others(0), bad(0), good(0);
0895     int lmin(99), lmax(0);
0896     while (fInput.getline(buffer, 1024)) {
0897       ++all;
0898       if (buffer[0] == '#') {
0899         ++comments;
0900       } else {
0901         ++others;
0902         std::vector<std::string> items = splitString(std::string(buffer));
0903         if (items.size() != 10) {
0904           ++bad;
0905         } else {
0906           ++good;
0907           int layer, ring, hex1, hex2, hex3, hex4;
0908           float rstart, rend, sipm;
0909           sscanf(
0910               buffer, "%d %d %f %f %f %X %X %X %X", &layer, &ring, &rstart, &rend, &sipm, &hex1, &hex2, &hex3, &hex4);
0911           int type = static_cast<int>(std::find(types, types + 1, items[9]) - types);
0912           if (layer > layMin_) {
0913             tile tl(sipm, hex1, hex2, hex3, hex4, type);
0914             int index = HGCalTileIndex::tileIndex(layer - layMin_, ring + 1, 0);
0915             module[index] = tl;
0916             lmin = std::min((layer - layMin_), lmin);
0917             lmax = std::max((layer - layMin_), lmax);
0918             ringR[ring] = std::pair<double, double>(rstart, rend);
0919             if (layerRing.find(layer) == layerRing.end()) {
0920               layerRing[layer] = std::pair<int, int>(ring, ring);
0921             } else {
0922               int rmin = std::min(ring, layerRing[layer].first);
0923               int rmax = std::max(ring, layerRing[layer].second);
0924               layerRing[layer] = std::pair<int, int>(rmin, rmax);
0925             }
0926           }
0927         }
0928       }
0929     }
0930     fInput.close();
0931     std::cout << "Read " << all << " records with " << comments << " comments " << others
0932               << " non-comment records out of which " << good << ":" << module.size() << ":" << ringR.size() << ":"
0933               << layerRing.size() << " are good and " << bad << " are bad\n"
0934               << std::endl;
0935 
0936     //Now write the content in the first file
0937     std::ofstream fOut(outfile1);
0938     char apost('"');
0939     unsigned int l1(0), l2(0);
0940     std::map<int, std::pair<double, double> >::const_iterator it1;
0941     fOut << "  <Vector name=" << apost << "TileRMin" << apost << " type=" << apost << "numeric" << apost
0942          << " nEntries=" << apost << ringR.size() << apost << ">";
0943     for (it1 = ringR.begin(); it1 != ringR.end(); ++it1) {
0944       std::string last = ((l1 + 1) == ringR.size()) ? " " : ",";
0945       if (l1 % 6 == 0)
0946         fOut << "\n    " << std::setw(8) << std::setprecision(6) << (it1->second).first << "*mm" << last;
0947       else
0948         fOut << std::setw(8) << std::setprecision(6) << (it1->second).first << "*mm" << last;
0949       ++l1;
0950     }
0951     fOut << "\n  </Vector>\n";
0952     fOut << "  <Vector name=" << apost << "TileRMax" << apost << " type=" << apost << "numeric" << apost
0953          << " nEntries=" << apost << ringR.size() << apost << ">";
0954     for (it1 = ringR.begin(); it1 != ringR.end(); ++it1) {
0955       std::string last = ((l2 + 1) == ringR.size()) ? " " : ",";
0956       if (l2 % 6 == 0)
0957         fOut << "\n    " << std::setw(8) << std::setprecision(6) << (it1->second).second << "*mm" << last;
0958       else
0959         fOut << std::setw(8) << std::setprecision(6) << (it1->second).second << "*mm" << last;
0960       ++l2;
0961     }
0962     fOut << "\n  </Vector>\n";
0963 
0964     unsigned int l3(0), l4(0);
0965     std::map<int, std::pair<int, int> >::const_iterator it2;
0966     fOut << "  <Vector name=" << apost << "TileRingMin" << apost << " type=" << apost << "numeric" << apost
0967          << " nEntries=" << apost << layerRing.size() << apost << ">";
0968     for (it2 = layerRing.begin(); it2 != layerRing.end(); ++it2) {
0969       std::string last = ((l3 + 1) == layerRing.size()) ? " " : ",";
0970       if (l3 % 14 == 0)
0971         fOut << "\n    " << std::setw(4) << (it2->second).first << last;
0972       else
0973         fOut << std::setw(4) << (it2->second).first << last;
0974       ++l3;
0975     }
0976     fOut << "\n  </Vector>\n";
0977     fOut << "  <Vector name=" << apost << "TileRingMax" << apost << " type=" << apost << "numeric" << apost
0978          << " nEntries=" << apost << layerRing.size() << apost << ">";
0979     for (it2 = layerRing.begin(); it2 != layerRing.end(); ++it2) {
0980       std::string last = ((l4 + 1) == layerRing.size()) ? " " : ",";
0981       if (l4 % 14 == 0)
0982         fOut << "\n    " << std::setw(4) << (it2->second).second << last;
0983       else
0984         fOut << std::setw(4) << (it2->second).second << last;
0985       ++l4;
0986     }
0987     fOut << "\n  </Vector>\n";
0988 
0989     unsigned int k1(0), k2(0), k3(0), k4(0), k5(0), k6(0);
0990     std::map<int, tile>::const_iterator itr;
0991     fOut << "  <Vector name=" << apost << "TileIndex" << apost << " type=" << apost << "numeric" << apost
0992          << " nEntries=" << apost << module.size() << apost << ">";
0993     for (itr = module.begin(); itr != module.end(); ++itr) {
0994       std::string last = ((k1 + 1) == module.size()) ? " " : ",";
0995       if (k1 % 7 == 0)
0996         fOut << "\n    " << std::setw(8) << itr->first << last;
0997       else
0998         fOut << std::setw(8) << itr->first << last;
0999       ++k1;
1000       if ((debug % 10) > 0)
1001         std::cout << "Tile " << HGCalTileIndex::tileLayer(itr->first) << ":" << HGCalTileIndex::tileRing(itr->first)
1002                   << " Type " << (itr->second).type << " Area " << (itr->second).sipm << std::hex << " HEX "
1003                   << (itr->second).hex[0] << " " << (itr->second).hex[1] << " " << (itr->second).hex[2] << " "
1004                   << (itr->second).hex[3] << std::dec << "\n";
1005     }
1006     fOut << "\n  </Vector>\n";
1007     fOut << "  <Vector name=" << apost << "TileProperty" << apost << " type=" << apost << "numeric" << apost
1008          << " nEntries=" << apost << module.size() << apost << ">";
1009     for (itr = module.begin(); itr != module.end(); ++itr) {
1010       std::string last = ((k2 + 1) == module.size()) ? " " : ",";
1011       int property = HGCalTileIndex::tileProperty((itr->second).type, (itr->second).sipm);
1012       if (k2 % 15 == 0)
1013         fOut << "\n    " << std::setw(3) << property << last;
1014       else
1015         fOut << std::setw(3) << property << last;
1016       ++k2;
1017     }
1018     fOut << "\n  </Vector>\n";
1019     fOut << "  <Vector name=" << apost << "TileHEX1" << apost << " type=" << apost << "numeric" << apost
1020          << " nEntries=" << apost << module.size() << apost << ">" << std::hex;
1021     for (itr = module.begin(); itr != module.end(); ++itr) {
1022       std::string last = ((k3 + 1) == module.size()) ? " " : ",";
1023       if (k3 % 6 == 0)
1024         fOut << "\n     0x" << (itr->second).hex[0] << last;
1025       else
1026         fOut << " 0x" << (itr->second).hex[0] << last;
1027       ++k3;
1028     }
1029     fOut << "\n  </Vector>\n" << std::dec;
1030     fOut << "  <Vector name=" << apost << "TileHEX2" << apost << " type=" << apost << "numeric" << apost
1031          << " nEntries=" << apost << module.size() << apost << ">" << std::hex;
1032     for (itr = module.begin(); itr != module.end(); ++itr) {
1033       std::string last = ((k4 + 1) == module.size()) ? " " : ",";
1034       if (k4 % 6 == 0)
1035         fOut << "\n     0x" << (itr->second).hex[1] << last;
1036       else
1037         fOut << " 0x" << (itr->second).hex[1] << last;
1038       ++k4;
1039     }
1040     fOut << "\n  </Vector>\n" << std::dec;
1041     fOut << "  <Vector name=" << apost << "TileHEX3" << apost << " type=" << apost << "numeric" << apost
1042          << " nEntries=" << apost << module.size() << apost << ">" << std::hex;
1043     for (itr = module.begin(); itr != module.end(); ++itr) {
1044       std::string last = ((k5 + 1) == module.size()) ? " " : ",";
1045       if (k5 % 6 == 0)
1046         fOut << "\n     0x" << (itr->second).hex[2] << last;
1047       else
1048         fOut << " 0x" << (itr->second).hex[2] << last;
1049       ++k5;
1050     }
1051     fOut << "\n  </Vector>\n" << std::dec;
1052     fOut << "  <Vector name=" << apost << "TileHEX4" << apost << " type=" << apost << "numeric" << apost
1053          << " nEntries=" << apost << module.size() << apost << ">" << std::hex;
1054     for (itr = module.begin(); itr != module.end(); ++itr) {
1055       std::string last = ((k6 + 1) == module.size()) ? " " : ",";
1056       if (k6 % 6 == 0)
1057         fOut << "\n     0x" << (itr->second).hex[3] << last;
1058       else
1059         fOut << " 0x" << (itr->second).hex[3] << last;
1060       ++k6;
1061     }
1062     fOut << "\n  </Vector>\n" << std::dec;
1063     fOut.close();
1064 
1065     //Now write for the second file
1066     makeTitle(outfile2, module, ringR, lmin, lmax, (((debug / 10) % 10) > 0));
1067   }
1068 }
1069 
1070 void ConvertScintillator::makeTitle(const char* outfile,
1071                                     const std::map<int, tile>& module,
1072                                     const std::map<int, std::pair<double, double> >& ringR,
1073                                     int lmin,
1074                                     int lmax,
1075                                     bool debug) {
1076   const int zside = 1;
1077   const int phiCassette = 24;
1078   std::vector<tileZone> zones;
1079   for (int layer = lmin; layer <= lmax; ++layer) {
1080     tileZone tile0;
1081     int kk, irmin, irmax;
1082     for (int phi = 1; phi <= HGCalProperty::kHGCalTilePhis; ++phi) {
1083       kk = irmin = irmax = 0;
1084       for (std::map<int, tile>::const_iterator itr = module.begin(); itr != module.end(); ++itr) {
1085         if ((HGCalTileIndex::tileLayer(itr->first) == layer) &&
1086             HGCalTileIndex::tileExist((itr->second).hex, zside, phi)) {
1087           int ir = HGCalTileIndex::tileRing(itr->first);
1088           if (kk == 0) {
1089             irmin = irmax = ir;
1090           } else {
1091             irmax = ir;
1092           }
1093           ++kk;
1094         }
1095       }
1096       if (debug)
1097         std::cout << "Layer|Phi|Ring " << layer << ":" << phi << ":" << irmin << ":" << irmax << std::endl;
1098       if (phi == 1) {
1099         tile0.layer = layer;
1100         tile0.rmin = irmin;
1101         tile0.rmax = irmax;
1102         tile0.phimin = phi;
1103         tile0.phimax = phi;
1104         tile0.cassette = (cassette_ == 0) ? 0 : 1;
1105       } else if ((tile0.rmin != irmin) || (tile0.rmax != irmax)) {
1106         if (cassette_ != 0) {
1107           if (tile0.cassette * phiCassette < tile0.phimax) {
1108             do {
1109               int phimax = tile0.phimax;
1110               tile0.phimax = tile0.cassette * phiCassette;
1111               zones.push_back(tile0);
1112               tile0.phimin = tile0.phimax + 1;
1113               tile0.phimax = phimax;
1114               ++tile0.cassette;
1115             } while (tile0.cassette * phiCassette < tile0.phimax);
1116           }
1117         }
1118         zones.push_back(tile0);
1119         int cassette = (cassette_ == 0) ? 0 : (1 + ((phi - 1) / phiCassette));
1120         tile0.layer = layer;
1121         tile0.rmin = irmin;
1122         tile0.rmax = irmax;
1123         tile0.phimin = phi;
1124         tile0.phimax = phi;
1125         tile0.cassette = cassette;
1126         if (phi == HGCalProperty::kHGCalTilePhis)
1127           zones.push_back(tile0);
1128       } else {
1129         tile0.phimax = phi;
1130         if (phi == HGCalProperty::kHGCalTilePhis)
1131           zones.push_back(tile0);
1132       }
1133     }
1134   }
1135 
1136   int nmax = zones.size();
1137   if (debug) {
1138     std::cout << "\nA total of " << nmax << " zones " << std::endl;
1139     for (int k = 0; k < nmax; ++k)
1140       std::cout << "[" << k << "] Layer " << zones[k].layer << " Ring " << zones[k].rmin << ":" << zones[k].rmax
1141                 << " phi " << zones[k].phimin << ":" << zones[k].phimax << " Cassette " << zones[k].cassette
1142                 << std::endl;
1143   }
1144   if (nmax > 0) {
1145     std::ofstream fout(outfile);
1146     char apost('"');
1147     unsigned int l1(0), l2(0);
1148     std::map<int, std::pair<double, double> >::const_iterator it1;
1149     fout << "  <Vector name=" << apost << "TileRMin" << apost << " type=" << apost << "numeric" << apost
1150          << " nEntries=" << apost << ringR.size() << apost << ">";
1151     for (it1 = ringR.begin(); it1 != ringR.end(); ++it1) {
1152       std::string last = ((l1 + 1) == ringR.size()) ? " " : ",";
1153       if (l1 % 6 == 0)
1154         fout << "\n    " << std::setw(8) << std::setprecision(6) << (it1->second).first << "*mm" << last;
1155       else
1156         fout << std::setw(8) << std::setprecision(6) << (it1->second).first << "*mm" << last;
1157       ++l1;
1158     }
1159     fout << "\n  </Vector>\n";
1160     fout << "  <Vector name=" << apost << "TileRMax" << apost << " type=" << apost << "numeric" << apost
1161          << " nEntries=" << apost << ringR.size() << apost << ">";
1162     for (it1 = ringR.begin(); it1 != ringR.end(); ++it1) {
1163       std::string last = ((l2 + 1) == ringR.size()) ? " " : ",";
1164       if (l2 % 6 == 0)
1165         fout << "\n    " << std::setw(8) << std::setprecision(6) << (it1->second).second << "*mm" << last;
1166       else
1167         fout << std::setw(8) << std::setprecision(6) << (it1->second).second << "*mm" << last;
1168       ++l2;
1169     }
1170     fout << "\n  </Vector>\n";
1171     fout << "  <Vector name=" << apost << "TileLayerRings" << apost << " type=" << apost << "numeric" << apost
1172          << " nEntries=" << apost << nmax << apost << ">";
1173     if (debug)
1174       std::cout << "  <Vector name=" << apost << "TileLayerRings" << apost << " type=" << apost << "numeric" << apost
1175                 << " nEntries=" << apost << nmax << apost << ">";
1176     for (int k = 0; k < nmax; ++k) {
1177       std::string last = ((k + 1) == nmax) ? " " : ",";
1178       int lyr1r2 = HGCalTileIndex::tilePack(zones[k].layer, zones[k].rmin, zones[k].rmax);
1179       if (k % 7 == 0) {
1180         fout << "\n    " << std::setw(9) << lyr1r2 << last;
1181         if (debug)
1182           std::cout << "\n    " << std::setw(9) << lyr1r2 << last;
1183       } else {
1184         fout << std::setw(9) << lyr1r2 << last;
1185         if (debug)
1186           std::cout << std::setw(9) << lyr1r2 << last;
1187       }
1188     }
1189     fout << "\n  </Vector>\n";
1190     if (debug)
1191       std::cout << "\n  </Vector>\n";
1192     int layer = -1;
1193     std::vector<int> layerStart;
1194     fout << "  <Vector name=" << apost << "TilePhiRange" << apost << " type=" << apost << "numeric" << apost
1195          << " nEntries=" << apost << nmax << apost << ">";
1196     if (debug)
1197       std::cout << "  <Vector name=" << apost << "TilePhiRange" << apost << " type=" << apost << "numeric" << apost
1198                 << " nEntries=" << apost << nmax << apost << ">";
1199     for (int k = 0; k < nmax; ++k) {
1200       std::string last = ((k + 1) == nmax) ? " " : ",";
1201       int f1f2 = HGCalTileIndex::tilePack(zones[k].cassette, zones[k].phimin, zones[k].phimax);
1202       if (k % 7 == 0) {
1203         fout << "\n    " << std::setw(9) << f1f2 << last;
1204         if (debug)
1205           std::cout << "\n    " << std::setw(9) << f1f2 << last;
1206       } else {
1207         fout << std::setw(9) << f1f2 << last;
1208         if (debug)
1209           std::cout << std::setw(9) << f1f2 << last;
1210       }
1211       if (zones[k].layer != layer) {
1212         layerStart.emplace_back(k);
1213         layer = zones[k].layer;
1214       }
1215     }
1216     fout << "\n  </Vector>\n";
1217     if (debug)
1218       std::cout << "\n  </Vector>\n";
1219     fout << "  <Vector name=" << apost << "TileLayerStart" << apost << " type=" << apost << "numeric" << apost
1220          << " nEntries=" << apost << layerStart.size() << apost << ">";
1221     if (debug)
1222       std::cout << "  <Vector name=" << apost << "TileLayerStart" << apost << " type=" << apost << "numeric" << apost
1223                 << " nEntries=" << apost << layerStart.size() << apost << ">";
1224     for (unsigned int k = 0; k < layerStart.size(); ++k) {
1225       std::string last = ((k + 1) == layerStart.size()) ? " " : ",";
1226       if (k % 10 == 0) {
1227         fout << "\n    " << std::setw(5) << layerStart[k] << last;
1228         if (debug)
1229           std::cout << "\n    " << std::setw(5) << layerStart[k] << last;
1230       } else {
1231         fout << std::setw(5) << layerStart[k] << last;
1232         if (debug)
1233           std::cout << std::setw(5) << layerStart[k] << last;
1234       }
1235     }
1236     fout << "\n  </Vector>\n";
1237     if (debug)
1238       std::cout << "\n  </Vector>\n";
1239     fout.close();
1240   }
1241 }
1242 
1243 ConvertNoseV0::ConvertNoseV0(unsigned int layMax1, unsigned int layMax2) : layMax1_(layMax1), layMax2_(layMax2) {
1244   std::cout << "ConvertNoseV0 Iniltailized with " << layMax1_ << ":" << layMax2_ << std::endl;
1245 }
1246 
1247 void ConvertNoseV0::convert(const char* infile, const char* outfile1, const char* outfile2, int modeGlobal, int debug) {
1248   std::ifstream fInput(infile);
1249   if (!fInput.good()) {
1250     std::cout << "Cannot open file " << infile << std::endl;
1251   } else {
1252     //First read in all records
1253     char buffer[1024];
1254     const int thksize = 4;
1255     std::string thick[thksize] = {"h120", "l200", "l300", "h200"};
1256     int addType[thksize] = {HGCalTypes::WaferFineThin,
1257                             HGCalTypes::WaferCoarseThin,
1258                             HGCalTypes::WaferCoarseThick,
1259                             HGCalTypes::WaferFineThick};
1260     const int partTypeH[6] = {HGCalTypes::WaferFull,
1261                               HGCalTypes::WaferHDTop,
1262                               HGCalTypes::WaferHDBottom,
1263                               HGCalTypes::WaferHDLeft,
1264                               HGCalTypes::WaferHDRight,
1265                               HGCalTypes::WaferHDFive};
1266     const int partTypeL[7] = {HGCalTypes::WaferFull,
1267                               HGCalTypes::WaferLDTop,
1268                               HGCalTypes::WaferLDBottom,
1269                               HGCalTypes::WaferLDLeft,
1270                               HGCalTypes::WaferLDRight,
1271                               HGCalTypes::WaferLDFive,
1272                               HGCalTypes::WaferLDThree};
1273     const unsigned int cassetteEE(12), cassetteHE(24);
1274     std::map<int, wafer> module1, module2;
1275     unsigned int all(0), comments(0), others(0), bad(0), good(0);
1276     unsigned int layers(layMax2_);
1277     std::vector<layerInfo> layer1, layer2;
1278     int cminEE(-1), cmaxEE(-1), cminHE(-1), cmaxHE(-1);
1279     bool global = (modeGlobal < 1);
1280     while (fInput.getline(buffer, 1024)) {
1281       ++all;
1282       if (debug % 10 > 1)
1283         std::cout << "[" << all << "] " << buffer << std::endl;
1284       if (buffer[0] == '#') {
1285         ++comments;
1286       } else {
1287         ++others;
1288         std::vector<std::string> items = splitString(std::string(buffer));
1289         if (others <= layMax2_) {
1290           unsigned int cassettes = (others <= layMax1_) ? cassetteEE : cassetteHE;
1291           if (items.size() < (cassettes + 2)) {
1292             if (debug % 10 > 1)
1293               std::cout << "Size " << items.size() << " expect >= " << (cassettes + 2) << std::endl;
1294             ++bad;
1295           } else {
1296             int layer = std::atoi(items[0].c_str());
1297             int type = std::atoi(items[1].c_str());
1298             std::vector<double> dR;
1299             for (unsigned int k = 0; k < cassettes; ++k)
1300               dR.emplace_back(std::atof(items[k + 2].c_str()));
1301             layerInfo ltype(layer, type, dR);
1302             if (others <= layMax1_) {
1303               layer1.emplace_back(ltype);
1304             } else {
1305               layer2.emplace_back(ltype);
1306             }
1307           }
1308         } else if (items.size() != 9) {
1309           ++bad;
1310         } else {
1311           ++good;
1312           unsigned int layer = std::atoi(items[0].c_str());
1313           int waferU = std::atoi(items[6].c_str());
1314           int waferV = std::atoi(items[7].c_str());
1315           int cassette = std::atoi(items[8].c_str());
1316           int thck = static_cast<int>(std::find(thick, thick + thksize, items[2]) - thick);
1317           int part = std::atoi(items[1].c_str());
1318           if ((thck <= thksize) && (part >= 0)) {
1319             if ((addType[thck] == HGCalTypes::WaferFineThin) || (addType[thck] == HGCalTypes::WaferFineThick))
1320               part = partTypeH[part];
1321             else
1322               part = partTypeL[part];
1323           }
1324           int orient = std::atoi(items[5].c_str());
1325           wafer waf(thck, part, orient, cassette);
1326           if (layer <= layMax1_) {
1327             int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV, false);
1328             module1[index] = waf;
1329             if ((cminEE < 0) || (cassette < cminEE))
1330               cminEE = cassette;
1331             if ((cmaxEE < 0) || (cassette > cmaxEE))
1332               cmaxEE = cassette;
1333           } else {
1334             int index = HGCalWaferIndex::waferIndex(layer - layMax1_, waferU, waferV, false);
1335             module2[index] = waf;
1336             if ((cminHE < 0) || (cassette < cminHE))
1337               cminHE = cassette;
1338             if ((cmaxHE < 0) || (cassette > cmaxHE))
1339               cmaxHE = cassette;
1340           }
1341         }
1342       }
1343     }
1344     fInput.close();
1345     std::cout << "Read " << all << " records with " << comments << " comments " << others
1346               << " non-comment records out of which " << good << ":" << module1.size() << ":" << module2.size()
1347               << " are good and " << bad << " are bad and with " << layers << " layers\n";
1348     std::cout << "\nThere are " << layer1.size() << " of types:" << std::endl;
1349     for (const auto& l : layer1) {
1350       std::cout << "Layer " << l.layer << " Type " << l.type << " DR";
1351       for (unsigned int k = 0; k < l.deltaR.size(); ++k)
1352         std::cout << ": " << l.deltaR[k];
1353       std::cout << std::endl;
1354     }
1355     std::cout << "\nThere are " << layer2.size() << " of types:" << std::endl;
1356     for (const auto& l : layer2) {
1357       std::cout << "Layer " << l.layer << " Type " << l.type << " DR";
1358       for (unsigned int k = 0; k < l.deltaR.size(); ++k)
1359         std::cout << ": " << l.deltaR[k];
1360       std::cout << std::endl;
1361     }
1362     std::cout << "\nMinimum and Maximum Cassette #'s:: EE: " << cminEE << ":" << cmaxEE << " HE: " << cminHE << ":"
1363               << cmaxHE << std::endl;
1364     std::cout << std::endl << std::endl;
1365 
1366     //Now write separately for EE and HE
1367     writeNose(outfile1, cassetteEE, layer1, module1, "EE", global, (debug % 10 > 0));
1368     // Next HEsil part
1369     writeNose(outfile2, cassetteHE, layer2, module2, "HE", global, ((debug / 10) % 10 > 0));
1370   }
1371 }
1372 
1373 void ConvertNoseV0::writeNose(const char* outfile,
1374                               const unsigned int cassettes,
1375                               const std::vector<layerInfo>& layers,
1376                               const std::map<int, wafer>& module,
1377                               const std::string& tag,
1378                               const bool& mode,
1379                               const bool& debug) {
1380   char apost('"');
1381   unsigned int k0(0), k1(0), k2(0), k3(0);
1382   std::map<int, wafer>::const_iterator itr;
1383   std::string blank = (mode) ? "  " : "    ";
1384   std::ofstream fOut(outfile);
1385   std::vector<int> layerStart;
1386   int layer(-1);
1387   if (mode) {
1388     fOut << blank << "<Vector name=" << apost << "LayerTypes" << tag << apost << " type=" << apost << "numeric" << apost
1389          << " nEntries=" << apost << layers.size() << apost << ">";
1390   } else {
1391     fOut << blank << "<Vector name=" << apost << "LayerTypes" << apost << " type=" << apost << "numeric" << apost
1392          << " nEntries=" << apost << layers.size() << apost << ">";
1393   }
1394   for (const auto& l : layers) {
1395     std::string last = ((k0 + 1) == layers.size()) ? " " : ",";
1396     if (k0 % 20 == 0)
1397       fOut << "\n  " << blank << std::setw(2) << l.type << last;
1398     else
1399       fOut << std::setw(2) << l.type << last;
1400     ++k0;
1401   }
1402   fOut << "\n" << blank << "</Vector>\n";
1403   if (mode) {
1404     fOut << blank << "<Vector name=" << apost << "WaferIndex" << tag << apost << " type=" << apost << "numeric" << apost
1405          << " nEntries=" << apost << module.size() << apost << ">";
1406   } else {
1407     fOut << blank << "<Vector name=" << apost << "WaferIndex" << apost << " type=" << apost << "numeric" << apost
1408          << " nEntries=" << apost << module.size() << apost << ">";
1409   }
1410   for (itr = module.begin(); itr != module.end(); ++itr) {
1411     std::string last = ((k1 + 1) == module.size()) ? " " : ",";
1412     if (k1 % 7 == 0)
1413       fOut << "\n  " << blank << std::setw(8) << itr->first << last;
1414     else
1415       fOut << std::setw(8) << itr->first << last;
1416     if (HGCalWaferIndex::waferLayer(itr->first) != layer) {
1417       layerStart.emplace_back(k1);
1418       layer = HGCalWaferIndex::waferLayer(itr->first);
1419     }
1420     ++k1;
1421     if (debug)
1422       std::cout << "Wafer " << HGCalWaferIndex::waferLayer(itr->first) << ":" << HGCalWaferIndex::waferU(itr->first)
1423                 << ":" << HGCalWaferIndex::waferV(itr->first) << " T " << (itr->second).thick << " P "
1424                 << (itr->second).partial << " O " << (itr->second).orient << " C " << (itr->second).cassette
1425                 << " Property "
1426                 << HGCalProperty::waferProperty(
1427                        (itr->second).thick, (itr->second).partial, (itr->second).orient, (itr->second).cassette)
1428                 << std::endl;
1429   }
1430   fOut << "\n" << blank << "</Vector>\n";
1431   if (mode)
1432     fOut << blank << "<Vector name=" << apost << "WaferProperties" << tag << apost << " type=" << apost << "numeric"
1433          << apost << " nEntries=" << apost << module.size() << apost << ">";
1434   else
1435     fOut << blank << "<Vector name=" << apost << "WaferProperties" << apost << " type=" << apost << "numeric" << apost
1436          << " nEntries=" << apost << module.size() << apost << ">";
1437   for (itr = module.begin(); itr != module.end(); ++itr) {
1438     int property = HGCalProperty::waferProperty(
1439         (itr->second).thick, (itr->second).partial, (itr->second).orient, (itr->second).cassette);
1440     std::string last = ((k2 + 1) == module.size()) ? " " : ",";
1441     if (k2 % 8 == 0)
1442       fOut << "\n  " << blank << std::setw(7) << property << last;
1443     else
1444       fOut << std::setw(7) << property << last;
1445     ++k2;
1446   }
1447   fOut << "\n" << blank << "</Vector>\n";
1448   if (mode) {
1449     fOut << blank << "<Vector name=" << apost << "WaferLayerStart" << tag << apost << " type=" << apost << "numeric"
1450          << apost << " nEntries=" << apost << layerStart.size() << apost << ">";
1451   } else {
1452     fOut << blank << "<Vector name=" << apost << "WaferLayerStart" << apost << " type=" << apost << "numeric" << apost
1453          << " nEntries=" << apost << layerStart.size() << apost << ">";
1454   }
1455   for (unsigned k = 0; k < layerStart.size(); ++k) {
1456     std::string last = ((k + 1) == layerStart.size()) ? " " : ",";
1457     if (k % 10 == 0)
1458       fOut << "\n  " << blank << std::setw(5) << layerStart[k] << last;
1459     else
1460       fOut << std::setw(5) << layerStart[k] << last;
1461   }
1462   fOut << "\n" << blank << "</Vector>\n";
1463   unsigned int csize = cassettes * layers.size();
1464   if (mode) {
1465     fOut << blank << "<Vector name=" << apost << "CassetteShift" << tag << apost << " type=" << apost << "numeric"
1466          << apost << " nEntries=" << apost << csize << apost << ">";
1467   } else {
1468     fOut << blank << "<Vector name=" << apost << "CassetteShift" << apost << " type=" << apost << "numeric" << apost
1469          << " nEntries=" << apost << csize << apost << ">";
1470   }
1471   for (const auto& l : layers) {
1472     ++k3;
1473     for (unsigned int k = 0; k < cassettes; ++k) {
1474       std::string last = ((k3 == layers.size()) && ((k + 1) == cassettes)) ? "*mm" : "*mm,";
1475       if ((k % 6) == 0)
1476         fOut << "\n  " << blank << std::setw(9) << l.deltaR[k] << last;
1477       else
1478         fOut << std::setw(9) << l.deltaR[k] << last;
1479     }
1480   }
1481   fOut << "\n" << blank << "</Vector>\n";
1482   fOut.close();
1483 }