11#include <TGraphErrors.h>
18#include "CaloDetDescr/CaloDetDescrElement.h"
20#include "CaloGeoHelpers/CaloSampling.h"
44 for(
int i=0;i<2;++i) {
56 for(
unsigned int i=CaloSampling::PreSamplerB;i<=CaloSampling::FCAL2;++i) {
69 int sampling=cell->getSampling();
124 bool found_overlap=
false;
192 cout<<
"Run another round of ";
209 for(
unsigned int side=0;side<=1;++side)
for(
unsigned int sample=0;sample<
MAX_SAMPLING;++sample)
216 for(t_cellmap::iterator calo_iter=
m_cells.begin();calo_iter!=
m_cells.end();++calo_iter)
225 double eta_raw=theDDE->
eta_raw();
239 double min_eta=theDDE->
eta()-theDDE->
deta()/2;
240 double max_eta=theDDE->
eta()+theDDE->
deta()/2;
244 if(rz_map_eta[side][sample].
find(eta_raw)==rz_map_eta[side][sample].end()) {
245 rz_map_eta [side][sample][eta_raw]=0;
246 rz_map_rmid[side][sample][eta_raw]=0;
247 rz_map_zmid[side][sample][eta_raw]=0;
248 rz_map_rent[side][sample][eta_raw]=0;
249 rz_map_zent[side][sample][eta_raw]=0;
250 rz_map_rext[side][sample][eta_raw]=0;
251 rz_map_zext[side][sample][eta_raw]=0;
252 rz_map_n [side][sample][eta_raw]=0;
254 rz_map_eta [side][sample][eta_raw]+=theDDE->
eta();
255 rz_map_rmid[side][sample][eta_raw]+=theDDE->
r();
256 rz_map_zmid[side][sample][eta_raw]+=theDDE->
z();
257 double drh=theDDE->
dr()/2;
258 double dzh=theDDE->
dz();
259 if(sample<=CaloSampling::EMB3) {
265 rz_map_rent[side][sample][eta_raw]+=theDDE->
r()-drh;
266 rz_map_zent[side][sample][eta_raw]+=theDDE->
z()-dzh*sign_side;
267 rz_map_rext[side][sample][eta_raw]+=theDDE->
r()+drh;
268 rz_map_zext[side][sample][eta_raw]+=theDDE->
z()+dzh*sign_side;
269 rz_map_n [side][sample][eta_raw]++;
274 for(
int side=0;side<=1;++side)
279 if(!rz_map_n[side][sample].
empty())
283 double eta_raw=iter->first;
290 double eta =rz_map_eta[side][sample][eta_raw]/iter->second;
291 double rmid=rz_map_rmid[side][sample][eta_raw]/iter->second;
292 double zmid=rz_map_zmid[side][sample][eta_raw]/iter->second;
293 double rent=rz_map_rent[side][sample][eta_raw]/iter->second;
294 double zent=rz_map_zent[side][sample][eta_raw]/iter->second;
295 double rext=rz_map_rext[side][sample][eta_raw]/iter->second;
296 double zext=rz_map_zext[side][sample][eta_raw]/iter->second;
310 std::cout<<
"rz-map for side="<<side<<
" sample="<<sample<<
" is empty!!!"<<std::endl;
317 m_graph_layers[sample]=
new TGraphErrors(rz_map_n[0][sample].size()+rz_map_n[1][sample].size());
321 for(
int side=0;side<=1;++side) {
323 double eta_raw=iter->first;
325 if(eta_raw>0) sign_side=+1;
327 double rmid=rz_map_rmid[side][sample][eta_raw]/iter->second;
328 double zmid=rz_map_zmid[side][sample][eta_raw]/iter->second;
331 double rext=rz_map_rext[side][sample][eta_raw]/iter->second;
332 double zext=rz_map_zext[side][sample][eta_raw]/iter->second;
351 if (sample < CaloSampling::PreSamplerB || sample >= CaloSampling::Unknown) {
354 TGraph* firstgr=
nullptr;
355 cout<<
"Start sample "<<sample<<
" ("<<
SamplingName(sample)<<
")"<<endl;
361 TGraph*
gr=
new TGraph(5);
362 gr->SetLineColor(TMath::Abs(calocol));
363 gr->SetFillColor(TMath::Abs(calocol));
365 gr->SetFillStyle(1001);
370 double r=theDDE->
r();
371 double dr=theDDE->
dr();
372 double x=theDDE->
x();
373 double dx=theDDE->
dx();
374 double y=theDDE->
y();
375 double dy=theDDE->
dy();
376 double z=theDDE->
z();
377 double dz=theDDE->
dz()*2;
381 if(CaloSampling::PreSamplerB<=sample && sample<=CaloSampling::EMB3) {
385 cout<<
"sample="<<sample<<
" r="<<
r<<
" dr="<<dr<<
" eta="<<
eta<<
" deta="<<
deta<<
" x="<<
x<<
" y="<<
y<<
" z="<<
z<<
" dz="<<dz<<endl;
388 cv.SetPtEtaPhi(
r-dr/2,
eta-
deta/2,0);
389 gr->SetPoint(0,cv.Z(),cv.Pt());
390 gr->SetPoint(4,cv.Z(),cv.Pt());
391 cv.SetPtEtaPhi(
r-dr/2,
eta+
deta/2,0);
392 gr->SetPoint(1,cv.Z(),cv.Pt());
393 cv.SetPtEtaPhi(
r+dr/2,
eta+
deta/2,0);
394 gr->SetPoint(2,cv.Z(),cv.Pt());
395 cv.SetPtEtaPhi(
r+dr/2,
eta-
deta/2,0);
396 gr->SetPoint(3,cv.Z(),cv.Pt());
398 if(sample<CaloSampling::FCAL0) {
399 cv.SetPtEtaPhi(1,
eta-
deta/2,0);cv*=(
z-dz/2)/cv.Z();
400 gr->SetPoint(0,cv.Z(),cv.Pt());
401 gr->SetPoint(4,cv.Z(),cv.Pt());
402 cv.SetPtEtaPhi(1,
eta+
deta/2,0);cv*=(
z-dz/2)/cv.Z();
403 gr->SetPoint(1,cv.Z(),cv.Pt());
404 cv.SetPtEtaPhi(1,
eta+
deta/2,0);cv*=(
z+dz/2)/cv.Z();
405 gr->SetPoint(2,cv.Z(),cv.Pt());
406 cv.SetPtEtaPhi(1,
eta-
deta/2,0);cv*=(
z+dz/2)/cv.Z();
407 gr->SetPoint(3,cv.Z(),cv.Pt());
411 for(
double px=
x-dx/2;px<=
x+dx/2;px+=dx) {
412 for(
double py=
y-dy/2;py<=
y+dy/2;py+=dy) {
413 double pr=TMath::Sqrt(px*px+py*py);
414 minr=TMath::Min(minr,pr);
415 maxr=TMath::Max(maxr,pr);
418 cv.SetXYZ(minr,0,
z-dz/2);
419 gr->SetPoint(0,cv.Z(),cv.Pt());
420 gr->SetPoint(4,cv.Z(),cv.Pt());
421 cv.SetXYZ(maxr,0,
z-dz/2);
422 gr->SetPoint(1,cv.Z(),cv.Pt());
423 cv.SetXYZ(maxr,0,
z+dz/2);
424 gr->SetPoint(2,cv.Z(),cv.Pt());
425 cv.SetXYZ(minr,0,
z+dz/2);
426 gr->SetPoint(3,cv.Z(),cv.Pt());
432 if(ngr==0) firstgr=
gr;
436 cout<<
"Done sample "<<sample<<
" ("<<
SamplingName(sample)<<
")="<<ngr<<endl;
442 TCanvas* c=
new TCanvas(
"CaloGeoForPhi0",
"Calo geometry for #phi~0");
443 TH2D* hcalolayout=
new TH2D(
"hcalolayoutPhi0",
"Reconstruction geometry: calorimeter layout;z [mm];r [mm]",50,-7000,7000,50,0,4000);
445 hcalolayout->SetStats(0);
446 hcalolayout->GetYaxis()->SetTitleOffset(1.4);
448 TLegend* leg=
new TLegend(0.30,0.13,0.70,0.37);
449 leg->SetFillStyle(0);
450 leg->SetFillColor(10);
451 leg->SetBorderSize(1);
457 std::string sname=Form(
"Sampling %2d : ",sample);
459 leg->AddEntry(
gr,sname.c_str(),
"LF");
477 if(sampling<0)
return nullptr;
483 if(!distance) distance=&dist;
487 if(steps) beststeps=(*steps);
491 for(
int skip_range_check=0;skip_range_check<=1;++skip_range_check) {
493 if(!skip_range_check) {
497 if(steps) intsteps=(*steps);
500 cout<<
"CaloGeometry::getDDE : check map"<<j<<
" skip_range_check="<<skip_range_check<<endl;
505 cout<<
"CaloGeometry::getDDE : map"<<j<<
" dist="<<newdist<<
" best dist="<<*distance<<
" steps="<<intsteps<<endl;
507 if(newdist<*distance) {
510 if(steps) beststeps=intsteps;
511 if(newdist<-0.1)
break;
546 if(steps) *steps=beststeps;
551 int isam = sampling - 20;
552 int iphi(-100000),ieta(-100000);
553 Long64_t mask1[]{0x34,0x34,0x35};
554 Long64_t mask2[]{0x36,0x36,0x37};
556 if(steps && found) *steps=0;
562 cout <<
"Error: Unable to find the closest FCal cell!" << endl;
568 Long64_t
id = (ieta << 5) + 2*iphi;
569 if(isam==2)
id+= (8<<8);
573 if(
z>0)
id+=(mask2[isam-1] << 12);
574 else id+=(mask1[isam-1] << 12);
583 if(!distance) distance=&dist;
584 float distanceX = abs(foundcell->
x()-
x) - foundcell->
dx()/2;
585 float distanceY = abs(foundcell->
y()-
y) - foundcell->
dy()/2;
586 *distance =
max(distanceX,distanceY);
596 int isam=sampling-20;
602 const double r = sqrt(
x*
x +
y*
y);
603 if(
r==0.)
return false;
604 const double r_inverse=1./
r;
606 if((
r/rmax)>(rmin*r_inverse)){
659 cout<<
"start CaloGeometry::Validate()"<<endl;
660 for(t_cellmap::iterator ic=m_cells.begin();ic!=m_cells.end();++ic) {
662 int sampling=cell->getSampling();
665 if(m_debug_identify==cell->identify()) {
666 cout<<
"CaloGeometry::Validate(), cell "<<ntest<<
" id="<<cell->identify()<<endl;
670 for(
int irnd=0;irnd<nrnd;++irnd) {
671 std::stringstream pos;
672 std::stringstream cellpos;
673 std::stringstream foundcellpos;
677 bool is_inside_foundcell=
false;
680 float eta=cell->eta()+1.95*(gRandom->Rndm()-0.5)*cell->deta();
681 float phi=cell->phi()+1.95*(gRandom->Rndm()-0.5)*cell->dphi();
682 foundcell=getDDE(sampling,
eta,
phi,&distance,&steps);
684 pos<<
"eta="<<
eta<<
" phi="<<
phi;
685 cellpos<<
"eta="<<cell->eta()<<
" eta_raw="<<cell->eta_raw()<<
" deta="<<cell->deta()
686 <<
" ("<<(cell->eta_raw()-cell->eta())/cell->deta()<<
") ; "
687 <<
"phi="<<cell->phi()<<
" phi_raw="<<cell->phi_raw()<<
" dphi="<<cell->dphi()
688 <<
" ("<<(cell->phi_raw()-cell->phi())/cell->dphi()<<
")";
690 foundcellpos<<
"eta="<<foundcell->
eta()<<
" eta_raw="<<foundcell->
eta_raw()<<
" deta="<<foundcell->
deta()
691 <<
" ("<<(foundcell->
eta_raw()-foundcell->
eta())/foundcell->
deta()<<
") ; "
692 <<
"phi="<<foundcell->
phi()<<
" phi_raw="<<foundcell->
phi_raw()<<
" dphi="<<foundcell->
dphi()
693 <<
" ("<<(foundcell->
phi_raw()-foundcell->
phi())/cell->dphi()<<
")";
694 is_inside_foundcell=TMath::Abs( (
eta-foundcell->
eta())/foundcell->
deta() )<0.55 && TMath::Abs( (
phi-foundcell->
phi())/foundcell->
dphi() )<0.55;
696 is_inside=TMath::Abs( (
eta-cell->eta())/cell->deta() )<0.49 && TMath::Abs( (
phi-cell->phi())/cell->dphi() )<0.49;
698 float x=cell->x()+1.95*(gRandom->Rndm()-0.5)*cell->dx();
699 float y=cell->y()+1.95*(gRandom->Rndm()-0.5)*cell->dy();
701 foundcell=getFCalDDE(sampling,
x,
y,
z);
703 pos<<
"x="<<
x<<
" y="<<
y<<
" z="<<
z;
704 cellpos<<
"x="<<cell->x()<<
" x_raw="<<cell->x_raw()<<
" dx="<<cell->dx()
705 <<
" ("<<(cell->x_raw()-cell->x())/cell->dx()<<
") ; "
706 <<
"y="<<cell->y()<<
" y_raw="<<cell->y_raw()<<
" dy="<<cell->dy()
707 <<
" ("<<(cell->y_raw()-cell->y())/cell->dy()<<
")";
709 foundcellpos<<
"x="<<foundcell->
x()<<
" x_raw="<<foundcell->
x_raw()<<
" dx="<<foundcell->
dx()
710 <<
" ("<<(foundcell->
x_raw()-foundcell->
x())/foundcell->
dx()<<
") ; "
711 <<
"y="<<foundcell->
y()<<
" y_raw="<<foundcell->
y_raw()<<
" dy="<<foundcell->
dy()
712 <<
" ("<<(foundcell->
y_raw()-foundcell->
y())/cell->dy()<<
")";
713 is_inside_foundcell=TMath::Abs( (
x-foundcell->
x())/foundcell->
dx() )<0.75 && TMath::Abs( (
y-foundcell->
y())/foundcell->
dy() )<0.75;
715 is_inside=TMath::Abs( (
x-cell->x())/cell->dx() )<0.49 && TMath::Abs( (
y-cell->y())/cell->dy() )<0.49;
719 if(m_debug && foundcell) {
720 cout<<
"CaloGeometry::Validate(), irnd="<<irnd<<
": cell id="<<cell->identify()<<
", sampling="<<sampling
721 <<
", foundcell id="<<foundcell->
identify()<<
", "<<steps<<
" steps"<<endl;
722 cout<<
" "<<cellpos.str()<<endl;
724 if(cell==foundcell) {
725 if(steps>3 && distance<-0.01) {
726 cout<<
"cell id="<<cell->identify()<<
", sampling="<<sampling<<
" found in "<<steps<<
" steps, dist="<<distance<<
" "<<pos.str()<<endl;
727 cout<<
" "<<cellpos.str()<<endl;
731 cout<<
"cell id="<<cell->identify()<<
" not found!";
732 cout<<
" No cell found in "<<steps<<
" steps, dist="<<distance<<
" "<<pos.str()<<endl;
733 cout<<
" input sampling="<<sampling<<
" "<<cellpos.str()<<endl;
736 if( is_inside && foundcell && !is_inside_foundcell) {
737 cout<<
"cell id="<<cell->identify()<<
" not found, but inside cell area!";
738 cout<<
" Found instead id="<<foundcell->
identify()<<
" in "<<steps<<
" steps, dist="<<distance<<
" "<<pos.str()<<endl;
739 cout<<
" input sampling="<<sampling<<
" "<<cellpos.str()<<endl;
740 cout<<
" output sampling="<<foundcell->
getSampling()<<
" "<<foundcellpos.str()<<endl;
746 if(ntest%25000==0) cout<<
"Validate cell "<<ntest<<
" with "<<nrnd<<
" random hits"<<endl;
749 cout<<
"end CaloGeometry::Validate()"<<endl;
762 return fabs(
eta-mineta);
766 return fabs(
eta-maxeta);
770 double d1=fabs(
eta-mineta);
771 double d2=fabs(
eta-maxeta);
772 if(d1<d2)
return -d1;
809 else return m_zmid_map[side][sample].find_closest(
eta)->second;
834 else return m_zent_map[side][sample].find_closest(
eta)->second;
859 else return m_zext_map[side][sample].find_closest(
eta)->second;
910 double x(0.),
y(0.),
r(0.);
924 unsigned long long phi_index,eta_index;
928 long mask1[]{0x34,0x34,0x35};
929 long mask2[]{0x36,0x36,0x37};
935 for(
int imap=1;imap<=3;imap++){
937 int sampling = imap+20;
940 cout <<
"Error: Incompatibility between FCalChannel map and GEO file: Different number of cells in m_cells_in_sampling and FCal_ChannelMap" << endl;
949 phi_index = it->first & 0xffff;
950 eta_index = it->first >> 16;
955 id=(mask1[imap-1]<<12) + (eta_index << 5) +2*phi_index;
957 if(imap==2)
id+= (8<<8);
962 id=(mask2[imap-1]<<12) + (eta_index << 5) +2*phi_index;
963 if(imap==2)
id+= (8<<8);
967 if(!TMath::AreEqualRel(
x, DDE1->
x(),1.E-8) || !TMath::AreEqualRel(
y, DDE1->
y(),1.E-8) || !TMath::AreEqualRel(
x, DDE2->
x(),1.E-8) || !TMath::AreEqualRel(
y, DDE2->
y(),1.E-8) ){
968 cout <<
"Error: Incompatibility between FCalChannel map and GEO file \n" <<
x <<
" " << DDE1->
x() <<
" " << DDE2->
x() <<
y <<
" " << DDE1->
y() <<
" " << DDE2->
y() << endl;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
const int CaloGeometry_calocol[24]
void print(char *figname, TCanvas *c1)
static const Attributes_t empty
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
This class groups all DetDescr information related to a CaloCell.
float y_raw() const
cell y_raw
float eta_raw() const
cell eta_raw
float dphi() const
cell dphi
CaloCell_ID::CaloSample getSampling() const
cell sampling
float x_raw() const
cell x_raw
Identifier identify() const override final
cell identifier
float eta() const
cell eta
float phi() const
cell phi
float phi_raw() const
cell phi_raw
float deta() const
cell deta
void merge_into_ref(CaloGeometryLookup *ref)
std::vector< FSmap< double, double > > m_zent_map[2]
virtual void InitRZmaps()
double deta(int sample, double eta) const
std::vector< t_cellmap > m_cells_in_sampling
std::vector< t_eta_cellmap > m_cells_in_sampling_for_phi0
virtual void post_process(int layer)
std::vector< double > m_max_eta_sample[2]
double zmid(int sample, double eta) const
double rent(int sample, double eta) const
bool isCaloBarrel(int sample) const
double zent(int sample, double eta) const
std::vector< FSmap< double, double > > m_rext_map[2]
virtual const CaloDetDescrElement * getFCalDDE(int sampling, float x, float y, float z, float *distance=0, int *steps=0) const
std::vector< FSmap< double, double > > m_zext_map[2]
FCAL_ChannelMap m_FCal_ChannelMap
std::vector< FSmap< double, double > > m_zmid_map[2]
double rmid(int sample, double eta) const
static std::string SamplingName(int sample)
static std::atomic< bool > m_debug
virtual bool PostProcessGeometry()
TGraph * DrawGeoSampleForPhi0(int sample, int calocol, bool print=false)
static const int MAX_SAMPLING
double zpos(int sample, double eta, int subpos=CaloSubPos::SUBPOS_MID) const
double rzpos(int sample, double eta, int subpos=CaloSubPos::SUBPOS_MID) const
void calculateFCalRminRmax()
bool getClosestFCalCellIndex(int sampling, float x, float y, int &ieta, int &iphi, int *steps=0) const
double rext(int sample, double eta) const
virtual void PrintMapInfo(int i, int j)
virtual const CaloDetDescrElement * getDDE(Identifier identify) const
double rzmid(int sample, double eta) const
std::vector< double > m_min_eta_sample[2]
std::vector< TGraphErrors * > m_graph_layers
TCanvas * DrawGeoForPhi0()
std::vector< double > m_FCal_rmin
virtual void addcell(const CaloDetDescrElement *cell)
void minmaxeta(int sample, double eta, double &mineta, double &maxeta) const
std::vector< std::vector< CaloGeometryLookup * > > m_cells_in_regions
double zext(int sample, double eta) const
virtual bool checkFCalGeometryConsistency()
static const Identifier m_debug_identify
std::vector< FSmap< double, double > > m_rmid_map[2]
double rzext(int sample, double eta) const
double rpos(int sample, double eta, int subpos=CaloSubPos::SUBPOS_MID) const
std::vector< bool > m_isCaloBarrel
std::vector< FSmap< double, double > > m_rent_map[2]
std::vector< double > m_FCal_rmax
double rzent(int sample, double eta) const
static constexpr unsigned int barrelPattern()
Get the bit-pattern for barrel samplings.
static std::string getSamplingName(CaloSample theSample)
Returns a string (name) for each CaloSampling.
static unsigned int getSamplingPattern(const CaloSample s)
Get a unsigned with one bit set.
std::map< _Key, _Tp >::iterator iterator
std::string find(const std::string &s)
return a remapped string