Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-08 22:40:15

0001 #include "L1Trigger/VertexFinder/interface/TP.h"
0002 
0003 namespace l1tVertexFinder {
0004 
0005   TP::TP()
0006       : settings_(nullptr),
0007         inTimeBx_(false),
0008         physicsCollision_(false),
0009         use_(false),
0010         useForEff_(false),
0011         useForAlgEff_(false),
0012         useForVertexReco_(false),
0013         nLayersWithStubs_(0) {}
0014 
0015   TP::TP(const TrackingParticlePtr& tpPtr, const AnalysisSettings& settings)
0016       : trackingParticle_(tpPtr), settings_(&settings) {
0017     const std::vector<SimTrack>& vst = trackingParticle_->g4Tracks();
0018     EncodedEventId eid = vst.at(0).eventId();
0019     inTimeBx_ = (eid.bunchCrossing() == 0);  // TP from in-time or out-of-time Bx.
0020     physicsCollision_ = (eid.event() == 0);  // TP from physics collision or from pileup.
0021 
0022     this->fillUse();        // Fill use_ flag, indicating if TP is worth keeping.
0023     this->fillUseForEff();  // Fill useForEff_ flag, indicating if TP is good for tracking efficiency measurement.
0024   }
0025 
0026   //=== Fill truth info with association from tracking particle to stubs.
0027   void TP::setMatchingStubs(const std::vector<Stub>& vMatchingStubs) {
0028     assocStubs_ = vMatchingStubs;
0029 
0030     this->fillUseForAlgEff();  // Fill useForAlgEff_ flag.
0031     this->fillUseForVertexReco();
0032     // Calculate number of tracker layers this TP has stubs in.
0033     nLayersWithStubs_ = countLayers();
0034   }
0035 
0036   //=== Count number of tracker layers a given list of stubs are in.
0037   //=== By default, consider both PS+2S modules, but optionally consider only the PS ones.
0038 
0039   unsigned int TP::countLayers(bool onlyPS) {
0040     //=== Unpack configuration parameters
0041 
0042     // Define layers using layer ID (true) or by bins in radius of 5 cm width (false).
0043     bool useLayerID = settings_->useLayerID();
0044     // When counting stubs in layers, actually histogram stubs in distance from beam-line with this bin size.
0045     float layerIDfromRadiusBin = settings_->layerIDfromRadiusBin();
0046     // Inner radius of tracker.
0047     float trackerInnerRadius = settings_->trackerInnerRadius();
0048 
0049     const int maxLayerID(30);
0050     std::vector<bool> foundLayers(maxLayerID, false);
0051 
0052     if (useLayerID) {
0053       // Count layers using CMSSW layer ID.
0054       for (const Stub& stub : assocStubs_) {
0055         if ((!onlyPS) || stub.psModule()) {  // Consider only stubs in PS modules if that option specified.
0056           int layerID = stub.layerId();
0057           if (layerID >= 0 && layerID < maxLayerID) {
0058             foundLayers[layerID] = true;
0059           } else {
0060             throw cms::Exception("Utility::invalid layer ID");
0061           }
0062         }
0063       }
0064     } else {
0065       // Count layers by binning stub distance from beam line.
0066       for (const Stub& stub : assocStubs_) {
0067         if ((!onlyPS) || stub.psModule()) {  // Consider only stubs in PS modules if that option specified.
0068           int layerID = (int)((stub.r() - trackerInnerRadius) / layerIDfromRadiusBin);
0069           if (layerID >= 0 && layerID < maxLayerID) {
0070             foundLayers[layerID] = true;
0071           } else {
0072             throw cms::Exception("Utility::invalid layer ID");
0073           }
0074         }
0075       }
0076     }
0077 
0078     unsigned int ncount = 0;
0079     for (const bool& found : foundLayers) {
0080       if (found)
0081         ncount++;
0082     }
0083 
0084     return ncount;
0085   }
0086 
0087   void TP::fillUseForVertexReco() {
0088     useForVertexReco_ = false;
0089     if (use_) {
0090       useForVertexReco_ = settings_->tpsUseForVtxReco()(trackingParticle_.get());
0091     }
0092 
0093     if (useForVertexReco_) {
0094       useForVertexReco_ = (countLayers() >= settings_->genMinStubLayers() and countLayers(true) >= 2);
0095     }
0096   }
0097 
0098   //=== Check if this tracking particle is worth keeping.
0099   void TP::fillUse() {
0100     // Use looser cuts here those those used for tracking efficiency measurement.
0101     // Keep only those TP that have a chance (allowing for finite track resolution) of being reconstructed as L1 tracks. L1 tracks not matching these TP will be defined as fake.
0102     use_ = settings_->tpsUse()(trackingParticle_.get());
0103   }
0104 
0105   //=== Check if this tracking particle can be used to measure the L1 tracking efficiency.
0106   void TP::fillUseForEff() {
0107     useForEff_ = false;
0108     if (use_) {
0109       useForEff_ = settings_->tpsUseForEff()(trackingParticle_.get());
0110     }
0111   }
0112 
0113   //=== Check if this tracking particle can be used to measure the L1 tracking algorithmic efficiency (makes stubs in enough layers).
0114   void TP::fillUseForAlgEff() {
0115     useForAlgEff_ = false;
0116     if (useForEff_) {
0117       useForAlgEff_ = (countLayers() >= settings_->genMinStubLayers());
0118     }
0119   }
0120 
0121 }  // namespace l1tVertexFinder