00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #include<Stiostream.h>
00068 #include "TStopwatch.h"
00069 #include<assert.h>
00070 #include<math.h>
00071 #include"TROOT.h"
00072 #include<TRandom.h>
00073 #include<TBrowser.h>
00074 #include<TPad.h>
00075 #include<StMessMgr.h>
00076 #include<TFile.h>
00077
00078 #include "StPmdUtil/StPmdGeom.h"
00079 #include "StPmdClusterMaker.h"
00080 #include "StPmdAbsClustering.h"
00081 #include "StPmdClustering.h"
00082 #include "StPmdUtil/StPmdDetector.h"
00083 #include "StPmdUtil/StPmdModule.h"
00084 #include "StPmdUtil/StPmdCollection.h"
00085 #include "StPmdUtil/StPmdClusterCollection.h"
00086 #include "StPmdUtil/StPmdCluster.h"
00087
00088 #include "StDbLib/StDbManager.hh"
00089 #include "StDbLib/StDbTable.h"
00090 #include "StDbLib/StDbConfigNode.hh"
00091
00092
00093 #include "StEventTypes.h"
00094 #include "StThreeVectorD.hh"
00095 #include "StHelixD.hh"
00096 #include "StPhysicalHelixD.hh"
00097 #include "StThreeVector.hh"
00098 #include "StHelix.hh"
00099 #include "SystemOfUnits.h"
00100
00101 ClassImp(StPmdClusterMaker)
00102
00103 TDataSet *clusterIn;
00104 StPmdCollection *cluster_hit;
00105 Float_t xv,yv,zv;
00106
00107 StPmdClusterMaker::StPmdClusterMaker(const char *name):StMaker(name)
00108 {
00109 mOptHist=kFALSE;
00110
00111
00112
00113
00114 mOptCalibrate=kFALSE;
00115
00116
00117
00118 mOptSimulate=kFALSE;
00119
00120
00121
00122
00123
00124 mOptRefineCluster=kFALSE;
00125
00126 cout<<" Default options: mOptCalibrate = "<<mOptCalibrate<<" mOptRefineCluster = "<<mOptRefineCluster<<" mOptSimulate="<<mOptSimulate<<endl;
00127 PMD_MIP=0.0;
00128
00129 }
00130
00131
00132 StPmdClusterMaker::~StPmdClusterMaker()
00133 {
00134 }
00135
00136 Int_t StPmdClusterMaker::Init()
00137 {
00138
00139 if(mOptHist)bookHistograms();
00140
00141 return StMaker::Init();
00142 }
00143
00144
00145 Int_t StPmdClusterMaker::InitRun(Int_t runnr) {
00146
00147 if(Debug())cout<<"StPmdClusterMaker::InitRun with run "<<runnr<<endl;
00148
00149 if(mOptCalibrate==kTRUE){
00150 ReadCalibrationsConst();
00151 }else{
00152 cout<<"Not reading the calibration Constants"<<endl;
00153 }
00154
00155 return StMaker::InitRun(runnr);
00156
00157 }
00158
00159
00160 void StPmdClusterMaker::bookHistograms()
00161 {
00162 mNclust= new TH1F("Nclust","Nclust (no cut)",100,-0.5,100.5);
00163 mNclust1= new TH1F("Nclust1","Nclust (1MIP cut)",100,-0.5,100.5);
00164 mNclust2= new TH1F("Nclust2","Nclust (2MIP cut)",100,-0.5,100.5);
00165 mNclust3= new TH1F("Nclust3","Nclust (3MIP cut)",100,-0.5,100.5);
00166
00167 mSmPmdCluster = new TH1F("Smno_pmd","SuperModule No",24,1.,24.);
00168 mEdepPmdCluster = new TH1F("EdepPmd","Energy deposited",10000,0.,10000);
00169 mSigmaLPmdCluster = new TH1F("SigmaLClusterPmd","Cluster SigmaL",50,0.5,4.5);
00170 mSigmaSPmdCluster = new TH1F("SigmaSClusterPmd","Cluster SigmaS",50,0.5,4.5);
00171 mNcellPmdCluster = new TH1F("NcellPmd","No of Cells per cls",50,-0.5,49.5);
00172 mEtaPmdCluster = new TH1F("EtaPmd","Eta Distribution",100,-4.,-2.);
00173 mPhiPmdCluster = new TH1F("PhiPmd","Phi Distribution",100,-3.14,3.14);
00174 mPmdCluster = new TH1F("PmdCluster"," NCluster in PMD",100,0,5000);
00175 mPhi2ModPmd = new TH2F("Phi2ModPmd","Phi vs Mod",12,0.5,12.5,360,-3.14,3.14);
00176 mHitVscluster = new TH2F("Pmd_hitvsClus","Hit vsclusPMD",50,0.5,50.5,50,0.5,50.5);
00177 mSigmaLCpvCluster = new TH1F("SigmaLClusterCpv","Cluster SigmaL",50,0.5,4.5);
00178 mSigmaSCpvCluster = new TH1F("SigmaSClusterCpv","Cluster SigmaS",50,0.5,4.5);
00179 mSmCpvCluster = new TH1F("Smno_cpv","CPV SuperModule No",24,1.,24.);
00180 mEdepCpvCluster = new TH1F("EdepCpv","Cpv Energy deposited",5000,0.,5000.);
00181 mNcellCpvCluster = new TH1F("NcellCpv","No of Cellsper cls (CPV)",50,-0.5,49.5);
00182 mEtaCpvCluster = new TH1F("EtaCpv","Cpv Eta Distribution",100,-4.,-2.);
00183 mPhiCpvCluster = new TH1F("PhiCpv","Cpv Phi Distribution",100,-3.14,3.14);
00184 mCpvCluster = new TH1F("CPVCluster"," NCluster in CPV",100,0,5000);
00185 mXYCpvCluster = new TH2F("CPV2D" ,"CPV Cluster 2D", 400,-200.,200.,400,-200.,200.);
00186 mXYPmdCluster = new TH2F("PMD2D" ,"PMD Cluster 2D", 400,-200.,200.,400,-200.,200.);
00187 }
00188
00189 Int_t StPmdClusterMaker::Make()
00190 {
00191 TStopwatch clock;
00192 clock.Start();
00193 clusterIn = GetDataSet("PmdSimulator");
00194 if(!clusterIn){
00195 clusterIn = GetDataSet("pmdReader");
00196 }
00197 if(!clusterIn){
00198 cout<<" No Hit_dataset found, return "<<endl;
00199 return kStWarn;
00200 }
00201 cluster_hit = (StPmdCollection*)clusterIn->Find("PmdCollection");
00202
00203 if(!cluster_hit){
00204 cout<<" No PmdCollection found, return "<<endl;
00205 return kStWarn;
00206 }
00207
00208
00209 if(cluster_hit)
00210 {
00211 StPmdDetector * cpv_det = cluster_hit->detector(Int_t(0));
00212 StPmdDetector * pmd_det = cluster_hit->detector(Int_t(1));
00213
00214
00215
00216 Int_t cpv_hits = cpv_det->numberOfHits();
00217 Int_t pre_hits = pmd_det->numberOfHits();
00218 cout<<" Number of hits on CPV = "<<cpv_hits<<endl;
00219 cout<<" Number of hits on PMD = "<<pre_hits<<endl;
00220 if((cpv_hits + pre_hits)>15000){
00221 cout<<" The number of hits on PMD are too large"<<endl;
00222 cout<<" The existing limit is 15000 hit on CPV+Pre"<<endl;
00223 return kStWarn;
00224 }
00225
00226
00227 Int_t choice=1;
00228
00229 if(choice==1){
00230 if(cpv_det && pmd_det){
00231 StPmdClustering *clust1 = new StPmdClustering(pmd_det, cpv_det);
00232
00233 if(PMD_MIP>0){
00234
00235 Double_t adccutoff = (Double_t)(PMD_MIP*0.15);
00236
00237 clust1->SetAdcCutOff(adccutoff);
00238 }else{
00239 if(mOptCalibrate==kFALSE) {
00240 clust1->SetAdcCutOff(7.0);
00241 clust1->SetOptCalibrate(kFALSE);
00242 }
00243 }
00244 if(mOptSimulate==kTRUE) {
00245 cout<<" Simulationflag is ON so the cutoff is set to 0.4"<<endl;
00246 clust1->SetAdcCutOff(0.4);
00247 clust1->SetOptSimulate(kTRUE);
00248 }
00249 if(mOptRefineCluster==kFALSE) {
00250 cout<<" Refined clustering is put off. (Default = ON)"<<endl;
00251 clust1->SetOptRefineCluster(kFALSE);
00252 }
00253
00254
00255 StEvent *currevent = (StEvent*)GetInputDS("StEvent");
00256 if(!currevent){
00257 cout<<"ClusterMaker **, No StEvent Pointer "<<endl;
00258 }
00259 StPrimaryVertex* Vertex=currevent->primaryVertex();
00260
00261 if(Vertex){
00262 StThreeVectorF v = Vertex->position();
00263
00264 clust1->SetVertexPos(v);
00265 }
00266
00267 if(clust1)
00268 {
00269 for(Int_t d=0;d<2;d++)
00270 {
00271 StPmdDetector *det = cluster_hit->detector(d);
00272
00273 clust1->findPmdClusters2(det);
00274
00275
00276 }
00277 }
00278 else
00279 {
00280 cout<<"clust1 not made"<<endl;
00281 return kStOK;
00282 }
00283 FillStEvent(pmd_det,cpv_det);
00284 cout<<" Number of pmd clusters="<<((StPmdClusterCollection*)pmd_det->cluster())->Nclusters()<<endl;
00285 cout<<" Number of cpv clusters="<<((StPmdClusterCollection*)cpv_det->cluster())->Nclusters()<<endl;
00286
00287
00288 if(mOptHist)FillHistograms(pmd_det,cpv_det);
00289
00290 }
00291 }
00292 }
00293
00294
00295
00296
00297
00298 return kStOK;
00299 }
00300
00301 void StPmdClusterMaker::Browse(TBrowser *b)
00302 {
00303 TDataSet::Browse(b);
00304 }
00305
00306 void StPmdClusterMaker::FillHistograms(StPmdDetector* pmd_det, StPmdDetector* cpv_det)
00307 {
00309 Int_t tothitpmd=0;
00310 Int_t tothitcpv=0;
00311 for(Int_t id=1;id<=12;id++){
00312 if(pmd_det->module_hit(id)>0){
00313 Int_t nmh=pmd_det->module_hit(id);
00314 tothitpmd+=nmh;
00315 }
00316
00317 if(cpv_det->module_hit(id)>0){
00318 Int_t nmh1=cpv_det->module_hit(id);
00319 tothitcpv+=nmh1;
00320 }
00321 }
00322
00323 StPmdClusterCollection* clusters = (StPmdClusterCollection*)pmd_det->cluster();
00324 StPmdClusterCollection* cpvclusters = (StPmdClusterCollection*)cpv_det->cluster();
00325
00326 Int_t nclust = clusters->Nclusters();
00327
00328 Int_t nclust_cpv = cpvclusters->Nclusters();
00329
00331 TIter next(clusters->Clusters());
00332
00333 StPmdCluster *spmcl1;
00334 for(Int_t i=0; i<nclust ; i++)
00335 {
00336 spmcl1 = (StPmdCluster*)next();
00337 Float_t eta=spmcl1->CluEta();
00338 Float_t phi=spmcl1->CluPhi();
00339 Float_t edep=spmcl1->CluEdep();
00340 Float_t sigmaL=spmcl1->CluSigmaL();
00341 Float_t sigmaS=spmcl1->CluSigmaS();
00342 Int_t mod=spmcl1->Module();
00343 Float_t ncell=spmcl1->NumofMems();
00344 Float_t xclu = spmcl1->CluX();
00345 Float_t yclu = spmcl1->CluY();
00346
00347 mSmPmdCluster->Fill(Float_t(mod));
00348 mEdepPmdCluster->Fill(edep);
00349 mSigmaLPmdCluster->Fill(sigmaL);
00350 mSigmaSPmdCluster->Fill(sigmaS);
00351 mNcellPmdCluster->Fill(ncell);
00352 mEtaPmdCluster->Fill(eta);
00353 mPhiPmdCluster->Fill(phi);
00354 mXYPmdCluster->Fill(xclu,yclu);
00355 }
00356 mHitVscluster->Fill(tothitpmd,Float_t(nclust));
00357 mPmdCluster->Fill(nclust);
00358 mCpvCluster->Fill(nclust_cpv);
00360 TIter nextcpv(cpvclusters->Clusters());
00361 StPmdCluster *spmcl2;
00362 for(Int_t i=0; i<nclust_cpv ; i++)
00363 {
00364 spmcl2 = (StPmdCluster*)nextcpv();
00365 Float_t eta=spmcl2->CluEta();
00366 Float_t phi=spmcl2->CluPhi();
00367 Float_t edep=spmcl2->CluEdep();
00368 Int_t mod=spmcl2->Module();
00369 Float_t sigmaL=spmcl2->CluSigmaL();
00370 Float_t sigmaS=spmcl2->CluSigmaS();
00371 Float_t ncell1=spmcl2->NumofMems();
00372 Float_t xclu = spmcl2->CluX();
00373 Float_t yclu = spmcl2->CluY();
00374
00375
00376 mSmCpvCluster->Fill(Float_t(mod));
00377 mEdepCpvCluster->Fill(edep);
00378 mSigmaLCpvCluster->Fill(sigmaL);
00379 mSigmaSCpvCluster->Fill(sigmaS);
00380 mNcellCpvCluster->Fill(ncell1);
00381 mEtaCpvCluster->Fill(eta);
00382 mPhiCpvCluster->Fill(phi);
00383 mXYCpvCluster->Fill(xclu,yclu);
00384 }
00385
00386 }
00387
00388 Int_t StPmdClusterMaker::Finish()
00389 {
00390 return StMaker::Finish();
00391 }
00392
00393
00394
00395
00396 void StPmdClusterMaker::FillStEvent(StPmdDetector* pmd_det, StPmdDetector* cpv_det)
00397 {
00398 cout<<"Filling StEvent in ClusterMaker"<<endl;
00399
00400 StPhmdCollection * PmdCollection=NULL;
00401 StEvent *currevent = (StEvent*)GetInputDS("StEvent");
00402 if(!currevent){
00403 cout<<"ClusterMaker **, No StEvent Pointer "<<endl;
00404 }
00405
00406 if(currevent)PmdCollection= currevent->phmdCollection();
00407 if(PmdCollection)
00408 {
00409 StPhmdDetector* evtdet0 = PmdCollection->detector(StDetectorId(kPhmdId));
00410 StPhmdDetector* evtdet1 = PmdCollection->detector(StDetectorId(kPhmdCpvId));
00411
00412 StPhmdClusterCollection* cluscollpmd = new StPhmdClusterCollection();
00413 cluscollpmd->setClusterFinderId(1);
00414 cluscollpmd->setClusterFinderParamVersion(1);
00415
00416 StPhmdClusterCollection* cluscollcpv = new StPhmdClusterCollection();
00417 cluscollcpv->setClusterFinderId(1);
00418 cluscollcpv->setClusterFinderParamVersion(1);
00419
00420 StPmdClusterCollection* clusters = (StPmdClusterCollection*)pmd_det->cluster();
00421 StPmdClusterCollection* cpvclusters = (StPmdClusterCollection*)cpv_det->cluster();
00422
00423 Int_t nclust = clusters->Nclusters();
00424 Int_t nclust_cpv = cpvclusters->Nclusters();
00425
00427 if(evtdet0)
00428 {
00429 evtdet0->setCluster(cluscollpmd);
00430 TIter next(clusters->Clusters());
00431 StPmdCluster *spmcl1;
00432 Int_t clustmip1=0;
00433 Int_t clustmip2=0;
00434 Int_t clustmip3=0;
00435 for(Int_t i=0; i<nclust ; i++)
00436 {
00437 spmcl1 = (StPmdCluster*)next();
00438 Float_t eta=spmcl1->CluEta();
00439 Float_t phi=spmcl1->CluPhi();
00440 Float_t edep=spmcl1->CluEdep();
00441 Float_t sigmaL=spmcl1->CluSigmaL();
00442 Float_t sigmaS=spmcl1->CluSigmaS();
00443 Int_t tempL=Int_t(sigmaL*1000);
00444 Int_t tempS=Int_t(sigmaS*1000);
00445 Int_t SigInt=tempL*10000+tempS;
00446 if(edep>2.5)clustmip1++;
00447 if(edep>5.)clustmip2++;
00448 if(edep>7.5)clustmip3++;
00449
00450 Int_t mod=spmcl1->Module();
00451 Float_t ncell=spmcl1->NumofMems();
00452
00453
00454 StPhmdCluster *pcls = new StPhmdCluster();
00455
00456
00457 pcls->setModule(mod-1);
00458 pcls->setNumberOfCells(Int_t(ncell));
00459
00460
00461 pcls->setEta(eta);
00462 pcls->setPhi(phi);
00463 pcls->setEnergy(edep);
00464 pcls->setSigma((Float_t)SigInt);
00465
00466
00467 cluscollpmd->addCluster(pcls);
00468 }
00469 if(mOptHist){
00470 mNclust->Fill(nclust);
00471 mNclust1->Fill(clustmip1);
00472 mNclust2->Fill(clustmip2);
00473 mNclust3->Fill(clustmip3);
00474 }
00475 }
00476
00478 if(evtdet1)
00479 {
00480 evtdet1->setCluster(cluscollcpv);
00481 TIter nextcpv(cpvclusters->Clusters());
00482 StPmdCluster *spmcl2;
00483 for(Int_t i=0; i<nclust_cpv ; i++)
00484 {
00485 spmcl2 = (StPmdCluster*)nextcpv();
00486 Float_t eta=spmcl2->CluEta();
00487 Float_t phi=spmcl2->CluPhi();
00488 Float_t edep=spmcl2->CluEdep();
00489 Float_t sigmaL=spmcl2->CluSigmaL();
00490 Float_t sigmaS=spmcl2->CluSigmaS();
00491 Int_t tempL=Int_t(sigmaL*1000);
00492 Int_t tempS=Int_t(sigmaS*1000);
00493 Int_t SigInt=tempL*10000+tempS;
00494 Int_t mod=spmcl2->Module();
00495 Float_t ncell=spmcl2->NumofMems();
00496
00497
00498 StPhmdCluster *pcls = new StPhmdCluster();
00499
00500 pcls->setModule(mod-1);
00501 pcls->setNumberOfCells(Int_t(ncell));
00502
00503
00504 pcls->setEta(eta);
00505 pcls->setPhi(phi);
00506 pcls->setEnergy(edep);
00507 pcls->setSigma(Float_t(SigInt));
00508 cluscollcpv->addCluster(pcls);
00509 }
00510 }
00511 }
00512 cout<<"Filled PMD StEvent in ClusterMaker"<<endl;
00513 }
00514
00515
00516
00517
00518 Bool_t StPmdClusterMaker::ReadCalibrationsConst()
00519 {
00520 if(Debug())cout<<" I AM IN READCALIB "<<endl;
00521
00522 StDbManager* mgr=StDbManager::Instance();
00523 StDbConfigNode* node=mgr->initConfig("Calibrations_pmd");
00524 node->setVersion("SMChain");
00525
00526 mDb=NULL;
00527 TString DbName = "Calibrations/pmd";
00528 mDb=GetInputDB(DbName.Data());
00529
00530 if(!mDb) return kFALSE;
00531
00532
00533 for(Int_t ism=0;ism<24;ism++){
00534 for(Int_t chain=0;chain<48;chain++){
00535 SM_chain_factor[ism][chain]=0.;
00536 }
00537 }
00538
00539 St_pmdSMChain_GNF * tab = (St_pmdSMChain_GNF*) mDb->Find("pmdSMChain_GNF");
00540 if (!tab) {
00541 cout<<"No pmdSMChain_GNF DBTable. Stopping."<<endl;
00542 return kFALSE;
00543 }
00544
00545
00546
00547
00548 pmdSMChain_GNF_st* smchain = tab->GetTable(64);
00549 PMD_MIP = smchain->mpv_factor;
00550
00551
00552 return kTRUE;
00553
00554 }
00555