CMS 3D CMS Logo

EcalSimpleProducer.cc
Go to the documentation of this file.
9 #include "TFormula.h"
10 #include <iostream>
11 #include <memory>
12 
13 #include <string>
14 
15 using namespace std;
16 using namespace edm;
17 
19  const int ievt = evt.id().event();
20  if (formula_.get() != nullptr) {
21  unique_ptr<EBDigiCollection> digis(new EBDigiCollection);
22 
23  digis->reserve(170 * 360);
24 
25  const int nSamples = digis->stride();
26  for (int iEta0 = 0; iEta0 < 170; ++iEta0) {
27  for (int iPhi0 = 0; iPhi0 < 360; ++iPhi0) {
28  int iEta1 = cIndex2iEta(iEta0);
29  int iPhi = cIndex2iPhi(iPhi0);
30  if (verbose_)
31  cout << "(" << iEta0 << "," << iPhi0 << "): ";
32  digis->push_back(EBDetId(iEta1, iPhi));
33  DataFrame dframe(digis->back());
34 
35  for (int t = 0; t < nSamples; ++t) {
36  uint16_t encodedAdc = (uint16_t)formula_->Eval(iEta0, iPhi0, ievt - 1, t);
37  if (verbose_)
38  cout << encodedAdc << ((t < (nSamples - 1)) ? "\t" : "\n");
39  dframe[t] = encodedAdc;
40  }
41  }
42  }
43  evt.put(std::move(digis));
44  // puts an empty digi collecion for endcap:
45  evt.put(std::make_unique<EEDigiCollection>());
46  }
47  if (tpFormula_.get() != nullptr) {
48  unique_ptr<EcalTrigPrimDigiCollection> tps = std::make_unique<EcalTrigPrimDigiCollection>();
49  tps->reserve(56 * 72);
50  const int nSamples = 5;
51  for (int iTtEta0 = 0; iTtEta0 < 56; ++iTtEta0) {
52  for (int iTtPhi0 = 0; iTtPhi0 < 72; ++iTtPhi0) {
53  int iTtEta1 = cIndex2iTtEta(iTtEta0);
54  int iTtPhi = cIndex2iTtPhi(iTtPhi0);
55 
56  if (verbose_)
57  cout << "(" << iTtEta0 << "," << iTtPhi0 << "): ";
58  int zside = iTtEta1 < 0 ? -1 : 1;
60 
61  tpframe.setSize(nSamples);
62 
63  if (verbose_)
64  cout << "TP: ";
65  for (int t = 0; t < nSamples; ++t) {
66  uint16_t encodedTp = (uint16_t)tpFormula_->Eval(iTtEta0, iTtPhi0, ievt - 1, t);
67 
68  if (verbose_)
69  cout << "TP(" << iTtEta0 << "," << iTtPhi0 << ") = " << encodedTp << ((t < (nSamples - 1)) ? "\t" : "\n");
70  tpframe.setSample(t, EcalTriggerPrimitiveSample(encodedTp));
71  }
72  tps->push_back(tpframe);
73  }
74  }
75  evt.put(std::move(tps));
76  }
77  if (simHitFormula_.get() != nullptr) { // generation of barrel sim hits
78  unique_ptr<PCaloHitContainer> hits = std::make_unique<PCaloHitContainer>();
79  for (int iEta0 = 0; iEta0 < 170; ++iEta0) {
80  for (int iPhi0 = 0; iPhi0 < 360; ++iPhi0) {
81  int iEta1 = cIndex2iEta(iEta0);
82  int iPhi = cIndex2iPhi(iPhi0);
83  if (verbose_)
84  cout << "(" << iEta0 << "," << iPhi0 << "): ";
85 
86  double em = simHitFormula_->Eval(iEta0, iPhi0, ievt - 1);
87  double eh = 0.;
88  double t = 0.;
89  const PCaloHit hit(EBDetId(iEta1, iPhi).rawId(), em, eh, t, 0, 0);
90  hits->push_back(hit);
91  }
92  }
93  evt.put(std::move(hits), "EcalHitsEB");
94  // puts an empty digi collecion for endcap:
95  evt.put(std::make_unique<PCaloHitContainer>(), "EcalHitsEE");
96  }
97 }
98 
100  string formula = pset.getParameter<string>("formula");
101  string tpFormula = pset.getParameter<string>("tpFormula");
102  string simHitFormula = pset.getParameter<string>("simHitFormula");
103 
104  verbose_ = pset.getUntrackedParameter<bool>("verbose", false);
105  // replaceAll(formula, "itt0",
106  // "((((ieta0<85)*(84-ieta0)+(ieta0>=85)*(ieta0-85))/5-18)*4+((iphi0/5+2)%4))");
107  replaceAll(formula, "ebm", "(ieta0<85)");
108  replaceAll(formula, "ebp", "(ieta0>84)");
109  replaceAll(formula, "ieta0", "x");
110  replaceAll(formula, "iphi0", "y");
111  replaceAll(formula, "ievt0", "z");
112  replaceAll(formula, "isample0", "t");
113  // cout << "----------> " << formula << endl;
114 
115  replaceAll(tpFormula, "itt0", "((ieta0<28)*(27-ieta0)+(ieta0>=28)*(ieta0-28))*4+(iphi0+2)%4");
116  replaceAll(tpFormula, "eb", "(ieta0>10 && ieta0<45)");
117  replaceAll(tpFormula, "ebm", "(ieta0>10 && ieta0<28)");
118  replaceAll(tpFormula, "ebp", "(ieta0>27 && ieta0<45)");
119  replaceAll(tpFormula, "ee", "(ieta0<11 || ieta0>44)");
120  replaceAll(tpFormula, "eem", "(ieta0<11)");
121  replaceAll(tpFormula, "eep", "(ieta0>44)");
122  replaceAll(tpFormula, "ieta0", "x");
123  replaceAll(tpFormula, "iphi0", "y");
124  replaceAll(tpFormula, "ievt0", "z");
125  replaceAll(tpFormula, "isample0", "t");
126  // cout << "----------> " << tpFormula << endl;
127 
128  // replaceAll(simHitormula, "itt0",
129  // "((((ieta0<85)*(84-ieta0)+(ieta0>=85)*(ieta0-85))/5-18)*4+((iphi0/5+2)%4))");
130  replaceAll(simHitFormula, "ebm", "(ieta0<85)");
131  replaceAll(simHitFormula, "ebp", "(ieta0>84)");
132  replaceAll(simHitFormula, "ieta0", "x");
133  replaceAll(simHitFormula, "iphi0", "y");
134  replaceAll(simHitFormula, "ievt0", "z");
135 
136  if (!formula.empty()) {
137  formula_ = std::make_unique<TFormula>("f", formula.c_str());
138  Int_t err = formula_->Compile();
139  if (err != 0) {
140  throw cms::Exception("Error in EcalSimpleProducer 'formula' config.");
141  }
142  produces<EBDigiCollection>();
143  produces<EEDigiCollection>();
144  }
145  if (!tpFormula.empty()) {
146  tpFormula_ = std::make_unique<TFormula>("f", tpFormula.c_str());
147  Int_t err = tpFormula_->Compile();
148  if (err != 0) {
149  throw cms::Exception("Error in EcalSimpleProducer 'tpFormula' config.");
150  }
151  produces<EcalTrigPrimDigiCollection>();
152  }
153  if (!simHitFormula.empty()) {
154  simHitFormula_ = std::make_unique<TFormula>("f", simHitFormula.c_str());
155  Int_t err = simHitFormula_->Compile();
156  if (err != 0) {
157  throw cms::Exception(
158  "Error in EcalSimpleProducer "
159  "'simHitFormula' config.");
160  }
161  produces<edm::PCaloHitContainer>("EcalHitsEB");
162  produces<edm::PCaloHitContainer>("EcalHitsEE");
163  }
164 }
165 
168  // cout << "replaceAll(" << s << "," << from << "," << to << ")\n";
169  while ((pos = s.find(from, pos)) != string::npos) {
170  // cout << "replace(" << pos << "," << from.size() << "," << to << ")\n";
171  s.replace(pos, from.size(), to);
172  // cout << " -> " << s << "\n";
173  }
174 }
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
ecaldqm::zside
int zside(DetId const &)
Definition: EcalDQMCommonUtils.cc:189
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
EBDetId
Definition: EBDetId.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
EBDetId.h
EcalSimpleProducer::simHitFormula_
std::unique_ptr< TFormula > simHitFormula_
Definition: EcalSimpleProducer.h:113
to
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
EcalSimpleProducer::tpFormula_
std::unique_ptr< TFormula > tpFormula_
Definition: EcalSimpleProducer.h:109
PresampleTask_cfi.nSamples
nSamples
Definition: PresampleTask_cfi.py:7
alignCSCRings.s
s
Definition: alignCSCRings.py:92
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
EcalElecEmulTccOnlyExample_cfg.tpFormula
tpFormula
Definition: EcalElecEmulTccOnlyExample_cfg.py:32
EcalDigiCollections.h
EcalSimpleProducer::verbose_
bool verbose_
Definition: EcalSimpleProducer.h:117
EcalSimpleProducer::replaceAll
void replaceAll(std::string &s, const std::string &from, const std::string &to) const
Definition: EcalSimpleProducer.cc:166
EcalSimpleProducer::produce
void produce(edm::Event &evt, const edm::EventSetup &) override
Definition: EcalSimpleProducer.cc:18
EcalSimpleProducer::formula_
std::unique_ptr< TFormula > formula_
Definition: EcalSimpleProducer.h:105
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalTriggerPrimitiveDigi::setSize
void setSize(int size)
Definition: EcalTriggerPrimitiveDigi.cc:60
edm::ParameterSet
Definition: ParameterSet.h:47
EcalSimpleProducer.h
Event.h
EBDigiCollection
Definition: EcalDigiCollections.h:56
EcalTriggerPrimitiveDigi::setSample
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
Definition: EcalTriggerPrimitiveDigi.h:36
edm::EventID::event
EventNumber_t event() const
Definition: EventID.h:40
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
EBDataFrame.h
edm::EventSetup
Definition: EventSetup.h:58
PCaloHit
Definition: PCaloHit.h:8
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
EcalSimpleProducer::EcalSimpleProducer
EcalSimpleProducer(const edm::ParameterSet &pset)
Definition: EcalSimpleProducer.cc:99
edm::DataFrame
Definition: DataFrame.h:15
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
EcalTriggerTower
Definition: EcalSubdetector.h:10
EcalTriggerPrimitiveDigi
Definition: EcalTriggerPrimitiveDigi.h:16
Exception
Definition: hltDiff.cc:245
edm::EventBase::id
edm::EventID id() const
Definition: EventBase.h:59
edm::EDProducer
Definition: EDProducer.h:35
Exception.h
PCaloHitContainer.h
EcalTriggerPrimitiveSample
Definition: EcalTriggerPrimitiveSample.h:12
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
hit
Definition: SiStripHitEffFromCalibTree.cc:88
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27