DataReader2021.cpp 20.9 KB
Newer Older
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
 /** @defgroup ana Analysis
 *   @ingroup ana
 *   @file DataReader2021.cpp
 *   @brief Implementation of DataReader2021.
 *
 *  Function definitions for DataReader2021 are provided.
 *  This class reads a rootfile with raw waveforms
 *  that are processed by rcdaqAnalysis running on prdf files.
 *  Then, in the event loop, analysis classes can be called.
 *
 *  @author Yakov Kulinich, Riccardo Longo
 *  @bug No known bugs.
 */

#include <TFile.h>
#include <TTree.h>

#include <iostream>
#include <fstream>

#include "DataReader2021.h"
#include "Analysis.h"
#include "Containers.h"
#include "RPD.h"
#include "ZDC.h"
#include "EM.h"
#include "Visualizer.h"


/** @brief Default Constructor for DataReader2021.
 */
DataReader2021::DataReader2021() : DataReader2021( 0, 0, "", 0 ){

}

/** @brief Constructor for DataReader2021.
 *
 *  @param nCh Number of channels being read
 *  @param nSamp Number of samples per channel
 */
DataReader2021::DataReader2021( const unsigned int nCh, const unsigned int nSamp )
  : DataReader2021( nCh, nSamp, "", 0 ){

  // here say we will read in list of files, maybe
  // there is better way to do it, just an idea for now.
  m_readListOfFiles = true;
}

/** @brief Constructor for DataReader2021.
 *
 *  @param nCh Number of channels being read
 *  @param nSamp Number of samples per channel
 *  @param fNameIn Input filename.
 */
DataReader2021::DataReader2021( const uint nCh, const uint nSamp,
			const std::string& fNameIn )
  : DataReader2021( nCh, nSamp, fNameIn, 0 ){

}


/** @brief Constructor for DataReader2021.
 *
 *  @param nCh Number of channels being read
 *  @param nSamp Number of samples per channel
 *  @param4 fNameIn Output file name (custom)
 *  @param3 runNum Run number being used.

 */
DataReader2021::DataReader2021( const uint nCh, const uint nSamp,
			const std::string& fNameIn, const uint runNum )
  : m_nCh( nCh ), m_nSamp( nSamp ), m_fNameIn( fNameIn ),
    m_runNumber( runNum ), m_readListOfFiles( false ), m_fIn( NULL ){

}


/** @brief Destructor for DataReader2021.
 */
DataReader2021::~DataReader2021(){


  for( auto& time : m_time ){
      delete time; time = NULL;
  }
  for( auto& det : m_detectors ){
      delete det; det = NULL;
  }
  for( auto& ana : m_ana ){
    delete ana; ana = NULL;
  }
  for( auto& det_ana : m_det_ana ){
    delete det_ana; det_ana = NULL;
  }

  //This line deletes all histograms so we don't have to
  gDirectory->GetList()->Delete();

  delete m_alignment; m_alignment = NULL;
  delete m_fOut; m_fOut = NULL;
  delete m_fIn; m_fIn = NULL;

}

/** @brief Adds an analysis to vector of analysis to be executed before the detector analysis (e.g. WaveForm Analysis)
 *
 *  @param ana Pointer to an Analysis.
 *
 *  @return none
 */
void DataReader2021::AddPreAnalysis( Analysis* ana ){
  ana->SetVerbosity( m_verbose );
  m_ana.push_back( ana );
}

/** @brief Adds an analysis to vector of detector analysis (e.g. ZDC, RPD or combined)
 *
 *  @param ana Pointer to an Analysis.
 *
 *  @return none
 */
void DataReader2021::AddDetectorAnalysis( Analysis* det_ana ){
  det_ana->SetVerbosity( m_verbose );
  m_det_ana.push_back( det_ana );
}

/**
 * @brief Allows the user to select which detectors will enter the waveform analysis and the detector analysis s
 * @param _useZDCs set it true to look to ATLAS HAD ZDC modules
 * @param _usePFRPD  set it true to look to the PFRPD
 * @param _useTRPD  set it true to look to the TRPD
 * @param _useUEM  set it true to look to the upgraded EM module
 */
