26 #include "CLHEP/Random/RandFlat.h"
42 label_(ps.getParameter<std::
string>(
"Label")),
43 geometryType_(ps.getParameter<std::
string>(
"GeometryType")),
47 NumberOfBarrelLayers(ps.exists(
"NumPixelBarrel")?ps.getParameter<int>(
"NumPixelBarrel"):3),
48 NumberOfEndcapDisks(ps.exists(
"NumPixelEndcap")?ps.getParameter<int>(
"NumPixelEndcap"):2),
49 theInstLumiScaleFactor(ps.getParameter<double>(
"theInstLumiScaleFactor")),
50 bunchScaleAt25(ps.getParameter<double>(
"bunchScaleAt25")),
52 AddPixelInefficiency(ps.getParameter<bool>(
"AddPixelInefficiencyFromPython")),
53 pixelEff_(ps, AddPixelInefficiency,NumberOfBarrelLayers,NumberOfEndcapDisks)
94 if (AddPixelInefficiency){
98 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix3");
99 if (NumberOfBarrelLayers>=4){thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix4");}
104 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix3");
105 if (NumberOfBarrelLayers>=4){thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix4");}
110 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix3");
111 if (NumberOfBarrelLayers>=4){thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix4");}
116 theLadderEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theLadderEfficiency_BPix3");
117 if ( ((theLadderEfficiency_BPix[0].
size()!=20) || (theLadderEfficiency_BPix[1].
size()!=32) ||
118 (theLadderEfficiency_BPix[2].
size()!=44)) && (NumberOfBarrelLayers==3) )
119 throw cms::Exception(
"Configuration") <<
"Wrong ladder number in efficiency config!";
124 theModuleEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theModuleEfficiency_BPix3");
125 if ( ((theModuleEfficiency_BPix[0].
size()!=4) || (theModuleEfficiency_BPix[1].
size()!=4) ||
126 (theModuleEfficiency_BPix[2].
size()!=4)) && (NumberOfBarrelLayers==3) )
127 throw cms::Exception(
"Configuration") <<
"Wrong module number in efficiency config!";
132 thePUEfficiency[i++] = conf.
getParameter<std::vector<double> >(
"thePUEfficiency_BPix3");
133 if ( ((thePUEfficiency[0].
size()==0) || (thePUEfficiency[1].
size()==0) ||
134 (thePUEfficiency[2].
size()==0)) && (NumberOfBarrelLayers==3) )
135 throw cms::Exception(
"Configuration") <<
"At least one PU efficiency (BPix) number is needed in efficiency config!";
137 if (NumberOfBarrelLayers>=5){
138 if (NumberOfTotLayers>20){
throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";}
141 thePixelColEfficiency[
j-1]=0.999;
142 thePixelEfficiency[
j-1]=0.999;
143 thePixelChipEfficiency[
j-1]=0.999;
148 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_FPix1");
149 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_FPix2");
150 if (NumberOfEndcapDisks>=3){thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_FPix3");}
152 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_FPix1");
153 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_FPix2");
154 if (NumberOfEndcapDisks>=3){thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_FPix3");}
156 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_FPix1");
157 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_FPix2");
158 if (NumberOfEndcapDisks>=3){thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_FPix3");}
160 if (NumberOfEndcapDisks>=4){
161 if (NumberOfTotLayers>20){
throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";}
164 thePixelColEfficiency[
j-1]=0.999;
165 thePixelEfficiency[
j-1]=0.999;
166 thePixelChipEfficiency[
j-1]=0.999;
177 thePUEfficiency[i++] = conf.
getParameter<std::vector<double> >(
"thePUEfficiency_FPix_Inner");
178 thePUEfficiency[i++] = conf.
getParameter<std::vector<double> >(
"thePUEfficiency_FPix_Outer");
179 if ( ((thePUEfficiency[3].
size()==0) || (thePUEfficiency[4].
size()==0)) && (NumberOfEndcapDisks==2) )
180 throw cms::Exception(
"Configuration") <<
"At least one (FPix) PU efficiency number is needed in efficiency config!";
192 LogDebug(
"DataMixingSiPixelMCDigiWorker")<<
"===============> adding MC signals for "<<e.
id();
200 for (; DSViter!=input->end();DSViter++){
203 LogDebug(
"DataMixingSiPixelMCDigiWorker") <<
"Processing DetID " << DSViter->id;
206 uint32_t detID = DSViter->id;
213 for (icopy=begin; icopy!=
end; icopy++) {
228 LogDebug(
"DataMixingSiPixelMCDigiWorker") <<
"\n===============> adding pileups from event "<<ep->
id()<<
" for bunchcrossing "<<bcr;
232 std::shared_ptr<Wrapper<edm::DetSetVector<PixelDigi> >
const> inputPTR =
247 for (; DSViter!=input->
end();DSViter++){
250 LogDebug(
"DataMixingSiPixelMCDigiWorker") <<
"Pileups: Processing DetID " << DSViter->id;
253 uint32_t detID = DSViter->id;
260 SiGlobalIndex::const_iterator itest;
269 for (icopy=begin; icopy!=
end; icopy++) {
280 for (icopy=begin; icopy!=
end; icopy++) {
297 std::vector< edm::DetSet<PixelDigi> > vPixelDigi;
305 for(SiGlobalIndex::const_iterator IDet =
SiHitStorage_.begin();
308 uint32_t detID = IDet->first;
316 int formerPixel = -1;
321 OneDetectorMap::const_iterator iLocalchk;
323 for(OneDetectorMap::const_iterator iLocal = LocalMap.begin();
324 iLocal != LocalMap.end(); ++iLocal) {
326 currentPixel = iLocal->first;
328 if (currentPixel == formerPixel) {
329 ADCSum+=(iLocal->second).
adc();
333 if (ADCSum > 511) ADCSum = 255;
334 else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
336 Signals.insert( std::make_pair(formerPixel, ADCSum));
341 formerPixel = currentPixel;
342 ADCSum = (iLocal->second).
adc();
346 if((++iLocalchk) == LocalMap.end()) {
347 if (ADCSum > 511) ADCSum = 255;
348 else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
349 Signals.insert( std::make_pair(formerPixel, ADCSum));
356 _signal.insert( std::make_pair( detID, Signals));
361 LogInfo(
"DataMixingSiPixelMCDigiWorker") <<
"total # Merged Pixels: " <<
_signal.size() ;
378 for(TrackingGeometry::DetUnitContainer::const_iterator iu =
pDD->detUnits().begin(); iu !=
pDD->detUnits().end(); iu ++){
380 if((*iu)->type().isTrackerPixel()) {
391 if(theSignal.size()>0) {
397 int numRows = topol->
nrows();
402 double pixelEfficiency = 1.0;
403 double columnEfficiency = 1.0;
404 double chipEfficiency = 1.0;
409 int layerIndex=tTopo->
layer(detID);
416 if(numColumns>416)
LogWarning (
"Pixel Geometry") <<
" wrong columns in barrel "<<numColumns;
417 if(numRows>160)
LogWarning (
"Pixel Geometry") <<
" wrong rows in barrel "<<numRows;
421 if (module<=4) module=5-
module;
431 unsigned int panelIndex=tTopo->
pxfPanel(detID);
432 unsigned int moduleIndex=tTopo->
pxfModule(detID);
442 if(numColumns>260 || numRows>160) {
443 if(numColumns>260)
LogWarning (
"Pixel Geometry") <<
" wrong columns in endcaps "<<numColumns;
444 if(numRows>160)
LogWarning (
"Pixel Geometry") <<
" wrong rows in endcaps "<<numRows;
447 if ((panelIndex==1 && (moduleIndex==1 || moduleIndex==2)) || (panelIndex==2 && moduleIndex==1)) {
455 pixelEfficiency = 0.999;
456 columnEfficiency = 0.999;
457 chipEfficiency = 0.999;
463 std::auto_ptr<PixelIndices> pIndexConverter(
new PixelIndices(numColumns,numRows));
468 std::map<int, int, std::less<int> >chips, columns;
469 std::map<int, int, std::less<int> >::iterator
iter;
480 pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
481 int dColInChip = pIndexConverter->DColumn(colROC);
483 int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
486 columns[dColInDet]++;
490 for ( iter = chips.begin(); iter != chips.end() ; iter++ ) {
492 float rand = CLHEP::RandFlat::shoot(engine);
493 if( rand > chipEfficiency ) chips[iter->first]=0;
497 for ( iter = columns.begin(); iter != columns.end() ; iter++ ) {
499 float rand = CLHEP::RandFlat::shoot(engine);
500 if( rand > columnEfficiency ) columns[iter->first]=0;
512 pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
513 int dColInChip = pIndexConverter->DColumn(colROC);
515 int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
518 float rand = CLHEP::RandFlat::shoot(engine);
519 if( chips[chipIndex]==0 || columns[dColInDet]==0
520 || rand>pixelEfficiency ) {
531 vPixelDigi.push_back(SPD);
550 double bunchScale=1.0;
554 for (
unsigned int i=0;
i<ps.size();
i++)
555 if ( ps[
i].getBunchCrossing() == 0 )
559 for (
size_t i=0;
i<5;
i++) {
561 double instlumi_pow=1.;
565 instlumi_pow*=instlumi;
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
std::vector< double > thePUEfficiency[20]
std::multimap< int, PixelDigi > OneDetectorMap
const double bunchScaleAt25
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
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
static std::string const input
signal_map_type::const_iterator signal_map_const_iterator
uint32_t rawId() const
get the raw id
double thePixelColEfficiency[20]
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
const double theInstLumiScaleFactor
DetId geographicalId() const
The label of this GeomDet.
std::map< int, Amplitude, std::less< int > > signal_map_type
Container::value_type value_type
iterator end()
Return the off-the-end iterator.
std::vector< double > theLadderEfficiency_BPix[20]
unsigned int pxfModule(const DetId &id) const
const PixelEfficiencies pixelEff_
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
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &) const =0
Use this engine in event methods.
unsigned int layer(const DetId &id) const
std::string PixelDigiCollectionDM_
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
virtual ~DataMixingSiPixelMCDigiWorker()
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)
tuple size
Write out results.
unsigned int pxfPanel(const DetId &id) const
double thePixelChipEfficiency[20]