Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saving the collections of ECAL selective readout flags in pi0/eta stream output #20973

Merged
merged 5 commits into from Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions HLTrigger/special/BuildFile.xml
Expand Up @@ -50,5 +50,6 @@
<use name="Geometry/EcalAlgo"/>
<use name="SimGeneral/HepPDTRecord"/>
<use name="TrackingTools/TransientTrack"/>
<use name="CalibCalorimetry/EcalTPGTools"/>

<flags EDM_PLUGIN="1"/>
87 changes: 86 additions & 1 deletion HLTrigger/special/src/HLTRechitsToDigis.cc
Expand Up @@ -31,10 +31,16 @@
#include "DataFormats/EcalDetId/interface/EEDetId.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
#include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"

#include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"

// for srFlags management
#include "CalibCalorimetry/EcalTPGTools/interface/EcalReadoutTools.h"
#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"


//
// class declaration
//
Expand All @@ -55,14 +61,22 @@ class HLTRechitsToDigis : public edm::stream::EDProducer<> {
edm::EDGetTokenT<EBDigiCollection> digisEBInToken_;
edm::EDGetTokenT<EEDigiCollection> digisEEInToken_;
edm::EDGetTokenT<EcalRecHitCollection> recHitsToken_;

// tokens for srFlags
edm::EDGetTokenT<EBSrFlagCollection> srFlagsEBInToken_;
edm::EDGetTokenT<EESrFlagCollection> srFlagsEEInToken_;

// input tags
edm::InputTag digisIn_;
edm::InputTag recHits_;
// srFlags
edm::InputTag srFlagsIn_;

// string for the produced digi collection
std::string digisOut_;
ecalRegion region_;
// string for the produced srFlags collection
std::string srFlagsOut_;

};
//

Expand All @@ -81,15 +95,29 @@ HLTRechitsToDigis::HLTRechitsToDigis(const edm::ParameterSet& iConfig)
// hit collections to save digis for
recHits_ = iConfig.getParameter<edm::InputTag> ("recHits");

// srFlags matched to digis to be saved
srFlagsIn_ = iConfig.getParameter<edm::InputTag> ("srFlagsIn");
srFlagsOut_ = iConfig.getParameter<std::string> ("srFlagsOut");

