ATLAS Offline Software
Loading...
Searching...
No Matches
VP1CaloCellManager.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9#include <QCheckBox>
10#include <QDoubleSpinBox>
11
13 VP1CC_SoNode2CCMap* node2cc,
14 bool useEt,
15 const QPair<bool,double>& scale,
16 bool outline,
17 const VP1CC_GlobalCuts& globalCuts):
18 m_type(type),
19 m_node2cc(node2cc),
20 m_useEt(useEt),
21 m_scale(scale),
22 m_outline(outline),
23 m_globalCuts(globalCuts)
24{
25 // Initialize private iterators
30
32}
33
35{
36 // Clear multimaps
38 while(it!=m_positiveCells.end()) {
39 if(it->second) {
40 delete it->second;
41 it->second = 0;
42 }
43 ++it;
44 }
45
46 it = m_negativeCells.begin();
47 while(it!=m_negativeCells.end()) {
48 if(it->second) {
49 delete it->second;
50 it->second = 0;
51 }
52 ++it;
53 }
54
55 m_positiveCells.clear();
56 m_negativeCells.clear();
57}
58
60{
61 double energy = cell->getCaloCell()->energy();
62
63 if(m_useEt)
64 energy = cell->energyToTransverse(energy);
65
66 // We need to choose which map to add the new cell to according to its energy sign
67 VP1CCMultimap& useMap = energy < 0 ? m_negativeCells : m_positiveCells;
68
69 // This is going to be the new key in the map
70 double ccKey = fabs(energy);
71
72 // Add new element to the map
73 useMap.emplace(ccKey,cell);
74}
75
76// ----------------- Slots --------------------------
78{
79 VP1CCIntervalMap::const_iterator it = intervals.find(m_type);
80 if(it!=intervals.end()) {
81 // Update scene with pos/neg cells
82 updateScene(it->first,true);
83 updateScene(it->second,false);
84 }
85}
86
87void VP1CaloCellManager::scaleUpdated(const QPair<bool,double>& new_scale)
88{
89 m_scale = new_scale;
90
91 // Redraw objects with new scale
92 // Pos
94 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
95 }
96
97 // Neg
99 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
100 }
101}
102
103void VP1CaloCellManager::outlineUpdated(const bool& new_outline)
104{
105 m_outline = new_outline;
106
107 // Redraw objects with new outline settings
108 // Pos
110 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
111 }
112
113 // Neg
115 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
116 }
117}
118
127
129{
130 m_globalCuts.clipRadius=radius; // Adjust radius to match new value
132 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
134 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
135}
136
137// ----------------- Private methods ------------------------
138void VP1CaloCellManager::updateScene(const VP1Interval& newInterval, bool positive)
139{
140 // We need to choose which map to work with, according to the value of 'positive' flag
141 VP1CCMultimap* useMap = 0;
142 VP1CCMultimapIterator* useItFirst = 0;
143 VP1CCMultimapIterator* useItLast = 0;
144 VP1Interval* currentInterval = 0;
145
146 if(positive) {
147 useMap = &m_positiveCells;
148 useItFirst = &m_firstDisplayedPos;
149 useItLast = &m_lastDisplayedPos;
150 currentInterval = &m_intervals.first;
151 } else {
152 useMap = &m_negativeCells;
153 useItFirst = &m_firstDisplayedNeg;
154 useItLast = &m_lastDisplayedNeg;
155 currentInterval = &m_intervals.second;
156 }
157
158 // If new iterval is equal to the existing one just check global cuts
159 if(*currentInterval==newInterval) {
160 for(VP1CCMultimapIterator it=*useItFirst; it!=*useItLast; ++it)
161 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
162 return;
163 }
164
165 // If new interval is empty hide everything and update the current interval
166 if(newInterval.isEmpty()) {
167 for(VP1CCMultimapIterator it=*useItFirst; it!=*useItLast; ++it)
168 it->second->remove3DObjects(m_node2cc);
169 *currentInterval = newInterval;
170 *useItFirst = useMap->end();
171 *useItLast = useMap->end();
172 return;
173 }
174
175 // If old interval was empty, find values for first & last iterators and
176 // display everything between them, taking into account global cuts
177 if(currentInterval->isEmpty()) {
178 *useItFirst = useMap->lower_bound(newInterval.lower());
179 if(newInterval.upper() == VP1Interval::inf())
180 *useItLast = useMap->end();
181 else
182 *useItLast = useMap->upper_bound(newInterval.upper());
183
184 for(VP1CCMultimapIterator it=*useItFirst; it!=*useItLast; ++it)
185 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
186
187 *currentInterval = newInterval;
188 return;
189 }
190
191 // No one is empty.
192 VP1CCMultimapIterator newIterator;
193
194 if(currentInterval->lower() != newInterval.lower() &&
195 currentInterval->upper() != newInterval.upper()) {
196 // This is unexpected!
197 // Hide everything what was there before and display new thresholds
198 for(VP1CCMultimapIterator it=*useItFirst; it!=*useItLast; ++it)
199 it->second->remove3DObjects(m_node2cc);
200
201 *useItFirst = useMap->lower_bound(newInterval.lower());
202 if(newInterval.upper() == VP1Interval::inf())
203 *useItLast = useMap->end();
204 else
205 *useItLast = useMap->upper_bound(newInterval.upper());
206
207 for(VP1CCMultimapIterator it=*useItFirst; it!=*useItLast; ++it)
208 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
209
210 } else if (currentInterval->lower() != newInterval.lower()) {
211 // Adjust lower threshold
212 newIterator = useMap->lower_bound(newInterval.lower());
213
214 if(currentInterval->lower() < newInterval.lower())
215 // May need to hide something
216 for(VP1CCMultimapIterator it=*useItFirst; it!=newIterator; ++it)
217 it->second->remove3DObjects(m_node2cc);
218 else
219 // May need to add new objects to the scene
220 for(VP1CCMultimapIterator it=newIterator; it!=*useItFirst; ++it)
221 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
222
223 *useItFirst = newIterator;
224
225 } else {
226
227 // Adjust upper threshold
228 if(newInterval.upper() == VP1Interval::inf()) {
229 newIterator = useMap->end();
230
231 // May need to add new objects to the scene
232 for(VP1CCMultimapIterator it=*useItLast; it!=newIterator; ++it)
233 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
234 } else {
235 newIterator = useMap->upper_bound(newInterval.upper());
236
237 if(*useItLast == useMap->end() ||
238 currentInterval->upper() > newInterval.upper()) {
239 // May need to hide something
240 for(VP1CCMultimapIterator it=newIterator; it!=*useItLast; ++it)
241 it->second->remove3DObjects(m_node2cc);
242 } else {
243 // May need to add new objects to the scene
244 for(VP1CCMultimapIterator it=*useItLast; it!=newIterator; ++it)
245 it->second->updateScene(m_node2cc,m_useEt,m_scale,m_outline,m_globalCuts);
246 }
247 }
248 *useItLast = newIterator;
249 }
250
251 *currentInterval = newInterval;
252}
VP1CCMultimap::iterator VP1CCMultimapIterator
std::multimap< double, VP1CaloCell * > VP1CCMultimap
QPair< VP1Interval, VP1Interval > VP1CCIntervalPair
QMap< VP1CC_SelectionTypes, VP1CCIntervalPair > VP1CCIntervalMap
VP1CC_SelectionTypes
std::map< SoNode *, VP1CaloCell *, std::less< SoNode * > > VP1CC_SoNode2CCMap
void updateScene(const VP1Interval &newInterval, bool positive)
QPair< bool, double > m_scale
VP1CC_GlobalCuts m_globalCuts
void selectionUpdated(const VP1CCIntervalMap &)
void clipVolumeRadiusChanged(double radius)
void globalCutsUpdated(const VP1CC_GlobalCuts &)
VP1CCMultimapIterator m_firstDisplayedPos
VP1CaloCellManager(VP1CC_SelectionTypes type, VP1CC_SoNode2CCMap *node2cc, bool useEt, const QPair< bool, double > &scale, bool outline, const VP1CC_GlobalCuts &globalCuts)
void scaleUpdated(const QPair< bool, double > &)
VP1CCMultimap m_positiveCells
VP1CCMultimapIterator m_lastDisplayedPos
void outlineUpdated(const bool &)
void add(VP1CaloCell *cell)
VP1CCMultimapIterator m_lastDisplayedNeg
VP1CCIntervalPair m_intervals
VP1CCMultimap m_negativeCells
VP1CCMultimapIterator m_firstDisplayedNeg
VP1CC_SelectionTypes m_type
VP1CC_SoNode2CCMap * m_node2cc
double lower() const
bool isEmpty() const
static double inf()
Definition VP1Interval.h:25
double upper() const