Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:01

0001 #include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 using namespace std;
0005 using namespace trklet;
0006 
0007 void SLHCEvent::addL1SimTrack(
0008     int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz) {
0009   L1SimTrack simtrack(eventid, trackid, type, pt, eta, phi, vx, vy, vz);
0010   simtracks_.push_back(simtrack);
0011 }
0012 
0013 bool SLHCEvent::addStub(string DTClink,
0014                         int region,
0015                         int layerdisk,
0016                         string stubword,
0017                         int isPSmodule,
0018                         int isFlipped,
0019                         bool tiltedBarrel,
0020                         unsigned int tiltedRingId,
0021                         unsigned int endcapRingId,
0022                         unsigned int detId,
0023                         double x,
0024                         double y,
0025                         double z,
0026                         double bend,
0027                         double strip,
0028                         vector<int> tps,
0029                         int stubindex) {
0030   L1TStub stub(DTClink,
0031                region,
0032                layerdisk,
0033                stubword,
0034                isPSmodule,
0035                isFlipped,
0036                tiltedBarrel,
0037                tiltedRingId,
0038                endcapRingId,
0039                detId,
0040                x,
0041                y,
0042                z,
0043                bend,
0044                strip,
0045                tps);
0046 
0047   stub.setUniqueIndex(stubindex);
0048   stubs_.push_back(stub);
0049   return true;
0050 }
0051 
0052 SLHCEvent::SLHCEvent(istream& in) {
0053   string tmp;
0054   in >> tmp;
0055   if (tmp != "Event:") {
0056     edm::LogVerbatim("Tracklet") << "Expected to read 'Event:' but found:" << tmp;
0057     if (tmp.empty()) {
0058       edm::LogVerbatim("Tracklet") << "WARNING: fewer events to process than specified!";
0059       return;
0060     } else {
0061       edm::LogVerbatim("Tracklet") << "ERROR, aborting reading file";
0062       abort();
0063     }
0064   }
0065   in >> eventnum_;
0066 
0067   // read the SimTracks
0068   in >> tmp;
0069   while (tmp != "SimTrackEnd") {
0070     if (!(tmp == "SimTrack:" || tmp == "SimTrackEnd")) {
0071       edm::LogVerbatim("Tracklet") << "Expected to read 'SimTrack:' or 'SimTrackEnd' but found:" << tmp;
0072       abort();
0073     }
0074     int eventid;
0075     int trackid;
0076     int type;
0077     double pt;
0078     double eta;
0079     double phi;
0080     double vx;
0081     double vy;
0082     double vz;
0083     in >> eventid >> trackid >> type >> pt >> eta >> phi >> vx >> vy >> vz;
0084     L1SimTrack simtrack(eventid, trackid, type, pt, eta, phi, vx, vy, vz);
0085     simtracks_.push_back(simtrack);
0086     in >> tmp;
0087   }
0088 
0089   //read stubs
0090   in >> tmp;
0091   while (tmp != "Stubend") {
0092     if (!in.good()) {
0093       edm::LogVerbatim("Tracklet") << "File not good (SLHCEvent)";
0094       abort();
0095     };
0096     if (!(tmp == "Stub:" || tmp == "Stubend")) {
0097       edm::LogVerbatim("Tracklet") << "Expected to read 'Stub:' or 'StubEnd' but found:" << tmp;
0098       abort();
0099     }
0100     string DTClink;
0101     int region;
0102     int layerdisk;
0103     string stubword;
0104     int isPSmodule;
0105     int isFlipped;
0106     double x;
0107     double y;
0108     double z;
0109     double bend;
0110     double strip;
0111     unsigned int ntps;
0112     vector<int> tps;
0113 
0114     in >> DTClink >> region >> layerdisk >> stubword >> isPSmodule >> isFlipped >> x >> y >> z >> bend >> strip >> ntps;
0115 
0116     // TO FIX: READ THESE FROM INPUT FILE
0117     bool tiltedBarrel = false;
0118     unsigned int tiltedRingId = 999999;
0119     unsigned int endcapRingId = 999999;
0120     unsigned int detId = 999999;  // Lower sensor in module
0121 
0122     for (unsigned int itps = 0; itps < ntps; itps++) {
0123       int tp;
0124       in >> tp;
0125       tps.push_back(tp);
0126     }
0127 
0128     L1TStub stub(DTClink,
0129                  region,
0130                  layerdisk,
0131                  stubword,
0132                  isPSmodule,
0133                  isFlipped,
0134                  tiltedBarrel,
0135                  tiltedRingId,
0136                  endcapRingId,
0137                  detId,
0138                  x,
0139                  y,
0140                  z,
0141                  bend,
0142                  strip,
0143                  tps);
0144 
0145     in >> tmp;
0146 
0147     double t = std::abs(stub.z()) / stub.r();
0148     double eta = asinh(t);
0149 
0150     if (std::abs(eta) < 2.6) {
0151       stubs_.push_back(stub);
0152     }
0153   }
0154 }
0155 
0156 void SLHCEvent::write(ofstream& out) {
0157   out << "Event: " << eventnum_ << endl;
0158 
0159   for (auto& simtrack : simtracks_) {
0160     simtrack.write(out);
0161   }
0162   out << "SimTrackEnd" << endl;
0163 
0164   for (auto& stub : stubs_) {
0165     stub.write(out);
0166   }
0167   out << "Stubend" << endl;
0168 }
0169 
0170 unsigned int SLHCEvent::layersHit(int tpid, int& nlayers, int& ndisks) {
0171   int l1 = 0;
0172   int l2 = 0;
0173   int l3 = 0;
0174   int l4 = 0;
0175   int l5 = 0;
0176   int l6 = 0;
0177 
0178   int d1 = 0;
0179   int d2 = 0;
0180   int d3 = 0;
0181   int d4 = 0;
0182   int d5 = 0;
0183 
0184   for (auto& stub : stubs_) {
0185     if (stub.tpmatch(tpid)) {
0186       if (stub.layer() == 0)
0187         l1 = 1;
0188       if (stub.layer() == 1)
0189         l2 = 1;
0190       if (stub.layer() == 2)
0191         l3 = 1;
0192       if (stub.layer() == 3)
0193         l4 = 1;
0194       if (stub.layer() == 4)
0195         l5 = 1;
0196       if (stub.layer() == 5)
0197         l6 = 1;
0198 
0199       if (abs(stub.disk()) == 1)
0200         d1 = 1;
0201       if (abs(stub.disk()) == 2)
0202         d2 = 1;
0203       if (abs(stub.disk()) == 3)
0204         d3 = 1;
0205       if (abs(stub.disk()) == 4)
0206         d4 = 1;
0207       if (abs(stub.disk()) == 5)
0208         d5 = 1;
0209     }
0210   }
0211 
0212   nlayers = l1 + l2 + l3 + l4 + l5 + l6;
0213   ndisks = d1 + d2 + d3 + d4 + d5;
0214 
0215   return l1 + 2 * l2 + 4 * l3 + 8 * l4 + 16 * l5 + 32 * l6 + 64 * d1 + 128 * d2 + 256 * d3 + 512 * d4 + 1024 * d5;
0216 }