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") {
186 for (
unsigned int ii=0;
ii<subdets.size();++
ii) {
188 if (tags.size()==1) tag=tags[0];
189 else if(tags.size()>1) tag=tags[
ii];
197 produces<CrossingFrame<PSimHit> >(
label);
198 if(makePCrossingFrame) {
199 produces<PCrossingFrame<PSimHit> >(
label);
201 consumes<std::vector<PSimHit> >(
tag);
204 LogInfo(
"MixingModule") <<
"Will mix "<<
object<<
"s with InputTag= "<<tag.
encode()<<
", label will be "<<
label;
208 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!";
218 produces<PileupMixingContent>();
220 produces<CrossingFramePlaybackInfoNew>();
231 for(
auto const& digiName : digiNames) {
238 if(accumulator.get() !=
nullptr) {
274 if (adjuster->checkSignal(e)){
281 if (worker->checkSignal(e)){
308 delete digiAccumulator;
314 LogDebug(
"MixingModule")<<
"===============> adding signals for "<<e.
id();
325 int bunchCrossing,
int eventId,
337 adjuster->doOffset(
bunchSpace_, bunchCrossing, eventPrincipal, &moduleCallingContext, eventId, vertexOffset);
343 for (
auto const& worker :
workers_) {
344 LogDebug(
"MixingModule") <<
" merging Event: id " << eventPrincipal.
id();
347 worker->addPileups(eventPrincipal, &moduleCallingContext, eventId);
357 std::vector<edm::SecondaryEventIDAndFileInfo> recordEventID;
358 std::vector<size_t> sizes;
360 size_t playbackCounter = 0
U;
363 bool oldFormatPlayback =
false;
370 "CrossingFramePlaybackInfoNew on the input file, but playback " 371 "option set!!!!! Please change the input file if you really want " 372 "playback!!!!!!" << std::endl;
374 oldFormatPlayback =
true;
380 std::vector<int> PileupList;
386 if((source0 && source0->doPileUp(0) ) && !
playback_) {
398 std::vector<int> numInteractionList;
400 std::vector<float> TrueInteractionList;
401 std::vector<edm::EventID> eventInfoList;
407 bunchCrossingList.push_back(bunchCrossing);
409 numInteractionList.push_back(0);
410 TrueInteractionList.push_back(0);
413 numInteractionList.push_back(PileupList[bunchCrossing-
minBunch_]);
420 bunchCrossingList.push_back(bunchIdx);
421 for (
size_t readSrcIdx=0; readSrcIdx<
maxNbSources_; ++readSrcIdx) {
423 if(oldFormatPlayback) {
424 std::vector<edm::EventID>
const& playEventID = oldFormatPlaybackInfo_H->
getStartEventId(readSrcIdx, bunchIdx);
425 size_t numberOfEvents = playEventID.size();
426 if(readSrcIdx == 0) {
427 PileupList.push_back(numberOfEvents);
429 numInteractionList.push_back(numberOfEvents);
430 TrueInteractionList.push_back(numberOfEvents);
434 if(readSrcIdx == 0) {
435 PileupList.push_back(numberOfEvents);
437 numInteractionList.push_back(numberOfEvents);
438 TrueInteractionList.push_back(numberOfEvents);
446 (*accItr)->StorePileupInformation( bunchCrossingList,
459 for (
size_t setBcrIdx=0; setBcrIdx<
workers_.size(); ++setBcrIdx) {
460 workers_[setBcrIdx]->setBcrOffset();
463 (*accItr)->initializeBunchCrossing(e, setup, bunchIdx);
466 for (
size_t readSrcIdx=0; readSrcIdx<
maxNbSources_; ++readSrcIdx) {
471 for (
size_t setSrcIdx=0; setSrcIdx<
workers_.size(); ++setSrcIdx) {
472 workers_[setSrcIdx]->setSourceOffset(readSrcIdx);
475 if (!source || !source->doPileUp(bunchIdx)) {
484 int vertexOffset = 0;
489 int numberOfEvents = (readSrcIdx == 0 ? PileupList[bunchIdx -
minBunch_] : 1);
490 sizes.push_back(numberOfEvents);
493 _2, vertexOffset, std::ref(setup), e.
streamID()), numberOfEvents, e.
streamID());
494 }
else if(oldFormatPlayback) {
495 std::vector<edm::EventID>
const& playEventID = oldFormatPlaybackInfo_H->
getStartEventId(readSrcIdx, bunchIdx);
496 size_t numberOfEvents = playEventID.size();
497 if(readSrcIdx == 0) {
498 PileupList.push_back(numberOfEvents);
501 sizes.push_back(numberOfEvents);
502 std::vector<EventID>::const_iterator
begin = playEventID.begin();
503 std::vector<EventID>::const_iterator
end = playEventID.end();
505 begin, end, recordEventID,
507 _2, vertexOffset, std::ref(setup), e.
streamID()));
510 if(readSrcIdx == 0) {
511 PileupList.push_back(numberOfEvents);
514 sizes.push_back(numberOfEvents);
515 std::vector<SecondaryEventIDAndFileInfo>::const_iterator
begin = playbackInfo_H->
getEventId(playbackCounter);
516 playbackCounter += numberOfEvents;
517 std::vector<SecondaryEventIDAndFileInfo>::const_iterator
end = playbackInfo_H->
getEventId(playbackCounter);
519 begin, end, recordEventID,
521 _2, vertexOffset, std::ref(setup), e.
streamID()));
525 (*accItr)->finalizeBunchCrossing(e, setup, bunchIdx);
530 for (
auto const item : recordEventID) {
531 eventInfoList.emplace_back(item.eventID());
540 std::unique_ptr<PileupMixingContent> PileupMixing_;
542 PileupMixing_ = std::unique_ptr<PileupMixingContent>(
new PileupMixingContent(bunchCrossingList,
560 std::unique_ptr<CrossingFramePlaybackInfoNew> pOut(
playbackInfo_);
567 (*accItr)->beginRun(run, setup);
574 (*accItr)->endRun(run, setup);
581 (*accItr)->beginLuminosityBlock(lumi, setup);
588 (*accItr)->endLuminosityBlock(lumi, setup);
596 (*accItr)->initializeEvent(event, setup);
603 (*accItr)->accumulate(event, setup);
610 (*accItr)->accumulate(event, setup, streamID);
617 (*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")
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
const std::string names[nVars_]
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)
bool pileAllWorkers(EventPrincipal const &ep, ModuleCallingContext const *, int bcr, int id, int &offset, const edm::EventSetup &setup, edm::StreamID const &)
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 endRun(Run const &r1, EventSetup const &c) override