AliPhysics  63e47e1 (63e47e1)
createTree.C
Go to the documentation of this file.
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <AliEMCALGeometry.h>
3 #include <AliOADBContainer.h>
4 #include <TCanvas.h>
5 #include <TClonesArray.h>
6 #include <TDatime.h>
7 #include <TFile.h>
8 #include <TGrid.h>
9 #include <TH2F.h>
10 #include <TLegend.h>
11 #include <TMap.h>
12 #include <TNtuple.h>
13 #include <TObject.h>
14 #include <TProfile.h>
15 #include <TSystem.h>
16 #include "LInfo.h"
17 #include "TInfo.h"
18 #include "plotOCDB_Temperature.C"
19 #include "plotOCDB_LED.C"
20 
21 class TCalCell : public TObject {
22  public:
23  TCalCell() : fId(0), fSM(0), fLedM(0), fLedR(0), fMonM(0), fMonR(0), fLocT(0), fSMT(0) {;}
24  virtual ~TCalCell() {;}
25  Short_t fId; // cell id
26  Short_t fSM; // super module index
27  Short_t fRow; // row (phi) index
28  Short_t fCol; // col (eta) index
29  Short_t fBad; // bad cell
30  Double32_t fLedM; //[0,0,16] led mean
31  Double32_t fLedR; //[0,0,16] led rms
32  Double32_t fMonM; //[0,0,16] mon mean
33  Double32_t fMonR; //[0,0,16] mon rms
34  Double32_t fLocT; //[0,0,16] loc T
35  Double32_t fSMT; //[0,0,16] sm T
36  ClassDef(TCalCell, 2); // CalCell class
37 };
38 
39 class TCalSM : public TObject {
40 public:
41  TCalSM() : fSM(0), fAvgT(0), fT1(0), fT2(0), fT3(0), fT4(0), fT5(0), fT6(0), fT7(0), fFracLed(0), fFracMon(0) {;}
42  virtual ~TCalSM() {;}
43  Short_t fSM; // super module index
44  Double32_t fAvgT; //[0,0,16] sm T
45  Double32_t fT1; //[0,0,16] sensor T 1
46  Double32_t fT2; //[0,0,16] sensor T 2
47  Double32_t fT3; //[0,0,16] sensor T 3
48  Double32_t fT4; //[0,0,16] sensor T 4
49  Double32_t fT5; //[0,0,16] sensor T 5
50  Double32_t fT6; //[0,0,16] sensor T 6
51  Double32_t fT7; //[0,0,16] sensor T 7
52  Double32_t fT8; //[0,0,16] sensor T 8
53  Double32_t fFracLed; // fraction led info for each SM
54  Double32_t fFracMon; // fraction mon info for each SM
55  ClassDef(TCalSM, 1); // CalSM class
56 };
57 
58 class TCalInfo : public TObject {
59  public:
60  TCalInfo() : fRunNo(0), fAvTime(0), fFirstTime(0), fLastTime(0), fMinT(0), fMaxT(0), fFracS(0), fSMs("TCalSM"), fCells("TCalCell") {}
61  virtual ~TCalInfo() {;}
62  Int_t fRunNo; // run number
63  UInt_t fAvTime; // average start time
64  UInt_t fFirstTime; // first time
65  UInt_t fLastTime; // last time
66  Float_t fMinT; // min temperature
67  Float_t fMaxT; // max temperature
68  Float_t fFracS; // fraction good sensors
69  TClonesArray fSMs; // array with SM infos
70  TClonesArray fCells; // array with cells
71  ClassDef(TCalInfo, 2); // CalInfo class
72 };
73 #endif
74 
75 void createTree(const char *period,
76  const char *ofile = "treeout.root",
77  Bool_t doprint = 0,
78  Bool_t appBC = kFALSE, // boolean to switch on bad channel
79  TString badpath = "$ALICE_ROOT/OADB/EMCAL", // location of bad channel map
80  Int_t referenceRun = 286313 // define reference run to which all are being calibrated
81 ) {
82  TDraw td(period);
83  td.Compute();
84  LDraw ld(period);
85  ld.Compute();
86 
87  if (appBC) {
88  cout << "INFO: will be using bad channel map from: " << badpath.Data() << endl;
89  }
90 
91  TObjArray *ta = td.GetArray();
92  if (!ta) {
93  cerr << "No time objects for period " << period << endl;
94  return;
95  }
96  TObjArray *la = ld.GetArray();
97  if (!la) {
98  cerr << "No led objects for period " << period << endl;
99  return;
100  }
101 
102  const Int_t rns=la->GetEntries();
103  cout << "Working on period " << period << " with " << rns << " runs" << endl;
104 
105  AliEMCALGeometry *g= AliEMCALGeometry::GetInstanceFromRunNumber(referenceRun);
106  const Int_t kSM=g->GetNumberOfSuperModules();
107  const Int_t kNcells=g->GetNCells();
108  const Int_t gain = 1;
109 
110  TCalInfo *info = new TCalInfo;
111  TFile *out = TFile::Open(ofile,"recreate");
112  out->SetCompressionLevel(9);
113  TTree* fTree = new TTree("tcal", "Temp calibration tree");
114  fTree->SetDirectory(out);
115  fTree->Branch("event", &info, 32000, 99);
116 
117  TClonesArray &carr = info->fCells;
118  TClonesArray &cSMarr = info->fSMs;
119  Int_t l = 0;
120  Int_t t = 0;
121 
122  Int_t runno = -1;
123  Int_t idx = -1;
124  TObjArray *arrayBC=0;
125  TH2I *badmaps[kSM];
126  for (Int_t i=0;i<kSM;++i)
127  badmaps[i]=0;
128 
129  for (Int_t i=0;i<rns;++i) {
130  l++;
131  t++;
132  LInfo *linfo = dynamic_cast<LInfo*>(la->At(l));
133  if (!linfo){
134  cout << "skipping due to missing info in LED tree!" << endl;
135  t++;
136  continue;
137  }
138  TInfo *tinfo = dynamic_cast<TInfo*>(ta->At(t));
139  if (!tinfo){
140  cout << "skipping due to missing info in temp tree!" << endl;
141  l++;
142  continue;
143  }
144  Int_t runl = linfo->GetRunNo();
145  Int_t runt = tinfo->GetRunNo();
146  if (runl!=runt) {
147  if (runl > runt){
148  l--;
149  } else {
150  t--;
151  }
152  cout << " Run numbers differ, skipping " << runl << " " << runt << endl;
153  continue;
154  }
155  cout << "Working on run " << runl << endl;
156  gSystem->Sleep(0.5);
157  info->fRunNo = runt;
158  info->fAvTime = tinfo->GetAverageTime();
159  info->fFirstTime = tinfo->GetFirstTime();
160  info->fLastTime = tinfo->GetLastTime();
161  info->fMinT = tinfo->AbsMinT();
162  info->fMaxT = tinfo->AbsMaxT();
163  info->fFracS = tinfo->Fraction();
164 
165  cSMarr.Clear();
166  cSMarr.ExpandCreate(kSM);
167  for (Int_t sm=0; sm<kSM; sm++) {
168  cout << "SM "<< sm << ":\t"<< tinfo->AvgTempSM(sm) << endl;
169  TCalSM *smInfo = (TCalSM*)cSMarr.At(sm);
170  smInfo->fSM = sm;
171  smInfo->fAvgT = tinfo->AvgTempSM(sm);
172  smInfo->fT1 = tinfo->T(sm*8,3);
173  smInfo->fT2 = tinfo->T(sm*8+1,3);
174  smInfo->fT3 = tinfo->T(sm*8+2,3);
175  smInfo->fT4 = tinfo->T(sm*8+3,3);
176  smInfo->fT5 = tinfo->T(sm*8+4,3);
177  smInfo->fT6 = tinfo->T(sm*8+5,3);
178  smInfo->fT7 = tinfo->T(sm*8+6,3);
179  smInfo->fT8 = tinfo->T(sm*8+7,3);
180  smInfo->fFracLed = linfo->FracLeds(sm,gain);
181  smInfo->fFracMon = linfo->FracStrips(sm,gain);
182  }
183 
184  carr.Clear();
185  carr.ExpandCreate(kNcells);
186 
187  Double_t avg[20];
188  for (Int_t sm=0; sm<kSM; ++sm) {
189  avg[sm]=tinfo->AvgTempSM(sm);
190  }
191 
192  if (runt!=runno && appBC) {
193  runno=runt;
194  AliOADBContainer *contBC = new AliOADBContainer("");
195  contBC->InitFromFile(Form("%s/EMCALBadChannels.root",badpath.Data()),"AliEMCALBadChannels");
196  if (!contBC) {
197  cerr << "Could not load bc map for run " << runno << endl;
198  } else {
199  Int_t idxCurr =contBC->GetIndexForRun(runno);
200  if ( idx != idxCurr ){
201  cout << "INFO: need to switch bad channel map" << endl;
202  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runno);
203  if (!arrayBC){
204  cout << "WARNING: missing bad channel map for run: " << runno << " Will continue without using bad channel map!"<< endl;
205  }
206  for (Int_t i=0; i<kSM; ++i) {
207  delete badmaps[i];
208  if (!arrayBC){
209  badmaps[i] = NULL;
210  } else {
211  badmaps[i] = (TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
212  badmaps[i]->SetDirectory(0);
213  }
214  }
215  idx = idxCurr;
216  }
217  delete contBC;
218  }
219  }
220 
221  for (Int_t sm=0; sm<kSM; ++sm) {
222  Int_t nrow = g->GetNumberOfCellsInPhiDirection(sm);
223  Int_t ncol = g->GetNumberOfCellsInEtaDirection(sm);
224 
225  TH1 *hmonm = linfo->GetLedMonHist(sm,gain);
226  TH1 *hmonr = linfo->GetLedMonRmsHist(sm,gain);
227  TH2 *hledm = linfo->GetLedHist(sm,gain);
228  TH2 *hledr = linfo->GetLedRmsHist(sm,gain);
229 
230  for (Int_t col=0; col<ncol; ++col) {
231  for (Int_t row=0; row<nrow; ++row) {
232  Int_t id = g->GetAbsCellIdFromCellIndexes(sm,row,col);
233  TCalCell *cell = (TCalCell*)carr.At(id);
234  cell->fId = id;
235  Int_t badcell = 0;
236  if (appBC && badmaps[sm])
237  badcell = badmaps[sm]->GetBinContent(col,row);
238  cell->fSM = sm;
239  cell->fRow = row;
240  cell->fCol = col;
241  cell->fBad = badcell;
242 
243  Int_t orow=row;
244  Int_t ocol=col;
245  // shift to online row(phi)/col(eta)
246  g->ShiftOfflineToOnlineCellIndexes(sm, orow, ocol);
247  Int_t ns = TInfo::SensId(sm,orow,ocol);
248  cell->fLedM = hledm->GetBinContent(hledm->FindBin(ocol,orow));
249  cell->fLedR = hledm->GetBinError(hledm->FindBin(ocol,orow));
250  cell->fMonM = hmonm->GetBinContent(hmonm->FindBin(ocol/2));
251  cell->fMonR = hmonm->GetBinError(hmonm->FindBin(ocol/2));
252  cell->fLocT = tinfo->T(ns,3);
253  cell->fSMT = avg[sm];
254  }
255  }
256  }
257  fTree->Fill();
258  }
259  out->cd();
260  fTree->Write();
261  out->Close();
262 }
263 
265 {
266  createTree("lhc16f","tree_lhc16f.root");
267  createTree("lhc16g","tree_lhc16g.root");
268  createTree("lhc16h","tree_lhc16h.root");
269  createTree("lhc16i","tree_lhc16i.root");
270  createTree("lhc16j","tree_lhc16j.root");
271  createTree("lhc16k","tree_lhc16k.root");
272  createTree("lhc16l","tree_lhc16g.root");
273  createTree("lhc16o","tree_lhc16g.root");
274  createTree("lhc16p","tree_lhc16g.root");
275  createTree("lhc17p","tree_lhc17p.root");
276  createTree("lhc18d","tree_lhc18d.root");
277 }
Double32_t fT2
Definition: createTree.C:46
double Double_t
Definition: External.C:58
Double32_t fSMT
Definition: createTree.C:35
Short_t fBad
Definition: createTree.C:29
Double32_t fFracLed
Definition: createTree.C:53
Short_t fSM
Definition: createTree.C:43
Double_t FracLeds(Int_t sm, Int_t gain=1) const
Definition: LInfo.cxx:224
TObjArray * GetArray()
Definition: plotOCDB_LED.C:21
UInt_t GetLastTime() const
Definition: TInfo.h:25
Definition: TInfo.h:10
void Compute()
Definition: plotOCDB_LED.C:43
TSystem * gSystem
UInt_t GetAverageTime() const
Definition: TInfo.h:22
Float_t fFracS
Definition: createTree.C:68
UInt_t fFirstTime
Definition: createTree.C:64
Float_t AbsMaxT(Int_t t=2) const
Definition: TInfo.cxx:23
Double32_t fT6
Definition: createTree.C:50
Short_t fId
Definition: createTree.C:25
Double32_t fT3
Definition: createTree.C:47
Double32_t fT1
Definition: createTree.C:45
TClonesArray fCells
Definition: createTree.C:70
Double32_t fMonM
Definition: createTree.C:32
Definition: LInfo.h:11
virtual ~TCalCell()
Definition: createTree.C:24
TProfile * GetLedMonRmsHist(Int_t sm, Int_t gain=1) const
Definition: LInfo.h:21
int Int_t
Definition: External.C:63
Float_t fMaxT
Definition: createTree.C:67
unsigned int UInt_t
Definition: External.C:33
float Float_t
Definition: External.C:68
Short_t fRow
Definition: createTree.C:27
TProfile2D * GetLedRmsHist(Int_t sm, Int_t gain=1) const
Definition: LInfo.h:24
void createTree(const char *period, const char *ofile="treeout.root", Bool_t doprint=0, Bool_t appBC=kFALSE, TString badpath="$ALICE_ROOT/OADB/EMCAL", Int_t referenceRun=286313)
Definition: createTree.C:75
Short_t fSM
Definition: createTree.C:26
Double32_t fLedR
Definition: createTree.C:31
Double_t FracStrips(Int_t sm, Int_t gain=1) const
Definition: LInfo.cxx:251
void createTree_all()
Definition: createTree.C:264
Short_t fCol
Definition: createTree.C:28
TProfile * GetLedMonHist(Int_t sm, Int_t gain=1) const
Definition: LInfo.h:20
Int_t GetRunNo() const
Definition: LInfo.h:30
UInt_t GetFirstTime() const
Definition: TInfo.h:23
virtual ~TCalInfo()
Definition: createTree.C:61
Float_t AvgTempSM(Int_t sm, Int_t type=3) const
Definition: TInfo.cxx:36
TCalSM()
Definition: createTree.C:41
TProfile2D * GetLedHist(Int_t sm, Int_t gain=1) const
Definition: LInfo.h:23
Double32_t fT5
Definition: createTree.C:49
short Short_t
Definition: External.C:23
void Compute()
TObjArray * GetArray()
virtual ~TCalSM()
Definition: createTree.C:42
UInt_t fAvTime
Definition: createTree.C:63
UInt_t fLastTime
Definition: createTree.C:65
static Int_t SensId(Int_t sm, Int_t row, Int_t col)
Definition: TInfo.cxx:281
Definition: External.C:220
Double32_t fT4
Definition: createTree.C:48
Double32_t fLocT
Definition: createTree.C:34
Int_t fRunNo
Definition: createTree.C:62
Float_t T(Int_t ns, Int_t t) const
Definition: TInfo.cxx:80
TClonesArray fSMs
Definition: createTree.C:69
Float_t fMinT
Definition: createTree.C:66
Double32_t fMonR
Definition: createTree.C:33
Double32_t fAvgT
Definition: createTree.C:44
Double32_t fFracMon
Definition: createTree.C:54
Float_t AbsMinT(Int_t t=1) const
Definition: TInfo.cxx:10
Double_t Fraction() const
Definition: TInfo.h:29
Double32_t fT8
Definition: createTree.C:52
bool Bool_t
Definition: External.C:53
TCalCell()
Definition: createTree.C:23
TCalInfo()
Definition: createTree.C:60
Double32_t fLedM
Definition: createTree.C:30
Int_t GetRunNo() const
Definition: TInfo.h:27
Double32_t fT7
Definition: createTree.C:51
Definition: External.C:196