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 
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 
EcalPerEvtMatacqAnalyzer::laser_color
int laser_color
Definition: EcalPerEvtMatacqAnalyzer.h:40
EcalPerEvtMatacqAnalyzer::EcalPerEvtMatacqAnalyzer
EcalPerEvtMatacqAnalyzer(const edm::ParameterSet &iConfig)
Definition: EcalPerEvtMatacqAnalyzer.cc:33
mps_fire.i
i
Definition: mps_fire.py:355
EcalPerEvtMatacqAnalyzer::nsamples
unsigned int nsamples
Definition: EcalPerEvtMatacqAnalyzer.h:43
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EcalMatacqDigi
Definition: EcalMatacqDigi.h:16
EcalPerEvtMatacqAnalyzer::runType
int runType
Definition: EcalPerEvtMatacqAnalyzer.h:34
N_channels
#define N_channels
Definition: EcalMatacqAnalyzer.h:11
tree
Definition: tree.py:1
EcalDetIdCollections.h
edm::SortedCollection
Definition: SortedCollection.h:49
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EcalPerEvtMatacqAnalyzer::runNum
int runNum
Definition: EcalPerEvtMatacqAnalyzer.h:35
edm::Handle
Definition: AssociativeIterator.h:50
EcalPerEvtMatacqAnalyzer::outFile
TFile * outFile
Definition: EcalPerEvtMatacqAnalyzer.h:50
EcalPerEvtMatacqAnalyzer::outfile
std::string outfile
Definition: EcalPerEvtMatacqAnalyzer.h:28
EcalPerEvtMatacqAnalyzer.h
EcalPerEvtMatacqAnalyzer::digiCollection_
std::string digiCollection_
Definition: EcalPerEvtMatacqAnalyzer.h:23
EcalPerEvtMatacqAnalyzer::digiProducer_
std::string digiProducer_
Definition: EcalPerEvtMatacqAnalyzer.h:24
EcalDCCHeaderBlock::LASER_GAP
Definition: EcalDCCHeaderBlock.h:42
EcalMatacqDigi::adcCount
const float adcCount(const int &i) const
Definition: EcalMatacqDigi.h:53
EcalPerEvtMatacqAnalyzer::~EcalPerEvtMatacqAnalyzer
~EcalPerEvtMatacqAnalyzer() override
Definition: EcalPerEvtMatacqAnalyzer.cc:62
EcalRawDataCollections.h
MakerMacros.h
EcalDCCHeaderBlock::LASER_STD
Definition: EcalDCCHeaderBlock.h:26
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
EcalPerEvtMatacqAnalyzer::endJob
void endJob() override
Definition: EcalPerEvtMatacqAnalyzer.cc:208
EcalPerEvtMatacqAnalyzer::eventHeaderProducer_
std::string eventHeaderProducer_
Definition: EcalPerEvtMatacqAnalyzer.h:26
EcalDigiCollections.h
EcalMatacqDigi::size
int size() const
Definition: EcalMatacqDigi.h:75
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalDCCHeaderBlock::LASER_POWER_SCAN
Definition: EcalDCCHeaderBlock.h:27
EcalDCCHeaderBlock::EcalDCCEventSettings
Definition: EcalDCCHeaderBlock.h:64
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
EcalPerEvtMatacqAnalyzer::resdir_
std::string resdir_
Definition: EcalPerEvtMatacqAnalyzer.h:22
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
EcalPerEvtMatacqAnalyzer::eventHeaderCollection_
std::string eventHeaderCollection_
Definition: EcalPerEvtMatacqAnalyzer.h:25
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
EcalPerEvtMatacqAnalyzer::iEvent
int iEvent
Definition: EcalPerEvtMatacqAnalyzer.h:30
EcalMatacqDigi::tTrig
float tTrig() const
Definition: EcalMatacqDigi.h:105
EcalPerEvtMatacqAnalyzer::beginJob
void beginJob() override
Definition: EcalPerEvtMatacqAnalyzer.cc:70
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
std
Definition: JetResolutionObject.h:76
EcalDCCHeaderBlock::EcalDCCEventSettings::wavelength
short wavelength
Definition: EcalDCCHeaderBlock.h:67
EcalDCCHeaderBlock::LASER_DELAY_SCAN
Definition: EcalDCCHeaderBlock.h:28
EventSetup.h
EcalPerEvtMatacqAnalyzer
Definition: EcalPerEvtMatacqAnalyzer.h:12
Exception.h
EcalPerEvtMatacqAnalyzer::matacq
double matacq[2560]
Definition: EcalPerEvtMatacqAnalyzer.h:41
EcalPerEvtMatacqAnalyzer::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: EcalPerEvtMatacqAnalyzer.cc:80
ParameterSet.h
EcalPerEvtMatacqAnalyzer::IsTreeCreated
int IsTreeCreated
Definition: EcalPerEvtMatacqAnalyzer.h:49
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
EcalPerEvtMatacqAnalyzer::ttrig
double ttrig
Definition: EcalPerEvtMatacqAnalyzer.h:52
EcalPerEvtMatacqAnalyzer::IsFileCreated
int IsFileCreated
Definition: EcalPerEvtMatacqAnalyzer.h:48
EcalPerEvtMatacqAnalyzer::maxsamp
unsigned int maxsamp
Definition: EcalPerEvtMatacqAnalyzer.h:42
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37