void DataReader2021::SelectDetectorForAnalysis(bool _useUEM, bool _usePFRPD, bool _useTRPD, bool _useZDCs){

    m_useUEM = _useUEM;
    m_useZDCs = _useZDCs;
    m_usePFRPD = _usePFRPD;
    m_useTRPD = _useTRPD;

    std::string enableDet;
    enableDet = "Detectors Selected for Analysis: ";

    if (m_useUEM) enableDet += " Upg.EM ";
    if (m_usePFRPD) enableDet += " PanFlute-RPD " ;
    if (m_useTRPD) enableDet += " Tile-RPD " ;
    if (m_useZDCs) enableDet += " HAD1 HAD2 HAD3 " ;

    enableDet += ";";
    std::cout << enableDet << std::endl;
}

/** @brief Enables the read from list of files option for DataReader2021
 *
 *  @param listname name of the list of files to be processed (with the full path if it's not in the execution folder)
 *
 *  @return none
 */
void DataReader2021::ReadListOfFiles( std::string listname ){

    m_readListOfFiles = true;
    m_fListOfFiles = listname;
}


/**
 * @brief Reads the .xml configuration file and load characteristics for all the channels, immediately sorted into detectors objects
 * @param _inFile
 */
void DataReader2021::LoadAlignmentFile(std::string _inFile ){

    m_XMLparser = new XMLSettingsReader();

    if (!m_XMLparser->parseFile(_inFile)) {
            std::cerr << " Data Reader could not parse file : " << _inFile << std::endl;
            return;
    }

    m_alignment = new Alignment2021();
    m_alignment->runNumber = m_runNumber;

    std::cout << "Loading .xml Alignment File..." << std::endl;
    std::cout << "Found " << m_XMLparser->getBaseNodeCount("Alignment") << " alignment entries " << std::endl;
    std::cout << "Retrieving the information for run " << m_runNumber << std::endl;

    int run;
    for (unsigned int i = 0; i < m_XMLparser->getBaseNodeCount("Alignment"); i++) {
        m_XMLparser->getChildValue("Alignment",i,"run",run);
        if(run != m_runNumber) continue;
        std::cout << "Found Run Entry in Alignment file for run " << m_runNumber << std::endl;
        m_XMLparser->getChildValue("Alignment",i,"beam_type",m_alignment->beam_type);
        m_XMLparser->getChildValue("Alignment",i,"beam_energy",m_alignment->beam_energy);
        m_XMLparser->getChildValue("Alignment",i,"x_det_table",m_alignment->x_det_table);
        m_XMLparser->getChildValue("Alignment",i,"x_det_table",m_alignment->x_det_table);
        m_XMLparser->getChildValue("Alignment",i,"x_trig_table",m_alignment->x_trig_table);
        m_XMLparser->getChildValue("Alignment",i,"y_trig_table",m_alignment->y_trig_table);
        m_XMLparser->getChildValue("Alignment",i,"Det1",m_alignment->Det1);
        m_XMLparser->getChildValue("Alignment",i,"Det2",m_alignment->Det2);
        m_XMLparser->getChildValue("Alignment",i,"Det3",m_alignment->Det3);
        m_XMLparser->getChildValue("Alignment",i,"Det4",m_alignment->Det4);
        m_XMLparser->getChildValue("Alignment",i,"Det5",m_alignment->Det5);
        m_XMLparser->getChildValue("Alignment",i,"Det6",m_alignment->Det6);
    }

    if(m_alignment == NULL) std::cout << "WARNING: ALIGNMENT NOT FOUND!!!" << std::endl;
    delete m_XMLparser; m_XMLparser = NULL;
    return;

}

/**
 * @brief Reads the .xml configuration file and load characteristics for all the channels, immediately sorted into detectors objects
 * @param _inFile
 */
