StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPmdDiscriminatorMaker.cxx
1 /***************************************************************
2  *
3  * $Id: StPmdDiscriminatorMaker.cxx,v 1.10 2007/04/26 04:13:19 perev Exp $
4  * Author: Subhasis Chattopadhyay
5  ***************************************************************
6  *
7  * Description: StPmdDiscriminationMaker is class for photon/hadron
8  * discrimination
9  *
10  ****************************************************************
11  * $Log: StPmdDiscriminatorMaker.cxx,v $
12  * Revision 1.10 2007/04/26 04:13:19 perev
13  * Remove StBFChain dependency
14  *
15  * Revision 1.9 2005/10/21 00:54:06 subhasis
16  * fillStEvent crash due to mismatch in length of pmdclust and phmdclust fixed
17  *
18  * Revision 1.8 2005/02/23 05:17:18 subhasis
19  * DiscbyNN option fixed
20  *
21  * Revision 1.7 2004/10/30 00:08:00 subhasis
22  * TranFlag added and set to 0 in ctor
23  *
24  * Revision 1.6 2004/07/16 14:29:32 subhasis
25  * more checks on edep Discriminate
26  *
27  * Revision 1.5 2004/07/13 12:59:11 subhasis
28  * Ncluster() is put with check in PrepareInput()
29  *
30  * Revision 1.4 2003/09/02 17:58:48 perev
31  * gcc 3.2 updates + WarnOff
32  *
33  * Revision 1.3 2003/08/04 18:53:44 perev
34  * warnOff
35  *
36  * Revision 1.2 2003/05/29 13:12:51 subhasis
37  * several changes to include NN
38  *
39  ****************************************************************/
40 #include<Stiostream.h>
41 #include<assert.h>
42 #include<math.h>
43 #include"TROOT.h"
44 #include<TRandom.h>
45 #include<TBrowser.h>
46 #include<TPad.h>
47 #include<StMessMgr.h>
48 #include<TFile.h>
49 
50 #include "StPmdDiscriminator.h"
51 #include "StPmdDiscriminatorMaker.h"
52 #include "StPmdDiscriminatorNN.h"
53 #include "StPmdUtil/StPmdCollection.h"
54 #include "StPmdUtil/StPmdDetector.h"
55 #include "StPmdUtil/StPmdClusterCollection.h"
56 #include "StPmdUtil/StPmdCluster.h"
57 #include "StNNCluster.h"
58 #include "StEventTypes.h"
59 
60 StPmdCl NNContainer;
61 Int_t EventProcessed=0;
62 Int_t EtaPhiArr_CPV[400][1400];
63 
65  TDataSet *clusterIn;
67 StPmdCollection *cluster_hit;
69 
70 bool discbyNN=false;
72  mApplyFlagNN=0;
73  mTrainFlag=0;
74 }
75 
76 StPmdDiscriminatorMaker::~StPmdDiscriminatorMaker()
77 {
78  // !destructor
79 }
80 
81 Int_t StPmdDiscriminatorMaker::Init()
82 {
84  return StMaker::Init();
85 }
86 
88 {
89  mEdepPmd = new TH1F("EdepPmd","Energy deposited",100,0.,0.02);
90  mEtaPmd = new TH1F("EtaPmd","Eta Distribution",100,-6., 6.);
91  mPhiPmd = new TH1F("PhiPmd","Phi Distribution",100,-3.14,3.14);
92  mMCPID = new TH1F("McPID","Mc PID",11,-0.5,10.5);
93  mcpvmatched = new TH1F("cpvmatched","CPV Matched",100,0,100.);
94  mEtadiff = new TH1F("DeltaEta","Eta Difference",200,0.,200.);
95  mPhidiff = new TH1F("DeltaPhi","Phi Difference",4000,0.,3000.);
96  mEtaPhi = new TH2F("DeltaEtaDetaPhi","(Delta) Eta Phi Distribution",100,0,200.,4000,0.,3000.);
97  mClusterPID = new TH1F("ClusterPID","ClusterPID based on matching",10,0.5,10.5);
98  mClusterEdepPID = new TH1F("ClusterEdepPID","ClusterPID based on Edep",10,0.5,10.5);
99  mEdepVsPID = new TH2F("EdepVsPID","PID based on Edep",100,0.,200.,100,0.,10.);
100  mNNoutput = new TH1F("NNTrainOut","Training output from NN",100,0.,2.);
101 }
102 
104 {
105  EventProcessed++;
106 
108  StEvent *currevent = (StEvent*)GetInputDS("StEvent");
109  if(!currevent){
110  cout << "PMDDISC ***** Can not get StEvent pointer . sorry \n"; return kStErr;
111  }
112 
113  StPhmdCollection* phmdcl = (StPhmdCollection*)currevent->phmdCollection();
114  clusterIn = GetDataSet("PmdSimulator");
115  cluster_hit = (StPmdCollection*)clusterIn->Find("PmdCollection");
116  StPmdDetector* pmd_det;
117  StPmdDetector* cpv_det;
118  if(cluster_hit){
119  pmd_det = cluster_hit->detector(Int_t(0));
120  cpv_det = cluster_hit->detector(Int_t(1));
121  }
122 
123  if(phmdcl){
124  StPhmdClusterCollection* cluscoll;
125  StPhmdClusterCollection* cpvcluscoll;
126  for(Int_t d=0;d<2;d++){
127  StDetectorId pdet=static_cast<StDetectorId>(kPhmdCpvId+d);
128  StPhmdDetector* detector=(StPhmdDetector*)phmdcl->detector(StDetectorId(pdet));
129  if(detector){
130  if(d==1)cluscoll = detector->cluster();
131  if(d==0)cpvcluscoll = detector->cluster();
132  if(d==1){
133  if(discbyNN){
134  Int_t ret=PrepareInputforNN(pmd_det,cpv_det,cluscoll,cpvcluscoll);
135  if(ret==1)goto DISC;
136  }
137  }
138  if(d==1&&cluscoll)cout<<"ncls "<<cluscoll->numberOfclusters()<<endl;
139  }
140  }
141  }
142  cout<<"DISCMAKER*****"<<mApplyFlagNN<<endl;
143  if(mApplyFlagNN==1){
144 
145  StPmdDiscriminatorNN *discNN = new StPmdDiscriminatorNN(NNContainer);
146  discNN->setApplyFlag(1);
147  discNN->setDisMaker(this);
148 
149  if(discNN)
150  {
151  discNN->Discriminate();
152  }
153  NNContainer.clear();
154 
155  }
156 
157  DISC:
158 
159  if(cluster_hit){
160  StPmdDetector * pmd_det = cluster_hit->detector(Int_t(0));
161  StPmdDetector * cpv_det = cluster_hit->detector(Int_t(1));
162  StPmdDiscriminator *disc = new StPmdDiscriminator(mEdepThreshold, pmd_det, cpv_det);
163 
164  if(disc){
165  disc->SetEdepcut(0.0000063);
166  cout<<"calling edep_disc "<<endl;
167 
168  disc->Discriminate();
169  // disc->Print(); //! Print photon like hits
170  }
171  fillHistograms(pmd_det,cpv_det);
172  }
173 
175 
176  fillStEvent(cluster_hit,phmdcl);
177 
179 
180  return kStOK;
181 }
182 
183 
185 {
186  TDataSet::Browse(b);
187 }
188 
189 void StPmdDiscriminatorMaker::fillHistograms(StPmdDetector* pmd_det, StPmdDetector* cpv_det)
190 {
191  StPmdClusterCollection* clusters = (StPmdClusterCollection*)pmd_det->cluster();
192  Int_t nclust=0;
193  if(clusters){nclust = clusters->Nclusters();}
194 
195  if(nclust>0){
196  TIter next(clusters->Clusters());
197  StPmdCluster *spmcl1;
198  for(Int_t i=0; i<nclust ; i++)
199  {
200  spmcl1 = (StPmdCluster*)next();
201  // Float_t eta=spmcl1->CluEta();
202  // Float_t phi=spmcl1->CluPhi();
203  Float_t edep=spmcl1->CluEdep();
204  Int_t PID=spmcl1->CluPID();
205  Int_t EdepPID=spmcl1->CluEdepPID();
206 
207  mEdepVsPID->Fill(edep*1000000,Float_t(EdepPID));
208  mClusterPID->Fill(Float_t(PID));
209  mClusterEdepPID->Fill(Float_t(EdepPID));
210  }
211  }
212 }
213 
214 
215 Int_t StPmdDiscriminatorMaker::PrepareInputforNN(StPmdDetector* pmd_det,StPmdDetector* cpv_det,StPhmdClusterCollection* cluscoll,StPhmdClusterCollection* cpvcluscoll)
216 
217 {
218  cout<<"prepareInput***"<<endl;
219  Double_t etapmd,phipmd,edeppmd;
220  Double_t etacpv,phicpv,edepcpv;
221 
222  Bool_t mcpvdone;
223 
224  for(Int_t ibineta=0;ibineta<400;ibineta++){
225  for(Int_t ibinphi=0;ibinphi<1400;ibinphi++){
226  EtaPhiArr_CPV[ibineta][ibinphi]=-999;
227  }
228  }
229 
230  StPmdClusterCollection* clusters = (StPmdClusterCollection*)pmd_det->cluster();
231  StPmdClusterCollection* clusters1 = (StPmdClusterCollection*)cpv_det->cluster();
232  // Int_t nclust = clusters->Nclusters();
233 
234  if(cluscoll){
235  Int_t Ncluster0=cluscoll->numberOfclusters();
236  if(Ncluster0>0)
237  {
238  const StSPtrVecPhmdCluster& pmdclusters= cluscoll->clusters();
239  const StSPtrVecPhmdCluster& cpvclusters= cpvcluscoll->clusters();
240 
241  cout<<"PMD cluster size "<<pmdclusters.size()<<endl;
242  cout<<"CPV cluster size "<<cpvclusters.size()<<endl;
243 
244 if(clusters1){
245  Int_t nclust1=0;
246  nclust1 = clusters1->Nclusters();
247  TIter nextCPV(clusters1->Clusters());
248  StPmdCluster *spmcl2;
249  for(Int_t icpv=0; icpv<nclust1 ; icpv++)
250  {
251  Int_t etabin,phibin;
252  spmcl2 = (StPmdCluster*)nextCPV();
253  etacpv=spmcl2->CluEta();
254  phicpv=spmcl2->CluPhi();
255  edepcpv=spmcl2->CluEdep();
256 
257  if(fabs(etacpv)>2. && fabs(etacpv)<4.){etabin=Int_t((fabs(etacpv)-2)/mDeltaEta);}
258  if(fabs(phicpv)<3.14){phibin=Int_t((phicpv+3.14)/mDeltaPhi);}
259  EtaPhiArr_CPV[etabin][phibin]=icpv;
260  }
261  }
262 
263 
264  Int_t cpvmatched=0;
265  Int_t hadmatched=0;
266  StPmdCluster *spmcl1;
267  if(clusters){
268  TIter next(clusters->Clusters());
269  for(UInt_t i=0;i<pmdclusters.size();i++)
270  {
271  Int_t etabin,phibin;
272  mcpvdone=true;
273  spmcl1 = (StPmdCluster*)next();
274  StPhmdCluster *cl1=(StPhmdCluster*)pmdclusters[i];
275  cl1->setMcPid(spmcl1->McCluPID());
276 
277  StNNCluster* nncls = new StNNCluster();
278  nncls->setPmdCluster(cl1);
279 
280  etapmd=spmcl1->CluEta();
281  phipmd=spmcl1->CluPhi();
282  edeppmd=spmcl1->CluEdep();
283  mMCPID->Fill(Float_t(spmcl1->McCluPID()));
284 
285  if(fabs(etapmd)>2. && fabs(etapmd)<4.)etabin=Int_t((fabs(etapmd)-2)/mDeltaEta);
286  if(fabs(phipmd)<3.14)phibin=Int_t((phipmd+3.14)/mDeltaPhi);
287 
288  for(Int_t ibineta=0;ibineta<400;ibineta++){
289  for(Int_t ibinphi=0;ibinphi<1400;ibinphi++){
290  if(EtaPhiArr_CPV[ibineta][ibinphi]!=-999 && EtaPhiArr_CPV[ibineta][ibinphi]!=0){
291  Float_t etadiff=abs(ibineta-etabin);
292  Float_t phidiff=abs(ibinphi-phibin);
293  mEtaPhi->Fill(etadiff,phidiff);
294  mEtadiff->Fill(etadiff);
295  mPhidiff->Fill(phidiff);
296  }
297  }
298  }
299 
300  if(EtaPhiArr_CPV[etabin][phibin]!=-999){
301  Int_t index=EtaPhiArr_CPV[etabin][phibin];
302  nncls->setCpvCluster((StPhmdCluster*)cpvclusters[index]);
303  if(spmcl1->McCluPID()==8){
304  hadmatched++;
305  spmcl1->setCluPID(8); //PID 8 set for photon
306  }
307  if(spmcl1->McCluPID()==1){
308  hadmatched++;
309  spmcl1->setCluPID(1); //PID 8 set for photon
310  }
311  cpvmatched++;
312  }
313 
314 
315  NNContainer.push_back(nncls);
316  }
317  }
318  if(cpvmatched>0)mcpvmatched->Fill(cpvmatched);
319 
320  }
321  }
322  return 0;
323 }
324 
326 {
327  if(mApplyFlagNN!=1 && mTrainFlag==1){
328  StPmdDiscriminatorNN *discNN = new StPmdDiscriminatorNN(NNContainer);
329  discNN->setApplyFlag(0);
330  discNN->setDisMaker(this);
331  if(discNN)
332  {
333  discNN->Discriminate();
334  }
335  }
336  return StMaker::Finish();
337 }
338 
339 
340 
341 void StPmdDiscriminatorMaker::fillStEvent(StPmdCollection* cluster_hit,StPhmdCollection* phmdcl)
342 {
343 
344  if(cluster_hit){
345  StPmdDetector * pmd_det = cluster_hit->detector(Int_t(0));
346  StPmdClusterCollection* clusters = (StPmdClusterCollection*)pmd_det->cluster();
347  if(phmdcl){
348 
349  StDetectorId pdet=static_cast<StDetectorId>(kPhmdId);
350  StPhmdDetector* detector=(StPhmdDetector*)phmdcl->detector(StDetectorId(pdet));
351  if(detector){
352  StPhmdClusterCollection* cluscoll = detector->cluster();
353  if(cluscoll){
354  const StSPtrVecPhmdCluster& pmdclusters= cluscoll->clusters();
355  Int_t nclust = clusters->Nclusters();
356  TIter next(clusters->Clusters());
357  StPmdCluster *spmcl1;
358  int nclust_phmd=pmdclusters.size();
359 
360  int loopcls=0;
361  if(nclust==nclust_phmd)loopcls=nclust;
362  if(nclust<nclust_phmd)loopcls=nclust;
363  if(nclust>nclust_phmd)loopcls=nclust_phmd;
364 
365  for(Int_t i=0; i<loopcls ; i++)
366  {
367  spmcl1 = (StPmdCluster*)next();
368  int edeppid=spmcl1->CluEdepPID();
369  StPhmdCluster *cl1=(StPhmdCluster*)pmdclusters[i];
370  if(!cl1)break;
371  if(cl1)cl1->setEnergyPid(edeppid);
372  }
373  }
374  }
375  }
376  }
377 }
378 
StPmdDetector * detector(Int_t)
destructor
Int_t Nclusters() const
destructor
TH2F * mEtaPhi
1-D delts phi distribution
TObjArray * Clusters()
no. of clusters
void bookHistograms()
Setting Traininbg or testing flag.
virtual void Browse(TBrowser *b)
Browse this dataset (called by TBrowser).
Definition: TDataSet.cxx:297
Float_t CluEdep() const
cluster phi
Definition: StPmdCluster.h:119
TH1F * mcpvmatched
2-D CpvClusters vs Matched Clusters
Float_t CluPhi() const
cluster eta
Definition: StPmdCluster.h:118
TH1F * mPhidiff
1-D delta eta distribution
TH1F * mClusterEdepPID
1-D plot for PID through Matching
void Browse(TBrowser *b)
Browse this dataset (called by TBrowser).
TH1F * mEtaPmd
1-D EDep Display for PMD
Definition: Stypes.h:40
Int_t McCluPID() const
cluster PID based on CPV/PMD matching
Definition: StPmdCluster.h:124
TH2F * mEdepVsPID
1-D plot for PID through E-cut
virtual Int_t Finish()
Definition: StMaker.cxx:776
Float_t CluEta() const
number of cells in the cluster as float
Definition: StPmdCluster.h:117
Definition: Stypes.h:44
TH1F * mClusterPID
DeltaEta-DeltaPhi Distribution.
TH1F * mMCPID
1-D delts phi distribution
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362