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