CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
EcalMatacqAnalyzer Class Reference

#include <EcalMatacqAnalyzer.h>

Inheritance diagram for EcalMatacqAnalyzer:
edm::EDAnalyzer edm::EDConsumerBase

Public Types

enum  VarCol { iBlue, iRed, nColor }
 
enum  VarSide { iSide0, iSide1, nSide }
 
- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c) override
 
void beginJob () override
 
 EcalMatacqAnalyzer (const edm::ParameterSet &iConfig)
 
void endJob () override
 
 ~EcalMatacqAnalyzer () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

double _cutwindow
 
int _debug
 
int _fedid
 
unsigned int _highlev
 
unsigned int _lowlev
 
unsigned int _nevlasers
 
unsigned int _noiseCut
 
unsigned int _nsamplesaftmax
 
unsigned int _nsamplesshape
 
unsigned int _parabnaftmax
 
unsigned int _parabnbefmax
 
double _presample
 
unsigned int _presampleshape
 
unsigned int _slide
 
unsigned int _thres
 
unsigned int _timeaftmax
 
unsigned int _timebefmax
 
double ampl
 
int color
 
std::vector< int > colors
 
int dccID
 
std::string digiCollection_
 
std::string digiProducer_
 
int event
 
std::string eventHeaderCollection_
 
std::string eventHeaderProducer_
 
int fedID
 
double fit
 
double fw20
 
double fw80
 
double fwhm
 
int iEvent
 
bool isThereMatacq
 
int laserEvents
 
int lightside
 
double matacq [2560]
 
int maxsamp
 
TTree * meanTree [nColor]
 
TMTQMTQ [nColor][nSide]
 
TTree * mtqShape
 
int nsamples
 
unsigned int nSides
 
std::string outfile
 
TFile * outFile
 
double peak
 
double ped
 
double pedsig
 
std::string resdir_
 
int runNum
 
int runType
 
std::string sampfile
 
TFile * sampFile
 
double sigma
 
double sliding
 
int status
 
TTree * tree
 
double trise
 
double tt
 
double ttrig
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 14 of file EcalMatacqAnalyzer.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

EcalMatacqAnalyzer::EcalMatacqAnalyzer ( const edm::ParameterSet iConfig)
explicit

Definition at line 38 of file EcalMatacqAnalyzer.cc.

References digiCollection_, digiProducer_, eventHeaderCollection_, eventHeaderProducer_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), resdir_, and AlCaHLTBitMon_QueryRunRegistry::string.

