CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
APVCyclePhaseProducerFromL1TS.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: APVCyclePhaseProducerFromL1TS
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Mon Jan 12 09:05:45 CET 2009
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
30 
32 
35 
37 
40 
41 #include <map>
42 #include <vector>
43 #include <string>
44 
45 #include "TH1F.h"
46 #include "TProfile.h"
47 
50 
51 //
52 // class decleration
53 //
54 
56  public:
59 
60 private:
61  virtual void beginJob() ;
62  virtual void beginRun(edm::Run&, const edm::EventSetup&);
63  virtual void endRun(edm::Run&, const edm::EventSetup&);
64  virtual void produce(edm::Event&, const edm::EventSetup&);
65  virtual void endJob() ;
66 
67  // ----------member data ---------------------------
68 
70  const std::vector<std::string> _defpartnames;
71  const std::vector<int> _defphases;
72  const bool _wantHistos;
73  const bool _useEC0;
74  const int _magicOffset;
75 
76  TH1F* _hsize;
77  TH1F* _hlresync;
78  TH1F* _hlOC0;
79  TH1F* _hlTE;
80  TH1F* _hlEC0;
81  TH1F* _hlstart;
82  TH1F* _hlHR;
83 
86 
87  const unsigned int _firstgoodrun;
88 
89  long long _lastResync;
90  long long _lastHardReset;
91  long long _lastStart;
92  long long _lastEventCounter0;
93  long long _lastOrbitCounter0;
94  long long _lastTestEnable;
95 
96 
97 };
98 
99 //
100 // constants, enums and typedefs
101 //
102 
103 
104 //
105 // static data member definitions
106 //
107 
108 //
109 // constructors and destructor
110 //
112  _l1tscollection(iConfig.getParameter<edm::InputTag>("l1TSCollection")),
113  _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
114  _defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
115  _wantHistos(iConfig.getUntrackedParameter<bool>("wantHistos",false)),
116  _useEC0(iConfig.getUntrackedParameter<bool>("useEC0",false)),
117  _magicOffset(iConfig.getUntrackedParameter<int>("magicOffset",8)),
118  _firstgoodrun(131768),
119  _lastResync(-1),_lastHardReset(-1),_lastStart(-1),
120  _lastEventCounter0(-1),_lastOrbitCounter0(-1),_lastTestEnable(-1)
121 {
122 
123  produces<APVCyclePhaseCollection,edm::InEvent>();
124 
125  //now do what ever other initialization is needed
126 
127 }
128 
129 
131 {
132 
133  // do anything here that needs to be done at desctruction time
134  // (e.g. close files, deallocate resources etc.)
135 
136 }
137 
138 
139 //
140 // member functions
141 //
142 
143 // ------------ method called to produce the data ------------
144 void
146 
147 {
148 
149  // reset offset vector
150 
151  if(_wantHistos) {
152 
154 
155  char dirname[300];
156  sprintf(dirname,"run_%d",iRun.run());
157  TFileDirectory subrun = tfserv->mkdir(dirname);
158 
159  _hsize = subrun.make<TH1F>("size","Level1TriggerScalers Collection size",20,-0.5,19.5);
160 
161  _hlresync = subrun.make<TH1F>("lresync","Orbit of last resync",3600,0.,3600*11223);
162  _hlresync->GetXaxis()->SetTitle("Orbit"); _hlresync->GetYaxis()->SetTitle("Events");
163  _hlresync->SetBit(TH1::kCanRebin);
164 
165  _hlOC0 = subrun.make<TH1F>("lOC0","Orbit of last OC0",3600,0.,3600*11223);
166  _hlOC0->GetXaxis()->SetTitle("Orbit"); _hlOC0->GetYaxis()->SetTitle("Events");
167  _hlOC0->SetBit(TH1::kCanRebin);
168 
169  _hlTE = subrun.make<TH1F>("lTE","Orbit of last TestEnable",3600,0.,3600*11223);
170  _hlTE->GetXaxis()->SetTitle("Orbit"); _hlTE->GetYaxis()->SetTitle("Events");
171  _hlTE->SetBit(TH1::kCanRebin);
172 
173  _hlstart = subrun.make<TH1F>("lstart","Orbit of last Start",3600,0.,3600*11223);
174  _hlstart->GetXaxis()->SetTitle("Orbit"); _hlstart->GetYaxis()->SetTitle("Events");
175  _hlstart->SetBit(TH1::kCanRebin);
176 
177  _hlEC0 = subrun.make<TH1F>("lEC0","Orbit of last EC0",3600,0.,3600*11223);
178  _hlEC0->GetXaxis()->SetTitle("Orbit"); _hlEC0->GetYaxis()->SetTitle("Events");
179  _hlEC0->SetBit(TH1::kCanRebin);
180 
181  _hlHR = subrun.make<TH1F>("lHR","Orbit of last HardReset",3600,0.,3600*11223);
182  _hlHR->GetXaxis()->SetTitle("Orbit"); _hlHR->GetYaxis()->SetTitle("Events");
183  _hlHR->SetBit(TH1::kCanRebin);
184 
185  _hdlec0lresync = subrun.make<TH1F>("dlec0lresync","Orbit difference EC0-Resync",4000,-1999.5,2000.5);
186  _hdlec0lresync->GetXaxis()->SetTitle("lastEC0-lastResync");
187 
188  _hdlresynclHR = subrun.make<TH1F>("dlresynclHR","Orbit difference Resync-HR",4000,-1999.5,2000.5);
189  _hdlresynclHR->GetXaxis()->SetTitle("lastEC0-lastResync");
190 
191  }
192 
193  if(iRun.run() < _firstgoodrun) {
194  LogDebug("UnreliableMissingL1TriggerScalers") <<
195  "In this run L1TriggerScalers is missing or unreliable for phase determination: default phases will be used";
196  }
197 
198 }
199 
200 void
202 {
203  // summary of absolute bx offset vector
204 
205 }
206 
207 
208 void
210 
211  using namespace edm;
212 
213  std::auto_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection() );
214 
215 
216  const std::vector<int>& phases = _defphases;
217  const std::vector<std::string>& partnames = _defpartnames;
218 
219  int phasechange = 0;
220 
221  if(iEvent.run() >= _firstgoodrun ) {
222 
224  iEvent.getByLabel(_l1tscollection,l1ts);
225 
226  if(_wantHistos) _hsize->Fill(l1ts->size());
227 
228  // offset computation
229 
230  long long orbitoffset = 0;
231 
232  if(l1ts->size()>0) {
233 
234  if((*l1ts)[0].lastResync()!=0) {
235  orbitoffset = _useEC0 ? (*l1ts)[0].lastEventCounter0() + _magicOffset : (*l1ts)[0].lastResync() + _magicOffset;
236  }
237 
238  if(_wantHistos) {
239  _hlresync->Fill((*l1ts)[0].lastResync());
240  _hlOC0->Fill((*l1ts)[0].lastOrbitCounter0());
241  _hlTE->Fill((*l1ts)[0].lastTestEnable());
242  _hlstart->Fill((*l1ts)[0].lastStart());
243  _hlEC0->Fill((*l1ts)[0].lastEventCounter0());
244  _hlHR->Fill((*l1ts)[0].lastHardReset());
245  }
246 
247  if(_lastResync != (*l1ts)[0].lastResync()) {
248  _lastResync = (*l1ts)[0].lastResync();
249  if(_wantHistos) _hdlec0lresync->Fill((*l1ts)[0].lastEventCounter0()-(*l1ts)[0].lastResync());
250  LogDebug("TTCSignalReceived") << "New Resync at orbit " << _lastResync ;
251  }
252  if(_lastHardReset != (*l1ts)[0].lastHardReset()) {
253  _lastHardReset = (*l1ts)[0].lastHardReset();
254  if(_wantHistos) _hdlresynclHR->Fill((*l1ts)[0].lastResync()-(*l1ts)[0].lastHardReset());
255  LogDebug("TTCSignalReceived") << "New HardReset at orbit " << _lastHardReset ;
256  }
257  if(_lastTestEnable != (*l1ts)[0].lastTestEnable()) {
258  _lastTestEnable = (*l1ts)[0].lastTestEnable();
259  // LogDebug("TTCSignalReceived") << "New TestEnable at orbit " << _lastTestEnable ;
260  }
261  if(_lastOrbitCounter0 != (*l1ts)[0].lastOrbitCounter0()) {
262  _lastOrbitCounter0 = (*l1ts)[0].lastOrbitCounter0();
263  LogDebug("TTCSignalReceived") << "New OrbitCounter0 at orbit " << _lastOrbitCounter0 ;
264  }
265  if(_lastEventCounter0 != (*l1ts)[0].lastEventCounter0()) {
266  _lastEventCounter0 = (*l1ts)[0].lastEventCounter0();
267  LogDebug("TTCSignalReceived") << "New EventCounter0 at orbit " << _lastEventCounter0 ;
268  }
269  if(_lastStart != (*l1ts)[0].lastStart()) {
270  _lastStart = (*l1ts)[0].lastStart();
271  LogDebug("TTCSignalReceived") << "New Start at orbit " << _lastStart ;
272  }
273 
274  phasechange = ((long long)(orbitoffset*3564))%70;
275 
276  }
277  }
278 
279 
280  if(phases.size() < partnames.size() ) {
281  // throw exception
282  throw cms::Exception("InvalidAPVCyclePhases") << " Inconsistent phases/partitions vector sizes: "
283  << phases.size() << " "
284  << partnames.size();
285  }
286 
287  for(unsigned int ipart=0;ipart<partnames.size();++ipart) {
288  if(phases[ipart]>=0) {
289  apvphases->get()[partnames[ipart]] = (phases[ipart]+phasechange)%70;
290 
291  }
292  }
293 
294 
295  iEvent.put(apvphases);
296 
297 }
298 
299 // ------------ method called once each job just before starting event loop ------------
300 void
302 {
303 }
304 
305 // ------------ method called once each job just after ending the event loop ------------
306 void
308 }
309 
310 //define this as a plug-in
#define LogDebug(id)
RunNumber_t run() const
Definition: RunBase.h:42
const std::vector< std::string > _defpartnames
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
RunNumber_t run() const
Definition: Event.h:67
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual void endRun(edm::Run &, const edm::EventSetup &)
virtual void beginRun(edm::Run &, const edm::EventSetup &)
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
APVCyclePhaseProducerFromL1TS(const edm::ParameterSet &)
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition: Run.h:33