// -------------------------------------------------------------------------- // ----- Class CbmTofHitProducer ------ // ----- 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 "CbmTofHitProducer.h" #include "CbmTofPoint.h" #include "CbmTofHit.h" #include "CbmMCTrack.h" #include "FairRootManager.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 ------------------------------------------- CbmTofHitProducer::CbmTofHitProducer() { fVerbose = 1; fSigmaT = 0.; fSigmaXY = 0.; fSigmaY = 0.; fSigmaZ = 0.; fNHits = -1; } // ---- Constructor ---------------------------------------------------- CbmTofHitProducer::CbmTofHitProducer(const char *name, Int_t verbose) :FairTask(name,verbose) { fVerbose = verbose; fSigmaT = 0.; fSigmaXY = 0.; fSigmaY = 0.; fSigmaZ = 0.; fNHits = -1; } // ---- Destructor ---------------------------------------------------- CbmTofHitProducer::~CbmTofHitProducer() { // FairRootManager *fManager =FairRootManager::Instance(); // fManager->Write(); } // ---- Init ---------------------------------------------------------- InitStatus CbmTofHitProducer::Init() { cout << "nh - version of CbmTofHitProducer initializing" << endl; FairRootManager *fManager = FairRootManager::Instance(); fTofPoints = (TClonesArray *) fManager->GetObject("TofPoint"); fMCTracks = (TClonesArray *) fManager->GetObject("MCTrack"); FILE *par; //Reading the parameter file. In the future this must be done in a different way. char header='#'; int module, cell, smodule, smtype; Int_t nsmtyp=10, nsm=255, nmodules=10, ncells=255; Float_t X_tmp, Y_tmp, Z_tmp, Dx_tmp, Dy_tmp; // 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"; tofGeoFile += "/parameters/tof/par_tof.txt"; par=fopen(tofGeoFile,"r"); if(par==NULL) { printf("\n ERROR WHILE OPENING THE PARAMETER FILE IN TOF HIT PRODUCER!"); return kFATAL; } // initialize accounting variables ActSMtypMax=0; for (Int_t i=0; i<=maxSMtyp; i++){ ActnSMMax[i]=0; ActnModMax[i]=0; ActnCellMax[i]=0; } //Skip the header. In the future the header structure must be defined. FIXME while (fscanf(par,"%c",&header)>=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.; //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.; } fclose(par); cout << "Filled position array with ActSMtypMax " << ActSMtypMax << endl; for (Int_t i=1; i<=ActSMtypMax; i++){ cout << " SMtype " << i <<" nsmod " << ActnSMMax[i] << " nmod "<< ActnModMax[i] << " ncell " << ActnCellMax[i] << endl; } fHitCollection = new TClonesArray("CbmTofHit"); fManager->Register("TofHit","Tof",fHitCollection, kTRUE); cout << "-I- CbmTofHitProducer: Intialization successfull" << endl; return kSUCCESS; } // ---- Exec ---------------------------------------------------------- void CbmTofHitProducer::Exec(Option_t * option) { fHitCollection->Clear(); fNHits = -1; //Must start in -1 CbmTofPoint *pt; CbmMCTrack *mc; Int_t nTofPoint = fTofPoints->GetEntries(); Int_t nMCTracks = fMCTracks ->GetEntries(); Int_t tof_tracks = 0, tof_tracks_vert = 0, tof_tracks_local = 0; cout << "-I- CbmTofHitProducer(Exec): " << nTofPoint << " points in Tof for this event with " << nMCTracks << " MC tracks "<< endl; //Some numbers on TOF distributions for(Int_t p=0;pAt(p); if(mc->GetNPoints(kTOF)>0) tof_tracks++; if(mc->GetNPoints(kTOF)>0 && mc->GetMotherId()==-1) tof_tracks_vert++; } cout << "-I- CbmTofHitProducer : " << tof_tracks << " tracks in Tof " << endl; cout << "-I- CbmTofHitProducer : " << tof_tracks_vert << " tracks in Tof from vertex" << endl; // cout << "-I- CbmTofHitProducer : " << tof_tracks-tof_tracks_local // << " tracks in Tof able to produce a hit" << endl; TVector3 pos; Int_t ngaps=8; //FIXME: these parameters must be provided externally 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 Float_t sigma_T=0.07, sigma_Y=0.7, sigma_t_gap, t_o, T_smearing = 0, sigma_el=0.07, 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; //Here check for the validity of the parameters if(fSigmaY>1) cout<<"IRREALISTIC TOF POSITION RESOLUTION!! (HitProducer may crash)"<0)||fSigmaT>0.2) cout<<"IRREALISTIC 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(); gap = pt->GetGap(); cell = pt->GetCell(); module = pt->GetModule(); // smodule = pt->GetSModule(); // smtype = pt->GetSMtype(); smodule = 0; smtype = 0; pt->Position(pos); if(fVerbose >2) { pt->Print(""); //FIXME cout << endl; } // T_smearing = gRandom->Gaus(t_o, sigma_t_gap); T_smearing = gRandom->Gaus(0., 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 >2 || abs(X_local)>1.5) { cout << j <<". TofHit -" << " TID:" << trackID << " SMtype: " << smtype << " SM: " << smodule << " Mod: " << module << " Str: " << cell << " G: " << gap << " posX " << pos.X() << " posY " << pos.Y() << " tl " << tl_new << " tr " << tr_new << " xl " << X_local << " yl " << Y_local << endl; } //Take the fastest time from all the points/gaps in this cell if(tl_new2) { pt = (CbmTofPoint*) fTofPoints->At(ref); pt->Position(pos); cout << " pos check for point "<2) { cout <<"Add hit of smtyp " << t << " sm " << i << " mod " << j << " str " << k <<" tl " << tl[t][i][j][k] << " tr " << tr[t][i][j][k] <<" xh " << xHit << " yh " << yHit << " fl "<< flag << endl; } AddHit(pt->GetDetectorID(), hitPos, hitPosErr, ref, tHit, flag); //XXXX } } } } } cout << "-I- CbmTofHitProducer : " << fNHits+1 << " hits in Tof created, "<< nFl1<< " single, "<< nFl2<< " multiple hits " << endl; } // ---- Add Hit to HitCollection -------------------------------------- void CbmTofHitProducer::AddHit(Int_t detID, TVector3 &posHit, TVector3 &posHitErr, Int_t ref, Double_t tHit, Int_t flag) { 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 CbmTofHitProducer::Finish() { } // ---- SetSigmaT ----------------------------------------------------- void CbmTofHitProducer::SetSigmaT(Double_t sigma) { fSigmaT = sigma; } // ---- SetSigmaXY ----------------------------------------------------- void CbmTofHitProducer::SetSigmaXY(Double_t sigma) { fSigmaXY = sigma; } // ---- SetSigmaY ----------------------------------------------------- void CbmTofHitProducer::SetSigmaY(Double_t sigma) { fSigmaY = sigma; } // ---- SetSigmaZ ----------------------------------------------------- void CbmTofHitProducer::SetSigmaZ(Double_t sigma) { fSigmaZ = sigma; } // ---- GetSigmaXY ----------------------------------------------------- Double_t CbmTofHitProducer::GetSigmaT() { return fSigmaT; } // ---- GetSigmaXY ----------------------------------------------------- Double_t CbmTofHitProducer::GetSigmaXY() { return fSigmaXY; } // ---- GetSigmaY ----------------------------------------------------- Double_t CbmTofHitProducer::GetSigmaY() { return fSigmaY; } // ---- GetSigmaZ ----------------------------------------------------- Double_t CbmTofHitProducer::GetSigmaZ() { return fSigmaZ; } ClassImp(CbmTofHitProducer)