00001
00002
00003
00004 #include <TVector3.h>
00005 #include <TH2.h>
00006 #include <TF1.h>
00007 #include <TFile.h>
00008 #include <TLine.h>
00009 #include <TPolyLine.h>
00010 #include <TCrown.h>
00011 #include <TRandom3.h>
00012
00013 #include "StFgtSlowSimuMaker.h"
00014 #include "HexLatice.h"
00015
00016 #include "tables/St_g2t_fgt_hit_Table.h"
00017
00018 ClassImp(StFgtSlowSimuMaker)
00019
00020
00021 StFgtSlowSimuMaker::StFgtSlowSimuMaker(const char *name):StMaker(name){
00023 setHList(0);
00024 memset(hA,0,sizeof(hA));
00025 geom=new StFgtGeom();
00026 mRnd = new TRandom3();
00027
00028
00029 forcePerpTracks(false);
00030 meLossTab[0]=-999;
00031
00032 par_2DpixAmplThres=0.1;
00033 par_stripAmplThres=1.0;
00034 par_XYamplSigma=0.035 ;
00035
00036 par_radStripGainMean=1.0;par_radStripGainSigma=0.0;
00037 par_cutoffOfBichel = 9992;
00038 mRadStripRelativeGain=0;
00039 mPhiStripRelativeGain=0;
00040 hexLat=0;
00041 }
00042
00043
00044 void
00045 StFgtSlowSimuMaker::Clear(Option_t *) {
00046 int i,j;
00047 for(i=0;i<kFgtMxDisk;i++){
00048 for(j=0;j<kFgtMxQuad;j++) {
00049 mG2tHitList[i][j].clear();
00050 }
00051 mRadAdcList[i].clear();
00052 mPhiAdcList[i].clear();
00053 }
00054 StMaker::Clear();
00055 }
00056
00057
00058
00059 StFgtSlowSimuMaker::~StFgtSlowSimuMaker(){
00060
00061 }
00062
00063
00064
00065 void
00066 StFgtSlowSimuMaker::saveHisto(TString fname){
00067
00068 CloseHisto();
00069
00070 TString outName=fname+".hist.root";
00071 TFile f( outName,"recreate");
00072 assert(f.IsOpen());
00073 printf("%d histos are written to '%s' ...\n",HList->GetEntries(),outName.Data());
00074
00075 HList->Write();
00076 f.Close();
00077
00078 }
00079
00080
00081
00082
00083
00084 Int_t
00085 StFgtSlowSimuMaker::Finish(){
00086 LOG_INFO<<"::Finish() \n"<< endm;
00087
00088
00089 return StMaker::Finish();
00090 }
00091
00092
00093
00094
00095
00096
00097 Int_t
00098 StFgtSlowSimuMaker::Init(){
00099 LOG_INFO<<"::Init() "<< endm;
00100 assert(HList);
00101 assert( meLossTab[0]>0);
00102 mInpEve=0;
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 amplF= new TF1("Gs","exp( -(x-[0])*(x-[0])/2./[1]/[1])",-1.,1.);
00114 amplF->SetParNames("X0","sig");
00115 amplF ->SetParameters(0.,par_XYamplSigma);
00116 amplF ->SetLineWidth(2); amplF->SetLineColor(kMagenta);
00117
00118 InitHisto1();
00119 InitHisto2();
00120
00121
00122 mRadStripRelativeGain=new double[geom->radStripGBLId_number()+1];
00123 memset(mRadStripRelativeGain,0,sizeof(mRadStripRelativeGain));
00124 int i;
00125 for(i=0;i<geom->radStripGBLId_number();i++) {
00126 double del=99999;
00127 while(fabs(del)> 2.*par_radStripGainSigma)
00128 del= mRnd->Gaus(0,par_radStripGainSigma);
00129 mRadStripRelativeGain[i]=par_radStripGainMean+del;
00130
00131 }
00132
00133
00134 mPhiStripRelativeGain=new double[geom->phiStripGBLId_number()+1];
00135 memset(mPhiStripRelativeGain,0,sizeof(mPhiStripRelativeGain));
00136 for(i=0;i<geom->phiStripGBLId_number();i++) {
00137 double del=99999;
00138 while(fabs(del)> 2.*par_phiStripGainSigma)
00139 del= mRnd->Gaus(0,par_phiStripGainSigma);
00140 mPhiStripRelativeGain[i]=par_phiStripGainMean+del;
00141
00142 }
00143
00144
00145 if(par_hexLaticePitch >0.001) {
00146 hexLat=new HexLatice (par_hexLaticePitch, par_hexLaticePhi1deg);
00147 } else {
00148 LOG_INFO<<Form("::Init hexGemLatice DISABLED, too small pitch")<<endm;
00149 par_hexLaticePitch = 0.0;
00150 }
00151
00152 geom->printParam();
00153
00154 LOG_INFO<<Form("::Init params: X,YamplSigma=%.4f cm, 2DpixAmplThres=%.2f a.u., stripAmplThres=%.2f a.u., forcePerpTracks=%d useOnlyDisk=%d RadGain(m=%.2f,sig=%.2f) PhiGain(m=%.2f,sig=%.2f, GemHexLatice: pitch/um=%.1f, phi1/deg=%.1f, transDiffusion=%.1f um/1cmOfPath, cutoffOfBichel=%d)",par_XYamplSigma,par_2DpixAmplThres,par_stripAmplThres,par_forcePerp,par_useOnlyDisk,par_radStripGainMean,par_radStripGainSigma,par_phiStripGainMean,par_phiStripGainSigma,par_hexLaticePitch*1e4, par_hexLaticePhi1deg,par_transDiffusionPerPath*1e4,par_cutoffOfBichel)<< endm;
00155
00156 assert(par_XYamplSigma>0);
00157
00158 Info("Init","testing access to TGeoManager");
00159
00160 if (gGeoManager) {
00161 Info("Load","TGeoManager(%s,%s) is already there"
00162 ,gGeoManager->GetName(),gGeoManager->GetTitle());
00163 } else {
00164 Warning("Init","add TGeoManager");
00165
00166
00167
00168 TString ts = "SandBox.C(0,0)";
00169
00170 int ierr=0;
00171 gROOT->Macro(ts, &ierr);
00172 assert(!ierr);
00173 }
00174 assert(gGeoManager);
00175
00176 TGeoVolume *geoFgt = gGeoManager ->FindVolumeFast("FGMO");
00177 assert(geoFgt);
00178 geoFgt -> Print();
00179 geoFgt -> InspectMaterial();
00180 geoFgt -> InspectShape();
00181 printf("XXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXX\nXXXXXXXXXX\n");
00182
00183
00184
00185 return StMaker::Init();
00186 }
00187
00188
00189
00190
00191 Int_t
00192 StFgtSlowSimuMaker::Make(){
00193 mInpEve++;
00194
00195 LOG_INFO <<"::Make() inpEve="<< mInpEve<<endm;
00196
00197 St_g2t_fgt_hit *fgt_hitT = (St_g2t_fgt_hit *) GetDataSet("g2t_fgt_hit");
00198 if(fgt_hitT ==0) {
00199 LOG_FATAL<<Form("g2t_Fgt table empty")<<endm;
00200 return kStOK;
00201 }
00202
00203
00204
00205
00206
00207
00208
00209 sort_g2t_hits( fgt_hitT );
00210
00211 int iDisk=0,iQuad=0;
00212 for(iDisk=0;iDisk<kFgtMxDisk;iDisk++) {
00213 digRad->Reset(); digPhi->Reset();
00214 if(par_useOnlyDisk) if(par_useOnlyDisk-1 != iDisk) continue;
00215 for(iQuad=0;iQuad<kFgtMxQuad;iQuad++) {
00216 digXY->Reset();
00217
00218 printf(" process %d g2t hits in disk=%d quad=%d\n", mG2tHitList[iDisk][iQuad].size(),iDisk,iQuad);
00219
00220 vector<fgt_g2t_auxil> &L=mG2tHitList[iDisk][iQuad];
00221 if(L.size()<=0) continue;
00222 for(UInt_t
00223 i=0;i<L.size();i++) {
00224
00225 responseFrankModel(L[i].Rloc,L[i].Dloc);
00226 hA[11+iDisk]->Fill(L[i].Rlab.x(),L[i].Rlab.y());
00227 printf("iQ=%d itr=%d R/cm=%.2f phi/deg=%.3f\n",iQuad,i,L[i].Rlab.Perp(), L[i].Rlab.Phi()/3.1416*180);
00228 }
00229
00230 if(!projectQuadrant(iQuad)) continue;
00231
00232
00233 }
00234
00235 exportStripPlane(digRad,mRadAdcList[iDisk]);
00236 exportStripPlane(digPhi,mPhiAdcList[iDisk]);
00237
00238 }
00239
00240 printf(" Summary of fired strips\n disk #Rad-strip #Phi-strip \n");
00241 for(iDisk=0;iDisk<kFgtMxDisk;iDisk++) printf("%d %d %d \n",iDisk,mRadAdcList[iDisk].size(),mPhiAdcList[iDisk].size());
00242
00243 return kStOK;
00244 }
00245
00246
00247
00248
00249 void
00250 StFgtSlowSimuMaker::sort_g2t_hits( St_g2t_fgt_hit *fgt_hitT){
00251 g2t_fgt_hit_st *hitPtr = fgt_hitT->GetTable();
00252 assert(hitPtr);
00253 LOG_INFO<<Form("Sorting g2t FGT hits, size=%d",fgt_hitT->GetNRows())<<endm;
00254
00255 int ntot=0;
00256 Int_t nhits = fgt_hitT->GetNRows();
00257 for(Int_t ih=0; ih<nhits; ih++,hitPtr++) {
00258 Int_t ivid = hitPtr->volume_id;
00259
00260
00261 Int_t numbv1 = ivid/1000000;
00262 Int_t numbv2 = (ivid/10000)%100;
00263 int diskID, iQuad;
00264
00265
00266 diskID = numbv1 - 1;
00267 iQuad = 0;
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 cout << " Volume_id diskID QuadID: "
00279 << ivid << " " << diskID << " " << iQuad << endl;
00280
00281 TVector3 Rlab( hitPtr->x);
00282 TVector3 Rloc=Rlab;
00283
00284
00285
00286
00287
00288
00289
00290
00291 Rloc.RotateZ(-geom->phiQuadXaxis(iQuad));
00292
00293 hA[3]->Fill(1);
00294 if(diskID!=8 && !geom->inDisk(Rlab)) continue;
00295 hA[3]->Fill(2);
00296
00297 if(fabs(Rloc.x()) < geom->deadQuadEdge()) continue;
00298 hA[3]->Fill(3);
00299 if(fabs(Rloc.y()) < geom->deadQuadEdge()) continue;
00300 hA[3]->Fill(4);
00301
00302 double tof_ns=hitPtr->tof*1.e9;
00303 hA[5]->Fill(tof_ns);
00304 if(hitPtr->tof> geom-> maxTof() ) continue;
00305 hA[3]->Fill(5);
00306
00307 TVector3 Plab(hitPtr->p);
00308 if(Plab.Mag()>0) hA[7]->Fill(log10(Plab.Mag()*1000.));
00309 if(Plab.Mag()< geom-> minPmag() ) continue;
00310 hA[3]->Fill(6);
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 int iQuadChk=geom->getQuad(Rlab.Phi());
00327 if(iQuad != iQuadChk) {
00328 cout << " Something wrong in quadIDs!! " << endl;
00329 cout << " iQuad from StFgtGeom and iQuad from Geant = "
00330 << iQuadChk << ", " << iQuad << endl;
00331 }
00332
00333
00334
00335
00336 double ds=hitPtr->ds;
00337
00338 TVector3 verLab=Plab.Unit();
00339 if(par_forcePerp) verLab=TVector3(0,0,1);
00340 TVector3 Rloc2=Rlab+ds*verLab; Rloc2.RotateZ(-geom->phiQuadXaxis(iQuad));
00341 TVector3 Dloc=Rloc2-Rloc;
00342
00343 fgt_g2t_auxil aux;
00344 aux.hitPtr=hitPtr;
00345 aux.Rloc=Rloc;
00346 aux.Dloc=Dloc;
00347 aux.Rlab=Rlab+ds/2.*verLab;
00348
00349 aux.iQuad=iQuad;
00350 mG2tHitList[diskID][iQuad].push_back(aux);
00351
00352 ntot++;
00353
00354
00355
00356
00357 hA[3]->Fill(10+5*diskID);
00358 hA[3]->Fill(10+5*diskID+iQuad+1);
00359 double de_kev=hitPtr->de*1.e6;
00360 hA[0]->Fill(de_kev);
00361 hA[1]->Fill(hitPtr->ds);
00362 hA[2]->Fill(Rlab.z());
00363 hA[4]->Fill(Rlab.x(),Rlab.y());
00364 hA[6]->Fill(Rlab.Perp());
00365
00366 }
00367 LOG_INFO<<Form("Sorting g2g FGT %d hits --> accepted %d",nhits,ntot)<<endm;
00368 }
00369
00370
00371
00372
00373
00374 bool
00375 StFgtSlowSimuMaker::projectQuadrant( int iquad) {
00376
00377 double totAmp=digXY->Integral();
00378 LOG_INFO<<Form("::digiQuad() totAmp=%g",totAmp)<< endm;
00379 if(totAmp <par_stripAmplThres) return false;
00380
00381 int nPix=0;
00382
00383 double sumAmp=0;
00384
00385 int nx=digXY->GetNbinsX();
00386 int ny=digXY->GetNbinsY();
00387 int bx,by;
00388 for(bx=1;bx<=nx;bx++)
00389 for(by=1;by<=ny;by++) {
00390 float amp=digXY->GetBinContent(bx,by);
00391 if(amp<par_2DpixAmplThres) continue;
00392 nPix++;
00393 sumAmp+=amp;
00394 double x=digXY->GetXaxis()->GetBinCenter(bx);
00395 double y=digXY->GetYaxis()->GetBinCenter(by);
00396 int iRadID,iPhiID;
00397 if( !geom->localXYtoStripID(iquad,x,y,iRadID, iPhiID)) continue;
00398
00399
00400
00401 digRad->Fill(iRadID,amp* mRadStripRelativeGain[iRadID]);
00402 digPhi->Fill(iPhiID,amp* mPhiStripRelativeGain[iPhiID]);
00403
00404 digRadAll->Fill(iRadID,amp* mRadStripRelativeGain[iRadID]);
00405 digPhiAll->Fill(iPhiID,amp* mPhiStripRelativeGain[iPhiID]);
00406
00407 }
00408 printf("digi: nPix=%d sumAmp=%g\n", nPix,sumAmp);
00409
00410 return true;
00411 }
00412
00413
00414
00415
00416
00417 void
00418 StFgtSlowSimuMaker::exportStripPlane(TH1F *h, vector<fgt_strip> &L) {
00419 float *y=h->GetArray();
00420 y++;
00421 float nx=h->GetNbinsX();
00422 for(int id=0;id<nx;id++,y++) {
00423 double ene=*y;
00424 if(ene <par_stripAmplThres) continue;
00425 fgt_strip st;
00426 st.id=id;
00427 st.adc=ene;
00428 L.push_back(st);
00429
00430 }
00431 }
00432
00433
00434
00435
00436
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460