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

Primitive RPC trigger #26967

Merged
merged 11 commits into from
Jul 9, 2019
61 changes: 61 additions & 0 deletions L1Trigger/RPCTriggerPrimitives/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# RPCTriggerPrimitives

This is the first version of the RPCTriggerPrimitives for the RPC detector. Which uses as an input the RPCDigis as an input and the RPCRecHits (New collection) as an output. The output of this module is an edm branch named RPCPrimitivesDigis, following the RPCRecHit format already committed in CMSSW_10_6_0. We apply the cluster size cut and emulate max two clusters per link board. The module can be tuned by the parameters LinkBoardCut and ClusterSizeCut for phaseII.

# Out of the box instructions

```
ssh -XY username@lxplus7.cern.ch
SCRAM_ARCH=slc7_amd64_gcc700; export SCRAM_ARCH (in .bashrc file)
scram list CMSSW_10_6_0
cmsrel CMSSW_10_6_0
cd CMSSW_10_6_0/src
cmsenv
```

```
You need to do a fork from your githut repository to cmssw-offline repository. The url is:
https://github.com/cms-sw/cmssw
```


```
git cms-init
git cms-addpkg L1Trigger/L1TMuonEndCap
git cms-addpkg CondTools/RPC

cd CondTools/RPC
cp /eos/cms/store/group/dpg_rpc/comm_rpc/Run-II/cppf_payloads/RPCLinkMap.db data
for analyser in test/RPC*LinkMapPopConAnalyzer_cfg.py; do
cmsRun $analyser
done; # <- this produces RPCLinkMap.db sqlite file yourself
cd -

git remote add YourGitHubName git@github.com:YourGitHubName/cmssw.git
git fetch YourGitHubName
git checkout -b PrimitiveTrigger
scram b -j6

```

## Set your environment with my branch

```
git remote add maseguracern git@github.com:maseguracern/cmssw.git
git cms-merge-topic -u maseguracern:PrimitiveTrigger
scram b -j6
```

# Run test producer
```
cd test
cmsRun rpcprimitive_MC.py
```

## Modifying files
```
git add <Modified files>
git commit -m "Commit message"
git push my-cmssw YourBranchName
```

21 changes: 21 additions & 0 deletions L1Trigger/RPCTriggerPrimitives/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<library file="*.cc" name="L1TriggerRPCTriggerPrimitivesPlugins">
<use name="L1Trigger/RPCTriggerPrimitives"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

this line is causing a warning message:

****WARNING: Invalid tool L1Trigger/RPCTriggerPrimitives. Please fix src/L1Trigger/RPCTriggerPrimitives/plugins/BuildFile.xml file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed...

<use name="FWCore/MessageLogger"/>
<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/Utilities"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/DetId"/>
<use name="DataFormats/MuonDetId"/>
<use name="DataFormats/RPCRecHit"/>
<use name="DataFormats/TrackingRecHit"/>
<use name="CondFormats/RPCObjects"/>
<use name="CondFormats/DataRecord"/>
<use name="Geometry/RPCGeometry"/>
<use name="Geometry/Records"/>
<use name="TrackingTools/TrackRefitter"/>
<flags EDM_PLUGIN="1"/>
</library>


Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RPCTriggerPrimitives producer for RPPRecHits in L1T Level
// Author Alejandro Segura -- Universidad de los Andes

#include "L1TMuonRPCTriggerPrimitivesProducer.h"

L1TMuonRPCTriggerPrimitivesProducer::L1TMuonRPCTriggerPrimitivesProducer(const edm::ParameterSet& iConfig)
: preprocess_pointer_(std::make_unique<PrimitivePreprocess>(iConfig, consumesCollector())) {
produces<RPCRecHitCollection>();
}

L1TMuonRPCTriggerPrimitivesProducer::~L1TMuonRPCTriggerPrimitivesProducer() {}

void L1TMuonRPCTriggerPrimitivesProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
// Create pointers to the collections which will store the new primitive digis
auto Tprimitive_digis = std::make_unique<RPCRecHitCollection>();

preprocess_pointer_->beginRun(iSetup);
preprocess_pointer_->Preprocess(iEvent, iSetup, *Tprimitive_digis);
// Fill the output collections
iEvent.put(std::move(Tprimitive_digis));
}

void L1TMuonRPCTriggerPrimitivesProducer::beginStream(edm::StreamID iID) {}

void L1TMuonRPCTriggerPrimitivesProducer::endStream() {}

// Define this as a plug-in
DEFINE_FWK_MODULE(L1TMuonRPCTriggerPrimitivesProducer);
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef L1Trigger_RPCTriggerPrimitives_L1TMuonRPCTriggerPrimitivesProducer_h
#define L1Trigger_RPCTriggerPrimitives_L1TMuonRPCTriggerPrimitivesProducer_h

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DataFormats/MuonDetId/interface/RPCDetId.h"
#include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"

