// -------------------------------------------------------------------------- // ----- Class CbmTofHitProducerNew ------ // ----- Created by E. Cordier 14/09/05 ------ // ----- Modified by D. Gonzalez-Diaz 07/09/06 ------ // ----- Modified by D. Gonzalez-Diaz 02/02/07 ------ // ----- modified nh 24/10/2012 // -------------------------------------------------------------------------- #include "CbmTofHitProducerNew.h" #include "CbmMCTrack.h" #include "CbmTofPoint.h" // in cbmdata/tof #include "CbmTofHit.h" // in cbmdata/tof #include "CbmTofGeoHandler.h" // in tof/TofTools #include "CbmTofCell.h" // in tof/TofData #include "CbmTofDigiPar.h" // in tof/TofParam #include "FairRootManager.h" #include "FairRunAna.h" #include "FairRuntimeDb.h" #include "FairLogger.h" #include "TRandom.h" #include "TString.h" #include "TVector3.h" #include "TSystem.h" #include "TClonesArray.h" #include using std::cout; using std::endl; // ---- Default constructor ------------------------------------------- CbmTofHitProducerNew::CbmTofHitProducerNew() : FairTask("CbmTofHitProducerNew"), fVerbose(1), fParFileName(""), fTofPoints(NULL), fMCTracks(NULL), fHitCollection(NULL), X(), Dx(), Y(), Dy(), Z(), Ch(), ActSMtypMax(), ActnSMMax(), ActnModMax(), ActnCellMax(), tl(), tr(), trackID_left(), trackID_right(), point_left(), point_right(), fSigmaT(0.), fSigmaXY(0.), fSigmaY(0.), fSigmaZ(0.), fVersion(""), fNHits(-1), fGeoHandler(new CbmTofGeoHandler()), fDigiPar(NULL), fCellInfo(NULL), fParInitFromAscii(kTRUE) { } // ---- Constructor ---------------------------------------------------- CbmTofHitProducerNew::CbmTofHitProducerNew(const char *name, Int_t verbose) :FairTask(TString(name),verbose), fVerbose(1), fParFileName(""), fTofPoints(NULL), fMCTracks(NULL), fHitCollection(NULL), X(), Dx(), Y(), Dy(), Z(), Ch(), ActSMtypMax(), ActnSMMax(), ActnModMax(), ActnCellMax(), tl(), tr(), trackID_left(), trackID_right(), point_left(), point_right(), fSigmaT(0.), fSigmaXY(0.), fSigmaY(0.), fSigmaZ(0.), fVersion(""), fNHits(-1), fGeoHandler(new CbmTofGeoHandler()), fDigiPar(NULL), fCellInfo(NULL), fParInitFromAscii(kTRUE) { cout << "CbmTofHitProducerNew instantiated with verbose = "<Write(); if (fGeoHandler) { delete fGeoHandler; } } // -------------------------------------------------- void CbmTofHitProducerNew::SetParContainers() { if (!fParInitFromAscii) { LOG(INFO)<<" Get the digi parameters for tof"<GetRuntimeDb(); fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar")); } } // -------------------------------------------------------------------- InitStatus CbmTofHitProducerNew::ReInit() { if (!fParInitFromAscii) { LOG(INFO)<<"Reinitialize the digi parameters for tof"<GetRuntimeDb(); fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar")); } } // ---- Init ---------------------------------------------------------- InitStatus CbmTofHitProducerNew::Init() { cout << "nh - version of CbmTofHitProducerNew initializing with file " << fParFileName << endl; FairRootManager *fManager = FairRootManager::Instance(); fTofPoints = (TClonesArray *) fManager->GetObject("TofPoint"); fMCTracks = (TClonesArray *) fManager->GetObject("MCTrack"); // Initialize the TOF GeoHandler Bool_t isSimulation=kFALSE; Int_t bla = fGeoHandler->Init(isSimulation); Int_t nsmtyp=10, nsm=255, nmodules=10, ncells=255; Int_t iCh=0; // channel identifier // Initialize the matrixes [make this index visible in all the macro]. FIXME for(int t=0;tGetenv("VMCWORKDIR"); // tofGeoFile += "/parameters/tof/tof_standard.geom.par"; if (fParFileName==""){ tofGeoFile += "/parameters/tof/par_tof.txt"; }else{ tofGeoFile += fParFileName; } cout << " CbmTofHitProducerNew::Read parameters from "<< fParFileName << "," <=0){ // cout << "ReadH "<< header << endl; if((int)(header-'0')==0) break; } //Read the first line // fscanf(par,"%5d %5d %5d %2d %5.1f %5.1f %5.1f %2.1f %2.1f ", fscanf(par,"%d %d %d %d %f %f %f %f %f ", &smodule, &module, &cell, &smtype, &X_tmp, &Y_tmp, &Z_tmp, &Dx_tmp, &Dy_tmp); // cout << "Read " << smodule << " mod " << module << " cell "<< cell << " SMtyp " << smtype << " X,Y " << X_tmp <<","<< Y_tmp <ActSMtypMax) ActSMtypMax=smtype; if(smodule>ActnSMMax[ActSMtypMax]) ActnSMMax[ActSMtypMax]=smodule; if(module>ActnModMax[ActSMtypMax]) ActnModMax[ActSMtypMax]=module; if(cell>ActnCellMax[ActSMtypMax]) ActnCellMax[ActSMtypMax]=cell; X[smtype][smodule][module][cell] = X_tmp/10.; Y[smtype][smodule][module][cell] = Y_tmp/10.; Z[smtype][smodule][module][cell] = Z_tmp/10.; Dx[smtype][smodule][module][cell] = Dx_tmp/10.; Dy[smtype][smodule][module][cell] = Dy_tmp/10.; Ch[smtype][smodule][module][cell] = iCh++; //Read all the lines while(fscanf(par,"%5d %5d %5d %2d %f %f %f %f %f", &smodule, &module, &cell, &smtype, &X_tmp, &Y_tmp, &Z_tmp, &Dx_tmp, &Dy_tmp)>=0){ // cout << "Read " << smodule << " mod " << module << " cell "<< cell << " SMtyp " << smtype << " X,Y " << X_tmp <<","<< Y_tmp <ActSMtypMax) ActSMtypMax=smtype; if(smodule>ActnSMMax[ActSMtypMax]) ActnSMMax[ActSMtypMax]=smodule; if(module>ActnModMax[ActSMtypMax]) ActnModMax[ActSMtypMax]=module; if(cell>ActnCellMax[ActSMtypMax]) ActnCellMax[ActSMtypMax]=cell; X[smtype][smodule][module][cell] = X_tmp/10.; // units are cm Y[smtype][smodule][module][cell] = Y_tmp/10.; Z[smtype][smodule][module][cell] = Z_tmp/10.; Dx[smtype][smodule][module][cell] = Dx_tmp/10.; Dy[smtype][smodule][module][cell] = Dy_tmp/10.; Ch[smtype][smodule][module][cell] = iCh++; } fclose(par); cout << "Filled position array with ActSMtypMax " << ActSMtypMax << " and " << iCh << " active Channels "<< endl; } else { cout <<" InitParametersFromContainer "<Register("TofHit","Tof",fHitCollection, kTRUE); cout << "-I- CbmTofHitProducerNew: Initialization successful for " << nCh <<" electronics channels"<< endl; return kSUCCESS; } void CbmTofHitProducerNew::InitParametersFromContainer() { // Initialize the matrixes [make this index visible in all the macro]. FIXME Int_t nsmtyp=10, nsm=255, nmodules=10, ncells=255; for(int t=0;tGetNrOfModules(); LOG(INFO)<<"Parameter container contain "<GetCellId(icell); // cellId is assigned in CbmTofCreateDigiPar fCellInfo =fDigiPar->GetCell(cellId); Int_t smtype = fGeoHandler->GetSMType(cellId); Int_t smodule = fGeoHandler->GetSModule(cellId); Int_t module = fGeoHandler->GetCounter(cellId); Int_t cell = fGeoHandler->GetCell(cellId); Double_t x = fCellInfo->GetX(); Double_t y = fCellInfo->GetY(); Double_t z = fCellInfo->GetZ(); Double_t dx = fCellInfo->GetSizex(); Double_t dy = fCellInfo->GetSizey(); if(icell < 0){ cout << "-I- InitPar "<At(p); if(mc->GetNPoints(kTOF)>0) tof_tracks++; if(mc->GetNPoints(kTOF)>0 && mc->GetMotherId()==-1) tof_tracks_vert++; } cout << "-I- CbmTofHitProducerNew : " << tof_tracks << " tracks in Tof " << endl; cout << "-I- CbmTofHitProducerNew : " << tof_tracks_vert << " tracks in Tof from vertex" << endl; // cout << "-I- CbmTofHitProducerNew : " << tof_tracks-tof_tracks_local // << " tracks in Tof able to produce a hit" << endl; TVector3 pos; Double_t xHit, yHit, zHit, tHit, xHitErr, yHitErr, zHitErr; Double_t tl_new, tr_new; Double_t Dz=2.04; //FIXME: Introduce also Dz and Z as (constant) parameters Double_t sigma_T=0.098, sigma_Y=0.7, sigma_t_gap, t_o, T_smearing = 0, sigma_el=0.04, vprop = 15., Pgap = 0.75; //time[ns], position[cm], velocity[cm/ns] //FIXME: these parameters must be provided externally Int_t trackID, smtype, smodule, module, cell, gap, flag, ref; if (fSigmaT>0.) sigma_T=fSigmaT; // single gap resolution else fSigmaT=sigma_T; // take default if (fSigmaEl>0.) sigma_el=fSigmaEl; // electronics channel resolution else fSigmaEl=sigma_el; // take default //Here check for the validity of the parameters if(fSigmaY>1) cout<<"UNREALISTIC TOF POSITION RESOLUTION!! (HitProducer may crash)"<0)||fSigmaT>0.2) cout<<"UNREALISTIC TOF RESOLUTION!! (HitProducer may crash)"<Uniform(1)>Pgap) continue; // Get a pointer to the TOF point pt = (CbmTofPoint*) fTofPoints->At(j); if(pt == NULL) { cout<<"Be careful: hole in the CbmTofPoint TClonesArray!"<GetTrackID() < 0) continue; mc = (CbmMCTrack*) fMCTracks-> At(pt->GetTrackID()); // pointer to MC - info //if((mc->GetStartZ())>996) continue; //Get relevant information from the point trackID = pt->GetTrackID(); Int_t detID = pt->GetDetectorID(); cell = fGeoHandler->GetCell(detID); module = fGeoHandler->GetCounter(detID); gap = fGeoHandler->GetGap(detID); smodule = fGeoHandler->GetSModule(detID); smtype = fGeoHandler->GetSMType(detID); Int_t cellID = fGeoHandler->GetCellId(detID); // fCellInfo =fDigiPar->GetCell(cellID); if( //0){ smtype<0. || smtype>ActSMtypMax || smodule<0. || smodule>ActnSMMax[smtype] || module<0. || module>ActnModMax[smtype] || cell<0. || cell>ActnCellMax[smtype] || Dx[smtype][smodule][module][cell]<0. ) { LOG(INFO)<<"-E- TofHitProducerNew: detId: "<< detID <<" SMType: "<Position(pos); if(fVerbose >2) { pt->Print(""); //FIXME cout << endl; } // T_smearing = gRandom->Gaus(t_o, sigma_t_gap); T_smearing = gRandom->Gaus(1.21*sigma_T, sigma_T); Float_t X_local = pos.X()-X[smtype][smodule][module][cell]; Float_t Y_local = pos.Y()-Y[smtype][smodule][module][cell]; tl_new = pt->GetTime() + T_smearing - Y_local/vprop + gRandom->Gaus(0,sigma_el); tr_new = pt->GetTime() + T_smearing + Y_local/vprop + gRandom->Gaus(0,sigma_el); if(fVerbose >1 || TMath::Abs(X_local)>1.5) { cout << "-W- TofHitProNew " << j <<". Poi," << " TID:" << trackID << " detID: " << detID << " cellID: " << cellID << " SMtype: " << smtype << " SM: " << smodule << " Mod: " << module << " Str: " << cell << " G: " << gap << " posX " << Form("%6.2f",pos.X())<<","<< Form("%6.2f",X[smtype][smodule][module][cell]) << " posY " << Form("%6.2f",pos.Y())<<","<< Form("%6.2f",Y[smtype][smodule][module][cell]) << " tl " << Form("%6.2f",tl_new) << " tr " << Form("%6.2f",tr_new) << endl; if(TMath::Abs(X_local)>1.5) { continue; //prevent crashes } } //Take the fastest time from all the points/gaps in this cell if(tl_newAt(ref); if(trackID_left[t][i][j][k]==trackID_right[t][i][j][k]){ flag = 1; nFl1++; // Check consistency if(fVerbose >2) { pt->Position(pos); cout << " pos check for point "<1) { // if(1) { cout << ii++ << " Add hit smt " << t << " sm " << i << " mod " << j << " str " << k <<" Ch " << iCh <<" tl " << tl[t][i][j][k] << " tr " << tr[t][i][j][k] <<" xh " << xHit << " yh " << yHit << " fl "<< flag << " refPoi " << ref <<" TID "<< trackID_left[t][i][j][k] <<","<GetDetectorID(), hitPos, hitPosErr, ref, tHit, flag, iCh); } } } } } cout << "-I- CbmTofHitProducerNew : " << fNHits+1 << " hits in Tof created, "<< nFl1<< " single, "<< nFl2<< " multiple hits " << endl; } // ---- Add Hit to HitCollection -------------------------------------- void CbmTofHitProducerNew::AddHit(Int_t detID, TVector3 &posHit, TVector3 &posHitErr, Int_t ref, Double_t tHit, Int_t flag, Int_t iChannel) { // new((*fHitCollection)[fNHits]) CbmTofHit(detID, posHit, posHitErr, ref, tHit, flag, iChannel); new((*fHitCollection)[fNHits]) CbmTofHit(detID, posHit, posHitErr, ref, tHit, flag); if(fVerbose > 1) { CbmTofHit* tofHit = (CbmTofHit*) fHitCollection->At(fNHits); tofHit->Print(); cout << endl; } } // ---- Finish -------------------------------------------------------- void CbmTofHitProducerNew::Finish() { } // ---- SetSigmaT ----------------------------------------------------- void CbmTofHitProducerNew::SetSigmaT(Double_t sigma) { fSigmaT = sigma; } // ---- SetSigmaEl ----------------------------------------------------- void CbmTofHitProducerNew::SetSigmaEl(Double_t sigma) { fSigmaEl = sigma; } // ---- SetSigmaXY ----------------------------------------------------- void CbmTofHitProducerNew::SetSigmaXY(Double_t sigma) { fSigmaXY = sigma; } // ---- SetSigmaY ----------------------------------------------------- void CbmTofHitProducerNew::SetSigmaY(Double_t sigma) { fSigmaY = sigma; } // ---- SetSigmaZ ----------------------------------------------------- void CbmTofHitProducerNew::SetSigmaZ(Double_t sigma) { fSigmaZ = sigma; } // ---- GetSigmaT ----------------------------------------------------- Double_t CbmTofHitProducerNew::GetSigmaT() { return fSigmaT; } // ---- GetSigmaEl ----------------------------------------------------- Double_t CbmTofHitProducerNew::GetSigmaEl() { return fSigmaEl; } // ---- GetSigmaXY ----------------------------------------------------- Double_t CbmTofHitProducerNew::GetSigmaXY() { return fSigmaXY; } // ---- GetSigmaY ----------------------------------------------------- Double_t CbmTofHitProducerNew::GetSigmaY() { return fSigmaY; } // ---- GetSigmaZ ----------------------------------------------------- Double_t CbmTofHitProducerNew::GetSigmaZ() { return fSigmaZ; } ClassImp(CbmTofHitProducerNew)