void DataReader2021::LoadConfigurationFile(std::string _inFile ){

    m_XMLparser = new XMLSettingsReader();

    if (!m_XMLparser->parseFile(_inFile)) {
            std::cerr << " Data Reader could not parse file : " << _inFile << std::endl;
            return;
    }

    std::cout << "Loading .xml Configuration File..." << std::endl;
    std::cout << "Found " << m_XMLparser->getBaseNodeCount("channel") << " channel entries " << std::endl;

    std::vector < Channel* > channelEntries;
    int first_run, last_run;

    for (unsigned int i = 0; i < m_XMLparser->getBaseNodeCount("channel"); i++) {
        Channel *buffer_ch = new Channel();
        m_XMLparser->getChildValue("channel",i,"start_run",first_run);
        m_XMLparser->getChildValue("channel",i,"end_run",last_run);

        //Discard entries for any channel that does not apply to our run
        if(m_runNumber < first_run || m_runNumber > last_run) continue;

        //If the entry applies, we store it in the vector
        m_XMLparser->getChildValue("channel",i,"detector",buffer_ch->detector);
        m_XMLparser->getChildValue("channel",i,"name",buffer_ch->name);
        m_XMLparser->getChildValue("channel",i,"mapping_row",buffer_ch->mapping_row);
        m_XMLparser->getChildValue("channel",i,"mapping_column",buffer_ch->mapping_column);
        m_XMLparser->getChildValue("channel",i,"delay",buffer_ch->PMTcode);
        m_XMLparser->getChildValue("channel",i,"delay",buffer_ch->delay);
        m_XMLparser->getChildValue("channel",i,"offset",buffer_ch->offset);
        m_XMLparser->getChildValue("channel",i,"HV",buffer_ch->HV);
        m_XMLparser->getChildValue("channel",i,"is_on",buffer_ch->is_on);
        m_XMLparser->getChildValue("channel",i,"Vop",buffer_ch->Vop);

        bool isNew(true);
        for( int k = 0; k < channelEntries.size(); k++){
            if(buffer_ch->name == channelEntries.at(k)->name){
                std::cout << "WARNING!!! Redundancy in your settings file for " << buffer_ch->name << ". Check it carefully. The second entry found will be skipped..." << std::endl;
                isNew = false;
            }
        }
        if(isNew) channelEntries.push_back(buffer_ch);
    }

    std::cout << "Loaded " << channelEntries.size() << " configuration entries " << std::endl;
    if( channelEntries.size() < 18 ) std::cout << "WARNING!!!! Number of Channels < 18. Seems that some entry is missed for this run in the config.xml. BE CAREFUL!" << std::endl;
    ZDC* zdc1 = new ZDC(channelEntries,m_runNumber,1);
    ZDC* zdc2 = new ZDC(channelEntries,m_runNumber,2);
    ZDC* zdc3 = new ZDC(channelEntries,m_runNumber,3);
    RPD* pfrpd = new RPD(channelEntries,m_runNumber, "PFRPD");
    RPD* trpd = new RPD(channelEntries,m_runNumber, "TRPD");
    EM* uem = new EM(channelEntries,m_runNumber, "UEM");

    m_detectors.push_back(zdc1); //Position 0 goes for ZDC1 - HAD1
    m_detectors.push_back(zdc2); //Position 1 goes for ZDC2 - HAD2
    m_detectors.push_back(zdc3); //Position 2 goes for ZDC3 - HAD3

    m_detectors.push_back(pfrpd); //Position 3 goes for the PF RPD
    m_detectors.push_back(trpd); //Position 4 goes for the TILE RPD

    m_detectors.push_back(uem); //Position 5 goes for the upgraded EM (or the CMS one)

    std::cout << "Detector configuration: loading complete! " << std::endl;
    delete m_XMLparser; m_XMLparser = NULL;
    return;
}


/** @brief Loads calibrated timing information for DRS4 modules based on run number
 *  @param _inFile Optional argument for loading a custom file
 *
 *  Uses run number to determine scan number and loads the appropriate DRS4 timing
 *  information from the 2018 Testbeam. After loading, we hand each Channel a
 *  pointer to its timing vector. Must be run after LoadConfigurationFile()
 *
 */
