Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-19 00:05:08

0001 /*! \brief   Implementation of methods of TTClusterBuilder.h
0002  *  \details Here, in the source file, the methods which do depend
0003  *           on the specific type <T> that can fit the template.
0004  *
0005  *  \author Nicola
0006  *  \date   2013, Jul 12
0007  *
0008  */
0009 
0010 #include "L1Trigger/TrackTrigger/plugins/TTClusterBuilder.h"
0011 
0012 /// Implement the producer
0013 template <>
0014 void TTClusterBuilder<Ref_Phase2TrackerDigi_>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0015   /// Prepare output
0016   auto ttClusterDSVForOutput = std::make_unique<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>>();
0017   std::map<DetId, std::vector<Ref_Phase2TrackerDigi_>> rawHits;
0018   this->RetrieveRawHits(rawHits, iEvent);
0019 
0020   // Retrieve tracker topology from geometry
0021   const TrackerTopology* const tTopo = &iSetup.getData(tTopoToken);
0022   const TrackerGeometry* const theTrackerGeom = &iSetup.getData(tGeomToken);
0023   auto const& theClusterFindingAlgo = iSetup.getData(theClusterFindingAlgoToken);
0024 
0025   // Loop on the OT stacks
0026   for (auto gd = theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++) {
0027     DetId detid = (*gd)->geographicalId();
0028     if (detid.subdetId() == 1 || detid.subdetId() == 2)
0029       continue;  // only run on OT
0030     if (!tTopo->isLower(detid))
0031       continue;  // loop on the stacks: choose the lower arbitrarily
0032     DetId lowerDetid = detid;
0033     DetId upperDetid = tTopo->partnerDetId(detid);
0034 
0035     /// Temp vectors containing the vectors of the
0036     /// hits used to build each cluster
0037     std::vector<std::vector<Ref_Phase2TrackerDigi_>> lowerHits, upperHits;
0038 
0039     /// Find the hits in each stack member
0040     typename std::map<DetId, std::vector<Ref_Phase2TrackerDigi_>>::const_iterator lowerHitFind =
0041         rawHits.find(lowerDetid);
0042     typename std::map<DetId, std::vector<Ref_Phase2TrackerDigi_>>::const_iterator upperHitFind =
0043         rawHits.find(upperDetid);
0044 
0045     /// If there are hits, cluster them
0046     /// It is the TTClusterAlgorithm::Cluster method which
0047     /// calls the constructor to the Cluster class!
0048     bool isPSP = (theTrackerGeom->getDetectorType(lowerDetid) == TrackerGeometry::ModuleType::Ph2PSP);
0049     if (lowerHitFind != rawHits.end())
0050       theClusterFindingAlgo.Cluster(lowerHits, lowerHitFind->second, isPSP);
0051     if (upperHitFind != rawHits.end())
0052       theClusterFindingAlgo.Cluster(upperHits, upperHitFind->second, false);
0053 
0054     /// Create TTCluster objects and store them
0055     /// Use the FastFiller with edmNew::DetSetVector
0056     {
0057       edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>::FastFiller lowerOutputFiller(*ttClusterDSVForOutput,
0058                                                                                             lowerDetid);
0059       for (unsigned int i = 0; i < lowerHits.size(); i++) {
0060         TTCluster<Ref_Phase2TrackerDigi_> temp(lowerHits.at(i), lowerDetid, 0, storeLocalCoord);
0061         lowerOutputFiller.push_back(temp);
0062       }
0063       if (lowerOutputFiller.empty())
0064         lowerOutputFiller.abort();
0065     }
0066     {
0067       edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>::FastFiller upperOutputFiller(*ttClusterDSVForOutput,
0068                                                                                             upperDetid);
0069       for (unsigned int i = 0; i < upperHits.size(); i++) {
0070         TTCluster<Ref_Phase2TrackerDigi_> temp(upperHits.at(i), upperDetid, 1, storeLocalCoord);
0071         upperOutputFiller.push_back(temp);
0072       }
0073       if (upperOutputFiller.empty())
0074         upperOutputFiller.abort();
0075     }
0076   }  /// End of loop over detector elements
0077 
0078   /// Put output in the event
0079   iEvent.put(std::move(ttClusterDSVForOutput), "ClusterInclusive");
0080 }
0081 
0082 /// Retrieve hits from the event
0083 template <>
0084 void TTClusterBuilder<Ref_Phase2TrackerDigi_>::RetrieveRawHits(
0085     std::map<DetId, std::vector<Ref_Phase2TrackerDigi_>>& mRawHits, const edm::Event& iEvent) {
0086   mRawHits.clear();
0087   /// Loop over the tags used to identify hits in the cfg file
0088   std::vector<edm::EDGetTokenT<edm::DetSetVector<Phase2TrackerDigi>>>::iterator it;
0089   for (it = rawHitTokens.begin(); it != rawHitTokens.end(); ++it) {
0090     /// For each tag, get the corresponding handle
0091     edm::Handle<edm::DetSetVector<Phase2TrackerDigi>> HitHandle;
0092     iEvent.getByToken(*it, HitHandle);
0093     edm::DetSetVector<Phase2TrackerDigi>::const_iterator detsIter;
0094     edm::DetSet<Phase2TrackerDigi>::const_iterator hitsIter;
0095 
0096     /// Loop over detector elements identifying Digis
0097     for (detsIter = HitHandle->begin(); detsIter != HitHandle->end(); detsIter++) {
0098       DetId id = detsIter->id;
0099       for (hitsIter = detsIter->data.begin(); hitsIter != detsIter->data.end(); hitsIter++) {
0100         mRawHits[id].push_back(edm::makeRefTo(HitHandle, id, hitsIter));
0101       }
0102     }
0103   }
0104 }