CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTBDigiProducer.cc
Go to the documentation of this file.
1 
22 
23 
25 {
26 
28 
29  EBdigiCollection_ = params.getParameter<std::string>("EBdigiCollection");
30  EEdigiCollection_ = params.getParameter<std::string>("EEdigiCollection");
31 
32  const std::string hitsProducer (
33  params.getParameter<std::string>("hitsProducer") ) ;
34 
35  m_barrelHitsName = hitsProducer + "EcalHitsEB" ;
36  m_endcapHitsName = hitsProducer + "EcalHitsEE" ;
37 
38  produces<EBDigiCollection>( EBdigiCollection_ );
39  produces<EEDigiCollection>( EEdigiCollection_ );
40 
41  produces<EcalTBTDCRawInfo>(); //For TB
42 
43  // initialize the default valuer for hardcoded parameters and the EB/EE shape
44 
45  bool addNoise = params.getParameter<bool>("doNoise");
46  double simHitToPhotoelectronsBarrel = params.getParameter<double>("simHitToPhotoelectronsBarrel");
47  double simHitToPhotoelectronsEndcap = params.getParameter<double>("simHitToPhotoelectronsEndcap");
48  double photoelectronsToAnalogBarrel = params.getParameter<double>("photoelectronsToAnalogBarrel");
49  double photoelectronsToAnalogEndcap = params.getParameter<double>("photoelectronsToAnalogEndcap");
50  double samplingFactor = params.getParameter<double>("samplingFactor");
51  double timePhase = params.getParameter<double>("timePhase");
52  int readoutFrameSize = params.getParameter<int>("readoutFrameSize");
53  int binOfMaximum = params.getParameter<int>("binOfMaximum");
54  bool doPhotostatistics = params.getParameter<bool>("doPhotostatistics");
55  bool syncPhase = params.getParameter<bool>("syncPhase");
56 
57  // possible phase shift for asynchronous trigger (e.g. test-beam)
58 
59  doPhaseShift = !syncPhase; //For TB
60  thisPhaseShift = 1.; //For TB
61 
62  theParameterMap = new EcalSimParameterMap(simHitToPhotoelectronsBarrel, simHitToPhotoelectronsEndcap,
63  photoelectronsToAnalogBarrel, photoelectronsToAnalogEndcap,
64  samplingFactor, timePhase, readoutFrameSize, binOfMaximum,
65  doPhotostatistics, syncPhase);
66 
67 
70 
71  EcalCorrMatrix thisMatrix;
72 
73  std::vector<double> corrNoiseMatrix = params.getParameter< std::vector<double> >("CorrelatedNoiseMatrix");
74  if ( corrNoiseMatrix.size() == (unsigned int)(readoutFrameSize*readoutFrameSize) ) {
75  for ( int row = 0 ; row < readoutFrameSize; ++row ) {
76  for ( int column = 0 ; column < readoutFrameSize; ++column ) {
77  int index = column + readoutFrameSize*row;
78  thisMatrix(row,column) = corrNoiseMatrix[index];
79  }
80  }
81  }
82  theNoiseMatrix = new EcalCorrMatrix(thisMatrix);
83 
85 
86  theCoder = new EcalCoder(addNoise, theCorrNoise);
87  bool applyConstantTerm = params.getParameter<bool>("applyConstantTerm");
88  double rmsConstantTerm = params.getParameter<double> ("ConstantTerm");
89  theElectronicsSim = new EcalElectronicsSim(theParameterMap, theCoder, applyConstantTerm, rmsConstantTerm);
90 
91 
93  theElectronicsSim,
94  addNoise );
95 
97  theElectronicsSim,
98  addNoise );
99 
100 
101  // not containment corrections
102  EBs25notCont = params.getParameter<double>("EBs25notContainment");
103  EEs25notCont = params.getParameter<double>("EEs25notContainment");
104 
105 //For TB --------------------------------------
106 
108 
109  typedef std::vector< edm::ParameterSet > Parameters;
110  Parameters ranges=params.getParameter<Parameters>("tdcRanges");
111  for(Parameters::iterator itRanges = ranges.begin(); itRanges != ranges.end(); ++itRanges)
112  {
114  aRange.runRanges.first = itRanges->getParameter<int>("startRun");
115  aRange.runRanges.second = itRanges->getParameter<int>("endRun");
116  aRange.tdcMin = itRanges->getParameter< std::vector<double> >("tdcMin");
117  aRange.tdcMax = itRanges->getParameter< std::vector<double> >("tdcMax");
118  tdcRanges.push_back(aRange);
119  }
120 
121  use2004OffsetConvention_ = params.getUntrackedParameter< bool >("use2004OffsetConvention",false);
122 
123  ecalTBInfoLabel = params.getUntrackedParameter<std::string>("EcalTBInfoLabel","SimEcalTBG4Object");
124  doReadout = params.getParameter<bool>("doReadout");
125 
126  theTBReadout = new EcalTBReadout(ecalTBInfoLabel);
127 
128  tunePhaseShift = params.getParameter<double>("tunePhaseShift");
129 
130 //For TB --------------------------------------
131 }
132 
133 
135 {
136  if (theParameterMap) { delete theParameterMap; }
137  if (theEBResponse) { delete theEBResponse; }
138  if (theEEResponse) { delete theEEResponse; }
139  if (theCorrNoise) { delete theCorrNoise; }
140  if (theNoiseMatrix) { delete theNoiseMatrix; }
141  if (theCoder) { delete theCoder; }
142  if (theElectronicsSim){ delete theElectronicsSim; }
143  if (theBarrelDigitizer){ delete theBarrelDigitizer; }
144  if (theEndcapDigitizer){ delete theEndcapDigitizer; }
145 }
146 
148  const edm::EventSetup& eventSetup )
149 {
150  // Step A: Get Inputs
151 
152 //For TB ----------------
153  edm::ESHandle<CaloGeometry> hGeometry ;
154  eventSetup.get<CaloGeometryRecord>().get( hGeometry ) ;
156  hGeometry->getSubdetectorGeometry( DetId::Ecal, EcalBarrel ) ) ;
158  hGeometry->getSubdetectorGeometry( DetId::Ecal, EcalEndcap ) ) ;
159 
160  // takes no time because gives back const ref
161  const std::vector<DetId>& theBarrelDets (
162  hGeometry->getValidDetIds(DetId::Ecal, EcalBarrel) ) ;
163 // const std::vector<DetId>& theEndcapDets (
164 // hGeometry->getValidDetIds(DetId::Ecal, EcalEndcap) ) ;
165 
166 // theBarrelDigitizer->setDetIds( theBarrelDets ) ;
167 // theEndcapDigitizer->setDetIds( theEndcapDets ) ;
168  theTBReadout ->setDetIds( theBarrelDets ) ;
169 
170 //For TB ----------------
171 
172  checkCalibrations(eventSetup);
173 
174  // Get input
175  edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
176  event.getByLabel( "mix", m_barrelHitsName, crossingFrame ) ;
177 
178  MixCollection<PCaloHit>* EBHits ( crossingFrame.isValid() ?
179  new MixCollection<PCaloHit>( crossingFrame.product() ) : 0 ) ;
180 
181  const bool isEB ( 0 != EBHits &&
182  0 != EBHits->size() ) ;
183 
184  event.getByLabel( "mix", m_endcapHitsName, crossingFrame ) ;
185  MixCollection<PCaloHit>* EEHits ( crossingFrame.isValid() ?
186  new MixCollection<PCaloHit>( crossingFrame.product() ) : 0 ) ;
187 
188  const bool isEE ( 0 != EEHits &&
189  0 != EEHits->size() ) ;
190 
191 //For TB ----------------------------------------
192  std::auto_ptr<EcalTBTDCRawInfo> TDCproduct(new EcalTBTDCRawInfo(1));
193  if( doPhaseShift )
194  {
195  edm::Handle<PEcalTBInfo> theEcalTBInfo ;
196  event.getByLabel( ecalTBInfoLabel, theEcalTBInfo ) ;
197  thisPhaseShift = theEcalTBInfo->phaseShift();
198 
199  DetId detId( DetId::Ecal, 1 ) ;
200  setPhaseShift( detId );
201 
202  fillTBTDCRawInfo( *TDCproduct ) ; // fill the TDC info in the event
203 
204  }
205 //For TB ----------------------------------------
206 
207  // Step B: Create empty output and then fill it
208  std::auto_ptr<EBDigiCollection> barrelResult( new EBDigiCollection() ) ;
209  std::auto_ptr<EEDigiCollection> endcapResult( new EEDigiCollection() ) ;
210 
211  if ( isEB )
212  {
213  std::auto_ptr<MixCollection<PCaloHit> > barrelHits( EBHits );
214  theBarrelDigitizer->run( *barrelHits, *barrelResult ) ;
215  edm::LogInfo("DigiInfo") << "EB Digis: " << barrelResult->size();
216  std::cout << "EB Digis: " << barrelResult->size()<<std::endl;
217 
218 /*
219  CaloDigiCollectionSorter sorter(5) ;
220 
221  std::vector<EBDataFrame> sortedDigisEB = sorter.sortedVector(*barrelResult);
222  LogDebug("EcalDigi") << "Top 10 EB digis";
223  std::cout<< "Top 10 EB digis\n";
224  for(int i = 0; i < std::min(10,(int) sortedDigisEB.size()); ++i)
225  {
226  LogDebug("EcalDigi") << sortedDigisEB[i];
227  std::cout << sortedDigisEB[i]<<"\n";
228  }
229  std::cout<< std::endl ;
230 */
231  }
232 
233  if( isEE )
234  {
235  std::auto_ptr<MixCollection<PCaloHit> > endcapHits( EEHits );
236  theEndcapDigitizer->run( *endcapHits, *endcapResult ) ;
237  edm::LogInfo("EcalDigi") << "EE Digis: " << endcapResult->size();
238  std::cout << "EE Digis: " << endcapResult->size()<<std::endl;
239  }
240 
241  //For TB -------------------------------------------
242  // perform the TB readout if required,
243  // otherwise simply fill the proper object
244 
245  std::auto_ptr<EBDigiCollection> barrelReadout( new EBDigiCollection() ) ;
246  if ( doReadout )
247  {
249  *theTTmap,
250  *barrelResult,
251  *barrelReadout);
252  }
253  else
254  {
255  barrelResult->swap(*barrelReadout);
256  }
257 
258  // Step D: Put outputs into event
259 //TB event.put(barrelResult, EBdigiCollection_);
260  event.put( barrelReadout, EBdigiCollection_ ) ;
261  event.put( endcapResult, EEdigiCollection_ ) ;
262  event.put( TDCproduct ) ;
263 
264 //For TB -------------------------------------------
265 }
266 
267 
269 {
270 
271  // Pedestals from event setup
272 
274  eventSetup.get<EcalPedestalsRcd>().get( dbPed );
275  const EcalPedestals* thePedestals=dbPed.product();
276 
277  theCoder->setPedestals( thePedestals );
278 
279  // Ecal Intercalibration Constants
281  eventSetup.get<EcalIntercalibConstantsMCRcd>().get(pIcal);
282  const EcalIntercalibConstantsMC *ical = pIcal.product();
283 
285 
286  // ADC -> GeV Scale
288  eventSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
289  const EcalADCToGeVConstant* agc = pAgc.product();
290 
291  // Gain Ratios
293  eventSetup.get<EcalGainRatiosRcd>().get(pRatio);
294  const EcalGainRatios* gr = pRatio.product();
295 
296  theCoder->setGainRatios( gr );
297 
298  EcalMGPAGainRatio * defaultRatios = new EcalMGPAGainRatio();
299 
300  double theGains[theCoder->NGAINS+1];
301  theGains[0] = 0.;
302  theGains[3] = 1.;
303  theGains[2] = defaultRatios->gain6Over1() ;
304  theGains[1] = theGains[2]*(defaultRatios->gain12Over6()) ;
305 
306  LogDebug("EcalDigi") << " Gains: " << "\n" << " g1 = " << theGains[1] << "\n" << " g2 = " << theGains[2] << "\n" << " g3 = " << theGains[3];
307 
308  delete defaultRatios;
309 
310  const double EBscale = (agc->getEBValue())*theGains[1]*(theCoder->MAXADC)*EBs25notCont;
311  LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEBValue() << "\n" << " notCont = " << EBs25notCont << "\n" << " saturation for EB = " << EBscale << ", " << EBs25notCont;
312  const double EEscale = (agc->getEEValue())*theGains[1]*(theCoder->MAXADC)*EEs25notCont;
313  LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEEValue() << "\n" << " notCont = " << EEs25notCont << "\n" << " saturation for EB = " << EEscale << ", " << EEs25notCont;
314  theCoder->setFullScaleEnergy( EBscale , EEscale );
315 
316 }
317 
318 /* //TB
319 void EcalTBDigiProducer::checkGeometry(const edm::EventSetup & eventSetup)
320 {
321  // TODO find a way to avoid doing this every event
322  edm::ESHandle<CaloGeometry> hGeometry;
323  eventSetup.get<CaloGeometryRecord>().get(hGeometry);
324 
325  const CaloGeometry * pGeometry = &*hGeometry;
326 
327  // see if we need to update
328  if(pGeometry != theGeometry) {
329  theGeometry = pGeometry;
330  updateGeometry();
331  }
332 }
333 
334 void EcalTBDigiProducer::updateGeometry() {
335  theEcalResponse->setGeometry(theGeometry);
336 //TB theESResponse->setGeometry(theGeometry);
337 
338  const std::vector<DetId>& theBarrelDets = theGeometry->getValidDetIds(DetId::Ecal, EcalBarrel);
339  const std::vector<DetId>& theEndcapDets = theGeometry->getValidDetIds(DetId::Ecal, EcalEndcap);
340 //TB const std::vector<DetId>& theESDets = theGeometry->getValidDetIds(DetId::Ecal, EcalPreshower);
341 
342  edm::LogInfo("EcalDigi") << "deb geometry: " << "\n"
343  << "\t barrel: " << theBarrelDets.size () << "\n"
344  << "\t endcap: " << theEndcapDets.size () << "\n";
345 //TB << "\t preshower: " << theESDets.size();
346 
347  theBarrelDigitizer->setDetIds(theBarrelDets);
348  theEndcapDigitizer->setDetIds(theEndcapDets);
349 //TB if (!doFast) { theESDigitizer->setDetIds(theESDets); }
350 //TB if ( doFast) { theESDigitizerFast->setDetIds(theESDets); }
351 
352  theTBReadout->setDetIds(theBarrelDets);
353 }
354 */
355 //For TB --------------------------------------------------------
356 
358 
360  if ( !parameters.syncPhase() ) {
361 
362  int myDet = detId.subdetId();
363 
364  LogDebug("EcalDigi") << "Setting the phase shift " << thisPhaseShift << " and the offset " << tunePhaseShift << " for the subdetector " << myDet;
365 
366  if ( myDet == 1) {
367  double passPhaseShift = thisPhaseShift+tunePhaseShift;
368  if ( use2004OffsetConvention_ ) passPhaseShift = 1.-passPhaseShift;
369  theEBResponse->setPhaseShift(passPhaseShift);
370  theEEResponse->setPhaseShift(passPhaseShift);
371  }
372 
373  }
374 
375 }
376 
378 
379  unsigned int thisChannel = 1;
380 
381  unsigned int thisCount = (unsigned int)(thisPhaseShift*(tdcRanges[0].tdcMax[0]-tdcRanges[0].tdcMin[0]) + tdcRanges[0].tdcMin[0]);
382 
383  EcalTBTDCSample theTBTDCSample(thisChannel, thisCount);
384 
385  unsigned int sampleIndex = 0;
386  theTBTDCRawInfo.setSample(sampleIndex, theTBTDCSample);
387 
388  LogDebug("EcalDigi") << theTBTDCSample << "\n" << theTBTDCRawInfo;
389 
390 }
391 //For TB --------------------------------------------------------
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
dictionary parameters
Definition: Parameters.py:2
virtual const CaloSimParameters & simParameters(const DetId &id) const
return the sim parameters relative to the right subdet
virtual void produce(edm::Event &event, const edm::EventSetup &eventSetup)
Creates electronics signals from hits.
CaloHitRespoNew * theEBResponse
void run(MixCollection< PCaloHit > &input, DigiCollection &output)
const EBShape theEBShape
const EcalTrigTowerConstituentsMap * theTTmap
std::string EBdigiCollection_
void setIntercalibConstants(const EcalIntercalibConstantsMC *ical)
Definition: EcalCoder.cc:58
EcalTBReadout * theTBReadout
Main class for Parameters in different subdetectors.
EcalCorrMatrix * theNoiseMatrix
CorrelatedNoisifier< EcalCorrMatrix > * theCorrNoise
int size() const
Definition: MixCollection.h:23
void fillTBTDCRawInfo(EcalTBTDCRawInfo &theTBTDCRawInfo)
void performReadout(edm::Event &event, const EcalTrigTowerConstituentsMap &theTTmap, EBDigiCollection &input, EBDigiCollection &output)
master function to be called once per event
void setGeometry(const CaloSubdetectorGeometry *geometry)
const EEShape theEEShape
EBDigitizer * theBarrelDigitizer
void setPhaseShift(const DetId &detId)
void setPedestals(const EcalPedestals *pedestals)
can be fetched every event from the EventSetup
Definition: EcalCoder.cc:46
EcalElectronicsSim * theElectronicsSim
std::string EEdigiCollection_
EEDigitizer * theEndcapDigitizer
float gain6Over1() const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
math::ErrorD< CaloSamples::MAXSAMPLES >::type EcalCorrMatrix
bool isValid() const
Definition: HandleBase.h:76
vector< ParameterSet > Parameters
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
void setPhaseShift(double phaseShift)
std::string m_barrelHitsName
std::vector< EcalTBTDCRecInfoAlgo::EcalTBTDCRanges > tdcRanges
void setGainRatios(const EcalGainRatios *gainRatios)
Definition: EcalCoder.cc:52
void setDetIds(const std::vector< DetId > &detIds)
tell the readout which cells exist
Definition: EcalTBReadout.h:31
Definition: DetId.h:20
EcalTDigitizer< EEDigitizerTraits > EEDigitizer
void setFullScaleEnergy(double EBscale, double EEscale)
Definition: EcalCoder.cc:37
std::string m_endcapHitsName
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
float gain12Over6() const
T const * product() const
Definition: Handle.h:74
EcalTDigitizer< EBDigitizerTraits > EBDigitizer
void setSample(unsigned int i, const EcalTBTDCSample &sam)
CaloHitRespoNew * theEEResponse
EcalTBDigiProducer(const edm::ParameterSet &params)
const EcalSimParameterMap * theParameterMap
tuple cout
Definition: gather_cfg.py:41
void checkCalibrations(const edm::EventSetup &eventSetup)
bool syncPhase() const
choice of the ADC time alignment (synchronous for LHC, asynchronous for test beams) ...