void DataReader2021::LoadTimingFile(std::string _inFile){
    //TODO: Check if 2021 data taking this method is still useful or is obsolete
    std::string inFile,buffer;
    char data[12];
    float dat;
    std::vector< Channel* > vChannel;
    m_time.resize(5);
    for(int i = 0; i < 5; i++){
        m_time[i] = new std::vector< float >;
    }

    int chNo;
    int start[] = {79,  152, 190, 202, 215, 258 };
    int stop[]  = {112, 171, 200, 213, 231, 413 };
    int scanNum = 0;

    //If the user has selected a file, use it and skip determining the scan number
    if(_inFile != ""){
        std::cout << "Using timing file definied by user " << _inFile << std::endl;
        inFile = _inFile;
        goto open;
    }

    //Determine scan number using ranges defined by start and stop.
    //Scan 6-13 have identical timing data, so we treat them all as scan 6
    for(int i = 0; i < 6; i++){
        if(start[i]<=m_runNumber && stop[i]>=m_runNumber){
            scanNum = i+1;
        }
    }
    if(scanNum == 0){
        std::cerr << "Scan number not defined, defaulting timing data to Scan 1" << std::endl;
        scanNum = 1;
    }
    inFile = (std::string)std::getenv("JZCaPA") + Form("/Utils/Timing_data/2018scan%d.txt",scanNum);

    open:
    std::ifstream file( inFile.c_str() );
    if( !file.is_open() ){
        std::cerr << "WARNING: Timing data file didn't open " << inFile << std::endl;
        return;
    }

    //Get the headers out
    getline(file,buffer);
    getline(file,buffer);

    while(!file.eof()){
        getline(file,buffer);
        if(buffer == "") break;

        //Loop through the DRS4 modules pushing the data into the vector
        //and chopping off the front of the string
        for(int drs = 0; drs<4; drs++){
            buffer.copy( data , 11 );
            dat = atof(data);
            m_time[drs]->push_back( dat );
            buffer.erase(buffer.front(),11);
        }
        //The spacing on the file is a bit weird, so fill the last one differently
        m_time[4]->push_back( atof( buffer.c_str() ) );
    }
    file.close();

    //Loop through the detector vector and their Channel vectors assigning the
    //time vector based on hardware channel number (Channel::name)
    for( auto& det : m_detectors ){
        vChannel = det->GetChannelsVector();
        for( Channel* ch : vChannel ){
            buffer = ch->name;
            //Remove "Signal" from name and convert to int
            buffer.erase(0,6);
            chNo = atoi( buffer.c_str() );

            //If the channel already has a time vector, print an error and continue
            if(ch->pTimeVec != 0){
                std::cerr << "WARNING: Overwriting Channel time vector" << std::endl;
            }
            ch->pTimeVec = m_time[chNo/4];
        }
    }
    std::cout << "DRS4 Timing: loading complete " << std::endl;
}

/**
 * @brief DataReader2021::GetDetector allows the user to access the detectors objects after loading them at the beginning of the execution
 * @param _detName can be ZDC1 (upstream module), ZDC2 (downstream module) or RPD.
 * @return
 */
Detector* DataReader2021::GetDetector( std::string _detName ){

    for( int iDet = 0; iDet < (int)m_detectors.size(); iDet++){
        if( _detName == m_detectors.at(iDet)->GetName() ){
          return m_detectors.at(iDet);
        }
    }

    std::cout << "WARNING: detector recognition glitch. NULL pointer being returned..." << std::endl;
    return NULL;
}


/** @brief Console output update
 *  @return none
 *
 *  Called by the TTimer in ProcessEvents
 *  Updates the console with CPU and RAM usage,
 *  number of events processed and events/second
 *  if verbosity is not zero
 */
