CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalEBTrigPrimProducer.cc
Go to the documentation of this file.
1 
11 
17 
22 //
23 
24 /*
25 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBGroupRcd.h"
26 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBIdMapRcd.h"
27 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainTowerEERcd.h"
28 
29 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBGroup.h"
30 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBIdMap.h"
31 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainTowerEE.h"
32 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainStripEERcd.h"
33 #include "CondFormats/EcalObjects/interface/EcalTPGWeightIdMap.h"
34 #include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h"
35 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainStripEE.h"
36 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
37 #include "CondFormats/DataRecord/interface/EcalTPGStripStatusRcd.h"
38 #include "CondFormats/EcalObjects/interface/EcalTPGStripStatus.h"
39 */
40 
41 #include "EcalEBTrigPrimProducer.h"
42 
43 #include <memory>
44 
46 
48  : barrelOnly_(iConfig.getParameter<bool>("BarrelOnly")),
49  tcpFormat_(iConfig.getParameter<bool>("TcpOutput")),
50  debug_(iConfig.getParameter<bool>("Debug")),
51  famos_(iConfig.getParameter<bool>("Famos")),
52  nSamples_(iConfig.getParameter<int>("nOfSamples")),
53  binOfMaximum_(iConfig.getParameter<int>("binOfMaximum")) {
54  tokenEBdigi_ = consumes<EBDigiCollection>(iConfig.getParameter<edm::InputTag>("barrelEcalDigis"));
56  esConsumes<EcalTPGLinearizationConst, EcalTPGLinearizationConstRcd, edm::Transition::BeginRun>();
57  theEcalTPGPedestals_Token_ = esConsumes<EcalTPGPedestals, EcalTPGPedestalsRcd, edm::Transition::BeginRun>();
59  esConsumes<EcalTPGCrystalStatus, EcalTPGCrystalStatusRcd, edm::Transition::BeginRun>();
60  theEcalTPGWEightIdMap_Token_ = esConsumes<EcalTPGWeightIdMap, EcalTPGWeightIdMapRcd, edm::Transition::BeginRun>();
61  theEcalTPGWEightGroup_Token_ = esConsumes<EcalTPGWeightGroup, EcalTPGWeightGroupRcd, edm::Transition::BeginRun>();
63  esConsumes<EcalTPGSlidingWindow, EcalTPGSlidingWindowRcd, edm::Transition::BeginRun>();
64  theEcalTPGLutGroup_Token_ = esConsumes<EcalTPGLutGroup, EcalTPGLutGroupRcd, edm::Transition::BeginRun>();
65  theEcalTPGLutIdMap_Token_ = esConsumes<EcalTPGLutIdMap, EcalTPGLutIdMapRcd, edm::Transition::BeginRun>();
66  theEcalTPGTowerStatus_Token_ = esConsumes<EcalTPGTowerStatus, EcalTPGTowerStatusRcd, edm::Transition::BeginRun>();
67  theEcalTPGSpike_Token_ = esConsumes<EcalTPGSpike, EcalTPGSpikeRcd, edm::Transition::BeginRun>();
68  //register your products
69  produces<EcalEBTrigPrimDigiCollection>();
70  if (tcpFormat_)
71  produces<EcalEBTrigPrimDigiCollection>("formatTCP");
72  if (not barrelOnly_) {
73  eTTmapToken_ = esConsumes<edm::Transition::BeginRun>();
74  theGeometryToken_ = esConsumes<edm::Transition::BeginRun>();
75  }
76 }
77 
79  //ProcessHistory is guaranteed to be constant for an entire Run
80  //binOfMaximum_ = findBinOfMaximum(fillBinOfMaximumFromHistory_,binOfMaximum_,run.processHistory());
81 
82  if (barrelOnly_) {
83  algo_ = std::make_unique<EcalEBTrigPrimTestAlgo>(nSamples_, binOfMaximum_, tcpFormat_, debug_, famos_);
84  } else {
85  auto const& theGeometry = setup.getData(theGeometryToken_);
86  auto const& eTTmap = setup.getData(eTTmapToken_);
87  algo_ = std::make_unique<EcalEBTrigPrimTestAlgo>(
88  &eTTmap, &theGeometry, nSamples_, binOfMaximum_, tcpFormat_, debug_, famos_);
89  }
90  // get a first version of the records
91  cacheID_ = this->getRecords(setup);
92  nEvent_ = 0;
93 }
94 
96  // get parameter records for xtals
97  auto theEcalTPGLinearization_handle = setup.getHandle(theEcalTPGLinearization_Token_);
98  const EcalTPGLinearizationConst* ecaltpLin = theEcalTPGLinearization_handle.product();
99  //
100  edm::ESHandle<EcalTPGPedestals> theEcalTPGPedestals_handle = setup.getHandle(theEcalTPGPedestals_Token_);
101  const EcalTPGPedestals* ecaltpPed = theEcalTPGPedestals_handle.product();
102  //
103  edm::ESHandle<EcalTPGCrystalStatus> theEcalTPGCrystalStatus_handle = setup.getHandle(theEcalTPGCrystalStatus_Token_);
104  const EcalTPGCrystalStatus* ecaltpgBadX = theEcalTPGCrystalStatus_handle.product();
105  //
106  //for strips
107  //
108  edm::ESHandle<EcalTPGWeightIdMap> theEcalTPGWEightIdMap_handle = setup.getHandle(theEcalTPGWEightIdMap_Token_);
109  const EcalTPGWeightIdMap* ecaltpgWeightMap = theEcalTPGWEightIdMap_handle.product();
110  //
111  edm::ESHandle<EcalTPGWeightGroup> theEcalTPGWEightGroup_handle = setup.getHandle(theEcalTPGWEightGroup_Token_);
112  const EcalTPGWeightGroup* ecaltpgWeightGroup = theEcalTPGWEightGroup_handle.product();
113  //
114  edm::ESHandle<EcalTPGSlidingWindow> theEcalTPGSlidingWindow_handle = setup.getHandle(theEcalTPGSlidingWindow_Token_);
115  const EcalTPGSlidingWindow* ecaltpgSlidW = theEcalTPGSlidingWindow_handle.product();
116  // TCP
117  edm::ESHandle<EcalTPGLutGroup> theEcalTPGLutGroup_handle = setup.getHandle(theEcalTPGLutGroup_Token_);
118  const EcalTPGLutGroup* ecaltpgLutGroup = theEcalTPGLutGroup_handle.product();
119  //
120  edm::ESHandle<EcalTPGLutIdMap> theEcalTPGLutIdMap_handle = setup.getHandle(theEcalTPGLutIdMap_Token_);
121  const EcalTPGLutIdMap* ecaltpgLut = theEcalTPGLutIdMap_handle.product();
122  //
123  edm::ESHandle<EcalTPGTowerStatus> theEcalTPGTowerStatus_handle = setup.getHandle(theEcalTPGTowerStatus_Token_);
124  const EcalTPGTowerStatus* ecaltpgBadTT = theEcalTPGTowerStatus_handle.product();
125  //
126  edm::ESHandle<EcalTPGSpike> theEcalTPGSpike_handle = setup.getHandle(theEcalTPGSpike_Token_);
127  const EcalTPGSpike* ecaltpgSpike = theEcalTPGSpike_handle.product();
128 
130  algo_->setPointers(ecaltpLin,
131  ecaltpPed,
132  ecaltpgBadX,
133  ecaltpgWeightMap,
134  ecaltpgWeightGroup,
135  ecaltpgSlidW,
136  ecaltpgLutGroup,
137  ecaltpgLut,
138  ecaltpgBadTT,
139  ecaltpgSpike);
140  return setup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
141 }
142 
144 
146 
147 // ------------ method called to produce the data ------------
149  nEvent_++;
150 
151  // get input collections
152  edm::Handle<EBDigiCollection> barrelDigiHandle;
153 
154  if (!e.getByToken(tokenEBdigi_, barrelDigiHandle)) {
156  labelsForToken(tokenEBdigi_, labels);
157  edm::LogWarning("EcalTPG") << " Couldnt find Barrel digis " << labels.module << " and label "
158  << labels.productInstance << "!!!";
159  }
160 
161  if (debug_)
162  std::cout << "EcalTPG"
163  << " =================> Treating event " << nEvent_ << ", Number of EB digis "
164  << barrelDigiHandle.product()->size() << std::endl;
165 
166  auto pOut = std::make_unique<EcalEBTrigPrimDigiCollection>();
167  auto pOutTcp = std::make_unique<EcalEBTrigPrimDigiCollection>();
168 
169  // if ( e.id().event() != 648 ) return;
170 
171  //std::cout << " Event number " << e.id().event() << std::endl;
172 
173  // invoke algorithm
174 
175  const EBDigiCollection* ebdigi = nullptr;
176  ebdigi = barrelDigiHandle.product();
177  algo_->run(ebdigi, *pOut, *pOutTcp);
178 
179  if (debug_)
180  std::cout << "produce"
181  << " For Barrel " << pOut->size() << " TP Digis were produced" << std::endl;
182 
183  // debug prints if TP >0
184 
185  int nonZeroTP = 0;
186  for (unsigned int i = 0; i < pOut->size(); ++i) {
187  if (debug_) {
188  std::cout << "EcalTPG Printing only non zero TP "
189  << " For tower " << (((*pOut)[i])).id() << ", TP is " << (*pOut)[i];
190  for (int isam = 0; isam < (*pOut)[i].size(); ++isam) {
191  if ((*pOut)[i][isam].encodedEt() > 0) {
192  nonZeroTP++;
193  std::cout << " (*pOut)[i][isam].raw() " << (*pOut)[i][isam].raw() << " (*pOut)[i][isam].encodedEt() "
194  << (*pOut)[i][isam].encodedEt() << std::endl;
195  }
196  }
197  }
198  }
199  if (debug_)
200  std::cout << "EcalTPG"
201  << "\n =================> For Barrel , " << pOut->size()
202  << " TP Digis were produced (including zero ones)"
203  << " Non zero primitives were " << nonZeroTP << std::endl;
204 
205  // put result into the Event
206  e.put(std::move(pOut));
207  if (tcpFormat_)
208  e.put(std::move(pOutTcp), "formatTCP");
209 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::ESGetToken< EcalTPGPedestals, EcalTPGPedestalsRcd > theEcalTPGPedestals_Token_
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
EcalEBTrigPrimProducer(const edm::ParameterSet &conf)
edm::ESGetToken< EcalTPGLutIdMap, EcalTPGLutIdMapRcd > theEcalTPGLutIdMap_Token_
edm::EDGetTokenT< EBDigiCollection > tokenEBdigi_
edm::ESGetToken< EcalTPGSpike, EcalTPGSpikeRcd > theEcalTPGSpike_Token_
unsigned long long getRecords(edm::EventSetup const &setup)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
edm::ESGetToken< EcalTPGTowerStatus, EcalTPGTowerStatusRcd > theEcalTPGTowerStatus_Token_
std::unique_ptr< EcalEBTrigPrimTestAlgo > algo_
edm::ESGetToken< EcalTPGLutGroup, EcalTPGLutGroupRcd > theEcalTPGLutGroup_Token_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > theGeometryToken_
def move
Definition: eostools.py:511
char const * module
Definition: ProductLabels.h:5
edm::ESGetToken< EcalTPGWeightGroup, EcalTPGWeightGroupRcd > theEcalTPGWEightGroup_Token_
void produce(edm::Event &e, const edm::EventSetup &c) override
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > eTTmapToken_
T const * product() const
Definition: Handle.h:70
edm::ESGetToken< EcalTPGWeightIdMap, EcalTPGWeightIdMapRcd > theEcalTPGWEightIdMap_Token_
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< EcalTPGLinearizationConst, EcalTPGLinearizationConstRcd > theEcalTPGLinearization_Token_
edm::ESGetToken< EcalTPGCrystalStatus, EcalTPGCrystalStatusRcd > theEcalTPGCrystalStatus_Token_
char const * productInstance
Definition: ProductLabels.h:6
T get() const
Definition: EventSetup.h:88
void endRun(const edm::Run &, const edm::EventSetup &) override
tuple cout
Definition: gather_cfg.py:144
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
Log< level::Warning, false > LogWarning
edm::ESGetToken< EcalTPGSlidingWindow, EcalTPGSlidingWindowRcd > theEcalTPGSlidingWindow_Token_
Definition: Run.h:45