// This Class' Header ------------------ #include "TtTimeMatch.h" // C/C++ Headers ---------------------- #include // Collaborating Class Headers -------- #include "FairRootManager.h" #include "TClonesArray.h" #include "PndSdsHit.h" #include "PndSdsDigi.h" #include "PndSdsDigiStrip.h" #include "PndSdsDigiPixel.h" #include "TFile.h" #include "TTree.h" #include "TGeoTrack.h" #include "TGeoManager.h" #include "FairEventHeader.h" #include "TH1F.h" using namespace std; TtTimeMatch::TtTimeMatch() { std::cout << "TtTimeMatch ctor" << std::endl; fRange = 10.; temp1 = new TH1F("TimeDifference1","TimeDifference1",10000,-4999.5,+5000.5); temp2 = new TH1F("TimeDifference2","TimeDifference2",10000,-4999.5,+5000.5); temp3 = new TH1F("TimeDifference3","TimeDifference3",10000,-4999.5,+5000.5); temp4 = new TH1F("TimeDifference4","TimeDifference4",10000,-4999.5,+5000.5); tempTot = new TH1F("TimeDifferenceTot","TimeDifferenceTot",10000,-4999.5,+5000.5); fSpillPix = 0; fSpillStr = 0; } TtTimeMatch::~TtTimeMatch() { } void TtTimeMatch::Run() { std::cout << "hi!" << std::endl; std::cout << "Strip" << std::endl; std::cout << fInStrFileName.Data() << std::endl; std::cout << fInStrBranch.Data() << std::endl; std::cout << "Pixel" << std::endl; std::cout << fInPixFileName.Data() << std::endl; std::cout << fInPixBranch.Data() << std::endl; TFile *fS = new TFile(fInStrFileName.Data()); TTree *tS = (TTree*) fS->Get("cbmsim"); TClonesArray *strInput = new TClonesArray("PndSdsHit",10); tS->SetBranchAddress(fInStrBranch.Data(),&strInput); TFile *fP = new TFile(fInPixFileName.Data()); TTree *tP = (TTree*) fP->Get("cbmsim"); //TClonesArray *pixInput = new TClonesArray("PndSdsDigiPixel",10); TClonesArray *pixInput = new TClonesArray("PndSdsHit",10); tP->SetBranchAddress(fInPixBranch.Data(),&pixInput); TFile *fO = new TFile(fOutFileName.Data(),"RECREATE"); // TTree *tO = new TTree("cbmsim","cbmsim"); // tO->SetDirectory(fO); // TClonesArray *pixOutput = new TClonesArray("PndSdsDigiStrip",10); // TClonesArray *strOutput = new TClonesArray("PndSdsDigiPixel",10); // TClonesArray &pixO = * pixOutput; // TClonesArray &strO = * strOutput; // tO->Branch(fOutPixBranch.Data(),&pixOutput); // tO->Branch(fOutStrBranch.Data(),&strOutput); temp1->SetDirectory(fO); temp2->SetDirectory(fO); temp3->SetDirectory(fO); temp4->SetDirectory(fO); tempTot->SetDirectory(fO); Long64_t evS,evP; Long64_t clockStr = 0; Long64_t clockPix = 0; UInt_t triggerStr = 0; UInt_t triggerPix = 0; Long64_t pEvStart = 0; Long64_t pEvStop = 0; Int_t evPm = 0; Int_t cS=0,cP=0; Int_t pix_c_out=0; Bool_t controlStr = false; Bool_t controlStart = false; std::cout << "StripEvents: " << tS->GetEntries() << std::endl; std::cout << "PixelEvents: " << tP->GetEntries() << std::endl; // loop on events Int_t MemPix = 0; Bool_t safeCheck = kFALSE; for(Long64_t ie = 0 ; ie < tS->GetEntriesFast() ; ie++) { cS = 0; cP = 0; // pixOutput->Clear(); // strOutput->Clear(); tS->GetEvent(ie); PndSdsHit *hit = (PndSdsHit*) strInput->At(0); // pix_c_out = 0; controlStr = false; controlStart = false; if (hit) { clockStr = hit->GetClock(); triggerStr = hit->GetTriggerID(); //if (triggerStr!=3366) continue; if (triggerStr!=fSpillStr) continue; clockPix = clockStr; triggerPix = fSpillPix; std::cout << "* spillStr: " << triggerStr << ", spillPix " << triggerPix << ", timeStr " << clockStr << ", timePix " << clockPix << ", range " << fRange << std::endl; Bool_t probe = kTRUE; //for(Long64_t ye = pEvStart ; (clockPix < (clockStr+fRange)) && (yeGetEntriesFast()) && (triggerPix==fSpillPix) ; ye++) for(Long64_t ye = pEvStart ; (yeGetEntriesFast()) && (triggerPix<=fSpillPix) && probe; ye++) { std::cout << "~" << std::endl; tP->GetEvent(ye); for (Int_t ke = 0 ; ke < pixInput->GetEntries() ; ke++) { //PndSdsDigi *hitP = (PndSdsDigi*) pixInput->At(ke); PndSdsHit *hitP = (PndSdsHit*) pixInput->At(ke); if (hitP){ clockPix = hitP->GetClock(); triggerPix = hitP->GetTriggerID(); std::cout << "~ spillStr: " << triggerStr << ", spillPix " << triggerPix << ", pixelSpillSel " << fSpillPix << ", stripSpillSel " << fSpillStr << ", timeStr " << clockStr << ", timePix " << clockPix << ", range " << fRange << std::endl; //if (clockPix < (clockStr-fRange)) pEvStart = ye; //std::cout << "~ spillStr: " << triggerStr << ", spillPix " << triggerPix << ", timeStr " << clockStr << ", timePix " << clockPix << ", range " << fRange << std::endl; if (triggerPix==fSpillPix) { if (clockPix < (clockStr-fRange)) pEvStart = ye; if (clockPix > (clockStr+fRange)) probe=kFALSE; } //if ( (triggerPix==(triggerStr-3354)) && (clockPix >= (clockStr-fRange)) && (clockPix <= (clockStr+fRange)) ) if ( (triggerPix==fSpillPix) && (clockPix >= (clockStr-fRange)) && (clockPix <= (clockStr+fRange)) ) { std::cout << "$$$$" << std::endl; tempTot->Fill(-clockStr+clockPix); if (hitP->GetSensorID() == 0) temp1->Fill(-clockStr+clockPix); if (hitP->GetSensorID() == 1) temp2->Fill(-clockStr+clockPix); if (hitP->GetSensorID() == 2) temp3->Fill(-clockStr+clockPix); if (hitP->GetSensorID() == 3) temp4->Fill(-clockStr+clockPix); //std::cout << "~ spillStr: " << triggerStr << ", spillPix " << triggerPix << ", timeStr " << clockStr << ", timePix " << clockPix << ", range " << fRange << std::endl; /*if (!controlStr) { // saving strip hits for (Int_t str_c = 0 ; str_c < strInput->GetEntries() ; str_c++) { PndSdsHit* hitS2 = (PndSdsHit*) strInput->At(str_c); new(strO[str_c])PndSdsHit(*hitS2); } controlStr = true; } // saving pixel hits for (Int_t pix_c = 0 ; pix_c < pixInput->GetEntries() ; pix_c++) { PndSdsHit* hitP2 = (PndSdsHit*) pixInput->At(pix_c); new(pixO[pix_c_out])PndSdsHit(*hitP2); pix_c_out++; } tO->Fill(); // filling output tree if (!controlStart) { // it's setting the next start point of the loop on pixel hits // to the first pixel event inside the time range of the previous event // This might be optimized in a smarter way pEvStart=ye; controlStart = true; } */ } // end check on time coincidence } // check on pixel hit } // end loop on pixel hits within one event } // end loop on pixel events } // check on strip hit } // end of loop on strip hit //tO->Write(); tempTot->SetDirectory(fO); temp1->SetDirectory(fO); temp2->SetDirectory(fO); temp3->SetDirectory(fO); temp4->SetDirectory(fO); tempTot->Write(); temp1->Write(); temp2->Write(); temp3->Write(); temp4->Write(); fO->Close(); } ClassImp(TtTimeMatch);