CMS 3D CMS Logo

EcalPerEvtMatacqAnalyzer.cc
Go to the documentation of this file.
1 /*
2  * \class EcalPerEvtMatacqAnalyzer
3  *
4  * primary author: Gautier Hamel De Monchenault - CEA/Saclay
5  * author: Julie Malcles - CEA/Saclay
6  */
7 
8 #include <TFile.h>
9 #include <TTree.h>
10 #include <TChain.h>
11 
13 
14 #include <sstream>
15 #include <iostream>
16 #include <iomanip>
17 
20 
25 
27 
28 //========================================================================
30  : iEvent(0),
31  // framework parameters with default values
32 
33  _presample(iConfig.getUntrackedParameter<double>("nPresamples", 6.7)),
34  _nsamplesaftmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesAftMax", 80)),
35  _nsamplesbefmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesBefMax", 20)),
36  _noiseCut(iConfig.getUntrackedParameter<unsigned int>("noiseCut", 7)),
37  _parabnbefmax(iConfig.getUntrackedParameter<unsigned int>("paraBeforeMax", 8)),
38  _parabnaftmax(iConfig.getUntrackedParameter<unsigned int>("paraAfterMax", 7)),
39  _thres(iConfig.getUntrackedParameter<unsigned int>("threshold", 10)),
40  _lowlev(iConfig.getUntrackedParameter<unsigned int>("lowLevel", 20)),
41  _highlev(iConfig.getUntrackedParameter<unsigned int>("highLevel", 80)),
42  _nevlasers(iConfig.getUntrackedParameter<unsigned int>("nEventLaser", 600)),
43  resdir_(iConfig.getUntrackedParameter<std::string>("resDir")),
44  digiCollection_(iConfig.getParameter<std::string>("digiCollection")),
45  digiProducer_(iConfig.getParameter<std::string>("digiProducer")),
46  eventHeaderCollection_(iConfig.getParameter<std::string>("eventHeaderCollection")),
47  eventHeaderProducer_(iConfig.getParameter<std::string>("eventHeaderProducer")),
48  pmatToken_(consumes<EcalMatacqDigiCollection>(edm::InputTag(digiProducer_, digiCollection_))),
49  dccToken_(consumes<EcalRawDataCollection>(edm::InputTag(digiProducer_)))
50 
51 //========================================================================
52 {
53  //now do what ever initialization is needed
54 }
55 
56 //========================================================================
58  //========================================================================
59 
60  //Initializations
61 
62  IsFileCreated = 0;
63  IsTreeCreated = 0;
64 }
65 
66 //========================================================================
68  //========================================================================
69 
70  ++iEvent;
71 
72  // retrieving MATACQ :
73  const edm::Handle<EcalMatacqDigiCollection>& pmatacqDigi = e.getHandle(pmatToken_);
74  const EcalMatacqDigiCollection* matacqDigi = (pmatacqDigi.isValid()) ? pmatacqDigi.product() : nullptr;
75  if (!(pmatacqDigi.isValid()))
76  edm::LogWarning("EcalPerEvtMatacqAnalyzer") << "Error! can't get the product " << digiCollection_.c_str();
77 
78  // retrieving DCC header
79 
80  const edm::Handle<EcalRawDataCollection>& pDCCHeader = e.getHandle(dccToken_);
81  const EcalRawDataCollection* DCCHeader = (pDCCHeader.isValid()) ? pDCCHeader.product() : nullptr;
82  if (!pDCCHeader.isValid())
83  edm::LogWarning("EcalPerEvtMatacqAnalyzer") << "Error! can't get the product " << eventHeaderCollection_.c_str();
84 
85  // ====================================
86  // Decode Basic DCCHeader Information
87  // ====================================
88 
89  for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
90  ++headerItr) {
91  event = headerItr->getLV1();
92  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
93 
94  laser_color = (int)settings.wavelength;
95 
96  // Get run type and run number
97 
98  runType = headerItr->getRunType();
99  runNum = headerItr->getRunNumber();
100 
101  // Cut on runType
102 
105  return;
106 
107  // Define output results files' names
108 
109  if (IsFileCreated == 0) {
110  std::stringstream namefile;
111 
112  namefile << resdir_ << "/MatacqPerEvt-Run" << runNum << ".root";
113  outfile = namefile.str();
114 
115  outFile = new TFile(outfile.c_str(), "RECREATE");
116 
117  // declaration of the tree to fill
118 
119  tree = new TTree("MatacqTree", "MatacqTree");
120 
121  IsFileCreated = 1;
122  }
123  }
124 
125  // ===========================
126  // Decode Matacq Information
127  // ===========================
128 
129  int iCh = 0;
130  double max = 0;
131 
132  for (EcalMatacqDigiCollection::const_iterator it = matacqDigi->begin(); it != matacqDigi->end();
133  ++it) { // Loop on matacq channel
134 
135  //
136  const EcalMatacqDigi& digis = *it;
137 
138  if (digis.size() == 0 || iCh >= N_channels)
139  continue;
140 
141  max = 0;
142  maxsamp = 0;
143  nsamples = digis.size();
144 
145  if (IsTreeCreated == 0) {
146  //List of branches
147 
148  std::stringstream mat;
149  mat << "matacq[" << nsamples << "]/D" << std::endl;
150 
151  tree->Branch("event", &event, "event/I");
152  tree->Branch("laser_color", &laser_color, "laser_color/I");
153  // tree->Branch( "nsamples", &nsamples , "nsamples/I" );
154  tree->Branch("matacq", &matacq, mat.str().c_str());
155  tree->Branch("maxsamp", &maxsamp, "maxsamp/I");
156  tree->Branch("ttrig", &ttrig, "ttrig/D");
157 
158  tree->SetBranchAddress("event", &event);
159  tree->SetBranchAddress("laser_color", &laser_color);
160  tree->SetBranchAddress("matacq", matacq);
161  // tree->SetBranchAddress( "nsamples", &nsamples );
162  tree->SetBranchAddress("maxsamp", &maxsamp);
163  tree->SetBranchAddress("ttrig", &ttrig);
164 
165  IsTreeCreated = 1;
166  }
167 
168  ttrig = digis.tTrig();
169 
170  for (int i = 0; i < digis.size(); ++i) { // Loop on matacq samples
171  matacq[i] = digis.adcCount(i);
172  if (matacq[i] > max) {
173  max = matacq[i];
174  maxsamp = i;
175  }
176  }
177 
178  iCh++;
179  }
180 
181  tree->Fill();
182 
183 } // analyze
184 
185 //========================================================================
187  tree->Write();
188  outFile->Close();
189 }
190 
const edm::EDGetTokenT< EcalRawDataCollection > dccToken_
T const * product() const
Definition: Handle.h:70
std::vector< T >::const_iterator const_iterator
void analyze(const edm::Event &e, const edm::EventSetup &c) override
float adcCount(const int &i) const
#define N_channels
int iEvent
Definition: GenABIO.cc:224
EcalPerEvtMatacqAnalyzer(const edm::ParameterSet &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
float tTrig() const
const_iterator end() const
const std::string eventHeaderCollection_
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
int size() const
Definition: tree.py:1
Log< level::Warning, false > LogWarning
const edm::EDGetTokenT< EcalMatacqDigiCollection > pmatToken_
Definition: event.py:1