44 mixProdStep2_(ps_mix.getParameter<
bool>(
"mixProdStep2")),
45 mixProdStep1_(ps_mix.getParameter<
bool>(
"mixProdStep1")),
49 if (
mixProdStep1_)
LogInfo(
"MixingModule") <<
" The MixingModule was run in the Step1 mode. It produces a mixed secondary source.";
50 if (
mixProdStep2_)
LogInfo(
"MixingModule") <<
" The MixingModule was run in the Step2 mode. It uses a mixed secondary source.";
53 if (ps_mix.
exists(
"useCurrentProcessOnly")) {
58 if (ps_mix.
exists(
"LabelPlayback")) {
61 if (labelPlayback.empty()) {
69 if (ps_mix.
exists(
"WrapLongTimes")) {
70 wrapLongTimes_ = ps_mix.
getParameter<
bool>(
"WrapLongTimes");
75 std::vector<std::string>
names = ps.getParameterNames();
76 for(std::vector<std::string>::iterator it=names.begin();it!= names.end();++it) {
78 if (!pset.
exists(
"type"))
continue;
80 std::vector<InputTag> tags=pset.
getParameter<std::vector<InputTag> >(
"input");
87 if (
object==
"SimTrack") {
89 if (!tags.empty()) tag=tags[0];
95 if(makeCrossingFrame) {
97 produces<CrossingFrame<SimTrack> >(
label);
99 consumes<std::vector<SimTrack> >(
tag);
101 LogInfo(
"MixingModule") <<
"Will mix "<<
object<<
"s with InputTag= "<<tag.
encode()<<
", label will be "<<
label;
104 }
else if (
object==
"RecoTrack") {
106 if (!tags.empty()) tag=tags[0];
115 LogInfo(
"MixingModule") <<
"Will mix "<<
object<<
"s with InputTag= "<<tag.
encode()<<
", label will be "<<
label;
118 }
else if (
object==
"SimVertex") {
120 if (!tags.empty()) tag=tags[0];
126 if(makeCrossingFrame) {
128 produces<CrossingFrame<SimVertex> >(
label);
130 consumes<std::vector<SimVertex> >(
tag);
132 LogInfo(
"MixingModule") <<
"Will mix "<<
object<<
"s with InputTag "<<tag.
encode()<<
", label will be "<<
label;
135 }
else if (
object==
"HepMCProduct") {
137 if (!tags.empty()) tag=tags[0];
142 if(makeCrossingFrame) {
144 produces<CrossingFrame<HepMCProduct> >(
label);
146 consumes<HepMCProduct>(
tag);
148 LogInfo(
"MixingModule") <<
"Will mix "<<
object<<
"s with InputTag= "<<tag.
encode()<<
", label will be "<<
label;
150 for(
size_t i = 1;
i < tags.size(); ++
i) {
154 mayConsume<HepMCProduct>(fallbackTag);
157 }
else if (
object==
"PCaloHit") {
161 for (
unsigned int ii=0;
ii<subdets.size();++
ii) {
163 if (tags.size()==1) tag=tags[0];
164 else if(tags.size()>1) tag=tags[
ii];
171 produces<CrossingFrame<PCaloHit> >(
label);
172 consumes<std::vector<PCaloHit> >(
tag);
175 LogInfo(
"MixingModule") <<
"Will mix "<<
object<<
"s with InputTag= "<<tag.
encode()<<
", label will be "<<
label;
180 }
else if (
object==
"PSimHit") {
184 for (
unsigned int ii=0;
ii<subdets.size();++
ii) {
186 if (tags.size()==1) tag=tags[0];
187 else if(tags.size()>1) tag=tags[
ii];
194 produces<CrossingFrame<PSimHit> >(
label);
195 consumes<std::vector<PSimHit> >(
tag);
198 LogInfo(
"MixingModule") <<
"Will mix "<<
object<<
"s with InputTag= "<<tag.
encode()<<
", label will be "<<
label;
202 LogWarning(
"MixingModule") <<
"You have asked to mix an unknown type of object("<<
object<<
").\n If you want to include it in mixing, please contact the authors of the MixingModule!";
212 produces<PileupMixingContent>();
214 produces<CrossingFramePlaybackInfoNew>();
225 for(
auto const& digiName : digiNames) {
232 if(accumulator.get() !=
nullptr) {
268 if (adjuster->checkSignal(e)){
275 if (worker->checkSignal(e)){
302 delete digiAccumulator;
308 LogDebug(
"MixingModule")<<
"===============> adding signals for "<<e.
id();
319 int bunchCrossing,
int eventId,
331 adjuster->doOffset(
bunchSpace_, bunchCrossing, eventPrincipal, &moduleCallingContext, eventId, vertexOffset);
337 for (
auto const& worker :
workers_) {
338 LogDebug(
"MixingModule") <<
" merging Event: id " << eventPrincipal.
id();
341 worker->addPileups(eventPrincipal, &moduleCallingContext, eventId);
349 std::vector<edm::SecondaryEventIDAndFileInfo> recordEventID;
350 std::vector<size_t> sizes;
352 size_t playbackCounter = 0
U;
355 bool oldFormatPlayback =
false;
362 "CrossingFramePlaybackInfoNew on the input file, but playback " 363 "option set!!!!! Please change the input file if you really want " 364 "playback!!!!!!" << std::endl;
366 oldFormatPlayback =
true;
372 std::vector<int> PileupList;
378 if((source0 && source0->doPileUp(0) ) && !
playback_) {
390 std::vector<int> numInteractionList;
392 std::vector<float> TrueInteractionList;
393 std::vector<edm::EventID> eventInfoList;
399 bunchCrossingList.push_back(bunchCrossing);
401 numInteractionList.push_back(0);
402 TrueInteractionList.push_back(0);
405 numInteractionList.push_back(PileupList[bunchCrossing-
minBunch_]);
412 bunchCrossingList.push_back(bunchIdx);
413 for (
size_t readSrcIdx=0; readSrcIdx<
maxNbSources_; ++readSrcIdx) {
415 if(oldFormatPlayback) {
416 std::vector<edm::EventID>
const& playEventID = oldFormatPlaybackInfo_H->
getStartEventId(readSrcIdx, bunchIdx);
417 size_t numberOfEvents = playEventID.size();
418 if(readSrcIdx == 0) {
419 PileupList.push_back(numberOfEvents);
421 numInteractionList.push_back(numberOfEvents);
422 TrueInteractionList.push_back(numberOfEvents);
426 if(readSrcIdx == 0) {
427 PileupList.push_back(numberOfEvents);
429 numInteractionList.push_back(numberOfEvents);
430 TrueInteractionList.push_back(numberOfEvents);
438 (*accItr)->StorePileupInformation( bunchCrossingList,
451 for (
size_t setBcrIdx=0; setBcrIdx<
workers_.size(); ++setBcrIdx) {
452 workers_[setBcrIdx]->setBcrOffset();
455 (*accItr)->initializeBunchCrossing(e, setup, bunchIdx);
458 for (
size_t readSrcIdx=0; readSrcIdx<
maxNbSources_; ++readSrcIdx) {
463 for (
size_t setSrcIdx=0; setSrcIdx<
workers_.size(); ++setSrcIdx) {
464 workers_[setSrcIdx]->setSourceOffset(readSrcIdx);
467 if (!source || !source->doPileUp(bunchIdx)) {
476 int vertexOffset = 0;
481 int numberOfEvents = (readSrcIdx == 0 ? PileupList[bunchIdx -
minBunch_] : 1);
482 sizes.push_back(numberOfEvents);
485 _2, vertexOffset, std::ref(setup), e.
streamID()), numberOfEvents, e.
streamID());
486 }
else if(oldFormatPlayback) {
487 std::vector<edm::EventID>
const& playEventID = oldFormatPlaybackInfo_H->
getStartEventId(readSrcIdx, bunchIdx);
488 size_t numberOfEvents = playEventID.size();
489 if(readSrcIdx == 0) {
490 PileupList.push_back(numberOfEvents);
493 sizes.push_back(numberOfEvents);
494 std::vector<EventID>::const_iterator
begin = playEventID.begin();
495 std::vector<EventID>::const_iterator
end = playEventID.end();
497 begin, end, recordEventID,
499 _2, vertexOffset, std::ref(setup), e.
streamID()));
502 if(readSrcIdx == 0) {
503 PileupList.push_back(numberOfEvents);
506 sizes.push_back(numberOfEvents);
507 std::vector<SecondaryEventIDAndFileInfo>::const_iterator
begin = playbackInfo_H->
getEventId(playbackCounter);
508 playbackCounter += numberOfEvents;
509 std::vector<SecondaryEventIDAndFileInfo>::const_iterator
end = playbackInfo_H->
getEventId(playbackCounter);
511 begin, end, recordEventID,
513 _2, vertexOffset, std::ref(setup), e.
streamID()));
517 (*accItr)->finalizeBunchCrossing(e, setup, bunchIdx);
522 for (
auto const item : recordEventID) {
523 eventInfoList.emplace_back(item.eventID());
532 std::unique_ptr<PileupMixingContent> PileupMixing_;
534 PileupMixing_ = std::unique_ptr<PileupMixingContent>(
new PileupMixingContent(bunchCrossingList,
552 std::unique_ptr<CrossingFramePlaybackInfoNew> pOut(
playbackInfo_);
559 (*accItr)->beginRun(run, setup);
566 (*accItr)->endRun(run, setup);
573 (*accItr)->beginLuminosityBlock(lumi, setup);
580 (*accItr)->endLuminosityBlock(lumi, setup);
588 (*accItr)->initializeEvent(event, setup);
595 (*accItr)->accumulate(event, setup);
602 (*accItr)->accumulate(event, setup, streamID);
609 (*accItr)->finalizeEvent(event, setup);
void setInfo(std::vector< edm::SecondaryEventIDAndFileInfo > &eventInfo, std::vector< size_t > &sizes)
std::vector< edm::SecondaryEventIDAndFileInfo >::const_iterator getEventId(size_t offset) const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void beginRun(const edm::Run &r, const edm::EventSetup &setup) override
void beginLuminosityBlock(LuminosityBlock const &l1, EventSetup const &c) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
const int & bunchSpace() const
static std::string const source("source")
static const HistoName names[]
std::vector< edm::EventID > getStartEventId(const unsigned int s, const int bcr) const
void createDigiAccumulators(const edm::ParameterSet &mixingPSet, edm::ConsumesCollector &iC)
std::vector< float > TrueNumInteractions_
EventID const & id() const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
def setup(process, global_tag, zero_tesla=False)
void addSignals(const edm::Event &e, const edm::EventSetup &es) override
void endRun(const edm::Run &r, const edm::EventSetup &setup) override
void put(edm::Event &e, const edm::EventSetup &es) override
const int & maxBunch() const
ModuleCallingContext const * moduleCallingContext() const
void reload(const edm::EventSetup &) override
std::string friendlyName(std::string const &iFullName)
void endLuminosityBlock(LuminosityBlock const &l1, EventSetup const &c) override
void checkSignal(const edm::Event &e) override
std::vector< MixingWorkerBase * > workers_
Accumulators digiAccumulators_
void initializeEvent(Event const &event, EventSetup const &setup) override
MixingModule(const edm::ParameterSet &ps, MixingCache::Config const *globalConf)
std::vector< AdjusterBase * > adjusters_
size_t getNumberOfEvents(int bunchIdx, size_t sourceNumber) const
static const unsigned int maxNbSources_
std::vector< MixingWorkerBase * > workersObjects_
void beginRun(Run const &r1, EventSetup const &c) override
std::vector< std::string > getParameterNames() const
CrossingFramePlaybackInfoNew * playbackInfo_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
def getProcessName(pdgGen, requiredNumberOfGeneratedObjects)
bool useCurrentProcessOnly_
virtual void branchesActivate(const std::string &friendlyName, const std::string &subdet, InputTag &tag, std::string &label)
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
ParameterSet const & getParameterSet(std::string const &) const
std::vector< std::string > wantedBranches_
std::vector< AdjusterBase * > adjustersObjects_
InputTag inputTagPlayback_
void accumulateEvent(Event const &event, EventSetup const &setup)
void createnewEDProduct() override
std::vector< std::shared_ptr< PileUp > > inputSources_
std::unique_ptr< DigiAccumulatorMixMod > makeDigiAccumulator(ParameterSet const &, ProducerBase &, ConsumesCollector &) const
StreamID streamID() const
const int & minBunch() const
bool binary_search_all(ForwardSequence const &s, Datum const &d)
wrappers for std::binary_search
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
void finalizeEvent(Event &event, EventSetup const &setup) override
void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
static DigiAccumulatorMixModFactory const * get()
static const std::string subdets[7]
void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
void doPileUp(edm::Event &e, const edm::EventSetup &es) override
void pileAllWorkers(EventPrincipal const &ep, ModuleCallingContext const *, int bcr, int id, int &offset, const edm::EventSetup &setup, edm::StreamID const &)
void endRun(Run const &r1, EventSetup const &c) override