Examples of Token/Handle to get collections in CMSSW

Check collection

edm::Handle<LumiDetails> d;
              evt.getLuminosityBlock().getByLabel("lumiProducer",d); 
              // Check that there is something
              if (!d.isValid())  return;
              //use d

From 2016, CMSSW 7.6 ??, new way of getting collections , with Tokens

In class definition i have the following:

    edm::EDGetTokenT<EBRecHitCollection> tok_EB_;
    edm::EDGetTokenT<EERecHitCollection> tok_EE_;

    edm::EDGetTokenT<EBDigiCollection> tok_EB_digi;

In class constructor where we have access to "config"

    tok_EB_    =
consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
    tok_EE_    =
consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));

    tok_EB_digi = consumes<EBDigiCollection>(edm::InputTag("selectDigi",
"selectedEcalEBDigiCollection"));

And then in analysis part I have the following:

     edm::Handle<EBRecHitCollection> EBRecHits;
     edm::Handle<EERecHitCollection> EERecHits;

    iEvent.getByToken( tok_EB_, EBRecHits );
    iEvent.getByToken( tok_EE_, EERecHits );
And then perform usual manipulations with CMSSW collections.

Old Handle notes

Use the Reco Data Format Table to get the Handle and Tags.
  • Find the header needed for the data format by clicking on the entry in the 'Containers' column.
  • Add the correxponding entry into the BuildFile (see WorkBookBuildFilesIntro ).
  • 'Handle' needs the name listed in the containers column.
  • getByLabel needs the text from the InputTag/Module(instance, if present), column.
  • The InputTag gives the name of the corresponding Process which is needed for the config file (see WriteFrameworkModule).

14 Feb 2011

More notes on collections.
What Handle getByLabel Comment
EcalRawDataCollection
Handle<EcalRawDataCollection> DCCHeaders;
iEvent.getByLabel("ecalEBunpacker", DCCHeaders)
EE digis
edm::Handle<EEDigiCollection>  ee_digis;
iEvent.getByLabel(ecalEBunpacker,eeDigis, ee_digis);
ee_digis is a smart pointer
EB digis
edm::Handle<EBDigiCollection>  eb_digis;
iEvent.getByLabel(ecalEBunpacker,ebDigis, eb_digis);
eb_digis is a smart pointer
 
RecHits
Handle<EcalRecHitCollection> rechits;
e.getByLabel(EcalRecHitCollection_, rechits);
where EcalRecHitCollection_ = ps.getParameter<InputTag>("EcalRecHitCollection"); in the analysis
with private attribute, parameter declaration: Input Tag EcalRecHitCollection_
and where EcalRecHitCollection = cms.InputTag("ecalRecHit","EcalRecHitsEE") in the config file
 
Basic ECAL clusters
edm::Handle<BasicClusterCollection> clustersH;
evt.getByLabel(ebBasicClusterTags_[i], clustersH);
James
Basic ECAL clusters
edm::Handle<reco::BasicClusterCollection> bccHandle;
iEvent.getByLabel(barrelClusterProducer_, barrelClusterCollection_, bccHandle);
Haupt, 29.4.2008
Track collection
edm::Handle<TrackCollection> tracksH;
evt.getByLabel(trackCollectionTag_, tracksH);

Cluster collection

James Jackson, 4Dec2009
  
