//----------------------------------------------------------- // File and Version Information: // $Id$ // // Description: // eader for T2K and FOPI data for the gemTPCdecoding program // // // Environment: // Software developed for the PANDA Detector at FAIR. // // Author List: // Maxence Vandenbroucke TUM (original author) // // //----------------------------------------------------------- // Panda Headers ---------------------- // This Class' Header ------------------ #include "TpcCdcDataReaderTask.h" // C/C++ Headers ---------------------- #include #include #include // Collaborating Class Headers -------- #include "FairRootManager.h" #include "TClonesArray.h" #include "TVector3.h" #include #include "FairRunAna.h" #include "FairRuntimeDb.h" #include "FopiEvent.h" #include "CdcHit.h" #include "CdcTrack.h" #include "RpcTrack.h" #include "BarrelTrack.h" #include "HeliHit.h" #include "HeliTrack.h" #include "PlawaTrack.h" using std::fabs; // Class Member definitions ----------- ClassImp(TpcCdcDataReaderTask) TpcCdcDataReaderTask::TpcCdcDataReaderTask() : _persistence(kFALSE), fCutoff(0), fEventNb(0), fSpillNb(0)//, fEventId(NULL) { fSampleBranchName = "TpcSample"; fFOPIEvBranchName = "TpcFopiEvent"; fCdcHitBranchName = "TpcCdcHit"; fCdcTrackBranchName = "TpcCdcTrack"; fRpcTrackBranchName = "TpcRpcTrack"; fFile = "TBtest/run.root"; nEvents=0; fEv=NULL; //not setting this to 0 gives a segfault. ROOT is fully awesome } TpcCdcDataReaderTask::~TpcCdcDataReaderTask() {;} InitStatus TpcCdcDataReaderTask::Init() { //Get ROOT Manager FairRootManager* ioman= FairRootManager::Instance(); if(ioman==0) { Error("TpcCdcDataReaderTask::Init","RootManager not instantiated!"); return kERROR; } // Get input data fIntree = new TChain("tpcEvent"); fIntree->Add(fFile.Data());//before AddFile fIntree->SetBranchAddress("tpcEvent", &fEv); fFOPIEv= new TClonesArray("FopiEvent"); fCdcTrack = new TClonesArray("CdcTrack"); fRpcTrack = new TClonesArray("RpcTrack"); fCdcHit= new TClonesArray("CdcHit"); fCdcIntree = new TChain("FOPITree"); fCdcIntree->Add(fCdcFile.Data());//before AddFile fCdcIntree->SetBranchAddress("FopiEventBr",&fFOPIEv); fCdcIntree->SetBranchAddress("CdcTrackBr",&fCdcTrack); fCdcIntree->SetBranchAddress("RpcTrackBr",&fRpcTrack); fCdcIntree->SetBranchAddress("CdcHitBr",&fCdcHit); fLoop=0; fCdcLoop=1; if(fIntree->IsZombie()) { std::cout << "TpcCdcDataReaderTask::Init data file/tree "<< fFile << " couldn't be loaded -> abort" <IsZombie()){ std::cout << "TpcCdcDataReaderTask::Init data file/tree "<< fCdcFile << " couldn't be loaded -> abort" <GetEntries()<< std::endl; std::cout<<"Number of Entries in CdcChain: "<GetEntries()<< std::endl; if(nEvents==0) nEvents=fCdcIntree->GetEntries(); // create and register output array fSampleOutArray = new TClonesArray("TpcSample"); //fEventIdOutArray = new TClonesArray("TpcEventIdentifier"); fFopiEventOutArray = new TClonesArray("FopiEvent"); fCdcHitOutArray = new TClonesArray("CdcHit"); fCdcTrackOutArray = new TClonesArray("CdcTrack"); fRpcTrackOutArray = new TClonesArray("RpcTrack"); ioman->Register("TpcSample","Tpc",fSampleOutArray,_persistence); //ioman->Register("TpcEventIdentifier","Tpc", fEventIdOutArray, _persistence); ioman->Register("TpcFopiEvent","Tpc", fFopiEventOutArray, _persistence); ioman->Register("TpcCdcHit","Tpc", fCdcHitOutArray, _persistence); ioman->Register("TpcCdcTrack","Tpc", fCdcTrackOutArray, _persistence); ioman->Register("TpcRpcTrack","Tpc", fRpcTrackOutArray, _persistence); return kSUCCESS; } //EXEC void TpcCdcDataReaderTask::Exec(Option_t* opt){ std::cerr << "TpcCdcDataReaderTask::Exec\n"; fIntree->AddFile(fFile.Data()); fCdcIntree->AddFile(fCdcFile.Data()); // Reset output Arrays if(fSampleOutArray==0) Fatal("TpcCdcDataReaderTask::Exec()","No SampleOutArray"); else if(fFopiEventOutArray==0) Fatal("TpcCdcDataReaderTask::Exec()","No FopiEventOutArray"); else if(fCdcTrackOutArray==0) Fatal("TpcCdcDataReaderTask::Exec()","No CdcTrackOutArray"); else if(fCdcHitOutArray==0) Fatal("TpcCdcDataReaderTask::Exec()","No CdcHitOutArray"); else if(fRpcTrackOutArray==0) Fatal("TpcCdcDataReaderTask::Exec()","No RpcTrackOutArray"); fSampleOutArray->Delete(); //fEventIdOutArray->Delete(); fFopiEventOutArray->Delete(); fCdcTrackOutArray->Delete(); fRpcTrackOutArray->Delete(); fCdcHitOutArray->Delete(); const std::vector* samples; while(fCdcLoopGetEntries()&&fCdcLoopGetEvent(fCdcLoop); fCdcLoop++; int FOPIEvNb=((FopiEvent*)fFOPIEv->At(0))->GetEvtNum(); int cdcSpillNb=((FopiEvent*)fFOPIEv->At(0))->GetSpillNum(); int cdcRunNb=((FopiEvent*)fFOPIEv->At(0))->GetRunNum(); if(cdcRunNb==runNr){ std::cout << "RUN NUMBER DO MATCH! GO AHED\n" ; } else{ std::cerr << "RUN NUMBER DOES NOT MATCH!!! Bailing out!"<< std::endl; throw; } if(cdcSpillNb>2048){ continue; } int loopSearch=0; std::cout<<"searching tpc for ev: "<GetEntries()&&loopSearch<20){ //get the TpcEvent; fIntree->GetEvent(loopSearch+fLoop); loopSearch++; fEventNb = fEv->getEventNb(); fSpillNb = fEv->getSpillNb(); std::cout<<"tpc ev: "<getEventVector(); std :: cout << "Copying "<< samples->size()<<" samples.\n" ; if(samples->size()At(0); FopiEvent* theEv= new ((*fFopiEventOutArray)[0]) FopiEvent(*fopiev); std :: cout << "Saving "<< samples->size()<<" samples\n"; for(unsigned int i=0; isize(); i++){ TpcSample* theSample = new((*fSampleOutArray)[i]) TpcSample((*samples)[i]); } for(unsigned int i=0;iGetEntries();++i){ CdcTrack* track=(CdcTrack*)fCdcTrack->At(i); CdcTrack* theTrack= new ((*fCdcTrackOutArray)[i]) CdcTrack(*track); RpcTrack* rpctr=(RpcTrack*)fRpcTrack->At(i); RpcTrack* theRpcTr= new ((*fRpcTrackOutArray)[i]) RpcTrack(*rpctr); } for(unsigned int i=0;iGetEntries();++i){ CdcHit* hit=(CdcHit*)fCdcHit->At(i); CdcHit* theHit= new ((*fCdcHitOutArray)[i]) CdcHit(*hit); } return; } } return; } return; } void TpcCdcDataReaderTask::SetParContainers() { std::cout<<"TpcCdcDataReaderTask::SetParContainers"<GetRuntimeDb(); if ( ! db ) Fatal("SetParContainers", "No runtime database"); // Get Tpc digitisation parameter container fPar= (TpcDigiPar*) db->getContainer("TpcDigiPar"); if (! fPar ) Fatal("SetParContainers", "TpcDigiPar not found"); }