40  :
41 
42  iEvent(0),
43 
44  // framework parameters with default values
45 
46  _presample(iConfig.getUntrackedParameter<double>("nPresamples", 6.7)),
47  _nsamplesaftmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesAftMax", 80)),
48  _noiseCut(iConfig.getUntrackedParameter<unsigned int>("noiseCut", 7)),
49  _parabnbefmax(iConfig.getUntrackedParameter<unsigned int>("paraBeforeMax", 8)),
50  _parabnaftmax(iConfig.getUntrackedParameter<unsigned int>("paraAfterMax", 7)),
51  _thres(iConfig.getUntrackedParameter<unsigned int>("threshold", 10)),
52  _lowlev(iConfig.getUntrackedParameter<unsigned int>("lowLevel", 20)),
53  _highlev(iConfig.getUntrackedParameter<unsigned int>("highLevel", 80)),
54  _nevlasers(iConfig.getUntrackedParameter<unsigned int>("nEventLaser", 600)),
55  _timebefmax(iConfig.getUntrackedParameter<unsigned int>("timeBefMax", 100)),
56  _timeaftmax(iConfig.getUntrackedParameter<unsigned int>("timeAftMax", 250)),
57  _cutwindow(iConfig.getUntrackedParameter<double>("cutWindow", 0.1)),
58  _nsamplesshape(iConfig.getUntrackedParameter<unsigned int>("nSamplesShape", 250)),
59  _presampleshape(iConfig.getUntrackedParameter<unsigned int>("nPresamplesShape", 50)),
60  _slide(iConfig.getUntrackedParameter<unsigned int>("nSlide", 100)),
61  _fedid(iConfig.getUntrackedParameter<int>("fedID", -999)),
62  _debug(iConfig.getUntrackedParameter<int>("debug", 0)),
63  nSides(NSIDES),
64  lightside(0),
65  runType(-1),
66  runNum(0),
67  event(0),
68  color(-1),
69  maxsamp(0),
70  nsamples(0),
71  tt(0)
72 
73 //========================================================================
74 {
75  //now do what ever initialization is needed
76 
77  resdir_ = iConfig.getUntrackedParameter<std::string>("resDir");
78 
79  digiCollection_ = iConfig.getParameter<std::string>("digiCollection");
80  digiProducer_ = iConfig.getParameter<std::string>("digiProducer");
81 
82  eventHeaderCollection_ = iConfig.getParameter<std::string>("eventHeaderCollection");
83  eventHeaderProducer_ = iConfig.getParameter<std::string>("eventHeaderProducer");
84 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
#define NSIDES
unsigned int _presampleshape
unsigned int _nsamplesshape
std::string eventHeaderProducer_
unsigned int _timebefmax
std::string eventHeaderCollection_
unsigned int _parabnaftmax
unsigned int _timeaftmax
std::string digiCollection_
unsigned int _nsamplesaftmax
unsigned int _parabnbefmax
EcalMatacqAnalyzer::~EcalMatacqAnalyzer ( )
override

Definition at line 87 of file EcalMatacqAnalyzer.cc.

87  {
88  //========================================================================
89 
90  // do anything here that needs to be done at desctruction time
91  // (e.g. close files, deallocate resources etc.)
92 }

Member Function Documentation

void EcalMatacqAnalyzer::analyze ( const edm::Event e,
const edm::EventSetup c 
)
override

Definition at line 139 of file EcalMatacqAnalyzer.cc.

References _debug, _fedid, EcalMatacqDigi::adcCount(), edm::SortedCollection< T, SORT >::begin(), beam_dqm_sourceclient-live_cfg::cerr, color, gather_cfg::cout, dccID, digiCollection_, digiProducer_, edm::SortedCollection< T, SORT >::end(), eventHeaderCollection_, eventHeaderProducer_, cppFunctionSkipper::exception, fedID, spr::find(), edm::Event::getByLabel(), mps_fire::i, iEvent, createfilelist::int, isThereMatacq, EcalDCCHeaderBlock::LASER_DELAY_SCAN, EcalDCCHeaderBlock::LASER_GAP, EcalDCCHeaderBlock::LASER_POWER_SCAN, EcalDCCHeaderBlock::LASER_STD, laserEvents, lightside, matacq, SiStripPI::max, maxsamp, nsamples, edm::Handle< T >::product(), runNum, runType, EcalMatacqDigi::size(), tt, EcalMatacqDigi::tTrig(), and EcalDCCHeaderBlock::EcalDCCEventSettings::wavelength.

139  {
140  //========================================================================
141 
142  ++iEvent;
143 
144  if (_debug == 1)
145  std::cout << "-- debug test -- Entering Analyze -- event= " << iEvent << std::endl;
146 
147  // retrieving MATACQ :
149  const EcalMatacqDigiCollection* matacqDigi = nullptr;
150  try {
151  e.getByLabel(digiProducer_, digiCollection_, pmatacqDigi);
152  matacqDigi = pmatacqDigi.product();
153  if (_debug == 1)
154  std::cout << "-- debug test -- Matacq Digis Found -- " << std::endl;
155 
156  } catch (std::exception& ex) {
157  std::cerr << "Error! can't get the product EcalMatacqDigi producer:" << digiProducer_.c_str()
158  << " collection:" << digiCollection_.c_str() << std::endl;
159  if (_debug == 1)
160  std::cout << "-- debug test -- No Matacq Digis Found -- " << std::endl;
161  return;
162  }
163 
164  // retrieving DCC header
165 
167  const EcalRawDataCollection* DCCHeader = nullptr;
168  try {
170  DCCHeader = pDCCHeader.product();
171  } catch (std::exception& ex) {
172  std::cerr << "Error! can't get the product EcalRawData producer:" << eventHeaderProducer_.c_str()
173  << " collection:" << eventHeaderCollection_.c_str() << std::endl;
174  return;
175  }
176 
177  // ====================================
178  // Decode Basic DCCHeader Information
179  // ====================================
180 
181  if (_debug == 1)
182  std::cout << "-- debug test -- Before header -- " << std::endl;
183 
184  for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
185  ++headerItr) {
186  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
187  color = (int)settings.wavelength;
188  if (color < 0)
189  return;
190 
191  // Get run type and run number
192 
193  int fed = headerItr->fedId();
194 
195  if (fed != _fedid && _fedid != -999)
196  continue;
197 
198  runType = headerItr->getRunType();
199  runNum = headerItr->getRunNumber();
200  event = headerItr->getLV1();
201 
202  if (_debug == 1)
203  std::cout << "-- debug test -- runtype:" << runType << " event:" << event << " runNum:" << runNum << std::endl;
204 
205  dccID = headerItr->getDccInTCCCommand();
206  fedID = headerItr->fedId();
207  lightside = headerItr->getRtHalf();
208 
209  //assert (lightside<2 && lightside>=0);
210 
211  if (lightside != 1 && lightside != 0) {
212  std::cout << "Unexpected lightside: " << lightside << " for event " << iEvent << std::endl;
213  return;
214  }
215  if (_debug == 1) {
216  std::cout << "-- debug test -- Inside header before fed cut -- color=" << color << ", dcc=" << dccID
217  << ", fed=" << fedID << ", lightside=" << lightside << ", runType=" << runType << std::endl;
218  }
219 
220  // take event only if the fed corresponds to the DCC in TCC
221  if (600 + dccID != fedID)
222  continue;
223 
224  if (_debug == 1) {
225  std::cout << "-- debug test -- Inside header after fed cut -- color=" << color << ", dcc=" << dccID
226  << ", fed=" << fedID << ", lightside=" << lightside << ", runType=" << runType << std::endl;
227  }
228 
229  // Cut on runType
230 
233  return;
234 
235  std::vector<int>::iterator iter = find(colors.begin(), colors.end(), color);
236  if (iter == colors.end()) {
237  colors.push_back(color);
238  std::cout << " new color found " << color << " " << colors.size() << std::endl;
239  }
240  }
241 
242  if (_debug == 1)
243  std::cout << "-- debug test -- Before digis -- Event:" << iEvent << std::endl;
244 
245  // Count laser events
246  laserEvents++;
247 
248  // ===========================
249  // Decode Matacq Information
250  // ===========================
251 
252  int iCh = 0;
253  double max = 0;
254 
255  for (EcalMatacqDigiCollection::const_iterator it = matacqDigi->begin(); it != matacqDigi->end();
256  ++it) { // Loop on matacq channel
257 
258  //
259  const EcalMatacqDigi& digis = *it;
260 
261  //if(digis.size()==0 || iCh>=N_channels) continue;
262  if (_debug == 1) {
263  std::cout << "-- debug test -- Inside digis -- digi size=" << digis.size() << std::endl;
264  }
265 
266  if (digis.size() == 0)
267  continue;
268  else
269  isThereMatacq = true;
270 
271  max = 0;
272  maxsamp = 0;
273  nsamples = digis.size();
274  tt = digis.tTrig();
275 
276  for (int i = 0; i < digis.size(); ++i) { // Loop on matacq samples
277  matacq[i] = -digis.adcCount(i);
278  if (matacq[i] > max) {
279  max = matacq[i];
280  maxsamp = i;
281  }
282  }
283  if (_debug == 1) {
284  std::cout << "-- debug test -- Inside digis -- nsamples=" << nsamples << ", max=" << max << std::endl;
285  }
286 
287  iCh++;
288  }
289 
290  if (_debug == 1)
291  std::cout << "-- debug test -- After digis -- Event: " << iEvent << std::endl;
292  tree->Fill();
293 
294 } // analyze
std::vector< T >::const_iterator const_iterator
float tTrig() const
std::string eventHeaderProducer_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const float adcCount(const int &i) const
std::string eventHeaderCollection_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
const_iterator end() const
T const * product() const
Definition: Handle.h:69
int size() const
Definition: colors.py:1
Definition: tree.py:1
std::string digiCollection_
const_iterator begin() const
void EcalMatacqAnalyzer::beginJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 95 of file EcalMatacqAnalyzer.cc.

