StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makeEEmcTreePart1.C
1 /*
2  * Created May 2012, by S. Gliske
3  *
4  * Macro to write "Part 1" of the EEmcTree, by reading in a MuDst
5  * and applying the calibration.
6  *
7  * Note: much of this script is based on Alice's runABClusterMaker.C
8  * and Weihong's runEEmcPi0.C
9  *
10  */
11 
12 // forward declarations
13 class StChain;
14 class St_db_Maker;
15 class StEEmcDbMaker;
16 class StMuDstMaker;
17 class StEEmcA2EMaker;
18 class StSpinDbMaker;
19 class StEEmcSlowMaker;
20 
21 class StSpinInfoMaker_t;
23 class StEEmcTreeMaker_t;
25 class StTrigCounter;
26 
27 //
28 // some variables that others tend to make global
29 //
30 StChain *analysisChain = 0;
31 StMuDstMaker *muDstMaker = 0;
32 St_db_Maker *starDatabase = 0;
33 StEEmcDbMaker *eemcDbMaker = 0;
34 StSpinDbMaker *spinDb = 0;
35 StEEmcA2EMaker *a2EMakerPtr = 0;
36 StEEmcEnergyMaker_t *energyMakerPtr = 0;
37 StEEmcTreeMaker_t *treeMakerPtr = 0;
38 StMcEEmcTreeMaker_t *mcTreeMakerPtr = 0;
39 StSpinInfoMaker_t *spinInfoMakerPtr = 0;
40 
41 //
42 // the main routine
43 //
44 void makeEEmcTreePart1( Long_t neventsIn = -1,
45  Long_t neventsOut = -1,
46  const Char_t *inputFileName = "",
47  const Char_t *outputFileName = "McEEmcTree.root",
48  Int_t displayFreq = 1000,
49  Char_t trigVer = 'f',
50  Char_t* eemcSetupPath = "/star/u/sgliske/Share/StarTrigSimuSetup/", // make sure this path ends with a '/' and has a subdirectory for the year of interest
51  Bool_t isMC = 0,
52  Bool_t noMCdateTime = 0,
53  Bool_t skipMcTreeMaker = 0 ){
54 
55  std::cout << "***** Loading libraries *****" << endl;
56 
57  gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
58  loadSharedLibraries();
59  assert( !gSystem->Load("StDetectorDbMaker"));
60  assert( !gSystem->Load("StTpcDb"));
61  assert( !gSystem->Load("StDbUtilities"));
62  assert( !gSystem->Load("StDbBroker"));
63  assert( !gSystem->Load("St_db_Maker"));
64  assert( !gSystem->Load("StEEmcUtil")); // needed by eemcDb
65  assert( !gSystem->Load("StEEmcDbMaker"));
66  assert( !gSystem->Load("StEEmcA2EMaker"));
67  assert( !gSystem->Load("StDaqLib")); // needed by bemcDb
68  assert( !gSystem->Load("StEmcRawMaker"));
69  assert( !gSystem->Load("StEmcADCtoEMaker"));
70  if (isMC) {
71  assert( !gSystem->Load("StMcEvent"));
72  assert( !gSystem->Load("StMcEventMaker"));
73  assert( !gSystem->Load("StEmcSimulatorMaker"));
74  assert( !gSystem->Load("StEEmcSimulatorMaker"));
75  assert( !gSystem->Load("StEpcMaker"));
76  }
77  assert( !gSystem->Load("StSpinDbMaker") );
78  assert( !gSystem->Load("StTriggerUtilities"));
79  assert( !gSystem->Load("StEEmcPoolEEmcTreeContainers") );
80  assert( !gSystem->Load("StEEmcTreeMaker") );
81 
82  //gDebug=5;
83 
84  std::cout << "***** Done loading libraries *****" << endl;
85  std::cout << "***** Instanciating all the classes *****" << endl;
86 
87  //
88  // Create the analysis chain
89  //
90  analysisChain = new StChain("eemcAnalysisChain");
91 
92  //
93  // IO Maker to read the geant file
94  //
95  if( isMC ){
96  ioMaker = new StIOMaker();
97 
98  TString geantFileName = inputFileName;
99  geantFileName.ReplaceAll("MuDst","geant");
100  ioMaker->SetFile(geantFileName);
101 
102  ioMaker->SetIOMode("r");
103  ioMaker->SetBranch("*",0,"1"); //deactivate all branches
104  ioMaker->SetBranch("geantBranch",0,"r"); //activate geant Branch
105  ioMaker->SetBranch("minimcBranch",0,"r"); //activate geant Branch
106  };
107 
108  //
109  // MuDst maker for reading input
110  //
111  Int_t nfiles = 10000;
112  muDstMaker = new StMuDstMaker( 0, 0, "", inputFileName, "MuDst", nfiles );
113  muDstMaker->SetStatus("*",0);
114  muDstMaker->SetStatus("*Event*",1);
115  muDstMaker->SetStatus("PrimaryVertices",1);
116  muDstMaker->SetStatus("EmcAll",1);
117 
118  // just to make sure StEvent is found for the trig simu
119  StMuDst2StEventMaker *muDst2StEvent = new StMuDst2StEventMaker();
120 
121  //
122  // Maker for StMcEvent
123  //
124  if( isMC ){
125  StMcEventMaker *mcEventMaker = new StMcEventMaker();
126  mcEventMaker->doPrintEventInfo = false;
127  mcEventMaker->doPrintMemoryInfo = false;
128  };
129 
130 
131  //
132  // Connect to the STAR databse
133  //
134  starDatabase = new St_db_Maker("StarDb","MySQL:StarDb","MySQL:StarDb","$STAR/StarDb");
135  starDatabase->SetAttr("blacklist", "fgt");
136  starDatabase->SetAttr("blacklist", "svt");
137  starDatabase->SetAttr("blacklist", "tpc");
138  starDatabase->SetAttr("blacklist", "ftpc");
139 
140  if( isMC && noMCdateTime )
141  starDatabase->SetDateTime(20060512,43500);
142 
143  //
144  // Initialize EEMC database
145  //
146  eemcDbMaker = new StEEmcDbMaker("eemcDb");
147 
148  // this is the interface to the STAR logger
149  // SwitchOn("D") turns on debugging
150  // SwitchOff("D") turns off debuggin
151  // "I" is info and "W" is warn
152  gMessMgr->SwitchOff("D");
153  gMessMgr->SwitchOff("I");
154  //gMessMgr->SetLevel(2);
155 
156  // note: moving the slow simu to here doesn't seem to make any difference
157 
158  //
159  // Trigger counter
160  //
161  StTrigCounter* trigCounter = new StTrigCounter( "trigCounter", 117001 );
162 
163  //
164  // Energy to ADC maker
165  //
166  a2EMakerPtr = new StEEmcA2EMaker("EEmcA2EMaker");
167  a2EMakerPtr->database("eemcDb"); // sets db connection
168  a2EMakerPtr->source("MuDst",1); // sets mudst as input
169  a2EMakerPtr->threshold(3.0,0); // tower threshold
170  a2EMakerPtr->threshold(3.0,1); // pre1 threshold
171  a2EMakerPtr->threshold(3.0,2); // pre2 threshold
172  a2EMakerPtr->threshold(3.0,3); // post threshold
173  a2EMakerPtr->threshold(3.0,4); // smdu threshold
174  a2EMakerPtr->threshold(3.0,5); // smdv threshold
175 
176  //
177  // Now start things particular to the StEEmcTreeMaker
178  //
179 
180 
181  //
182  // create spin DB maker and info maker
183  //
184  if( !isMC ){
185  spinDb = new StSpinDbMaker("spinDb");
186  spinInfoMakerPtr = new StSpinInfoMaker_t( "SpinInfoMaker" );
187  };
188 
189  // Energy Structure Maker
190  energyMakerPtr = new StEEmcEnergyMaker_t( "energyMkr", "EEmcA2EMaker" );
191  energyMakerPtr->setStripThres( isMC ? 0.0 : 0.001 );
192  energyMakerPtr->setTowerThres( isMC ? 0.0 : 1.0 );
193 
194  // I'm told one must use slow simulator to get pedestals correct for L2,
195  // but I'll put it after the A2Emaker and Energy maker, so it doesn't mess them up
196 
197  // Note: this will actually add the pedestal to the adc value, so
198  // it seems this is the wrong thing to do if one already has the
199  // pedestals in the adc's in the MuDst.
200  if( 0 && isMC==1 ){
201  StEEmcSlowMaker *slowSim = new StEEmcSlowMaker("slowSim");
202 
203  // note: changing the sampling fraction does not effect the
204  // L0 trigger decision. Also, it is probably better to use the value
205  // in the slow simulator, so that it matches data. (S. Gliske,
206  // Sept 2012)
207 
208  // This 1.3 comes from the iron/air MC, where the sampling
209  // fraction was believed to be near 4%, but slow/fast simulator
210  // used 5%.
211 
212  // Now that the slow/fast simulator uses 0.048, it is a 1.25 scaling factor
213 
214  // slowSim->setSamplingFraction(0.0384); // effectively scale all Tower energies with a factor of 1.3 (added by: Ilya Selyuzhenkov; April 11, 2008)
215 
216  slowSim->setAddPed(true);
217  slowSim->setSmearPed(true);
218  };
219 
220  //
221  // Trigger emulator
222  //
223  StTriggerSimuMaker *simuTrig = new StTriggerSimuMaker("StarTrigSimu");
224  simuTrig->setMC(isMC); // must be before individual detectors, to be passed
225  simuTrig->useBbc();
226  simuTrig->useEemc(0); //default=0:just process ADC, 1,2:comp w/trgData,see .
227  simuTrig->eemc->setSetupPath(eemcSetupPath);
228 
229  // Collect all output histograms
230  TObjArray* HList=new TObjArray;
231  simuTrig->setHList(HList);
232 
233  // DSM settings
234  int eemcDsmSetup[20]; // see StEemcTriggerSimu::initRun() for definition
235  memset(eemcDsmSetup, 0,sizeof(eemcDsmSetup));// clear all, may be a bad default
236 
237  if( trigVer == 'd' ){
238  // valid runs 7130037-7132029
239  eemcDsmSetup[0]=6; // HTthr0
240  eemcDsmSetup[1]=12; // HTthr1
241  eemcDsmSetup[2]=22; // HTthr2
242  eemcDsmSetup[3]=1; // TPthr0
243  eemcDsmSetup[4]=20; // TPthr1
244  eemcDsmSetup[5]=31; // TPthr2
245  } else if ( trigVer == 'e' ){
246  // valid runs 7132045-7133051
247  eemcDsmSetup[0]=6; // HTthr0
248  eemcDsmSetup[1]=17; // HTthr1
249  eemcDsmSetup[2]=22; // HTthr2
250  eemcDsmSetup[3]=1; // TPthr0
251  eemcDsmSetup[4]=20; // TPthr1
252  eemcDsmSetup[5]=31; // TPthr2
253  } else if ( trigVer == 'f' ){
254  // valid runs 7133052-7156040
255  eemcDsmSetup[0]=6; // HTthr0
256  eemcDsmSetup[1]=16; // HTthr1
257  eemcDsmSetup[2]=22; // HTthr2
258  eemcDsmSetup[3]=1; // TPthr0
259  eemcDsmSetup[4]=20; // TPthr1
260  eemcDsmSetup[5]=31; // TPthr2
261  } else if ( trigVer == 'g' ){
262  // test trigger, ht1 & tp2 are 1 DSM (roughly 5%) higher than 'e'
263  eemcDsmSetup[0]=6; // HTthr0
264  eemcDsmSetup[1]=18; // HTthr1
265  eemcDsmSetup[2]=22; // HTthr2
266  eemcDsmSetup[3]=1; // TPthr0
267  eemcDsmSetup[4]=21; // TPthr1
268  eemcDsmSetup[5]=31; // TPthr2
269  } else if ( trigVer == 'h' ){
270  // test trigger, ht1 & tp2 are 2 DSM (roughly 10%) higher than 'e'
271  eemcDsmSetup[0]=6; // HTthr0
272  eemcDsmSetup[1]=19; // HTthr1
273  eemcDsmSetup[2]=22; // HTthr2
274  eemcDsmSetup[3]=1; // TPthr0
275  eemcDsmSetup[4]=22; // TPthr1
276  eemcDsmSetup[5]=31; // TPthr2
277  } else {
278  cerr << "Invalid trigger version" << endl;
279  return;
280  };
281  eemcDsmSetup[10]=2; //HTTPthrSelc, 2=use_thres_#1
282  simuTrig->eemc->setDsmSetup(eemcDsmSetup);
283 
284  // so far, just 2006 in this macro
286  simL2Mk->setSetupPath(eemcSetupPath);
287 
288  if (isMC) simL2Mk->setMC();
289  simuTrig->useL2(simL2Mk);
290 
291  //
292  // Tree Maker
293  //
294  treeMakerPtr = new StEEmcTreeMaker_t( "EEmcTreeMkr" );
295  treeMakerPtr->setTreeStatus( StEEmcTreeMaker_t::PART_1, StEEmcTreeMaker_t::WRITE, outputFileName );
296  treeMakerPtr->setTreeStatus( StEEmcTreeMaker_t::PART_2, StEEmcTreeMaker_t::IGNORE, "" );
297  treeMakerPtr->setTreeStatus( StEEmcTreeMaker_t::PART_3, StEEmcTreeMaker_t::IGNORE, "" );
298  treeMakerPtr->setMaxNumEvents( neventsIn );
299  treeMakerPtr->setEEmcEnergyMkr( energyMakerPtr );
300  treeMakerPtr->doSpinInfoIO( !isMC );
301  treeMakerPtr->doEvtHddrIO( 1 );
302  treeMakerPtr->setHTTPthres( 0, 0 );
303 
304 
305 
306  if( !isMC )
307  treeMakerPtr->setSpinInfoMkr( spinInfoMakerPtr );
308 
309  // McTree Maker
310  if( isMC && !skipMcTreeMaker ){
311  // determine the McTree filename from the outputFileName
312  TString filename = outputFileName;
313  if( filename.Contains("EEmcTree") )
314  filename.ReplaceAll("EEmcTree", "McEEmcTree" );
315  else if ( filename.EndsWith(".root") )
316  filename.ReplaceAll(".root", ".McEEmcTree.root");
317  else
318  filename += ".McEEmcTree.root";
319  filename.ReplaceAll("_Part1","");
320  filename.ReplaceAll(".Part1","");
321 
322  mcTreeMakerPtr = new StMcEEmcTreeMaker_t( "McEEmcTreeMkr" );
323  mcTreeMakerPtr->setEnergyThreshold( 0.0 );
324  mcTreeMakerPtr->addTrigger( -999 );
325  mcTreeMakerPtr->setTreeStatus( StMcEEmcTreeMaker_t::WRITE, filename.Data() );
326  };
327 
328  // debugging info
329  std::cout << "***** Done instanciating all the classes *****" << endl;
330  analysisChain->ls(3);
331 
332  //
333  // Initialize all makers
334  //
335 
336  std::cout << "***** Initializing all makers in the analysis chain *****" << std::endl;
337 
338  analysisChain->Init();
339 
340  std::cout << "***** Initialization done *****" << std::endl;
341 
342  //
343  // Finally ready to loop over the events
344  //
345 
346  // If neventsIn/Out is negative, reset to a large value
347  // for an Int_t
348  if( neventsIn < 0 )
349  neventsIn = 1<<30-1;
350  if( neventsOut < 0 )
351  neventsOut = 1<<30-1;
352 
353  Int_t ierr = kStOK; // err flag
354  Long_t nevents = 1; // cumulative number of events in
355  for( ; nevents <= neventsIn && treeMakerPtr->getNumPart1EventsWritten() < neventsOut && !ierr; ++nevents ){
356  // clear
357  analysisChain->Clear();
358 
359  // make
360  ierr = analysisChain->Make();
361 
362  // Print every so many events
363  if( (nevents+1) % displayFreq == 1 ){
364  trigCounter->printStatus();
365  std::cout << "***** finished event number " << nevents << ", " << treeMakerPtr->getNumPart1EventsWritten() << " *****" << std::endl;
366  };
367 
368  if( ierr ){
369  std::cout << "***** ERROR FLAG " << ierr << " on event number " << nevents << " *****" << endl;
370  };
371  };
372 
373  //---------------------------------------------------------------
374 
375 
376  //
377  // Calls the ::Finish() method on all makers
378  //
379  analysisChain->Finish();
380 
381  //
382  // Delete the chain
383  //
384  // analysisChain->Delete();
385 
386  return;
387 };
388 
389 /*
390  * $Id: makeEEmcTreePart1.C,v 1.1 2012/12/17 20:01:28 sgliske Exp $
391  * $Log: makeEEmcTreePart1.C,v $
392  * Revision 1.1 2012/12/17 20:01:28 sgliske
393  * moved from offline/users/sgliske/StRoot/StEEmcPool/StEEmcTreeMaker/macros
394  *
395  *
396  */
EEmc ADC –&gt; energy maker.
void printStatus()
monitering status
virtual void SetIOMode(Option_t *iomode="w")
number of transactions
Definition: StIOInterFace.h:35
void source(const Char_t *, Int_t=0)
void setAddPed(Bool_t a=true)
Add pedestal offsets from DB.
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
void setTreeStatus(treeTypeEnum_t type, iostatus_t iostatus, const Char_t *fileName)
modifiers
void setTreeStatus(iostatus_t iostatus, const Char_t *fileName)
modifiers
virtual Int_t Finish()
Definition: StChain.cxx:85
void threshold(Float_t cut, Int_t layer)
Filling of all StMcEvent classes from g2t tables Transform all the data in the g2t tables into the co...
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
Bool_t doPrintMemoryInfo
lots of screen output
virtual Int_t Make()
Definition: StChain.cxx:110
Definition: Stypes.h:40
void SetStatus(const char *arrType, int status)
void setSmearPed(Bool_t s=true)
Smear the pedestal with sigma from DB.
Include StRoot headers.
Slow simulator for EEMC.
StTrigCounter(const Char_t *myName, Int_t trigID=117001)
constructor
void database(const Char_t *)
Set the name of the EEMC database, init obtains pointer.