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),
53 AddPixelInefficiency(ps.getParameter<bool>(
"AddPixelInefficiency")),
54 pixelEff_(ps, AddPixelInefficiency,NumberOfBarrelLayers,NumberOfEndcapDisks)
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");
113 conf.
exists(
"thePixelEfficiency_BPix4") && conf.
exists(
"thePixelChipEfficiency_BPix4");
115 conf.
exists(
"thePixelEfficiency_FPix3") && conf.
exists(
"thePixelChipEfficiency_FPix3");
117 LogInfo (
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the config file.\n";
122 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix3");
123 if (NumberOfBarrelLayers>=4){thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix4");}
128 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix3");
129 if (NumberOfBarrelLayers>=4){thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix4");}
134 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix3");
135 if (NumberOfBarrelLayers>=4){thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix4");}
137 if (NumberOfBarrelLayers==3){
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!";
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!";
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){
205 throw cms::Exception(
"Configuration") <<
"At least one (FPix) PU efficiency number is needed in efficiency config!";
209 else LogInfo (
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the database.\n";
227 theInstLumiScaleFactor = SiPixelDynamicInefficiency->gettheInstLumiScaleFactor();
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(TrackerGeometry::DetUnitContainer::const_iterator it_module = geom->detUnits().begin(); it_module != geom->detUnits().end(); it_module++) {
236 if( dynamic_cast<PixelGeomDetUnit const*>((*it_module))==0)
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(TrackerGeometry::DetUnitContainer::const_iterator it_module = geom->detUnits().begin(); it_module != geom->detUnits().end(); it_module++) {
253 if( dynamic_cast<PixelGeomDetUnit const*>((*it_module))==0)
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() ;
476 for(TrackingGeometry::DetUnitContainer::const_iterator iu =
pDD->detUnits().begin(); iu !=
pDD->detUnits().end(); iu ++){
478 if((*iu)->type().isTrackerPixel()) {
489 if(theSignal.size()>0) {
495 int numRows = topol->
nrows();
500 double pixelEfficiency = 1.0;
501 double columnEfficiency = 1.0;
502 double chipEfficiency = 1.0;
508 int layerIndex=tTopo->
layer(detID);
515 if(numColumns>416)
LogWarning (
"Pixel Geometry") <<
" wrong columns in barrel "<<numColumns;
516 if(numRows>160)
LogWarning (
"Pixel Geometry") <<
" wrong rows in barrel "<<numRows;
520 if (module<=4) module=5-
module;
530 unsigned int panelIndex=tTopo->
pxfPanel(detID);
531 unsigned int moduleIndex=tTopo->
pxfModule(detID);
541 if(numColumns>260 || numRows>160) {
542 if(numColumns>260)
LogWarning (
"Pixel Geometry") <<
" wrong columns in endcaps "<<numColumns;
543 if(numRows>160)
LogWarning (
"Pixel Geometry") <<
" wrong rows in endcaps "<<numRows;
546 if ((panelIndex==1 && (moduleIndex==1 || moduleIndex==2)) || (panelIndex==2 && moduleIndex==1)) {
554 pixelEfficiency = 0.999;
555 columnEfficiency = 0.999;
556 chipEfficiency = 0.999;
565 LogDebug (
"Pixel Digitizer") <<
" enter pixel_inefficiency " << pixelEfficiency <<
" "
566 << columnEfficiency <<
" " << chipEfficiency;
571 std::auto_ptr<PixelIndices> pIndexConverter(
new PixelIndices(numColumns,numRows));
577 std::map<int, int, std::less<int> >chips,
columns;
578 std::map<int, int, std::less<int> >::iterator iter;
589 pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
590 int dColInChip = pIndexConverter->DColumn(colROC);
592 int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
595 columns[dColInDet]++;
599 for ( iter = chips.begin(); iter != chips.end() ; iter++ ) {
601 float rand = CLHEP::RandFlat::shoot(engine);
602 if( rand > chipEfficiency ) chips[iter->first]=0;
606 for ( iter = columns.begin(); iter != columns.end() ; iter++ ) {
608 float rand = CLHEP::RandFlat::shoot(engine);
609 if( rand > columnEfficiency ) columns[iter->first]=0;
621 pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
622 int dColInChip = pIndexConverter->DColumn(colROC);
624 int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
627 float rand = CLHEP::RandFlat::shoot(engine);
628 if( chips[chipIndex]==0 || columns[dColInDet]==0
629 || rand>pixelEfficiency ) {
640 vPixelDigi.push_back(SPD);
663 for (
unsigned int i=0;
i<ps.size();
i++)
664 if ( ps[
i].getBunchCrossing() == 0 )
670 double instlumi_pow=1.;
674 instlumi_pow*=instlumi;
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
void init_DynIneffDB(const edm::EventSetup &, const unsigned int &)
std::multimap< int, PixelDigi > OneDetectorMap
SiGlobalIndex SiHitStorage_
void push_back(const T &t)
double theInnerEfficiency_FPix[20]
virtual int ncolumns() const =0
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
virtual int nrows() const =0
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 > &)
Container::value_type value_type
double thePixelColEfficiency[20]
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
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.
T const * product() const
edm::InputTag pixeldigi_collectionSig_
const int NumberOfBarrelLayers
unsigned int layer(const DetId &id) const
std::string PixelDigiCollectionDM_
std::vector< double > pu_scale
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_
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)
std::vector< std::vector< double > > thePUEfficiency
tuple size
Write out results.
unsigned int pxfPanel(const DetId &id) const
double thePixelChipEfficiency[20]