CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTAlbertoBenvenutiTask.cc
Go to the documentation of this file.
1 
2 
3 /*
4  * See header file for a description of this class.
5  *
6  * \author G. Mila - INFN Torino
7  */
8 
9 
11 
12 // Framework
14 
15 // Digis
19 
20 // Geometry
25 
26 // T0s
31 
34 
35 
36 #include <stdio.h>
37 #include <sstream>
38 #include <math.h>
39 #include "TFile.h"
40 #include "TPostScript.h"
41 #include "TCanvas.h"
42 
43 using namespace edm;
44 using namespace std;
45 
46 
48 
49  debug = ps.getUntrackedParameter<bool>("debug", false);
50  if(debug)
51  cout<<"[DTAlbertoBenvenutiTask]: Constructor"<<endl;
52 
53  outputFile = ps.getUntrackedParameter<string>("outputFile", "DTDigiSources.root");
54  maxTDCHits = ps.getUntrackedParameter<int>("maxTDCHits",1000);
55 
56  // tMax (not yet from the DB)
57  tMax = parameters.getParameter<int>("defaultTmax");
58 
59  parameters = ps;
60 
61  //set Token(-s)
62  DTUnpackerToken_ = consumes<DTDigiCollection>(std::string("dtunpacker"));
63 }
64 
65 
67 
68  if(debug)
69  cout << "DTAlbertoBenvenutiTask: analyzed " << nevents << " events" << endl;
70 
71 }
72 
73 
75 
76  if(debug)
77  cout<<"[DTAlbertoBenvenutiTask] endjob called!"<<endl;
78 
79  map< DTChamberId, vector<TH1F*> > TBMap_perChamber;
80 
81  for(map<DTWireId, TH1F* >::const_iterator wHisto = TBMap.begin();
82  wHisto != TBMap.end();
83  wHisto++) {
84  DTChamberId chId = (*wHisto).first.layerId().superlayerId().chamberId();
85  TBMap_perChamber[chId].push_back((*wHisto).second);
86  }
87 
88 
89  for(map<DTChamberId, vector<TH1F*> >::const_iterator Histo = TBMap_perChamber.begin();
90  Histo != TBMap_perChamber.end();
91  Histo++) {
92  stringstream station; station << (*Histo).first.station();
93  stringstream sector; sector << (*Histo).first.sector();
94  stringstream wheel; wheel << (*Histo).first.wheel();
95 
96  string fileTag = "TimeBoxes";
97  string fileName = fileTag
98  + "_W" + wheel.str()
99  + "_Sec" + sector.str()
100  + "_St" + station.str()
101  + ".ps";
102 
103  TPostScript psFile(fileName.c_str(),111);
104  psFile.Range(20,26);
105  int counter = 0;
106  TCanvas c1("c1","",600,780);
107  c1.Divide(4,4);
108  psFile.NewPage();
109 
110  cout<<"[DTAlbertoBenvenutiTask] filling the file: "<<fileName<<endl;
111  for(vector<TH1F*>::const_iterator tbHisto = (*Histo).second.begin();
112  tbHisto != (*Histo).second.end();
113  tbHisto++) {
114  counter++;
115  c1.cd(counter);
116  (*tbHisto)->Draw();
117  if(counter%16 == 0 && counter>=16){
118  c1.Update();
119  psFile.NewPage();
120  c1.Clear();
121  c1.Divide(4,4);
122  counter=0;
123  }
124  } // loop over TB histos (divided per chamber)
125 
126  } //loop over the chambers
127 
128 }
129 
130 
132 
133  if(debug)
134  cout<<"[DTAlbertoBenvenutiTask]: BeginJob"<<endl;
135 
136  nevents = 0;
137 
138 }
139 
140 
141 
143 
144  // Get the geometry
145  context.get<MuonGeometryRecord>().get(muonGeom);
146 
147  // tTrig
148  if (parameters.getUntrackedParameter<bool>("readDB", true))
149  context.get<DTTtrigRcd>().get(tTrigMap);
150 
151  // t0s
152  if (parameters.getParameter<bool>("performPerWireT0Calibration"))
153  context.get<DTT0Rcd>().get(t0Map);
154 
155 }
156 
157 
159 
160  if (debug) cout<<"[DTAlbertoBenvenutiTask]: booking"<<endl;
161 
162  stringstream wheel; wheel << dtWire.layerId().superlayerId().chamberId().wheel();
163  stringstream station; station << dtWire.layerId().superlayerId().chamberId().station();
164  stringstream sector; sector << dtWire.layerId().superlayerId().chamberId().sector();
165 
166  // Loop over all the chambers
167  vector<const DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
168  vector<const DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
169  // Loop over the SLs
170  for (; ch_it != ch_end; ++ch_it) {
171  DTChamberId ch = (*ch_it)->id();
172  if(ch == dtWire.layerId().superlayerId().chamberId()){
173  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
174  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
175  // Loop over the SLs
176  for(; sl_it != sl_end; ++sl_it) {
177  DTSuperLayerId sl = (*sl_it)->id();
178  stringstream superLayer; superLayer << sl.superlayer();
179  vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin();
180  vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
181  // Loop over the Ls
182  for(; l_it != l_end; ++l_it) {
183  DTLayerId layerId = (*l_it)->id();
184  stringstream layer; layer << layerId.layer();
185  const int firstWire = muonGeom->layer(layerId)->specificTopology().firstChannel();
186  const int lastWire = muonGeom->layer(layerId)->specificTopology().lastChannel();
187  // Loop overt the wires
188  for(int wr=firstWire; wr -lastWire <= 0; wr++) {
189 
190  stringstream wire; wire << wr;
191  DTWireId wrId(layerId, wr);
192 
193  string histoTag = "TimeBox";
194  string histoName = histoTag
195  + "_W" + wheel.str()
196  + "_St" + station.str()
197  + "_Sec" + sector.str()
198  + "_SL" + superLayer.str()
199  + "_L" + layer.str()
200  + "_wire" + wire.str();
201 
202  if (debug) cout<<"[DTAlbertoBenvenutiTask]: histoName "<<histoName<<endl;
203 
204  if ( parameters.getUntrackedParameter<bool>("readDB", false) )
205  // ttrig and rms are TDC counts
206  tTrigMap->get(dtWire.layerId().superlayerId(), tTrig, tTrigRMS, kFactor,
208  else tTrig = parameters.getParameter<int>("defaultTtrig");
209 
210  string histoTitle = histoName + " (TDC Counts)";
211  int timeBoxGranularity = parameters.getUntrackedParameter<int>("timeBoxGranularity",4);
212 
213  if (!parameters.getUntrackedParameter<bool>("readDB", true)) {
214  int maxTDCCounts = 6400 * parameters.getUntrackedParameter<int>("tdcRescale", 1);
215  TH1F *TB = new TH1F(histoName.c_str(),histoTitle.c_str(), maxTDCCounts/timeBoxGranularity, 0, maxTDCCounts);
216  TBMap[wrId] = TB;
217  }
218  else {
219  TH1F *TB = new TH1F(histoName.c_str(),histoTitle.c_str(), 2*tMax/timeBoxGranularity, tTrig-tMax, tTrig+2*tMax);
220  TBMap[wrId] = TB;
221  }
222 
223  } // loopover wires
224  } // loop over Ls
225  } // loop over SLs
226  } // if is the right chamber to book
227  } // loop over chambers
228 }
229 
230 
232 
233  nevents++;
234  if (nevents%1000 == 0 && debug) {}
235 
237  e.getByToken(DTUnpackerToken_, dtdigis);
238 
239  bool checkNoisyChannels = parameters.getUntrackedParameter<bool>("checkNoisyChannels",false);
241  if(checkNoisyChannels) {
242  // Get the map of noisy channels
243  c.get<DTStatusFlagRcd>().get(statusMap);
244  }
245 
246  int tdcCount = 0;
248  for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
249  for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
250  digiIt!=((*dtLayerId_It).second).second; ++digiIt){
251  tdcCount++;
252  }
253  }
254 
255  bool isSyncNoisy = false;
256  if (tdcCount > maxTDCHits) isSyncNoisy = true;
257 
258  for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
259  for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
260  digiIt!=((*dtLayerId_It).second).second; ++digiIt){
261 
262  bool isNoisy = false;
263  bool isFEMasked = false;
264  bool isTDCMasked = false;
265  bool isTrigMask = false;
266  bool isDead = false;
267  bool isNohv = false;
268  const DTWireId wireId(((*dtLayerId_It).first), (*digiIt).wire());
269  if(checkNoisyChannels) {
270  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
271  }
272 
273  // for clearness..
274 // const DTSuperLayerId dtSLId = ((*dtLayerId_It).first).superlayerId();
275 // uint32_t indexSL = dtSLId.rawId();
276 // const DTChamberId dtChId = dtSLId.chamberId();
277 // uint32_t indexCh = dtChId.rawId();
278 // int layer_number=((*dtLayerId_It).first).layer();
279 // int superlayer_number=dtSLId.superlayer();
280 // const DTLayerId dtLId = (*dtLayerId_It).first;
281 // uint32_t indexL = dtLId.rawId();
282 
283  float t0; float t0RMS;
284  int tdcTime = (*digiIt).countsTDC();
285 
286  if (parameters.getParameter<bool>("performPerWireT0Calibration")) {
287  const DTWireId dtWireId(((*dtLayerId_It).first), (*digiIt).wire());
288  t0Map->get(dtWireId, t0, t0RMS, DTTimeUnits::counts) ;
289  tdcTime += int(round(t0));
290  }
291 
292  // avoid to fill TB with noise
293  if ((!isNoisy ) && (!isSyncNoisy)) {
294  // TimeBoxes per wire
295  if (TBMap.find(wireId) == TBMap.end()){
296  bookHistos(wireId);
297  TBMap[wireId]->Fill(tdcTime);
298  }
299  else
300  TBMap[wireId]->Fill(tdcTime);
301  }
302  }
303  }
304 }
305 
306 
307 
308 // Local Variables:
309 // show-trailing-whitespace: t
310 // truncate-lines: t
311 // End:
T getUntrackedParameter(std::string const &, T const &) const
dictionary parameters
Definition: Parameters.py:2
virtual ~DTAlbertoBenvenutiTask()
Destructor.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
DTChamberId chamberId() const
Return the corresponding ChamberId.
void beginRun(const edm::Run &, const edm::EventSetup &)
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:59
void bookHistos()
Definition: Histogram.h:33
U second(std::pair< T, U > const &p)
int superlayer() const
Return the superlayer number (deprecated method name)
#define debug
Definition: HDRShower.cc:19
const T & get() const
Definition: EventSetup.h:55
std::vector< DTDigi >::const_iterator const_iterator
Definition: DTT0Rcd.h:9
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:62
int sector() const
Definition: DTChamberId.h:61
static std::atomic< unsigned int > counter
void bookHistos(const DTWireId dtWire)
Book the ME.
tuple cout
Definition: gather_cfg.py:121
DTAlbertoBenvenutiTask(const edm::ParameterSet &ps)
Constructor.
int station() const
Return the station number.
Definition: DTChamberId.h:51
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
Definition: Run.h:41