forked from eutelescope/eutelescope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEUTelCalibrateEventProcessor.cc
710 lines (569 loc) · 31.6 KB
/
EUTelCalibrateEventProcessor.cc
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
// Author Antonio Bulgheroni, INFN <mailto:antonio.bulgheroni@gmail.com>
// Version $Id$
/*
* This source code is part of the Eutelescope package of Marlin.
* You are free to use this source files for your own development as
* long as it stays in a public research context. You are not
* allowed to use it for commercial purpose. You must put this
* header with author names in all development based on this file.
*
*/
// eutelescope includes ".h"
#include "EUTELESCOPE.h"
#include "EUTelExceptions.h"
#include "EUTelCalibrateEventProcessor.h"
#include "EUTelRunHeaderImpl.h"
#include "EUTelEventImpl.h"
#include "EUTelHistogramManager.h"
// marlin includes ".h"
#include "marlin/Processor.h"
#include "marlin/Exceptions.h"
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
// aida includes <.h>
#include <marlin/AIDAProcessor.h>
#include <AIDA/IHistogramFactory.h>
#include <AIDA/IHistogram1D.h>
#include <AIDA/ITree.h>
#endif
// lcio includes <.h>
#include <IMPL/TrackerRawDataImpl.h>
#include <IMPL/TrackerDataImpl.h>
#include <IMPL/LCCollectionVec.h>
#include <UTIL/CellIDDecoder.h>
#include <UTIL/CellIDEncoder.h>
// system includes <>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <memory>
using namespace std;
using namespace lcio;
using namespace marlin;
using namespace eutelescope;
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
string EUTelCalibrateEventProcessor::_rawDataDistHistoName = "RawDataDistHisto";
string EUTelCalibrateEventProcessor::_dataDistHistoName = "DataDistHisto";
string EUTelCalibrateEventProcessor::_commonModeDistHistoName = "CommonModeDistHisto";
string EUTelCalibrateEventProcessor::_skippedRowDistHistoName = "SkippedRowDistHisto";
string EUTelCalibrateEventProcessor::_skippedPixelDistHistoName = "SkippedPixelDistHisto";
string EUTelCalibrateEventProcessor::_skippedPixelPerRowDistHistoName = "SkippedPixelPerRowDistHisto";
#endif
const unsigned short EUTelCalibrateEventProcessor::_maxNoOfConsecutiveMissing = 10;
EUTelCalibrateEventProcessor::EUTelCalibrateEventProcessor () :Processor("EUTelCalibrateEventProcessor") {
// modify processor description
_description =
"EUTelCalibrateEventProcessor subtracts the pedestal value from the input data";
// first of all we need to register the input collection
registerInputCollection (LCIO::TRACKERRAWDATA, "RawDataCollectionName",
"Input raw data collection",
_rawDataCollectionName, string ("rawdata"));
registerInputCollection (LCIO::TRACKERDATA, "PedestalCollectionName",
"Pedestal from the condition file",
_pedestalCollectionName, string ("pedestal"));
registerInputCollection (LCIO::TRACKERDATA, "NoiseCollectionName",
"Noise from the condition file",
_noiseCollectionName, string("noise"));
registerInputCollection (LCIO::TRACKERRAWDATA, "StatusCollectionName",
"Pixel status from the condition file",
_statusCollectionName, string("status"));
registerOutputCollection (LCIO::TRACKERDATA, "CalibratedDataCollectionName",
"Name of the output calibrated data collection",
_calibratedDataCollectionName, string("data"));
// now the optional parameters
registerProcessorParameter ("DebugHistoFilling",
"Flag to switch on (1) or off (0) the detector debug histogram filling",
_fillDebugHisto, static_cast<bool> (false));
registerProcessorParameter ("PerformCommonMode",
"Flag to switch on the common mode suppression algorithm. 0 -> off, 1 -> full frame, 2 -> row wise",
_doCommonMode, static_cast<int> (1));
registerProcessorParameter ("HitRejectionCut",
"Threshold of pixel SNR for hit rejection",
_hitRejectionCut, static_cast<float> (3.5));
registerProcessorParameter ("MaxNoOfRejectedPixels",
"Maximum allowed number of rejected pixel per event",
_maxNoOfRejectedPixels, static_cast<int> (3000));
registerProcessorParameter("MaxNoOfRejectedPixelPerRow",
"Maximum allowed number of rejected pixels per row (only with RowWise)",
_maxNoOfRejectedPixelPerRow,
static_cast < int > (25) );
registerProcessorParameter("MaxNoOfSkippedRow",
"Maximum allowed number of skipped rows (only with RowWise)",
_maxNoOfSkippedRow,
static_cast< int > ( 15 ) );
registerProcessorParameter("HistoInfoFileName", "This is the name of the histogram information file",
_histoInfoFileName, string( "histoinfo.xml" ) );
}
void EUTelCalibrateEventProcessor::init () {
// this method is called only once even when the rewind is active
// usually a good idea to
printParameters ();
if ( _fillDebugHisto == 1 ) {
streamlog_out( WARNING2 ) << "Filling debug histograms is slowing down the procedure" << endl;
}
// set to zero the run counter
_iRun = 0;
_isGeometryReady = false;
// reset the number of consecutive missing events
_noOfConsecutiveMissing = 0;
}
void EUTelCalibrateEventProcessor::processRunHeader (LCRunHeader * rdr) {
auto_ptr<EUTelRunHeaderImpl> runHeader( new EUTelRunHeaderImpl( rdr ) );
runHeader->addProcessor( type());
// increment the run counter
++_iRun;
}
void EUTelCalibrateEventProcessor::initializeGeometry(LCEvent * event) throw ( marlin::SkipEventException ) {
// now I need the _ancillaryIndexMap. For this I need to take the
// pedestal input collection
try {
LCCollectionVec * pedestalCol = dynamic_cast< LCCollectionVec * > ( event->getCollection( _pedestalCollectionName ) );
CellIDDecoder< TrackerDataImpl > pedestalDecoder( pedestalCol ) ;
for ( size_t iDetector = 0; iDetector < pedestalCol->size(); ++iDetector ) {
TrackerDataImpl * pedestal = dynamic_cast< TrackerDataImpl * > ( pedestalCol->getElementAt( iDetector ) ) ;
int sensorID = pedestalDecoder( pedestal )["sensorID"];
_ancillaryIndexMap.insert( make_pair( sensorID, iDetector ) );
unsigned int noOfPixel = ( pedestalDecoder( pedestal )["xMax"] - pedestalDecoder( pedestal )["xMin"] + 1 ) *
( pedestalDecoder( pedestal )["yMax"] - pedestalDecoder( pedestal )["yMin"] + 1 );
_noOfPixelMap.insert( make_pair( sensorID, noOfPixel ) );
unsigned int noOfPixelPerRow = ( pedestalDecoder( pedestal )["xMax"] - pedestalDecoder( pedestal )["xMin"] + 1 );
_noOfPixelPerRowMap.insert( make_pair ( sensorID, noOfPixelPerRow ));
unsigned int noOfRow = ( pedestalDecoder( pedestal )["yMax"] - pedestalDecoder( pedestal )["yMin"] + 1 );
_noOfRowMap.insert( make_pair( sensorID, noOfRow ) );
}
} catch ( lcio::DataNotAvailableException ) {
streamlog_out( WARNING2 ) << "Unable to initialize the geometry with the current event. Trying with the next one" << endl;
_isGeometryReady = false;
throw SkipEventException( this ) ;
}
_isGeometryReady = true;
}
void EUTelCalibrateEventProcessor::processEvent (LCEvent * event) {
if ( !_isGeometryReady ) {
initializeGeometry( event ) ;
}
EUTelEventImpl * evt = static_cast<EUTelEventImpl*> (event);
if ( evt->getEventType() == kEORE ) {
streamlog_out ( DEBUG4 ) << "EORE found: nothing else to do." << endl;
return;
} else if ( evt->getEventType() == kUNKNOWN ) {
streamlog_out ( WARNING2 ) << "Event number " << evt->getEventNumber() << " in run " << evt->getRunNumber()
<< " is of unknown type. Continue considering it as a normal Data Event." << endl;
}
try {
LCCollectionVec * inputCollectionVec = dynamic_cast < LCCollectionVec * > (evt->getCollection(_rawDataCollectionName));
LCCollectionVec * pedestalCollectionVec = dynamic_cast < LCCollectionVec * > (evt->getCollection(_pedestalCollectionName));
LCCollectionVec * noiseCollectionVec = dynamic_cast < LCCollectionVec * > (evt->getCollection(_noiseCollectionName));
LCCollectionVec * statusCollectionVec = dynamic_cast < LCCollectionVec * > (evt->getCollection(_statusCollectionName));
CellIDDecoder<TrackerRawDataImpl> cellDecoder( inputCollectionVec );
// reset the number of consecutive missing
_noOfConsecutiveMissing = 0;
if (isFirstEvent()) {
// since v00-00-09 the consistency check between input
// collection size and ancillary one has been removed.
for (unsigned int iDetector = 0; iDetector < inputCollectionVec->size(); iDetector++) {
TrackerRawDataImpl * rawData = dynamic_cast < TrackerRawDataImpl * >(inputCollectionVec->getElementAt(iDetector));
int sensorID = cellDecoder(rawData)["sensorID"];
// To get the proper pedestal collection I need to go through
// the _ancillaryIndexMap. This takes the sensorID as input and
// gets the position in the collection as output
TrackerDataImpl * pedestal = dynamic_cast < TrackerDataImpl * > (pedestalCollectionVec->getElementAt( _ancillaryIndexMap[ sensorID ] ));
if (rawData->getADCValues().size() != pedestal->getChargeValues().size()){
stringstream ss;
ss << "Input data and pedestal are incompatible\n"
<< "Detector " << sensorID << " has " << rawData->getADCValues().size() << " pixels in the input data \n"
<< "while " << pedestal->getChargeValues().size() << " in the pedestal data " << endl;
throw IncompatibleDataSetException(ss.str());
}
// in the case MARLIN_USE_AIDA and the user wants to fill detector
// debug histogram, this is the right place to book them. As usual
// histograms are grouped in directory identifying the detector
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
string basePath, tempHistoName;
basePath = "detector_" + to_string( sensorID ) + "/";
// prepare the histogram manager
auto_ptr<EUTelHistogramManager> histoMgr( new EUTelHistogramManager( _histoInfoFileName ));
EUTelHistogramInfo * histoInfo;
bool isHistoManagerAvailable;
try {
isHistoManagerAvailable = histoMgr->init();
} catch ( ios::failure& e) {
streamlog_out ( ERROR1 ) << "I/O problem with " << _histoInfoFileName << "\n"
<< "Continuing without histogram manager" << endl;
isHistoManagerAvailable = false;
} catch ( ParseException& e ) {
streamlog_out ( ERROR1 ) << e.what() << "\n"
<< "Continuing without histogram manager" << endl;
isHistoManagerAvailable = false;
}
if ( ( _fillDebugHisto == 1 ) ||
( _doCommonMode == 1 ) ||
( _doCommonMode == 2 ) ) {
// it was changed from mkdir to mkdirs to be sure all
// intermediate folders were properly created, but then I had
// to come back to mkdir because this is the only supported in RAIDA.
AIDAProcessor::tree(this)->mkdir(basePath.c_str());
}
if (_fillDebugHisto == 1) {
// book the raw data histogram
tempHistoName = _rawDataDistHistoName + "_d" + to_string( sensorID ) ;
int rawDataDistHistoNBin = 4096;
double rawDataDistHistoMin = -2048.5;
double rawDataDistHistoMax = rawDataDistHistoMin + rawDataDistHistoNBin;
string rawDataDistTitle = "Raw data distribution";
if ( isHistoManagerAvailable ) {
histoInfo = histoMgr->getHistogramInfo(_rawDataDistHistoName);
if ( histoInfo ) {
streamlog_out ( DEBUG2 ) << (* histoInfo ) << endl;
rawDataDistHistoNBin = histoInfo->_xBin;
rawDataDistHistoMin = histoInfo->_xMin;
rawDataDistHistoMax = histoInfo->_xMax;
if ( histoInfo->_title != "" ) rawDataDistTitle = histoInfo->_title;
}
}
AIDA::IHistogram1D * rawDataDistHisto =
AIDAProcessor::histogramFactory(this)->createHistogram1D( (basePath + tempHistoName).c_str(),
rawDataDistHistoNBin, rawDataDistHistoMin, rawDataDistHistoMax);
if ( rawDataDistHisto ) {
_aidaHistoMap.insert(make_pair(tempHistoName, rawDataDistHisto));
rawDataDistHisto->setTitle(rawDataDistTitle.c_str());
} else {
streamlog_out ( ERROR1 ) << "Problem booking the " << (basePath + tempHistoName) << ".\n"
<< "Very likely a problem with path name. Switching off histogramming and continue w/o" << endl;
_fillDebugHisto = 0;
}
// book the pedestal corrected data histogram
tempHistoName = _dataDistHistoName + "_d" + to_string( sensorID );
int dataDistHistoNBin = 5000;
double dataDistHistoMin = -500.;
double dataDistHistoMax = 500.;
string dataDistTitle = "Data (pedestal sub'ed) distribution";
if ( isHistoManagerAvailable ) {
histoInfo = histoMgr->getHistogramInfo(_dataDistHistoName);
if ( histoInfo ) {
streamlog_out ( DEBUG2 ) << (* histoInfo ) << endl;
dataDistHistoNBin = histoInfo->_xBin;
dataDistHistoMin = histoInfo->_xMin;
dataDistHistoMax = histoInfo->_xMax;
if ( histoInfo->_title != "" ) dataDistTitle = histoInfo->_title;
}
}
AIDA::IHistogram1D * dataDistHisto =
AIDAProcessor::histogramFactory(this)->createHistogram1D( (basePath + tempHistoName).c_str(),
dataDistHistoNBin, dataDistHistoMin, dataDistHistoMax);
if ( dataDistHisto ) {
_aidaHistoMap.insert(make_pair(tempHistoName, dataDistHisto));
dataDistHisto->setTitle(dataDistTitle.c_str());
} else {
streamlog_out ( ERROR1 ) << "Problem booking the " << (basePath + tempHistoName) << ".\n"
<< "Very likely a problem with path name. Switching off histogramming and continue w/o" << endl;
_fillDebugHisto = 0;
}
}
if ( _doCommonMode == 1 || _doCommonMode == 2) {
// book the common mode histo
tempHistoName = _commonModeDistHistoName + "_d" + to_string( sensorID );
int commonModeDistHistoNBin = 100;
double commonModeDistHistoMin = -10;
double commonModeDistHistoMax = +10;
string commonModeTitle = "Common mode distribution";
if ( isHistoManagerAvailable ) {
histoInfo = histoMgr->getHistogramInfo(_commonModeDistHistoName);
if ( histoInfo ) {
streamlog_out ( DEBUG2 ) << (* histoInfo ) << endl;
commonModeDistHistoNBin = histoInfo->_xBin;
commonModeDistHistoMin = histoInfo->_xMin;
commonModeDistHistoMax = histoInfo->_xMax;
if ( histoInfo->_title != "" ) commonModeTitle = histoInfo->_title;
}
}
AIDA::IHistogram1D * commonModeDistHisto =
AIDAProcessor::histogramFactory(this)->createHistogram1D( (basePath + tempHistoName).c_str(),
commonModeDistHistoNBin, commonModeDistHistoMin,
commonModeDistHistoMax);
if ( commonModeDistHisto ) {
_aidaHistoMap.insert(make_pair(tempHistoName, commonModeDistHisto));
commonModeDistHisto->setTitle(commonModeTitle.c_str());
} else {
streamlog_out ( ERROR1 ) << "Problem booking the " << (basePath + tempHistoName) << ".\n"
<< "Very likely a problem with path name. Switching off histogramming and continue w/o" << endl;
// setting _fillDebugHisto to 0 is not solving the problem
// because the common mode histogram is independent from
// the debug histogram. And disabling the common mode
// calculation is probably too much. The simplest solution
// would be to add another switch to the class data
// members. Since the fill() method is protected by a
// previous check on the retrieved histogram pointer,
// continue should be safe.
}
}
if ( _doCommonMode == 1 ) {
// book full frame common mode histograms
tempHistoName = _skippedPixelDistHistoName + "_d" + to_string( sensorID );
int skippedPixelDistHistoNBin = static_cast< int > ( _noOfPixelMap[ sensorID ] / 100. );
double skippedPixelDistHistoMin = 0.;
double skippedPixelDistHistoMax = static_cast< double > ( _noOfPixelMap[ sensorID ] );
string skippedPixelDistTitle = "Pixel exceeding the hit rejection cut";
AIDA::IHistogram1D * skippedPixelDistHisto =
AIDAProcessor::histogramFactory( this )->createHistogram1D( (basePath + tempHistoName).c_str(),
skippedPixelDistHistoNBin, skippedPixelDistHistoMin,skippedPixelDistHistoMax) ;
if ( skippedPixelDistHisto ) {
_aidaHistoMap.insert( make_pair( tempHistoName, skippedPixelDistHisto ) );
skippedPixelDistHisto->setTitle( skippedPixelDistTitle );
} else {
streamlog_out ( ERROR1 ) << "Problem booking the " << (basePath + tempHistoName) << ".\n"
<< "Very likely a problem with path name. Switching off histogramming and continue w/o" << endl;
}
}
if ( _doCommonMode == 2 ) {
// book row wise common mode histograms
tempHistoName = _skippedPixelPerRowDistHistoName + "_d" + to_string( sensorID );
int skippedPixelPerRowDistHistoNBin = _noOfPixelPerRowMap[ sensorID ] + 1 ;
double skippedPixelPerRowDistHistoMin = -0.5;
double skippedPixelPerRowDistHistoMax = _noOfPixelPerRowMap[ sensorID ] + 0.5 ;
string skippedPixelPerRowDistTitle = "Pixel in a row exceeding the hit rejection cut";
AIDA::IHistogram1D * skippedPixelPerRowDistHisto =
AIDAProcessor::histogramFactory( this )->createHistogram1D( (basePath + tempHistoName).c_str(),
skippedPixelPerRowDistHistoNBin, skippedPixelPerRowDistHistoMin, skippedPixelPerRowDistHistoMax );
if ( skippedPixelPerRowDistHisto ) {
_aidaHistoMap.insert( make_pair( tempHistoName, skippedPixelPerRowDistHisto ) );
skippedPixelPerRowDistHisto->setTitle( skippedPixelPerRowDistTitle );
} else {
streamlog_out ( ERROR1 ) << "Problem booking the " << (basePath + tempHistoName) << ".\n"
<< "Very likely a problem with path name. Switching off histogramming and continue w/o" << endl;
}
tempHistoName = _skippedRowDistHistoName + "_d" + to_string( sensorID );
int skippedRowDistHistoNBin = _noOfRowMap[ sensorID ] + 1 ;
double skippedRowDistHistoMin = -0.5;
double skippedRowDistHistoMax = _noOfRowMap[ sensorID ] + 0.5 ;
string skippedRowDistTitle = "Row rejected in common mode calculation";
AIDA::IHistogram1D * skippedRowDistHisto =
AIDAProcessor::histogramFactory( this )->createHistogram1D( (basePath + tempHistoName).c_str(),
skippedRowDistHistoNBin, skippedRowDistHistoMin, skippedRowDistHistoMax );
if ( skippedRowDistHisto ) {
_aidaHistoMap.insert( make_pair( tempHistoName, skippedRowDistHisto ));
skippedRowDistHisto->setTitle( skippedRowDistTitle ) ;
} else {
streamlog_out ( ERROR1 ) << "Problem booking the " << (basePath + tempHistoName) << ".\n"
<< "Very likely a problem with path name. Switching off histogramming and continue w/o" << endl;
}
}
#endif
}
_isFirstEvent = false;
}
LCCollectionVec * correctedDataCollection = new LCCollectionVec(LCIO::TRACKERDATA);
_minX.clear();
_maxX.clear();
_minY.clear();
_maxY.clear();
for (unsigned int iDetector = 0; iDetector < inputCollectionVec->size(); iDetector++) {
vector< float > commonModeCorVec;
commonModeCorVec.clear();
// reset quantity for the common mode.
double pixelSum = 0.;
double commonMode = 0.;
int goodPixel = 0;
int skippedPixel = 0;
int skippedRow = 0;
TrackerRawDataImpl * rawData = dynamic_cast < TrackerRawDataImpl * >(inputCollectionVec->getElementAt(iDetector));
int sensorID = cellDecoder(rawData)["sensorID"];
// this is the corresponding element in the ancillary collections
size_t ancillaryPos = _ancillaryIndexMap[ sensorID ];
TrackerDataImpl * pedestal = dynamic_cast < TrackerDataImpl * > (pedestalCollectionVec->getElementAt( ancillaryPos ));
TrackerDataImpl * noise = dynamic_cast < TrackerDataImpl * > (noiseCollectionVec->getElementAt( ancillaryPos ));
TrackerRawDataImpl * status = dynamic_cast < TrackerRawDataImpl * >(statusCollectionVec->getElementAt( ancillaryPos ));
TrackerDataImpl * corrected = new TrackerDataImpl;
CellIDEncoder<TrackerDataImpl> idDataEncoder(EUTELESCOPE::MATRIXDEFAULTENCODING, correctedDataCollection);
idDataEncoder["sensorID"] = sensorID;
idDataEncoder["xMin"] = static_cast<int > (cellDecoder(rawData)["xMin"]);
idDataEncoder["xMax"] = static_cast<int > (cellDecoder(rawData)["xMax"]);
idDataEncoder["yMin"] = static_cast<int > (cellDecoder(rawData)["yMin"]);
idDataEncoder["yMax"] = static_cast<int > (cellDecoder(rawData)["yMax"]);
_minX.push_back( cellDecoder( rawData ) ["xMin"] ) ;
_maxX.push_back( cellDecoder( rawData ) ["xMax"] ) ;
_minY.push_back( cellDecoder( rawData ) ["yMin"] ) ;
_maxY.push_back( cellDecoder( rawData ) ["yMax"] ) ;
idDataEncoder.setCellID(corrected);
ShortVec::const_iterator rawIter = rawData->getADCValues().begin();
FloatVec::const_iterator pedIter = pedestal->getChargeValues().begin();
FloatVec::const_iterator noiseIter = noise->getChargeValues().begin();
ShortVec::const_iterator statusIter = status->getADCValues().begin();
bool isEventValid = true;
if ( _doCommonMode == 1 ) {
// FULLFRAME common mode
while ( rawIter != rawData->getADCValues().end() ) {
bool isHit = ( ((*rawIter) - (*pedIter)) > _hitRejectionCut * (*noiseIter) );
bool isGood = ( (*statusIter) == EUTELESCOPE::GOODPIXEL );
if ( !isHit && isGood ) {
pixelSum += (*rawIter) - (*pedIter);
++goodPixel;
} else if ( isHit ) {
++skippedPixel;
}
++rawIter;
++pedIter;
++noiseIter;
++statusIter;
}
if ( ( ( _maxNoOfRejectedPixels == -1 ) || ( skippedPixel < _maxNoOfRejectedPixels ) ) &&
( goodPixel != 0 ) ) {
commonMode = pixelSum / goodPixel;
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
string tempHistoName = _commonModeDistHistoName + "_d" + to_string( sensorID );
if ( AIDA::IHistogram1D* histo = dynamic_cast<AIDA::IHistogram1D*>(_aidaHistoMap[tempHistoName]) )
histo->fill(commonMode);
#endif
} else {
isEventValid = false;
}
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
string tempHistoName = _skippedPixelDistHistoName + "_d" + to_string( sensorID ) ;
if ( AIDA::IHistogram1D* histo = dynamic_cast<AIDA::IHistogram1D*>(_aidaHistoMap[tempHistoName]) )
histo->fill( skippedPixel );
#endif
} else if ( _doCommonMode == 2 ) {
// ROWWISE common mode
ShortVec adcValues = rawData->getADCValues ();
FloatVec _pedestal = pedestal->getChargeValues();
ShortVec _status = status->getADCValues();
FloatVec _noise = noise->getChargeValues();
int iPixel = 0;
int colCounter = 0;
int rowLength = _maxX[iDetector] - _minX[iDetector] + 1;
for (int yPixel = _minY[iDetector]; yPixel <= _maxY[iDetector]; yPixel++) {
double pixelSum = 0.;
double commonMode = 0.;
int goodPixel = 0;
int skippedPixelPerRow = 0;
for ( int xPixel = _minX[iDetector]; xPixel <= _maxX[iDetector]; xPixel++) {
bool isHit = ( ( adcValues[iPixel] - _pedestal[iPixel] ) > _hitRejectionCut * _noise[iPixel] );
bool isGood = ( _status[iPixel] == EUTELESCOPE::GOODPIXEL );
if ( !isHit && isGood ) {
pixelSum += adcValues[iPixel] - _pedestal[iPixel];
++goodPixel;
} else if ( isHit ) {
++skippedPixelPerRow;
++skippedPixel;
}
++iPixel;
}
// we are now at the end of the row, so let's calculate the
// common mode
if ( ( skippedPixelPerRow < _maxNoOfRejectedPixelPerRow ) &&
( goodPixel != 0 ) ) {
commonMode = pixelSum / goodPixel ;
commonModeCorVec.insert( commonModeCorVec.begin() + colCounter * rowLength, rowLength, commonMode );
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
string tempHistoName = _commonModeDistHistoName + "_d" + to_string( sensorID );
if ( AIDA::IHistogram1D* histo = dynamic_cast<AIDA::IHistogram1D*>(_aidaHistoMap[tempHistoName]) )
histo->fill(commonMode);
#endif
} else {
commonModeCorVec.insert( commonModeCorVec.begin() + colCounter * rowLength, rowLength, 0. );
++skippedRow;
}
++colCounter;
}
if ( skippedRow > _maxNoOfSkippedRow ) {
isEventValid = false;
}
} // end if on _doCommonMode
if(isEventValid) {
if(_doCommonMode == 2) {
ShortVec adcValues = rawData->getADCValues ();
FloatVec _pedestal = pedestal->getChargeValues();
int iPixel = 0;
for (int yPixel = _minY[iDetector]; yPixel <= _maxY[iDetector]; yPixel++) {
for ( int xPixel = _minX[iDetector]; xPixel <= _maxX[iDetector]; xPixel++) {
double correctedValue = adcValues[iPixel] - _pedestal[iPixel] - commonModeCorVec[iPixel];
corrected->chargeValues().push_back(correctedValue);
++iPixel;
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
if (_fillDebugHisto == 1) {
string tempHistoName = _rawDataDistHistoName + "_d" + to_string( sensorID );
if ( AIDA::IHistogram1D* histo = dynamic_cast<AIDA::IHistogram1D*>(_aidaHistoMap[tempHistoName]) ) {
histo->fill(adcValues[iPixel]);
} else {
streamlog_out ( ERROR1 ) << "Not able to retrieve histogram pointer for " << tempHistoName
<< ".\nDisabling histogramming from now on " << endl;
_fillDebugHisto = 0 ;
}
tempHistoName = _dataDistHistoName + "_d" + to_string( sensorID );
if ( AIDA::IHistogram1D * histo = dynamic_cast<AIDA::IHistogram1D*>(_aidaHistoMap[tempHistoName]) ) {
histo->fill(correctedValue);
} else {
streamlog_out ( ERROR1 ) << "Not able to retrieve histogram pointer for " << tempHistoName
<< ".\nDisabling histogramming from now on " << endl;
_fillDebugHisto = 0 ;
}
}
#endif
}
}
} else {
// that's the case the user wants to apply the FullFrame
// common mode or doesn't want to apply any correction at
// all. In this last case the value of the commonMode
// variable is taken directly from the initialization ( = 0 ).
rawIter = rawData->getADCValues().begin();
pedIter = pedestal->getChargeValues().begin();
while ( rawIter != rawData->getADCValues().end() ) {
double correctedValue = (*rawIter) - (*pedIter) - commonMode;
corrected->chargeValues().push_back(correctedValue);
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
if (_fillDebugHisto == 1) {
string tempHistoName = _rawDataDistHistoName + "_d" + to_string( sensorID );
if ( AIDA::IHistogram1D* histo = dynamic_cast<AIDA::IHistogram1D*>(_aidaHistoMap[tempHistoName]) ) {
histo->fill(*rawIter);
} else {
streamlog_out ( ERROR1 ) << "Not able to retrieve histogram pointer for " << tempHistoName
<< ".\nDisabling histogramming from now on " << endl;
_fillDebugHisto = 0 ;
}
tempHistoName = _dataDistHistoName + "_d" + to_string( sensorID );
if ( AIDA::IHistogram1D * histo = dynamic_cast<AIDA::IHistogram1D*>(_aidaHistoMap[tempHistoName]) ) {
histo->fill(correctedValue);
} else {
streamlog_out ( ERROR1 ) << "Not able to retrieve histogram pointer for " << tempHistoName
<< ".\nDisabling histogramming from now on " << endl;
_fillDebugHisto = 0 ;
}
}
#endif
++rawIter;
++pedIter;
}
}
} else {
// this is the case the event is not valid because of common
// mode. This is the right place to throw a SkipEventException
// possibly motivating the reason.
if ( _doCommonMode == 1 ) {
streamlog_out ( WARNING4 ) << "Skipping event " << evt->getEventNumber() << " because of maximum number of pixel exceeded (" << skippedPixel << ")" << endl;
} else if ( _doCommonMode == 2 ) {
streamlog_out ( WARNING4 ) << "Skipping event " << evt->getEventNumber() << " because of maximum number of skipped row exceeded (" << skippedRow << ")" << endl;
} else {
streamlog_out ( WARNING4 ) << "Skipping event " << evt->getEventNumber() << " for an unknown reason " << endl;
}
throw SkipEventException( this );
}
correctedDataCollection->push_back(corrected);
}
evt->addCollection(correctedDataCollection, _calibratedDataCollectionName);
} catch (DataNotAvailableException& e) {
if ( _noOfConsecutiveMissing <= _maxNoOfConsecutiveMissing ) {
streamlog_out ( WARNING2 ) << "No input collection found on event " << event->getEventNumber()
<< " in run " << event->getRunNumber() << endl;
if ( _noOfConsecutiveMissing == _maxNoOfConsecutiveMissing ) {
streamlog_out ( MESSAGE2 ) << "Assuming the run was taken in ZS. Not issuing any other warning" << endl;
}
++_noOfConsecutiveMissing;
}
}
}
void EUTelCalibrateEventProcessor::check (LCEvent * /* evt */ ) {
// nothing to check here - could be used to fill check plots in reconstruction processor
}
void EUTelCalibrateEventProcessor::end() {
streamlog_out ( MESSAGE2 ) << "Successfully finished" << endl;
}