//----------------------------------------------------------- // File and Version Information: // $Id$ // // Description: // Reading data from GEMs and silicons used at the // testbench at COMPASS importing the trees of // gemMonitor into the framework // Use the event number in run to synchronize with the // TPC data // // Environment: // Software developed for the baby TPC // // Author List: // Maxence Vandembroucke (original author) // Physics Department E18, TUM // // //----------------------------------------------------------- #include "CERNDataReaderTask.h" #include "TpcEventIdentifier.h" #include "CsGEM/CsGEMPlane.h" #include "TFile.h" #include "TClonesArray.h" #include "TTree.h" #include "TTreeIndex.h" #include "TBStripHit.h" #include static unsigned int fEvInTree = 0; ClassImp(CernDataReaderTask) CernDataReaderTask::CernDataReaderTask() : fPersistence(kFALSE), fCsGEMInBranch("GM01X1__."), fTpcEventIDBranch("TpcEventIdentifier"), fInputFileName(""), fInputFile(NULL), fGEMTreeName("Hits"), fNGEMEvents(0), fCsGEMArray(NULL), fTpcEventID(NULL), DEBUG(true)//todo { ; } CernDataReaderTask::~CernDataReaderTask() { if(fInputFile!=NULL && fInputFile->IsZombie() == false) { fInputFile->Close(); delete fInputFile; } } InitStatus CernDataReaderTask::Init() { if(fInputFileName.Length() < 2) { Error("CernDataReaderTask::Init()", "No Input file given"); return kERROR; } fInputFile = new TFile(fInputFileName, "read"); //check if valid if(fInputFile->IsZombie()) { Error("CernDataReaderTask::Init()", "Input file not ok"); return kERROR; } //TODO: check for valid keys (as I did in time extraction code) fGEMTree = (TTree*) fInputFile->Get(fGEMTreeName); fNGEMEvents = fGEMTree->GetEntriesFast(); //connect input Arrays planes.reserve(fGEMTree->GetNbranches()); for (int i=0; i< fGEMTree->GetNbranches();i++) { if(DEBUG) std::cout << "fGEMtree in branch '" << fGEMTree->GetListOfBranches()->At(i)->GetName() << "'" << std::endl; TString branchname(fGEMTree->GetListOfBranches()->At(i)->GetName()); planes.push_back(new CsGEMPlane); fGEMTree->SetBranchAddress(branchname, &(planes.back())); } //build output arrays fCsGEMArray = new TClonesArray("TBStripHit"); //connect to the framework: FairRootManager* ioman = FairRootManager::Instance(); if(ioman==0) { Fatal("CernDataReaderTask::Init()","RootManager not instantiated!"); return kFATAL; } // Get TPC EventID info fTpcEventID = (TClonesArray*) ioman->GetObject(fTpcEventIDBranch); // Register output arrays ioman->Register("TBStripHit", "Tpc", fCsGEMArray, fPersistence); //build tree Index for fast access later on: std::cout<<"CernDataReaderTask::Init() Building tree index ... " <GetListOfBranches()->At(0)->GetName(); major += "GetHeader().GetEvtNumInRun()"; int nE = fGEMTree->BuildIndex(major); std::cout<<" ... Index has "<GetTreeIndex(); //Tree has ownership if(DEBUG) fGEMIndex->Print("10"); } void CernDataReaderTask::Exec(Option_t* opt) { DEBUG=false; if(DEBUG) { std::cout << "CernDataReaderTask::Exec" << std::endl; } //clear output arrays: if(fCsGEMArray!=NULL) //could never happen, but let's be paranoid fCsGEMArray->Delete(); if(fTpcEventID->GetEntriesFast()<1) { Fatal("CernDataReaderTask::Exec()","No TPC EventID found!"); return; } TpcEventIdentifier* tpcid = (TpcEventIdentifier*)(*fTpcEventID)[0]; unsigned int tpcEvent = tpcid->getEventInSpill(); unsigned int tpcSpill = tpcid->getSpill(); if(DEBUG) { std::cout<<"looking for entry with"<GetEntryNumberWithIndex((int)(tpcSpill * (1<<20) + tpcEvent), 0); if(treeEv<0) { Warning("CernDataReaderTask::Exec()", "No matching Entry in Gem Monitor Tree could be found"); std::cout<<"looking for entry with Spill: "<GetEntry(fEvInTree); if(DEBUG) { CsGEMPlane* cp = planes[0]; CsGEMPlaneHeader * ch = cp->GetHeader(); std::cout<<"In GEM Tree"<GetEvtNumInSpill() <& listcl = cp->GetClusters(); for (std::list::const_iterator it=listcl.begin(); it!=listcl.end(); it++) { CsGEMCluster* cl = *it; TBStripHit * hit = new ((*fCsGEMArray)[counter++]) TBStripHit(cl->GetPosition(), cl->GetAmp()[2], i, cl->GetHits().size(), cl->GetPositionErr(), cp->GetName()); } } return; }