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

Simulation of the readout and digitization for the MIP timing detector barrel #23584

Merged
merged 14 commits into from Jun 27, 2018
Merged
Expand Up @@ -20,4 +20,4 @@
)

from Configuration.Eras.Modifier_phase2_timing_layer_new_cff import phase2_timing_layer_new
phase2_timing_layer_new.toModify( RecoLocalFastTimeFEVT.outputCommands, func=lambda outputCommands: outputCommands.extend(['drop *_ftlUncalibratedRecHits_*_*','keep *_mtdUncalibratedRecHits_*_*']) )
phase2_timing_layer_new.toModify( RecoLocalFastTimeFEVT.outputCommands, func=lambda outputCommands: outputCommands.extend(['drop *_ftlUncalibratedRecHits_*_*','keep *_mtdUncalibratedRecHits_*_*','drop *_ftlRecHits_*_*','keep *_mtdRecHits_*_*']) )
Expand Up @@ -6,8 +6,9 @@
fastTimingLocalReco = cms.Sequence(ftlUncalibratedRecHits*ftlRecHits)

from RecoLocalFastTime.FTLRecProducers.mtdUncalibratedRecHits_cfi import mtdUncalibratedRecHits
_phase2_timing_layer_new_fastTimingLocalReco = cms.Sequence(mtdUncalibratedRecHits*ftlRecHits)
from RecoLocalFastTime.FTLRecProducers.mtdRecHits_cfi import mtdRecHits
_phase2_timing_layer_new_fastTimingLocalReco = cms.Sequence(mtdUncalibratedRecHits*mtdRecHits)
from Configuration.Eras.Modifier_phase2_timing_layer_new_cff import phase2_timing_layer_new
phase2_timing_layer_new.toReplaceWith(fastTimingLocalReco, _phase2_timing_layer_new_fastTimingLocalReco)
phase2_timing_layer_new.toModify(ftlRecHits, barrelUncalibratedRecHits = cms.InputTag('mtdUncalibratedRecHits:FTLBarrel'),
phase2_timing_layer_new.toModify(mtdRecHits, barrelUncalibratedRecHits = cms.InputTag('mtdUncalibratedRecHits:FTLBarrel'),
endcapUncalibratedRecHits = cms.InputTag('mtdUncalibratedRecHits:FTLEndcap') )
50 changes: 50 additions & 0 deletions RecoLocalFastTime/FTLCommonAlgos/interface/MTDRecHitAlgoBase.h
@@ -0,0 +1,50 @@
#ifndef RecoLocalFastTime_FTLCommonAlgos_MTDRecHitAlgoBase_HH
#define RecoLocalFastTime_FTLCommonAlgos_MTDRecHitAlgoBase_HH

/** \class MTDRecHitAlgoBase
* Template algorithm to make rechits from uncalibrated rechits
*
* \author Lindsey Gray
*/

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "DataFormats/FTLRecHit/interface/FTLRecHit.h"
#include "DataFormats/FTLRecHit/interface/FTLUncalibratedRecHit.h"

namespace edm {
class Event;
class EventSetup;
}

class MTDRecHitAlgoBase {
public:

/// Constructor
MTDRecHitAlgoBase(const edm::ParameterSet& conf,
edm::ConsumesCollector& sumes):
name_( conf.getParameter<std::string>("algoName") ){ };

/// Destructor
virtual ~MTDRecHitAlgoBase() { };

/// get event and eventsetup information
virtual void getEvent(const edm::Event&) = 0;
virtual void getEventSetup(const edm::EventSetup&) = 0;

/// make rechits from dataframes
virtual FTLRecHit makeRecHit(const FTLUncalibratedRecHit& uRecHit, uint32_t& flags) const = 0;

const std::string& name() const { return name_; }

private:
std::string name_;

};

#include "FWCore/PluginManager/interface/PluginFactory.h"
typedef edmplugin::PluginFactory< MTDRecHitAlgoBase* (const edm::ParameterSet&, edm::ConsumesCollector&) > MTDRecHitAlgoFactory;


#endif
51 changes: 51 additions & 0 deletions RecoLocalFastTime/FTLCommonAlgos/plugins/MTDRecHitAlgo.cc
@@ -0,0 +1,51 @@
#include "RecoLocalFastTime/FTLCommonAlgos/interface/MTDRecHitAlgoBase.h"

class MTDRecHitAlgo : public MTDRecHitAlgoBase {
public:
/// Constructor
MTDRecHitAlgo( const edm::ParameterSet& conf,
edm::ConsumesCollector& sumes ) :
MTDRecHitAlgoBase( conf, sumes ),
thresholdToKeep_( conf.getParameter<double>("thresholdToKeep") ),
calibration_( conf.getParameter<double>("calibrationConstant") ) { }

/// Destructor
~MTDRecHitAlgo() override { }

/// get event and eventsetup information
void getEvent(const edm::Event&) final {}
void getEventSetup(const edm::EventSetup&) final {}

/// make the rec hit
FTLRecHit makeRecHit(const FTLUncalibratedRecHit& uRecHit, uint32_t& flags ) const final;

private:
double thresholdToKeep_, calibration_;
};


FTLRecHit
MTDRecHitAlgo::makeRecHit(const FTLUncalibratedRecHit& uRecHit, uint32_t& flags) const {

float energy = uRecHit.amplitude() * calibration_;
float time = uRecHit.time();
float timeError = uRecHit.timeError();

FTLRecHit rh( uRecHit.id(), energy, time, timeError );

// Now fill flags
// all rechits from the digitizer are "good" at present
if( energy > thresholdToKeep_ ) {
flags = FTLRecHit::kGood;
rh.setFlag(flags);
} else {
flags = FTLRecHit::kKilled;
rh.setFlag(flags);
}

return rh;
}


#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_EDM_PLUGIN( MTDRecHitAlgoFactory, MTDRecHitAlgo, "MTDRecHitAlgo" );
41 changes: 23 additions & 18 deletions RecoLocalFastTime/FTLCommonAlgos/plugins/MTDUncalibRecHitAlgo.cc
Expand Up @@ -7,13 +7,17 @@ class MTDUncalibRecHitAlgo : public MTDUncalibratedRecHitAlgoBase {
MTDUncalibRecHitAlgo( const edm::ParameterSet& conf,
edm::ConsumesCollector& sumes ) :
MTDUncalibratedRecHitAlgoBase( conf, sumes ) {
uint32_t nBits = conf.getParameter<uint32_t>("adcNbits");
double saturation = conf.getParameter<double>("adcSaturation");
adcLSB_ = saturation/(1<<nBits);

toaLSBToNS_ = conf.getParameter<double>("toaLSB_ns");
uint32_t BTL_nBits = conf.getParameter<uint32_t>("BTLadcNbits");
double BTL_saturation = conf.getParameter<double>("BTLadcSaturation");
BTL_adcLSB_ = BTL_saturation/(1<<BTL_nBits);
BTL_toaLSBToNS_ = conf.getParameter<double>("BTLtoaLSB_ns");
BTL_timeError_ = conf.getParameter<double>("BTLtimeResolutionInNs");

timeError_ = conf.getParameter<double>("timeResolutionInNs");
uint32_t ETL_nBits = conf.getParameter<uint32_t>("ETLadcNbits");
double ETL_saturation = conf.getParameter<double>("ETLadcSaturation");
ETL_adcLSB_ = ETL_saturation/(1<<ETL_nBits);
ETL_toaLSBToNS_ = conf.getParameter<double>("ETLtoaLSB_ns");
ETL_timeError_ = conf.getParameter<double>("ETLtimeResolutionInNs");
}

/// Destructor
Expand All @@ -28,43 +32,44 @@ class MTDUncalibRecHitAlgo : public MTDUncalibratedRecHitAlgoBase {
FTLUncalibratedRecHit makeRecHit(const ETLDataFrame& dataFrame ) const final;

private:
double adcLSB_, toaLSBToNS_, timeError_;
double BTL_adcLSB_, BTL_toaLSBToNS_, BTL_timeError_;
double ETL_adcLSB_, ETL_toaLSBToNS_, ETL_timeError_;
};

FTLUncalibratedRecHit
MTDUncalibRecHitAlgo::makeRecHit(const BTLDataFrame& dataFrame ) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A similar simplification could be done here, though there's more information to pass (sample.data(), sample.toa(), dataFrame.id(), adcLSB, toaLSBToNS, timeError).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would leave two distinct methods: makeRecHit(const BTLDataFrame& dataFrame ) and makeRecHit(const ETLDataFrame& dataFrame ). For the time being they are implemented in the same way, but they refer to two different detectors, built with different technologies, and
soon (~a couple of weeks) will have different impementations.

constexpr int iSample=2; //only in-time sample
const auto& sample = dataFrame.sample(iSample);

double amplitude = double(sample.data()) * adcLSB_;
double time = double(sample.toa()) * toaLSBToNS_;
double amplitude = double(sample.data()) * BTL_adcLSB_;
double time = double(sample.toa()) * BTL_toaLSBToNS_;

unsigned char flag = 0;

LogDebug("MTDUncalibRecHit") << "ADC+: set the charge to: " << amplitude << ' ' << sample.data()
<< ' ' << adcLSB_ << ' ' << std::endl;
<< ' ' << BTL_adcLSB_ << ' ' << std::endl;
LogDebug("MTDUncalibRecHit") << "ADC+: set the time to: " << time << ' ' << sample.toa()
<< ' ' << toaLSBToNS_ << ' ' << std::endl;
<< ' ' << BTL_toaLSBToNS_ << ' ' << std::endl;
LogDebug("MTDUncalibRecHit") << "Final uncalibrated amplitude : " << amplitude << std::endl;

return FTLUncalibratedRecHit( dataFrame.id(), amplitude, time, timeError_, flag);
return FTLUncalibratedRecHit( dataFrame.id(), amplitude, time, BTL_timeError_, flag);
}
FTLUncalibratedRecHit
MTDUncalibRecHitAlgo::makeRecHit(const ETLDataFrame& dataFrame ) const {
constexpr int iSample=2; //only in-time sample
const auto& sample = dataFrame.sample(iSample);

double amplitude = double(sample.data()) * adcLSB_;
double time = double(sample.toa()) * toaLSBToNS_;
double amplitude = double(sample.data()) * ETL_adcLSB_;
double time = double(sample.toa()) * ETL_toaLSBToNS_;
unsigned char flag = 0;

LogDebug("MTDUncalibRecHit") << "ADC+: set the charge to: " << amplitude << ' ' << sample.data()
<< ' ' << adcLSB_ << ' ' << std::endl;
<< ' ' << ETL_adcLSB_ << ' ' << std::endl;
LogDebug("MTDUncalibRecHit") << "ADC+: set the time to: " << time << ' ' << sample.toa()
<< ' ' << toaLSBToNS_ << ' ' << std::endl;
<< ' ' << ETL_toaLSBToNS_ << ' ' << std::endl;
LogDebug("MTDUncalibRecHit") << "Final uncalibrated amplitude : " << amplitude << std::endl;

return FTLUncalibratedRecHit( dataFrame.id(), amplitude, time, timeError_, flag);
return FTLUncalibratedRecHit( dataFrame.id(), amplitude, time, ETL_timeError_, flag);
}

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down
Expand Up @@ -3,8 +3,12 @@
# MTD "uncalibrated" rechit producer from digis
mtdUncalibRecHitAlgo = cms.PSet(
algoName = cms.string("MTDUncalibRecHitAlgo"),
adcNbits = cms.uint32(12),
adcSaturation = cms.double(102),
toaLSB_ns = cms.double(0.005),
timeResolutionInNs = cms.double(0.025)
BTLadcNbits = cms.uint32(10),
BTLadcSaturation = cms.double(600),
BTLtoaLSB_ns = cms.double(0.020),
BTLtimeResolutionInNs = cms.double(0.025),
ETLadcNbits = cms.uint32(12),
ETLadcSaturation = cms.double(102),
ETLtoaLSB_ns = cms.double(0.005),
ETLtimeResolutionInNs = cms.double(0.025)
)
3 changes: 3 additions & 0 deletions RecoLocalFastTime/FTLCommonAlgos/src/MTDRecHitAlgoBase.cc
@@ -0,0 +1,3 @@
#include "RecoLocalFastTime/FTLCommonAlgos/interface/MTDRecHitAlgoBase.h"

EDM_REGISTER_PLUGINFACTORY(MTDRecHitAlgoFactory,"MTDRecHitAlgoFactory");
96 changes: 96 additions & 0 deletions RecoLocalFastTime/FTLRecProducers/plugins/MTDRecHitProducer.cc
@@ -0,0 +1,96 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"

#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/FTLDigi/interface/FTLDigiCollections.h"
#include "DataFormats/FTLRecHit/interface/FTLRecHitCollections.h"

#include "RecoLocalFastTime/FTLCommonAlgos/interface/MTDRecHitAlgoBase.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

class MTDRecHitProducer : public edm::stream::EDProducer<> {

public:
explicit MTDRecHitProducer(const edm::ParameterSet& ps);
~MTDRecHitProducer() override;
void produce(edm::Event& evt, const edm::EventSetup& es) override;

private:

const edm::EDGetTokenT<FTLUncalibratedRecHitCollection> ftlbURecHits_; // collection of barrel digis
const edm::EDGetTokenT<FTLUncalibratedRecHitCollection> ftleURecHits_; // collection of endcap digis

const std::string ftlbInstance_; // instance name of barrel hits
const std::string ftleInstance_; // instance name of endcap hits

std::unique_ptr<MTDRecHitAlgoBase> barrel_,endcap_;
};

MTDRecHitProducer::MTDRecHitProducer(const edm::ParameterSet& ps) :
ftlbURecHits_( consumes<FTLUncalibratedRecHitCollection>( ps.getParameter<edm::InputTag>("barrelUncalibratedRecHits") ) ),
ftleURecHits_( consumes<FTLUncalibratedRecHitCollection>( ps.getParameter<edm::InputTag>("endcapUncalibratedRecHits") ) ),
ftlbInstance_( ps.getParameter<std::string>("BarrelHitsName") ),
ftleInstance_( ps.getParameter<std::string>("EndcapHitsName") )
{

produces< FTLRecHitCollection >(ftlbInstance_);
produces< FTLRecHitCollection >(ftleInstance_);

auto sumes = consumesCollector();

const edm::ParameterSet& barrel = ps.getParameterSet("barrel");
const std::string& barrelAlgo = barrel.getParameter<std::string>("algoName");
barrel_.reset( MTDRecHitAlgoFactory::get()->create(barrelAlgo, barrel, sumes) );

const edm::ParameterSet& endcap = ps.getParameterSet("endcap");
const std::string& endcapAlgo = endcap.getParameter<std::string>("algoName");
endcap_.reset( MTDRecHitAlgoFactory::get()->create(endcapAlgo, endcap, sumes) );

}

MTDRecHitProducer::~MTDRecHitProducer() {
}

void
MTDRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es) {


// tranparently get things from event setup
barrel_->getEventSetup(es);
endcap_->getEventSetup(es);

barrel_->getEvent(evt);
endcap_->getEvent(evt);

// prepare output
auto barrelRechits = std::make_unique<FTLRecHitCollection>();
auto endcapRechits = std::make_unique<FTLRecHitCollection>();

edm::Handle< FTLUncalibratedRecHitCollection > hBarrel;
evt.getByToken( ftlbURecHits_, hBarrel );
barrelRechits->reserve(hBarrel->size()/2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why only reserve half the size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a cut in energy and not all UncalibratedRecHits are converted to RecHits. I think that reserving the all size would use more memory than needed.

for(const auto& uhit : *hBarrel) {
uint32_t flags = FTLRecHit::kGood;
auto rechit = std::move( barrel_->makeRecHit(uhit, flags) );
if( flags == FTLRecHit::kGood ) barrelRechits->push_back( std::move(rechit) );
}

edm::Handle< FTLUncalibratedRecHitCollection > hEndcap;
evt.getByToken( ftleURecHits_, hEndcap );
endcapRechits->reserve(hEndcap->size()/2);
for(const auto& uhit : *hEndcap) {
uint32_t flags = FTLRecHit::kGood;
auto rechit = std::move( endcap_->makeRecHit(uhit, flags) );
if( flags == FTLRecHit::kGood ) endcapRechits->push_back( std::move(rechit) );
}

// put the collection of recunstructed hits in the event
evt.put(std::move(barrelRechits), ftlbInstance_);
evt.put(std::move(endcapRechits), ftleInstance_);
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE( MTDRecHitProducer );
25 changes: 25 additions & 0 deletions RecoLocalFastTime/FTLRecProducers/python/mtdRecHits_cfi.py
@@ -0,0 +1,25 @@
import FWCore.ParameterSet.Config as cms

_barrelAlgo = cms.PSet(
algoName = cms.string("MTDRecHitAlgo"),
thresholdToKeep = cms.double(1.), # MeV
calibrationConstant = cms.double(0.026041667), # MeV/pC
)


_endcapAlgo = cms.PSet(
algoName = cms.string("MTDRecHitAlgo"),
thresholdToKeep = cms.double(0.5), # MIPs
calibrationConstant = cms.double(1.),
)


mtdRecHits = cms.EDProducer(
"MTDRecHitProducer",
barrel = _barrelAlgo,
endcap = _endcapAlgo,
barrelUncalibratedRecHits = cms.InputTag('mtdUncalibratedRecHits:FTLBarrel'),
endcapUncalibratedRecHits = cms.InputTag('mtdUncalibratedRecHits:FTLEndcap'),
BarrelHitsName = cms.string('FTLBarrel'),
EndcapHitsName = cms.string('FTLEndcap'),
)
4 changes: 2 additions & 2 deletions RecoLocalFastTime/FTLRecProducers/test/MTDRecoDump.cc
Expand Up @@ -36,8 +36,8 @@ MTDRecoDump::MTDRecoDump(const edm::ParameterSet& iConfig)

{

tok_BTL_reco = consumes<FTLRecHitCollection>(edm::InputTag("ftlRecHits","FTLBarrel"));
tok_ETL_reco = consumes<FTLRecHitCollection>(edm::InputTag("ftlRecHits","FTLEndcap"));
tok_BTL_reco = consumes<FTLRecHitCollection>(edm::InputTag("mtdRecHits","FTLBarrel"));
tok_ETL_reco = consumes<FTLRecHitCollection>(edm::InputTag("mtdRecHits","FTLEndcap"));

}

Expand Down
19 changes: 14 additions & 5 deletions SimFastTiming/FastTimingCommon/interface/BTLDeviceSim.h
Expand Up @@ -11,6 +11,10 @@

#include <tuple>

namespace CLHEP {
class HepRandomEngine;
}

class BTLDeviceSim {

public:
Expand All @@ -23,13 +27,18 @@ class BTLDeviceSim {

void getHitsResponse(const std::vector<std::tuple<int,uint32_t,float> > &hitRefs,
const edm::Handle<edm::PSimHitContainer> &hits,
mtd_digitizer::MTDSimHitDataAccumulator *simHitAccumulator);

mtd_digitizer::MTDSimHitDataAccumulator *simHitAccumulator,
CLHEP::HepRandomEngine *hre);

private:

float MIPPerMeV_;
float bxTime_;
float tofDelay_;
const float refSpeed_;
const float bxTime_;
const float LightYield_;
const float LightCollEff_;
const float LightCollTime_;
const float smearLightCollTime_;
const float PDE_;

};

Expand Down