|
//____________________________________________________________________ // // BrTpcAddSeqModule // // This class adds TPCSequences together in order to do effisiency // analysis on the TPC's. Give a digitized geant track and a real event to // to the event method and it merges them togehter. // // Author : T.M.Larsen //____________________________________________________________________ // // $Id: BrTpcAddSeqModule.cxx,v 1.2 2002/01/03 19:53:04 cholm Exp $ // $Author: cholm $ // $Date: 2002/01/03 19:53:04 $ // $Copyright: (C) 2001 BRAHMS Collaboration <brahmlib@rhic.bnl.gov> // #ifndef BRAT_BrTpcAddSeqModule #include "BrTpcAddSeqModule.h" #endif #ifndef ROOT_TDirectory #include "TDirectory.h" #endif #ifndef WIN32 #include <iostream> #else #include <iostream.h> #endif #ifndef BRAT_BrTableNames #include "BrTableNames.h" #endif //____________________________________________________________________ ClassImp(BrTpcAddSeqModule); //____________________________________________________________________ BrTpcAddSeqModule::BrTpcAddSeqModule() : BrModule() { // Default constructor. Should not be used ... SetState(kSetup); fAddedSeq = NULL; } //____________________________________________________________________ BrTpcAddSeqModule::BrTpcAddSeqModule(const Char_t* name, const Char_t* title) : BrModule(name, title) { // Named Constructor SetState(kSetup); fAddedSeq = NULL; } //____________________________________________________________________ BrTpcAddSeqModule::~BrTpcAddSeqModule() { // the destructor } //____________________________________________________________________ void BrTpcAddSeqModule::DefineHistograms() { // Define histograms. They are: // <fill in here> if (GetState() != kInit) { Stop("DefineHistograms", "Must be called after Init"); return; } TDirectory* saveDir = gDirectory; TDirectory* histDir = gDirectory->mkdir(GetName()); histDir->cd(); // Make histograms here gDirectory = saveDir; } //____________________________________________________________________ void BrTpcAddSeqModule::Init() { // Job-level initialisation SetState(kInit); } //____________________________________________________________________ void BrTpcAddSeqModule::Begin() { // Run-level initialisation SetState(kBegin); } //__________________________________________________________________ void BrTpcAddSeqModule::AddSequence(BrTpcSequence* sequence) { //function that adds the sequences together if (fAddedSeq == 0) { fAddedSeq = new BrTpcSequence(*sequence); fAddedSeq->SetClustNum(-1); } //only adds them together if they belong to the same padrow. else if (sequence->GetPad() == fAddedSeq->GetPad() && sequence->GetRow() == fAddedSeq->GetRow()) { //Figuring out if the addedseq needs to be enlarged i.e. finding //out earliest start time and latest stoptime. Int_t start = sequence->GetTime(); Int_t stop = start + sequence->GetNseq(); if (fAddedSeq->GetTime() > start && fAddedSeq->GetTime() + fAddedSeq->GetNseq() >= stop) Enlarge(start, fAddedSeq->GetTime() + fAddedSeq->GetNseq() - 1); else if (fAddedSeq->GetTime() > start && fAddedSeq->GetTime() + fAddedSeq->GetNseq() < stop) Enlarge(start, stop); else if (fAddedSeq->GetTime() <= start && fAddedSeq->GetTime() + fAddedSeq->GetNseq() < stop) Enlarge(fAddedSeq->GetTime(), stop); //Add the sequence to addedseq; Int_t i = start - fAddedSeq->GetTime(); //counter for addedseq Int_t k = 0; //counter for sequence //go through the sequence to be added while (k < sequence->GetNseq()) { fAddedSeq->SetAdc(i, fAddedSeq->GetAdc(i) + sequence->GetAdc(k)); i++; k++; } } else { Char_t warningtext[120]; sprintf(warningtext, "Try to add sequence (pad %d row %d) to (pad %d row %d)", sequence->GetPad(), sequence->GetRow(), fAddedSeq->GetPad(), fAddedSeq->GetRow()); Warning("Add", warningtext); } } // end of Add(); //__________________________________________________________________ void BrTpcAddSeqModule::Enlarge(Short_t start, Short_t stop) { //Makes addedsequences array of timebins larger BrTpcSequence* temp = new BrTpcSequence(stop - start + 1); temp->SetClustNum(-1); //Setting variables in the new TPCSequence temp->SetTime(start); temp->SetPad(fAddedSeq->GetPad()); temp->SetRow(fAddedSeq->GetRow()); Int_t i = 0; //Set first values to zero if the new sequence starts before the old one while(start + i < fAddedSeq->GetTime()) { temp->SetAdc(i, 0); i++; } Int_t k = 0; //Add the old values in the sequence to the new one in the right places while (k < fAddedSeq->GetNseq()) { temp->SetAdc(i, fAddedSeq->GetAdc(k)); i++; k++; } //Set last values to zero if the new sequence ends after the old one while (start + i <= stop) { temp->SetAdc(i, 0); i++; } //delete the old addedseq delete fAddedSeq; fAddedSeq = temp; } //end of Enlarge; //____________________________________________________________________ void BrTpcAddSeqModule::Event(BrEventNode* inNode, BrEventNode* outNode) { // Per event method // Give two events, add the datatables together and put the results // in the resultnode. The resultnode needs to be initiated before // the user calls this. // // The inputnode must contain to nodes: // // inputnode--|- "Geant Digitized" node // | // |- "raw" node // // check that all the nessecery objects are present SetState(kEvent); Debug(1,"Event","Staring to add the seq together! Detector is %s", GetName()); if (inNode == 0 || outNode == 0) { Warning("Event","Not all arguments were initiated"); SetStatus(kFailure); return; } //add the two nodes together BrEventNode *geantnode = inNode->GetEventNode("Geant Digitized"); BrEventNode *rawnode = inNode->GetEventNode("raw"); if (!geantnode) { Warning("Event","Unable to find the "Geant Digitized" node in input!"); SetStatus(kFailure); return; } if (!rawnode) { Warning("Event", "Unable to find the "raw" node in input!"); SetStatus(kFailure); return; } Char_t TableName[32]; sprintf(TableName,"%s %s", BRTABLENAMES kTPCSequence, GetName()); BrDataTable *datatable1 = geantnode->GetDataTable(TableName); BrDataTable *datatable2 = rawnode->GetDataTable(TableName); if (!datatable1 || !datatable2) { Warning("Event", "There are missing datatables in the nodes!"); SetStatus(kFailure); return; } // now we are ready to add the seq together TList *seqarray1 = new TList(); TList *seqarray2 = new TList(); //Sort the datatables if they are sortable datatable1->Sort(); datatable2->Sort(); //Put datatable1 in a list for faster finding of sequences; for (Int_t i = 0; i < datatable1->GetEntries(); i++) seqarray1->AddLast(datatable1->At(i)); //Put datatable2 in a list for faster finding of sequences; for (Int_t i = 0; i < datatable2->GetEntries(); i++) seqarray2->AddLast(datatable2->At(i)); // add the arrays BrDataTable *addedtable = AddArrays(seqarray1, seqarray2); outNode->AddDataTable(addedtable); Debug(1, "Event", "datatable 1 #%s datatable 2 #%s Result #%s", datatable1->GetEntries(), datatable2->GetEntries(), addedtable->GetEntries()); delete seqarray1; delete seqarray2; } // end of event() //____________________________________________________________________ BrDataTable* BrTpcAddSeqModule::AddArrays(TList *array1, TList *array2) { // The new added data table BrDataTable *addedtable = new BrDataTable(Form("%s %s", BRTABLENAMES kTPCSequence, GetName()), "raw + digitized"); //Adding array 2 to array 1 Int_t num_of_obj_in_array = array1->GetSize(); while (num_of_obj_in_array > 0) { BrTpcSequence *seq = (BrTpcSequence*) array1->First(); array1->Remove(seq); AddSequence(seq); // Add all equal padrows in array1 together, then all in array2 AddAllEqualPadRows(array1, seq->GetRow(), seq->GetPad()); AddAllEqualPadRows(array2, seq->GetRow(), seq->GetPad()); // Put the new BrTpcSequence into the datatable // The sequence will be split up in BrTpcSequencePPModule Debug(20, "AddArrays", "Added all pad:%s row:%s", seq->GetPad(), seq->GetRow()); //Then put all the equal padrows into the outputdatatable addedtable->Add(fAddedSeq); fAddedSeq = NULL; num_of_obj_in_array = array1->GetSize(); } //end loop through array1. //Put the rest of the sequences from array2 //into the new addeddatatable while (array2->GetSize() > 0) { BrTpcSequence *seq = (BrTpcSequence*) array2->First(); seq->SetClustNum(-1); addedtable->Add(new BrTpcSequence(*seq)); Debug(20, "AddArrays", "Single seq added, pad:%s row:%s", seq->GetPad(), seq->GetRow()); array2->Remove(seq); } if (!array1->IsEmpty() || !array2->IsEmpty()) { Warning("AddArrays","Was not able to add all from sequences together!"); SetStatus(kFailure); } return addedtable; } //_____________________________________________________________________ void BrTpcAddSeqModule::AddAllEqualPadRows(TList *array, Int_t row, Int_t pad) { // Searches through the list and adds the ones which are equal to // pad and row to addedseq, returns the number of sequences found. Int_t numfound = 0; // All equal padrows comes in a heap, since they are sorted. // Use this to shorten search. Bool_t foundheap = kFALSE; BrTpcSequence *compareseq = NULL; Int_t k = 0; // loop through the array while (k <= array->LastIndex()) { compareseq = (BrTpcSequence*) array->At(k); if (compareseq == 0) return; // Add the sequence and remove that sequence from the list. if (pad == compareseq->GetPad() && row == compareseq->GetRow()) { foundheap = kTRUE; AddSequence(compareseq); array->Remove(compareseq); k--; numfound++; } if (foundheap) if (pad != compareseq->GetPad() || row != compareseq->GetRow()) return; k++; } // end loop through list. } //____________________________________________________________________ void BrTpcAddSeqModule::End() { // Run-level finalisation SetState(kEnd); } //____________________________________________________________________ void BrTpcAddSeqModule::Finish() { // Job-level finalisation SetState(kFinish); } //____________________________________________________________________ void BrTpcAddSeqModule::Print(Option_t* option) const { // Print module information // See BrModule::Print for options. // In addition this module defines the Option: // <fill in here> TString opt(option); opt.ToLower(); BrModule::Print(option); if (opt.Contains("d")) cout << endl << " Original author: Truls Martin Larsen" << endl << " Last Modifications: " << endl << " $Author: cholm $" << endl << " $Date: 2002/01/03 19:53:04 $" << endl << " $Revision: 1.2 $ " << endl << endl << "-------------------------------------------------" << endl; } //____________________________________________________________________ // // $Log: BrTpcAddSeqModule.cxx,v $ // Revision 1.2 2002/01/03 19:53:04 cholm // Prepared to use BrTableNames class (or perhaps BrDetectorList) for table names // // Revision 1.1 2001/12/18 12:39:42 trulsml // This is the new BrTpcSequenceAdder. Fixed serious bug, and gave it new name. // // |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|