AliPhysics  5eaf189 (5eaf189)
scanAll.C
Go to the documentation of this file.
1 const int kNSM = 20; // max # of SuperModules
2 const int kNumSens = 160; // max total
3 
4 const int kNumSensPerSM = 8; // per SuperModule (nominally, not true for EMCal 1/3 SMs, a.k.a. SMs 10,11 & 18,19 seemingly...)
5 
6 // init to strange values
7 const int kInitMin = 100;
8 const int kInitMax = 0;
9 // limits for acceptable values
10 const int kTooHigh = 35;
11 const int kTooLow = 15;
12 // not too far from SuperModule median
13 const float kMaxDiffMedian = 2;
14 
15 const int debug = 0;
16 
17 void scanAll(const char *listfile = "filelist.txt")
18 {
19 
20  int nruns = 0;
21  ifstream fin(listfile);
22  Int_t runno = 0;
23  char fn[200];
24 
25  Int_t iSM = 0;
26  Int_t nOk = 0;
27  Int_t nPTot = 0;
28  Int_t minStart = 0;
29  Int_t maxEnd = 0;
30  Float_t aveMin = 0;
31  Float_t aveMax = 0;
32  // output
33  TFile destFile("all.root", "recreate");
34  destFile.cd();
35  TTree *tree = new TTree("tree","");
36  tree->Branch("runno", &runno, "runno/I");
37  tree->Branch("iSM", &iSM, "iSM/I");
38  tree->Branch("nOk", &nOk, "nOk/I");
39  tree->Branch("nPTot", &nPTot, "nPTot/I");
40  tree->Branch("minStart", &minStart, "minStart/I");
41  tree->Branch("maxEnd", &maxEnd, "maxEnd/I");
42  tree->Branch("aveMin", &aveMin, "aveMin/F");
43  tree->Branch("aveMax", &aveMax, "aveMax/F");
44 
45  // loop over input
46  while ( fin.good() ) {
47  fin >> runno >> fn;
48  if ( fin.good() ) {
49  cout << " filename fn " << fn << " runno " << runno << endl;
50  nruns++;
51 
52  // get the file
53  TFile *file0 = TFile::Open(fn);
54  AliEMCALSensorTempArray *arr = (AliEMCALSensorTempArray *) AliCDBEntry->GetObject();
55  if (debug>0) {
56  file0->ls();
57  arr->Print();
58  cout << " NumSensors " << arr->NumSensors()
59  << " GetFirstIdDCS() " << arr->GetFirstIdDCS()
60  << " GetLastIdDCS() " << arr->GetLastIdDCS()
61  << endl;
62  }
63  file0->Close();
64 
65  // info for each sensor
66  int np[kNumSens] = {0};
67  double min[kNumSens] = {0};
68  double max[kNumSens] = {0};
69  int id = 0;
70 
71  minStart = 0x7FFFffff;
72  maxEnd = 0;
73 
74  for (int isensor=0; isensor<kNumSens; isensor++) {
75  AliEMCALSensorTemp *o = arr->GetSensor(isensor);
76  if (o) {
77  iSM = o->GetSide() + o->GetSector()*2;
78  id = o->GetIdDCS();
79  int is = iSM*kNumSensPerSM + o->GetNum();
80  if (is != id) {
81  cout << " id mismatch: id " << id << " " << is << endl;
82  }
83  if (debug>1) {
84  o->Print();
85  cout << " side " << o->GetSide()
86  << " sector " << o->GetSector()
87  << " num " << o->GetNum()
88  << " startTime " << o->GetStartTime()
89  << " endTime " << o->GetEndTime()
90  << endl;
91  }
92  if ( minStart > o->GetStartTime() ) { minStart = o->GetStartTime(); }
93  if ( maxEnd < o->GetEndTime() ) { maxEnd = o->GetEndTime(); }
94 
95  AliSplineFit *f = o->GetFit();
96  np[is] = 0;
97  min[is] = kInitMin;
98  max[is] = kInitMax;
99 
100  if (f) {
101  np[is] = f->GetKnots();
102  if (debug>1) {
103  cout << " np " << np[is] << endl;
104  }
105  Double_t *x = f->GetX();
106  Double_t *y0 = f->GetY0();
107  Double_t *y1 = f->GetY1();
108  for (int i=0; i<np[is]; i++) {
109  if (debug>1) {
110  cout << " i " << i
111  << " x " << x[i]
112  << " y0 " << y0[i]
113  << " y1 " << y1[i]
114  << endl;
115  }
116  if (min[is]>y0[i]) min[is]=y0[i];
117  if (max[is]<y0[i]) max[is]=y0[i];
118  }
119  }
120  }
121  }
122 
123  for (iSM=0; iSM<kNSM; iSM++) {
124  if (debug>1) {
125  cout << " iSM " << iSM << endl;
126  }
127  aveMin = 0;
128  aveMax = 0;
129  nOk = 0;
130  nPTot = 0;
131 
132  double tmp[kNumSensPerSM] = {0};
133  for (int is=0; is<kNumSensPerSM; is++) {
134  id = is + iSM*kNumSensPerSM;
135  if (np[id]>0 && max[id]<kTooHigh && min[id]>kTooLow) { // some OK readings
136  tmp[nOk] = min[id];
137  nOk++;
138  }
139  }
140  double median = TMath::Median(nOk, tmp);
141 
142  nOk = 0; // reset
143  for (int is=0; is<kNumSensPerSM; is++) {
144  id = is + iSM*kNumSensPerSM;
145  if (np[id]>0 &&
146  TMath::Abs(median - max[id])<kMaxDiffMedian &&
147  TMath::Abs(median - min[id])<kMaxDiffMedian &&
148  max[id]<kTooHigh && min[id]>kTooLow) { // some OK readings
149  nOk++;
150  nPTot += np[id];
151  if (debug>1) {
152  printf("is %d np %d median %3.2f min %3.2f max %3.2f diff %3.2f\n",
153  is, np[id], median, min[id], max[id],
154  max[id] - min[id]);
155  }
156  aveMin += min[id];
157  aveMax += max[id];
158  }
159 
160  }
161 
162  if (nOk > 0) {
163  aveMin /= nOk;
164  aveMax /= nOk;
165 
166  if (debug>0) {
167  printf("iSM %d average min %3.2f max %3.2f (max+min)/2 %3.2f\n",
168  iSM, aveMin, aveMax, (aveMin + aveMax)/2.);
169  }
170  }
171 
172  tree->Fill();
173  } // SM loop
174 
175  }
176  }
177  cout << " nruns " << nruns << endl;
178 
179  destFile.cd();
180  tree->Write();
181  destFile.Close();
182 
183  return;
184 }
185 
void scanAll(const char *listfile="filelist.txt")
Definition: scanAll.C:17
double Double_t
Definition: External.C:58
const int debug
Definition: scanAll.C:15
const int kInitMax
Definition: scanAll.C:8
const int kNumSens
Definition: scanAll.C:2
const int kTooHigh
Definition: scanAll.C:10
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
const int kTooLow
Definition: scanAll.C:11
const float kMaxDiffMedian
Definition: scanAll.C:13
const int kNSM
Definition: scanAll.C:1
const int kInitMin
Definition: scanAll.C:7
const int kNumSensPerSM
Definition: scanAll.C:4