References color, isThereMatacq, laserEvents, lightside, matacq, maxsamp, nsamples, outfile, resdir_, sampfile, sampFile, and tt.

95  {
96  //========================================================================
97 
98  // Define temporary file name
99 
100  sampfile = resdir_;
101  sampfile += "/TmpTreeMatacqAnalyzer.root";
102 
103  sampFile = new TFile(sampfile.c_str(), "RECREATE");
104 
105  // declaration of the tree to fill
106 
107  tree = new TTree("MatacqTree", "MatacqTree");
108 
109  //List of branches
110 
111  tree->Branch("event", &event, "event/I");
112  tree->Branch("color", &color, "color/I");
113  tree->Branch("matacq", &matacq, "matacq[2560]/D");
114  tree->Branch("nsamples", &nsamples, "nsamples/I");
115  tree->Branch("maxsamp", &maxsamp, "maxsamp/I");
116  tree->Branch("tt", &tt, "tt/D");
117  tree->Branch("lightside", &lightside, "lightside/I");
118 
119  tree->SetBranchAddress("event", &event);
120  tree->SetBranchAddress("color", &color);
121  tree->SetBranchAddress("matacq", matacq);
122  tree->SetBranchAddress("nsamples", &nsamples);
123  tree->SetBranchAddress("maxsamp", &maxsamp);
124  tree->SetBranchAddress("tt", &tt);
125  tree->SetBranchAddress("lightside", &lightside);
126 
127  // Define output results files' names
128 
129  std::stringstream namefile;
130  namefile << resdir_ << "/MATACQ.root";
131  outfile = namefile.str();
132 
133  // Laser events counter
134  laserEvents = 0;
135  isThereMatacq = false;
136 }
Definition: tree.py:1
Definition: event.py:1
void EcalMatacqAnalyzer::endJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 297 of file EcalMatacqAnalyzer.cc.