// region specific tokens
switch(region_) {
case barrel:
digisEBInToken_ = consumes<EBDigiCollection>(digisIn_);
produces<EBDigiCollection>(digisOut_);
// protection against empty InputTag to allow for backward compatibility
if (not srFlagsIn_.label().empty()) {
srFlagsEBInToken_ = consumes<EBSrFlagCollection>(srFlagsIn_);
produces<EBSrFlagCollection>(srFlagsOut_);
}
break;
case endcap:
digisEEInToken_ = consumes<EEDigiCollection>(digisIn_);
produces<EEDigiCollection>(digisOut_);
// protection against empty InputTag to allow for backward compatibility
if (not srFlagsIn_.label().empty()) {
srFlagsEEInToken_ = consumes<EESrFlagCollection>(srFlagsIn_);
produces<EESrFlagCollection>(srFlagsOut_);
}
break;
case invalidRegion:
break;
Expand Down Expand Up @@ -126,6 +154,15 @@ HLTRechitsToDigis::produce(edm::Event& iEvent, edm::EventSetup const& setup) {
// output collections
std::unique_ptr<EBDigiCollection> outputEBDigiCollection( new EBDigiCollection );
std::unique_ptr<EEDigiCollection> outputEEDigiCollection( new EEDigiCollection );

// handles for srFlags
Handle<EBSrFlagCollection> srFlagsEBHandle;
Handle<EESrFlagCollection> srFlagsEEHandle;

// output collections
std::unique_ptr<EBSrFlagCollection> outputEBSrFlagCollection( new EBSrFlagCollection );
std::unique_ptr<EESrFlagCollection> outputEESrFlagCollection( new EESrFlagCollection );
EcalReadoutTools ecalReadOutTool(iEvent, setup);

// calibrated rechits
Handle<EcalRecHitCollection> recHitsHandle;
Expand All @@ -136,37 +173,81 @@ HLTRechitsToDigis::produce(edm::Event& iEvent, edm::EventSetup const& setup) {
case barrel: {
iEvent.getByToken(digisEBInToken_, digisEBHandle);
const EBDigiCollection* digisEB = digisEBHandle.product();

const EBSrFlagCollection* srFlagsEB = nullptr;
// protection against uninitialized token (empty InputTag) to allow for backward compatibility
if (not srFlagsEBInToken_.isUninitialized()) {
iEvent.getByToken(srFlagsEBInToken_, srFlagsEBHandle);
srFlagsEB = srFlagsEBHandle.product();
}

// loop over the collection of rechits and match to digis
// at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
EcalRecHitCollection::const_iterator ituneEB;
for (ituneEB = recHitsHandle->begin(); ituneEB != recHitsHandle->end(); ituneEB++) {
EcalRecHit const & hit = (*ituneEB);
EcalDigiCollection::const_iterator digiLookUp = digisEB->find(hit.id());
// protect against a digi not existing
if( digiLookUp == digisEB->end()) continue;
outputEBDigiCollection->push_back( digiLookUp->id(), digiLookUp->begin() );

EBSrFlagCollection::const_iterator srFlagLookUp;
if (not srFlagsEBInToken_.isUninitialized()) {
// same matching for srFlags
// firstly, get the tower id
const EcalTrigTowerDetId& ttId = ecalReadOutTool.readOutUnitOf( static_cast<EBDetId>(hit.id()) );
// avoid inserting the same tower twice in the output collection (all the digis in the same tower will have the same SR flag)
if (outputEBSrFlagCollection->find(ttId) != outputEBSrFlagCollection->end()) continue;
srFlagLookUp = srFlagsEB->find( ttId );
// protect against a srFlag not existing
if( srFlagLookUp == srFlagsEB->end()) continue;
outputEBSrFlagCollection->push_back( *srFlagLookUp );
}
}

// add the built collection to the event
iEvent.put(std::move(outputEBDigiCollection), digisOut_);
if (not srFlagsEBInToken_.isUninitialized()) iEvent.put(std::move(outputEBSrFlagCollection), srFlagsOut_);
break;
}
case endcap: {
iEvent.getByToken(digisEEInToken_, digisEEHandle);
const EEDigiCollection* digisEE = digisEEHandle.product();

const EESrFlagCollection* srFlagsEE = nullptr;
// protection against uninitialized token (empty InputTag) to allow for backward compatibility
if (not srFlagsEEInToken_.isUninitialized()) {
iEvent.getByToken(srFlagsEEInToken_, srFlagsEEHandle);
srFlagsEE = srFlagsEEHandle.product();
}

// loop over the collection of rechits and match to digis
// at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
EcalRecHitCollection::const_iterator ituneEE;
for (ituneEE = recHitsHandle->begin(); ituneEE != recHitsHandle->end(); ituneEE++) {
EcalRecHit const & hit = (*ituneEE);
EcalDigiCollection::const_iterator digiLookUp = digisEE->find(hit.id());
// protect against a digi not existing for the saved rechit
if(digiLookUp == digisEE->end()) continue;
outputEEDigiCollection->push_back( digiLookUp->id(), digiLookUp->begin() );

EESrFlagCollection::const_iterator srFlagLookUp;
if (not srFlagsEEInToken_.isUninitialized()) {
// same matching for srFlags
// firstly, get the tower id
const EcalScDetId& scId = ecalReadOutTool.readOutUnitOf( static_cast<EEDetId>(hit.id()) );
// avoid inserting the same tower twice in the output collection (all the digis in the same tower will have the same SR flag)
if (outputEESrFlagCollection->find(scId) != outputEESrFlagCollection->end()) continue;
srFlagLookUp = srFlagsEE->find( scId );
// protect against an srFlag not existing for the saved rechit
if(srFlagLookUp == srFlagsEE->end()) continue;
outputEESrFlagCollection->push_back( *srFlagLookUp );
}
} // end loop over endcap rechits

// add the built collection to the event
iEvent.put(std::move(outputEEDigiCollection), digisOut_);
if (not srFlagsEEInToken_.isUninitialized()) iEvent.put(std::move(outputEESrFlagCollection), srFlagsOut_);
break;
}
case invalidRegion: {
Expand Down Expand Up @@ -222,6 +303,10 @@ HLTRechitsToDigis::fillDescriptions(edm::ConfigurationDescriptions& descriptions
->setComment("Name for the collection of Digis saved by the module");
desc.add<edm::InputTag>("recHits",edm::InputTag("hltAlCaPi0EBUncalibrator","pi0EcalRecHitsEB"))
->setComment("Collection of rechits to match Digis to");
desc.add<edm::InputTag>("srFlagsIn",edm::InputTag())
->setComment("The collection of either barrel or endcap srFlags which correspond to the rechit collection");
desc.add<std::string>("srFlagsOut","pi0EBSrFlags")
->setComment("Name for the collection of SrFlags saved by the module");
descriptions.add("hltFindMatchingECALDigisToRechits", desc);
}

Expand Down