StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
runEEmcClusterMaker.C
1 //--
2 //-- runEEmcClusterMaker.C
3 //--
4 
5 //-- switch should be commented out when analysing real data
6 #define MONTE_CARLO
7 
8 class StChain;
9 class St_db_Maker;
10 class StEEmcD;
11 class StMuDstMaker;
12 class StEEmcA2EMaker;
16 class StEEmcMixMaker;
17 class StEEmcMixQAMaker;
18 class StSpinDbMaker;
19 class StEEmcPi0Maker;
20 
21 //--
22 //-- globals
23 //--
24 StChain *mChain = 0;
25 St_db_Maker *mStarDatabase = 0;
26 StEEmcDb *mEEmcDatabase = 0;
27 StMuDstMaker *mMuDstMaker = 0;
29 
31 
32 Int_t count = 0;
33 Int_t stat = 0;
34 
35 Int_t prescale = 1;
36 
37 #include <vector>
38 
39 void runEEmcClusterMaker( Int_t nevents = -1,
40  // Char_t *name = "6149020.lis",
41  // Char_t *ofile= "6149020.root",
42  Char_t *name="test.MuDst.root",
43  Char_t *ofile="mc.root",
44  Char_t *path = "./",
45  Int_t trigID=96261,
46  Int_t nfiles = 100
47  )
48 {
49 
50 
51  TString pathname = path;
52  pathname += name;
53 
54  //--
55  //-- Load shared libraries
56  //--
57  LoadLibs();
58 
59  //--
60  //-- Create the analysis chain
61  //--
62  mChain = new StChain("eemcAnalysisChain");
63 
64  //--
65  //-- MuDst maker for reading input
66  //--
67  mMuDstMaker = new StMuDstMaker(0,0,path,name,"MuDst",nfiles);
68  mMuDstMaker->SetStatus("*",0);
69  mMuDstMaker->SetStatus("MuEvent",1);
70  mMuDstMaker->SetStatus("EmcAll",1);
71 
72  //--
73  //-- Connect to the STAR databse
74  //--
75  mStarDatabase = new St_db_Maker("StarDb", "MySQL:StarDb");
76 
77 
78 
79 #ifdef MONTE_CARLO
80  //--
81  //-- Setup ideal gains for processing MC data
82  //--
83  mStarDatabase->SetFlavor("sim","eemcPMTcal");
84  mStarDatabase->SetFlavor("sim","eemcPIXcal");
85  mStarDatabase->SetFlavor("sim","eemcPMTped");
86  mStarDatabase->SetFlavor("sim","eemcPMTstat");
87  mStarDatabase->SetFlavor("sim","eemcPMTname");
88  mStarDatabase->SetFlavor("sim","eemcADCconf");
89  mStarDatabase->SetDateTime(20050101,0);
90 #endif
91 
92 
93  //--
94  //-- Initialize EEMC database
95  //--
96  mEEmcDatabase = new StEEmcDbMaker("eemcDb");
97  //mEEmcDatabase -> setSectors(1,7);
98 
99  gMessMgr -> SwitchOff("D");
100  gMessMgr -> SwitchOn("I");
101 
102 
103 
104  //--
105  //-- Initialize SPIN database
106  //--
107  mSpinDb = new StSpinDbMaker("mSpinDb");
108 
109 
110 
111 #ifdef MONTE_CARLO
112  //--
113  //-- Initialize slow simulator
114  //--
115  StEEmcSlowMaker *slowSim = new StEEmcSlowMaker("slowSim");
116  slowSim->setDropBad(0); // 0=no action, 1=drop chn marked bad in db
117  slowSim->setAddPed(0); // 0=no action, 1=ped offset from db
118  slowSim->setSmearPed(0); // 0=no action, 1=gaussian ped, width from db
119  slowSim->setOverwrite(1); // 0=no action, 1=overwrite muDst values
120 #endif
121 
122 
123  //--
124  //-- Energy to ADC maker
125  //--
126  mEEanalysis=new StEEmcA2EMaker("AandE");
127  mEEanalysis->database("eemcDb"); // sets db connection
128  mEEanalysis->source("MuDst",1); // sets mudst as input
129  mEEanalysis->threshold(3.0,0); // tower threshold (n sigma above pedestal)
130  mEEanalysis->threshold(3.0,1); // pre1 threshold
131  mEEanalysis->threshold(3.0,2); // pre2 threshold
132  mEEanalysis->threshold(3.0,3); // post threshold
133  mEEanalysis->threshold(3.0,4); // smdu threshold
134  mEEanalysis->threshold(3.0,5); // smdv threshold
135 #ifdef MONTE_CARLO
136  mEEanalysis->scale(1.2); // scale energies by x1.2
137 #endif
138 
139 
140  //--
141  //-- Cluster maker.
142  //--
143  mEEclusters=new StMyClusterMaker("mEEclusters", mEEanalysis, mMuDstMaker );
144 
145  /* SMD parameters */
146 
147  // Sets the SMD seed threshold
148  ((StMyClusterMaker*)mEEclusters)->setSmdSeedEnergy( 5.0/1000.0 );
149  // Sets the minimum energy an SMD strip needs to be added to a cluster
150  ((StMyClusterMaker*)mEEclusters)->setSmdMinimumEnergy(0.5/1000.0 );
151  // Sets the maximum number of strips on either side of the seed strip
152  ((StMyClusterMaker*)mEEclusters)->setSmdMaximumSize(3);
153  // Requires the cluster energy to grow by at least this factor when the
154  // next two strips are added, otherwise the cluster is terminated
155  ((StMyClusterMaker*)mEEclusters)->setSmdTruncationRatio(1.20);
156  // Sets the minimum number of strips the cluster must contain
157  ((StMyClusterMaker*)mEEclusters)->setSmdMinimumStrips(3);
158 
159  /* Tower parameters */
160 
161  // Sets tower seed threshold
162  ((StMyClusterMaker*)mEEclusters)->setSeedEnergy(0.8);
163  // Sets the minimum energy on a tower to be added to a cluster
164  ((StMyClusterMaker*)mEEclusters)->setMinimumEnergy(0.5);
165 
166 
167  mChain->ls(3);
168  mChain->Init();
169 
170  //-----------------------------------------------------------------
171  //--
172  //-- This is where the business happens. We loop over all events.
173  //-- when mChain -> Make() is called, ::Make() will be called on
174  //-- all of the makers created above.
175  //--
176  //
177 
178 
179 
180 
181  Int_t stat = 0; // error flag
182  Int_t count = 0; // event count
183  while ( stat == 0 ) {
184 
185 
186  printf("event=%d\n",count);
187 
188  //--
189  //-- Terminate once we reach nevents --
190  //--
191  if ( count++ >= nevents ) if ( nevents > 0 ) break;
192 
193  //--
194  //-- Call clear on all makers
195  //--
196  mChain -> Clear();
197 
198 
199  //--
200  //-- Process the event through all makers
201  //--
202  stat = mChain -> Make();
203 
204  //--
205  //-- Set to printout on every 10th event
206  //--
207  // if ( (count%prescale) ) continue;
208 
209  std::cout << "------------------------------------------------";
210  std::cout << "event=" << count << std::endl;
211 
212  //--
213  //-- Print the number of hits in the towers, pre/postshower layers
214  //--
215  Int_t nhits[]={0,0,0,0,0,0};
216  for ( int i = 0; i < 4; i++ ) {
217  // std::cout << " layer=" << i
218  // << " nhits=" << mEEanalysis->numberOfHitTowers(i) << std::endl;
219  nhits[i]+=mEEanalysis->numberOfHitTowers(i);
220  }
221 
222  //--
223  //-- Print the total number of smd strips which fired
224  //--
225  Int_t nu=0,nv=0;
226  for ( Int_t sec=0;sec<12;sec++ )
227  {
228  nu+=mEEanalysis->numberOfHitStrips(sec,0);
229  nv+=mEEanalysis->numberOfHitStrips(sec,1);
230  }
231  nhits[4]=nu;
232  nhits[5]=nv;
233 
234 
235  //--
236  //-- Print number of clusters in each layer
237  //--
238  Int_t ncl[6]={0,0,0,0,0,0};
239  ncl[0]+=mEEclusters->numberOfClusters(0);
240  ncl[1]+=mEEclusters->numberOfClusters(1);
241  ncl[2]+=mEEclusters->numberOfClusters(2);
242  ncl[3]+=mEEclusters->numberOfClusters(3);
243  ncl[4]+=mEEclusters->numberOfClusters(4);
244  ncl[5]+=mEEclusters->numberOfClusters(5);
245 
246  const Char_t *lay[]={"tower:","pre1: ", "pre2: ", "post: ", "smdu: ", "smdv: "};
247  for ( Int_t i=0;i<6;i++ )
248  {
249  //std::cout << lay[i] << " " << nhits[i] << " " << ncl[i] << std::endl;
250  printf("%s nhits=%2i nclusters=%2i\n",lay[i],nhits[i],ncl[i]);
251  }
252 
253 
254  //--
255  //-- Example code to find the highest-energy tower cluster in
256  //-- the endcap.
257  //--
258  StEEmcCluster gamma_candidate;
259  for ( Int_t sector = 0; sector < 12; sector++ )
260  {
261 
262  Int_t nclusters = mEEclusters->numberOfClusters( sector, 0 );
263  for ( Int_t ic=0;ic<nclusters;ic++ )
264  {
265  StEEmcCluster cluster = mEEclusters->cluster(sector,0,ic);
266  Float_t pt = cluster.momentum().Perp();
267  Float_t old = gamma_candidate.momentum().Perp();
268  if ( pt > old )
269  {
270  gamma_candidate = cluster;
271  }
272  }
273  }
274 
275  // verify cluster is valid
276  if ( gamma_candidate.key() >= 0 )
277  gamma_candidate.print();
278  else {
279  std::cout << "no gamma candidate found" << std::endl;
280  continue;
281  }
282 
283  Int_t nu = mEEclusters->numberOfMatchingSmdClusters( gamma_candidate, 0 );
284  Int_t nv = mEEclusters->numberOfMatchingSmdClusters( gamma_candidate, 1 );
285 
286  std::cout << "Number of matching u=" << nu << " v=" << nv << std::endl;
287  for ( Int_t iu=0;iu<nu;iu++ )
288  {
289  StEEmcSmdCluster smdu=mEEclusters->matchingSmdCluster( gamma_candidate, 0, iu );
290  smdu.printLine();
291  }
292  for ( Int_t iv=0;iv<nv;iv++ )
293  {
294  StEEmcSmdCluster smdv=mEEclusters->matchingSmdCluster( gamma_candidate, 1, iv );
295  smdv.printLine();
296  }
297 
298 
299 
300 
301 
302  }
303  //--
304  //-----------------------------------------------------------------
305 
306 
307  //--
308  //-- For debugging purposes, it's often useful to print out the
309  //-- database
310  //--
311  mEEmcDatabase = (StEEmcDb*)mChain->GetDataSet("StEEmcDb");
312  if (mEEmcDatabase) mEEmcDatabase->exportAscii("dbdump.dat");
313 
314  //--
315  //-- Calls the ::Finish() method on all makers
316  //--
317  mChain -> Finish();
318 
319  return;
320 
321 }
322 
323 void LoadLibs()
324 {
325  //-- Load muDst shared libraries --
326  gROOT -> LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
327  loadSharedLibraries();
328 
329  gSystem->Load("StDbLib");
330  gSystem->Load("StDbBroker");
331  gSystem->Load("St_db_Maker");
332  gSystem->Load("StEEmcUtil");
333  gSystem->Load("StEEmcDbMaker");
334  gSystem->Load("StEEmcSimulatorMaker");
335 
336  gSystem->Load("StEEmcA2EMaker");
337  gSystem->Load("StEEmcClusterMaker");
338 
339 
340 }
341 
TVector3 momentum() const
Definition: StEEmcCluster.h:69
void Clear(Option_t *opts="")
User defined functions.
EEmc ADC –&gt; energy maker.
void scale(Float_t s)
StEEmcGenericClusterMaker * mEEclusters
void source(const Char_t *, Int_t=0)
void setAddPed(Bool_t a=true)
Add pedestal offsets from DB.
StEEmcA2EMaker * mEEanalysis
Int_t numberOfMatchingSmdClusters(const StEEmcCluster &cluster, Int_t plane) const
A maker for creating pi0 histograms.
Int_t numberOfHitStrips(Int_t sector, Int_t plane) const
void print() const
Prints cluster data.
Int_t numberOfHitTowers(Int_t layer) const
Int_t numberOfClusters(Int_t sector, Int_t layer) const
void threshold(Float_t cut, Int_t layer)
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
StEEmcSmdCluster & matchingSmdCluster(const StEEmcCluster &cluster, Int_t plane, Int_t index)
void setOverwrite(Bool_t o=true)
Overwrite the muDst values.
void setDropBad(Bool_t d=true)
Drop bad channels marked as &quot;fail&quot; in DB.
A base class for representing clusters of EEMC smd strips.
A class for finding EEMC points.
void SetStatus(const char *arrType, int status)
void setSmearPed(Bool_t s=true)
Smear the pedestal with sigma from DB.
A base class for describing clusters of EEMC towers.
Definition: StEEmcCluster.h:50
virtual Int_t Finish()
Definition: StMaker.cxx:776
A class for mixing pi0 candidates.
Slow simulator for EEMC.
void database(const Char_t *)
Set the name of the EEMC database, init obtains pointer.
StEEmcCluster & cluster(Int_t sector, Int_t layer, Int_t index)