16 using std::binary_search;
17 #include "Sti/Base/Filter.h"
18 #include "Sti/StiDetectorTreeBuilder.h"
19 #include "Sti/StlUtilities.h"
20 #include "Sti/StiCompositeLeafIterator.h"
21 #include "Sti/StiPlacement.h"
22 #include "Sti/StiDetectorContainer.h"
23 ostream& operator<<(ostream&,
const NameMapKey&);
26 StiDetectorContainer::StiDetectorContainer(
const string & name,
27 const string & description,
34 _masterDetectorBuilder(masterBuilder)
36 cout <<
"StiDetectorContainer::StiDetectorContainer() -I- Started/Done"<<endl;
39 StiDetectorContainer::~StiDetectorContainer()
41 cout <<
"StiDetectorContainer::~StiDetectorContainer() -I- Started"<<endl;
46 cout <<
"StiDetectorContainer::~StiDetectorContainer() -I- Done"<<endl;
49 void StiDetectorContainer::initialize()
51 cout <<
"StiDetectorContainer::initialize() -I- Started" << endl;
52 cout <<
"StiDetectorContainer::initialize() -I- Use master builder to build detectors" << endl;
53 build(_masterDetectorBuilder);
54 cout <<
"StiDetectorContainer::initialize() -I- Now extract detectors and add them to the _sortedDetectors" << endl;
55 _sortedDetectors.reserve(1000);
56 _sortedDetectors.clear();
57 _selectedDetectors.clear();
58 vector<StiDetectorBuilder*>::iterator bIter;
59 for (bIter=_masterDetectorBuilder->begin(); bIter!=_masterDetectorBuilder->end(); ++bIter)
61 string name = (*bIter)->getName();
62 ULong_t where = name.find(
"Tpc");
65 cout <<
"StiDetectorContainer::initialize() -I- Skipping group: "<<name<<endl;
68 int nRows = (*bIter)->getNRows();
69 for (
int row=0;row<nRows;row++)
71 int nSectors = (*bIter)->getNSectors(row);
72 for (
int sector=0; sector<nSectors; sector++)
74 StiDetector* detector = (*bIter)->getDetector(row,sector);
75 if (!detector)
continue;
76 if (detector->isActive())
79 cout <<
"StiDetectorContainer::initialize() -I- Not Adding detector unit: "<< detector->
getName()<<endl;
83 cout <<
"StiDetectorContainer::initialize() -I- Done" << endl;
94 assert(layer->getTreeNode() &&
"StiDetectorContainer::setToDetector(StiDetector*) layer->getTreeNode()==0");
95 setToLeaf( layer->getTreeNode() );
104 tempOrderKey.key =
static_cast<double>( StiPlacement::kMidRapidity );
105 mySameOrderKey.morderKey = tempOrderKey;
106 StiDetectorNodeVector::iterator where = find_if(mroot->
begin(), mroot->
end(), mySameOrderKey);
107 assert(where!=mroot->
end() &&
"StiDetectorContainer::setToDetector(StiDetector*) mid-rapidity region not found - where==0");
110 mradial_it = (*mregion)->begin();
111 mphi_it = (*mradial_it)->begin();
116 assert(*mphi_it &&
"StiDetectorContainer::operator*() *mphi_it==0");
118 assert(det &&
"StiDetectorContainer::operator*() *mphi_it==0");
122 StiDetector* StiDetectorContainer::getCurrentDetector()
const
124 assert(*mphi_it &&
"StiDetectorContainer::getCurrentDetector() *mphi_it==0");
126 assert(det &&
"StiDetectorContainer::getCurrentDetector() det==0");
146 if (mradial_it == (*mregion)->begin() ) {
153 StiDetectorNodeVector::const_iterator oldPhiNodeP = mphi_it;
155 bool foundIt =
false;
158 if (rMin >=0 && (*(*mradial_it)->begin())->getData()->getPlacement()->getNormalRadius() < rMin)
161 mphi_it = (*mradial_it)->begin();
165 mphi_it = (*mradial_it)->begin()+oldPhiNode->
getOrderKey().index;
175 double phiDiff = TMath::Abs((*mphi_it)->getData()->getPlacement()->getNormalRefAngle() -
176 oldPhiNode->
getData()->getPlacement()->getNormalRefAngle());
177 if (phiDiff > TMath::Pi()) phiDiff = TMath::TwoPi() - phiDiff;
178 foundIt = (phiDiff <= phiCut);
180 if (foundIt && zCut >= 0) {
181 double zDiff = TMath::Abs((*mphi_it)->getData()->getPlacement()->getZcenter() -
182 oldPhiNode->
getData()->getPlacement()->getZcenter());
183 foundIt = (zDiff <= zCut);
187 mphi_it = oldPhiNodeP;
188 return moveIn(phiCut,zCut);
194 bool StiDetectorContainer::setPhi(
const StiOrderKey& oldOrder)
196 mphi_it = gFindClosestOrderKey((*mradial_it)->begin(),
197 (*mradial_it)->end(), oldOrder);
198 if (mphi_it == (*mradial_it)->end())
200 cout <<
"StiDetectorContainer::setPhiIterator() -E- Find Phi failed"<<endl;
213 cout <<
"StiDetectorContainer::build() -I- Starting"<<endl;
214 cout <<
"StiDetectorContainer::build() -I- Building using builder:"<<builder->
getName()<<endl;
219 mroot = treeBuilder.
build(builder);
220 assert(mroot &&
"StiDetectorContainer::build() mroot==0");
239 cout <<
"StiDetectorContainer::build() -I- Done"<<endl;
255 if (mphi_it == leaf->
end()) {
256 cout <<
"StiDetectorContainer::setToLeaf(StiDetectorNode*). ERROR:\t"
257 <<
"Node not found in parent. Abort"<<endl;
264 if (mradial_it == parentInRadius->
end()) {
265 cout <<
"StiDetectorContainer::setToLeaf(StiDetectorNode*) -E- Node not found in parent. Abort?"<<endl;
277 _sortedDetectors.push_back(det);
278 sort(_sortedDetectors.begin(), _sortedDetectors.end(),
RPhiLessThan());
291 cout <<
"RPhiLessThan::operator() -E- !lhsp || !rhsp "<<endl;
294 if (lhsp->getLayerRadius()<rhsp->getLayerRadius())
296 else if (lhsp->getLayerRadius()>rhsp->getLayerRadius())
300 double la = lhsp->getLayerAngle();
301 double ra = rhsp->getLayerAngle();
302 if ((la<0) != (ra<0)) {
if (la<0) la+=2*M_PI;
if (ra<0) ra+=2*M_PI;}
307 vector<StiDetector*> & StiDetectorContainer::getDetectors()
309 return _sortedDetectors;
312 vector<StiDetector*> & StiDetectorContainer::getDetectors(Filter<StiDetector> & filter)
314 _selectedDetectors.clear();
316 for (vector<StiDetector*>::const_iterator i=_sortedDetectors.begin();
317 i!=_sortedDetectors.end();
321 if (filter.accept(detector))
322 _selectedDetectors.push_back(detector);
324 return _selectedDetectors;
327 vector<StiDetector*>::iterator StiDetectorContainer::begin()
329 cout <<
"StiDetectorContainer::begin() -I- size:"<<_sortedDetectors.size()<<endl;
330 return _sortedDetectors.begin();
333 vector<StiDetector*>::iterator StiDetectorContainer::end()
335 return _sortedDetectors.end();
338 vector<StiDetector*>::const_iterator StiDetectorContainer::begin()
const
340 cout <<
"StiDetectorContainer::begin() const -I- size:"<<_sortedDetectors.size()<<endl;
341 return _sortedDetectors.begin();
344 vector<StiDetector*>::const_iterator StiDetectorContainer::end()
const
346 return _sortedDetectors.end();
void add(StiDetector *det)
Add a detector element to the sorted vector.
bool moveIn(double phiCut=-1.0, double zCut=-1.0, double rMin=-1.0)
Step in radially in STAR TPC global coordinates.
T * getData() const
Return a (non-const!) pointer to the data hung on this node.
StiDetectorNode * build(StiDetectorBuilder *builder)
Build the Detector model.
void setToDetector(const StiDetector *layer)
Set iterators to the detector nearest to the passed StiDetector pointer.
vec_type::iterator whereInParent()
Provide the iterator into the parent that can be dereferenced to get this node.
unsigned int getChildCount() const
Return the number of children that belong to this node.
StiDetector * operator*() const
Dereference current iterator and return a pointer to current StiDetector.
const StiOrderKey & getOrderKey() const
Return a reference to the the orderkey of this node.
virtual void build(StiDetectorBuilder *builder)
Builds the detector tree given a pointer to the detector builder.
void reset()
This performs a full internal reset of interator structure.
vec_type::iterator begin()
Provide random access iterator to the beginning of the vector of children.
vec_type::iterator end()
Provide random access iterator to the end of the vector of children.
StiCompositeTreeNode * getParent() const
Return a (non-const!) pointer to the parent of this node.
const string & getName() const
Get the name of the object.