-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththrescanlib.cpp
More file actions
1606 lines (1402 loc) · 50.3 KB
/
threscanlib.cpp
File metadata and controls
1606 lines (1402 loc) · 50.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "threscanlib.h"
#include "utillib.h"
#include "menulib.h"
#include "treevariables.h"
// Local tree variables
static UShort_t colNum;
static UShort_t rowNum;
Int_t n8b10bErrors;
Int_t corruptEvents;
Int_t oversizeEvts;
Int_t timeouts;
Int_t pixWOHits[NUMCHIPS];
Int_t pixWOThres[NUMCHIPS];
Int_t hotPixels[NUMCHIPS];
//Float_t thresValue;
//Float_t noiseValue;
UShort_t thresValue;
UShort_t noiseValue;
Float_t avrgThres[NUMCHIPS];
Float_t thresRMS[NUMCHIPS];
Float_t deviation[NUMCHIPS];
Float_t avrgNoise[NUMCHIPS];
Float_t noiseRMS[NUMCHIPS];
Int_t classificThreScan;
static Long64_t testTunOffset;
void analyzeAllThresholdScans(std::vector<ComponentDB::componentShort> componentList, AlpideDB *db, const THicType hicType)
{
//
// Steering routine to analyze the data of all Threshold Scans for all HICs
//
// Inputs:
// componentList : a vector of componentShort with the list
// of all HICs
// db : a pointer to the Alpide DB
// hicType : the HIC type (IB or OB)
//
// Outputs:
//
// Return:
//
// Created: 29 Jan 2019 Mario Sitta
// Updated: 31 Jan 2019 Mario Sitta
// Updated: 26 Feb 2019 Mario Sitta HIC type added
// Updated: 05 Jul 2019 Mario Sitta Chip Wafer and position added
// Updated: 16 Sep 2019 Mario Sitta HIC name added
//
// We need to define here the TTree's for the existing ROOT file
TTree *oldHicQualTree = 0, *oldHicRecpTree = 0, *oldHicHSTree = 0, *oldHicStaveTree = 0;
TTree *oldHicQualTunTree = 0, *oldHicRecpTunTree = 0, *oldHicHSTunTree = 0, *oldHicStaveTunTree = 0;
TTree *oldHicQualResTree = 0, *oldHicRecpResTree = 0, *oldHicHSResTree = 0, *oldHicStaveResTree = 0;
TTree *oldActFastListTree = 0;
// Should never happen (the caller should have created it for us)
if (!db) {
printMessage("analyzeAllThresholdScans","Error: the DataBase was not opened");
f12ToExit();
return;
}
ActivityDB *activityDB = new ActivityDB(db);
// Check whether the ROOT file already exists
// If yes, ask the user whether to use it or redo a new one
TString rootFileName;
if (hicType == HIC_IB)
rootFileName = "IBHIC_ThresholdScan_AllHICs.root";
else
rootFileName = "OBHIC_ThresholdScan_AllHICs.root";
redoFromStart = kTRUE;
if(CheckRootFileExists(rootFileName)) {
if(AskUserRedoScan() == 2) { // User chose to re-use existing tree
redoFromStart = kFALSE;
TString oldRootFileName;
if(!RenameExistingRootFile(rootFileName, "_old", oldRootFileName)) {
printMessage("\nanalyzeAllThresholdScans","Error: error renaming existing ROOT file");
f12ToExit();
return;
}
TFile *oldThrescanFile = OpenRootFile(oldRootFileName);
if(!oldThrescanFile) {
printMessage("\nanalyzeAllThresholdScans","Error: error opening existing ROOT file");
f12ToExit();
return;
}
oldHicQualTree = ReadThreScanTree("hicQualTree",oldThrescanFile);
oldHicRecpTree = ReadThreScanTree("hicRecpTree",oldThrescanFile);
oldHicHSTree = ReadThreScanTree("hicHSTree",oldThrescanFile);
oldHicStaveTree = ReadThreScanTree("hicStaveTree",oldThrescanFile);
oldHicQualTunTree = ReadThreScanTree("hicQualTunTree",oldThrescanFile);
oldHicRecpTunTree = ReadThreScanTree("hicRecpTunTree",oldThrescanFile);
oldHicHSTunTree = ReadThreScanTree("hicHSTunTree",oldThrescanFile);
oldHicStaveTunTree = ReadThreScanTree("hicStaveTunTree",oldThrescanFile);
oldHicQualResTree = ReadThreScanTreeResult("hicQualResTree",oldThrescanFile);
oldHicRecpResTree = ReadThreScanTreeResult("hicRecpResTree",oldThrescanFile);
oldHicHSResTree = ReadThreScanTreeResult("hicHSResTree",oldThrescanFile);
oldHicStaveResTree = ReadThreScanTreeResult("hicStaveResTree",oldThrescanFile);
oldActFastListTree = ReadHicActListTreeTS(oldThrescanFile);
if(!oldHicQualTree || !oldHicRecpTree || !oldHicHSTree || !oldHicStaveTree ||
!oldHicQualTunTree || !oldHicRecpTunTree || !oldHicHSTunTree || !oldHicStaveTunTree ||
!oldHicQualResTree || !oldHicRecpResTree || !oldHicHSResTree || !oldHicStaveResTree ||
!oldActFastListTree) {
printMessage("\nanalyzeAllThresholdScans","Error: error reading trees from existing ROOT file");
f12ToExit();
return;
}
} // if(AskUserRedoScan())
} // if(CheckRootFileExists())
// Open the ROOT file
TFile *newThrescanFile = OpenRootFile(rootFileName, kTRUE);
if(!newThrescanFile) {
printMessage("\nanalyzeAllThresholdScans","Error: error opening new ROOT file");
f12ToExit();
return;
}
// Create or read the trees
TTree *hicQualTree = CreateTreeThresholdScan("hicQualTree","HicQualificationTest");
TTree *hicRecpTree = CreateTreeThresholdScan("hicRecpTree","HicReceptionTest");
TTree *hicHSTree = CreateTreeThresholdScan("hicHSTree","HicHalfStaveTest");
TTree *hicStaveTree = CreateTreeThresholdScan("hicStaveTree","HicStaveTest");
TTree *hicQualTunTree = CreateTreeThresholdScan("hicQualTunTree","HicQualifTuneTest");
TTree *hicRecpTunTree = CreateTreeThresholdScan("hicRecpTunTree","HicReceptTuneTest");
TTree *hicHSTunTree = CreateTreeThresholdScan("hicHSTunTree","HicHalfStavTuneTest");
TTree *hicStaveTunTree = CreateTreeThresholdScan("hicStaveTunTree","HicStaveTuneTest");
TTree *hicQualResTree = CreateTreeThresholdScanResult("hicQualResTree","HicQualificationTestResults");
TTree *hicRecpResTree = CreateTreeThresholdScanResult("hicRecpResTree","HicReceptionTestResults");
TTree *hicHSResTree = CreateTreeThresholdScanResult("hicHSResTree","HicHalfStaveTestResults");
TTree *hicStaveResTree = CreateTreeThresholdScanResult("hicStaveResTree","HicStaveTestResults");
TTree *actFastListTree = CreateHicActListTreeTS();
// Loop on all components
int totHICAnal = 0, totActAnal = 0;
std::vector<ComponentDB::compActivity> tests;
std::vector<ComponentDB::componentShort>::iterator iComp;
for (iComp = componentList.begin(); iComp != componentList.end(); iComp++) {
ComponentDB::componentShort comp = *iComp;
DbGetAllTests (db, comp.ID, tests, STThreshold, true);
// Get the list of chips in this HIC
std::vector<TChild> children;
int nChildren = DbGetListOfChildren(db, comp.ID, children, true);
if (nChildren == 0)
printMessage("\nanalyzeThresholdScan","Warning: HIC has no children ", comp.ComponentID.c_str());
// Loop on all activities
std::vector<ComponentDB::compActivity>::iterator it;
for(it = tests.begin(); it != tests.end(); it++) {
ComponentDB::compActivity act = *it;
ActivityDB::activityLong actLong;
activityDB->Read(act.ID, &actLong);
TTree *testree = 0, *testuntree = 0, *resultree = 0;
TTree *oldtestree = 0, *oldtestuntree = 0, *oldresultree = 0;
if(actLong.Type.Name.find("HIC") != string::npos &&
actLong.Type.Name.find("Qualification") != string::npos) {
testree = hicQualTree;
testuntree = hicQualTunTree;
resultree = hicQualResTree;
oldtestree = oldHicQualTree;
oldtestuntree = oldHicQualTunTree;
oldresultree = oldHicQualResTree;
actMask = ACTMASK_QUALIF;
}
if(actLong.Type.Name.find("HIC") != string::npos &&
actLong.Type.Name.find("Reception") != string::npos) {
testree = hicRecpTree;
testuntree = hicRecpTunTree;
resultree = hicRecpResTree;
oldtestree = oldHicRecpTree;
oldtestuntree = oldHicRecpTunTree;
oldresultree = oldHicRecpResTree;
actMask = ACTMASK_RECEPT;
}
if(actLong.Type.Name.find("HS") != string::npos &&
(actLong.Type.Name.find("ML") != string::npos ||
actLong.Type.Name.find("OL") != string::npos)) {
testree = hicHSTree;
testuntree = hicHSTunTree;
resultree = hicHSResTree;
oldtestree = oldHicHSTree;
oldtestuntree = oldHicHSTunTree;
oldresultree = oldHicHSResTree;
actMask = ACTMASK_HALFST;
}
if(actLong.Type.Name.find("Stave") != string::npos &&
(actLong.Type.Name.find("ML") != string::npos ||
actLong.Type.Name.find("OL") != string::npos)) {
testree = hicStaveTree;
testuntree = hicStaveTunTree;
resultree = hicStaveResTree;
oldtestree = oldHicStaveTree;
oldtestuntree = oldHicStaveTunTree;
oldresultree = oldHicStaveResTree;
actMask = ACTMASK_STAVET;
}
if (!testree) continue; // Not a Qualification/Reception/HS/Stave test
if(!redoFromStart)
if(FindActivityInThreScanTree(oldActFastListTree, comp.ID, act.ID, actMask)) {
printMessage("\nanalyzeAllThresholdScans", "Activity already in file, copying trees ", actLong.Name.c_str());
CopyThreScanOldToNew(comp.ID, act.ID, testree, testuntree, resultree, oldtestree, oldtestuntree, oldresultree);
actFastListTree->Fill();
continue;
}
string eosPath = FindEOSPath(actLong, hicType);
if(eosPath.length() == 0) { // No valid path found on EOS
string hicAct = actLong.Name + " " + actLong.Type.Name;
printMessage("\nanalyzeAllThresholdScans", "EOS for this activity does not exists", hicAct.c_str());
continue;
}
// Fill the tree for all chips (only post-tuning scans)
testOffset = testree->GetEntries();
testTunOffset = testuntree->GetEntries();
testResOffset = resultree->GetEntries();
strncpy(hicName, comp.ComponentID.c_str(), HICNAMELEN-1);
hicClass = ConvertTestResult(act.Result.Name);
ThresholdScanAllChips(testree, actLong, comp.ID, act.ID, eosPath, hicType, children, false);
ThresholdTuneAllChips(testuntree, actLong, comp.ID, act.ID, eosPath, hicType, children);
ThresholdScanResults(resultree, actLong, comp.ID, act.ID, eosPath, hicType);
Long64_t prevTestOffset = testree->GetEntries();
Long64_t prevTestTunOffset = testuntree->GetEntries();
Long64_t prevTestResOffset = resultree->GetEntries();
if(testOffset == prevTestOffset || testResOffset == prevTestResOffset || testTunOffset == prevTestTunOffset)
printMessage("\nanalyzeAllThresholdScans", "Trees not filled for activity ", actLong.Name.c_str());
else
actFastListTree->Fill();
totActAnal++;
cout << ".";
fflush(stdout);
}
totHICAnal++;
if(totHICAnal%50 == 0) cout << totHICAnal;
fflush(stdout);
if(totHICAnal%50 == 0) { // Renew the db credentials
db = 0;
db = initAlpideDB();
activityDB = 0;
activityDB = new ActivityDB(db);
}
}
// Close the ROOT file and exit
hicQualTree->Write();
hicRecpTree->Write();
hicHSTree->Write();
hicStaveTree->Write();
hicQualResTree->Write();
hicRecpResTree->Write();
hicHSResTree->Write();
hicStaveResTree->Write();
actFastListTree->Write();
CloseRootFile(newThrescanFile);
#ifdef USENCURSES
mvprintw(LINES-4, 0, "\n ROOT file %s filled with %d activities\n", rootFileName.Data(), totActAnal);
#else
printf("\n\n ROOT file %s filled with %d activities\n", rootFileName.Data(), totActAnal);
#endif
f12ToExit();
}
void analyzeThresholdScan(const int hicid, const ComponentDB::compActivity act, AlpideDB *db, const THicType hicType)
{
//
// Steering routine to analyze Threshold Scan data for one HIC
//
// Inputs:
// hicid : the HIC id
// act : the HIC activity whose DigiScan will be analyzed
// db : a pointer to the Alpide DB
// hicType : the HIC type (IB or OB)
//
// Outputs:
//
// Return:
//
// Created: 28 Jan 2019 Mario Sitta
// Updated: 31 Jan 2019 Mario Sitta
// Updated: 26 Feb 2019 Mario Sitta HIC type added
// Updated: 06 Jun 2019 Mario Sitta Get rid of timestamp from act name
// Updated: 05 Jul 2019 Mario Sitta Chip Wafer and position added
// Updated: 16 Sep 2019 Mario Sitta HIC name added
//
// Should never happen (the caller should have created it for us)
if (!db) {
printMessage("analyzeThresholdScan","Error: the DataBase was not opened");
f12ToExit();
return;
}
ActivityDB *activityDB = new ActivityDB(db);
// Get the proper path to the Digital Scan result files
ActivityDB::activityLong actLong;
activityDB->Read(act.ID, &actLong);
string eosPath = FindEOSPath(actLong, hicType);
if (eosPath == "") {
printMessage("\nanalyzeThresholdScan","Error: no valid EOS path found");
f12ToExit();
return;
}
// Open the ROOT file
string rootFileName;
if (hicType == HIC_IB)
rootFileName = act.Name.substr(act.Name.find("IBHIC"));
else
rootFileName = act.Name.substr(act.Name.find("OBHIC"));
size_t beginTS = rootFileName.find("[");
size_t endTS = rootFileName.find("]");
if (beginTS != string::npos && endTS != string::npos) // Remove the timestamp
rootFileName.erase(beginTS - 1); // Till end of string (-1 is for blank space)
replace(rootFileName.begin(), rootFileName.end(), ' ', '_');
rootFileName += "_ThresholdScan.root";
TFile *threscanFile = OpenRootFile(rootFileName, kTRUE);
if (!threscanFile) {
printMessage("\nanalyzeThresholdScan","Error: error opening the ROOT file");
f12ToExit();
return;
}
// Create the trees
TTree *threscanTree = CreateTreeThresholdScan("threscanTree","ThresholdScanTree");
if (!threscanTree) {
printMessage("\nanalyzeThresholdScan","Error: error creating the ROOT tree");
f12ToExit();
return;
}
TTree *threstunTree = CreateTreeThresholdScan("threstunTree","ThresholdTuneTree");
if (!threstunTree) {
printMessage("\nanalyzeThresholdScan","Error: error creating the ROOT tree");
f12ToExit();
return;
}
TTree *thresresulTree = CreateTreeThresholdScanResult("thresresulTree","ThresholdScanResulTree");
if (!thresresulTree) {
printMessage("\nanalyzeThresholdScan","Error: error creating the ROOT tree");
f12ToExit();
return;
}
// Get the list of chips in this HIC
std::vector<TChild> children;
int nChildren = DbGetListOfChildren(db, hicid, children, true);
if (nChildren == 0)
printMessage("\nanalyzeThresholdScan","Warning: HIC has no children");
// Get the name of the HIC
int componentTypeId;
if (hicType == HIC_IB)
componentTypeId = DbGetComponentTypeId (db, "Inner Barrel HIC Module");
else
componentTypeId = DbGetComponentTypeId (db, "Outer Barrel HIC Module");
string hicNameStr = DbGetComponentName(db, componentTypeId, hicid);
strncpy(hicName, hicNameStr.c_str(), HICNAMELEN-1);
// Fill the trees for all chips (all scans)
hicClass = ConvertTestResult(act.Result.Name);
ThresholdScanAllChips(threscanTree, actLong, hicid, act.ID, eosPath, hicType, children);
ThresholdTuneAllChips(threstunTree, actLong, hicid, act.ID, eosPath, hicType, children);
ThresholdScanResults(thresresulTree, actLong, hicid, act.ID, eosPath, hicType);
// Close the ROOT file and exit
threscanTree->Write();
threstunTree->Write();
thresresulTree->Write();
CloseRootFile(threscanFile);
#ifdef USENCURSES
printw("\n ROOT file %s filled\n", rootFileName.c_str());
#else
printf("\n ROOT file %s filled\n", rootFileName.c_str());
#endif
f12ToExit();
}
void CopyThreScanOldToNew(const UInt_t hicid, const UInt_t actid,
TTree *newscan, TTree *newtun, TTree *newres,
TTree *oldscan, TTree *oldtun, TTree *oldres)
{
//
// Copies all data of a given activity from the old tree to the new tree
//
// Inputs:
// hicid : the HIC Id
// actid : the Activity Id
// newscan : the new scan tree
// newtun : the new tuning tree
// newres : the new result tree
// oldscan : the old scan tree
// oldtun : the old tuning tree
// oldres : the old result tree
//
// Outputs:
//
// Return:
//
// Created: 18 Jan 2019 Mario Sitta
// Updated: 31 Jan 2019 Mario Sitta We have 3 trees here
//
// Save current values (they were filled by FindActivityInThreScanTree
// which was called just before us), then update
Long64_t offsetest = testOffset;
Long64_t offsettun = testTunOffset;
Long64_t offsetres = testResOffset;
testOffset = newscan->GetEntries();
testTunOffset = newtun->GetEntries();
testResOffset = newres->GetEntries();
// Copy scan data from old tree to new tree
Long64_t currEntries = oldscan->GetEntries();
Int_t i = 0;
oldscan->GetEntry(offsetest + i); // Get the first entry, then loop
while(hicID == hicid && actID == actid && (offsetest + i) < currEntries) {
newscan->Fill();
i++;
oldscan->GetEntry(offsetest + i);
}
// Copy tuning data from old tree to new tree
currEntries = oldtun->GetEntries();
i = 0;
oldtun->GetEntry(offsettun + i); // Ditto
while(hicID == hicid && actID == actid && (offsettun + i) < currEntries) {
newtun->Fill();
i++;
oldtun->GetEntry(offsetest + i);
}
// Copy condition data from old tree to new tree
currEntries = oldres->GetEntries();
i = 0;
oldres->GetEntry(offsetres + i); // Ditto
while(hicID == hicid && actID == actid && (offsetres + i) < currEntries) {
newres->Fill();
i++;
oldres->GetEntry(offsetres + i);
}
// Reset values (to fill new activity tree) then exit
hicID = hicid;
actID = actid;
return;
}
TTree* CreateHicActListTreeTS(void)
{
//
// Creates an ancillary tree to store a list of HICs and Activity IDs
// in order to fast search whether a given HIC/Activity is already present
//
// Inputs:
//
// Outputs:
//
// Return:
// a pointer to the created ROOT tree
//
// Created: 27 Nov 2018 Mario Sitta
// Updated: 18 Jan 2019 Mario Sitta
//
TTree *newTree = 0;
newTree = new TTree("actFastListTree", "HicActFastListTree");
if(newTree) {
newTree->Branch("hicID", &hicID, "hicID/i");
newTree->Branch("actID", &actID, "actID/i");
newTree->Branch("actMask", &actMask, "actMask/s");
newTree->Branch("actOffs", &testOffset, "testOffset/L");
newTree->Branch("actTunOff", &testTunOffset, "testTunOffset/L");
newTree->Branch("actResOff", &testResOffset, "testResOffset/L");
}
return newTree;
}
TTree* CreateTreeThresholdScan(TString treeName, TString treeTitle)
{
//
// Creates a tree for the Threshold Scan
//
// Inputs:
// treeName : the tree name
// treeTitle : the tree title
//
// Outputs:
//
// Return:
// a pointer to the created ROOT tree
//
// Created: 08 Jan 2019 Mario Sitta
// Updated: 05 Jul 2019 Mario Sitta Chip Wafer and position added
// Updated: 09 Jul 2019 Mario Sitta HIC class added
// Updated: 16 Sep 2019 Mario Sitta HIC name added
//
TTree *newTree = 0;
newTree = new TTree(treeName.Data(), treeTitle.Data());
if(newTree) {
newTree->Branch("hicName", hicName, "hicName[13]/B");
newTree->Branch("hicID", &hicID, "hicID/i");
newTree->Branch("actID", &actID, "actID/i");
newTree->Branch("locID", &locID, "locID/I");
newTree->Branch("condVB", &condVB, "condVB/b");
newTree->Branch("hicClass", &hicClass, "hicClass/B");
newTree->Branch("chipNum", &chipNum, "chipNum/b");
newTree->Branch("waferNum", &waferNum, "waferNum/B");
newTree->Branch("waferPos", &waferPos, "waferPos/B");
newTree->Branch("colNum", &colNum, "colNum/s");
newTree->Branch("rowNum", &rowNum, "rowNum/s");
// newTree->Branch("thresh", &thresValue, "thresValue/F");
// newTree->Branch("noise", &noiseValue, "noiseValue/F");
newTree->Branch("thresh", &thresValue, "thresValue/s");
newTree->Branch("noise", &noiseValue, "noiseValue/s");
}
return newTree;
}
TTree* CreateTreeThresholdScanResult(TString treeName, TString treeTitle)
{
//
// Creates a tree for the Threshold Scan Result
//
// Inputs:
// treeName : the tree name
// treeTitle : the tree title
//
// Outputs:
//
// Return:
// a pointer to the created ROOT tree
//
// Created: 08 Jan 2019 Mario Sitta
// Updated: 09 Jul 2019 Mario Sitta HIC class added
// Updated: 16 Sep 2019 Mario Sitta HIC name added
//
TTree *newTree = 0;
newTree = new TTree(treeName.Data(), treeTitle.Data());
if(newTree) {
newTree->Branch("hicName", hicName, "hicName[13]/B");
newTree->Branch("hicID", &hicID, "hicID/i");
newTree->Branch("actID", &actID, "actID/i");
newTree->Branch("locID", &locID, "locID/I");
newTree->Branch("startDate", &startDate, "startDate/l");
newTree->Branch("condVB", &condVB, "condVB/b");
newTree->Branch("hicClass", &hicClass, "hicClass/B");
newTree->Branch("vdddStart", &vdddStart, "vdddStart/F");
newTree->Branch("vdddEnd", &vdddEnd, "vdddEnd/F");
newTree->Branch("vddaStart", &vddaStart, "vddaStart/F");
newTree->Branch("vddaEnd", &vddaEnd, "vddaEnd/F");
newTree->Branch("vdddSetStart", &vdddSetStart, "vdddSetStart/F");
newTree->Branch("vdddSetEnd", &vdddSetEnd, "vdddSetEnd/F");
newTree->Branch("vddaSetStart", &vddaSetStart, "vddaSetStart/F");
newTree->Branch("vddaSetEnd", &vddaSetEnd, "vddaSetEnd/F");
newTree->Branch("idddStart", &idddStart, "idddStart/F");
newTree->Branch("idddEnd", &idddEnd, "idddEnd/F");
newTree->Branch("iddaStart", &iddaStart, "iddaStart/F");
newTree->Branch("iddaEnd", &iddaEnd, "iddaEnd/F");
newTree->Branch("anaSupVoltStart", &anaSupVoltStart, "anaSupVoltStart/F");
newTree->Branch("anaSupVoltEnd", &anaSupVoltEnd, "anaSupVoltEnd/F");
newTree->Branch("digSupVoltStart", &digSupVoltStart, "digSupVoltStart/F");
newTree->Branch("digSupVoltEnd", &digSupVoltEnd, "digSupVoltEnd/F");
newTree->Branch("tempStart", &tempStart, "tempStart/F");
newTree->Branch("tempEnd", &tempEnd, "tempEnd/F");
newTree->Branch("chipAnalVoltStart", chipAnalVoltStart, "chipAnalVoltStart[14]/F");
newTree->Branch("chipAnalVoltEnd", chipAnalVoltEnd, "chipAnalVoltEnd[14]/F");
newTree->Branch("chipDigiVoltStart", chipDigiVoltStart, "chipDigiVoltStart[14]/F");
newTree->Branch("chipDigiVoltEnd", chipDigiVoltEnd, "chipDigiVoltEnd[14]/F");
newTree->Branch("chipTempStart", chipTempStart, "chipTempStart[14]/F");
newTree->Branch("chipTempEnd", chipTempEnd, "chipTempEnd[14]/F");
newTree->Branch("n8b10bErr", &n8b10bErrors, "n8b10bErrors/I");
newTree->Branch("corruptEvts", &corruptEvents, "corruptEvents/I");
newTree->Branch("oversizEvts", &oversizeEvts, "oversizeEvts/I");
newTree->Branch("timeouts", &timeouts, "timeouts/I");
newTree->Branch("pixwohits", pixWOHits, "pixWOHits[14]/I");
newTree->Branch("pixwothrs", pixWOThres, "pixWOThres[14]/I");
newTree->Branch("hotpix", hotPixels, "hotPixels[14]/I");
newTree->Branch("avgthres", avrgThres, "avrgThres[14]/F");
newTree->Branch("rmsthres", thresRMS, "thresRMS[14]/F");
newTree->Branch("deviation", deviation, "deviation[14]/F");
newTree->Branch("avgNoise", avrgNoise, "avrgNoise[14]/F");
newTree->Branch("rmsnoise", noiseRMS, "noiseRMS[14]/F");
newTree->Branch("reg700Start", reg700Start, "reg700Start[14]/s");
newTree->Branch("reg700End", reg700End, "reg700End[14]/s");
newTree->Branch("classificVers", &classificVers, "classificVers/F");
newTree->Branch("classificThreScan", &classificThreScan, "classificThreScan/I");
// newTree->Branch("numWorkChips", &numWorkChips, "numWorkChips/F");
}
return newTree;
}
void ThresholdScanAllChips(TTree *ftree, ActivityDB::activityLong actlong, const int hicid, const int actid, const string eospath, const THicType hicType, std::vector<TChild> children, bool allScans)
{
//
// Loops on chips and fills the tree for the given activity
//
// Inputs:
// ftree : the tree to be filled
// actlong : the activityLong for which the analysis is done
// hicid : the HIC id
// actid : the activity id
// eospath : the input file path on EOS
// hicType : the HIC type (IB or OB)
// children: vector of all HIC children
// allScans: if false analyze only post-tuning scans, if true do all
//
// Outputs:
//
// Return:
//
// Created: 29 Jan 2019 Mario Sitta
// Updated: 26 Feb 2019 Mario Sitta HIC type added, bug fix in chip loop
// Updated: 10 Jul 2019 Mario Sitta Wafer number and chip position added
//
hicID = hicid;
actID = actid;
locID = actlong.Location.ID;
// Open Threshold Scan files and fill the tree
string dataName, resultName;
unsigned char conds[4] = {100, 200, 103, 203}; // See next method for code meaning
for (int icond = 0; icond < 4; icond ++) {
if(conds[icond] < 200 && !allScans) continue;
const int numchips = ((hicType == HIC_OB) ? NUMCHIPS+1 : NUMCHIPSIB);
for (int ichip = 0; ichip < numchips; ichip++) {
if(hicType == HIC_IB) chipNum = ichip;
if(hicType == HIC_OB && ichip == 7) continue;
if(hicType == HIC_OB && ichip > 7)
chipNum = ichip - 1;
else
chipNum = ichip;
WaferNumAndPos(hicType, children, chipNum, waferNum, waferPos);
Int_t code = (conds[icond]/10)*10; // We deliberately divide int's
Int_t vBB = conds[icond] - code;
bool nominal = (code == 100);
if(GetThresholdFileName(actlong, ichip, nominal, vBB, dataName, resultName)) {
condVB = conds[icond];
FillThreScanTree(ftree, eospath, dataName);
}
}
}
}
void ThresholdTuneAllChips(TTree *ftree, ActivityDB::activityLong actlong, const int hicid, const int actid, const string eospath, const THicType hicType, std::vector<TChild> children)
{
//
// Loops on chips and fills the tree for the threshold tuning
//
// Inputs:
// ftree : the tree to be filled
// actlong : the activityLong for which the analysis is done
// hicid : the HIC id
// actid : the activity id
// eospath : the input file path on EOS
// hicType : the HIC type (IB or OB)
// children: vector of all HIC children
//
// Outputs:
//
// Return:
//
// Created: 31 Jan 2019 Mario Sitta
// Updated: 26 Feb 2019 Mario Sitta HIC type added, bug fix in chip loop
// Updated: 10 Jul 2019 Mario Sitta Wafer number and chip position added
//
hicID = hicid;
actID = actid;
locID = actlong.Location.ID;
// Open Threshold Tune files and fill the tree
string dataName, resultName;
const int numchips = ((hicType == HIC_OB) ? NUMCHIPS+1 : NUMCHIPSIB);
for (int ichip = 0; ichip < numchips; ichip++) {
if(hicType == HIC_OB && ichip == 7) continue;
if(hicType == HIC_OB && ichip > 7)
chipNum = ichip - 1;
else
chipNum = ichip;
if(GetITHRTuneFileName(actlong, ichip, 0, dataName, resultName)) {
condVB = 100;
FillThreScanTree(ftree, eospath, dataName);
}
}
for (int ichip = 0; ichip < numchips; ichip++) {
if(hicType == HIC_OB && ichip == 7) continue;
if(hicType == HIC_OB && ichip > 7)
chipNum = ichip - 1;
else
chipNum = ichip;
if(GetVCASNTuneFileName(actlong, ichip, 0, dataName, resultName)) {
condVB = 200;
FillThreScanTree(ftree, eospath, dataName);
}
}
}
void ThresholdScanResults(TTree *ftree, ActivityDB::activityLong actlong, const int hicid, const int actid, const string eospath, const THicType hicType)
{
//
// Fills the tree for the given activity results
//
// Inputs:
// ftree : the tree to be filled
// actlong : the activityLong for which the analysis is done
// hicid : the HIC id
// actid : the activity id
// eospath : the input file path on EOS
// hicType : the HIC type (IB or OB)
//
// Outputs:
//
// Return:
//
// Created: 27 Jan 2019 Mario Sitta
// Updated: 26 Feb 2019 Mario Sitta HIC type added
//
hicID = hicid;
actID = actid;
locID = actlong.Location.ID;
startDate = (ulong)actlong.StartDate;
// Open Threshold Scan Result files and fill the tree
string dataName, resultName;
// Nominal thresholds, 0V BB
if(GetThresholdFileName(actlong, 0, true, 0, dataName, resultName)) {
condVB = 100;
FillThreScanTreeResult(ftree, eospath, resultName, actlong, hicType);
}
// Tuned thresholds, 0V BB
if(GetThresholdFileName(actlong, 0, false, 0, dataName, resultName)) {
condVB = 200;
FillThreScanTreeResult(ftree, eospath, resultName, actlong, hicType);
}
// Nominal thresholds, 3V BB
if(GetThresholdFileName(actlong, 0, true, 3, dataName, resultName)) {
condVB = 103;
FillThreScanTreeResult(ftree, eospath, resultName, actlong, hicType);
}
// Tuned thresholds, 3V BB
if(GetThresholdFileName(actlong, 0, false, 3, dataName, resultName)) {
condVB = 203;
FillThreScanTreeResult(ftree, eospath, resultName, actlong, hicType);
}
}
Bool_t FillThreScanTree(TTree *tree, string path, string file)
{
//
// Opens the Threshold_FitResults file and fills the tree
//
// Inputs:
// tree : the pointer to the tree to be filled
// path : the input file path
// file : the input file name
//
// Outputs:
//
// Return:
// true if the input file was read without error, otherwise false
//
// Created: 30 Jan 2019 Mario Sitta
// Updated: 27 Mar 2019 Mario Sitta Fix reading files with , insteda of .
//
FILE* infile;
string fullName;
Int_t row, column;
Float_t thresh, noise, chisq;
fullName = path + "/" + file;
infile = fopen(fullName.c_str(),"r");
if (!infile) {
printMessage("FillThreScanTree","Warning: cannot open input file",file.c_str());
return kFALSE;
}
char line[50];
// while(fscanf(infile, "%d %d %f %f %f", &column, &row, &thresh, &noise, &chisq) != EOF){
while(fgets(line, sizeof(line), infile)){
SanitizeThresScanInput(line);
sscanf(line, "%d %d %f %f %f", &column, &row, &thresh, &noise, &chisq);
rowNum = row;
colNum = column;
// thresValue = thresh;
// noiseValue = noise;
thresValue = (UShort_t)(thresh*100);
noiseValue = (UShort_t)(noise*100);
tree->Fill();
}
fclose(infile);
return kTRUE;
}
Bool_t FillThreScanTreeResult(TTree *tree, string path, string file, ActivityDB::activityLong actlong, const THicType hicType)
{
//
// Opens the ThresholdScanResult file and fills the tree
// (Implementation is a bit ugly since there are many formats
// with a different number of lines and often in different order)
//
// Inputs:
// tree : the pointer to the tree to be filled
// path : the input file path
// file : the input file name
// actlong : the activityLong for which the analysis is done
// hicType : the HIC type (IB or OB)
//
// Outputs:
//
// Return:
// true if the input file was read without error, otherwise false
//
// Created: 29 Jan 2019 Mario Sitta Modelled on Digital Scan routine
// Updated: 05 Feb 2019 Mario Sitta Bug fix in reading registers
// Updated: 26 Feb 2019 Mario Sitta HIC type added
//
FILE* infile;
string fullName;
float value, dummy;
unsigned int reg, regval;
int ichip, ivalue;
char *line = NULL;
size_t len = 0;
fullName = path + "/" + file;
infile = fopen(fullName.c_str(),"r");
if (!infile) {
printMessage("FillThreScanTreeResult","Warning: cannot open input file",file.c_str());
return kFALSE;
}
ResetThreScanTreeVariables();
for (int j=0; j<3; j++) // Skip first three lines
getline(&line, &len, infile);
// Scan the file, search for data
// (file format not unique, lines can be in any order)
bool chipResulFound = false, regStartFound = false, regEndFound = false;
while(getline(&line, &len, infile) > 0) {
if (strlen(line) < 2) continue; // Blank line
if (strstr(line,"Board registers")) break; // We've finished
if (strstr(line,"Number of chips")) {
chipResulFound = true;
continue;
}
if (strstr(line,"Chip registers (start)")) {
regStartFound = true;
regEndFound = false;
continue;
}
if (strstr(line,"Chip registers (end)")) {
regStartFound = false;
regEndFound = true;
continue;
}
if(regStartFound || regEndFound) goto chipRegisters; // OMG, a goto!!!
if(chipResulFound) goto singleChipResults; // OOMG, a second goto!!!
// General data
if (strstr(line,"VDDD (start)")) {
sscanf(line, "VDDD (start): %f", &vdddStart);
continue;
}
if (strstr(line,"VDDD (end)")) {
sscanf(line, "VDDD (end): %f", &vdddEnd);
continue;
}
if (strstr(line,"VDDA (start)")) {
sscanf(line, "VDDA (start): %f", &vddaStart);
continue;
}
if (strstr(line,"VDDA (end)")) {
sscanf(line, "VDDA (end): %f", &vddaEnd);
continue;
}
if (strstr(line,"VDDD set (start)")) {
sscanf(line, "VDDD set (start): %f", &vdddSetStart);
continue;
}
if (strstr(line,"VDDD set (end)")) {
sscanf(line, "VDDD set (end): %f", &vdddSetEnd);
continue;
}
if (strstr(line,"VDDA set (start)")) {
sscanf(line, "VDDA set (start): %f", &vddaSetStart);
continue;
}
if (strstr(line,"VDDA set (end)")) {
sscanf(line, "VDDA set (end): %f", &vddaSetEnd);
continue;
}
if (strstr(line,"IDDD (start)")) {
sscanf(line, "IDDD (start): %f", &idddStart);
continue;
}
if (strstr(line,"IDDD (end)")) {
sscanf(line, "IDDD (end): %f", &idddEnd);
continue;
}
if (strstr(line,"IDDA (start)")) {
sscanf(line, "IDDA (start): %f", &iddaStart);
continue;
}
if (strstr(line,"IDDA (end)")) {
sscanf(line, "IDDA (end): %f", &iddaEnd);
continue;
}
if (strstr(line,"Analogue Supply Voltage") && strstr(line,"start")) {
if (strstr(line,"on-chip"))
sscanf(line, "Analogue Supply Voltage (on-chip, start): %f", &anaSupVoltStart);
else
sscanf(line, "Analogue Supply Voltage (start): %f", &anaSupVoltStart);
continue;
}
if (strstr(line,"Analogue Supply Voltage") && strstr(line,"end")) {