Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:07

0001 // -*- C++ -*-
0002 //
0003 // Package:    HGCalCellUVTester
0004 // Class:      HGCalCellUVTester
0005 //
0006 /**\class HGCalCellUVTester HGCalCellUVTester.cc
0007  test/HGCalCellUVTester.cc
0008 
0009  Description: <one line class summary>
0010 
0011  Implementation:
0012      <Notes on implementation>
0013 */
0014 //
0015 // Original Author:  Sunanda Banerjee, Pruthvi Suryadevara
0016 //         Created:  Mon 2022/01/15
0017 //
0018 //
0019 
0020 // system include files
0021 #include <fstream>
0022 #include <iostream>
0023 #include <memory>
0024 #include <string>
0025 #include <vector>
0026 #include <stdlib.h>
0027 #include <cmath>
0028 
0029 // user include files
0030 #include "FWCore/Framework/interface/Frameworkfwd.h"
0031 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0032 
0033 #include "FWCore/Framework/interface/Event.h"
0034 #include "FWCore/Framework/interface/EventSetup.h"
0035 #include "FWCore/Framework/interface/MakerMacros.h"
0036 
0037 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0039 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0040 #include "Geometry/HGCalCommonData/interface/HGCalCellUV.h"
0041 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0042 
0043 class HGCalCellUVTester : public edm::one::EDAnalyzer<> {
0044 public:
0045   explicit HGCalCellUVTester(const edm::ParameterSet&);
0046   ~HGCalCellUVTester() override = default;
0047   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0048 
0049   void beginJob() override {}
0050   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0051   void endJob() override {}
0052 
0053 private:
0054   const double waferSize_;
0055   const int waferType_;
0056   const int placeIndex_;
0057 };
0058 
0059 HGCalCellUVTester::HGCalCellUVTester(const edm::ParameterSet& iC)
0060     : waferSize_(iC.getParameter<double>("waferSize")),
0061       waferType_(iC.getParameter<int>("waferType")),
0062       placeIndex_(iC.getParameter<int>("cellPlacementIndex")) {
0063   edm::LogVerbatim("HGCalGeom") << "Test positions for wafer of size " << waferSize_ << " Type " << waferType_
0064                                 << " Placement Index " << placeIndex_;
0065 }
0066 
0067 void HGCalCellUVTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0068   edm::ParameterSetDescription desc;
0069   desc.add<double>("waferSize", 166.4408);
0070   desc.add<int>("waferType", 1);
0071   desc.add<int>("cellPlacementIndex", 6);
0072   descriptions.add("hgcalCellUVTester", desc);
0073 }
0074 
0075 // ------------ method called to produce the data  ------------
0076 void HGCalCellUVTester::analyze(const edm::Event&, const edm::EventSetup&) {
0077   const int nFine(12), nCoarse(8);
0078   HGCalCellUV wafer(waferSize_, 0.0, nFine, nCoarse);
0079   HGCalCell wafer2(waferSize_, nFine, nCoarse);
0080   double r2 = 0.5 * waferSize_;
0081   double R2 = 2 * r2 / sqrt(3);
0082   int nCells = (waferType_ == 0) ? nFine : nCoarse;
0083   int indexMin = (placeIndex_ >= 0) ? placeIndex_ : 0;
0084   int indexMax = (placeIndex_ >= 0) ? placeIndex_ : 11;
0085   edm::LogVerbatim("HGCalGeom") << "\nHGCalCellUVTester:: nCells " << nCells << " and placement index between "
0086                                 << indexMin << " and " << indexMax << "\n\n";
0087   auto start_t = std::chrono::high_resolution_clock::now();
0088 
0089   for (int i = 0; i < 100000; i++) {
0090     double xi = (2 * r2 * (float)rand() / RAND_MAX) - r2;
0091     double yi = (2 * R2 * (float)rand() / RAND_MAX) - R2;
0092     double c1 = yi + xi / sqrt(3);
0093     double c2 = yi - (xi / sqrt(3));
0094     if ((xi < r2) && (xi > -1 * r2) && (c1 < R2) && (c1 > -1 * R2) && (c2 < R2) &&
0095         (c2 > -1 * R2)) {  //Only allowing (x, y) inside a wafer
0096       std::pair<int32_t, int32_t> uv1 = wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, true, false);
0097       std::pair<int32_t, int32_t> uv2 = wafer.cellUVFromXY2(xi, yi, placeIndex_, waferType_, true, false);
0098       std::pair<int32_t, int32_t> uv3 = wafer.cellUVFromXY3(xi, yi, placeIndex_, waferType_, true, false);
0099       //std::pair<int32_t, int32_t> uv2 = wafer.HGCalCellUVFromXY2(xi, yi, placeIndex_, waferType_, true, false);
0100       std::string comment = ((uv1.first != uv3.first) || (uv2.first != uv3.first) || (uv1.second != uv3.second) ||
0101                              (uv2.second != uv3.second))
0102                                 ? " ***** ERROR *****"
0103                                 : "";
0104       edm::LogVerbatim("HGCalGeom") << "x = " << xi << " y = " << yi << " type = " << waferType_ << " placement index "
0105                                     << placeIndex_ << " u " << uv1.first << ":" << uv2.first << ":" << uv3.first
0106                                     << " v " << uv1.second << ":" << uv2.second << ":" << uv3.second << ":" << comment;
0107     }
0108   }
0109   auto end_t = std::chrono::high_resolution_clock::now();
0110   auto diff_t = end_t - start_t;
0111   edm::LogVerbatim("HGCalGeom") << "Execution time for 100000 events = "
0112                                 << std::chrono::duration<double, std::milli>(diff_t).count() << " ms";
0113 }
0114 
0115 // define this as a plug-in
0116 DEFINE_FWK_MODULE(HGCalCellUVTester);