#include "DataFormats/RPCRecHit/interface/RPCRecHit.h"
#include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"

#include "TVector3.h"

#include "L1Trigger/RPCTriggerPrimitives/plugins/PrimitivePreprocess.h"

// Class declaration

class L1TMuonRPCTriggerPrimitivesProducer : public edm::stream::EDProducer<> {
public:
explicit L1TMuonRPCTriggerPrimitivesProducer(const edm::ParameterSet&);
~L1TMuonRPCTriggerPrimitivesProducer() override;

private:
void beginStream(edm::StreamID) override;
void endStream() override;
void produce(edm::Event& event, const edm::EventSetup& setup) override;

std::unique_ptr<PrimitivePreprocess> preprocess_pointer_;
};

#endif /* #define L1Trigger_RPCTriggerPrimitives_L1TMuonRPCTriggerPrimitivesProducer_h */
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "FWCore/PluginManager/interface/PluginFactory.h"
#include "L1Trigger/RPCTriggerPrimitives/plugins/PrimitiveAlgoFactory.h"

EDM_REGISTER_PLUGINFACTORY(PrimitiveAlgoFactory, "PrimitiveAlgoFactory");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a big problem. The exact same Factory is already registered under a different name:

typedef edmplugin::PluginFactory<RPCRecHitBaseAlgo *(const edm::ParameterSet &)> RPCRecHitAlgoFactory;

One cannot registered two factories with identically signatures under two different names. Only one name will be used by the system which leads to problems loading the plugins.

