11 #include "GaudiKernel/IEventProcessor.h"
31 while (std::getline(
ss,
line,
'\n'))
64 return StatusCode::SUCCESS;
78 SmartIF<IEventProcessor> appMgr{service(
"ApplicationMgr")};
80 ATH_MSG_ERROR(
"Failed to retrieve ApplicationMgr as IEventProcessor");
81 return StatusCode::FAILURE;
83 return appMgr->stopRun();
89 return StatusCode::SUCCESS;
104 ATH_MSG_INFO(
"Cannot read more events from file, returning");
105 return StatusCode::SUCCESS;
114 if (hit.getBarcodePt() == 0)
continue;
118 int lyr = hit.getPhysLayer();
119 int eta = hit.getEtaModule();
120 int phi = hit.getPhiModule();
122 if (hit.isPixel() && hit.isBarrel()) {
126 else if (hit.isPixel() && !hit.isBarrel()) {
129 eta = hit.getEtaModule();
130 lyr = hit.getPhysLayer();
136 else if (!hit.isPixel() && hit.isBarrel()) {
140 else if (!hit.isPixel() && !hit.isBarrel()) {
162 m_modules.insert(std::pair<FPGATrackSimModuleId, Module>(
mod.moduleId(),
mod));
171 return StatusCode::SUCCESS;
199 m_pmap <<
"! silicon endCap physDisk physLayer ['stereo' stripSide <strip only>] 'plane1' logiLayer1 'plane2' logiLayer2\n";
200 m_pmap <<
"\nregion " << reg <<
"\n";
203 for (
int lyr = 0; lyr <=
m_pbmax; lyr++) {
206 m_pmap <<
"pixel 0 -1 " << lyr <<
" plane1 " <<
p1 <<
" plane2 " <<
p2 <<
"\n";
208 for (
int lyr = 0; lyr <=
m_pemax[0]; lyr++) {
211 m_pmap <<
"pixel 1 " << lyr <<
" " << lyr <<
" plane1 " <<
p1 <<
" plane2 " <<
p2 <<
"\n";
213 for (
int lyr = 0; lyr <=
m_pemax[1]; lyr++) {
216 m_pmap <<
"pixel 2 " << lyr <<
" " << lyr <<
" plane1 " <<
p1 <<
" plane2 " <<
p2 <<
"\n";
218 for (
int lyr = 0; lyr <=
m_sbmax; lyr++) {
221 m_pmap <<
"SCT 0 -1 " << lyr <<
" stereo " << lyr % 2 <<
" plane1 " <<
p1 <<
" plane2 " <<
p2 <<
"\n";
223 for (
int lyr = 0; lyr <=
m_semax[0]; lyr++) {
226 m_pmap <<
"SCT 1 " << lyr/2 <<
" " << lyr <<
" stereo " << lyr % 2 <<
" plane1 " <<
p1 <<
" plane2 " <<
p2 <<
"\n";
228 for (
int lyr = 0; lyr <=
m_semax[1]; lyr++) {
231 m_pmap <<
"SCT 2 " << lyr/2 <<
" " << lyr <<
" stereo " << lyr % 2 <<
" plane1 " <<
p1 <<
" plane2 " <<
p2 <<
"\n";
238 m_rmap <<
"towers 1 phi 16\n\n0\n";
254 ATH_MSG_ERROR(
"Error: Unable to open file for reading: " << pmap_path);
255 return StatusCode::FAILURE;
258 std::ostringstream
buffer;
260 std::string fileContent =
buffer.str();
264 std::string newContent;
266 newContent += fileContent;
273 ATH_MSG_ERROR(
"Error: Unable to open file for writing: " << pmap_path);
274 return StatusCode::FAILURE;
280 return StatusCode::SUCCESS;
288 std::set<int> key_etamods;
290 float total_hits = 0;
292 total_hits +=
etamod.second;
294 ATH_MSG_INFO(
"Found " << total_hits <<
" hits in the key layer, applying global trim factor of " <<
m_globalTrim <<
"%");
299 key_etamods.insert(
etamod.first);
301 ATH_MSG_INFO(
"Eta module " <<
etamod.first <<
" only contains " <<
etamod.second <<
" out of " << total_hits <<
" hits, excluding from slices.");
307 std::vector<std::vector<int>> key_modules_for_slices;
310 std::vector<int> key_etas;
311 std::vector<int> key_etas2;
312 key_etas.insert(key_etas.end(), key_etamods.begin(), key_etamods.end());
314 for (
unsigned i = 0;
i < key_etas.size();
i++)
316 if (
i >= (key_modules_for_slices.size() * etasPerSlice)) key_modules_for_slices.push_back(std::vector<int>());
317 key_modules_for_slices.back().push_back(key_etas[
i]);
320 std::map<int, int> keymod2slice;
321 for (
unsigned s = 0;
s < key_modules_for_slices.size();
s++)
322 for (
unsigned e = 0;
e < key_modules_for_slices[
s].size();
e++)
323 keymod2slice[key_modules_for_slices[
s][
e]] =
s;
336 std::stringstream eta_slices;
337 for (
unsigned s = 0;
s < key_modules_for_slices.size();
s++){
338 for (
unsigned e = 0;
e < key_modules_for_slices[
s].size();
e++){
339 eta_slices << key_modules_for_slices[
s][
e] <<
" ";
350 std::vector<std::vector<int>> key_modules_for_slices2;
353 for (
unsigned i = 0;
i < key_etas2.size();
i++)
355 if (
i >= (key_modules_for_slices2.size() * etasPerSlice2)) key_modules_for_slices2.push_back(std::vector<int>());
356 key_modules_for_slices2.back().push_back(key_etas2[
i]);
359 std::map<int, int> keymod2slice2;
360 for (
unsigned s = 0;
s < key_modules_for_slices2.size();
s++)
361 for (
unsigned e = 0;
e < key_modules_for_slices2[
s].size();
e++)
362 keymod2slice2[key_modules_for_slices2[
s][
e]] =
s;
374 for (
auto&
m: pair.second)
377 if (keymod2slice[
m->eta] ==
s1)
key1 =
true;
380 if (keymod2slice2[
m->eta] ==
s2)
key2 =
true;
388 if (newSlice + 1 > new_nSlice) new_nSlice = newSlice + 1;
394 ATH_MSG_INFO(
"These slices were further divided based on the key layer 2: '" <<
key2 <<
"'. Now nSlices = " <<
m_nSlices.value());
405 if (
isOnKeyLayer(1,hit.getDetType(),hit.getDetectorZone(), hit.getPhysLayer()))
407 if (keymod2slice.count(hit.getEtaModule()) > 0) {
408 int s = keymod2slice[hit.getEtaModule()];
417 std::stringstream
trim;
418 std::stringstream gtrim;
419 trim << std::fixed << std::setprecision(3) <<
m_trim;
420 gtrim << std::fixed << std::setprecision(3) <<
m_globalTrim;
421 std::string str_trim =
trim.str();
422 std::string str_gtrim = gtrim.str();
423 int dot = str_trim.find_last_of(
".");
424 str_trim.replace(
dot,1,
"p");
425 str_gtrim.replace(str_gtrim.find_last_of(
"."), 1,
"p");
437 if (
m->numTracks.empty()) {
446 std::vector<std::vector<int>> slicedTracks (
m_nSlices.value());
449 slicedTracks[
s].push_back(trk);
463 for (
auto trk : slicedTracks[
s]) {
483 ATH_MSG_INFO(
"Trimmed off " << trimmed <<
" modules that were hit by less than " <<
m_trim <<
"% of tracks");
501 return StatusCode::SUCCESS;
506 std::stringstream
trim;
507 std::stringstream gtrim;
508 trim << std::fixed << std::setprecision(3) <<
m_trim;
509 gtrim << std::fixed << std::setprecision(3) <<
m_globalTrim;
510 std::string str_trim =
trim.str();
511 std::string str_gtrim = gtrim.str();
512 int dot = str_trim.find_last_of(
".");
513 str_trim.replace(
dot,1,
"p");
514 str_gtrim.replace(str_gtrim.find_last_of(
"."), 1,
"p");
516 std::string slicingType =
"";
517 if (
m_key2) slicingType =
"2D";
520 ATH_MSG_INFO(
"Creating eta patterns file: " << etapat_path);
525 for (
auto&
m: pair.second)
539 std::stringstream track_etapatts;
540 unsigned planesDone = 0;
544 if (
m->plane ==
static_cast<int>(
p))
546 track_etapatts << std::to_string(static_cast<int>(
m->det)) <<
"\t" <<
std::to_string(
static_cast<int>(
m->bec)) <<
"\t" <<
std::to_string(
m->eta) <<
"\t\t";
553 m_etapat << track_etapatts.str() <<
"\n";
557 return StatusCode::SUCCESS;
564 for (
const auto& hit: allHits)
568 int lyr = hit.getPhysLayer();
595 m_radfile << std::setprecision(3) << std::fixed <<
avg <<
" ";
617 m_radfile << std::setprecision(3) << std::fixed <<
avg <<
" ";
626 return StatusCode::SUCCESS;
633 for (
const auto& hit: allHits)
637 int lyr = hit.getPhysLayer();
648 m_z[
slice][plane].push_back(hit.getZ());
662 float median = (minZ + maxZ)/2;
677 bool doneInitial =
false;
694 float median = (minZ + maxZ)/2;
705 return StatusCode::SUCCESS;
720 return StatusCode::SUCCESS;
731 std::vector<TH2F*> h_slicemap;
732 char *
hname =
new char[20];
736 sprintf(
hname,
"rz_slice%u",
i);
740 h_slicemap.push_back(
h);
743 for (
const auto& hit: allHits)
747 h_slicemap[
s]->Fill(hit.getZ(),hit.getR());
751 h_slicemap[
i]->Write();
758 int det =
static_cast<int>(t_det);
759 int bec =
static_cast<int>(t_bec);
774 for (
auto& plane : planes) {
775 for (
auto&
layer : plane) {
785 std::stringstream rmap_line;
786 std::set<int>
etas, phis;
788 for(
int lyr = 0; lyr <=
max; lyr++)
792 for (
const auto& hit:
hits)
794 if(
static_cast<int>(hit.getPhysLayer()) == lyr && hit.getDetectorZone() ==
bec)
796 etas.insert(hit.getEtaModule());
797 phis.insert(hit.getPhiModule());
800 if (
etas.size() != 0) rmap_line << static_cast<int>(
det) <<
" " <<
static_cast<int>(
bec) <<
" " << lyr <<
" " << *phis.begin() <<
" " << *phis.rbegin() <<
" " << phis.size() <<
" " << *
etas.begin() <<
" " << *
etas.rbegin() <<
" " <<
etas.size() <<
"\n";
801 else rmap_line << static_cast<int>(
det) <<
" " <<
static_cast<int>(
bec) <<
" " << lyr <<
" 0 0 0 0 0 0\n";
805 return rmap_line.str();
813 std::string
det,
bec, lyr;
814 std::map <std::string, std::vector<std::string>> abrevs = { {
"pb",{
"pixel",
"barrel"}}, {
"pe",{
"pixel",
"endcap"}}, {
"sb",{
"strip",
"barrel"}}, {
"se",{
"strip",
"endcap"}} };
828 ATH_MSG_ERROR(
"Invalid KeyString: '" <<
m_keystring <<
"'." <<
"Accepted formats are 'strip,posEndcap,2', 'pixel,barrel,3', or 'plane 0'");
836 std::string plane =
s.substr(0,
s.find(
delimiter));
838 for (
unsigned i = 0;
i <
s.size();
i++){
839 std::string reg =
s[
i].substr(0, 2);
840 std::vector<std::string>
zone = abrevs[reg];
841 if (
s[
i].back() ==
'+')
zone[1] =
"posEndcap";
842 if (
s[
i].back() ==
'-')
zone[1] =
"negEndcap";
845 std::string lyr =
s[
i].substr(2);
851 ATH_MSG_ERROR(
"Invalid KeyString: '" <<
m_keystring <<
"'." <<
"Accepted formats are 'strip,posEndcap,2', 'pixel,barrel,3', or 'plane 0'");
873 ATH_MSG_ERROR(
"Invalid KeyString2: '" <<
m_keystring2 <<
"'." <<
"Accepted formats are 'strip,posEndcap,2', 'pixel,barrel,3', or 'plane 0'");
881 std::string plane =
s.substr(0,
s.find(
delimiter));
883 for (
unsigned i = 0;
i <
s.size();
i++){
884 std::string reg =
s[
i].substr(0, 2);
885 std::vector<std::string>
zone = abrevs[reg];
886 if (
s[
i].back() ==
'+')
zone[1] =
"posEndcap";
887 if (
s[
i].back() ==
'-')
zone[1] =
"negEndcap";
890 std::string lyr =
s[
i].substr(2);
896 ATH_MSG_ERROR(
"Invalid KeyString2: '" <<
m_keystring2 <<
"'." <<
"Accepted formats are 'strip,posEndcap,2', 'pixel,barrel,3', or 'plane 0'");
904 std::stringstream subrmap_line;
905 std::set<int>
etas, phis;
907 std::vector<Module*> mods;
908 for (
auto*
mod: allmods)
911 for(
int lyr = 0; lyr <=
max; lyr++)
920 phis.insert(
mod->phi);
923 if (
etas.size() != 0) subrmap_line << static_cast<int>(
det) <<
" " <<
static_cast<int>(
bec) <<
" " << lyr <<
" " << *phis.begin() <<
" " << *phis.rbegin() <<
" " << phis.size() <<
" " << *
etas.begin() <<
" " << *
etas.rbegin() <<
" " <<
etas.size() <<
"\n";
924 else subrmap_line << static_cast<int>(
det) <<
" " <<
static_cast<int>(
bec) <<
" " << lyr <<
" 0 0 0 0 0 0\n";
928 return subrmap_line.str();