void DataReader2021::UpdateConsole( Long_t _updateRate){

    if( m_verbose == 0 ){ return; }
    if(m_event!=0){


        // Get CPU information
        gSystem->GetCpuInfo(&m_cpuInfo, 100);
        gSystem->GetProcInfo( &m_procInfo );
        // Get Memory information
        gSystem->GetMemInfo(&m_memInfo);
        // Get events/second
        double rate = 1000*(m_event-m_event_old)/_updateRate;
        m_event_old = m_event;

        std::cout << "\r" << std::left <<  Form("Processed %5d events, ", m_event);
        std::cout << Form( "%5.1f ev/s, ", rate);
        std::cout << Form( "CPU use/time: %3d%%/%6.1fs, ", (int)m_cpuInfo.fTotal, (double)m_procInfo.fCpuSys + m_procInfo.fCpuUser);
        std::cout << Form( "RAM:%4.1f/%4.1fGB, ", (double)m_memInfo.fMemUsed/1024, (double)m_memInfo.fMemTotal/1024);
        std::cout << Form( "RAM used by process: %ldMB   ", (m_procInfo.fMemResident + m_procInfo.fMemVirtual)/1024 );
        std::cout << std::flush;
    }
}

/** @brief Run method for DataReader2021
 *  @return none
 *
 *  Call Initialize, ProcessEvents, and Finalize
 *  Made so the driver class only has to call one method.
 *
 */
void DataReader2021::Run(){

  Initialize();
  if( !m_fIn ){
      std::cerr << "Input file didn't open... exiting" << std::endl;
      return;
  }
  ProcessEvents();
  Finalize();
}

/** @brief Initialization method for DataReader2021
 *
 *  Select which file(s) to read. For now just a single
 *  file, later this can be extended to read many and make
 *  chain of files for example. Also create and initialize
 *  the analysis that will be running.
 *
 *  @return none
 */
void DataReader2021::Initialize(){

  if( m_readListOfFiles ){

    // Riccardo - 21/01/2019 - TChain implementation
    // The file list name is supposed to be already set
    m_fileChain = new TChain("tree");
    std::ifstream inFile;
    inFile.open(m_fListOfFiles.c_str());
    std::string reader_buff;
    while(inFile >> reader_buff){
        //Let's push all the files in the list into the TChain
        m_fileChain->Add(reader_buff.c_str());
    }
    /** TODO - Add fileChain reading below
     */
  } else {
    m_fIn = TFile::Open( m_fNameIn.c_str() );
  }

  // If no output directory is specified by the user
  // one is created for this run in $JZCaPA/results
  if( m_outputDir == "" ){
      m_outputDir = (std::string)std::getenv("JZCaPA") + Form("/results/run%d/", m_runNumber);
      gSystem->Exec( ("mkdir -p " + m_outputDir).c_str() );
  }

  // If we are reading a list of files, or have no run number
  // make default name output.root, otherwise make it
  // outputN.root, where N is a run number of a file.
  std::string fNameOut = m_readListOfFiles ?
    (m_outputDir + "output.root") : Form( (m_outputDir + "output%d.root").c_str(), m_runNumber );

  m_fOut = new TFile( fNameOut.c_str(), "RECREATE" );
  m_tOut = new TTree("AnalysisTree","AnalysisTree");
  m_tOut->Branch("runNumber", &m_runNumber, "m_runNumber/i");
  m_tOut->Branch("evNo", &m_event, "m_event/I");
  m_tOut->Branch("x_det_table", &m_alignment->x_det_table, "x_det_table/D");
  m_tOut->Branch("y_det_table", &m_alignment->y_det_table, "y_det_table/D");
  m_tOut->Branch("x_trig_table", &m_alignment->x_trig_table, "x_trig_table/D");
  m_tOut->Branch("y_trig_table", &m_alignment->y_trig_table, "y_trig_table/D");

  for( uint detID = 0; detID < (int) m_detectors.size(); detID++ ){
     m_detectors.at(detID)->SetAlignment2021(m_alignment);
  }
  for( auto& ana : m_ana ){
    ana->Initialize();
    ana->SetupHistograms();
  }
  for( auto& det_ana : m_det_ana ){
    det_ana->Initialize( m_detectors );
    det_ana->SetupHistograms();
    det_ana->SetBranches( m_tOut );
  }
}



