13 #ifdef ENABLE_XROOTD_SUPPORT
14 #include "XrdStreamBuf.h"
17 #include "CaloDetDescr/CaloDetDescrElement.h"
25 const std::string& hashFileName)
27 std::map<uint64_t, uint64_t> cellId_vs_cellHashId_map;
29 std::unique_ptr<std::istream> hashStream{};
30 std::unique_ptr<std::streambuf> hashStreamBuf{};
31 #ifdef ENABLE_XROOTD_SUPPORT
32 if (hashFileName.find(
"root://") != std::string::npos) {
33 hashStreamBuf = std::make_unique<XrdStreamBuf>(hashFileName);
34 hashStream = std::make_unique<std::istream>(hashStreamBuf.get());
37 std::unique_ptr<std::ifstream> hashStreamDirect = std::make_unique<std::ifstream>(hashFileName);
38 if (!hashStreamDirect->is_open()) {
39 std::cout <<
"Error: Could not open " << hashFileName << std::endl;
40 throw std::runtime_error(
"Could not open file");
42 hashStream = std::move(hashStreamDirect);
43 #ifdef ENABLE_XROOTD_SUPPORT
47 std::cout <<
"Loading cellId_vs_cellHashId_map" << std::endl;
51 while (!hashStream->eof()) {
54 *hashStream >>
id >> hash_id;
55 cellId_vs_cellHashId_map[
id] = hash_id;
57 std::cout <<
"Line: " <<
i <<
" id " << std::hex <<
id <<
" hash_id "
58 << std::dec << hash_id << std::endl;
61 std::cout <<
"Done." << std::endl;
63 auto f = std::unique_ptr<TFile>(TFile::Open(
fileName.c_str()));
65 std::cerr <<
"Error: Could not open file '" <<
fileName <<
"'" << std::endl;
77 TBranch *b_identifier;
78 TBranch *b_calosample;
98 fChain->SetMakeClass(1);
99 fChain->SetBranchAddress(
"identifier", &
cell.m_identify, &b_identifier);
100 fChain->SetBranchAddress(
"calosample", &
cell.m_calosample, &b_calosample);
101 fChain->SetBranchAddress(
"eta", &
cell.m_eta, &b_eta);
102 fChain->SetBranchAddress(
"phi", &
cell.m_phi, &b_phi);
103 fChain->SetBranchAddress(
"r", &
cell.m_r, &b_r);
104 fChain->SetBranchAddress(
"eta_raw", &
cell.m_eta_raw, &b_eta_raw);
105 fChain->SetBranchAddress(
"phi_raw", &
cell.m_phi_raw, &b_phi_raw);
106 fChain->SetBranchAddress(
"r_raw", &
cell.m_r_raw, &b_r_raw);
107 fChain->SetBranchAddress(
"x", &
cell.m_x, &b_x);
108 fChain->SetBranchAddress(
"y", &
cell.m_y, &b_y);
109 fChain->SetBranchAddress(
"z", &
cell.m_z, &b_z);
110 fChain->SetBranchAddress(
"x_raw", &
cell.m_x_raw, &b_x_raw);
111 fChain->SetBranchAddress(
"y_raw", &
cell.m_y_raw, &b_y_raw);
112 fChain->SetBranchAddress(
"z_raw", &
cell.m_z_raw, &b_z_raw);
113 fChain->SetBranchAddress(
"deta", &
cell.m_deta, &b_deta);
114 fChain->SetBranchAddress(
"dphi", &
cell.m_dphi, &b_dphi);
115 fChain->SetBranchAddress(
"dr", &
cell.m_dr, &b_dr);
116 fChain->SetBranchAddress(
"dx", &
cell.m_dx, &b_dx);
117 fChain->SetBranchAddress(
"dy", &
cell.m_dy, &b_dy);
118 fChain->SetBranchAddress(
"dz", &
cell.m_dz, &b_dz);
120 Long64_t
nentries = fChain->GetEntriesFast();
121 for (Long64_t jentry = 0; jentry <
nentries; jentry++) {
122 Long64_t ientry = fChain->LoadTree(jentry);
125 fChain->GetEntry(jentry);
127 if (cellId_vs_cellHashId_map.find(
cell.m_identify)
128 != cellId_vs_cellHashId_map.end()) {
129 cell.m_hash_id = cellId_vs_cellHashId_map[
cell.m_identify];
130 if (
cell.m_hash_id != jentry)
131 std::cout << jentry <<
" : ERROR hash=" <<
cell.m_hash_id << std::endl;
133 std::cout << std::endl
134 <<
"ERROR: Cell id not found in the cellId_vs_cellHashId_map!!!"
141 if (jentry % 25000 == 0) {
142 std::cout <<
"Checking loading cells from file" << std::endl
152 std::cout <<
"Result of PostProcessGeometry(): " << ok << std::endl;
155 unsigned long long cellid64(3179554531063103488);
159 std::cout <<
"\n \n";
160 std::cout <<
"Testing whether CaloGeoGeometry is loaded properly"
163 std::cout <<
"Cell is not found" << std::endl;
166 std::cout <<
"Identifier " <<
mcell->identify() <<
" sampling "
167 <<
mcell->getSampling() <<
" eta: " <<
mcell->eta()
168 <<
" phi: " <<
mcell->phi() <<
" CaloDetDescrElement=" <<
mcell
174 std::cout <<
"Identifier " << mcell2->
identify() <<
" sampling "
176 <<
" phi: " << mcell2->
phi() <<
" CaloDetDescrElement=" << mcell2
186 std::vector<std::unique_ptr<std::istream>> electrodes;
187 std::vector<std::unique_ptr<std::streambuf>> electrodesBuf;
188 electrodes.reserve(3);
189 electrodesBuf.reserve(3);
193 #ifdef ENABLE_XROOTD_SUPPORT
194 if (
file.find(
"root://") != std::string::npos) {
195 electrodesBuf.emplace_back(std::make_unique<XrdStreamBuf>(
file));
196 electrodes.emplace_back(std::make_unique<std::istream>(electrodesBuf.back().get()));
199 std::unique_ptr<std::ifstream> directStream = std::make_unique<std::ifstream>(
file);
200 if (!directStream->is_open()) {
201 std::cout <<
"Error: Could not open " <<
file << std::endl;
202 throw std::runtime_error(
"Could not open file");
204 electrodes.push_back(std::move(directStream));
205 #ifdef ENABLE_XROOTD_SUPPORT
220 std::string seventh_column;
221 std::string eight_column;
225 for (
int imodule = 1; imodule <= 3; imodule++) {
226 std::cout <<
"Loading FCal electrode #" << imodule << std::endl;
231 (*electrodes[imodule - 1]) >> tubeName;
232 if (electrodes[imodule - 1]->eof())
234 (*electrodes[imodule - 1]) >> thisTubeId;
235 (*electrodes[imodule - 1]) >> thisTubeI;
236 (*electrodes[imodule - 1]) >> thisTubeJ;
237 (*electrodes[imodule - 1]) >> thisTubeX;
238 (*electrodes[imodule - 1]) >> thisTubeY;
239 (*electrodes[imodule - 1]) >> seventh_column;
240 (*electrodes[imodule - 1]) >> eight_column;
241 (*electrodes[imodule - 1]) >> ninth_column;
243 tubeName.ReplaceAll(
"'",
"");
244 std::string tubeNamestring = tubeName.Data();
246 std::istringstream tileStream1(std::string(tubeNamestring, 1, 1));
247 std::istringstream tileStream2(std::string(tubeNamestring, 3, 2));
248 std::istringstream tileStream3(std::string(tubeNamestring, 6, 3));
249 int a1 = 0, a2 = 0, a3 = 0;
260 thisTubeJ, thisTubeX, thisTubeY,
270 electrodesBuf.clear();
279 std::stringstream
ss;
280 ss <<
"FCal" << isam - 20 << std::endl;
284 std::vector<double>
x;
285 std::vector<double>
y;
291 x.push_back(
it->second->x());
292 y.push_back(
it->second->y());
295 TGraph *graph =
new TGraph(
size, &
x[0], &
y[0]);
296 graph->SetLineColor(
color);
297 graph->SetTitle(
ss.str().c_str());
298 graph->SetMarkerStyle(21);
299 graph->SetMarkerColor(
color);
300 graph->SetMarkerSize(0.5);
301 graph->GetXaxis()->SetTitle(
"x [mm]");
302 graph->GetYaxis()->SetTitle(
"y [mm]");
313 double x(0.),
y(0.),
r(0.);
314 for (
int imap = 1; imap <= 3; imap++)
319 r = sqrt(
x *
x +
y *
y);
334 long mask1[]{0x34, 0x34, 0x35};
335 long mask2[]{0x36, 0x36, 0x37};
340 for (
int imap = 1; imap <= 3; imap++) {
342 int sampling = imap + 20;
349 <<
"Error: Incompatibility between FCalChannel map and GEO file: "
350 "Different number of cells in m_cells_in_sampling and "
353 std::cout <<
"m_cells_in_sampling: "
355 std::cout <<
"FCal_ChannelMap: "
366 phi_index =
it->first & 0xffff;
372 id = (mask1[imap - 1] << 12) + (
eta_index << 5) + 2 * phi_index;
377 Identifier id1((
unsigned long long)(
id << 44));
380 id = (mask2[imap - 1] << 12) + (
eta_index << 5) + 2 * phi_index;
386 if (!TMath::AreEqualRel(
x, DDE1->
x(), 1.E-8)
387 || !TMath::AreEqualRel(
y, DDE1->
y(), 1.E-8)
388 || !TMath::AreEqualRel(
x, DDE2->
x(), 1.E-8)
389 || !TMath::AreEqualRel(
y, DDE2->
y(), 1.E-8)) {
391 <<
"Error: Incompatibility between FCalChannel map and GEO file \n"
392 <<
x <<
" " << DDE1->
x() <<
" " << DDE2->
x() <<
y <<
" "
393 << DDE1->
y() <<
" " << DDE2->
y() << std::endl;