#include "PndOnlineSTTStdTSF.h" #include "TGraph.h" #include "TFitResult.h" // return value here sucks PndOnlineTrack *PndOnlineSTTStdTSF::FindTrackSegment(vector< list > &hit_channel_map) { vector segment_hits; PndOnlineTrack *new_track = NULL; bool layer1_hit = CheckHit(channel_list[0], hit_channel_map, segment_hits) || CheckHit(channel_list[3], hit_channel_map, segment_hits) || CheckHit(channel_list[7], hit_channel_map, segment_hits); bool layer2_hit = CheckHit(channel_list[1], hit_channel_map, segment_hits) || CheckHit(channel_list[5], hit_channel_map, segment_hits); bool layer3_hit = CheckHit(channel_list[4], hit_channel_map, segment_hits); bool layer4_hit = CheckHit(channel_list[2], hit_channel_map, segment_hits) || CheckHit(channel_list[6], hit_channel_map, segment_hits); int num_hit_layers = 0; if(layer1_hit) num_hit_layers++; if(layer2_hit) num_hit_layers++; if(layer3_hit) num_hit_layers++; if(layer4_hit) num_hit_layers++; //cout << " there are " << num_hit_layers << " layers with hits in them!" << endl; /* if(num_hit_layers == 4) { // check for full track segment return true; } else if(num_hit_layers == 3) { // check for partial track segment return true; } else { return false; } */ if( (num_hit_layers == 4) || (num_hit_layers == 3) ) { // build track segment //PndOnlineTrack *new_track = new PndOnlineTrack(); new_track = new PndOnlineTrack(); // hits are ordered by first layer -> last layer new_track->SetVertex( TVector3(segment_hits[0]->X(), segment_hits[0]->Y(), segment_hits[0]->Z() ) ); // hack to get rough direction (for testing!) double n = segment_hits.size(); double *x = new double[8]; double *y = new double[8]; for(int i=0; iX(); y[i] = segment_hits[i]->Y(); } TGraph gr(n, x, y); TFitResultPtr r = gr.Fit("1 ++ x","S"); //cout << "RESULT = " << r->Value(0) << " " << r->Value(1) << endl; // can only figure out transverse momentum here double sign = segment_hits[0]->X() > 0 ? 1. : -1.; new_track->SetMomentum( TVector3(sign, r->Value(1), 0.).Unit() ); delete x,y; //new_track->Momentum().Print(); //new_track->Vertex().Print(); // guess t0 is the time of the oldest hit double best_t0 = segment_hits[0]->BaseHit()->GetTimeStamp(); segment_hits[0]->SetStatus(PndOnlineTrackHit::kAssigned); for(int the_hit=1; the_hitSetStatus(PndOnlineTrackHit::kAssigned); if(best_t0 > segment_hits[the_hit]->BaseHit()->GetTimeStamp()) best_t0 = segment_hits[the_hit]->BaseHit()->GetTimeStamp(); } new_track->SetT0(best_t0); new_track->Hits() = segment_hits; cout << " the new track has " << new_track->Hits().size() << " hits " << endl; } return new_track; }