CMS 3D CMS Logo

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