References _cutwindow, _debug, _highlev, _lowlev, _nevlasers, _noiseCut, _nsamplesaftmax, _nsamplesshape, _parabnaftmax, _parabnbefmax, _presample, _presampleshape, _slide, _thres, _timeaftmax, _timebefmax, testProducerWithPsetDescEmpty_cfi::a2, ampl, color, TMatacq::compute_trise(), gather_cfg::cout, DEFINE_FWK_MODULE, TMatacq::doFit(), TMatacq::findPeak(), fw20, fw80, fwhm, TMTQ::get(), TMatacq::getAmpl(), TMatacq::getBaseLine(), TMatacq::getFwhm(), TMatacq::getsigBaseLine(), TMatacq::getsigTimpeak(), TMatacq::getSlide(), TMatacq::getTimax(), TMatacq::getTimpeak(), TMatacq::getTrise(), TMatacq::getWidth20(), TMatacq::getWidth80(), mps_fire::i, TMTQ::iAmpl, TMTQ::iFit, TMTQ::iFw20, TMTQ::iFw80, TMTQ::iFwhm, createfilelist::int, TMTQ::iPeak, TMTQ::iPed, TMTQ::iPedsig, TMTQ::iSigma, TMTQ::iSlide, isThereMatacq, TMTQ::iTrise, lightside, matacq, maxsamp, meanTree, MTQ, mtqShape, nColor, TMTQ::nOutVar, nsamples, nSide, nSides, outfile, outFile, peak, ped, pedsig, q1, q2, TMatacq::rawPulseAnalysis(), sampfile, sampFile, sigma, sliding, status, ctpps_dqm_sourceclient-live_cfg::test, trise, tt, ttrig, and heppy_batch::val.

Referenced by o2olib.O2ORunMgr::executeJob().

