26 #include "TParameter.h"
33 return (
int)(eta*1000);
39 ver = (TParameter<int>*)
source->Get(
"version");
43 TTree* TTreeMeta = (TTree*)
source->Get(
"meta");
44 TTree* TTreeLib = (TTree*)
source->Get(
"library");
46 if ((TTreeMeta ==
nullptr) || (TTreeLib ==
nullptr))
return nullptr;
48 std::cout <<
"EtaEnergyShowerLib header found." << std::endl;
52 if (!(newlib->
readMeta(TTreeMeta)) || !(newlib->
read(TTreeLib))) {
54 std::cout <<
"EtaEnergyShowerLib read unsuccessful." << std::endl;
77 std::ifstream filestr(
inputFile.c_str(),std::ios::in);
80 if (!filestr.is_open()) {
81 std::cout <<
"EtaEnergyShowerLib " <<
inputFile <<
": bad file!" << std::endl;
86 std::getline(filestr,instr);
87 std::stringstream
ss(instr);
103 std::vector<float> etalist;
106 float etaold = -9999999.9;
111 std::cout <<
"file reading failed! (not enough data)" << std::endl;
119 if ((
ss.fail()) || (eta <= etaold)) {
120 std::cout <<
"screwed etas! (" << eta <<
"<=" << etaold <<
")" << std::endl;
123 etalist.push_back(eta);
131 std::cout <<
"this structure is not valid" << std::endl;
145 std::getline(filestr,instr);
155 double eta =
track->GetPosition().eta();
159 library::const_iterator libit =
m_libData.upper_bound(eta);
163 std::cout <<
"Something is wrong with eta: mineta=" <<
m_mineta <<
" eta=" << eta << std::endl;
170 if ((*libit).second.empty()) {
171 std::cout <<
"The etabin corresponding to the eta is empty" << std::endl;
174 double trenergy =
track->GetKineticEnergy();
176 etabin::const_iterator etait = (*libit).second.lower_bound(trenergy);
177 if (etait == (*libit).second.end()) --etait;
178 else if (etait != (*libit).second.begin()) {
179 etabin::const_iterator etaitch = etait;
181 if (((*etait).first - trenergy) > (trenergy - (*etaitch).first)) {
186 if (randomShift > 0) {
187 double upperEnergy = (*etait).first * 1.01;
188 for (
int i = 0;
i < randomShift;
i++) {
190 if (etait == (*libit).second.end()) {
194 if ((*etait).first > upperEnergy)
break;
197 if ((randomShift < 0)&&(etait != (*libit).second.begin())) {
198 double lowerEnergy = (*etait).first * 0.99;
199 for (
int i = 0;
i > randomShift;
i--) {
201 if (etait == (*libit).second.begin()) {
205 if (lowerEnergy > (*etait).first)
break;
210 std::vector<EnergySpot>* outshower =
new std::vector<EnergySpot>();
211 Shower::const_iterator iter;
214 float energyScale =
track->GetKineticEnergy() / (*etait).first;
217 for (iter = (*etait).second.begin() ; iter != (*etait).second.end() ; ++iter) {
218 EnergySpot tmp( (*iter)->GetPosition(), (*iter)->GetEnergy(), (*iter)->GetTime() );
219 tmp.SetEnergy(
tmp.GetEnergy() * energyScale);
220 outshower->push_back(
tmp);
224 if (
stats !=
nullptr) {
235 double eta =
track->GetPosition().eta();
239 library::const_iterator libit =
m_libData.upper_bound(eta);
243 std::cout <<
"Something is wrong with eta: mineta=" <<
m_mineta <<
" eta=" << eta << std::endl;
248 if ((*libit).second.empty()) {
249 std::cout <<
"The etabin corresponding to the eta is empty" << std::endl;
252 double trenergy =
track->GetKineticEnergy();
253 etabin::const_iterator etait = (*libit).second.lower_bound(trenergy);
254 if (etait == (*libit).second.end()) --etait;
255 else if (etait != (*libit).second.begin()) {
256 etabin::const_iterator etaitch = etait;
258 if (((*etait).first - trenergy) > (trenergy - (*etaitch).first)) {
263 double rezZ = (*etait).second.getZSize();
264 etabin::const_iterator etaiter = etait;
267 double upperEnergy = (*etait).first * 1.01;
268 for (
int i = 0;
i < spread;
i++) {
270 if (etaiter == (*libit).second.end()) {
273 if (upperEnergy < (*etaiter).first)
break;
275 rezZ += (*etaiter).second.getZSize();
279 if (etaiter != (*libit).second.begin()) {
280 double lowerEnergy = (*etait).first * 0.99;
281 for (
int i = 0;
i < spread;
i++) {
283 if (lowerEnergy > (*etaiter).first)
break;
285 rezZ += (*etaiter).second.getZSize();
287 if (etaiter == (*libit).second.begin()) {
292 return rezZ/actualNumFS;
299 double eta =
track->GetPosition().eta();
303 library::const_iterator libit =
m_libData.upper_bound(eta);
307 std::cout <<
"Something is wrong with eta: mineta=" <<
m_mineta <<
" eta=" << eta << std::endl;
312 if ((*libit).second.empty()) {
313 std::cout <<
"The etabin corresponding to the eta is empty" << std::endl;
316 double trenergy =
track->GetKineticEnergy();
317 etabin::const_iterator etait = (*libit).second.lower_bound(trenergy);
318 if (etait == (*libit).second.end()) --etait;
319 else if (etait != (*libit).second.begin()) {
320 etabin::const_iterator etaitch = etait;
322 if (((*etait).first - trenergy) > (trenergy - (*etaitch).first)) {
327 double rezR = (*etait).second.getRSize();
328 etabin::const_iterator etaiter = etait;
331 double upperEnergy = (*etait).first * 1.01;
332 for (
int i = 0;
i < spread;
i++) {
334 if (etaiter == (*libit).second.end()) {
337 if (upperEnergy < (*etaiter).first)
break;
339 rezR += (*etaiter).second.getRSize();
343 if (etaiter != (*libit).second.begin()) {
344 double lowerEnergy = (*etait).first * 0.99;
345 for (
int i = 0;
i < spread;
i++) {
347 if (lowerEnergy > (*etaiter).first)
break;
349 rezR += (*etaiter).second.getRSize();
351 if (etaiter == (*libit).second.begin()) {
356 return rezR/actualNumFS;
362 std::cout <<
"ERROR: filled" << std::endl;
366 double eta = genParticle->production_vertex()->position().eta();
371 std::cout <<
"ERROR: eta is outside: " <<
m_mineta <<
" << " <<
m_maxeta <<
" : " << eta << std::endl;
375 std::cout <<
"ERROR: wrong pdgcode: " <<
m_particle <<
" != " << genParticle->pdg_id() << std::endl;
382 std::cout <<
"Something is wrong with eta: mineta=" <<
m_mineta <<
" eta=" << eta << std::endl;
386 (*libit).second.insert(etabin::value_type(genParticle->momentum().e(),(*shower)));
395 dest->WriteObject(&
ver,
"version");
403 dest->WriteObject(&TTreeLib,
"library");
404 dest->WriteObject(&TTreeMeta,
"meta");
424 int nentr =
source->GetEntriesFast();
425 if (nentr < 3)
return false;
426 Float_t
x,
y,
z,
e,time;
427 source->SetBranchAddress(
"x",&
x);
428 source->SetBranchAddress(
"y",&
y);
429 source->SetBranchAddress(
"z",&
z);
430 source->SetBranchAddress(
"e",&
e);
431 source->SetBranchAddress(
"time",&time);
437 int nsh = (
int)(
x+0.1);
442 for(
int i = 0;
i < nsh;
i++) {
445 int nhits = (
int)(
x+0.1);
447 Shower * shower = &((*curbin)[curEnergy]);
450 for(
int j = 0; j < nhits; j++) {
455 }
while (entr < nentr);
481 Float_t
x,
y,
z,
e,time;
482 dest->Branch(
"x",&
x);
483 dest->Branch(
"y",&
y);
484 dest->Branch(
"z",&
z);
485 dest->Branch(
"e",&
e);
486 dest->Branch(
"time",&time);
487 library::const_iterator libit;
489 x = (*libit).second.size();
494 etabin::const_iterator etait;
495 for (etait = (*libit).second.begin(); etait != (*libit).second.end(); ++etait) {
496 x = (*etait).second.size();
497 y = (*etait).second.getRSize();
498 z = (*etait).second.getZSize();
501 Shower::const_iterator iter;
502 for (iter = (*etait).second.begin(); iter != (*etait).second.end(); ++iter) {
503 x = (*iter)->GetPosition().x();
504 y = (*iter)->GetPosition().y();
505 z = (*iter)->GetPosition().z();
506 e = (*iter)->GetEnergy();
507 time = (*iter)->GetTime();
518 std::vector<float>::const_iterator iter;
520 for (iter = structure.begin(); iter != structure.end(); ++iter) {
529 std::map<int, std::string>
names;
530 std::map<int, int> sizes;
533 float etalow =
it->first;
535 library::const_iterator it_copy =
it;
540 etahigh = it_copy->first;
542 std::stringstream
ss;
543 ss << std::showpos << std::fixed << std::setprecision(2);
544 ss <<
"ETA: " << etalow <<
" .. " << etahigh;
553 std::cout <<
"Library is not created for production use" << std::endl;
557 double eta =
track->GetPosition().eta();
562 std::cout <<
"eta is outside library eta range: mineta=" <<
m_mineta <<
" maxeta: " <<
m_maxeta <<
" eta=" << eta << std::endl;
566 G4int particleCode =
track->GetDefinition()->GetPDGEncoding();
567 if ( particleCode < 0 ) particleCode = -particleCode;
570 std::cout <<
"wrong particle: " << particleCode <<
"!=" <<
m_particle << std::endl;