CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
APVShotsAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: APVShotsAnalyzer
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Tue Jul 19 11:56:00 CEST 2009
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
24 #include "TH1F.h"
25 #include "TProfile.h"
26 #include <vector>
27 #include <string>
28 
31 
34 
36 
38 
41 
43 
46 
49 
50 //******** Single include for the TkMap *************
52 //***************************************************
53 
54 //******** includes for the cabling *************
59 //***************************************************
60 
61 
62 //
63 // class decleration
64 //
65 
67 public:
68  explicit APVShotsAnalyzer(const edm::ParameterSet&);
70 
71 
72 private:
73  virtual void beginJob() ;
74  virtual void beginRun(const edm::Run&, const edm::EventSetup&) ;
75  virtual void endRun(const edm::Run&, const edm::EventSetup&) ;
76  virtual void analyze(const edm::Event&, const edm::EventSetup&);
77  virtual void endJob() ;
78 
79  void updateDetCabling( const edm::EventSetup& setup );
80 
81  // ----------member data ---------------------------
82 
84  bool _zs;
85  std::string _suffix;
86  int _nevents;
87 
88  TH1F* _nShots;
89  TProfile* _nShotsVsTime;
90  TH1F* _whichAPV;
91  TH1F* _stripMult;
92  TH1F* _median;
93  TH1F* _subDetector;
94  TH1F* _fed;
95 
96  TH2F* _medianVsFED;
97  TH2F* _nShotsVsFED;
98 
99 
101 
102  // DetCabling
104  uint32_t _cacheIdDet;
106 
107 };
108 
109 //
110 // constants, enums and typedefs
111 //
112 
113 //
114 // static data member definitions
115 //
116 
117 //
118 // constructors and destructor
119 //
121  _digicollection(iConfig.getParameter<edm::InputTag>("digiCollection")),
122  _zs(iConfig.getUntrackedParameter<bool>("zeroSuppressed",true)),
123  _suffix(iConfig.getParameter<std::string>("mapSuffix")),
124  _nevents(0),
125  _useCabling(iConfig.getUntrackedParameter<bool>("useCabling",true)),
126  _cacheIdDet(0),
127  _detCabling(0)
128 {
129  //now do what ever initialization is needed
130 
131  if(!_zs) _suffix += "_notZS";
132 
134 
135  _nShots = tfserv->make<TH1F>("nShots","Number of Shots per event",200,-0.5,199.5);
136  _nShots->GetXaxis()->SetTitle("Shots"); _nShots->GetYaxis()->SetTitle("Events");
137  _nShots->StatOverflows(kTRUE);
138 
139  _nShotsVsTime = tfserv->make<TProfile>("nShotsVsTime","Mean number of shots vs orbit number",3600,0.5,3600*11223+0.5);
140  _nShotsVsTime->GetXaxis()->SetTitle("Orbit"); _nShotsVsTime->GetYaxis()->SetTitle("Number of Shots");
141  _nShotsVsTime->SetBit(TH1::kCanRebin);
142 
143  _whichAPV = tfserv->make<TH1F>("whichAPV","APV with shots",6,-0.5,5.5);
144  _whichAPV->GetXaxis()->SetTitle("APV"); _whichAPV->GetYaxis()->SetTitle("Shots");
145 
146  _stripMult = tfserv->make<TH1F>("stripMultiplicity","Shot Strip Multiplicity",129,-0.5,128.5);
147  _stripMult->GetXaxis()->SetTitle("Number of Strips"); _stripMult->GetYaxis()->SetTitle("Shots");
148 
149  _median = tfserv->make<TH1F>("median","APV Shot charge median",256,-0.5,255.5);
150  _median->GetXaxis()->SetTitle("Charge [ADC]"); _median->GetYaxis()->SetTitle("Shots");
151 
152  _subDetector = tfserv->make<TH1F>("subDets","SubDetector Shot distribution",10,-0.5,9.5);
153  _subDetector->GetYaxis()->SetTitle("Shots");
154 
155  if (_useCabling) {
156  _fed = tfserv->make<TH1F>("fed","FED Shot distribution",440,50,490);
157  _fed->GetYaxis()->SetTitle("Shots");
158 
159  _nShotsVsFED = tfserv->make<TH2F>("nShotsVsFED","Number of Shots per event vs fedid",440,50,490,200,-0.5,199.5);
160  _nShotsVsFED->GetXaxis()->SetTitle("fedId"); _nShots->GetYaxis()->SetTitle("Shots"); _nShots->GetZaxis()->SetTitle("Events");
161  _nShotsVsFED->StatOverflows(kTRUE);
162 
163  _medianVsFED = tfserv->make<TH2F>("medianVsFED","APV Shot charge median vs fedid",440,50,490,256,-0.5,255.5);
164  _medianVsFED->GetXaxis()->SetTitle("fedId");_medianVsFED->GetYaxis()->SetTitle("Charge [ADC]"); _median->GetZaxis()->SetTitle("Shots");
165  }
166 
167  tkhisto =new TkHistoMap("ShotMultiplicity","ShotMultiplicity",-1);
168  tkhisto2 =new TkHistoMap("StripMultiplicity","StripMultiplicity",-1);
169 }
170 
171 
173 {
174 
175  // do anything here that needs to be done at desctruction time
176  // (e.g. close files, deallocate resources etc.)
177  if ( _detCabling ) _detCabling = 0;
178 
179 }
180 
181 
182 //
183 // member functions
184 //
185 
186 // ------------ method called to for each event ------------
187 void
189 {
190  using namespace edm;
191 
192  if (_useCabling){
193  //retrieve cabling
194  updateDetCabling( iSetup );
195  }
196 
197  _nevents++;
198 
200  iEvent.getByLabel(_digicollection,digis);
201 
202  // loop on detector with digis
203 
204  int nshots=0;
205  std::vector<int> nshotsperFed;
206 
207  const uint16_t lNumFeds = sistrip::FED_ID_MAX-sistrip::FED_ID_MIN+1;
208  if (_useCabling){
209  nshotsperFed.resize(lNumFeds,0);
210  }
211 
212  APVShotFinder apvsf(*digis,_zs);
213  const std::vector<APVShot>& shots = apvsf.getShots();
214 
215  for(std::vector<APVShot>::const_iterator shot=shots.begin();shot!=shots.end();++shot) {
216  if(shot->isGenuine()) {
217 
218  //get the fedid from the detid
219 
220  uint32_t det=shot->detId();
221  if (_useCabling){
222  const std::vector<const FedChannelConnection *> & conns = _detCabling->getConnections( det );
223 
224  if (!(conns.size())) continue;
225  uint16_t lFedId = 0;
226  for (uint32_t ch = 0; ch<conns.size(); ch++) {
227  lFedId = conns[ch]->fedId();
228  //uint16_t lFedCh = conns[ch]->fedCh();
229 
230  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
231  std::cout << " -- Invalid fedid " << lFedId << " for detid " << det << " connection " << ch << std::endl;
232  continue;
233  }
234  else break;
235  }
236 
237  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
238  std::cout << " -- No valid fedid (=" << lFedId << ") found for detid " << det << std::endl;
239  continue;
240  }
241  ++nshotsperFed[lFedId-sistrip::FED_ID_MIN];
242  _fed->Fill(lFedId);
243  _medianVsFED->Fill(lFedId,shot->median());
244 
245 
246  }
247 
248  ++nshots;
249 
250 
251  _whichAPV->Fill(shot->apvNumber());
252  _median->Fill(shot->median());
253  _stripMult->Fill(shot->nStrips());
254  _subDetector->Fill(shot->subDet());
255  tkhisto2->fill(det,shot->nStrips());;
256  tkhisto->add(det,1);
257 
258 
259 
260  }
261  }
262 
263  _nShots->Fill(nshots);
264  if (_useCabling){
265  for (uint16_t lFed(0); lFed<lNumFeds; lFed++){
266  _nShotsVsFED->Fill(lFed+sistrip::FED_ID_MIN,nshotsperFed[lFed]);
267  }
268  }
269 
270  _nShotsVsTime->Fill(iEvent.orbitNumber(),nshots);
271 
272 
273 }
274 
275 void
277 {}
278 
279 void
281 {
282 }
283 
284 
285 // ------------ method called once each job just before starting event loop ------------
286 void
288 {
289 
290 }
291 
292 // ------------ method called once each job just after ending the event loop ------------
293 void
295 
296  edm::LogInfo("EndOfJob") << _nevents << " analyzed events";
297 
299  TrackerMap tkmap,tkmap2;
300 
301  tkmap.setPalette(1);
302  tkmap2.setPalette(1);
303  tkhisto->dumpInTkMap(&tkmap);
304  tkhisto2->dumpInTkMap(&tkmap2);
305  std::string tkshotmultmapname = "ShotMultiplicity_" + _suffix + ".png";
306  tkmap.save(true,0,0,tkshotmultmapname);
307  std::string tkstripmultmapname = "StripMultiplicity_" + _suffix + ".png";
308  tkmap2.save(true,0,0,tkstripmultmapname);
309 
310  std::string rootmapname = "TKMap_"+_suffix+".root";
311  tkhisto->save(rootmapname);
312  tkhisto2->save(rootmapname);
313 }
314 
315 
317 {
318  if (_useCabling){
319  uint32_t cache_id = setup.get<SiStripDetCablingRcd>().cacheIdentifier();//.get( cabling_ );
320 
321  if ( _cacheIdDet != cache_id ) { // If the cache ID has changed since the last update...
322  // Update the cabling object
324  setup.get<SiStripDetCablingRcd>().get( c );
325  _detCabling = c.product();
326  _cacheIdDet = cache_id;
327  } // end of new cache ID check
328  }
329 }
330 
331 
332 
333 
334 //define this as a plug-in
static const uint16_t FED_ID_MIN
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TProfile * _nShotsVsTime
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
const std::vector< APVShot > & getShots() const
void save(std::string filename)
Definition: TkHistoMap.cc:41
int iEvent
Definition: GenABIO.cc:243
virtual void endJob()
APVShotsAnalyzer(const edm::ParameterSet &)
TkHistoMap * tkhisto2
void fill(uint32_t &detid, float value)
Definition: TkHistoMap.cc:130
void setPalette(int numpalette)
Definition: TrackerMap.h:68
void save(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:632
virtual void endRun(const edm::Run &, const edm::EventSetup &)
const SiStripDetCabling * _detCabling
The cabling object.
int orbitNumber() const
Definition: EventBase.h:63
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:184
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual void analyze(const edm::Event &, const edm::EventSetup &)
TkHistoMap * tkhisto
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
virtual void beginJob()
T * make() const
make new ROOT object
tuple cout
Definition: gather_cfg.py:121
static const uint16_t FED_ID_MAX
uint32_t _cacheIdDet
DB cache ID used to establish if the cabling has changed during the run.
void add(uint32_t &detid, float value)
Definition: TkHistoMap.cc:163
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void updateDetCabling(const edm::EventSetup &setup)
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: Run.h:33
edm::InputTag _digicollection