297  {
298  // Don't do anything if there is no events
299  if (!isThereMatacq) {
300  std::cout << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" << std::endl;
301  std::cout << "\t+=+ WARNING! NO MATACQ +=+" << std::endl;
302  std::cout << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" << std::endl;
303 
304  // Remove temporary file
305  FILE* test;
306  test = fopen(sampfile.c_str(), "r");
307  if (test) {
308  std::stringstream del2;
309  del2 << "rm " << sampfile;
310  system(del2.str().c_str());
311  }
312  return;
313  }
314 
315  assert(colors.size() <= nColor);
316  unsigned int nCol = colors.size();
317 
318  for (unsigned int iCol = 0; iCol < nCol; iCol++) {
319  for (unsigned int iSide = 0; iSide < nSide; iSide++) {
320  MTQ[iCol][iSide] = new TMTQ();
321  }
322  }
323 
324  outFile = new TFile(outfile.c_str(), "RECREATE");
325 
326  TProfile* shapeMat = new TProfile("shapeLaser", "shapeLaser", _nsamplesshape, -0.5, double(_nsamplesshape) - 0.5);
327  TProfile* shapeMatTmp = new TProfile(
328  "shapeLaserTmp", "shapeLaserTmp", _timeaftmax + _timebefmax, -0.5, double(_timeaftmax + _timebefmax) - 0.5);
329 
330  std::cout << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" << std::endl;
331  std::cout << "\t+=+ Analyzing MATACQ data +=+" << std::endl;
332 
333  //
334  // create output ntuple
335  //
336 
337  mtqShape = new TTree("MatacqShape", "MatacqShape");
338 
339  // list of branches
340  // keep Patrice's notations
341 
342  mtqShape->Branch("event", &event, "event/I");
343  mtqShape->Branch("color", &color, "color/I");
344  mtqShape->Branch("status", &status, "status/I");
345  mtqShape->Branch("peak", &peak, "peak/D");
346  mtqShape->Branch("sigma", &sigma, "sigma/D");
347  mtqShape->Branch("fit", &fit, "fit/D");
348  mtqShape->Branch("ampl", &ampl, "ampl/D");
349  mtqShape->Branch("trise", &trise, "trise/D");
350  mtqShape->Branch("fwhm", &fwhm, "fwhm/D");
351  mtqShape->Branch("fw20", &fw20, "fw20/D");
352  mtqShape->Branch("fw80", &fw80, "fw80/D");
353  mtqShape->Branch("ped", &ped, "ped/D");
354  mtqShape->Branch("pedsig", &pedsig, "pedsig/D");
355  mtqShape->Branch("ttrig", &ttrig, "ttrig/D");
356  mtqShape->Branch("sliding", &sliding, "sliding/D");
357 
358  mtqShape->SetBranchAddress("event", &event);
359  mtqShape->SetBranchAddress("color", &color);
360  mtqShape->SetBranchAddress("status", &status);
361  mtqShape->SetBranchAddress("peak", &peak);
362  mtqShape->SetBranchAddress("sigma", &sigma);
363  mtqShape->SetBranchAddress("fit", &fit);
364  mtqShape->SetBranchAddress("ampl", &ampl);
365  mtqShape->SetBranchAddress("fwhm", &fwhm);
366  mtqShape->SetBranchAddress("fw20", &fw20);
367  mtqShape->SetBranchAddress("fw80", &fw80);
368  mtqShape->SetBranchAddress("trise", &trise);
369  mtqShape->SetBranchAddress("ped", &ped);
370  mtqShape->SetBranchAddress("pedsig", &pedsig);
371  mtqShape->SetBranchAddress("ttrig", &ttrig);
372  mtqShape->SetBranchAddress("sliding", &sliding);
373 
374  unsigned int endsample;
375  unsigned int presample;
376 
377  // loop over the entries of the tree
378  TChain* fChain = (TChain*)tree;
379  Long64_t nentries = fChain->GetEntriesFast();
380  Long64_t nbytes = 0, nb = 0;
381 
382  for (Long64_t jentry = 0; jentry < nentries; jentry++) {
383  // load the event
384  Long64_t ientry = fChain->LoadTree(jentry);
385  if (ientry < 0)
386  break;
387  nb = fChain->GetEntry(jentry);
388  nbytes += nb;
389 
390  status = 0;
391  peak = -1;
392  sigma = 0;
393  fit = -1;
394  ampl = -1;
395  trise = -1;
396  ttrig = tt;
397  fwhm = 0;
398  fw20 = 0;
399  fw80 = 0;
400  ped = 0;
401  pedsig = 0;
402  sliding = 0;
403 
404  if (_debug == 1)
405  std::cout << "-- debug test -- inside loop 1 -- jentry:" << jentry << " over nentries=" << nentries << std::endl;
406 
407  // create the object for Matacq data analysis
408 
409  endsample = maxsamp + _nsamplesaftmax;
410  presample = int(_presample * nsamples / 100.);
411  TMatacq* mtq = new TMatacq(nsamples,
412  presample,
413  endsample,
414  _noiseCut,
417  _thres,
418  _lowlev,
419  _highlev,
420  _nevlasers,
421  _slide);
422 
423  if (_debug == 1)
424  std::cout << "-- debug test -- inside loop 2 -- " << std::endl;
425 
426  // analyse the Matacq data
427  if (mtq->rawPulseAnalysis(nsamples, &matacq[0]) == 0) {
428  status = 1;
429  ped = mtq->getBaseLine();
430  pedsig = mtq->getsigBaseLine();
431 
432  if (_debug == 1)
433  std::cout << "-- debug test -- inside loop 3 -- ped:" << ped << std::endl;
434  if (mtq->findPeak() == 0) {
435  peak = mtq->getTimpeak();
436  sigma = mtq->getsigTimpeak();
437  }
438  if (_debug == 1)
439  std::cout << "-- debug test -- inside loop 4 -- peak:" << peak << std::endl;
440  if (mtq->doFit() == 0) {
441  fit = mtq->getTimax();
442  ampl = mtq->getAmpl();
443  fwhm = mtq->getFwhm();
444  fw20 = mtq->getWidth20();
445  fw80 = mtq->getWidth80();
446  sliding = mtq->getSlide();
447  }
448  if (_debug == 1)
449  std::cout << "-- debug test -- inside loop 4 -- ampl:" << ampl << std::endl;
450  if (mtq->compute_trise() == 0) {
451  trise = mtq->getTrise();
452  }
453  if (_debug == 1)
454  std::cout << "-- debug test -- inside loop 5 -- trise:" << trise << std::endl;
455  }
456 
457  if (_debug == 1)
458  std::cout << "-- debug test -- inside loop 6 -- status:" << status << std::endl;
459 
460  if (status == 1 && mtq->findPeak() == 0) {
461  int firstS = int(peak - double(_timebefmax));
462  int lastS = int(peak + double(_timeaftmax));
463 
464  // Fill histo if there are enough samples
465  if (_debug == 1)
466  std::cout << "-- debug test -- inside loop 7 -- firstS:" << firstS << ", nsamples:" << nsamples << std::endl;
467 
468  if (firstS >= 0 && lastS <= nsamples) {
469  for (int i = firstS; i < lastS; i++) {
470  shapeMatTmp->Fill(double(i) - firstS, matacq[i]);
471  }
472 
473  } else { // else extrapolate
474 
475  int firstSBis;
476 
477  if (firstS < 0) { // fill first bins with 0
478 
479  double thisped;
480  thisped = (matacq[0] + matacq[1] + matacq[2] + matacq[4] + matacq[5]) / 5.0;
481 
482  for (int i = firstS; i < 0; i++) {
483  shapeMatTmp->Fill(double(i) - firstS, thisped);
484  }
485  firstSBis = 0;
486 
487  } else {
488  firstSBis = firstS;
489  }
490 
491  if (lastS > nsamples) {
492  for (int i = firstSBis; i < int(nsamples); i++) {
493  shapeMatTmp->Fill(double(i) - firstS, matacq[i]);
494  }
495 
496  //extrapolate with expo tail
497 
498  double expb = 0.998;
499  double matacqval = expb * matacq[nsamples - 1];
500 
501  for (int i = nsamples; i < lastS; i++) {
502  shapeMatTmp->Fill(double(i) - firstS, matacqval);
503  matacqval *= expb;
504  }
505 
506  } else {
507  for (int i = firstSBis; i < lastS; i++) {
508  shapeMatTmp->Fill(double(i) - firstS, matacq[i]);
509  }
510  }
511  }
512  }
513  if (_debug == 1)
514  std::cout << "-- debug test -- inside loop 8" << std::endl;
515 
516  // get back color
517 
518  int iCol = nCol;
519  for (unsigned int i = 0; i < nCol; i++) {
520  if (color == colors[i]) {
521  iCol = i;
522  i = nCol;
523  }
524  }
525  if (_debug == 1)
526  std::cout << "-- debug test -- inside loop 8bis color:" << color << " iCol:" << iCol << " nCol:" << nCol
527  << std::endl;
528 
529  // fill TMTQ
530 
531  if (status == 1 && mtq->findPeak() == 0 && mtq->doFit() == 0 && mtq->compute_trise() == 0)
532  MTQ[iCol][lightside]->addEntry(peak, sigma, fit, ampl, trise, fwhm, fw20, fw80, ped, pedsig, sliding);
533 
534  // fill the output tree
535 
536  if (_debug == 1)
537  std::cout << "-- debug test -- inside loop 9" << std::endl;
538  mtqShape->Fill();
539 
540  // clean up
541  delete mtq;
542  }
543 
544  if (_debug == 1)
545  std::cout << "-- debug test -- after loop " << std::endl;
546  sampFile->Close();
547 
548  double Peak[6], Sigma[6], Fit[6], Ampl[6], Trise[6], Fwhm[6], Fw20[6], Fw80[6], Ped[6], Pedsig[6], Sliding[6];
549  int Side;
550 
551  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
552  std::stringstream nametree;
553  nametree << "MatacqCol" << colors[iColor];
554  meanTree[iColor] = new TTree(nametree.str().c_str(), nametree.str().c_str());
555  meanTree[iColor]->Branch("side", &Side, "Side/I");
556  meanTree[iColor]->Branch("peak", &Peak, "Peak[6]/D");
557  meanTree[iColor]->Branch("sigma", &Sigma, "Sigma[6]/D");
558  meanTree[iColor]->Branch("fit", &Fit, "Fit[6]/D");
559  meanTree[iColor]->Branch("ampl", &Ampl, "Ampl[6]/D");
560  meanTree[iColor]->Branch("trise", &Trise, "Trise[6]/D");
561  meanTree[iColor]->Branch("fwhm", &Fwhm, "Fwhm[6]/D");
562  meanTree[iColor]->Branch("fw20", &Fw20, "Fw20[6]/D");
563  meanTree[iColor]->Branch("fw80", &Fw80, "Fw80[6]/D");
564  meanTree[iColor]->Branch("ped", &Ped, "Ped[6]/D");
565  meanTree[iColor]->Branch("pedsig", &Pedsig, "Pedsig[6]/D");
566  meanTree[iColor]->Branch("sliding", &Sliding, "Sliding[6]/D");
567 
568  meanTree[iColor]->SetBranchAddress("side", &Side);
569  meanTree[iColor]->SetBranchAddress("peak", Peak);
570  meanTree[iColor]->SetBranchAddress("sigma", Sigma);
571  meanTree[iColor]->SetBranchAddress("fit", Fit);
572  meanTree[iColor]->SetBranchAddress("ampl", Ampl);
573  meanTree[iColor]->SetBranchAddress("fwhm", Fwhm);
574  meanTree[iColor]->SetBranchAddress("fw20", Fw20);
575  meanTree[iColor]->SetBranchAddress("fw80", Fw80);
576  meanTree[iColor]->SetBranchAddress("trise", Trise);
577  meanTree[iColor]->SetBranchAddress("ped", Ped);
578  meanTree[iColor]->SetBranchAddress("pedsig", Pedsig);
579  meanTree[iColor]->SetBranchAddress("sliding", Sliding);
580  }
581 
582  for (unsigned int iCol = 0; iCol < nCol; iCol++) {
583  for (unsigned int iSide = 0; iSide < nSides; iSide++) {
584  Side = iSide;
585  std::vector<double> val[TMTQ::nOutVar];
586 
587  for (int iVar = 0; iVar < TMTQ::nOutVar; iVar++) {
588  val[iVar] = MTQ[iCol][iSide]->get(iVar);
589 
590  for (unsigned int i = 0; i < val[iVar].size(); i++) {
591  switch (iVar) {
592  case TMTQ::iPeak:
593  Peak[i] = val[iVar].at(i);
594  break;
595  case TMTQ::iSigma:
596  Sigma[i] = val[iVar].at(i);
597  break;
598  case TMTQ::iFit:
599  Fit[i] = val[iVar].at(i);
600  break;
601  case TMTQ::iAmpl:
602  Ampl[i] = val[iVar].at(i);
603  break;
604  case TMTQ::iFwhm:
605  Fwhm[i] = val[iVar].at(i);
606  break;
607  case TMTQ::iFw20:
608  Fw20[i] = val[iVar].at(i);
609  break;
610  case TMTQ::iFw80:
611  Fw80[i] = val[iVar].at(i);
612  break;
613  case TMTQ::iTrise:
614  Trise[i] = val[iVar].at(i);
615  break;
616  case TMTQ::iPed:
617  Ped[i] = val[iVar].at(i);
618  break;
619  case TMTQ::iPedsig:
620  Pedsig[i] = val[iVar].at(i);
621  break;
622  case TMTQ::iSlide:
623  Sliding[i] = val[iVar].at(i);
624  break;
625  }
626  }
627  }
628  meanTree[iCol]->Fill();
629  if (_debug == 1)
630  std::cout << "-- debug test -- inside final loop " << std::endl;
631  }
632  }
633 
634  // Calculate maximum with pol 2
635 
636  int im = shapeMatTmp->GetMaximumBin();
637  double q1 = shapeMatTmp->GetBinContent(im - 1);
638  double q2 = shapeMatTmp->GetBinContent(im);
639  double q3 = shapeMatTmp->GetBinContent(im + 1);
640 
641  double a2 = (q3 + q1) / 2.0 - q2;
642  double a1 = q2 - q1 + a2 * (1 - 2 * im);
643  double a0 = q2 - a1 * im - a2 * im * im;
644 
645  double am = a0 - a1 * a1 / (4 * a2);
646 
647  // Compute pedestal
648 
649  double bl = 0;
650  for (unsigned int i = 1; i < _presampleshape + 1; i++) {
651  bl += shapeMatTmp->GetBinContent(i);
652  }
653  bl /= _presampleshape;
654 
655  // Compute and save laser shape
656 
657  if (_debug == 1)
658  std::cout << "-- debug test -- computing shape " << std::endl;
659 
660  int firstBin = 0;
661  double height = 0.0;
662 
663  for (unsigned int i = _timebefmax; i > _presampleshape; i--) {
664  height = shapeMatTmp->GetBinContent(i) - bl;
665 
666  if (height < (am - bl) * _cutwindow) {
667  firstBin = i;
668  i = _presampleshape;
669  }
670  }
671 
672  unsigned int lastBin = firstBin + _nsamplesshape;
673 
674  for (unsigned int i = firstBin; i < lastBin; i++) {
675  shapeMat->Fill(i - firstBin, shapeMatTmp->GetBinContent(i) - bl);
676  }
677 
678  mtqShape->Write();
679  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
680  meanTree[iColor]->Write();
681  }
682  if (_debug == 1)
683  std::cout << "-- debug test -- writing " << std::endl;
684  shapeMat->Write();
685 
686  // close the output file
687  outFile->Close();
688 
689  // Remove temporary file
690  FILE* test;
691  test = fopen(sampfile.c_str(), "r");
692  if (test) {
693  std::stringstream del2;
694  del2 << "rm " << sampfile;
695  system(del2.str().c_str());
696  }
697 
698  std::cout << "\t+=+ .................... done +=+" << std::endl;
699  std::cout << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" << std::endl;
700 }
double getWidth80()
Definition: TMatacq.h:73
Definition: TMTQ.h:8
unsigned int _presampleshape
unsigned int _nsamplesshape
int compute_trise()
Definition: TMatacq.cc:353
double getTimax()
Definition: TMatacq.h:68
TMTQ * MTQ[nColor][nSide]
double getBaseLine()
Definition: TMatacq.h:61
double getsigBaseLine()
Definition: TMatacq.h:62
double q2[4]
Definition: TauolaWrapper.h:88
double getFwhm()
Definition: TMatacq.h:71
TTree * meanTree[nColor]
double getsigTimpeak()
Definition: TMatacq.h:65
unsigned int _timebefmax
double getSlide()
Definition: TMatacq.h:74
Definition: Fit.h:32
std::vector< double > get(int)
Definition: TMTQ.cc:69
int doFit()
Definition: TMatacq.cc:219
double getAmpl()
Definition: TMatacq.h:67
int rawPulseAnalysis(Int_t, Double_t *)
Definition: TMatacq.cc:57
unsigned int _parabnaftmax
double getWidth20()
Definition: TMatacq.h:72
int findPeak()
Definition: TMatacq.cc:136
double q1[4]
Definition: TauolaWrapper.h:87
double getTrise()
Definition: TMatacq.h:70
unsigned int _timeaftmax
Definition: colors.py:1
Definition: TMatacq.h:9
Definition: tree.py:1
unsigned int _nsamplesaftmax
Definition: event.py:1
double getTimpeak()
Definition: TMatacq.h:64
unsigned int _parabnbefmax

