Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-04 06:14:11

0001 /* \file testCSCTriggerMapping.cc
0002  *
0003  * \author Lindsey Gray
0004  * Based on template from S. Argiro & N. Amapane
0005  */
0006 
0007 #include <cppunit/extensions/HelperMacros.h>
0008 #include <FWCore/Utilities/interface/Exception.h>
0009 #include "FWCore/PluginManager/interface/ProblemTracker.h"
0010 #include <CondFormats/CSCObjects/interface/CSCTriggerMappingFromFile.h>
0011 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0012 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0013 #include <iostream>
0014 #include <cstdlib>
0015 
0016 std::string treleasetop(getenv("CMSSW_BASE"));
0017 std::string tmappingFilePath = treleasetop + "/src/CondFormats/CSCObjects/test/";
0018 
0019 class testCSCTriggerMapping : public CppUnit::TestFixture {
0020   CPPUNIT_TEST_SUITE(testCSCTriggerMapping);
0021 
0022   CPPUNIT_TEST(testRead);
0023 
0024   CPPUNIT_TEST_SUITE_END();
0025 
0026 public:
0027   testCSCTriggerMapping()
0028       : myName_("testCSCTriggerMapping"), dashedLineWidth(104), dashedLine(std::string(dashedLineWidth, '-')) {}
0029 
0030   void setUp() {
0031     char* ret = getenv("CMSSW_BASE");
0032     if (!ret) {
0033       std::cerr << "env variable SCRAMRT_LOCALRT not set, try eval `scramv1 runt -sh`" << std::endl;
0034       exit(1);
0035     }
0036   }
0037 
0038   void tearDown() {}
0039 
0040   void testRead();
0041 
0042 private:
0043   const std::string myName_;
0044   const int dashedLineWidth;
0045   std::string dashedLine;
0046 };
0047 
0048 void testCSCTriggerMapping::testRead() {
0049   std::cout << myName_ << ": --- t e s t C S C T r i g g e r M a p p i n g  ---" << std::endl;
0050   std::cout << "start " << dashedLine << std::endl;
0051 
0052   std::string mappingFileName = tmappingFilePath + "csc_trigger_test_map.txt";
0053 
0054   CSCTriggerMappingFromFile theMapping(mappingFileName);
0055 
0056   //theMapping.setDebugV( true );
0057 
0058   // Loop over all possible endcaps, stations, sectors, subsectors and cscids
0059   // TEST CSCTriggerMapping::chamber(...)
0060 
0061   for (int endcap = 1; endcap <= 1; ++endcap)
0062     for (int station = 2; station <= 3; ++station)
0063       for (int sector = 5; sector <= 5; ++sector)
0064         for (int cscid = 1; cscid <= 9; ++cscid) {
0065           if (station == 1)
0066             for (int subs = 1; subs <= 2; ++subs) {
0067               std::cout << "\n"
0068                         << myName_ << ": search for sw id for hw labels, endcap= " << endcap << ", station=" << station
0069                         << ", sector=" << sector << ", subsector=" << subs << ", cscid= " << cscid << std::endl;
0070               int id = theMapping.chamber(endcap, station, sector, subs, cscid);
0071 
0072               std::cout << myName_ << ": found chamber rawId = " << id << std::endl;
0073 
0074               CSCDetId cid(id);
0075 
0076               std::cout << myName_ << ": from CSCDetId for this chamber, endcap= " << cid.endcap()
0077                         << ", station=" << cid.station() << ", ring=" << cid.ring() << ", chamber=" << cid.chamber()
0078                         << std::endl;
0079 
0080               // Now try direct mapping for specific layers
0081               // TEST CSCTriggerMapping::detId(...)
0082 
0083               for (int layer = 1; layer <= 6; ++layer) {
0084                 std::cout << myName_ << ": map layer with hw labels, endcap= " << endcap << ", station=" << station
0085                           << ", sector=" << sector << ", subsector=" << subs << ", cscid= " << cscid
0086                           << ", layer=" << layer << std::endl;
0087 
0088                 CSCDetId lid = theMapping.detId(endcap, station, sector, subs, cscid, layer);
0089 
0090                 // And check what we've actually selected...
0091                 std::cout << myName_ << ": from CSCDetId for this layer, endcap= " << lid.endcap()
0092                           << ", station=" << lid.station() << ", ring=" << lid.ring() << ", chamber=" << lid.chamber()
0093                           << ", layer=" << lid.layer() << std::endl;
0094               }
0095             }
0096           else {
0097             std::cout << "\n"
0098                       << myName_ << ": search for sw id for hw labels, endcap= " << endcap << ", station=" << station
0099                       << ", sector=" << sector << ", subsector=" << 0 << ", cscid= " << cscid << std::endl;
0100             int id = theMapping.chamber(endcap, station, sector, 0, cscid);
0101 
0102             std::cout << myName_ << ": found chamber rawId = " << id << std::endl;
0103 
0104             CSCDetId cid(id);
0105 
0106             std::cout << myName_ << ": from CSCDetId for this chamber, endcap= " << cid.endcap()
0107                       << ", station=" << cid.station() << ", ring=" << cid.ring() << ", chamber=" << cid.chamber()
0108                       << std::endl;
0109 
0110             // Now try direct mapping for specific layers
0111             // TEST CSCTriggerMapping::detId(...)
0112 
0113             for (int layer = 1; layer <= 6; ++layer) {
0114               std::cout << myName_ << ": map layer with hw labels, endcap= " << endcap << ", station=" << station
0115                         << ", sector=" << sector << ", subsector=" << 0 << ", cscid= " << cscid << ", layer=" << layer
0116                         << std::endl;
0117 
0118               CSCDetId lid = theMapping.detId(endcap, station, sector, 0, cscid, layer);
0119 
0120               // And check what we've actually selected...
0121               std::cout << myName_ << ": from CSCDetId for this layer, endcap= " << lid.endcap()
0122                         << ", station=" << lid.station() << ", ring=" << lid.ring() << ", chamber=" << lid.chamber()
0123                         << ", layer=" << lid.layer() << std::endl;
0124             }
0125           }
0126           std::cout << std::endl;
0127         }
0128 
0129   std::cout << dashedLine << " end" << std::endl;
0130 }
0131 
0132 ///registration of the test so that the runner can find it
0133 CPPUNIT_TEST_SUITE_REGISTRATION(testCSCTriggerMapping);