NOTE NOTE
Things start here for the instantiation of tags !!!!!!!!!!!!!
// ClusterAnalysis::ClusterAnalysis
// Instantiates the analysis, calls user methods as required
ClusterAnalysis::ClusterAnalysis(const edm::ParameterSet &ps)
{
   // Load track and RecHit input tags
   trackCollectionTag_ = ps.getParameter<edm::InputTag>("Tracks");   <=used in evt.getBylabel(trackCollectionTag_,tracksH); below
   loadTracks_ = ps.getParameter<bool>("LoadTracks");   <=checks for loaded track collection, below 
   ebRecHitsTag_ = ps.getParameter<edm::InputTag>("EBRecHits");   <=used by  evt.getByLabel(ebRecHitsTag_, ebRecHitsH_); below
   eeRecHitsTag_ = ps.getParameter<edm::InputTag>("EERecHits");   <=used by  evt.getByLabel(eeRecHitsTag_, eeRecHitsH_); below
   
   // Load barrel cluster input tags
   std::vector<std::string> ebBct = ps.getParameter<std::vector<std::string> >("EBBasicClusters");
   for(std::vector<std::string>::const_iterator it = ebBct.begin(); it != ebBct.end(); ++it)
   {
      ebBasicClusterTags_.push_back(edm::InputTag(*it));
   }
   std::vector<std::string> ebSct = ps.getParameter<std::vector<std::string> >("EBSuperClusters");
   for(std::vector<std::string>::const_iterator it = ebSct.begin(); it != ebSct.end(); ++it)
   {
      ebSuperClusterTags_.push_back(edm::InputTag(*it));
   }
NOTE  NOTE end of instantiation section
..............
..............several lines of histo code..............

// ClusterAnalysis::analyze
// Analysis method called for each event
void ClusterAnalysis::analyze(const edm::Event &evt, const edm::EventSetup &es)
{
   // Get the track collection
   edm::Handle<TrackCollection> tracksH;
   if(loadTracks_)
   {
      evt.getByLabel(trackCollectionTag_, tracksH);
   }

   // Get the RecHits
   evt.getByLabel(ebRecHitsTag_, ebRecHitsH_);
   evt.getByLabel(eeRecHitsTag_, eeRecHitsH_);
   ebRecHits_ = ebRecHitsH_.product();
   eeRecHits_ = eeRecHitsH_.product();
   
   // Get the geometry / topology
   es.get<CaloGeometryRecord>().get(geometry_);
   es.get<CaloTopologyRecord>().get(topology_);

   // Barrel BasicClusters
   for(unsigned int i = 0; i < ebBasicClusterTags_.size(); ++i)
   {
edm::Handle<BasicClusterCollection> clustersH;
      evt.getByLabel(ebBasicClusterTags_[i], clustersH);
     DoBasicClusterAnalysisEB(*clustersH, *tracksH, evt, ebBasicClusterHists1D_[i], ebBasicClusterHists2D_[i]);
   }
   // Endcap BasicClusters
   for(unsigned int i = 0; i < eeBasicClusterTags_.size(); ++i)
   {
      edm::Handle<BasicClusterCollection> clustersH;
      evt.getByLabel(eeBasicClusterTags_[i], clustersH);
      DoBasicClusterAnalysisEE(*clustersH, *tracksH, evt, eeBasicClusterHists1D_[i], eeBasicClusterHists2D_[i]);
   }
   // Barrel SuperClusters
   for(unsigned int i = 0; i < ebSuperClusterTags_.size(); ++i)
   {
      edm::Handle<SuperClusterCollection> clustersH;
      evt.getByLabel(ebSuperClusterTags_[i], clustersH);
      DoSuperClusterAnalysisEB(*clustersH, *tracksH, evt, ebSuperClusterHists1D_[i], ebSuperClusterHists2D_[i]);
   }
   // Endcap SuperClusters
   for(unsigned int i = 0; i < eeSuperClusterTags_.size(); ++i)
   {
      edm::Handle<SuperClusterCollection> clustersH;
      evt.getByLabel(eeSuperClusterTags_[i], clustersH);
      DoSuperClusterAnalysisEE(*clustersH, *tracksH, evt, eeSuperClusterHists1D_[i], eeSuperClusterHists2D_[i]);
   }
}
// ClusterAnalysis::endJob

eeDigis

Handle with EE digis - from Sasha Ledovskoy Notes: search for 'digiProducer_' with LXR successful

Found on line 105 of

 http://cmslxr.fnal.gov/lxr/source/SimCalorimetry/EcalSelectiveReadoutProducers/interface/EcalSelectiveReadoutProducer.h#105

105   std::string digiProducer_; // name of module/plugin/producer making digis
106   std::string ebdigiCollection_; // secondary name given to collection of input digis
107 std::string eedigiCollection_; // secondary name given to collection of input digis

Great ! Now have correlations to the Handle
Along with:

108 std::string ebSRPdigiCollection_; // secondary name given to collection of suppressed digis
109   std::string eeSRPdigiCollection_; // secondary name given to collection of suppressed digis
110   std::string ebSrFlagCollection_; // secondary name given to collection of SR flag digis
111   std::string eeSrFlagCollection_; // secondary name given to collection of SR flag digis
112   std::string trigPrimProducer_; // name of module/plugin/producer making triggere primitives
113   std::string trigPrimCollection_; // name of module/plugin/producer making triggere primitives

 
string digiProducer_ = "ecalEBunpacker";
string eeDigiCollection_ = "eeDigis";
edm::Handle<EEDigiCollection>  ee_digis;   <= preapare a collection which I call "ee_digis", of type "EEDigiCollection"
iEvent.getByLabel(digiProducer_,eeDigiCollection_, ee_digis);
.....
.....is effectively....
iEvent.getByLabel(ecalEBunpacker,eeDigis, ee_digis); 
=> which asks "ecalEBunpacker" to unpack 
=> the "eeDigis" collection and put it into ee_digis
....
   if ( ee_digis->size() == 0 ){
     edm::LogError("My Code: ") << "EE Digis were not found!";}
   //******************************************************************
   for ( EEDigiCollection::const_iterator digiItr= ee_digis->begin();
                digiItr != ee_digis->end(); 
                               ++digiItr ) {    //1           
     EEDetId detId = EEDetId((*digiItr).id());
     // look if there is a digi record at jx,jy,jz
     int jx = EEDetId((*digiItr).id()).ix();
     int jy = EEDetId((*digiItr).id()).iy();
     int jz = EEDetId((*digiItr).id()).zside();
   //Get the 10 time samples for the digi record at jx,jy,jz for jx=49, jy=87, jz=-1
     int gain[10];
     int adc[10];
    for ( unsigned int i=0; i< (*digiItr).size() ; ++i ) { //2
       EEDataFrame df( *digiItr );
       gain[i] = df.sample(i).gainId();
       adc[i]  = df.sample(i).adc();
            h107->Fill(gain[i]);

ECAL Rechit collection - Sam's different method

 
evtHelper_.makeHeepEvent(iEvent,iSetup,heepEvt_);
  const EcalRecHitCollection& eeHits = *heepEvt_.eeHitsFull();
  for(size_t hitNr=0;hitNr<eeHits.size();hitNr++){
    const EcalRecHit& hit = eeHits[hitNr];   <= get 'hit' here. Energy = hit.energy()
    //    std::cout <<"hit energy etc"<<hit.energy(); //<<std::endl;
    int detId = hit.id().rawId();  <= detId declared and initialised here
    float eta = GeomFuncs::getCellPos(detId).Eta(); <= eta here
    float phi = GeomFuncs::getCellPos(detId).Phi();  <= phi here
    int hits = eeHits.size(); <= number of rechits here
    EEDetId eeDetId(detId);
    int ix = eeDetId.ix();
    int iy = eeDetId.iy();
//    std::cout << "total hits, counter hitNr, ix, iy, eta, phi, hit energy " <<std::endl;
//    std::cout << hits << " " <<  hitNr << " " << ix << " " << iy << 
                                    " " << eta << " " << phi << " " << hit.energy() << std::endl;  
//    if (( gain[i] == 1 ) && (jz == 1) ) { 
    h001->Fill(ix,iy); h002->Fill(ix,iy,hit.energy()); 

-- DavidCockerill - 20-Aug-2010

Edit | Attach | Watch | Print version | History: r10 < r9 < r8 < r7 < r6 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r10 - 2016-08-18 - DavidCockerill
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback