StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makeADCplot.C
1 /***************************************************************************
2  *
3  * $Id: makeADCplot.C,v 1.1 2012/01/31 09:26:18 sgliske Exp $
4  * Author: S. Gliske, Sept 2011
5  *
6  ***************************************************************************
7  *
8  * Description: Script to make the basic ADC vs channel or ADC vs strip plots.
9  *
10  ***************************************************************************
11  *
12  * $Log: makeADCplot.C,v $
13  * Revision 1.1 2012/01/31 09:26:18 sgliske
14  * StFgtQaMakers moved to StFgtPool
15  *
16  * Revision 1.1 2011/09/30 19:05:32 sgliske
17  * general update
18  *
19  *
20  **************************************************************************/
21 
22 // forward declarations
23 class StChain;
24 class StFgtCosmicMaker;
25 class StFgtCorAdcMaker;
27 
28 StChain *analysisChain = 0;
29 StFgtCosmicMaker *cosmicMkr = 0;
30 StFgtCorAdcMaker *adcCorrector = 0;
31 StFgtQaAdcVsChannel *adcPlotter = 0;
32 
33 TCanvas *can = 0;
34 
35 Int_t makeADCplot( const Char_t *filename = "testfile.sfs",
36  const Char_t *pedfilename = "testfile.Ped.txt",
37  Int_t disc = 0,
38  Int_t quad = 0,
39  Char_t plotVsStrip = 'c',
40  Int_t subtrPeds = 1,
41  const Char_t *runname = "testrun",
42  const Char_t *quadname = "010",
43  Int_t nevents = -1,
44  Int_t timeBin = 4,
45  Int_t numDiscs = 3 ){
46  LoadLibs();
47  Int_t ierr = 0;
48 
49  Short_t timeBinMask = (1<<timeBin);
50 
51  cout << "Constructing the chain" << endl;
52  analysisChain = new StChain("eemcAnalysisChain");
53 
54  cout << "Constructing the cosmic maker" << endl;
55  cosmicMkr = new StFgtCosmicMaker( "cosmicMaker", filename );
56  cosmicMkr->setNumDiscs( numDiscs );
57 
58  cout << "Constructing the ADC corrector" << endl;
59 
60  // useful for removing extra time bins even if not ped subtracting
61 
62  adcCorrector = new StFgtCorAdcMaker( "adcCorrector", "cosmicMaker" );
63  adcCorrector->setPedReaderFile( pedfilename );
64  adcCorrector->setTimeBinMask( timeBinMask );
65  adcCorrector->setAbsThres( -10000 ); // set below -4096 to skip cut
66  adcCorrector->setRelThres( 0 ); // set to zero to skip cut
67  adcCorrector->doSubtrPeds( subtrPeds );
68  adcCorrector->doRemoveOtherTimeBins( 1 );
69 
70  cout << "Constructing the QA maker" << endl;
71 
72  // ranges and number of strips/channels to average over
73  Int_t binFactorX = 8, binFactorY = 32;
74  Float_t sansPedYmax = 1024;
75  Float_t sansPedYmin = -512;
76  Int_t sansPedYbins = 4096/binFactorY;
77 
78  if( plotVsStrip == 'R' || plotVsStrip == 'r' )
79  binFactorX = 1;
80  else if ( plotVsStrip == 'P' )
81  binFactorX = 4;
82 
83  if( subtrPeds )
84  binFactorY = 1;
85 
86  adcPlotter = new StFgtQaAdcVsChannel( "fgtQaAdc_1", "cosmicMaker", disc, quad, quadname );
87  adcPlotter->setTimeBin( timeBin );
88  adcPlotter->setFilenameBase( "" ); // do not save
89  adcPlotter->setToPlotVsStrip( plotVsStrip );
90  adcPlotter->setToSubtrPeds( 0 ); // already done
91  adcPlotter->setBinFactors( binFactorX, binFactorY );
92  if( subtrPeds ){
93  adcPlotter->setYbins( sansPedYbins );
94  adcPlotter->setYrange( sansPedYmin, sansPedYmax );
95  };
96 
97  cout << "Initializing" << endl;
98  ierr = analysisChain->Init();
99  cout << "\t done initializing" << endl;
100 
101  if( ierr ){
102  cout << "Error initializing" << endl;
103  return;
104  };
105 
106  if( nevents < 0 )
107  nevents = 1<<30; // a big number
108 
109  cout << "Looping over events..." << endl;
110  for( int i=0; i<nevents && !ierr; ++i ){
111 
112  if( (i+1)%1000 == 1 )
113  cout << "event number " << i << endl;
114 
115  //cout << "clear" << endl;
116  analysisChain->Clear();
117 
118  //cout << "make" << endl;
119  ierr = analysisChain->Make();
120 
121  if( cosmicMkr->atEOF() )
122  ierr = 127;
123  };
124 
125  cout << "Making plots..." << endl;
126 
127  // now do some plotting
128  TH2F* hAdc = adcPlotter->getHist();
129 
130  gROOT->SetStyle("Plain");
131  gStyle->SetOptStat(0);
132  gStyle->SetEndErrorSize(0);
133  gStyle->SetTitleBorderSize(0);
134  gStyle->SetTitleTextColor(kRed);
135 
136  Int_t width = 1800;
137  Int_t height = 600;
138  if( plotVsStrip == 'R' || plotVsStrip == 'r' || plotVsStrip == 'P' ){
139  width /= 3;
140  height = width+1;
141  };
142 
143  gROOT->SetStyle("Plain");
144  TCanvas *can = new TCanvas( "fgtQAcan", "Fgt Cosmic QA", width, height );
145 
146  gStyle->SetOptStat(0);
147  gStyle->SetPalette(1);
148 
149  //can->SetRightMargin( 0.02 );
150  //can->SetLeftMargin( 0.13 );
151  //hAdc->GetYaxis()->SetTitleOffset( 1.55 );
152 
153  hAdc->SetMaximum( subtrPeds ? 100 : 200 );
154  hAdc->Draw("COLZ");
155 
156  cout << "ready to save" << endl;
157 
158  std::string fileOut = "fgtCQA.ADCplot.";
159  fileOut += runname;
160  fileOut += ".fgt";
161  fileOut += quadname;
162  fileOut += ".eps";
163 
164  cout << "\tsaving to '" << fileOut << "'" << endl;
165  can->Print( fileOut.data() );
166 
167  TFile *f = new TFile ("testfile.root", "RECREATE");
168  hAdc->Write();
169  f->Close();
170 
171  //
172  // Calls the ::Finish() method on all makers
173  //
174  cout << "finish" << endl;
175  analysisChain->Finish(); // bug in LOG_ makes this fail
176 
177  cout << "all done" << endl;
178  return;
179 };
180 
181 
182 // load the shared libraries
183 void LoadLibs() {
184  // common shared libraries
185 
186  gSystem->Load("libPhysics");
187  gSystem->Load("St_base");
188  gSystem->Load("StChain");
189  gSystem->Load("StEvent");
190  cout << "loaded StEvent library" << endl;
191 
192  gSystem->Load("StFgtUtil");
193  gSystem->Load("StFgtRawMaker");
194  gSystem->Load("RTS");
195  gSystem->Load("StFgtPedMaker");
196  gSystem->Load("StFgtQaMakers");
197  gSystem->Load("StFgtCorAdcMaker");
198 
199 };
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
virtual Int_t Finish()
Definition: StChain.cxx:85
virtual Int_t Make()
Definition: StChain.cxx:110