23 double tdiff1 = fabs(pair1->
ee.first->t-pair1->
ee.second->t);
24 double tdiff2 = fabs(pair2->
ee.first->t-pair2->
ee.second->t);
25 return (tdiff1<tdiff2);
35 DELTA_T_CLUST_MAX = 10.0;
36 DELTA_T_PAIR_MAX = 10.0;
38 gPARMS->SetDefaultParameter(
"PSPair:DELTA_T_CLUST_MAX",DELTA_T_CLUST_MAX,
39 "Maximum difference in ns between hits in a cluster"
40 " in left and right arm of fine PS");
42 gPARMS->SetDefaultParameter(
"PSPair:DELTA_T_PAIR_MAX",DELTA_T_PAIR_MAX,
43 "Maximum difference in ns between a pair of hits"
44 " in left and right arm of fine PS");
65 vector<const DPSHit*> hits;
77 for (
unsigned int ii = 0; ii < hits.size(); ii++) {
78 if( hits[ii]->arm == 0 ) {
80 tmp.
column = hits[ii]->column;
84 tmp.
time = hits[ii]->t;
86 tiles_left.push_back(tmp);
88 if( hits[ii]->arm == 1 ) {
90 tmp.
column = hits[ii]->column;
94 tmp.
time = hits[ii]->t;
96 tiles_right.push_back(tmp);
100 sort(tiles_left.begin(), tiles_left.end(),SortByTile);
101 sort(tiles_right.begin(),tiles_right.end(),SortByTile);
105 vector<int> my_index;
109 cout <<
" Tiles Left Side = " << tiles_left.size() << endl;
111 if(tiles_left.size() > 0){
113 for (
unsigned int ii = 0; ii < tiles_left.size(); ii++){
117 if( tiles_left[ii].used == 1)
continue;
119 tiles_left[ii].used = 1;
121 last_tile = tiles_left[ii].column;
123 my_index.push_back(ii);
125 for (
unsigned int jj = ii + 1; jj < tiles_left.size(); jj++){
126 if(fabs(tiles_left[ii].time - tiles_left[jj].time) < DELTA_T_CLUST_MAX){
127 if( std::abs(tiles_left[jj].
column - last_tile) <= 1){
129 tiles_left[jj].used = 1;
130 last_tile = tiles_left[jj].column;
132 my_index.push_back(jj);
141 clust_left.push_back(tmp);
151 cout <<
" Tiles Right Side = " << tiles_right.size() << endl;
154 if(tiles_right.size() > 0){
156 for (
unsigned int ii = 0; ii < tiles_right.size(); ii++){
160 if( tiles_right[ii].used == 1)
continue;
162 tiles_right[ii].used = 1;
164 last_tile = tiles_right[ii].column;
166 my_index.push_back(ii);
168 for (
unsigned int jj = ii + 1; jj < tiles_right.size(); jj++){
169 if(fabs(tiles_right[ii].time - tiles_right[jj].time) < DELTA_T_CLUST_MAX){
170 if( std::abs(tiles_right[jj].
column - last_tile) <= 1){
172 tiles_right[jj].used = 1;
173 last_tile = tiles_right[jj].column;
175 my_index.push_back(jj);
184 clust_right.push_back(tmp);
191 double max_integral = 0.;
192 double max_peak = 0.;
193 double max_time = 0.;
196 if( clust_left.size() > 0){
197 for(
unsigned ii = 0; ii < clust_left.size(); ii++){
198 unsigned int nhits = clust_left[ii].hit_index.size();
202 double time_tmp = 0.;
206 for(
unsigned jj = 0; jj < nhits; jj++){
207 int index = clust_left[ii].hit_index[jj];
208 en_tmp += tiles_left[
index].energy*tiles_left[
index].integral;
209 time_tmp += tiles_left[
index].time*tiles_left[
index].integral;
210 norm += tiles_left[
index].integral;
211 if(tiles_left[index].integral > max_integral) {
212 max_integral = tiles_left[
index].integral;
213 max_peak = tiles_left[
index].pulse_peak;
214 max_time = tiles_left[
index].time;
215 max_column = tiles_left[
index].column;
219 clust_left[ii].column = max_column;
220 clust_left[ii].energy = en_tmp/norm;
221 clust_left[ii].time = time_tmp/norm;
222 clust_left[ii].integral = max_integral;
223 clust_left[ii].pulse_peak = max_peak;
224 clust_left[ii].time_tile = max_time;
226 clust_left[ii].column = 0;
227 clust_left[ii].energy = 0;
228 clust_left[ii].time = 0;
229 clust_left[ii].integral = 0;
230 clust_left[ii].pulse_peak = 0;
231 clust_left[ii].time_tile = 0;
242 if( clust_right.size() > 0){
243 for(
unsigned ii = 0; ii < clust_right.size(); ii++){
244 unsigned int nhits = clust_right[ii].hit_index.size();
248 double time_tmp = 0.;
253 for(
unsigned jj = 0; jj < nhits; jj++){
254 int index = clust_right[ii].hit_index[jj];
255 en_tmp += tiles_right[
index].energy*tiles_right[
index].integral;
256 time_tmp += tiles_right[
index].time*tiles_right[
index].integral;
257 norm += tiles_right[
index].integral;
258 if(tiles_right[index].integral > max_integral) {
259 max_integral = tiles_right[
index].integral;
260 max_peak = tiles_right[
index].pulse_peak;
261 max_time = tiles_right[
index].time;
262 max_column = tiles_right[
index].column;
266 clust_right[ii].column = max_column;
267 clust_right[ii].energy = en_tmp/norm;
268 clust_right[ii].time = time_tmp/norm;
269 clust_right[ii].integral = max_integral;
270 clust_right[ii].pulse_peak = max_peak;
271 clust_right[ii].time_tile = max_time;
273 clust_right[ii].column = 0;
274 clust_right[ii].energy = 0;
275 clust_right[ii].time = 0;
276 clust_right[ii].integral = 0;
277 clust_right[ii].pulse_peak = 0;
278 clust_right[ii].time_tile = 0;
286 cout <<
" Number of Left clusters found = " << clust_left.size() << endl;
288 for(
unsigned ii = 0; ii < clust_left.size(); ii++){
291 cout <<
" Number of tiles inside the cluster = " <<
292 clust_left[ii].hit_index.size() << endl;
294 for(
unsigned jj = 0; jj < clust_left[ii].hit_index.size(); jj++){
295 int index_l = clust_left[ii].hit_index[jj];
297 cout <<
" Index = " << index_l <<
298 " Tile = " << tiles_left[index_l].column <<
299 " Energy = " << tiles_left[index_l].energy <<
300 " Integral = " << tiles_left[index_l].integral << endl;
304 cout <<
" Cluster ENERGY: " << ii <<
" " << clust_left[ii].energy <<
305 " TIME = " << clust_left[ii].time << endl;
313 cout <<
" Number of Right clusters found = " << clust_right.size() << endl;
317 for(
unsigned ii = 0; ii < clust_right.size(); ii++){
320 cout <<
" Number of tiles inside the cluster = " <<
321 clust_right[ii].hit_index.size() << endl;
323 for(
unsigned jj = 0; jj < clust_right[ii].hit_index.size(); jj++){
324 int index_r = clust_right[ii].hit_index[jj];
326 cout <<
" Index = " << index_r <<
327 " Tile = " << tiles_right[index_r].column <<
328 " Energy = " << tiles_right[index_r].energy <<
329 " Integral = " << tiles_right[index_r].integral << endl;
333 cout <<
" Cluster ENERGY: " << ii <<
" " << clust_right[ii].energy <<
334 " TIME = " << clust_right[ii].time << endl;
339 if( (clust_left.size() > 0) && (clust_right.size() > 0)) {
340 for(
unsigned ii = 0; ii < clust_left.size(); ii++){
341 for(
unsigned jj = 0; jj < clust_right.size(); jj++){
343 if(fabs(clust_left[ii].time - clust_right[jj].time) < DELTA_T_PAIR_MAX){
347 cout <<
" PAIR FOUND: " <<
" E = " <<
348 clust_left[ii].energy + clust_right[jj].energy << endl;
355 pair->
SetPair(clust_left[ii].
column, clust_left[ii].pulse_peak, clust_left[ii].integral, clust_left[ii].time_tile,
356 clust_left[ii].hit_index.size(), clust_left[ii].energy, clust_left[ii].time,
357 clust_right[jj].column, clust_right[jj].pulse_peak, clust_right[jj].integral, clust_right[jj].time_tile,
358 clust_right[jj].hit_index.size(), clust_right[jj].energy, clust_right[jj].time );
360 _data.push_back(pair);
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
bool SortByTimeDifference(const DPSPair *pair1, const DPSPair *pair2)
pair< const PSClust *, const PSClust * > ee
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static bool SortByTile(const tile &tile1, const tile &tile2)
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t fini(void)
Called after last event of last event source has been processed.
static char index(char c)
jerror_t init(void)
Called once at program start.
void SetPair(int column_l, double pulse_peak_l, double integral_l, double t_tile_l, int ntiles_l, double E_l, double t_l, int column_r, double pulse_peak_r, double integral_r, double t_tile_r, int ntiles_r, double E_r, double t_r)