FairRoot/PandaRoot
plot_hitpattern.C
Go to the documentation of this file.
1 
10 
12 //void plot_hitpattern(TString theRunName = "test", Int_t theWhat = 1, Int_t fEventMin = 0, Int_t fEventMax = -2)
14 {
15 
16  TString theRunName = "test";
17  Int_t theWhat = 3;
18  Int_t fEventMin = 0;
19  Int_t fEventMax = -1;
20  Bool_t fSecondaries = kTRUE;
21 
22  gROOT->LoadMacro("$VMCWORKDIR/gconfig/rootlogon.C");
23  gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
24  rootlogon();
25  basiclibs();
26  gSystem->Load("libDsk");
27 
28  TString fTitle = "Hit Pattern: Pion 4GeV 15deg - hits: ";
29 
30 
31 // TString fFileName = TString(fPath).Append("sim_dsk.").Append(fRunName).Append(".root");
32  TString fFileName = TString("sim_dsk.").Append(theRunName).Append(".root");
33  TFile *fFile = 0;
34  fFile = gROOT->GetFile(fFileName);
35  if (fFile == 0)
36  fFile = new TFile(fFileName);
37 
38  TTree *fTree = (TTree *)fFile->Get("pndsim");
39  fTree->SetBranchStatus("*",0);
40  fTree->SetBranchStatus("DskCerenkov.*",1);
41  fTree->SetBranchStatus("DskParticle.*",1);
42 
43  Int_t fNofEvents = fTree->GetEntries();
44 
45  TClonesArray *cArray = 0;
46  cArray = new TClonesArray("PndDskCerenkov");
47  fTree->SetBranchAddress("DskCerenkov",&cArray);
48  PndDskCerenkov *fCerenkov = 0;
49 
50  TClonesArray *pArray = 0;
51  pArray = new TClonesArray("PndDskParticle");
52  fTree->SetBranchAddress("DskParticle",&pArray);
54 
55 
56  if (fEventMax == -2) fEventMax = fEventMin;
57  if (fEventMax == -1) fEventMax = fNofEvents-1;
58 
59 // const Int_t fArraySize = 600 * ( fEeventMax - fEeventMin +1);
60 
61  const Int_t fArraySize = 1000*600;
62  Double_t priDetNum[fArraySize];
63  Double_t priTof[fArraySize];
64  Double_t secDetNum[fArraySize];
65  Double_t secTof[fArraySize];
66 
67  Int_t pris = 0;
68  Int_t secs = 0;
69 
70  printf("Will process events %i to %i\n",fEventMin,fEventMax);
71 
72  // select event
73  for (Int_t j=fEventMin; j<=fEventMax; j++) {
74 
75  fTree->GetEntry(j);
76  printf("Processing event %i\n",j);
77 
78 
79  // first, find primary particle
80  Bool_t searching = kTRUE;
81  TIter pIter(pArray);
82  PndDskParticle* pEntry;
83  while ( searching && (pEntry = (PndDskParticle *)pIter.Next()) ) {
84  if (pEntry->GetTrackID() == 0 )
85  searching = false;
86  }
87 
88  // now the Cerenkovs
89  PndDskCerenkov* cEntry = 0;
90  TIter cIter(cArray);
91  while ( (cEntry = (PndDskCerenkov*)cIter.Next()) ) {
92 
93  if ( cEntry->GetDetTime() > 0. ) { // is detected
94 
95  if ( cEntry->GetMotherTrackID() == 0 && theWhat != 2) { // is primary
96  priDetNum[pris] = cEntry->GetDetNumber()+1;
97  priTof[pris] = cEntry->GetDetTime() - pEntry->GetTime();
98  pris++;
99  cout << "added primary "
100  << cEntry->GetTrackID()
101  << " with " << cEntry->GetWavelength()
102  << " in " << cEntry->GetDetNumber() << endl;
103  } else if (theWhat > 1) { // is from secondary
104  secDetNum[secs] = cEntry->GetDetNumber()+1;
105  secTof[secs] = cEntry->GetDetTime() - pEntry->GetTime();
106  secs++;
107  cout << "added secondary (" << cEntry->GetMotherPdgCode() << ") "
108  << cEntry->GetTrackID()
109  << " with " << cEntry->GetWavelength()
110  << " in " << cEntry->GetDetNumber() << endl;
111  }
112  }
113  }
114  }
115 
116 // delete cArray;
117 // delete pArray;
118 
119 
120  TMultiGraph *mg = new TMultiGraph();
121  char priStr[3]; sprintf(priStr,"%i",pris);
122  char secStr[3]; sprintf(secStr,"%i",secs);
123  mg->SetTitle(TString(fTitle).Append(priStr).Append(". From Secondaries: ").Append(secStr));
124 
125  // now plot, the real hits
126  TGraph* grPris = new TGraph(pris, priDetNum, priTof);
127  grPris->SetMarkerColor(2);
128  grPris->SetFillStyle(0);
129  mg->Add(grPris);
130 
131  // hits from secondary particle cerenkovs
132  if (fSecondaries && secs>0) {
133  TGraph* grSecs = new TGraph(secs, secDetNum, secTof);
134  grSecs->SetMarkerColor(4);
135  grSecs->SetFillStyle(0);
136  mg->Add(grSecs);
137  }
138 
139  mg->Draw("A*");
140 
141  mg->GetXaxis()->SetTitle("detector number");
142  mg->GetYaxis()->SetTitle("time of flight [ns]");
143 
144 // c1->Update();
145 
146  cout << "This is Event No. " << fEventMin << ". Detected Cerenkovs: " << pris << " from primary, " << secs << " from secondaries." << endl;
147  return 0;
148 }
149 
150 
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
basiclibs()
TMultiGraph * mg
Definition: NHitsPerEvent.C:17
Int_t GetMotherPdgCode() const
Int_t GetDetNumber() const
Int_t * fParticle
Definition: run_full.C:24
Double_t
Double_t GetDetTime() const
Int_t GetMotherTrackID() const
int plot_hitpattern()
theWhat: 1 = primary, 2 = secondary, 3 = both
Double_t GetWavelength() const