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
|
/*
* \class EcalPerEvtLaserAnalyzer
*
* primary author: Julie Malcles - CEA/Saclay
* author: Gautier Hamel De Monchenault - CEA/Saclay
*/
#include "TFile.h"
#include "TTree.h"
#include "EcalPerEvtLaserAnalyzer.h"
#include <sstream>
#include <iomanip>
#include <ctime>
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEEGeom.h"
#include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEBGeom.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
#include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
#include "CalibCalorimetry/EcalLaserAnalyzer/interface/TPNFit.h"
#include "CalibCalorimetry/EcalLaserAnalyzer/interface/PulseFitWithFunction.h"
using namespace std;
//========================================================================
EcalPerEvtLaserAnalyzer::EcalPerEvtLaserAnalyzer(const edm::ParameterSet& iConfig)
//========================================================================
: iEvent(0),
eventHeaderCollection_(iConfig.getParameter<std::string>("eventHeaderCollection")),
eventHeaderProducer_(iConfig.getParameter<std::string>("eventHeaderProducer")),
digiCollection_(iConfig.getParameter<std::string>("digiCollection")),
digiProducer_(iConfig.getParameter<std::string>("digiProducer")),
digiPNCollection_(iConfig.getParameter<std::string>("digiPNCollection")),
rawDataToken_(consumes<EcalRawDataCollection>(edm::InputTag(eventHeaderProducer_, eventHeaderCollection_))),
pnDiodeDigiToken_(consumes<EcalPnDiodeDigiCollection>(edm::InputTag(digiProducer_, digiPNCollection_))),
mappingToken_(esConsumes()),
// framework parameters with default values
_nsamples(iConfig.getUntrackedParameter<unsigned int>("nSamples", 10)),
_presample(iConfig.getUntrackedParameter<unsigned int>("nPresamples", 3)),
_firstsample(iConfig.getUntrackedParameter<unsigned int>("firstSample", 1)),
_lastsample(iConfig.getUntrackedParameter<unsigned int>("lastSample", 2)),
_nsamplesPN(iConfig.getUntrackedParameter<unsigned int>("nSamplesPN", 50)),
_presamplePN(iConfig.getUntrackedParameter<unsigned int>("nPresamplesPN", 6)),
_firstsamplePN(iConfig.getUntrackedParameter<unsigned int>("firstSamplePN", 7)),
_lastsamplePN(iConfig.getUntrackedParameter<unsigned int>("lastSamplePN", 8)),
_timingcutlow(iConfig.getUntrackedParameter<unsigned int>("timingCutLow", 3)),
_timingcuthigh(iConfig.getUntrackedParameter<unsigned int>("timingCutHigh", 7)),
_niter(iConfig.getUntrackedParameter<unsigned int>("nIter", 3)),
_fedid(iConfig.getUntrackedParameter<unsigned int>("fedID", 0)),
_tower(iConfig.getUntrackedParameter<unsigned int>("tower", 1)),
_channel(iConfig.getUntrackedParameter<unsigned int>("channel", 1)),
_ecalPart(iConfig.getUntrackedParameter<std::string>("ecalPart", "EB")),
resdir_(iConfig.getUntrackedParameter<std::string>("resDir")),
refalphabeta_(iConfig.getUntrackedParameter<std::string>("refAlphaBeta")),
nCrys(NCRYSEB),
IsFileCreated(0),
runType(-1),
runNum(0),
dccID(-1),
lightside(2),
doesRefFileExist(0),
ttMat(-1),
peakMat(-1),
peak(-1),
evtMat(-1),
colMat(-1)
//========================================================================
{
if (_ecalPart == "EB") {
ebDigiToken_ = consumes<EBDigiCollection>(edm::InputTag(digiProducer_, digiCollection_));
} else if (_ecalPart == "EE") {
eeDigiToken_ = consumes<EEDigiCollection>(edm::InputTag(digiProducer_, digiCollection_));
}
// Define geometrical constants
//
if (_ecalPart == "EB") {
nCrys = NCRYSEB;
} else {
nCrys = NCRYSEE;
}
}
//========================================================================
EcalPerEvtLaserAnalyzer::~EcalPerEvtLaserAnalyzer() {
//========================================================================
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
}
//========================================================================
void EcalPerEvtLaserAnalyzer::beginJob() {
//========================================================================
// Define temporary files' names
stringstream namefile1;
namefile1 << resdir_ << "/ADCSamples.root";
ADCfile = namefile1.str();
// Create temporary file and trees to save adc samples
ADCFile = new TFile(ADCfile.c_str(), "RECREATE");
stringstream name;
name << "ADCTree";
ADCtrees = new TTree(name.str().c_str(), name.str().c_str());
ADCtrees->Branch("iphi", &phi, "phi/I");
ADCtrees->Branch("ieta", &eta, "eta/I");
ADCtrees->Branch("dccID", &dccID, "dccID/I");
ADCtrees->Branch("event", &event, "event/I");
ADCtrees->Branch("color", &color, "color/I");
ADCtrees->Branch("adc", &adc, "adc[10]/D");
ADCtrees->Branch("ttrigMatacq", &ttrig, "ttrig/D");
ADCtrees->Branch("peakMatacq", &peak, "peak/D");
ADCtrees->Branch("pn0", &pn0, "pn0/D");
ADCtrees->Branch("pn1", &pn1, "pn1/D");
ADCtrees->SetBranchAddress("ieta", &eta);
ADCtrees->SetBranchAddress("iphi", &phi);
ADCtrees->SetBranchAddress("dccID", &dccID);
ADCtrees->SetBranchAddress("event", &event);
ADCtrees->SetBranchAddress("color", &color);
ADCtrees->SetBranchAddress("adc", adc);
ADCtrees->SetBranchAddress("ttrigMatacq", &ttrig);
ADCtrees->SetBranchAddress("peakMatacq", &peak);
ADCtrees->SetBranchAddress("pn0", &pn0);
ADCtrees->SetBranchAddress("pn1", &pn1);
IsFileCreated = 0;
}
//========================================================================
void EcalPerEvtLaserAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& c) {
//========================================================================
++iEvent;
// retrieving DCC header
edm::Handle<EcalRawDataCollection> pDCCHeader;
const EcalRawDataCollection* DCCHeader = nullptr;
e.getByToken(rawDataToken_, pDCCHeader);
if (!pDCCHeader.isValid()) {
edm::LogError("nodata") << "Error! can't get the product retrieving DCC header" << eventHeaderCollection_.c_str();
} else {
DCCHeader = pDCCHeader.product();
}
// retrieving crystal data from Event
edm::Handle<EBDigiCollection> pEBDigi;
const EBDigiCollection* EBDigi = nullptr;
edm::Handle<EEDigiCollection> pEEDigi;
const EEDigiCollection* EEDigi = nullptr;
if (_ecalPart == "EB") {
e.getByToken(ebDigiToken_, pEBDigi);
if (!pEBDigi.isValid()) {
edm::LogError("nodata") << "Error! can't get the product retrieving EB crystal data " << digiCollection_.c_str();
} else {
EBDigi = pEBDigi.product();
}
} else {
e.getByToken(eeDigiToken_, pEEDigi);
if (!pEEDigi.isValid()) {
edm::LogError("nodata") << "Error! can't get the product retrieving EE crystal data " << digiCollection_.c_str();
} else {
EEDigi = pEEDigi.product();
}
}
// retrieving crystal PN diodes from Event
edm::Handle<EcalPnDiodeDigiCollection> pPNDigi;
const EcalPnDiodeDigiCollection* PNDigi = nullptr;
e.getByToken(pnDiodeDigiToken_, pPNDigi);
if (!pPNDigi.isValid()) {
edm::LogError("nodata") << "Error! can't get the product " << digiPNCollection_.c_str();
} else {
PNDigi = pPNDigi.product();
}
// retrieving electronics mapping
const auto& TheMapping = c.getData(mappingToken_);
// ====================================
// Decode Basic DCCHeader Information
// ====================================
for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
++headerItr) {
// Get run type and run number
int fed = headerItr->fedId();
if (fed != _fedid && _fedid != -999)
continue;
runType = headerItr->getRunType();
runNum = headerItr->getRunNumber();
event = headerItr->getLV1();
dccID = headerItr->getDccInTCCCommand();
fedID = headerItr->fedId();
// take event only if the fed corresponds to the DCC in TCC
if (600 + dccID != fedID)
continue;
// Cut on runType
if (runType != EcalDCCHeaderBlock::LASER_STD && runType != EcalDCCHeaderBlock::LASER_GAP)
return;
// Define output results files' names
if (IsFileCreated == 0) {
stringstream namefile2;
namefile2 << resdir_ << "/APDAmpl_Run" << runNum << "_" << _fedid << "_" << _tower << "_" << _channel << ".root";
resfile = namefile2.str();
// Get Matacq ttrig
stringstream namefile;
namefile << resdir_ << "/Matacq-Run" << runNum << ".root";
doesRefFileExist = 0;
FILE* test;
test = fopen(namefile.str().c_str(), "r");
if (test)
doesRefFileExist = 1;
if (doesRefFileExist == 1) {
matacqFile = new TFile((namefile.str().c_str()));
matacqTree = (TTree*)matacqFile->Get("MatacqShape");
matacqTree->SetBranchAddress("event", &evtMat);
matacqTree->SetBranchAddress("color", &colMat);
matacqTree->SetBranchAddress("peak", &peakMat);
matacqTree->SetBranchAddress("ttrig", &ttMat);
}
IsFileCreated = 1;
}
// Retrieve laser color and event number
EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
int color = settings.wavelength;
vector<int>::iterator iter = find(colors.begin(), colors.end(), color);
if (iter == colors.end()) {
colors.push_back(color);
edm::LogVerbatim("EcalPerEvtLaserAnalyzer") << " new color found " << color << " " << colors.size();
}
}
// cut on fedID
if (fedID != _fedid && _fedid != -999)
return;
// ======================
// Decode PN Information
// ======================
TPNFit* pnfit = new TPNFit();
pnfit->init(_nsamplesPN, _firstsamplePN, _lastsamplePN);
double chi2pn = 0;
double ypnrange[50];
double dsum = 0.;
double dsum1 = 0.;
double bl = 0.;
double bl1 = 0.;
double val_max = 0.;
unsigned int samplemax = 0;
unsigned int k;
std::vector<double> allPNAmpl;
for (EcalPnDiodeDigiCollection::const_iterator pnItr = PNDigi->begin(); pnItr != PNDigi->end();
++pnItr) { // Loop on PNs
for (int samId = 0; samId < (*pnItr).size(); samId++) { // Loop on PN samples
pn[samId] = (*pnItr).sample(samId).adc();
}
for (dsum = 0., k = 0; k < _presamplePN; k++) {
dsum += pn[k];
}
bl = dsum / ((double)_presamplePN);
for (val_max = 0., k = 0; k < _nsamplesPN; k++) {
ypnrange[k] = pn[k] - bl;
if (ypnrange[k] > val_max) {
val_max = ypnrange[k];
samplemax = k;
}
}
chi2pn = pnfit->doFit(samplemax, &ypnrange[0]);
if (chi2pn == 101 || chi2pn == 102 || chi2pn == 103)
pnAmpl = 0.;
else
pnAmpl = pnfit->getAmpl();
allPNAmpl.push_back(pnAmpl);
}
// ===========
// Get Matacq
// ===========
ttrig = -1.;
peak = -1.;
if (doesRefFileExist == 1) {
// FIXME
if (color == 0)
matacqTree->GetEntry(event - 1);
else if (color == 3)
matacqTree->GetEntry(matacqTree->GetEntries("color==0") + event - 1);
ttrig = ttMat;
peak = peakMat;
}
// ===========================
// Decode EBDigis Information
// ===========================
double yrange[10];
int adcGain = 0;
int side = 0;
if (EBDigi) {
for (EBDigiCollection::const_iterator digiItr = EBDigi->begin(); digiItr != EBDigi->end();
++digiItr) { // Loop on crystals
EBDetId id_crystal(digiItr->id());
EBDataFrame df(*digiItr);
int etaG = id_crystal.ieta(); // global
int phiG = id_crystal.iphi(); // global
int etaL; // local
int phiL; // local
std::pair<int, int> LocalCoord = MEEBGeom::localCoord(etaG, phiG);
etaL = LocalCoord.first;
phiL = LocalCoord.second;
eta = etaG;
phi = phiG;
side = MEEBGeom::side(etaG, phiG);
EcalElectronicsId elecid_crystal = TheMapping.getElectronicsId(id_crystal);
int towerID = elecid_crystal.towerId();
// int channelID=elecid_crystal.channelId()-1; // FIXME so far for endcap only
int strip = elecid_crystal.stripId();
int xtal = elecid_crystal.xtalId();
int channelID = 5 * (strip - 1) + xtal - 1; // FIXME
int module = MEEBGeom::lmmod(etaG, phiG);
std::pair<int, int> pnpair = MEEBGeom::pn(module);
unsigned int MyPn0 = pnpair.first;
unsigned int MyPn1 = pnpair.second;
unsigned int channel = MEEBGeom::electronic_channel(etaL, phiL);
assert(channel < nCrys);
double adcmax = 0.0;
if (towerID != int(_tower) || channelID != int(_channel) || dccID != int(_fedid - 600))
continue;
else
channelNumber = channel;
for (unsigned int i = 0; i < (*digiItr).size(); ++i) { // Loop on adc samples
EcalMGPASample samp_crystal(df.sample(i));
adc[i] = samp_crystal.adc();
adcG[i] = samp_crystal.gainId();
if (i == 0)
adcGain = adcG[i];
if (i > 0)
adcGain = TMath::Max(adcG[i], adcGain);
if (adc[i] > adcmax) {
adcmax = adc[i];
}
}
for (dsum = 0., dsum1 = 0., k = 0; k < _presample; k++) {
dsum += adc[k];
if (k < _presample - 1)
dsum1 += adc[k];
}
bl = dsum / ((double)_presample);
bl1 = dsum1 / ((double)_presample - 1);
for (val_max = 0., k = 0; k < _nsamples; k++) {
yrange[k] = adc[k] - bl;
if (yrange[k] > val_max) {
val_max = yrange[k];
samplemax = k;
}
}
if (samplemax == 4 || samplemax == 5) {
for (k = 0; k < _nsamples; k++) {
yrange[k] = yrange[k] + bl - bl1;
}
}
for (unsigned int k = 0; k < _nsamples; k++) {
adc[k] = yrange[k];
}
pn0 = allPNAmpl[MyPn0];
pn1 = allPNAmpl[MyPn1];
if (samplemax >= _timingcutlow && samplemax <= _timingcuthigh && lightside == side)
ADCtrees->Fill();
}
} else {
for (EEDigiCollection::const_iterator digiItr = EEDigi->begin(); digiItr != EEDigi->end();
++digiItr) { // Loop on crystals
EEDetId id_crystal(digiItr->id());
EEDataFrame df(*digiItr);
phi = id_crystal.ix() - 1;
eta = id_crystal.iy() - 1;
side = 0; // FIXME
// Recover the TT id and the electronic crystal numbering from EcalElectronicsMapping
EcalElectronicsId elecid_crystal = TheMapping.getElectronicsId(id_crystal);
int towerID = elecid_crystal.towerId();
int channelID = elecid_crystal.channelId() - 1;
int module = MEEEGeom::lmmod(phi, eta);
std::pair<int, int> pnpair = MEEEGeom::pn(module, _fedid);
unsigned int MyPn0 = pnpair.first;
unsigned int MyPn1 = pnpair.second;
unsigned int channel = MEEEGeom::crystal(phi, eta);
assert(channel < nCrys);
double adcmax = 0.0;
if (towerID != int(_tower) || channelID != int(_channel) || dccID != int(_fedid - 600))
continue;
else
channelNumber = channel;
for (unsigned int i = 0; i < (*digiItr).size(); ++i) { // Loop on adc samples
EcalMGPASample samp_crystal(df.sample(i));
adc[i] = samp_crystal.adc();
adcG[i] = samp_crystal.gainId();
if (i == 0)
adcGain = adcG[i];
if (i > 0)
adcGain = TMath::Max(adcG[i], adcGain);
if (adc[i] > adcmax) {
adcmax = adc[i];
}
}
for (dsum = 0., dsum1 = 0., k = 0; k < _presample; k++) {
dsum += adc[k];
if (k < _presample - 1)
dsum1 += adc[k];
}
bl = dsum / ((double)_presample);
bl1 = dsum1 / ((double)_presample - 1);
for (val_max = 0., k = 0; k < _nsamples; k++) {
yrange[k] = adc[k] - bl;
if (yrange[k] > val_max) {
val_max = yrange[k];
samplemax = k;
}
}
if (samplemax == 4 || samplemax == 5) {
for (k = 0; k < _nsamples; k++) {
yrange[k] = yrange[k] + bl - bl1;
}
}
for (unsigned int k = 0; k < _nsamples; k++) {
adc[k] = yrange[k];
}
pn0 = allPNAmpl[MyPn0];
pn1 = allPNAmpl[MyPn1];
if (samplemax >= _timingcutlow && samplemax <= _timingcuthigh && lightside == side)
ADCtrees->Fill();
}
}
} // analyze
//========================================================================
void EcalPerEvtLaserAnalyzer::endJob() {
//========================================================================
assert(colors.size() <= nColor);
unsigned int nCol = colors.size();
ADCtrees->Write();
edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
<< "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
<< "\t+=+ Analyzing laser data: getting per event +=+";
edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
<< "\t+=+ APD Amplitudes and ADC samples +=+";
edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
<< "\t+=+ for fed:" << _fedid << ", tower:" << _tower << ", and channel:" << _channel;
// Define temporary tree to save APD amplitudes
APDFile = new TFile(resfile.c_str(), "RECREATE");
int ieta, iphi, channelID, towerID, flag;
double alpha, beta;
colors.push_back(color);
for (unsigned int i = 0; i < nCol; i++) {
stringstream name1;
name1 << "headerCol" << colors[i];
header[i] = new TTree(name1.str().c_str(), name1.str().c_str());
header[i]->Branch("alpha", &alpha, "alpha/D");
header[i]->Branch("beta", &beta, "beta/D");
header[i]->Branch("iphi", &iphi, "iphi/I");
header[i]->Branch("ieta", &ieta, "ieta/I");
header[i]->Branch("dccID", &dccID, "dccID/I");
header[i]->Branch("towerID", &towerID, "towerID/I");
header[i]->Branch("channelID", &channelID, "channelID/I");
header[i]->SetBranchAddress("alpha", &alpha);
header[i]->SetBranchAddress("beta", &beta);
header[i]->SetBranchAddress("iphi", &iphi);
header[i]->SetBranchAddress("ieta", &ieta);
header[i]->SetBranchAddress("dccID", &dccID);
header[i]->SetBranchAddress("towerID", &towerID);
header[i]->SetBranchAddress("channelID", &channelID);
}
stringstream name2;
name2 << "APDTree";
APDtrees = new TTree(name2.str().c_str(), name2.str().c_str());
//List of branches
APDtrees->Branch("event", &event, "event/I");
APDtrees->Branch("color", &color, "color/I");
APDtrees->Branch("adc", &adc, "adc[10]/D");
APDtrees->Branch("peakMatacq", &peak, "peak/D");
APDtrees->Branch("ttrigMatacq", &ttrig, "ttrig/D");
APDtrees->Branch("apdAmpl", &apdAmpl, "apdAmpl/D");
APDtrees->Branch("apdTime", &apdTime, "apdTime/D");
APDtrees->Branch("flag", &flag, "flag/I");
APDtrees->Branch("pn0", &pn0, "pn0/D");
APDtrees->Branch("pn1", &pn1, "pn1/D");
APDtrees->SetBranchAddress("event", &event);
APDtrees->SetBranchAddress("color", &color);
APDtrees->SetBranchAddress("adc", adc);
APDtrees->SetBranchAddress("peakMatacq", &peak);
APDtrees->SetBranchAddress("ttrigMatacq", &ttrig);
APDtrees->SetBranchAddress("apdAmpl", &apdAmpl);
APDtrees->SetBranchAddress("apdTime", &apdTime);
APDtrees->SetBranchAddress("flag", &flag);
APDtrees->SetBranchAddress("pn0", &pn0);
APDtrees->SetBranchAddress("pn1", &pn1);
// Retrieve alpha and beta for APD amplitudes calculation
TFile* alphaFile = new TFile(refalphabeta_.c_str());
TTree* alphaTree[2];
Double_t alphaRun, betaRun;
int ietaRun, iphiRun, channelIDRun, towerIDRun, dccIDRun, flagRun;
for (unsigned int i = 0; i < nCol; i++) {
stringstream name3;
name3 << "ABCol" << i;
alphaTree[i] = (TTree*)alphaFile->Get(name3.str().c_str());
alphaTree[i]->SetBranchStatus("*", false);
alphaTree[i]->SetBranchStatus("alpha", true);
alphaTree[i]->SetBranchStatus("beta", true);
alphaTree[i]->SetBranchStatus("iphi", true);
alphaTree[i]->SetBranchStatus("ieta", true);
alphaTree[i]->SetBranchStatus("dccID", true);
alphaTree[i]->SetBranchStatus("towerID", true);
alphaTree[i]->SetBranchStatus("channelID", true);
alphaTree[i]->SetBranchStatus("flag", true);
alphaTree[i]->SetBranchAddress("alpha", &alphaRun);
alphaTree[i]->SetBranchAddress("beta", &betaRun);
alphaTree[i]->SetBranchAddress("iphi", &iphiRun);
alphaTree[i]->SetBranchAddress("ieta", &ietaRun);
alphaTree[i]->SetBranchAddress("dccID", &dccIDRun);
alphaTree[i]->SetBranchAddress("towerID", &towerIDRun);
alphaTree[i]->SetBranchAddress("channelID", &channelIDRun);
alphaTree[i]->SetBranchAddress("flag", &flagRun);
}
PulseFitWithFunction* pslsfit = new PulseFitWithFunction();
double chi2;
for (unsigned int icol = 0; icol < nCol; icol++) {
IsThereDataADC[icol] = 1;
stringstream cut;
cut << "color==" << colors.at(icol);
if (ADCtrees->GetEntries(cut.str().c_str()) < 10)
IsThereDataADC[icol] = 0;
IsHeaderFilled[icol] = 0;
}
// Define submodule and channel number inside the submodule (as Patrice)
for (Long64_t jentry = 0; jentry < ADCtrees->GetEntriesFast(); jentry++) { // Loop on events
ADCtrees->GetEntry(jentry);
int iCry = channelNumber;
// get back color
unsigned int iCol = 0;
for (unsigned int i = 0; i < nCol; i++) {
if (color == colors[i]) {
iCol = i;
i = colors.size();
}
}
alphaTree[iCol]->GetEntry(iCry);
flag = flagRun;
iphi = iphiRun;
ieta = ietaRun;
towerID = towerIDRun;
channelID = channelIDRun;
alpha = alphaRun;
beta = betaRun;
if (IsHeaderFilled[iCol] == 0) {
header[iCol]->Fill();
IsHeaderFilled[iCol] = 1;
}
// Amplitude calculation
apdAmpl = 0;
apdTime = 0;
pslsfit->init(_nsamples, _firstsample, _lastsample, _niter, alphaRun, betaRun);
chi2 = pslsfit->doFit(&adc[0]);
if (chi2 < 0. || chi2 == 102 || chi2 == 101) {
apdAmpl = 0;
apdTime = 0;
} else {
apdAmpl = pslsfit->getAmpl();
apdTime = pslsfit->getTime();
}
APDtrees->Fill();
}
alphaFile->Close();
ADCFile->Close();
APDFile->Write();
APDFile->Close();
// Remove unwanted files
stringstream del;
del << "rm " << ADCfile;
system(del.str().c_str());
edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
<< "\t+=+ .................................................. done +=+";
edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
<< "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
}
DEFINE_FWK_MODULE(EcalPerEvtLaserAnalyzer);
|