Member Data Documentation

double EcalMatacqAnalyzer::_cutwindow
private

Definition at line 44 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

int EcalMatacqAnalyzer::_debug
private
int EcalMatacqAnalyzer::_fedid
private

Definition at line 48 of file EcalMatacqAnalyzer.h.

Referenced by analyze().

unsigned int EcalMatacqAnalyzer::_highlev
private

Definition at line 40 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_lowlev
private

Definition at line 39 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_nevlasers
private

Definition at line 41 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_noiseCut
private

Definition at line 35 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_nsamplesaftmax
private

Definition at line 34 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_nsamplesshape
private

Definition at line 45 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_parabnaftmax
private

Definition at line 37 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_parabnbefmax
private

Definition at line 36 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

double EcalMatacqAnalyzer::_presample
private

Definition at line 33 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_presampleshape
private

Definition at line 46 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_slide
private

Definition at line 47 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_thres
private

Definition at line 38 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_timeaftmax
private

Definition at line 43 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

unsigned int EcalMatacqAnalyzer::_timebefmax
private

Definition at line 42 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

double EcalMatacqAnalyzer::ampl
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

int EcalMatacqAnalyzer::color
private
std::vector<int> EcalMatacqAnalyzer::colors
private

Definition at line 88 of file EcalMatacqAnalyzer.h.

