37 #include "TPostScript.h"
47 cout <<
"[DTNoiseComputation]: Constructor" <<endl;
57 theFile =
new TFile(rootFileName.c_str(),
"READ");
61 theNewFile =
new TFile(newRootFileName.c_str(),
"RECREATE");
76 string CheckHistoName;
79 TH1F *hAverageNoiseHisto;
80 TH1F *hAverageNoiseIntegratedHisto;
81 TH1F *hAverageNoiseHistoPerCh;
82 TH1F *hAverageNoiseIntegratedHistoPerCh;
86 string AverageNoiseName;
87 string AverageNoiseIntegratedName;
88 string AverageNoiseNamePerCh;
89 string AverageNoiseIntegratedNamePerCh;
94 vector<DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
95 vector<DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
97 for (; ch_it != ch_end; ++ch_it) {
99 vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
100 vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
102 for(; sl_it != sl_end; ++sl_it) {
104 vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin();
105 vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
107 for(; l_it != l_end; ++l_it) {
112 CheckHistoName =
"DigiOccupancy_" + getLayerName(dtLId);
113 TH1F *hCheckHisto = (TH1F *)
theFile->Get(CheckHistoName.c_str());
116 stringstream wheel; wheel << ch.
wheel();
119 if(someHowNoisyC.find(make_pair(ch.
wheel(),ch.
station())) == someHowNoisyC.end()) {
120 TString histoName_someHowNoisy =
"somehowNoisyCell_W"+wheel.str()+
"_St"+station.str();
121 hsomeHowNoisyC =
new TH1F(histoName_someHowNoisy,histoName_someHowNoisy,getMaxNumBins(ch),1,getMaxNumBins(ch)+1);
122 someHowNoisyC[make_pair(ch.
wheel(),ch.
station())]=hsomeHowNoisyC;
125 if(noisyC.find(make_pair(ch.
wheel(),ch.
station())) == noisyC.end()) {
126 TString histoName_noisy =
"noisyCell_W"+wheel.str()+
"_St"+station.str();
127 hnoisyC =
new TH1F(histoName_noisy,histoName_noisy,getMaxNumBins(ch),1,getMaxNumBins(ch)+1);
132 if(AvNoisePerSuperLayer.find(dtLId.
superlayerId()) == AvNoisePerSuperLayer.end()) {
133 AverageNoiseName =
"AverageNoise_" + getSuperLayerName(dtLId.
superlayerId());
134 hAverageNoiseHisto =
new TH1F(AverageNoiseName.c_str(), AverageNoiseName.c_str(), 200, 0, 10000);
135 AverageNoiseIntegratedName =
"AverageNoiseIntegrated_" + getSuperLayerName(dtLId.
superlayerId());
136 hAverageNoiseIntegratedHisto =
new TH1F(AverageNoiseIntegratedName.c_str(), AverageNoiseIntegratedName.c_str(), 200, 0, 10000);
137 AvNoisePerSuperLayer[dtLId.
superlayerId()] = hAverageNoiseHisto;
138 AvNoiseIntegratedPerSuperLayer[dtLId.
superlayerId()] = hAverageNoiseIntegratedHisto;
140 cout <<
" New Average Noise Histo per SuperLayer : " << hAverageNoiseHisto->GetName() << endl;
141 cout <<
" New Average Noise Integrated Histo per SuperLayer : " << hAverageNoiseHisto->GetName() << endl;
145 AverageNoiseNamePerCh =
"AverageNoise_" + getChamberName(dtLId);
146 hAverageNoiseHistoPerCh =
new TH1F(AverageNoiseNamePerCh.c_str(), AverageNoiseNamePerCh.c_str(), 200, 0, 10000);
147 AverageNoiseIntegratedNamePerCh =
"AverageNoiseIntegrated_" + getChamberName(dtLId);
148 hAverageNoiseIntegratedHistoPerCh =
new TH1F(AverageNoiseIntegratedNamePerCh.c_str(), AverageNoiseIntegratedNamePerCh.c_str(), 200, 0, 10000);
152 cout <<
" New Average Noise Histo per chamber : " << hAverageNoiseHistoPerCh->GetName() << endl;
155 HistoName =
"DigiOccupancy_" + getLayerName(dtLId);
157 hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
158 int numBin = hOccHisto->GetXaxis()->GetNbins();
161 theAverageNoise[wireID]= hOccHisto->GetBinContent(
bin);
162 if(theAverageNoise[wireID] != 0) {
163 AvNoisePerSuperLayer[dtLId.
superlayerId()]->Fill(theAverageNoise[wireID]);
171 HistoName =
"DigiOccupancy_" + getLayerName(dtLId);
173 hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
174 numBin = hOccHisto->GetXaxis()->GetNbins();
177 theAverageNoise[wireID]= hOccHisto->GetBinContent(
bin);
178 if(hOccHisto->GetBinContent(
bin)<100){
180 AvNoise += hOccHisto->GetBinContent(
bin);
182 if(hOccHisto->GetBinContent(
bin)>100 && hOccHisto->GetBinContent(
bin)<500){
184 cout<<
"filling somehow noisy cell"<<endl;
186 if(hOccHisto->GetBinContent(
bin)>500){
188 cout<<
"filling noisy cell"<<endl;
191 AvNoise = AvNoise/numCell;
192 cout<<
"theAverageNoise for layer "<<getLayerName(dtLId)<<
" is : "<<AvNoise << endl;
196 int updates = MaxEvents/1000;
197 for(
int evt=0; evt<updates; evt++){
198 stringstream toAppend; toAppend << evt;
199 Histo2Name =
"DigiPerWirePerEvent_" + getLayerName(dtLId) +
"_" + toAppend.str();
201 hEvtHisto = (TH2F *)
theFile->Get(Histo2Name.c_str());
204 cout <<
" New Histo with the number of events per evt per wire: " << hEvtHisto->GetName() << endl;
205 theEvtMap[dtLId].push_back(hEvtHisto);
221 cout <<
"[DTNoiseComputation] endjob called!" <<endl;
222 TH1F *hEvtDistance=0;
223 TF1 *ExpoFit =
new TF1(
"ExpoFit",
"expo", 0.5, 1000.5);
224 ExpoFit->SetMarkerColor();
226 TProfile *theNoiseHisto =
new TProfile(
"theNoiseHisto",
"Time Constant versus Average Noise",100000,0,100000);
230 for(
map<
DTLayerId, vector<TH2F*> >::const_iterator lHisto = theEvtMap.begin();
231 lHisto != theEvtMap.end();
233 for(
int bin=1;
bin<(*lHisto).second[0]->GetYaxis()->GetNbins();
bin++){
236 for(
int i=0;
i<int((*lHisto).second.size());
i++){
237 for(
int evt=1; evt<=(*lHisto).second[
i]->GetXaxis()->GetNbins(); evt++){
238 if((*lHisto).second[
i]->GetBinContent(evt,
bin) == 0) distanceEvt++;
240 if(toDel.find(wire) == toDel.end()) {
242 stringstream toAppend; toAppend <<
bin;
243 string Histo =
"EvtDistancePerWire_" + getLayerName((*lHisto).first) +
"_" + toAppend.str();
244 hEvtDistance =
new TH1F(Histo.c_str(),Histo.c_str(), 50000,0.5,50000.5);
246 hEvtDistance->Fill(distanceEvt);
251 if(toDel.find(wire) != toDel.end()){
252 theHistoEvtDistancePerWire[wire] = hEvtDistance;
254 theHistoEvtDistancePerWire[wire]->Fit(
"ExpoFit",
"R");
255 funct = theHistoEvtDistancePerWire[wire]->GetFunction(
"ExpoFit");
256 double par0 = funct->GetParameter(0);
257 double par1 = funct->GetParameter(1);
258 cout<<
"par0: "<<par0<<
" par1: "<<par1<<endl;
259 double chi2rid = funct->GetChisquare()/funct->GetNDF();
261 theTimeConstant[wire]=1;
263 theTimeConstant[wire]=par1;
265 theHistoEvtDistancePerWire[wire]->Write();
273 for(map<DTWireId, double>::const_iterator AvNoise = theAverageNoise.begin();
274 AvNoise != theAverageNoise.end();
277 theNoiseHisto->Fill((*AvNoise).second, theTimeConstant[wire]);
278 cout<<
"Layer: "<<getLayerName(wire.layerId())<<
" wire: "<<wire.wire()<<endl;
279 cout<<
"The Average noise: "<<(*AvNoise).second<<endl;
280 cout<<
"The time constant: "<<theTimeConstant[wire]<<endl;
283 theNoiseHisto->Write();
289 double integratedNoise,
bin, halfBin, maxBin;
290 for(map<DTSuperLayerId, TH1F*>::const_iterator AvNoiseHisto = AvNoisePerSuperLayer.begin();
291 AvNoiseHisto != AvNoisePerSuperLayer.end();
294 numBin = (*AvNoiseHisto).second->GetXaxis()->GetNbins();
295 maxBin = (*AvNoiseHisto).second->GetXaxis()->GetXmax();
296 bin= double(maxBin/numBin);
297 halfBin=double(bin/2);
299 (*AvNoiseHisto).second->Write();
300 for(
int i=1;
i<numBin;
i++){
301 integratedNoise+=(*AvNoiseHisto).second->GetBinContent(
i);
302 AvNoiseIntegratedPerSuperLayer[(*AvNoiseHisto).first]->Fill(halfBin,integratedNoise);
306 AvNoiseIntegratedPerSuperLayer[(*AvNoiseHisto).first]->Write();
309 for(map<DTChamberId, TH1F*>::const_iterator AvNoiseHisto = AvNoisePerChamber.begin();
310 AvNoiseHisto != AvNoisePerChamber.end();
313 numBin = (*AvNoiseHisto).second->GetXaxis()->GetNbins();
314 maxBin = (*AvNoiseHisto).second->GetXaxis()->GetXmax();
318 (*AvNoiseHisto).second->Write();
319 for(
int i=1;
i<numBin;
i++){
320 integratedNoise+=(*AvNoiseHisto).second->GetBinContent(
i);
321 AvNoiseIntegratedPerChamber[(*AvNoiseHisto).first]->Fill(halfBin,integratedNoise);
325 AvNoiseIntegratedPerChamber[(*AvNoiseHisto).first]->Write();
331 vector<DTChamber*>::const_iterator chamber_it = dtGeom->chambers().begin();
332 vector<DTChamber*>::const_iterator chamber_end = dtGeom->chambers().end();
334 for (; chamber_it != chamber_end; ++chamber_it) {
335 vector<const DTSuperLayer*>::const_iterator sl_it = (*chamber_it)->superLayers().begin();
336 vector<const DTSuperLayer*>::const_iterator sl_end = (*chamber_it)->superLayers().end();
338 for(; sl_it != sl_end; ++sl_it) {
340 vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin();
341 vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
343 string canvasName =
"c" + getSuperLayerName(sl);
344 TCanvas
c1(canvasName.c_str(),canvasName.c_str(),600,780);
345 TLegend *
leg=
new TLegend(0.5,0.6,0.7,0.8);
346 for(; l_it != l_end; ++l_it) {
348 string HistoName =
"DigiOccupancy_" + getLayerName(layerId);
350 TH1F *hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
352 string TitleHisto =
"AverageNoise_" + getSuperLayerName(sl);
353 cout<<
"TitleHisto : "<<TitleHisto<<endl;
354 hOccHisto->SetTitle(TitleHisto.c_str());
355 stringstream layer; layer << layerId.
layer();
356 string legendHisto =
"layer " + layer.str();
357 leg->AddEntry(hOccHisto,legendHisto.c_str(),
"L");
358 hOccHisto->SetMaximum(getYMaximum(sl));
360 if(layerId.
layer() == 1)
363 hOccHisto->Draw(
"same");
364 hOccHisto->SetLineColor(layerId.
layer());
377 for(
map<pair<int,int>, TH1F*>::const_iterator nCell = noisyC.begin();
378 nCell != noisyC.end();
381 (*nCell).second->Write();
383 for(
map<pair<int,int>, TH1F*>::const_iterator somehownCell = someHowNoisyC.begin();
384 somehownCell != someHowNoisyC.end();
387 (*somehownCell).second->Write();
405 stringstream Layer; Layer << lId.
layer();
406 stringstream superLayer; superLayer << dtSLId.
superlayer();
407 stringstream wheel; wheel << dtChId.
wheel();
409 stringstream sector; sector << dtChId.
sector();
413 +
"_St" + station.str()
414 +
"_Sec" + sector.str()
415 +
"_SL" + superLayer.str()
416 +
"_L" + Layer.str();
426 stringstream superLayer; superLayer << dtSLId.
superlayer();
427 stringstream wheel; wheel << dtChId.
wheel();
429 stringstream sector; sector << dtChId.
sector();
431 string SuperLayerName =
433 +
"_St" + station.str()
434 +
"_Sec" + sector.str()
435 +
"_SL" + superLayer.str();
437 return SuperLayerName;
446 stringstream wheel; wheel << dtChId.
wheel();
448 stringstream sector; sector << dtChId.
sector();
452 +
"_St" + station.str()
453 +
"_Sec" + sector.str();
464 for(
int SL=1; SL<=3; SL++){
465 if(!(chId.
station()==4 && SL==2)){
466 for (
int L=1;
L<=4;
L++){
468 string HistoName =
"DigiOccupancy_" + getLayerName(layerId);
470 TH1F *hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
472 if (hOccHisto->GetXaxis()->GetXmax()>maximum)
473 maximum = hOccHisto->GetXaxis()->GetNbins();
485 double dummy =
pow(10.,10.);
487 for (
int L=1;
L<=4;
L++){
489 string HistoName =
"DigiOccupancy_" + getLayerName(layerId);
491 TH1F *hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
493 if (hOccHisto->GetMaximum(dummy)>maximum)
494 maximum = hOccHisto->GetMaximum(dummy);
DTNoiseComputation(const edm::ParameterSet &ps)
Constructor.
T getUntrackedParameter(std::string const &, T const &) const
int getMaxNumBins(const DTChamberId &chId) const
double getYMaximum(const DTSuperLayerId &slId) const
void beginRun(const edm::Run &, const edm::EventSetup &setup)
DTChamberId chamberId() const
Return the corresponding ChamberId.
int layer() const
Return the layer number.
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
std::string getChamberName(const DTLayerId &lId) const
Get the name of the chamber.
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
int superlayer() const
Return the superlayer number (deprecated method name)
std::string getLayerName(const DTLayerId &lId) const
Get the name of the layer.
std::string getSuperLayerName(const DTSuperLayerId &slId) const
Get the name of the superLayer.
virtual ~DTNoiseComputation()
Destructor.
int station() const
Return the station number.
int wheel() const
Return the wheel number.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Power< A, B >::type pow(const A &a, const B &b)