58
53
std::vector<SciFiDigit*> SciFiClusterRec::get_seeds(SciFiEvent &evt) {
59
54
std::vector<SciFiDigit*> seeds_in_event;
60
for ( unsigned int dig = 0; dig < evt.digits().size(); dig++ ) {
55
for ( size_t dig = 0; dig < evt.digits().size(); ++dig ) {
61
56
if ( evt.digits()[dig]->get_npe() > _min_npe/2.0 )
62
57
seeds_in_event.push_back(evt.digits()[dig]);
64
59
return seeds_in_event;
67
void SciFiClusterRec::make_clusters(SciFiEvent &evt, std::vector<SciFiDigit*> &seeds) {
68
int seeds_size = seeds.size();
69
for ( int i = 0; i < seeds_size; i++ ) {
70
if ( !seeds[i]->is_used() ) {
62
void SciFiClusterRec::make_clusters(SciFiEvent &evt, std::vector<SciFiDigit*> &seeds) {
63
size_t seeds_size = seeds.size();
64
for ( size_t i = 0; i < seeds_size; i++ ) {
65
if ( !(seeds[i]->is_used()) ) {
71
66
SciFiDigit* neigh = NULL;
72
67
SciFiDigit* seed = seeds[i];
74
69
double pe = seed->get_npe();
75
70
// Look for a neighbour.
76
for ( int j = i+1; j < seeds_size; j++ ) {
71
for ( size_t j = i+1; j < seeds_size; ++j ) {
77
72
if ( are_neighbours(seeds[i], seeds[j]) ) {
98
93
void SciFiClusterRec::process_cluster(SciFiCluster *clust) {
99
// Get the MiceModule of the plane...
100
94
int tracker = clust->get_tracker();
101
95
int station = clust->get_station();
102
96
int plane = clust->get_plane();
103
const MiceModule* this_plane = NULL;
104
this_plane = find_plane(tracker, station, plane);
105
assert(this_plane != NULL);
106
// compute it's direction & position in TRF...
107
ThreeVector trf_dir(0., 1., 0.);
108
ThreeVector trf_pos(0., 0., 0.);
110
construct(clust, this_plane, trf_dir, trf_pos, alpha);
112
clust->set_direction(trf_dir);
113
clust->set_position(trf_pos);
115
clust->set_alpha(alpha);
116
int id = 15*tracker + 3*(station-1) + (plane);
98
int id = 3*(station-1) + (plane+1);
99
id = ( tracker == 0 ? -id : id );
117
100
clust->set_id(id);
119
std::cerr << "----------Clustering--------- \n"
120
<< "Site ID: " << id << "\n"
121
<< "Tracker " << tracker << ", station " << station << ", plane " << plane << "\n"
122
<< "Fibre direction: " << dir << "\n"
123
<< "Position: " << tracker_ref_frame_pos << "\n";
127
void SciFiClusterRec::construct(SciFiCluster *clust,
128
const MiceModule* this_plane,
130
ThreeVector &tracker_ref_frame_pos,
132
ThreeVector perp(-1., 0., 0.);
134
CLHEP::HepRotation zflip;
135
const Hep3Vector rowx(-1., 0., 0.);
136
const Hep3Vector rowy(0., 1., 0.);
137
const Hep3Vector rowz(0., 0., -1.);
138
zflip.setRows(rowx, rowy, rowz);
139
G4RotationMatrix trot(this_plane->globalRotation());
140
// Rotations of the planes in the Tracker Reference Frame.
141
if ( clust->get_tracker() == 0 ) {
145
} else if ( clust->get_tracker() == 1 ) {
102
std::map<int, SciFiPlaneGeometry>::iterator iterator;
103
iterator = _geometry_map.find(id);
104
// Throw if the plane isn't found.
105
if ( iterator == _geometry_map.end() ) {
106
throw(Squeal(Squeal::nonRecoverable,
107
"Failed to find SciFi plane in _geometry_map.",
108
"SciFiClusterRec::process_cluster"));
110
SciFiPlaneGeometry this_plane = (*iterator).second;
111
ThreeVector plane_direction = this_plane.Direction;
112
ThreeVector plane_position = this_plane.Position;
113
double Pitch = this_plane.Pitch;
114
double CentralFibre = this_plane.CentralFibre;
115
// alpha is the distance to the central fibre.
116
double alpha = clust->get_channel()-CentralFibre;
117
double dist_mm = Pitch * 7.0 / 2.0 * alpha;
150
double Pitch = this_plane->propertyDouble("Pitch");
151
double CentralFibre = this_plane->propertyDouble("CentralFibre");
152
double dist_mm = Pitch * 7.0 / 2.0 * (clust->get_channel() - CentralFibre);
153
ThreeVector plane_position = clhep_to_root(this_plane->globalPosition());
119
ThreeVector perp = plane_direction.Orthogonal();
154
120
ThreeVector position = dist_mm * perp + plane_position;
155
ThreeVector reference = get_reference_frame_pos(clust->get_tracker());
157
tracker_ref_frame_pos = position - reference;
159
// ThreeVector tracker_ref_frame_pos;
160
if ( clust->get_tracker() == 0 ) {
161
tracker_ref_frame_pos = - (position - reference);
162
} else if ( clust->get_tracker() == 1 ) {
163
tracker_ref_frame_pos = position - reference;
166
alpha = clust->get_channel() - CentralFibre;
167
if ( clust->get_tracker() == 1 ) {
172
const MiceModule* SciFiClusterRec::find_plane(int tracker, int station, int plane) {
173
const MiceModule* scifi_plane = NULL;
174
for ( unsigned int j = 0; !scifi_plane && j < _modules.size(); j++ ) {
175
// Find the right module
176
if ( _modules[j]->propertyExists("Tracker", "int") &&
177
_modules[j]->propertyExists("Station", "int") &&
178
_modules[j]->propertyExists("Plane", "int") &&
179
_modules[j]->propertyInt("Tracker") ==
181
_modules[j]->propertyInt("Station") ==
183
_modules[j]->propertyInt("Plane") ==
186
scifi_plane = _modules[j];
192
ThreeVector SciFiClusterRec::get_reference_frame_pos(int tracker) {
193
// Reference plane is plane 0, station 1 of current tracker.
196
const MiceModule* reference_plane = NULL;
197
reference_plane = find_plane(tracker, station, plane);
199
assert(reference_plane != NULL);
200
ThreeVector reference_pos = clhep_to_root(reference_plane->globalPosition());
202
return reference_pos;
122
clust->set_direction(plane_direction);
123
clust->set_position(position);
124
clust->set_alpha(alpha);
205
127
bool SciFiClusterRec::are_neighbours(SciFiDigit *seed_i, SciFiDigit *seed_j) {
206
128
bool neigh = false;
208
if ( !seed_j->is_used() && // seed is unused
130
if ( !(seed_j->is_used()) && // seed is unused
209
131
seed_j->get_spill() == seed_i->get_spill() && // same spill
210
132
seed_j->get_event() == seed_i->get_event() && // same event
211
133
seed_j->get_tracker() == seed_i->get_tracker() && // same tracker