/* * PndOnlineHitProducer.h * * Created on: Nov. 14, 2012 * Author: Sean Dobbs (s-dobbs@northwestern.edu) */ #include "PndOnlineHitProducer.h" #include void PndOnlineHitProducer::LoadStream(int detector_id, TTree *sim_tree, char * hit_type, char *branch_name) { // debug info cout << "registering detector number " << detector_id << " with hit type " << hit_type << " and branch name " << branch_name << endl; // check if we've already loaded it before, and if we have, deleted it if(hit_collections[detector_id] > 0) { if(hit_collections[detector_id] != NULL) delete hit_collections[detector_id]; } // map the array of hits in hit_collections[detector_id] = new TClonesArray(hit_type); //hit_collections[detector_id] = new TClonesArray("FairHit"); sim_tree->SetBranchAddress(branch_name, &(hit_collections[detector_id])); // save the tree so we can move between events saved_trees[detector_id] = sim_tree; // keep track of the "current" hits //current_hits[detector_id] = NULL; //current_hits[detector_id] = new TClonesArray(hit_type); current_hits[detector_id] = new list< TObject* >(); // keep info of the "current" hits - store the info seperately since we have to deal with various types of incoming //current_hit_indexes[detector_id] = 0; //current_times[detector_id] = 0.0; } void PndOnlineHitProducer::LoadHits(int detector_id) { // for a first try, do the naive thing and load all the hits to start int num_entry = 0; FairHit* myhit = 0; int num_hit = 0; cout << " loading detector " << detector_id << " with " << saved_trees[detector_id]->GetEntriesFast() << " events..." << endl; // loop over entries, which do not correspond to events while (num_entry++ < saved_trees[detector_id]->GetEntriesFast()) { //cerr << " loading entry " << num_entry << endl; saved_trees[detector_id]->GetEntry(num_entry); cerr << " entry " << num_entry << " has " << hit_collections[detector_id]->GetEntriesFast() << " hits " << endl; for (int i=0; iGetEntriesFast(); ++i) { myhit = (FairHit*) (hit_collections[detector_id]->At(i)); //cerr << " loading hit #" << i // << " with timestamp " << myhit->GetTimeStamp() << endl; //cerr << (¤t_hits[detector_id].front()) << endl; //cerr << " loading hit #" << i //<< " with timestamp " << ( (FairHit*)(hit_collections[detector_id]->At(i)) )->GetTimeStamp() << endl; current_hits[detector_id]->push_back( (TObject *)(hit_collections[detector_id]->At(i)->Clone()) ); //current_hits[detector_id][i] = new TObject(*(hit_collections[detector_id]->At(i)->Clone())); //hit_collections[detector_id]->AddLast( hit_collections[detector_id]->At(i)->Clone() ); //hit_collections[detector_id]->AddLast( myhit->Clone() ); //hit_collections[detector_id]->AddLast( myhit ); // DEBUG //std::cout << //myhit->Print(); } } cerr << " number of hits " << current_hits[detector_id]->size() << endl; current_times[detector_id] = ((FairHit*)(*(current_hits[detector_id]->begin())))->GetTimeStamp(); //nexttime = myhit->GetTimeStamp(); } // return all the hits between currtime -> currtime + delta_t // times in ns list *PndOnlineHitProducer::GetHits(int detector_id, double delta_t) { // cerr << cerr << " getting hits from detector " << detector_id; cerr << " with " << current_hits[detector_id]->size() << " events..." << endl; double start_t = current_times[detector_id]; double curr_t = start_t; //TClonesArray *stored_hits = hit_collections[detector_id]; list< TObject* > *stored_hits = current_hits[detector_id]; // make new list of hits //TClonesArray *hit_list = new TClonesArray("FairHit"); list *hit_list = new list; // run over the list of hits int nhits = 0; for(list< TObject* >::iterator it=stored_hits->begin(); it!=stored_hits->end(); ++it) { FairHit *the_hit = (FairHit*)(*it); if( the_hit->GetTimeStamp() < start_t ) continue; else if (the_hit->GetTimeStamp() > start_t + delta_t ) break; else { // if we are in the window of hits that we want, add it to the list //hit_list->AddLast(the_hit); //hit_list[nhits++] = new FairHit(*the_hit); hit_list->push_back(the_hit); curr_t = the_hit->GetTimeStamp(); // ugh, is there something faster? } } // update the current timestamp current_times[detector_id] = curr_t; return hit_list; } // times in ns list *PndOnlineHitProducer::GetHits(int detector_id, double begin_t, double end_t) { double start_t = current_times[detector_id]; double curr_t = start_t; //TClonesArray *stored_hits = hit_collections[detector_id]; list< TObject* > &stored_hits = *(current_hits[detector_id]); // make new list of hits list *hit_list = new list(); // run over the list of hits for(list< TObject* >::iterator it=stored_hits.begin(); it!=stored_hits.end(); ++it) { FairHit *the_hit = (FairHit*)(*it); if( the_hit->GetTimeStamp() < begin_t ) continue; else if (the_hit->GetTimeStamp() > end_t ) break; else { // if we are in the window of hits that we want, add it to the list hit_list->push_back(the_hit); curr_t = the_hit->GetTimeStamp(); // ugh, is there something faster? } } // update the current timestamp current_times[detector_id] = curr_t; return hit_list; } /** // return all the hits between currtime -> currtime + delta_t TClonesArray *PndOnlineHitProducer::GetHits(int detector_id, double delta_t) { double start_t = current_times[detector_id]; double curr_t = start_t; TClonesArray *stored_hits = hit_collections[detector_id]; // make new list of hits TClonesArray *hit_list = new TClonesArray(); // run over the list of hits TIter next(stored_hits); FairHit *the_hit; while( the_hit=(FairHit *)next() ) { if( the_hit->GetTimeStamp() < start_t ) continue; else if (the_hit->GetTimeStamp() > start_t + delta_t ) break; else { // if we are in the window of hits that we want, add it to the list hit_list->AddLast(*next); curr_t = the_hit->GetTimeStamp(); // ugh, is there something faster? } } // update the current timestamp current_times[detector_id] = curr_t; return hit_list; } TClonesArray *PndOnlineHitProducer::GetHits(int detector_id, double begin_t, double end_t) { double start_t = current_times[detector_id]; double curr_t = start_t; TClonesArray *stored_hits = hit_collections[detector_id]; // make new list of hits TClonesArray *hit_list = new TClonesArray(); // run over the list of hits TIter next(stored_hits); FairHit *the_hit; while( the_hit=(FairHit *)next() ) { if( the_hit->GetTimeStamp() < begin_t ) continue; else if (the_hit->GetTimeStamp() > end_t ) break; else { // if we are in the window of hits that we want, add it to the list hit_list->AddLast(*next); curr_t = the_hit->GetTimeStamp(); // ugh, is there something faster? } } // update the current timestamp current_times[detector_id] = curr_t; return hit_list; } **/