27 #include "CLHEP/Random/RandFlat.h" 43 label_(ps.getParameter<
std::
string>(
"Label")),
44 geometryType_(ps.getParameter<
std::
string>(
"GeometryType")),
48 NumberOfBarrelLayers(ps.exists(
"NumPixelBarrel")?ps.getParameter<
int>(
"NumPixelBarrel"):3),
49 NumberOfEndcapDisks(ps.exists(
"NumPixelEndcap")?ps.getParameter<
int>(
"NumPixelEndcap"):2),
97 if (AddPixelInefficiency){
99 conf.
exists(
"thePixelColEfficiency_BPix1") && conf.
exists(
"thePixelColEfficiency_BPix2") && conf.
exists(
"thePixelColEfficiency_BPix3") &&
100 conf.
exists(
"thePixelColEfficiency_FPix1") && conf.
exists(
"thePixelColEfficiency_FPix2") &&
101 conf.
exists(
"thePixelEfficiency_BPix1") && conf.
exists(
"thePixelEfficiency_BPix2") && conf.
exists(
"thePixelEfficiency_BPix3") &&
102 conf.
exists(
"thePixelEfficiency_FPix1") && conf.
exists(
"thePixelEfficiency_FPix2") &&
103 conf.
exists(
"thePixelChipEfficiency_BPix1") && conf.
exists(
"thePixelChipEfficiency_BPix2") && conf.
exists(
"thePixelChipEfficiency_BPix3") &&
104 conf.
exists(
"thePixelChipEfficiency_FPix1") && conf.
exists(
"thePixelChipEfficiency_FPix2");
105 if (NumberOfBarrelLayers==3) FromConfig = FromConfig && conf.
exists(
"theLadderEfficiency_BPix1") && conf.
exists(
"theLadderEfficiency_BPix2") && conf.
exists(
"theLadderEfficiency_BPix3") &&
106 conf.
exists(
"theModuleEfficiency_BPix1") && conf.
exists(
"theModuleEfficiency_BPix2") && conf.
exists(
"theModuleEfficiency_BPix3") &&
107 conf.
exists(
"thePUEfficiency_BPix1") && conf.
exists(
"thePUEfficiency_BPix2") && conf.
exists(
"thePUEfficiency_BPix3") &&
108 conf.
exists(
"theInnerEfficiency_FPix1") && conf.
exists(
"theInnerEfficiency_FPix2") &&
109 conf.
exists(
"theOuterEfficiency_FPix1") && conf.
exists(
"theOuterEfficiency_FPix2") &&
110 conf.
exists(
"thePUEfficiency_FPix_Inner") && conf.
exists(
"thePUEfficiency_FPix_Outer") &&
111 conf.
exists(
"theInstLumiScaleFactor");
112 if (NumberOfBarrelLayers>=4) FromConfig = FromConfig && conf.
exists(
"thePixelColEfficiency_BPix4") &&
113 conf.
exists(
"thePixelEfficiency_BPix4") && conf.
exists(
"thePixelChipEfficiency_BPix4");
114 if (NumberOfEndcapDisks>=3) FromConfig = FromConfig && conf.
exists(
"thePixelColEfficiency_FPix4") &&
115 conf.
exists(
"thePixelEfficiency_FPix3") && conf.
exists(
"thePixelChipEfficiency_FPix3");
117 LogInfo (
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the config file.\n";
118 theInstLumiScaleFactor = conf.
getParameter<
double>(
"theInstLumiScaleFactor");
120 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix1");
121 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix2");
122 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix3");
123 if (NumberOfBarrelLayers>=4){thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix4");}
126 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix1");
127 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix2");
128 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix3");
129 if (NumberOfBarrelLayers>=4){thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix4");}
132 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix1");
133 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix2");
134 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix3");
135 if (NumberOfBarrelLayers>=4){thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix4");}
137 if (NumberOfBarrelLayers==3){
139 theLadderEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theLadderEfficiency_BPix1");
140 theLadderEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theLadderEfficiency_BPix2");
141 theLadderEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theLadderEfficiency_BPix3");
142 if ( ((theLadderEfficiency_BPix[0].
size()!=20) || (theLadderEfficiency_BPix[1].
size()!=32) ||
143 (theLadderEfficiency_BPix[2].
size()!=44)) && (NumberOfBarrelLayers==3) )
144 throw cms::Exception(
"Configuration") <<
"Wrong ladder number in efficiency config!";
147 theModuleEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theModuleEfficiency_BPix1");
148 theModuleEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theModuleEfficiency_BPix2");
149 theModuleEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theModuleEfficiency_BPix3");
150 if ( ((theModuleEfficiency_BPix[0].
size()!=4) || (theModuleEfficiency_BPix[1].
size()!=4) ||
151 (theModuleEfficiency_BPix[2].
size()!=4)) && (NumberOfBarrelLayers==3) )
152 throw cms::Exception(
"Configuration") <<
"Wrong module number in efficiency config!";
154 thePUEfficiency.push_back(conf.
getParameter<std::vector<double> >(
"thePUEfficiency_BPix1"));
155 thePUEfficiency.push_back(conf.
getParameter<std::vector<double> >(
"thePUEfficiency_BPix2"));
156 thePUEfficiency.push_back(conf.
getParameter<std::vector<double> >(
"thePUEfficiency_BPix3"));
157 if ( ((thePUEfficiency[0].
empty()) || (thePUEfficiency[1].
empty()) ||
158 (thePUEfficiency[2].
empty())) && (NumberOfBarrelLayers==3) )
159 throw cms::Exception(
"Configuration") <<
"At least one PU efficiency (BPix) number is needed in efficiency config!";
162 if (NumberOfBarrelLayers>=5){
163 if (NumberOfTotLayers>20){
throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";}
166 thePixelColEfficiency[j-1]=0.999;
167 thePixelEfficiency[j-1]=0.999;
168 thePixelChipEfficiency[j-1]=0.999;
173 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_FPix1");
174 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_FPix2");
175 if (NumberOfEndcapDisks>=3){thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_FPix3");}
177 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_FPix1");
178 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_FPix2");
179 if (NumberOfEndcapDisks>=3){thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_FPix3");}
181 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_FPix1");
182 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_FPix2");
183 if (NumberOfEndcapDisks>=3){thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_FPix3");}
185 if (NumberOfEndcapDisks>=4){
186 if (NumberOfTotLayers>20){
throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";}
189 thePixelColEfficiency[j-1]=0.999;
190 thePixelEfficiency[j-1]=0.999;
191 thePixelChipEfficiency[j-1]=0.999;
195 if (NumberOfBarrelLayers==3){
197 theInnerEfficiency_FPix[i++] = conf.
getParameter<
double>(
"theInnerEfficiency_FPix1");
198 theInnerEfficiency_FPix[i++] = conf.
getParameter<
double>(
"theInnerEfficiency_FPix2");
200 theOuterEfficiency_FPix[i++] = conf.
getParameter<
double>(
"theOuterEfficiency_FPix1");
201 theOuterEfficiency_FPix[i++] = conf.
getParameter<
double>(
"theOuterEfficiency_FPix2");
202 thePUEfficiency.push_back(conf.
getParameter<std::vector<double> >(
"thePUEfficiency_FPix_Inner"));
203 thePUEfficiency.push_back(conf.
getParameter<std::vector<double> >(
"thePUEfficiency_FPix_Outer"));
204 if ( ((thePUEfficiency[3].
empty()) || (thePUEfficiency[4].
empty())) && (NumberOfEndcapDisks==2) )
205 throw cms::Exception(
"Configuration") <<
"At least one (FPix) PU efficiency number is needed in efficiency config!";
206 pu_scale.resize(thePUEfficiency.size());
209 else LogInfo (
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the database.\n";
228 const std::map<uint32_t, double>& PixelGeomFactorsDB = SiPixelDynamicInefficiency->
getPixelGeomFactors();
229 const std::map<uint32_t, double>& ColGeomFactorsDB = SiPixelDynamicInefficiency->
getColGeomFactors();
230 const std::map<uint32_t, double>& ChipGeomFactorsDB = SiPixelDynamicInefficiency->
getChipGeomFactors();
231 const std::map<uint32_t, std::vector<double> >& PUFactors = SiPixelDynamicInefficiency->
getPUFactors();
232 std::vector<uint32_t > DetIdmasks = SiPixelDynamicInefficiency->
getDetIdmasks();
235 for(
const auto& it_module : geom->
detUnits()) {
236 if( dynamic_cast<PixelGeomDetUnit const*>(it_module)==
nullptr)
continue;
237 const DetId detid = it_module->geographicalId();
238 uint32_t rawid = detid.
rawId();
239 PixelGeomFactors[rawid] = 1;
240 ColGeomFactors[rawid] = 1;
241 ChipGeomFactors[rawid] = 1;
242 for (
auto db_factor : PixelGeomFactorsDB)
if (
matches(detid,
DetId(db_factor.first), DetIdmasks)) PixelGeomFactors[rawid] *= db_factor.second;
243 for (
auto db_factor : ColGeomFactorsDB)
if (
matches(detid,
DetId(db_factor.first), DetIdmasks)) ColGeomFactors[rawid] *= db_factor.second;
244 for (
auto db_factor : ChipGeomFactorsDB)
if (
matches(detid,
DetId(db_factor.first), DetIdmasks)) ChipGeomFactors[rawid] *= db_factor.second;
250 for (
auto factor : PUFactors) {
252 for(
const auto& it_module : geom->
detUnits()) {
253 if( dynamic_cast<PixelGeomDetUnit const*>(it_module)==
nullptr)
continue;
254 const DetId detid = it_module->geographicalId();
255 if (!
matches(detid, db_id, DetIdmasks))
continue;
256 if (iPU.count(detid.
rawId())) {
257 throw cms::Exception(
"Database")<<
"Multiple db_ids match to same module in SiPixelDynamicInefficiency DB Object";
262 thePUEfficiency.push_back(factor.second);
265 pu_scale.resize(thePUEfficiency.size());
270 for (
size_t i=0;
i<DetIdmasks.size(); ++
i) {
285 LogDebug(
"DataMixingSiPixelMCDigiWorker")<<
"===============> adding MC signals for "<<e.
id();
293 for (; DSViter!=input->end();DSViter++){
296 LogDebug(
"DataMixingSiPixelMCDigiWorker") <<
"Processing DetID " << DSViter->id;
299 uint32_t detID = DSViter->id;
306 for (icopy=begin; icopy!=
end; icopy++) {
321 LogDebug(
"DataMixingSiPixelMCDigiWorker") <<
"\n===============> adding pileups from event "<<ep->
id()<<
" for bunchcrossing "<<bcr;
325 std::shared_ptr<Wrapper<edm::DetSetVector<PixelDigi> >
const> inputPTR =
340 for (; DSViter!=input->
end();DSViter++){
343 LogDebug(
"DataMixingSiPixelMCDigiWorker") <<
"Pileups: Processing DetID " << DSViter->id;
346 uint32_t detID = DSViter->id;
353 SiGlobalIndex::const_iterator itest;
362 for (icopy=begin; icopy!=
end; icopy++) {
373 for (icopy=begin; icopy!=
end; icopy++) {
390 std::vector< edm::DetSet<PixelDigi> > vPixelDigi;
398 for(SiGlobalIndex::const_iterator IDet =
SiHitStorage_.begin();
401 uint32_t detID = IDet->first;
409 int formerPixel = -1;
414 OneDetectorMap::const_iterator iLocalchk;
416 for(OneDetectorMap::const_iterator iLocal = LocalMap.begin();
417 iLocal != LocalMap.end(); ++iLocal) {
419 currentPixel = iLocal->first;
421 if (currentPixel == formerPixel) {
422 ADCSum+=(iLocal->second).
adc();
426 if (ADCSum > 511) ADCSum = 255;
427 else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
429 Signals.insert( std::make_pair(formerPixel, ADCSum));
434 formerPixel = currentPixel;
435 ADCSum = (iLocal->second).
adc();
439 if((++iLocalchk) == LocalMap.end()) {
440 if (ADCSum > 511) ADCSum = 255;
441 else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
442 Signals.insert( std::make_pair(formerPixel, ADCSum));
449 _signal.insert( std::make_pair( detID, Signals));
454 LogInfo(
"DataMixingSiPixelMCDigiWorker") <<
"total # Merged Pixels: " <<
_signal.size() ;
478 if(iu->type().isTrackerPixel()) {
489 if(!theSignal.empty()) {
495 int numRows = topol->
nrows();
500 double pixelEfficiency = 1.0;
501 double columnEfficiency = 1.0;
502 double chipEfficiency = 1.0;
509 int layerIndex=tTopo->
layer(detID);
516 if(numColumns>416)
LogWarning (
"Pixel Geometry") <<
" wrong columns in barrel "<<numColumns;
517 if(numRows>160)
LogWarning (
"Pixel Geometry") <<
" wrong rows in barrel "<<numRows;
521 if (module<=4) module=5-
module;
531 unsigned int panelIndex=tTopo->
pxfPanel(detID);
532 unsigned int moduleIndex=tTopo->
pxfModule(detID);
542 if(numColumns>260 || numRows>160) {
543 if(numColumns>260)
LogWarning (
"Pixel Geometry") <<
" wrong columns in endcaps "<<numColumns;
544 if(numRows>160)
LogWarning (
"Pixel Geometry") <<
" wrong rows in endcaps "<<numRows;
547 if ((panelIndex==1 && (moduleIndex==1 || moduleIndex==2)) || (panelIndex==2 && moduleIndex==1)) {
555 pixelEfficiency = 0.999;
556 columnEfficiency = 0.999;
557 chipEfficiency = 0.999;
566 LogDebug (
"Pixel Digitizer") <<
" enter pixel_inefficiency " << pixelEfficiency <<
" " 567 << columnEfficiency <<
" " << chipEfficiency;
572 std::unique_ptr<PixelIndices> pIndexConverter(
new PixelIndices(numColumns,numRows));
578 std::map<int, int, std::less<int> >chips,
columns;
579 std::map<int, int, std::less<int> >::iterator iter;
590 pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
591 int dColInChip = pIndexConverter->DColumn(colROC);
593 int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
596 columns[dColInDet]++;
600 for ( iter = chips.begin(); iter != chips.end() ; iter++ ) {
602 float rand = CLHEP::RandFlat::shoot(engine);
603 if( rand > chipEfficiency ) chips[iter->first]=0;
607 for ( iter = columns.begin(); iter != columns.end() ; iter++ ) {
609 float rand = CLHEP::RandFlat::shoot(engine);
610 if( rand > columnEfficiency ) columns[iter->first]=0;
622 pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
623 int dColInChip = pIndexConverter->DColumn(colROC);
625 int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
628 float rand = CLHEP::RandFlat::shoot(engine);
629 if( chips[chipIndex]==0 || columns[dColInDet]==0
630 || rand>pixelEfficiency ) {
643 vPixelDigi.push_back(SPD);
666 for (
unsigned int i=0;
i<ps.size();
i++)
667 if ( ps[
i].getBunchCrossing() == 0 )
673 double instlumi_pow=1.;
677 instlumi_pow*=instlumi;
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
virtual int nrows() const =0
void init_DynIneffDB(const edm::EventSetup &, const unsigned int &)
std::multimap< int, PixelDigi > OneDetectorMap
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
SiGlobalIndex SiHitStorage_
void push_back(const T &t)
double theInnerEfficiency_FPix[20]
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
signal_map_type::iterator signal_map_iterator
std::vector< double > theModuleEfficiency_BPix[20]
const int NumberOfEndcapDisks
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiToken_
EventID const & id() const
unsigned int pxbLadder(const DetId &id) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
const std::string geometryType_
virtual void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
unsigned int pxbModule(const DetId &id) const
double theInstLumiScaleFactor
std::map< uint32_t, double > PixelGeomFactors
const bool AddPixelInefficiency
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
static std::string const input
signal_map_type::const_iterator signal_map_const_iterator
uint32_t rawId() const
get the raw id
bool matches(const DetId &, const DetId &, const std::vector< uint32_t > &)
const std::vector< uint32_t > getDetIdmasks() const
Container::value_type value_type
bunchspace
in terms of 25 ns
double thePixelColEfficiency[20]
edm::ESHandle< SiPixelDynamicInefficiency > SiPixelDynamicInefficiency_
DetId geographicalId() const
The label of this GeomDet.
std::map< int, Amplitude, std::less< int > > signal_map_type
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
PixelEfficiencies pixelEff_
iterator end()
Return the off-the-end iterator.
std::vector< double > theLadderEfficiency_BPix[20]
std::map< uint32_t, double > ChipGeomFactors
unsigned int pxfModule(const DetId &id) const
void init_from_db(const edm::ESHandle< TrackerGeometry > &, const edm::ESHandle< SiPixelDynamicInefficiency > &)
std::map< uint32_t, double > ColGeomFactors
void setPileupInfo(const std::vector< PileupSummaryInfo > &ps, const int &bs)
static std::pair< int, int > channelToPixel(int ch)
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
edm::InputTag pixeldigi_collectionSig_
const int NumberOfBarrelLayers
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
unsigned int layer(const DetId &id) const
std::string PixelDigiCollectionDM_
std::vector< double > pu_scale
double gettheInstLumiScaleFactor() const
virtual int ncolumns() const =0
void addSiPixelPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
double theOuterEfficiency_FPix[20]
StreamID streamID() const
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiPToken_
const std::map< unsigned int, std::vector< double > > & getPUFactors() const
double thePixelEfficiency[20]
iterator begin()
Return an iterator to the first DetSet.
void addSiPixelSignals(const edm::Event &e)
PixelEfficiencies(const edm::ParameterSet &conf, bool AddPixelInefficiency, int NumberOfBarrelLayers, int NumberOfEndcapDisks)
edm::InputTag pixeldigi_collectionPile_
collection_type::const_iterator const_iterator
collection_type::const_iterator const_iterator
Detector det() const
get the detector field from this detid
virtual ~DataMixingSiPixelMCDigiWorker()
std::map< uint32_t, size_t > iPU
virtual SubDetector subDetector() const
Which subdetector.
edm::ESHandle< TrackerGeometry > pDD
void putSiPixel(edm::Event &e, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > &ps, int &bs)
T const * product() const
std::vector< std::vector< double > > thePUEfficiency
unsigned int pxfPanel(const DetId &id) const
const std::map< unsigned int, double > & getColGeomFactors() const
const std::map< unsigned int, double > & getPixelGeomFactors() const
double thePixelChipEfficiency[20]
const std::map< unsigned int, double > & getChipGeomFactors() const