Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:34

0001 #include <fstream>
0002 #include <iostream>
0003 
0004 #include "CalibMuon/CSCCalibration/interface/CSCNoiseMatrixConditions.h"
0005 
0006 CSCNoiseMatrix *CSCNoiseMatrixConditions::prefillNoiseMatrix() {
0007   int old_chamber_id, old_strip, new_chamber_id, new_strip;
0008   float old_elm33, old_elm34, old_elm44, old_elm35, old_elm45, old_elm55;
0009   float old_elm46, old_elm56, old_elm66, old_elm57, old_elm67, old_elm77;
0010   std::vector<int> old_cham_id;
0011   std::vector<int> old_strips;
0012   std::vector<float> old_elem33;
0013   std::vector<float> old_elem34;
0014   std::vector<float> old_elem44;
0015   std::vector<float> old_elem45;
0016   std::vector<float> old_elem35;
0017   std::vector<float> old_elem55;
0018   std::vector<float> old_elem46;
0019   std::vector<float> old_elem56;
0020   std::vector<float> old_elem66;
0021   std::vector<float> old_elem57;
0022   std::vector<float> old_elem67;
0023   std::vector<float> old_elem77;
0024 
0025   float new_elm33, new_elm34, new_elm44, new_elm35, new_elm45, new_elm55;
0026   float new_elm46, new_elm56, new_elm66, new_elm57, new_elm67, new_elm77;
0027   std::vector<int> new_cham_id;
0028   std::vector<int> new_strips;
0029   std::vector<float> new_elem33;
0030   std::vector<float> new_elem34;
0031   std::vector<float> new_elem44;
0032   std::vector<float> new_elem45;
0033   std::vector<float> new_elem35;
0034   std::vector<float> new_elem55;
0035   std::vector<float> new_elem46;
0036   std::vector<float> new_elem56;
0037   std::vector<float> new_elem66;
0038   std::vector<float> new_elem57;
0039   std::vector<float> new_elem67;
0040   std::vector<float> new_elem77;
0041 
0042   const CSCDetId &detId = CSCDetId();
0043   CSCNoiseMatrix *cnmatrix = new CSCNoiseMatrix();
0044 
0045   int max_istrip, id_layer, max_ring, max_cham;
0046   unsigned int old_nrlines = 0;
0047   unsigned int new_nrlines = 0;
0048 
0049   std::ifstream olddata;
0050   olddata.open("old_matrix.dat", std::ios::in);
0051   if (!olddata) {
0052     std::cerr << "Error: old_matrix.dat -> no such file!" << std::endl;
0053     exit(1);
0054   }
0055 
0056   while (!olddata.eof()) {
0057     olddata >> old_chamber_id >> old_strip >> old_elm33 >> old_elm34 >> old_elm44 >> old_elm35 >> old_elm45 >>
0058         old_elm55 >> old_elm46 >> old_elm56 >> old_elm66 >> old_elm57 >> old_elm67 >> old_elm77;
0059     old_cham_id.push_back(old_chamber_id);
0060     old_strips.push_back(old_strip);
0061     old_elem33.push_back(old_elm33);
0062     old_elem34.push_back(old_elm34);
0063     old_elem44.push_back(old_elm44);
0064     old_elem35.push_back(old_elm35);
0065     old_elem45.push_back(old_elm45);
0066     old_elem55.push_back(old_elm55);
0067     old_elem46.push_back(old_elm46);
0068     old_elem56.push_back(old_elm56);
0069     old_elem66.push_back(old_elm66);
0070     old_elem57.push_back(old_elm57);
0071     old_elem67.push_back(old_elm67);
0072     old_elem77.push_back(old_elm77);
0073 
0074     old_nrlines++;
0075   }
0076   olddata.close();
0077 
0078   std::ifstream newdata;
0079   newdata.open("new_matrix.txt", std::ios::in);
0080   if (!newdata) {
0081     std::cerr << "Error: new_matrix.txt -> no such file!" << std::endl;
0082     exit(1);
0083   }
0084 
0085   while (!newdata.eof()) {
0086     newdata >> new_chamber_id >> new_strip >> new_elm33 >> new_elm34 >> new_elm44 >> new_elm35 >> new_elm45 >>
0087         new_elm55 >> new_elm46 >> new_elm56 >> new_elm66 >> new_elm57 >> new_elm67 >> new_elm77;
0088     new_cham_id.push_back(new_chamber_id);
0089     new_strips.push_back(new_strip);
0090     new_elem33.push_back(new_elm33);
0091     new_elem34.push_back(new_elm34);
0092     new_elem44.push_back(new_elm44);
0093     new_elem35.push_back(new_elm35);
0094     new_elem45.push_back(new_elm45);
0095     new_elem55.push_back(new_elm55);
0096     new_elem46.push_back(new_elm46);
0097     new_elem56.push_back(new_elm56);
0098     new_elem66.push_back(new_elm66);
0099     new_elem57.push_back(new_elm57);
0100     new_elem67.push_back(new_elm67);
0101     new_elem77.push_back(new_elm77);
0102     new_nrlines++;
0103   }
0104   newdata.close();
0105 
0106   // endcap=1 to 2,station=1 to 4, ring=1 to 4,chamber=1 to 36,layer=1 to 6
0107 
0108   for (int iendcap = detId.minEndcapId(); iendcap <= detId.maxEndcapId(); iendcap++) {
0109     for (int istation = detId.minStationId(); istation <= detId.maxStationId(); istation++) {
0110       max_ring = detId.maxRingId();
0111       // station 4 ring 4 not there(36 chambers*2 missing)
0112       // 3 rings max this way of counting (ME1a & b)
0113       if (istation == 1)
0114         max_ring = 3;
0115       if (istation == 2)
0116         max_ring = 2;
0117       if (istation == 3)
0118         max_ring = 2;
0119       if (istation == 4)
0120         max_ring = 1;
0121 
0122       for (int iring = detId.minRingId(); iring <= max_ring; iring++) {
0123         max_istrip = 80;
0124         max_cham = detId.maxChamberId();
0125         if (istation == 1 && iring == 1)
0126           max_cham = 36;
0127         if (istation == 1 && iring == 2)
0128           max_cham = 36;
0129         if (istation == 1 && iring == 3)
0130           max_cham = 36;
0131         if (istation == 2 && iring == 1)
0132           max_cham = 18;
0133         if (istation == 2 && iring == 2)
0134           max_cham = 36;
0135         if (istation == 3 && iring == 1)
0136           max_cham = 18;
0137         if (istation == 3 && iring == 2)
0138           max_cham = 36;
0139         if (istation == 4 && iring == 1)
0140           max_cham = 18;
0141 
0142         for (int ichamber = detId.minChamberId(); ichamber <= max_cham; ichamber++) {
0143           for (int ilayer = detId.minLayerId(); ilayer <= detId.maxLayerId(); ilayer++) {
0144             // station 1 ring 3 has 64 strips per layer instead of 80
0145             if (istation == 1 && iring == 3)
0146               max_istrip = 64;
0147 
0148             std::vector<CSCNoiseMatrix::Item> itemvector;
0149             itemvector.resize(max_istrip);
0150             id_layer = 100000 * iendcap + 10000 * istation + 1000 * iring + 10 * ichamber + ilayer;
0151 
0152             for (int istrip = 0; istrip < max_istrip; istrip++) {
0153               if (istation == 1 && iring == 1) {
0154                 itemvector[istrip].elem33 = 7.86675;
0155                 itemvector[istrip].elem34 = 2.07075;
0156                 itemvector[istrip].elem44 = 6.93875;
0157                 itemvector[istrip].elem35 = 1.42525;
0158                 itemvector[istrip].elem45 = 2.51025;
0159                 itemvector[istrip].elem55 = 7.93975;
0160                 itemvector[istrip].elem46 = 0.94725;
0161                 itemvector[istrip].elem56 = 2.39275;
0162                 itemvector[istrip].elem66 = 6.46475;
0163                 itemvector[istrip].elem57 = 1.86325;
0164                 itemvector[istrip].elem67 = 2.08025;
0165                 itemvector[istrip].elem77 = 6.67975;
0166                 cnmatrix->matrix[id_layer] = itemvector;
0167               }
0168 
0169               if (istation == 1 && iring == 2) {
0170                 itemvector[istrip].elem33 = 9.118;
0171                 itemvector[istrip].elem34 = 3.884;
0172                 itemvector[istrip].elem44 = 7.771;
0173                 itemvector[istrip].elem35 = 1.8225;
0174                 itemvector[istrip].elem45 = 3.7505;
0175                 itemvector[istrip].elem55 = 8.597;
0176                 itemvector[istrip].elem46 = 1.651;
0177                 itemvector[istrip].elem56 = 2.5225;
0178                 itemvector[istrip].elem66 = 6.583;
0179                 itemvector[istrip].elem57 = 1.5055;
0180                 itemvector[istrip].elem67 = 2.733;
0181                 itemvector[istrip].elem77 = 6.988;
0182                 cnmatrix->matrix[id_layer] = itemvector;
0183               }
0184 
0185               if (istation == 1 && iring == 3) {
0186                 itemvector[istrip].elem33 = 9.5245;
0187                 itemvector[istrip].elem34 = 3.2415;
0188                 itemvector[istrip].elem44 = 7.6265;
0189                 itemvector[istrip].elem35 = 1.7225;
0190                 itemvector[istrip].elem45 = 3.6075;
0191                 itemvector[istrip].elem55 = 8.7275;
0192                 itemvector[istrip].elem46 = 1.663;
0193                 itemvector[istrip].elem56 = 2.592;
0194                 itemvector[istrip].elem66 = 7.5685;
0195                 itemvector[istrip].elem57 = 1.7905;
0196                 itemvector[istrip].elem67 = 2.409;
0197                 itemvector[istrip].elem77 = 7.1495;
0198                 cnmatrix->matrix[id_layer] = itemvector;
0199               }
0200 
0201               if (istation == 2 && iring == 1) {
0202                 itemvector[istrip].elem33 = 9.06825;
0203                 itemvector[istrip].elem34 = 3.32025;
0204                 itemvector[istrip].elem44 = 7.52925;
0205                 itemvector[istrip].elem35 = 3.66125;
0206                 itemvector[istrip].elem45 = 3.39125;
0207                 itemvector[istrip].elem55 = 9.97625;
0208                 itemvector[istrip].elem46 = 1.32725;
0209                 itemvector[istrip].elem56 = 3.99025;
0210                 itemvector[istrip].elem66 = 8.10125;
0211                 itemvector[istrip].elem57 = 2.56456;
0212                 itemvector[istrip].elem67 = 2.96625;
0213                 itemvector[istrip].elem77 = 7.30925;
0214                 cnmatrix->matrix[id_layer] = itemvector;
0215               }
0216 
0217               if (istation == 2 && iring == 2) {
0218                 itemvector[istrip].elem33 = 16.7442;
0219                 itemvector[istrip].elem34 = 7.96925;
0220                 itemvector[istrip].elem44 = 14.1643;
0221                 itemvector[istrip].elem35 = 4.67975;
0222                 itemvector[istrip].elem45 = 8.44075;
0223                 itemvector[istrip].elem55 = 17.2243;
0224                 itemvector[istrip].elem46 = 3.68575;
0225                 itemvector[istrip].elem56 = 7.48825;
0226                 itemvector[istrip].elem66 = 14.4902;
0227                 itemvector[istrip].elem57 = 4.4482;
0228                 itemvector[istrip].elem67 = 6.47875;
0229                 itemvector[istrip].elem77 = 14.6733;
0230                 cnmatrix->matrix[id_layer] = itemvector;
0231               }
0232 
0233               if (istation == 3 && iring == 1) {
0234                 itemvector[istrip].elem33 = 9.3495;
0235                 itemvector[istrip].elem34 = 3.529;
0236                 itemvector[istrip].elem44 = 7.8715;
0237                 itemvector[istrip].elem35 = 3.8155;
0238                 itemvector[istrip].elem45 = 3.858;
0239                 itemvector[istrip].elem55 = 10.8205;
0240                 itemvector[istrip].elem46 = 1.8585;
0241                 itemvector[istrip].elem56 = 4.445;
0242                 itemvector[istrip].elem66 = 8.0175;
0243                 itemvector[istrip].elem57 = 3.29479;
0244                 itemvector[istrip].elem67 = 3.625;
0245                 itemvector[istrip].elem77 = 8.3895;
0246                 cnmatrix->matrix[id_layer] = itemvector;
0247               }
0248 
0249               if (istation == 3 && iring == 2) {
0250                 itemvector[istrip].elem33 = 13.6193;
0251                 itemvector[istrip].elem34 = 5.91025;
0252                 itemvector[istrip].elem44 = 11.3842;
0253                 itemvector[istrip].elem35 = 3.31775;
0254                 itemvector[istrip].elem45 = 5.69775;
0255                 itemvector[istrip].elem55 = 11.6652;
0256                 itemvector[istrip].elem46 = 2.46175;
0257                 itemvector[istrip].elem56 = 4.48325;
0258                 itemvector[istrip].elem66 = 9.95725;
0259                 itemvector[istrip].elem57 = 2.10561;
0260                 itemvector[istrip].elem67 = 4.04625;
0261                 itemvector[istrip].elem77 = 9.51625;
0262                 cnmatrix->matrix[id_layer] = itemvector;
0263               }
0264 
0265               if (istation == 4 && iring == 1) {
0266                 itemvector[istrip].elem33 = 10.0;
0267                 itemvector[istrip].elem34 = 4.0;
0268                 itemvector[istrip].elem44 = 10.0;
0269                 itemvector[istrip].elem35 = 3.0;
0270                 itemvector[istrip].elem45 = 8.0;
0271                 itemvector[istrip].elem55 = 10.0;
0272                 itemvector[istrip].elem46 = 2.0;
0273                 itemvector[istrip].elem56 = 5.0;
0274                 itemvector[istrip].elem66 = 10.0;
0275                 itemvector[istrip].elem57 = 3.0;
0276                 itemvector[istrip].elem67 = 4.0;
0277                 itemvector[istrip].elem77 = 10.0;
0278                 cnmatrix->matrix[id_layer] = itemvector;
0279               }
0280             }
0281           }
0282         }
0283       }
0284     }
0285   }
0286 
0287   // overwrite fakes with old values from DB
0288   int istrip = 0;
0289   std::vector<CSCNoiseMatrix::Item> itemvector;
0290   itemvector.resize(80);
0291 
0292   for (unsigned int mystrip = 0; mystrip < old_nrlines - 1; mystrip++) {
0293     if (old_strips[mystrip] == 0)
0294       istrip = 0;
0295     itemvector[istrip].elem33 = old_elem33[mystrip];
0296     itemvector[istrip].elem34 = old_elem34[mystrip];
0297     itemvector[istrip].elem44 = old_elem44[mystrip];
0298     itemvector[istrip].elem35 = old_elem35[mystrip];
0299     itemvector[istrip].elem45 = old_elem45[mystrip];
0300     itemvector[istrip].elem55 = old_elem55[mystrip];
0301     itemvector[istrip].elem46 = old_elem46[mystrip];
0302     itemvector[istrip].elem56 = old_elem56[mystrip];
0303     itemvector[istrip].elem66 = old_elem66[mystrip];
0304     itemvector[istrip].elem57 = old_elem57[mystrip];
0305     itemvector[istrip].elem67 = old_elem67[mystrip];
0306     itemvector[istrip].elem77 = old_elem77[mystrip];
0307     cnmatrix->matrix[old_cham_id[mystrip]] = itemvector;
0308     istrip++;
0309   }
0310 
0311   itemvector.resize(64);
0312   for (unsigned int mystrip = 0; mystrip < old_nrlines - 1; mystrip++) {
0313     if (old_strips[mystrip] == 0)
0314       istrip = 0;
0315     if (old_cham_id[mystrip] >= 113000 && old_cham_id[mystrip] <= 113999) {
0316       itemvector[istrip].elem33 = old_elem33[mystrip];
0317       itemvector[istrip].elem34 = old_elem34[mystrip];
0318       itemvector[istrip].elem44 = old_elem44[mystrip];
0319       itemvector[istrip].elem35 = old_elem35[mystrip];
0320       itemvector[istrip].elem45 = old_elem45[mystrip];
0321       itemvector[istrip].elem55 = old_elem55[mystrip];
0322       itemvector[istrip].elem46 = old_elem46[mystrip];
0323       itemvector[istrip].elem56 = old_elem56[mystrip];
0324       itemvector[istrip].elem66 = old_elem66[mystrip];
0325       itemvector[istrip].elem57 = old_elem57[mystrip];
0326       itemvector[istrip].elem67 = old_elem67[mystrip];
0327       itemvector[istrip].elem77 = old_elem77[mystrip];
0328       cnmatrix->matrix[old_cham_id[mystrip]] = itemvector;
0329       istrip++;
0330     }
0331   }
0332 
0333   itemvector.resize(64);
0334   for (unsigned int mystrip = 0; mystrip < old_nrlines - 1; mystrip++) {
0335     if (old_strips[mystrip] == 0)
0336       istrip = 0;
0337     if (old_cham_id[mystrip] >= 213000 && old_cham_id[mystrip] <= 213999) {
0338       itemvector[istrip].elem33 = old_elem33[mystrip];
0339       itemvector[istrip].elem34 = old_elem34[mystrip];
0340       itemvector[istrip].elem44 = old_elem44[mystrip];
0341       itemvector[istrip].elem35 = old_elem35[mystrip];
0342       itemvector[istrip].elem45 = old_elem45[mystrip];
0343       itemvector[istrip].elem55 = old_elem55[mystrip];
0344       itemvector[istrip].elem46 = old_elem46[mystrip];
0345       itemvector[istrip].elem56 = old_elem56[mystrip];
0346       itemvector[istrip].elem66 = old_elem66[mystrip];
0347       itemvector[istrip].elem57 = old_elem57[mystrip];
0348       itemvector[istrip].elem67 = old_elem67[mystrip];
0349       itemvector[istrip].elem77 = old_elem77[mystrip];
0350       cnmatrix->matrix[old_cham_id[mystrip]] = itemvector;
0351       istrip++;
0352     }
0353   }
0354 
0355   // overwrite old values with ones from new runs
0356   itemvector.resize(80);
0357   for (unsigned int mystrip = 0; mystrip < new_nrlines - 1; mystrip++) {
0358     if (new_strips[mystrip] == 0)
0359       istrip = 0;
0360     itemvector[istrip].elem33 = new_elem33[mystrip];
0361     itemvector[istrip].elem34 = new_elem34[mystrip];
0362     itemvector[istrip].elem44 = new_elem44[mystrip];
0363     itemvector[istrip].elem35 = new_elem35[mystrip];
0364     itemvector[istrip].elem45 = new_elem45[mystrip];
0365     itemvector[istrip].elem55 = new_elem55[mystrip];
0366     itemvector[istrip].elem46 = new_elem46[mystrip];
0367     itemvector[istrip].elem56 = new_elem56[mystrip];
0368     itemvector[istrip].elem66 = new_elem66[mystrip];
0369     itemvector[istrip].elem57 = new_elem57[mystrip];
0370     itemvector[istrip].elem67 = new_elem67[mystrip];
0371     itemvector[istrip].elem77 = new_elem77[mystrip];
0372     cnmatrix->matrix[new_cham_id[mystrip]] = itemvector;
0373     istrip++;
0374   }
0375 
0376   itemvector.resize(64);
0377   for (unsigned int mystrip = 0; mystrip < new_nrlines - 1; mystrip++) {
0378     if (new_strips[mystrip] == 0)
0379       istrip = 0;
0380     if (new_cham_id[mystrip] >= 113000 && new_cham_id[mystrip] <= 113999) {
0381       itemvector[istrip].elem33 = new_elem33[mystrip];
0382       itemvector[istrip].elem34 = new_elem34[mystrip];
0383       itemvector[istrip].elem44 = new_elem44[mystrip];
0384       itemvector[istrip].elem35 = new_elem35[mystrip];
0385       itemvector[istrip].elem45 = new_elem45[mystrip];
0386       itemvector[istrip].elem55 = new_elem55[mystrip];
0387       itemvector[istrip].elem46 = new_elem46[mystrip];
0388       itemvector[istrip].elem56 = new_elem56[mystrip];
0389       itemvector[istrip].elem66 = new_elem66[mystrip];
0390       itemvector[istrip].elem57 = new_elem57[mystrip];
0391       itemvector[istrip].elem67 = new_elem67[mystrip];
0392       itemvector[istrip].elem77 = new_elem77[mystrip];
0393       cnmatrix->matrix[new_cham_id[mystrip]] = itemvector;
0394       istrip++;
0395     }
0396   }
0397 
0398   itemvector.resize(64);
0399   for (unsigned int mystrip = 0; mystrip < new_nrlines - 1; mystrip++) {
0400     if (new_strips[mystrip] == 0)
0401       istrip = 0;
0402     if (new_cham_id[mystrip] >= 213000 && new_cham_id[mystrip] <= 213999) {
0403       itemvector[istrip].elem33 = new_elem33[mystrip];
0404       itemvector[istrip].elem34 = new_elem34[mystrip];
0405       itemvector[istrip].elem44 = new_elem44[mystrip];
0406       itemvector[istrip].elem35 = new_elem35[mystrip];
0407       itemvector[istrip].elem45 = new_elem45[mystrip];
0408       itemvector[istrip].elem55 = new_elem55[mystrip];
0409       itemvector[istrip].elem46 = new_elem46[mystrip];
0410       itemvector[istrip].elem56 = new_elem56[mystrip];
0411       itemvector[istrip].elem66 = new_elem66[mystrip];
0412       itemvector[istrip].elem57 = new_elem57[mystrip];
0413       itemvector[istrip].elem67 = new_elem67[mystrip];
0414       itemvector[istrip].elem77 = new_elem77[mystrip];
0415       cnmatrix->matrix[new_cham_id[mystrip]] = itemvector;
0416       istrip++;
0417     }
0418   }
0419   return cnmatrix;
0420 }
0421 
0422 CSCNoiseMatrixConditions::CSCNoiseMatrixConditions(const edm::ParameterSet &iConfig) {
0423   // the following line is needed to tell the framework what
0424   // data is being produced
0425   // added by Zhen (changed since 1_2_0)
0426   setWhatProduced(this, &CSCNoiseMatrixConditions::produceNoiseMatrix);
0427   findingRecord<CSCNoiseMatrixRcd>();
0428   // now do what ever other initialization is needed
0429 }
0430 
0431 CSCNoiseMatrixConditions::~CSCNoiseMatrixConditions() {
0432   // do anything here that needs to be done at desctruction time
0433   // (e.g. close files, deallocate resources etc.)
0434 }
0435 
0436 //
0437 // member functions
0438 //
0439 
0440 // ------------ method called to produce the data  ------------
0441 CSCNoiseMatrixConditions::ReturnType CSCNoiseMatrixConditions::produceNoiseMatrix(const CSCNoiseMatrixRcd &iRecord) {
0442   // Added by Zhen, need a new object so to not be deleted at exit
0443   return CSCNoiseMatrixConditions::ReturnType(prefillNoiseMatrix());
0444 }
0445 
0446 void CSCNoiseMatrixConditions::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0447                                               const edm::IOVSyncValue &,
0448                                               edm::ValidityInterval &oValidity) {
0449   oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
0450 }