int EcalMatacqAnalyzer::dccID
private

Definition at line 66 of file EcalMatacqAnalyzer.h.

Referenced by analyze().

std::string EcalMatacqAnalyzer::digiCollection_
private

Definition at line 52 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), and EcalMatacqAnalyzer().

std::string EcalMatacqAnalyzer::digiProducer_
private

Definition at line 53 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), and EcalMatacqAnalyzer().

int EcalMatacqAnalyzer::event
private
std::string EcalMatacqAnalyzer::eventHeaderCollection_
private

Definition at line 54 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), and EcalMatacqAnalyzer().

std::string EcalMatacqAnalyzer::eventHeaderProducer_
private

Definition at line 55 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), and EcalMatacqAnalyzer().

int EcalMatacqAnalyzer::fedID
private

Definition at line 67 of file EcalMatacqAnalyzer.h.

Referenced by analyze().

double EcalMatacqAnalyzer::fit
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by trackingPlots.Iteration::modules().

double EcalMatacqAnalyzer::fw20
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

double EcalMatacqAnalyzer::fw80
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

double EcalMatacqAnalyzer::fwhm
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

int EcalMatacqAnalyzer::iEvent
private

Definition at line 27 of file EcalMatacqAnalyzer.h.

Referenced by analyze().

bool EcalMatacqAnalyzer::isThereMatacq
private