This factory declaration should go away and the code should just use the existing RPCRecHitAlgoFactory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, I have problems by calling the rechitalgofactory, Does anyone know how can I solve?
L1TMuonRPCTriggerPrimitivesProducer.cc:(.text+0x28e): undefined reference to `edmplugin::PluginFactory<RPCRecHitBaseAlgo* (edm::ParameterSet const&)>::get()'

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have

<use name="RecoLocalMuon/RPCRecHit">

to your BuildFile.xml?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I do, but it does not work.

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem is the package RecoLocalMuon/RPCRecHit creates a plugin not a library and a plugin. Therefore you can't link to it and get the symbol you need. So it looks like files within RecoLocalMuon/RPCRecHit needs to be moved around so that at least RecoLocalMuon/RPCRecHit/src/RPCRecHitAlgoFactory.cc gets compiled into a library which is shared between the two packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

those changes generate similar errors.
tmp/slc7_amd64_gcc700/src/RecoLocalMuon/RPCRecHit/src/RecoLocalMuonRPCRecHit/RPCRecHitBaseAlgo.cc.o: In function RPCRecHitBaseAlgo::reconstruct(RPCRoll const&, RPCDetId const&, std::pair<__gnu_cxx::__normal_iterator<RPCDigi const*, std::vector<RPCDigi, std::allocator<RPCDigi> > >, __gnu_cxx::__normal_iterator<RPCDigi const*, std::vector<RPCDigi, std::allocator<RPCDigi> > > > const&, std::bitset<192ul> const&)': RPCRecHitBaseAlgo.cc:(.text+0x71): undefined reference to RPCClusterizer::doAction(std::pair<__gnu_cxx::__normal_iterator<RPCDigi const*, std::vector<RPCDigi, std::allocator > >, __gnu_cxx::__normal_iterator<RPCDigi const*, std::vector<RPCDigi, std::allocator > > > const&)'

Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't RPCRecHitStandardAlgo.cc one of the files to move out of src/ and into plugins/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, StandardAlgo is now in plugins

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you point us to your code?

@smuzaffar any ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/afs/cern.ch/user/m/masegura/CMSSW_10_6_0/src/RecoLocalMuon/RPCRecHit

9 changes: 9 additions & 0 deletions L1Trigger/RPCTriggerPrimitives/plugins/PrimitiveAlgoFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef L1Trigger_PrimitiveAlgoFactory_H
#define L1Trigger_PrimitiveAlgoFactory_H

#include "FWCore/PluginManager/interface/PluginFactory.h"
#include "RecoLocalMuon/RPCRecHit/interface/RPCRecHitBaseAlgo.h"

typedef edmplugin::PluginFactory<RPCRecHitBaseAlgo *(const edm::ParameterSet &)> PrimitiveAlgoFactory;

#endif
157 changes: 157 additions & 0 deletions L1Trigger/RPCTriggerPrimitives/plugins/PrimitivePreprocess.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include "L1Trigger/RPCTriggerPrimitives/plugins/PrimitivePreprocess.h"

PrimitivePreprocess::PrimitivePreprocess(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iConsumes)
: rpcToken_(iConsumes.consumes<RPCDigiCollection>(iConfig.getParameter<edm::InputTag>("Primitiverechitlabel"))),
processorvector_(),
Mapsource_(iConfig.getParameter<std::string>("Mapsource")),
ApplyLinkBoardCut_(iConfig.getParameter<bool>("ApplyLinkBoardCut")),
LinkBoardCut_(iConfig.getParameter<int>("LinkBoardCut")),
ClusterSizeCut_(iConfig.getParameter<int>("ClusterSizeCut")),
theRPCMaskedStripsObj(nullptr),
theRPCDeadStripsObj(nullptr),
// Get the concrete reconstruction algo from the factory
theAlgorithm{PrimitiveAlgoFactory::get()->create(iConfig.getParameter<std::string>("recAlgo"),
iConfig.getParameter<edm::ParameterSet>("recAlgoConfig"))},
maskSource_(MaskSource::EventSetup),
deadSource_(MaskSource::EventSetup) {
//Get LUT for linkboard map
std::ifstream inputFile(Mapsource_.fullPath().c_str(), std::ios::in);

if (!inputFile) {
throw cms::Exception("No LUT file") << "Error: Linkboard mapping cannot be opened";
exit(1);
}

while (inputFile.good()) {
RPCProcessor::Map_structure temp;
inputFile >> temp.linkboard_ >> temp.linkboard_ID >> temp.chamber1_ >> temp.chamber2_;
Final_MapVector.push_back(temp);
}
Final_MapVector.pop_back();

inputFile.close();

const std::string maskSource = iConfig.getParameter<std::string>("maskSource");

if (maskSource == "File") {
maskSource_ = MaskSource::File;
edm::FileInPath fp1 = iConfig.getParameter<edm::FileInPath>("maskvecfile");
std::ifstream inputFile_1(fp1.fullPath().c_str(), std::ios::in);
if (!inputFile_1) {
std::cerr << "Masked Strips File cannot not be opened" << std::endl;
exit(1);
}
while (inputFile_1.good()) {
RPCMaskedStrips::MaskItem Item;
inputFile_1 >> Item.rawId >> Item.strip;
if (inputFile_1.good())
MaskVec.push_back(Item);
}
inputFile_1.close();
}

const std::string deadSource = iConfig.getParameter<std::string>("deadSource");

if (deadSource == "File") {
deadSource_ = MaskSource::File;
edm::FileInPath fp2 = iConfig.getParameter<edm::FileInPath>("deadvecfile");
std::ifstream inputFile_2(fp2.fullPath().c_str(), std::ios::in);
if (!inputFile_2) {
std::cerr << "Dead Strips File cannot not be opened" << std::endl;
exit(1);
}
while (inputFile_2.good()) {
RPCDeadStrips::DeadItem Item;
inputFile_2 >> Item.rawId >> Item.strip;
if (inputFile_2.good())
DeadVec.push_back(Item);
}
inputFile_2.close();
}

//Closing the input files
}

PrimitivePreprocess::~PrimitivePreprocess() {}

void PrimitivePreprocess::beginRun(const edm::EventSetup& iSetup) {
// Get masked- and dead-strip information
theRPCMaskedStripsObj = std::make_unique<RPCMaskedStrips>();
theRPCDeadStripsObj = std::make_unique<RPCDeadStrips>();

// Getting the masked-strip information
if (maskSource_ == MaskSource::EventSetup) {
edm::ESHandle<RPCMaskedStrips> readoutMaskedStrips;
iSetup.get<RPCMaskedStripsRcd>().get(readoutMaskedStrips);
const RPCMaskedStrips* tmp_obj = readoutMaskedStrips.product();
theRPCMaskedStripsObj->MaskVec = tmp_obj->MaskVec;
delete tmp_obj;
}

else if (maskSource_ == MaskSource::File) {
std::vector<RPCMaskedStrips::MaskItem>::iterator posVec;
for (posVec = MaskVec.begin(); posVec != MaskVec.end(); ++posVec) {
RPCMaskedStrips::MaskItem Item;
Item.rawId = (*posVec).rawId;
Item.strip = (*posVec).strip;
theRPCMaskedStripsObj->MaskVec.push_back(Item);
}
}

// Getting the dead-strip information

if (deadSource_ == MaskSource::EventSetup) {
edm::ESHandle<RPCDeadStrips> readoutDeadStrips;
iSetup.get<RPCDeadStripsRcd>().get(readoutDeadStrips);
const RPCDeadStrips* tmp_obj = readoutDeadStrips.product();
theRPCDeadStripsObj->DeadVec = tmp_obj->DeadVec;
delete tmp_obj;
} else if (deadSource_ == MaskSource::File) {
std::vector<RPCDeadStrips::DeadItem>::iterator posVec;
for (posVec = DeadVec.begin(); posVec != DeadVec.end(); ++posVec) {
RPCDeadStrips::DeadItem Item;
Item.rawId = (*posVec).rawId;
Item.strip = (*posVec).strip;
theRPCDeadStripsObj->DeadVec.push_back(Item);
}
}
}

void PrimitivePreprocess::Preprocess(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
RPCRecHitCollection& primitivedigi) {
//loop over rpcdigis and cluster algorithm

std::map<std::string, std::string> LBName_ChamberID_Map_1;
std::map<std::string, std::string> LBID_ChamberID_Map_1;
std::map<std::string, std::string> LBName_ChamberID_Map_2;
std::map<std::string, std::string> LBID_ChamberID_Map_2;

std::vector<RPCProcessor::Map_structure>::iterator it;
for (it = Final_MapVector.begin(); it != Final_MapVector.end(); it++) {
LBName_ChamberID_Map_1[(*it).chamber1_] = (*it).linkboard_;
LBID_ChamberID_Map_1[(*it).chamber1_] = (*it).linkboard_ID;
if ((*it).chamber2_ != "-") {
LBName_ChamberID_Map_2[(*it).chamber2_] = (*it).linkboard_;
LBID_ChamberID_Map_2[(*it).chamber2_] = (*it).linkboard_ID;
}
}
// map_2 is only necessary for barrel

for (auto& iterator_ : processorvector_) {
iterator_.Process(iEvent,
iSetup,
rpcToken_,
primitivedigi,
theRPCMaskedStripsObj,
theRPCDeadStripsObj,
theAlgorithm,
LBName_ChamberID_Map_1,
LBID_ChamberID_Map_1,
LBName_ChamberID_Map_2,
LBID_ChamberID_Map_2,
ApplyLinkBoardCut_,
LinkBoardCut_,
ClusterSizeCut_);
}
}
71 changes: 71 additions & 0 deletions L1Trigger/RPCTriggerPrimitives/plugins/PrimitivePreprocess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef L1Trigger_RPCTriggerPrimitives_PrimitivePreprocess_h
#define L1Trigger_RPCTriggerPrimitives_PrimitivePreprocess_h

#include "DataFormats/MuonDetId/interface/RPCDetId.h"
#include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
#include "DataFormats/RPCRecHit/interface/RPCRecHit.h"
#include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/PluginManager/interface/PluginFactory.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "CondFormats/RPCObjects/interface/RPCMaskedStrips.h"
#include "CondFormats/RPCObjects/interface/RPCDeadStrips.h"
#include "CondFormats/DataRecord/interface/RPCMaskedStripsRcd.h"
#include "CondFormats/DataRecord/interface/RPCDeadStripsRcd.h"

#include "Geometry/RPCGeometry/interface/RPCRoll.h"
#include "Geometry/RPCGeometry/interface/RPCGeometry.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"

#include "RecoLocalMuon/RPCRecHit/interface/RPCRecHitBaseAlgo.h"

#include "L1Trigger/RPCTriggerPrimitives/plugins/PrimitiveAlgoFactory.h"
#include "L1Trigger/RPCTriggerPrimitives/plugins/RPCProcessor.h"

#include <string>
#include <fstream>
#include <memory>

class PrimitivePreprocess {
public:
explicit PrimitivePreprocess(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iConsumes);

~PrimitivePreprocess();

void beginRun(const edm::EventSetup&);

void Preprocess(const edm::Event& iEvent, const edm::EventSetup& iSetup, RPCRecHitCollection& primitivedigi);

private:
const edm::EDGetTokenT<RPCDigiCollection> rpcToken_;
std::array<RPCProcessor, 1> processorvector_;

edm::FileInPath Mapsource_;
bool ApplyLinkBoardCut_;
int LinkBoardCut_;
int ClusterSizeCut_;

std::vector<RPCProcessor::Map_structure> Final_MapVector;

//masking from rpcrechit module

std::vector<RPCMaskedStrips::MaskItem> MaskVec;
std::vector<RPCDeadStrips::DeadItem> DeadVec;

std::unique_ptr<RPCMaskedStrips> theRPCMaskedStripsObj;
// Object with mask-strips-vector for all the RPC Detectors

std::unique_ptr<RPCDeadStrips> theRPCDeadStripsObj;
// Object with dead-strips-vector for all the RPC Detectors

// The reconstruction algorithm
std::unique_ptr<RPCRecHitBaseAlgo> theAlgorithm;

enum class MaskSource { File, EventSetup } maskSource_, deadSource_;
};
#endif