StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
runEEmcPreAnalysis.C
1 //
2 // Runs StMuEEmcPreAnalysis maker, performs a (trivial) clustering
3 // around the high-tower in each event, and generates some histograms
4 // of tower, preshower and postshower response, and SMD response...
5 //
6 // Binning on the histograms may not be optimal...
7 //
8 
9 
10 // forward declarations
11 class StChain;
12 class StIOMaker;
13 class StMuDstMaker;
14 class StMuEEmcPreAnalysisMaker;
15 class StMuDbReader;
16 class StEEmcDb;
17 class St_db_Maker;
18 
19 StChain *chain;
20 StIOMaker *ioMaker;
21 StMuDstMaker *muDstMaker;
22 StMuEEmcPreAnalysisMaker *muEEmcAnal;
23 StMuDbReader *muDb;
24 StEEmcDb *eemdDb;
25 St_db_Maker *starDb;
26 
27 #include <iomanip>
28 
29 void runEEmcPreAnalysis ( Int_t nevents = 100, // Number of events
30  Int_t smdhist = 10, // Prescale on SMD histograms
31  Char_t *muDst = "MuDst/mcPi0n_field_onpi0_10000_06TC05_5.MuDst.root",
32  Char_t *output = "output.root" // Output file
33  );
34 
36 
37 void runEEmcPreAnalysis ( Int_t nevents, Int_t smdhist, Char_t *muDst, Char_t *output ) {
38 
39 
40  if ( output != "" )
41  TFile *f = new TFile( output, "RECREATE" );
42 
44  //
45  // Preshower, postshower and tower 2D histos
46  //
47  TH2F *hPre1VsTow = new TH2F("hPre1VsTow", "Preshower(1) energy deposit vs reco tower E", 100, 0., 20., 100, 0., 0.2);
48  TH2F *hPre2VsTow = new TH2F("hPre2VsTow", "Preshower(2) energy deposit vs reco tower E", 100, 0., 20., 100, 0., 0.2);
49  TH2F *hPostVsTow = new TH2F("hPostVsTow", "Postshower energy deposit vs reco tower E", 100, 0., 20., 100, 0., 0.2);
50  TH2F *hPre1VsPre2 = new TH2F("hPre1VsPre2","Preshower(1) energy deposit vs preshower(2) energy deposit", 100, 0., 0.2, 100, 0., 0.2);
51 
52 
54  //
55  // Load shared libraries
56  //
57  gROOT -> LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
58  loadSharedLibraries();
59  gSystem->Load("StEEmcUtil.so");
60  gSystem->Load("StMuEEmcPreAnalysisMaker.so");
61  gSystem->Load("StDbLib");
62  gSystem->Load("StDbBroker");
63  gSystem->Load("St_db_Maker");
64  gSystem->Load("StEEmcDbMaker");
65 
67  //
68  // Create the chain and add the muDst maker
69  //
70  chain = new StChain("StChain");
71  muDstMaker = new StMuDstMaker(0,0,"",muDst,"MuDst.root",1);
72  muDb = StMuDbReader::instance();
73 
74  starDb = new St_db_Maker("StarDb", "MySQL:StarDb");
75  new StEEmcDbMaker("eemcDb");
76 
77  muEEmcAnal = new StMuEEmcPreAnalysisMaker();
78 
80  //
81  // Initialize the chain in preparation to loop over events
82  //
83  chain -> Init();
84  chain -> ls(3);
85  eemcDb = (StEEmcDb*)chain->GetDataSet("StEEmcDb");
86  assert(eemcDb);
87  // starDb -> setTimeStampDay(20030516);
88  eemcDb -> setTimeStampDay(20040101);
89  eemcDb -> setPreferedFlavor( "set492", "eemcPMTcal" );
90 
92  //
93  // Event Loop
94  //
95 
96  Int_t status = 0;
97  Int_t ievent = 0;
98  while ( !status && ievent < nevents ) {
99 
100  if ( !ievent % 100 ) std::cout << "Processing event number " << ievent << std::endl;
101 
102  // Clear all makers on the chain
103  chain -> Clear();
104 
105  // Call all of the makers on the chain
106  status = chain -> Make();
107 
108  // Get the high-tower from the EEMC analysis maker
109  StMuEEmcTower *seed = muEEmcAnal -> getHighTower();
110  // StMuEEmcTower *neighbors[] = seed -> getNeighbors();
111 
112  // We take the 8 surrounding towers, plus the central
113  // "seed" tower, to be the cluster. The following
114  // loop determines the total energy of the cluster,
115  // total energy deposited in pre and postshower
116  // layers, and determines the first and last U and
117  // V smd strips within the "fiducial volume" of the
118  // cluster.
119 
120  Float_t energy = seed -> getEnergy(0);
121  Float_t energy_pre1 = seed -> getEnergy(1);
122  Float_t energy_pre2 = seed -> getEnergy(2);
123  Float_t energy_post = seed -> getEnergy(3);
124 
125  StMuEEmcStrip *ufirst = seed -> getFirstStrip('U');
126  StMuEEmcStrip *vfirst = seed -> getFirstStrip('V');
127  StMuEEmcStrip *ulast = seed -> getLastStrip('U');
128  StMuEEmcStrip *vlast = seed -> getLastStrip('V');
129 
130  std::cout << ievent << " seed: "
131  << std::setw(7) << std::setprecision(3) << energy << " "
132  << std::setw(7) << std::setprecision(3) << energy_pre1 << " "
133  << std::setw(7) << std::setprecision(3) << energy_pre2 << " "
134  << std::setw(7) << std::setprecision(3) << energy_post << " "
135  << std::setw(3) << ufirst -> getId() << " "
136  << std::setw(3) << ulast -> getId() << " "
137  << std::setw(3) << vfirst -> getId() << " "
138  << std::setw(3) << vlast -> getId() << " "
139  << std::endl;
140 
141  StMuEEmcTower *neighbor;
142 
143  for ( Int_t i = 0; i < 8; i++ ) {
144 
145  // Get a pointer to the neighboring tower, and
146  // punt if its NULL
147  neighbor = seed -> getNeighbor(i);
148  if ( !neighbor ) continue;
149 
150  energy += neighbor -> getEnergy(0);
151  energy_pre1 += neighbor -> getEnergy(1);
152  energy_pre2 += neighbor -> getEnergy(2);
153  energy_post += neighbor -> getEnergy(3);
154 
155  StMuEEmcStrip *mytmp = neighbor -> getFirstStrip('U');
156  if ( mytmp -> getId() < ufirst -> getId() ) ufirst = mytmp;
157  mytmp = neighbor -> getFirstStrip('V');
158  if ( mytmp -> getId() < vfirst -> getId() ) vfirst = mytmp;
159  mytmp = neighbor -> getLastStrip('U');
160  if ( mytmp -> getId() > ulast -> getId() ) ulast = mytmp;
161  mytmp = neighbor -> getLastStrip('V');
162  if ( mytmp -> getId() > vlast -> getId() ) vlast = mytmp;
163 
164  }
165 
166  // Fill preshower/postshower histos
167  hPre1VsTow -> Fill( energy, energy_pre1 );
168  hPre2VsTow -> Fill( energy, energy_pre2 );
169  hPostVsTow -> Fill( energy, energy_post );
170  hPre1VsPre2-> Fill( energy_pre2, energy_pre1 );
171 
173  //
174  // How often do we create a histogram for
175  // the SMD strips?
176  //
177  if ( !(ievent % smdhist) ) {
178 
179  f->cd();
180 
181  // Book and fill a histogram for SMD's (on event-by-event basis)
182  TString myname = "uEvent"; myname += ievent;
183  TString mytitle = "U SMD strip energy distribution";
184  Int_t min = ufirst -> getId() - 1;
185  Int_t max = ulast -> getId() + 1;
186  Int_t nbin = ( max - min + 1 );
187  TH1F *uhist = new TH1F(myname,mytitle,nbin,min,max);
188 
189  StMuEEmcStrip *strip;
190  for ( strip = ufirst; strip <= ulast; strip++ ) {
191  //$$$uhist -> Fill( (Float_t)strip->getId(), strip -> getEnergy() );
192 
193  Int_t id = strip -> getId() - min;
194  Float_t myenergy = strip -> getEnergy();
195  Float_t nphoto = (myenergy>0.) ? strip -> getNumPhotoElectrons() : 1;
196 
197  uhist -> SetBinContent( id, myenergy );
198  uhist -> SetBinError ( id, myenergy / sqrt(nphoto) );
199 
200  }
201 
202  myname = "vEvent"; myname += ievent;
203  mytitle = "V SMD strip energy distribution";
204  min = vfirst -> getId() - 1;
205  max = vlast -> getId() + 1;
206  nbin = ( max - min + 1 );
207  TH1F *vhist = new TH1F(myname,mytitle,nbin,min,max);
208 
209  for ( strip = vfirst; strip <= vlast; strip++ ) {
210  //$$$vhist -> Fill( (Float_t)strip->getId(), strip -> getEnergy() );
211 
212  Int_t id = strip -> getId() - min;
213  Float_t myenergy = strip -> getEnergy();
214  Float_t nphoto = (myenergy>0.) ? strip -> getNumPhotoElectrons() : 1;
215 
216  vhist -> SetBinContent( id, myenergy );
217  vhist -> SetBinError ( id, myenergy / sqrt(nphoto) );
218 
219  }
220 
221  }
223 
224 
225 
226  // Let the user know we're still alive
227  std::cout << ievent << " cluster: "
228  << std::setw(7) << std::setprecision(3) << energy << " "
229  << std::setw(7) << std::setprecision(3) << energy_pre1 << " "
230  << std::setw(7) << std::setprecision(3) << energy_pre2 << " "
231  << std::setw(7) << std::setprecision(3) << energy_post << " "
232  << std::setw(3) << ufirst -> getId() << " "
233  << std::setw(3) << ulast -> getId() << " "
234  << std::setw(3) << vfirst -> getId() << " "
235  << std::setw(3) << vlast -> getId() << " "
236  << std::endl
237  << std::endl;
238 
239  // Increment the event counter
240  ievent++;
241 
242  }
243 
244  f -> Write();
245 
246 }
virtual void Clear(Option_t *opt="")
User defined functions.
virtual Int_t Make()
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495