Definition at line 71 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), beginJob(), and endJob().

int EcalMatacqAnalyzer::laserEvents
private

Definition at line 70 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), and beginJob().

int EcalMatacqAnalyzer::lightside
private

Definition at line 63 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), beginJob(), and endJob().

double EcalMatacqAnalyzer::matacq[2560]
private

Definition at line 77 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), beginJob(), and endJob().

int EcalMatacqAnalyzer::maxsamp
private

Definition at line 78 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), beginJob(), and endJob().

TTree* EcalMatacqAnalyzer::meanTree[nColor]
private

Definition at line 86 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

TMTQ* EcalMatacqAnalyzer::MTQ[nColor][nSide]
private

Definition at line 85 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

TTree* EcalMatacqAnalyzer::mtqShape
private

Definition at line 93 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

int EcalMatacqAnalyzer::nsamples
private

Definition at line 79 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), beginJob(), and endJob().

unsigned int EcalMatacqAnalyzer::nSides
private

Definition at line 62 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

std::string EcalMatacqAnalyzer::outfile
private

Definition at line 57 of file EcalMatacqAnalyzer.h.

Referenced by beginJob(), and endJob().

TFile* EcalMatacqAnalyzer::outFile
private

Definition at line 90 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

double EcalMatacqAnalyzer::peak
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

double EcalMatacqAnalyzer::ped
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

double EcalMatacqAnalyzer::pedsig
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

std::string EcalMatacqAnalyzer::resdir_
private

Definition at line 51 of file EcalMatacqAnalyzer.h.

Referenced by beginJob(), and EcalMatacqAnalyzer().

int EcalMatacqAnalyzer::runNum
private

Definition at line 65 of file EcalMatacqAnalyzer.h.

Referenced by analyze().

int EcalMatacqAnalyzer::runType
private

Definition at line 64 of file EcalMatacqAnalyzer.h.

Referenced by analyze().

std::string EcalMatacqAnalyzer::sampfile
private

Definition at line 58 of file EcalMatacqAnalyzer.h.

Referenced by beginJob(), and endJob().

TFile* EcalMatacqAnalyzer::sampFile
private

Definition at line 82 of file EcalMatacqAnalyzer.h.

Referenced by beginJob(), and endJob().

double EcalMatacqAnalyzer::sigma
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

double EcalMatacqAnalyzer::sliding
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

int EcalMatacqAnalyzer::status
private
TTree* EcalMatacqAnalyzer::tree
private
double EcalMatacqAnalyzer::trise
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().

double EcalMatacqAnalyzer::tt
private

Definition at line 80 of file EcalMatacqAnalyzer.h.

Referenced by analyze(), beginJob(), and endJob().

double EcalMatacqAnalyzer::ttrig
private

Definition at line 92 of file EcalMatacqAnalyzer.h.

Referenced by endJob().