6 EventReducer::EventReducer(TString options) : afterhit(false), hodomask(false), outoftime(false), decluster(false), mergehodo(false), triggermask(false), sagitta(false), hough(false), externalpar(false), realization(false), difnim(false)
10 if(options.Contains(
"a")) afterhit =
true;
11 if(options.Contains(
"h")) hodomask =
true;
12 if(options.Contains(
"o")) outoftime =
true;
13 if(options.Contains(
"c")) decluster =
true;
14 if(options.Contains(
"m")) mergehodo =
true;
15 if(options.Contains(
"t")) triggermask =
true;
16 if(options.Contains(
"s")) sagitta =
true;
17 if(options.Contains(
"g")) hough =
true;
18 if(options.Contains(
"e")) externalpar =
true;
19 if(options.Contains(
"r")) realization =
true;
20 if(options.Contains(
"n")) difnim =
true;
24 SAGITTA_TARGET_CENTER = rc->
get_DoubleFlag(
"SAGITTA_TARGET_CENTER");
40 if(afterhit) std::cout <<
"EventReducer: after-pulse removal enabled. " << std::endl;
41 if(hodomask) std::cout <<
"EventReducer: hodoscope masking enabled. " << std::endl;
42 if(outoftime) std::cout <<
"EventReducer: out-of-time hits removal enabled. " << std::endl;
43 if(decluster) std::cout <<
"EventReducer: hit cluster removal enabled. " << std::endl;
44 if(mergehodo) std::cout <<
"EventReducer: v1495 hits will be merged with TW-TDC hits. " << std::endl;
45 if(triggermask) std::cout <<
"EventReducer: trigger road masking enabled. " << std::endl;
46 if(sagitta) std::cout <<
"EventReducer: sagitta reducer enabled. " << std::endl;
47 if(hough) std::cout <<
"EventReducer: hough transform reducer enabled. " << std::endl;
48 if(externalpar) std::cout <<
"EventReducer: will reset the alignment/calibration parameters. " << std::endl;
49 if(realization) std::cout <<
"EventReducer: realization enabled. " << std::endl;
50 if(difnim) std::cout <<
"EventReducer: trigger masking will be disabled in NIM events. " << std::endl;
51 if(fabs(timeOffset) > 0.01) std::cout <<
"EventReducer: " << timeOffset <<
" ns will be added to tdcTime. " << std::endl;
81 bool triggermask_local = triggermask;
84 triggermask_local =
false;
90 for(std::vector<Hit>::iterator iter = rawEvent->fAllHits.begin(); iter != rawEvent->fAllHits.end(); ++iter)
92 if(outoftime && (!iter->isInTime()))
continue;
96 if(realization && rndm.Rndm() > chamEff)
continue;
103 if(triggermask_local && p_geomSvc->
getPlaneType(iter->detectorID) == 1)
continue;
108 iter->pos = p_geomSvc->
getMeasurement(iter->detectorID, iter->elementID);
109 iter->driftDistance = p_geomSvc->
getDriftDistance(iter->detectorID, iter->tdcTime + timeOffset);
113 if(realization && iter->detectorID <=
nChamberPlanes) iter->driftDistance += rndm.Gaus(0., chamResol);
117 hodohitlist.push_back(*iter);
121 hitlist.push_back(*iter);
127 for(std::vector<Hit>::iterator iter = rawEvent->fTriggerHits.begin(); iter != rawEvent->fTriggerHits.end(); ++iter)
129 if(triggermask_local && p_geomSvc->
getPlaneType(iter->detectorID) == 1)
continue;
130 hodohitlist.push_back(*iter);
135 if(triggermask_local) p_triggerAna->
trimEvent(rawEvent, hodohitlist, mergehodo || USE_V1495_HIT, mergehodo || USE_TWTDC_HIT);
143 hitlist.merge(hodohitlist);
144 if(afterhit) hitlist.unique();
153 rawEvent->fAllHits.clear();
154 rawEvent->fAllHits.assign(hitlist.begin(), hitlist.end());
166 int detectorID_st1_max = 12;
167 int detectorID_st2_max = 18;
170 for(std::list<Hit>::iterator iter = hitlist.begin(); iter != hitlist.end(); ++iter)
173 if(iter->detectorID <= detectorID_st1_max)
177 else if(iter->detectorID <= detectorID_st2_max)
186 int idx_D1 = nHits_D1;
187 int idx_D2 = nHits_D1 + nHits_D2;
188 int idx_D3 = nHits_D1 + nHits_D2 + nHits_D3;
191 std::vector<Hit> hitTemp;
192 hitTemp.assign(hitlist.begin(), hitlist.end());
194 std::vector<int> flag(hitTemp.size(), -1);
195 for(
int i = idx_D2; i < idx_D3; ++i)
198 double slope_target = hitTemp[i].pos/(z3 - Z_TARGET);
199 double slope_dump = hitTemp[i].pos/(z3 - Z_DUMP);
200 for(
int j = idx_D1; j < idx_D2; ++j)
205 if(fabs((hitTemp[i].pos - hitTemp[j].pos)/(z2 - z3)) > TX_MAX)
continue;
206 double s2_target = hitTemp[j].pos - slope_target*(z2 - Z_TARGET);
207 double s2_dump = hitTemp[j].pos - slope_dump*(z2 - Z_DUMP);
209 for(
int k = 0; k < idx_D1; ++k)
212 if(flag[i] > 0 && flag[j] > 0 && flag[k] > 0)
continue;
215 double pos_exp_target = SAGITTA_TARGET_CENTER*s2_target + slope_target*(z1 - Z_TARGET);
216 double pos_exp_dump = SAGITTA_DUMP_CENTER*s2_dump + slope_dump*(z1 - Z_DUMP);
217 double win_target = fabs(s2_target*SAGITTA_TARGET_WIDTH);
218 double win_dump = fabs(s2_dump*SAGITTA_DUMP_WIDTH);
220 double p_min = std::min(pos_exp_target - win_target, pos_exp_dump - win_dump);
221 double p_max = std::max(pos_exp_target + win_target, pos_exp_dump + win_dump);
223 if(hitTemp[k].pos > p_min && hitTemp[k].pos < p_max)
234 for(std::list<Hit>::iterator iter = hitlist.begin(); iter != hitlist.end(); )
238 iter = hitlist.erase(iter);
246 if(idx >= idx_D3)
break;
252 std::vector<std::list<Hit>::iterator> cluster;
254 for(std::list<Hit>::iterator hit = hitlist.begin(); hit != hitlist.end(); ++hit)
259 if(cluster.size() == 0)
261 cluster.push_back(hit);
265 if(hit->detectorID != cluster.back()->detectorID)
268 cluster.push_back(hit);
270 else if(hit->elementID - cluster.back()->elementID > 1)
273 cluster.push_back(hit);
277 cluster.push_back(hit);
285 unsigned int clusterSize = cluster.size();
290 double w_max = 0.9*0.5*(cluster.back()->pos - cluster.front()->pos);
291 double w_min = w_max/9.*4.;
293 if((cluster.front()->driftDistance > w_max && cluster.back()->driftDistance > w_min) || (cluster.front()->driftDistance > w_min && cluster.back()->driftDistance > w_max))
295 cluster.front()->driftDistance > cluster.back()->driftDistance ? hitlist.erase(cluster.front()) : hitlist.erase(cluster.back());
297 else if(fabs(cluster.front()->tdcTime - cluster.back()->tdcTime) < 8. && cluster.front()->detectorID >= 19 && cluster.front()->detectorID <= 24)
299 hitlist.erase(cluster.front());
300 hitlist.erase(cluster.back());
308 for(
unsigned int i = 1; i < clusterSize; ++i)
310 dt_mean += fabs(cluster[i]->tdcTime - cluster[i-1]->tdcTime);
312 dt_mean = dt_mean/(clusterSize - 1);
317 for(
unsigned int i = 0; i < clusterSize; ++i)
319 hitlist.erase(cluster[i]);
336 for(
unsigned int i = 1; i < clusterSize - 1; ++i)
338 hitlist.erase(cluster[i]);
349 h2celementID_lo.clear();
350 h2celementID_hi.clear();
352 TString hodoNames[8] = {
"H1B",
"H1T",
"H2B",
"H2T",
"H3B",
"H3T",
"H4B",
"H4T"};
354 for(
int i = 0; i < 8; ++i) hodoIDs[i] = p_geomSvc->
getDetectorID(hodoNames[i].Data());
356 int chamIDs[8][12] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
357 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
358 {13, 14, 15, 16, 17, 18, 0, 0, 0, 0, 0, 0},
359 {13, 14, 15, 16, 17, 18, 0, 0, 0, 0, 0, 0},
360 {0, 0, 0, 0, 0, 0, 25, 26, 27, 28, 29, 30},
361 {19, 20, 21, 22, 23, 24, 0, 0, 0, 0, 0, 0},
362 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
363 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
365 for(
int i = 0; i < 8; ++i)
368 for(
int j = 1; j <= nPaddles; ++j)
371 int uniqueID = hodoIDs[i]*1000 + j;
374 double z0, x0_min, x0_max, y0_min, y0_max;
376 p_geomSvc->
get2DBoxSize(hodoIDs[i], j, x0_min, x0_max, y0_min, y0_max);
378 for(
int k = 0; k < 12; ++k)
380 if(chamIDs[i][k] < 1)
continue;
384 double x_min = x0_min - fabs(TX_MAX*(z - z0));
385 double x_max = x0_max + fabs(TX_MAX*(z - z0));
386 double y_min = y0_min - fabs(TY_MAX*(z - z0));
387 double y_max = y0_max + fabs(TY_MAX*(z - z0));
390 int elementID_hi = 0;
400 double x1, y1, x2, y2;
403 if(!
lineCrossing(x_min, y_min, x_min, y_max, x1, y1, x2, y2) &&
404 !
lineCrossing(x_max, y_min, x_max, y_max, x1, y1, x2, y2))
continue;
406 if(m < elementID_lo) elementID_lo = m;
407 if(m > elementID_hi) elementID_hi = m;
412 if(elementID_lo < 1) elementID_lo = 1;
416 h2celementID_lo[uniqueID].push_back(chamIDs[i][k]*1000 + elementID_lo);
417 h2celementID_hi[uniqueID].push_back(chamIDs[i][k]*1000 + elementID_hi);
423 c2helementIDs.clear();
424 for(LUT::iterator iter = h2celementID_lo.begin(); iter != h2celementID_lo.end(); ++iter)
426 int hodoUID = iter->first;
427 for(
unsigned int i = 0; i < h2celementID_lo[hodoUID].size(); ++i)
429 int chamUID_lo = iter->second[i];
430 int chamUID_hi = h2celementID_hi[hodoUID][i];
431 for(
int j = chamUID_lo; j <= chamUID_hi; ++j)
433 c2helementIDs[j].push_back(hodoUID);
441 for(std::list<Hit>::iterator iter = chamberhits.begin(); iter != chamberhits.end(); )
449 int uniqueID = iter->uniqueID();
452 for(std::vector<int>::iterator jter = c2helementIDs[uniqueID].begin(); jter != c2helementIDs[uniqueID].end(); ++jter)
454 if(std::find(hodohits.begin(), hodohits.end(),
Hit(*jter)) != hodohits.end())
467 iter = chamberhits.erase(iter);
473 double x3,
double y3,
double x4,
double y4)
475 double tc = (x1 - x2)*(y3 - y1) + (y1 - y2)*(x1 - x3);
476 double td = (x1 - x2)*(y4 - y1) + (y1 - y2)*(x1 - x4);
virtual bool get_BoolFlag(const std::string &name) const
void trimEvent(SRawEvent *rawEvent, std::list< Hit > &hitlist, bool USE_TRIGGER_HIT, bool USE_HIT)
virtual double get_DoubleFlag(const std::string &name) const
void get2DBoxSize(int detectorID, int elementID, double &x_min, double &x_max, double &y_min, double &y_max)
static recoConsts * instance()
bool init(std::string fileName, double cut_td=0., double cut_gun=1E8)
bool lineCrossing(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
Definition of hit structure.
void processCluster(std::vector< std::list< Hit >::iterator > &cluster)
EventReducer(TString options)
Int_t getNChamberHitsAll()
int getPlaneType(int detectorID) const
int reduceEvent(SRawEvent *rawEvent)
static GeomSvc * instance()
singlton instance
void hodoscopeMask(std::list< Hit > &chamberhits, std::list< Hit > &hodohits)
void reIndex(bool doSort=false)
Reset the number hits on each plane.
int getExpElementID(int detectorID, double pos_exp)
int getDetectorID(const std::string &detectorName) const
Get the plane position.
int getPlaneNElements(int detectorID)
void getMeasurement(int detectorID, int elementID, double &measurement, double &dmeasurement)
Convert the detectorID and elementID to the actual hit position.
void getWireEndPoints(int detectorID, int elementID, double &x_min, double &x_max, double &y_min, double &y_max)
double getDriftDistance(int detectorID, double tdcTime)
double getPlanePosition(int detectorID) const