/** @brief Process Events method for DataReader2021
 *
 *  Connect to files / chain of files.
 *  Read tree event by event, and fill basic waveforms.
 *  So far (12.12.18) For each event - Read Raw data for all channels,
 *  put it into 2D vector size NxM where N = nCh, M = nSamp
 *  Also, For each event - Fill N 1D histos that have size M.
 *  Then one can send these to any Analysis function they make.
 *  Here for example (12.12.18), we send to WFAnalysis::AnalyzeEvent( .. )
 *  See below - Have fun!
 *
 *  @return none
 */
void DataReader2021::ProcessEvents(){


  /** TODO : add reading for list of files
    * Please note that many of the implementations are now for a single-file treatment
    */
  TTree* tree = static_cast< TTree* >( m_fIn->Get( "tree" ) );

  //Specific pointers to each detector, if needed afterwards
  ZDC* zdc1 = static_cast< ZDC* >( GetDetector("ZDC1") );
  ZDC* zdc2 = static_cast< ZDC* >( GetDetector("ZDC2") );
  ZDC* zdc3 = static_cast< ZDC* >( GetDetector("ZDC3") );
  RPD* pfrpd =  static_cast< RPD* >( GetDetector("PFRPD") );
  RPD* trpd =  static_cast< RPD* >( GetDetector("TRPD") );
  EM*  uem = static_cast< EM* > ( GetDetector("UEM") );

  //All the raw channels addresses set for read-out
  for( uint detID = 0; detID < (int) m_detectors.size(); detID++ ){
       m_detectors.at(detID)->SetBranches(tree);
       m_detectors.at(detID)->SetNSamples(m_nSamp);
       m_detectors.at(detID)->DeclareHistograms();
  }

  std::cout << "File: " << m_fIn->GetName() << " has " << tree->GetEntries() << " events." << std::endl;

  // !! EVENT LOOP
  for( int ev = 0; ev < tree->GetEntries(); ev++ ){
    m_event = ev;
    tree->GetEntry( ev );

    // Fill the raw waveforms
    for( uint detID = 0; detID < (int) m_detectors.size(); detID++ )
        m_detectors.at(detID)->FillHistograms();

    // Now call all analysis and run their AnalyzeEvent.
    // Can either send a vector of histos, or a 2D vector
    // Of all the data, depending on what you want to do.
    // Note that at the moment none of this methods is doing anything
    for( auto& ana : m_ana ){
      //raw data analysis
        if(m_useZDCs){
            ana->AnalyzeEvent( zdc1->GetChannelsVector() );
            ana->AnalyzeEvent( zdc2->GetChannelsVector() );
            ana->AnalyzeEvent( zdc3->GetChannelsVector() );
        }
        if(m_usePFRPD) ana->AnalyzeEvent( pfrpd->GetChannelsVector() );
        if(m_useTRPD)  ana->AnalyzeEvent( trpd->GetChannelsVector() );
        if(m_useUEM)   ana->AnalyzeEvent( uem->GetChannelsVector() );
      }
    for( auto& det_ana : m_det_ana ){
      //Detector level analysis
      det_ana->AnalyzeEvent(  );
    }

  m_tOut->Fill();

  } // End event loop
}

/** @brief Finalize method for DataReader2021
 *
 *  Close any input files
 *  Call analysis finalize methods
 *
 *  @return none
 */
void DataReader2021::Finalize(){

  if( m_fIn ){
    m_fIn->Close();
  }

  // enter the output file since
  // we will be writing to it now.
  m_fOut->cd();

  //Add label, if wanted
  //To understand the kind of measurement, we use alignments
  Visualizer* viz = new Visualizer( "ATLAS" );

  if(m_useLabel){
      viz->SetOutputDirectory( m_outputDir );
      viz->SetTestBeamLabel( m_runNumber, m_alignment);
  }

  for( auto& ana : m_ana ){
    ana->Finalize();
  }
  for( auto& det_ana : m_det_ana ){
    det_ana->AssignVisualizer( viz );
    det_ana->Finalize();
  }

  m_tOut->Write();
  m_fOut->Close();
}