// ----------------------------------------- // PndDrcLutReco.cpp // // Created on: 13.07.2013 // Author: R.Dzhygadlo at gsi.de // ----------------------------------------- #include "PndDrcLutReco.h" #include "FairRootManager.h" #include "PndMCTrack.h" #include "PndDrcPDPoint.h" #include "PndDrcHit.h" #include "PndDrcPDHit.h" #include "PndDrcLutNode.h" #include "PndDrcTrackInfo.h" #include "PndDrcPhotonInfo.h" #include "PndDrcAmbiguityInfo.h" #include "PndGeoHandling.h" #include "TRandom.h" #include "TSystem.h" #include "TCanvas.h" using std::cout; using std::endl; // ----- Default constructor ------------------------------------------- PndDrcLutReco::PndDrcLutReco() :FairTask("PndDrcLutReco") { fInputFile = "luttab.root"; } // ----- Standard constructors ----------------------------------------- PndDrcLutReco::PndDrcLutReco(Int_t verbose) :FairTask("PndDrcLutReco",verbose) { fVerbose = verbose; fInputFile = "luttab.root"; } PndDrcLutReco::PndDrcLutReco(Int_t verbose, TString infilename) :FairTask("PndDrcLutReco",verbose) { fVerbose = verbose; fInputFile = infilename; } // ----- Destructor ---------------------------------------------------- PndDrcLutReco::~PndDrcLutReco() { } // ----- Initialization ------------------------------------------------ InitStatus PndDrcLutReco::Init() { cout << " ---------- INITIALIZATION ------------" << endl; nevents = 0; // Get RootManager FairRootManager* ioman = FairRootManager::Instance(); if ( ! ioman ) { cout << "-E- PndDrcLutReco::Init: " << "RootManager not instantiated!" << endl; return kFATAL; } // Get input array fMCArray = (TClonesArray*) ioman->GetObject("MCTrack"); if ( ! fMCArray ) { cout << "-W- PndDrcLutReco::Init: " << "No MCTrack array!" << endl; return kERROR; } // Get bar points array fBarPointArray = (TClonesArray*) ioman->GetObject("DrcBarPoint"); if ( ! fBarPointArray ) { cout << "-W- PndDrcLutReco::Init: " << "No DrcBarPoint array!" << endl; return kERROR; } // Get ev points array fEVPointArray = (TClonesArray*) ioman->GetObject("DrcEVPoint"); if ( ! fEVPointArray ) { cout << "-W- PndDrcLutReco::Init: " << "No DrcEVPoint array!" << endl; return kERROR; } // Get Photon point array fPDPointArray = (TClonesArray*) ioman->GetObject("DrcPDPoint"); if ( ! fPDPointArray ) { cout << "-W- PndDrcLutReco::Init: " << "No DrcPDPoint array!" << endl; return kERROR; } // Get digi array fDigiArray = (TClonesArray*) ioman->GetObject("DrcDigi"); if ( ! fDigiArray ) { cout << "-W- PndDrcLutReco::Init: " << "No DrcDigi array!" << endl; return kERROR; } // Get input array fPDHitArray = (TClonesArray*) ioman->GetObject("DrcPDHit"); if ( ! fPDHitArray ) { cout << "-W- PndDrcLutReco::Init: " << "No DrcPDHit array!" << endl; return kERROR; } fFile = new TFile(fInputFile); fTree=(TTree *) fFile->Get("dircsim") ; for(Int_t l=0; l<5; l++){ fLut[l] = new TClonesArray("PndDrcLutNode"); fTree->SetBranchAddress(Form("LUT%d",l),&fLut[l]); } fTree->GetEntry(0); // Create and register output array fDrcTrackInfoArray = new TClonesArray("PndDrcTrackInfo"); ioman->Register("DrcTrackInfo","Drc",fDrcTrackInfoArray, kTRUE); fGeo = new PndGeoDrc(); fBboxNum = fGeo->BBoxNum(); fPipehAngle = fGeo->PipehAngle(); fBarPhi = 2*atan(((fGeo->BarWidth() + fGeo->barhGap())/2.)/fGeo->radius())*180/TMath::Pi(); fDphi = 2.*(180. - 2*fPipehAngle)/(Double_t)fGeo->BBoxNum(); fHist = new TH1F("chrenkov_angle_hist","chrenkov_angle_hist", 50,0.65,0.86); fFit = new TF1("fgaus","[0]*exp(-0.5*((x-[1])/[2])*(x-[1])/[2])",0.65,0.86); fSpect = new TSpectrum(10); cout << "-I- PndDrcLutReco: Intialization successfull" << endl; return kSUCCESS; } // ----- Execution of Task --------------------------------------------- void PndDrcLutReco::Exec(Option_t* option) { nevents++; fDetectorID = 0; ProcessPhotonHit(); } //--------------Process Photon Hits----------------------------------------- void PndDrcLutReco::ProcessPhotonHit() { if ( ! fDrcTrackInfoArray ) Fatal("Exec", "No fDrcTrackInfoArray"); fDrcTrackInfoArray->Clear(); int nHits = fPDHitArray->GetEntriesFast(); if(fVerbose>1) std::cout<<"Event # "<< nevents<<" has "<SetBatch(kTRUE); PndDrcTrackInfo trackinfo; TVector3 dird, dir, momInBar,posInBar; Double_t cangle,tangle, boxPhi, evtime, bartime, directz, luttheta, barHitTime, pdHitTime, lutboxPhi=10.825,window1,window2; Int_t pdgcode, lutboxId=3; Bool_t reflected; TVector3 fnX1 = TVector3 (1,0,0); TVector3 fnY1 = TVector3( 0,1,0); bool testTrRes = false; Double_t angdiv,dtheta,dtphi; if(testTrRes){ Int_t rndm=0; if (gSystem->Getenv("RANDOM")) { rndm = atoi(gSystem->Getenv("RANDOM")); } gRandom->SetSeed(rndm); angdiv = 2*TMath::Pi()/180.; dtheta = gRandom->Uniform(-angdiv,angdiv); dtphi = gRandom->Uniform(-angdiv,angdiv); } // loop over tracks for(Int_t itrack=0; itrackGetEntriesFast(); itrack++){ fMCTrack = (PndMCTrack*)fMCArray->At(itrack); if( fMCTrack->GetMotherID()==-1) { Int_t mcboxId = -1; for(int i=0; iGetEntriesFast(); i++){ PndDrcBarPoint *barPoint = (PndDrcBarPoint*)fBarPointArray->At(i); if(itrack == barPoint->GetTrackID()) { mcboxId = barPoint->GetBoxId(); break; } } window1 = (mcboxId)*17-17; window2 = (mcboxId+1)*17+17; // Loop over PndDrcPDHits for(Int_t k=0; kAt(k); Int_t wsensorId = fPDHit->GetSensorId()/100; if(wsensorId < window1 || wsensorId > window2) { // std::cout<<"wsensorId "<GetRefIndex(); fDigi = (PndDrcDigi*) fDigiArray->At(digiID); Int_t pointID= fDigi->GetIndex(0); fPDPoint = (PndDrcPDPoint*)fPDPointArray->At(pointID); fBarPoint= (PndDrcBarPoint*)fBarPointArray->At(fPDPoint->GetBarPointID()); fBarPoint->Momentum(momInBar); photoninfo.SetMcPrimeMomentumInBar(momInBar); if(testTrRes){ double phiinit = momInBar.Phi(); momInBar.RotateZ(-phiinit); momInBar.RotateY(dtheta); momInBar.RotateZ(phiinit); momInBar.RotateZ(dtphi); } fBarPoint->Position(posInBar); Int_t boxId = fBarPoint->GetBoxId(); Int_t barId = fBarPoint->GetBarId(); barHitTime = fBarPoint->GetTime(); pdgcode = fBarPoint->GetPdgCode(); cangle = fBarPoint->GetThetaC(); pdHitTime = fPDHit->GetTime(); Double_t startPhi = posInBar.Phi()/TMath::Pi()*180; if(startPhi < 0) startPhi = 360 + startPhi; if(startPhi >= 0 && startPhi < 90) boxPhi = TMath::Floor(startPhi/fDphi) *fDphi + fDphi/2.; if(startPhi >= 90 && startPhi < 270) boxPhi = 90 + fPipehAngle + TMath::Floor((startPhi-90-fPipehAngle)/fDphi) *fDphi + fDphi/2.; if(startPhi >= 270 && startPhi < 360) boxPhi = 270 + fPipehAngle + TMath::Floor((startPhi-270-fPipehAngle)/fDphi) *fDphi + fDphi/2.; Double_t trackPhi = momInBar.Phi()*180/TMath::Pi(); if(trackPhi<0) trackPhi += 360; //Int_t barId = (int) (2.5 + (boxPhi-trackPhi)/fBarPhi); if(barId>4 || barId<0) { std::cout<<"Error in PndDrcLutReco: Bar Id is wrong. barId = "<< barId <GetTrackID(); Int_t evpointcount = 0; for(int i=0; iGetEntriesFast(); i++){ fEVPoint = (PndDrcEVPoint*)fEVPointArray->At(i); if(trackID == fEVPoint->GetTrackID()) evpointcount++; } if(((PndMCTrack*)fMCArray->At(trackID))->GetMomentum().Z()>0) reflected = kTRUE; else reflected = kFALSE; Int_t sensorId = fPDHit->GetSensorId(); Int_t recalculatedSensorId = (sensorId/100 - (boxId - lutboxId)*17)*100 + sensorId%100; if(sensorId>27200 || recalculatedSensorId>27200 || recalculatedSensorId <0) { std::cout<<"LUT reco: ignore vertical MCPblock for now. sensorId = "<GetMotherID() << " reconstructed cherenkov vs. mc " <GetMomentum()); trackinfo.SetMcMomentumInBar(momInBar); trackinfo.SetMcPdg(fMCTrack->GetPdgCode()); trackinfo.SetMcCherenkov(cangle); trackinfo.SetCherenkov(cherenkovreco); trackinfo.SetMcTimeInBar(barHitTime); new ((*fDrcTrackInfoArray)[fDrcTrackInfoArray->GetEntriesFast()]) PndDrcTrackInfo(trackinfo); } } if(fVerbose<2) gROOT->SetBatch(kFALSE); } Double_t PndDrcLutReco::FindPeak(){ Double_t cherenkovreco = -1; if(fHist->GetEntries()>5 ){ Int_t nfound = fSpect->Search(fHist,1,"",0.6); Float_t *xpeaks = fSpect->GetPositionX(); if(nfound>0) cherenkovreco = xpeaks[0]; fFit->SetParameter(1,cherenkovreco); // peak fFit->SetParameter(2,0.01); // width fHist->Fit("fgaus","Q","",cherenkovreco-0.02,cherenkovreco+0.02); cherenkovreco = fFit->GetParameter(1); if(cherenkovreco<0 || cherenkovreco>1 ) cherenkovreco = 0; if(fVerbose>1){ TCanvas* c = new TCanvas("c","c",0,0,800,1200); fHist->Draw(); c->Modified(); c->Update(); c->WaitPrimitive(); } } fHist->Reset(); return cherenkovreco; } // ----- Finish Task --------------------------------------------------- void PndDrcLutReco::Finish(){ for(Int_t l=0; l<10; l++){ fLut[l]->Clear(); } cout << "-I- PndDrcLutReco: Finish" << endl; } ClassImp(PndDrcLutReco)