CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
29 
30 using namespace std;
31 
32 //========================================================================
34  : iEvent(0),
35  // framework parameters with default values
36 
37  _presample(iConfig.getUntrackedParameter<double>("nPresamples", 6.7)),
38  _nsamplesaftmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesAftMax", 80)),
39  _nsamplesbefmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesBefMax", 20)),
40  _noiseCut(iConfig.getUntrackedParameter<unsigned int>("noiseCut", 7)),
41  _parabnbefmax(iConfig.getUntrackedParameter<unsigned int>("paraBeforeMax", 8)),
42  _parabnaftmax(iConfig.getUntrackedParameter<unsigned int>("paraAfterMax", 7)),
43  _thres(iConfig.getUntrackedParameter<unsigned int>("threshold", 10)),
44  _lowlev(iConfig.getUntrackedParameter<unsigned int>("lowLevel", 20)),
45  _highlev(iConfig.getUntrackedParameter<unsigned int>("highLevel", 80)),
46  _nevlasers(iConfig.getUntrackedParameter<unsigned int>("nEventLaser", 600))
47 
48 //========================================================================
49 {
50  //now do what ever initialization is needed
51 
52  resdir_ = iConfig.getUntrackedParameter<std::string>("resDir");
53 
54  digiCollection_ = iConfig.getParameter<std::string>("digiCollection");
55  digiProducer_ = iConfig.getParameter<std::string>("digiProducer");
56 
57  eventHeaderCollection_ = iConfig.getParameter<std::string>("eventHeaderCollection");
58  eventHeaderProducer_ = iConfig.getParameter<std::string>("eventHeaderProducer");
59 }
60 
61 //========================================================================
63  //========================================================================
64 
65  // do anything here that needs to be done at desctruction time
66  // (e.g. close files, deallocate resources etc.)
67 }
68 
69 //========================================================================
71  //========================================================================
72 
73  //Initializations
74 
75  IsFileCreated = 0;
76  IsTreeCreated = 0;
77 }
78 
79 //========================================================================
81  //========================================================================
82 
83  ++iEvent;
84 
85  // retrieving MATACQ :
87  const EcalMatacqDigiCollection* matacqDigi = nullptr;
88  try {
89  e.getByLabel(digiProducer_, digiCollection_, pmatacqDigi);
90  matacqDigi = pmatacqDigi.product();
91  } catch (std::exception& ex) {
92  std::cerr << "Error! can't get the product " << digiCollection_.c_str() << std::endl;
93  }
94 
95  // retrieving DCC header
96 
98  const EcalRawDataCollection* DCCHeader = nullptr;
99  try {
100  e.getByLabel(digiProducer_, pDCCHeader);
101  //e.getByLabel(eventHeaderProducer_,eventHeaderCollection_, pDCCHeader);
102  DCCHeader = pDCCHeader.product();
103  } catch (std::exception& ex) {
104  std::cerr << "Error! can't get the product " << eventHeaderCollection_.c_str() << std::endl;
105  }
106 
107  // ====================================
108  // Decode Basic DCCHeader Information
109  // ====================================
110 
111  for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
112  ++headerItr) {
113  event = headerItr->getLV1();
114  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
115 
116  laser_color = (int)settings.wavelength;
117 
118  // Get run type and run number
119 
120  runType = headerItr->getRunType();
121  runNum = headerItr->getRunNumber();
122 
123  // Cut on runType
124 
127  return;
128 
129  // Define output results files' names
130 
131  if (IsFileCreated == 0) {
132  stringstream namefile;
133 
134  namefile << resdir_ << "/MatacqPerEvt-Run" << runNum << ".root";
135  outfile = namefile.str();
136 
137  outFile = new TFile(outfile.c_str(), "RECREATE");
138 
139  // declaration of the tree to fill
140 
141  tree = new TTree("MatacqTree", "MatacqTree");
142 
143  IsFileCreated = 1;
144  }
145  }
146 
147  // ===========================
148  // Decode Matacq Information
149  // ===========================
150 
151  int iCh = 0;
152  double max = 0;
153 
154  for (EcalMatacqDigiCollection::const_iterator it = matacqDigi->begin(); it != matacqDigi->end();
155  ++it) { // Loop on matacq channel
156 
157  //
158  const EcalMatacqDigi& digis = *it;
159 
160  if (digis.size() == 0 || iCh >= N_channels)
161  continue;
162 
163  max = 0;
164  maxsamp = 0;
165  nsamples = digis.size();
166 
167  if (IsTreeCreated == 0) {
168  //List of branches
169 
170  stringstream mat;
171  mat << "matacq[" << nsamples << "]/D" << endl;
172 
173  tree->Branch("event", &event, "event/I");
174  tree->Branch("laser_color", &laser_color, "laser_color/I");
175  // tree->Branch( "nsamples", &nsamples , "nsamples/I" );
176  tree->Branch("matacq", &matacq, mat.str().c_str());
177  tree->Branch("maxsamp", &maxsamp, "maxsamp/I");
178  tree->Branch("ttrig", &ttrig, "ttrig/D");
179 
180  tree->SetBranchAddress("event", &event);
181  tree->SetBranchAddress("laser_color", &laser_color);
182  tree->SetBranchAddress("matacq", matacq);
183  // tree->SetBranchAddress( "nsamples", &nsamples );
184  tree->SetBranchAddress("maxsamp", &maxsamp);
185  tree->SetBranchAddress("ttrig", &ttrig);
186 
187  IsTreeCreated = 1;
188  }
189 
190  ttrig = digis.tTrig();
191 
192  for (int i = 0; i < digis.size(); ++i) { // Loop on matacq samples
193  matacq[i] = digis.adcCount(i);
194  if (matacq[i] > max) {
195  max = matacq[i];
196  maxsamp = i;
197  }
198  }
199 
200  iCh++;
201  }
202 
203  tree->Fill();
204 
205 } // analyze
206 
207 //========================================================================
209  tree->Write();
210  outFile->Close();
211 }
212 
T getUntrackedParameter(std::string const &, T const &) const
const edm::EventSetup & c
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< T >::const_iterator const_iterator
float tTrig() const
float adcCount(const int &i) const
void analyze(const edm::Event &e, const edm::EventSetup &c) override
#define N_channels
int iEvent
Definition: GenABIO.cc:224
EcalPerEvtMatacqAnalyzer(const edm::ParameterSet &iConfig)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
const_iterator end() const
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
int size() const
const_iterator begin() const